-
Notifications
You must be signed in to change notification settings - Fork 6k
Allow embedder controlled composition of Flutter layers. #10195
Changes from all commits
9ac4d51
2761522
29791ff
8e160ba
91a3d39
9b8c091
9f14706
786ae19
4c5b365
c09cc95
fa25174
04b0955
6f88bc9
976b965
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,8 +33,11 @@ static const int kGrCacheMaxCount = 8192; | |
| // system channel. | ||
| static const size_t kGrCacheMaxByteSize = 24 * (1 << 20); | ||
|
|
||
| GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate) | ||
| : delegate_(delegate), weak_factory_(this) { | ||
| GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate, | ||
| bool render_to_surface) | ||
| : delegate_(delegate), | ||
| render_to_surface_(render_to_surface), | ||
| weak_factory_(this) { | ||
| if (!delegate_->GLContextMakeCurrent()) { | ||
| FML_LOG(ERROR) | ||
| << "Could not make the context current to setup the gr context."; | ||
|
|
@@ -68,13 +71,18 @@ GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate) | |
|
|
||
| delegate_->GLContextClearCurrent(); | ||
|
|
||
| valid_ = true; | ||
| context_owner_ = true; | ||
|
|
||
| valid_ = true; | ||
| } | ||
|
|
||
| GPUSurfaceGL::GPUSurfaceGL(sk_sp<GrContext> gr_context, | ||
| GPUSurfaceGLDelegate* delegate) | ||
| : delegate_(delegate), context_(gr_context), weak_factory_(this) { | ||
| GPUSurfaceGLDelegate* delegate, | ||
| bool render_to_surface) | ||
| : delegate_(delegate), | ||
| context_(gr_context), | ||
| render_to_surface_(render_to_surface), | ||
| weak_factory_(this) { | ||
| if (!delegate_->GLContextMakeCurrent()) { | ||
| FML_LOG(ERROR) | ||
| << "Could not make the context current to setup the gr context."; | ||
|
|
@@ -236,6 +244,15 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGL::AcquireFrame(const SkISize& size) { | |
| return nullptr; | ||
| } | ||
|
|
||
| // TODO(38466): Refactor GPU surface APIs take into account the fact that an | ||
| // external view embedder may want to render to the root surface. | ||
| if (!render_to_surface_) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW I feel like we've reached a point where we're applying concepts that doesn't align well with the higher level surface API and we should probably revisit it at some point. What do you think about leaving filing an issue saying we should refactor and leaving a TODO here describing the reason for this workaround and saying that we should clean it up in a coming refactoring?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, added a TODO and filed a bug flutter/flutter#38466 |
||
| return std::make_unique<SurfaceFrame>( | ||
| nullptr, [](const SurfaceFrame& surface_frame, SkCanvas* canvas) { | ||
| return true; | ||
| }); | ||
| } | ||
|
|
||
| const auto root_surface_transformation = GetRootTransformation(); | ||
|
|
||
| sk_sp<SkSurface> surface = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,12 @@ namespace flutter { | |
|
|
||
| class GPUSurfaceGL : public Surface { | ||
| public: | ||
| GPUSurfaceGL(GPUSurfaceGLDelegate* delegate); | ||
| GPUSurfaceGL(GPUSurfaceGLDelegate* delegate, bool render_to_surface); | ||
|
|
||
| // Creates a new GL surface reusing an existing GrContext. | ||
| GPUSurfaceGL(sk_sp<GrContext> gr_context, GPUSurfaceGLDelegate* delegate); | ||
| GPUSurfaceGL(sk_sp<GrContext> gr_context, | ||
| GPUSurfaceGLDelegate* delegate, | ||
| bool render_to_surface); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The meaning of render_to_surface wasn't immediately clear to me (A GPU surface that does not render to surface?), maybe worth documenting it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I documented the ivar and filed a bug to get rid of this hack. |
||
|
|
||
| ~GPUSurfaceGL() override; | ||
|
|
||
|
|
@@ -49,9 +51,14 @@ class GPUSurfaceGL : public Surface { | |
| sk_sp<GrContext> context_; | ||
| sk_sp<SkSurface> onscreen_surface_; | ||
| sk_sp<SkSurface> offscreen_surface_; | ||
| bool context_owner_; | ||
| // TODO(38466): Refactor GPU surface APIs take into account the fact that an | ||
| // external view embedder may want to render to the root surface. This is a | ||
| // hack to make avoid allocating resources for the root surface when an | ||
| // external view embedder is present. | ||
| const bool render_to_surface_; | ||
| bool valid_ = false; | ||
| fml::WeakPtrFactory<GPUSurfaceGL> weak_factory_; | ||
| bool context_owner_; | ||
|
|
||
| bool CreateOrUpdateSurfaces(const SkISize& size); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it make it an owned mapping once we have a release proc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess so. The argument could also be made that this object does not own the mapping but gives the closure to collect it (so whoever passes in the closure to this owns the mapping).