This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Lift restriction that embedders may not trample the render thread OpenGL context in composition callbacks. #16653
Merged
chinmaygarde
merged 3 commits into
flutter-team-archive:master
from
chinmaygarde:grcontext_reset_after_embedder_context
Feb 18, 2020
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,38 @@ | ||
| // Copyright 2013 The Flutter 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_HASH_COMBINE_H_ | ||
| #define FLUTTER_FML_HASH_COMBINE_H_ | ||
|
|
||
| #include <functional> | ||
|
|
||
| namespace fml { | ||
|
|
||
| template <class Type> | ||
| constexpr void HashCombineSeed(std::size_t& seed, Type arg) { | ||
| seed ^= std::hash<Type>{}(arg) + 0x9e3779b9 + (seed << 6) + (seed >> 2); | ||
| } | ||
|
|
||
| template <class Type, class... Rest> | ||
| constexpr void HashCombineSeed(std::size_t& seed, | ||
| Type arg, | ||
| Rest... other_args) { | ||
| HashCombineSeed(seed, arg); | ||
| HashCombineSeed(seed, other_args...); | ||
| } | ||
|
|
||
| constexpr std::size_t HashCombine() { | ||
| return 0xdabbad00; | ||
| } | ||
|
|
||
| template <class... Type> | ||
| constexpr std::size_t HashCombine(Type... args) { | ||
| std::size_t seed = HashCombine(); | ||
| HashCombineSeed(seed, args...); | ||
| return seed; | ||
| } | ||
|
|
||
| } // namespace fml | ||
|
|
||
| #endif // FLUTTER_FML_HASH_COMBINE_H_ |
This file contains hidden or 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,23 @@ | ||
| // Copyright 2013 The Flutter 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/hash_combine.h" | ||
| #include "flutter/testing/testing.h" | ||
|
|
||
| namespace fml { | ||
| namespace testing { | ||
|
|
||
| TEST(HashCombineTest, CanHash) { | ||
| ASSERT_EQ(HashCombine(), HashCombine()); | ||
| ASSERT_EQ(HashCombine("Hello"), HashCombine("Hello")); | ||
| ASSERT_NE(HashCombine("Hello"), HashCombine("World")); | ||
| ASSERT_EQ(HashCombine("Hello", "World"), HashCombine("Hello", "World")); | ||
| ASSERT_NE(HashCombine("World", "Hello"), HashCombine("Hello", "World")); | ||
| ASSERT_EQ(HashCombine(12u), HashCombine(12u)); | ||
| ASSERT_NE(HashCombine(12u), HashCombine(12.0f)); | ||
| ASSERT_EQ(HashCombine('a'), HashCombine('a')); | ||
| } | ||
|
|
||
| } // namespace testing | ||
| } // namespace fml |
This file contains hidden or 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 hidden or 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 hidden or 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,107 @@ | ||
| // Copyright 2013 The Flutter 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/platform/embedder/embedder_external_view.h" | ||
| #include "flutter/fml/trace_event.h" | ||
| #include "flutter/shell/common/canvas_spy.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| static SkISize TransformedSurfaceSize(const SkISize& size, | ||
| const SkMatrix& transformation) { | ||
| const auto source_rect = SkRect::MakeWH(size.width(), size.height()); | ||
| const auto transformed_rect = transformation.mapRect(source_rect); | ||
| return SkISize::Make(transformed_rect.width(), transformed_rect.height()); | ||
| } | ||
|
|
||
| EmbedderExternalView::EmbedderExternalView( | ||
| const SkISize& frame_size, | ||
| const SkMatrix& surface_transformation) | ||
| : EmbedderExternalView(frame_size, surface_transformation, {}, nullptr) {} | ||
|
|
||
| EmbedderExternalView::EmbedderExternalView( | ||
| const SkISize& frame_size, | ||
| const SkMatrix& surface_transformation, | ||
| ViewIdentifier view_identifier, | ||
| std::unique_ptr<EmbeddedViewParams> params) | ||
| : render_surface_size_( | ||
| TransformedSurfaceSize(frame_size, surface_transformation)), | ||
| surface_transformation_(surface_transformation), | ||
| view_identifier_(view_identifier), | ||
| embedded_view_params_(std::move(params)), | ||
| recorder_(std::make_unique<SkPictureRecorder>()), | ||
| canvas_spy_(std::make_unique<CanvasSpy>( | ||
| recorder_->beginRecording(frame_size.width(), frame_size.height()))) { | ||
| } | ||
|
|
||
| EmbedderExternalView::~EmbedderExternalView() = default; | ||
|
|
||
| EmbedderExternalView::RenderTargetDescriptor | ||
| EmbedderExternalView::CreateRenderTargetDescriptor() const { | ||
| return {render_surface_size_}; | ||
| } | ||
|
|
||
| SkCanvas* EmbedderExternalView::GetCanvas() const { | ||
| return canvas_spy_->GetSpyingCanvas(); | ||
| } | ||
|
|
||
| SkISize EmbedderExternalView::GetRenderSurfaceSize() const { | ||
| return render_surface_size_; | ||
| } | ||
|
|
||
| bool EmbedderExternalView::IsRootView() const { | ||
| return !HasPlatformView(); | ||
| } | ||
|
|
||
| bool EmbedderExternalView::HasPlatformView() const { | ||
| return view_identifier_.platform_view_id.has_value(); | ||
| } | ||
|
|
||
| bool EmbedderExternalView::HasEngineRenderedContents() const { | ||
| return canvas_spy_->DidDrawIntoCanvas(); | ||
| } | ||
|
|
||
| EmbedderExternalView::ViewIdentifier EmbedderExternalView::GetViewIdentifier() | ||
| const { | ||
| return view_identifier_; | ||
| } | ||
|
|
||
| const EmbeddedViewParams* EmbedderExternalView::GetEmbeddedViewParams() const { | ||
| return embedded_view_params_.get(); | ||
| } | ||
|
|
||
| bool EmbedderExternalView::Render(const EmbedderRenderTarget& render_target) { | ||
| TRACE_EVENT0("flutter", "EmbedderExternalView::Render"); | ||
|
|
||
| FML_DCHECK(HasEngineRenderedContents()) | ||
| << "Unnecessary asked to render into a render target when there was " | ||
| "nothing to render."; | ||
|
|
||
| auto picture = recorder_->finishRecordingAsPicture(); | ||
| if (!picture) { | ||
| return false; | ||
| } | ||
|
|
||
| auto surface = render_target.GetRenderSurface(); | ||
| if (!surface) { | ||
| return false; | ||
| } | ||
|
|
||
| FML_DCHECK(SkISize::Make(surface->width(), surface->height()) == | ||
| render_surface_size_); | ||
|
|
||
| auto canvas = surface->getCanvas(); | ||
| if (!canvas) { | ||
| return false; | ||
| } | ||
|
|
||
| canvas->setMatrix(surface_transformation_); | ||
| canvas->clear(SK_ColorTRANSPARENT); | ||
| canvas->drawPicture(picture); | ||
| canvas->flush(); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| } // namespace flutter | ||
This file contains hidden or 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,118 @@ | ||
| // Copyright 2013 The Flutter 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_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_VIEW_H_ | ||
| #define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_VIEW_H_ | ||
|
|
||
| #include <optional> | ||
| #include <unordered_map> | ||
| #include <unordered_set> | ||
|
|
||
| #include "flutter/flow/embedded_views.h" | ||
| #include "flutter/fml/hash_combine.h" | ||
| #include "flutter/fml/macros.h" | ||
| #include "flutter/shell/common/canvas_spy.h" | ||
| #include "flutter/shell/platform/embedder/embedder_render_target.h" | ||
| #include "third_party/skia/include/core/SkPictureRecorder.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| class EmbedderExternalView { | ||
| public: | ||
| using PlatformViewID = int64_t; | ||
| struct ViewIdentifier { | ||
| std::optional<PlatformViewID> platform_view_id; | ||
|
|
||
| ViewIdentifier() {} | ||
|
|
||
| ViewIdentifier(PlatformViewID view_id) : platform_view_id(view_id) {} | ||
|
|
||
| struct Hash { | ||
| constexpr std::size_t operator()(const ViewIdentifier& desc) const { | ||
| if (!desc.platform_view_id.has_value()) { | ||
| return fml::HashCombine(); | ||
| } | ||
|
|
||
| return fml::HashCombine(desc.platform_view_id.value()); | ||
| } | ||
| }; | ||
|
|
||
| struct Equal { | ||
| constexpr bool operator()(const ViewIdentifier& lhs, | ||
| const ViewIdentifier& rhs) const { | ||
| return lhs.platform_view_id == rhs.platform_view_id; | ||
| } | ||
| }; | ||
| }; | ||
|
|
||
| struct RenderTargetDescriptor { | ||
| SkISize surface_size = SkISize::MakeEmpty(); | ||
|
|
||
| struct Hash { | ||
| constexpr std::size_t operator()( | ||
| const RenderTargetDescriptor& desc) const { | ||
| return fml::HashCombine(desc.surface_size.width(), | ||
| desc.surface_size.height()); | ||
| } | ||
| }; | ||
|
|
||
| struct Equal { | ||
| bool operator()(const RenderTargetDescriptor& lhs, | ||
| const RenderTargetDescriptor& rhs) const { | ||
| return lhs.surface_size == rhs.surface_size; | ||
| } | ||
| }; | ||
| }; | ||
|
|
||
| using ViewIdentifierSet = std::unordered_set<ViewIdentifier, | ||
| ViewIdentifier::Hash, | ||
| ViewIdentifier::Equal>; | ||
|
|
||
| using PendingViews = std::unordered_map<ViewIdentifier, | ||
| std::unique_ptr<EmbedderExternalView>, | ||
| ViewIdentifier::Hash, | ||
| ViewIdentifier::Equal>; | ||
|
|
||
| EmbedderExternalView(const SkISize& frame_size, | ||
| const SkMatrix& surface_transformation); | ||
|
|
||
| EmbedderExternalView(const SkISize& frame_size, | ||
| const SkMatrix& surface_transformation, | ||
| ViewIdentifier view_identifier, | ||
| std::unique_ptr<EmbeddedViewParams> params); | ||
|
|
||
| ~EmbedderExternalView(); | ||
|
|
||
| bool IsRootView() const; | ||
|
|
||
| bool HasPlatformView() const; | ||
|
|
||
| bool HasEngineRenderedContents() const; | ||
|
|
||
| ViewIdentifier GetViewIdentifier() const; | ||
|
|
||
| const EmbeddedViewParams* GetEmbeddedViewParams() const; | ||
|
|
||
| RenderTargetDescriptor CreateRenderTargetDescriptor() const; | ||
|
|
||
| SkCanvas* GetCanvas() const; | ||
|
|
||
| SkISize GetRenderSurfaceSize() const; | ||
|
|
||
| bool Render(const EmbedderRenderTarget& render_target); | ||
|
|
||
| private: | ||
| const SkISize render_surface_size_; | ||
| const SkMatrix surface_transformation_; | ||
| ViewIdentifier view_identifier_; | ||
| std::unique_ptr<EmbeddedViewParams> embedded_view_params_; | ||
| std::unique_ptr<SkPictureRecorder> recorder_; | ||
| std::unique_ptr<CanvasSpy> canvas_spy_; | ||
|
|
||
| FML_DISALLOW_COPY_AND_ASSIGN(EmbedderExternalView); | ||
| }; | ||
|
|
||
| } // namespace flutter | ||
|
|
||
| #endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_VIEW_H_ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
typo: should to "unnecessarily"
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.
Done.