forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow plugging in a software backend for rendering in the shell. (flu…
- Loading branch information
1 parent
98e0091
commit df9e956
Showing
29 changed files
with
921 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright 2017 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
source_set("fml") { | ||
public_deps = [] | ||
|
||
if (is_ios || is_mac) { | ||
public_deps += [ "platform/darwin" ] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2017 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
source_set("darwin") { | ||
visibility = [ "//flutter/fml" ] | ||
|
||
sources = [ | ||
"cf_utils.cc", | ||
"cf_utils.h", | ||
] | ||
|
||
deps = [ | ||
"//lib/ftl", | ||
] | ||
|
||
libs = [ "CoreFoundation.framework" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/fml/platform/darwin/cf_utils.h" | ||
|
||
namespace fml { | ||
|
||
// | ||
|
||
} // namespace fml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_FML_PLATFORM_DARWIN_CF_UTILS_H_ | ||
#define FLUTTER_FML_PLATFORM_DARWIN_CF_UTILS_H_ | ||
|
||
#include <CoreFoundation/CoreFoundation.h> | ||
#include "lib/ftl/macros.h" | ||
|
||
namespace fml { | ||
|
||
template <class T> | ||
class CFRef { | ||
public: | ||
CFRef() : instance_(nullptr) {} | ||
|
||
CFRef(T instance) : instance_(instance) {} | ||
|
||
~CFRef() { | ||
if (instance_ != nullptr) { | ||
CFRelease(instance_); | ||
} | ||
instance_ = nullptr; | ||
} | ||
|
||
operator T() const { return instance_; } | ||
|
||
operator bool() const { return instance_ != nullptr; } | ||
|
||
private: | ||
T instance_; | ||
|
||
FTL_DISALLOW_COPY_AND_ASSIGN(CFRef); | ||
}; | ||
|
||
} // namespace fml | ||
|
||
#endif // FLUTTER_FML_PLATFORM_DARWIN_CF_UTILS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/shell/gpu/gpu_surface_software.h" | ||
|
||
#include <memory> | ||
#include "lib/ftl/logging.h" | ||
|
||
namespace shell { | ||
|
||
GPUSurfaceSoftware::GPUSurfaceSoftware(GPUSurfaceSoftwareDelegate* delegate) | ||
: delegate_(delegate), weak_factory_(this) {} | ||
|
||
GPUSurfaceSoftware::~GPUSurfaceSoftware() = default; | ||
|
||
bool GPUSurfaceSoftware::Setup() { | ||
return IsValid(); | ||
} | ||
|
||
bool GPUSurfaceSoftware::IsValid() { | ||
return delegate_ != nullptr; | ||
} | ||
|
||
std::unique_ptr<SurfaceFrame> GPUSurfaceSoftware::AcquireFrame( | ||
const SkISize& size) { | ||
if (!IsValid()) { | ||
return nullptr; | ||
} | ||
|
||
auto backing_store = delegate_->AcquireBackingStore(size); | ||
|
||
if (backing_store == nullptr) { | ||
return nullptr; | ||
} | ||
|
||
if (size != SkISize::Make(backing_store->width(), backing_store->height())) { | ||
return nullptr; | ||
} | ||
|
||
SurfaceFrame::SubmitCallback | ||
on_submit = [self = weak_factory_.GetWeakPtr()]( | ||
const SurfaceFrame& surface_frame, SkCanvas* canvas) | ||
->bool { | ||
// If the surface itself went away, there is nothing more to do. | ||
if (!self || !self->IsValid() || canvas == nullptr) { | ||
return false; | ||
} | ||
|
||
canvas->flush(); | ||
|
||
return self->delegate_->PresentBackingStore(surface_frame.SkiaSurface()); | ||
}; | ||
|
||
return std::make_unique<SurfaceFrame>(backing_store, on_submit); | ||
} | ||
|
||
GrContext* GPUSurfaceSoftware::GetContext() { | ||
// The is no GrContext associated with a software surface. | ||
return nullptr; | ||
} | ||
|
||
} // namespace shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_SHELL_GPU_GPU_SURFACE_SOFTWARE_H_ | ||
#define FLUTTER_SHELL_GPU_GPU_SURFACE_SOFTWARE_H_ | ||
|
||
#include "flutter/shell/common/surface.h" | ||
#include "lib/ftl/macros.h" | ||
#include "lib/ftl/memory/weak_ptr.h" | ||
#include "third_party/skia/include/core/SkSurface.h" | ||
|
||
namespace shell { | ||
|
||
class GPUSurfaceSoftwareDelegate { | ||
public: | ||
virtual sk_sp<SkSurface> AcquireBackingStore(const SkISize& size) = 0; | ||
virtual bool PresentBackingStore(sk_sp<SkSurface> backing_store) = 0; | ||
}; | ||
|
||
class GPUSurfaceSoftware : public Surface { | ||
public: | ||
GPUSurfaceSoftware(GPUSurfaceSoftwareDelegate* delegate); | ||
|
||
~GPUSurfaceSoftware() override; | ||
|
||
bool Setup() override; | ||
|
||
bool IsValid() override; | ||
|
||
std::unique_ptr<SurfaceFrame> AcquireFrame(const SkISize& size) override; | ||
|
||
GrContext* GetContext() override; | ||
|
||
private: | ||
GPUSurfaceSoftwareDelegate* delegate_; | ||
|
||
ftl::WeakPtrFactory<GPUSurfaceSoftware> weak_factory_; | ||
|
||
FTL_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceSoftware); | ||
}; | ||
|
||
} // namespace shell | ||
|
||
#endif // FLUTTER_SHELL_GPU_GPU_SURFACE_SOFTWARE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.