From cd5632a6ebe56c151062e8c3f35ef0523a4e418c Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Tue, 20 Oct 2020 11:54:30 -0700 Subject: [PATCH 1/2] Reland fuchsia external view embedder will be shared with platform view This reverts commit 9b752790f4d25ab238576c719208d7a38c6293f3. --- flow/layers/child_scene_layer.cc | 4 +- flow/layers/child_scene_layer.h | 2 +- flow/layers/clip_path_layer.cc | 2 +- flow/layers/clip_path_layer.h | 2 +- flow/layers/clip_rect_layer.cc | 2 +- flow/layers/clip_rect_layer.h | 2 +- flow/layers/clip_rrect_layer.cc | 2 +- flow/layers/clip_rrect_layer.h | 2 +- flow/layers/container_layer.cc | 7 +- flow/layers/container_layer.h | 4 +- flow/layers/fuchsia_layer_unittests.cc | 12 ++-- flow/layers/layer.cc | 4 +- flow/layers/layer.h | 2 +- flow/layers/layer_tree.cc | 6 +- flow/layers/layer_tree.h | 2 +- flow/layers/opacity_layer.cc | 8 +-- flow/layers/opacity_layer.h | 2 +- flow/layers/platform_view_layer.cc | 5 +- flow/layers/platform_view_layer.h | 2 +- flow/layers/transform_layer.cc | 2 +- flow/layers/transform_layer.h | 2 +- flow/scene_update_context.cc | 70 ++++++++++--------- flow/scene_update_context.h | 16 +++-- .../fuchsia/flutter/compositor_context.cc | 8 +-- .../fuchsia/flutter/compositor_context.h | 9 +-- shell/platform/fuchsia/flutter/engine.cc | 36 ++++++---- shell/platform/fuchsia/flutter/engine.h | 6 +- .../platform/fuchsia/flutter/platform_view.cc | 3 + .../platform/fuchsia/flutter/platform_view.h | 4 ++ .../fuchsia/flutter/platform_view_unittest.cc | 17 ++++- shell/platform/fuchsia/flutter/surface.cc | 4 +- shell/platform/fuchsia/flutter/surface.h | 4 +- 32 files changed, 146 insertions(+), 107 deletions(-) diff --git a/flow/layers/child_scene_layer.cc b/flow/layers/child_scene_layer.cc index 858328a140b22..3408f7b4367d2 100644 --- a/flow/layers/child_scene_layer.cc +++ b/flow/layers/child_scene_layer.cc @@ -24,10 +24,10 @@ void ChildSceneLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { void ChildSceneLayer::Paint(PaintContext& context) const {} -void ChildSceneLayer::UpdateScene(SceneUpdateContext& context) { +void ChildSceneLayer::UpdateScene(std::shared_ptr context) { TRACE_EVENT0("flutter", "ChildSceneLayer::UpdateScene"); FML_DCHECK(needs_system_composite()); - context.UpdateView(layer_id_, offset_, size_, hit_testable_); + context->UpdateView(layer_id_, offset_, size_, hit_testable_); } } // namespace flutter diff --git a/flow/layers/child_scene_layer.h b/flow/layers/child_scene_layer.h index cad47db00462a..0ec7f3b16efb1 100644 --- a/flow/layers/child_scene_layer.h +++ b/flow/layers/child_scene_layer.h @@ -26,7 +26,7 @@ class ChildSceneLayer : public Layer { void Paint(PaintContext& context) const override; - void UpdateScene(SceneUpdateContext& context) override; + void UpdateScene(std::shared_ptr context) override; private: zx_koid_t layer_id_ = ZX_KOID_INVALID; diff --git a/flow/layers/clip_path_layer.cc b/flow/layers/clip_path_layer.cc index 038ead12a6805..0b714392b60f5 100644 --- a/flow/layers/clip_path_layer.cc +++ b/flow/layers/clip_path_layer.cc @@ -41,7 +41,7 @@ void ClipPathLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { #if defined(LEGACY_FUCHSIA_EMBEDDER) -void ClipPathLayer::UpdateScene(SceneUpdateContext& context) { +void ClipPathLayer::UpdateScene(std::shared_ptr context) { TRACE_EVENT0("flutter", "ClipPathLayer::UpdateScene"); FML_DCHECK(needs_system_composite()); diff --git a/flow/layers/clip_path_layer.h b/flow/layers/clip_path_layer.h index ce2e4e54d66e3..eac015db9e5d1 100644 --- a/flow/layers/clip_path_layer.h +++ b/flow/layers/clip_path_layer.h @@ -22,7 +22,7 @@ class ClipPathLayer : public ContainerLayer { } #if defined(LEGACY_FUCHSIA_EMBEDDER) - void UpdateScene(SceneUpdateContext& context) override; + void UpdateScene(std::shared_ptr context) override; #endif private: diff --git a/flow/layers/clip_rect_layer.cc b/flow/layers/clip_rect_layer.cc index fbd36dab65d05..cd4443b5c0198 100644 --- a/flow/layers/clip_rect_layer.cc +++ b/flow/layers/clip_rect_layer.cc @@ -36,7 +36,7 @@ void ClipRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { #if defined(LEGACY_FUCHSIA_EMBEDDER) -void ClipRectLayer::UpdateScene(SceneUpdateContext& context) { +void ClipRectLayer::UpdateScene(std::shared_ptr context) { TRACE_EVENT0("flutter", "ClipRectLayer::UpdateScene"); FML_DCHECK(needs_system_composite()); diff --git a/flow/layers/clip_rect_layer.h b/flow/layers/clip_rect_layer.h index b52a9512262d3..9c57861d87fe2 100644 --- a/flow/layers/clip_rect_layer.h +++ b/flow/layers/clip_rect_layer.h @@ -21,7 +21,7 @@ class ClipRectLayer : public ContainerLayer { } #if defined(LEGACY_FUCHSIA_EMBEDDER) - void UpdateScene(SceneUpdateContext& context) override; + void UpdateScene(std::shared_ptr context) override; #endif private: diff --git a/flow/layers/clip_rrect_layer.cc b/flow/layers/clip_rrect_layer.cc index b3ff833c4a4f3..32ed1a39096ab 100644 --- a/flow/layers/clip_rrect_layer.cc +++ b/flow/layers/clip_rrect_layer.cc @@ -37,7 +37,7 @@ void ClipRRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { #if defined(LEGACY_FUCHSIA_EMBEDDER) -void ClipRRectLayer::UpdateScene(SceneUpdateContext& context) { +void ClipRRectLayer::UpdateScene(std::shared_ptr context) { TRACE_EVENT0("flutter", "ClipRRectLayer::UpdateScene"); FML_DCHECK(needs_system_composite()); diff --git a/flow/layers/clip_rrect_layer.h b/flow/layers/clip_rrect_layer.h index 314886a1fed30..1422615c5c6b3 100644 --- a/flow/layers/clip_rrect_layer.h +++ b/flow/layers/clip_rrect_layer.h @@ -22,7 +22,7 @@ class ClipRRectLayer : public ContainerLayer { } #if defined(LEGACY_FUCHSIA_EMBEDDER) - void UpdateScene(SceneUpdateContext& context) override; + void UpdateScene(std::shared_ptr context) override; #endif private: diff --git a/flow/layers/container_layer.cc b/flow/layers/container_layer.cc index 825826b70835f..a6ad98ba1aae4 100644 --- a/flow/layers/container_layer.cc +++ b/flow/layers/container_layer.cc @@ -98,18 +98,19 @@ void ContainerLayer::CheckForChildLayerBelow(PrerollContext* context) { // All ContainerLayers make the check in PrerollChildren. } -void ContainerLayer::UpdateScene(SceneUpdateContext& context) { +void ContainerLayer::UpdateScene(std::shared_ptr context) { UpdateSceneChildren(context); } -void ContainerLayer::UpdateSceneChildren(SceneUpdateContext& context) { +void ContainerLayer::UpdateSceneChildren( + std::shared_ptr context) { FML_DCHECK(needs_system_composite()); std::optional frame; if (child_layer_exists_below_) { frame.emplace( context, SkRRect::MakeRect(paint_bounds()), SK_ColorTRANSPARENT, - SkScalarRoundToInt(context.alphaf() * 255), "flutter::ContainerLayer"); + SkScalarRoundToInt(context->alphaf() * 255), "flutter::ContainerLayer"); frame->AddPaintLayer(this); } diff --git a/flow/layers/container_layer.h b/flow/layers/container_layer.h index 0e5b27d7083fd..11eae5f3fe123 100644 --- a/flow/layers/container_layer.h +++ b/flow/layers/container_layer.h @@ -21,7 +21,7 @@ class ContainerLayer : public Layer { void Paint(PaintContext& context) const override; #if defined(LEGACY_FUCHSIA_EMBEDDER) void CheckForChildLayerBelow(PrerollContext* context) override; - void UpdateScene(SceneUpdateContext& context) override; + void UpdateScene(std::shared_ptr context) override; #endif const std::vector>& layers() const { return layers_; } @@ -33,7 +33,7 @@ class ContainerLayer : public Layer { void PaintChildren(PaintContext& context) const; #if defined(LEGACY_FUCHSIA_EMBEDDER) - void UpdateSceneChildren(SceneUpdateContext& context); + void UpdateSceneChildren(std::shared_ptr context); #endif // Try to prepare the raster cache for a given layer. diff --git a/flow/layers/fuchsia_layer_unittests.cc b/flow/layers/fuchsia_layer_unittests.cc index df8f8e746ae00..85278b8c60af5 100644 --- a/flow/layers/fuchsia_layer_unittests.cc +++ b/flow/layers/fuchsia_layer_unittests.cc @@ -261,7 +261,7 @@ struct TestContext { std::unique_ptr mock_session_wrapper; // SceneUpdateContext. - std::unique_ptr scene_update_context; + std::shared_ptr scene_update_context; // PrerollContext. MutatorsStack unused_stack; @@ -286,7 +286,7 @@ std::unique_ptr InitTest() { std::make_unique(std::move(session_ptr)); // Init SceneUpdateContext. - context->scene_update_context = std::make_unique( + context->scene_update_context = std::make_shared( "fuchsia_layer_unittest", fuchsia::ui::views::ViewToken(), scenic::ViewRefPair::New(), *(context->mock_session_wrapper)); @@ -410,7 +410,7 @@ TEST_F(FuchsiaLayerTest, DISABLED_PhysicalShapeLayersAndChildSceneLayers) { // Create another frame to be the "real" root. Required because // UpdateScene() traversal expects there to already be a top node. - SceneUpdateContext::Frame frame(*(test_context->scene_update_context), + SceneUpdateContext::Frame frame(test_context->scene_update_context, SkRRect::MakeRect(SkRect::MakeWH(100, 100)), SK_ColorTRANSPARENT, SK_AlphaOPAQUE, "fuchsia test root"); @@ -555,7 +555,7 @@ TEST_F(FuchsiaLayerTest, DISABLED_PhysicalShapeLayersAndChildSceneLayers) { // Finally, UpdateScene(). The MockSession will check the emitted commands // against the list above. - root->UpdateScene(*(test_context->scene_update_context)); + root->UpdateScene(test_context->scene_update_context); test_context->mock_session_wrapper->Present(); @@ -626,7 +626,7 @@ TEST_F(FuchsiaLayerTest, DISABLED_OpacityAndTransformLayer) { // Create another frame to be the "real" root. Required because // UpdateScene() traversal expects there to already be a top node. - SceneUpdateContext::Frame frame(*(test_context->scene_update_context), + SceneUpdateContext::Frame frame(test_context->scene_update_context, SkRRect::MakeRect(SkRect::MakeWH(100, 100)), SK_ColorTRANSPARENT, SK_AlphaOPAQUE, "fuchsia test root"); @@ -737,7 +737,7 @@ TEST_F(FuchsiaLayerTest, DISABLED_OpacityAndTransformLayer) { // Finally, UpdateScene(). The MockSession will check the emitted // commands against the list above. - root->UpdateScene(*(test_context->scene_update_context)); + root->UpdateScene(test_context->scene_update_context); test_context->mock_session_wrapper->Present(); diff --git a/flow/layers/layer.cc b/flow/layers/layer.cc index a242f977cde29..006f5cb84e916 100644 --- a/flow/layers/layer.cc +++ b/flow/layers/layer.cc @@ -67,13 +67,13 @@ void Layer::CheckForChildLayerBelow(PrerollContext* context) { } } -void Layer::UpdateScene(SceneUpdateContext& context) { +void Layer::UpdateScene(std::shared_ptr context) { FML_DCHECK(needs_system_composite()); FML_DCHECK(child_layer_exists_below_); SceneUpdateContext::Frame frame( context, SkRRect::MakeRect(paint_bounds()), SK_ColorTRANSPARENT, - SkScalarRoundToInt(context.alphaf() * 255), "flutter::Layer"); + SkScalarRoundToInt(context->alphaf() * 255), "flutter::Layer"); frame.AddPaintLayer(this); } diff --git a/flow/layers/layer.h b/flow/layers/layer.h index eeffabacbb325..0ce351db63b2f 100644 --- a/flow/layers/layer.h +++ b/flow/layers/layer.h @@ -154,7 +154,7 @@ class Layer { #if defined(LEGACY_FUCHSIA_EMBEDDER) // Updates the system composited scene. - virtual void UpdateScene(SceneUpdateContext& context); + virtual void UpdateScene(std::shared_ptr context); virtual void CheckForChildLayerBelow(PrerollContext* context); #endif diff --git a/flow/layers/layer_tree.cc b/flow/layers/layer_tree.cc index e0ac5157fc746..d669591da1654 100644 --- a/flow/layers/layer_tree.cc +++ b/flow/layers/layer_tree.cc @@ -62,11 +62,11 @@ bool LayerTree::Preroll(CompositorContext::ScopedFrame& frame, } #if defined(LEGACY_FUCHSIA_EMBEDDER) -void LayerTree::UpdateScene(SceneUpdateContext& context) { +void LayerTree::UpdateScene(std::shared_ptr context) { TRACE_EVENT0("flutter", "LayerTree::UpdateScene"); // Reset for a new Scene. - context.Reset(); + context->Reset(); const float inv_dpr = 1.0f / device_pixel_ratio_; SceneUpdateContext::Transform transform(context, inv_dpr, inv_dpr, 1.0f); @@ -82,7 +82,7 @@ void LayerTree::UpdateScene(SceneUpdateContext& context) { if (root_layer_->needs_painting()) { frame.AddPaintLayer(root_layer_.get()); } - context.root_node().AddChild(transform.entity_node()); + context->root_node().AddChild(transform.entity_node()); } #endif diff --git a/flow/layers/layer_tree.h b/flow/layers/layer_tree.h index b9cd8d37de7c0..b59f278296381 100644 --- a/flow/layers/layer_tree.h +++ b/flow/layers/layer_tree.h @@ -32,7 +32,7 @@ class LayerTree { bool ignore_raster_cache = false); #if defined(LEGACY_FUCHSIA_EMBEDDER) - void UpdateScene(SceneUpdateContext& context); + void UpdateScene(std::shared_ptr context); #endif void Paint(CompositorContext::ScopedFrame& frame, diff --git a/flow/layers/opacity_layer.cc b/flow/layers/opacity_layer.cc index 131b1d9f253b7..9e8001d6e3283 100644 --- a/flow/layers/opacity_layer.cc +++ b/flow/layers/opacity_layer.cc @@ -85,11 +85,11 @@ void OpacityLayer::Paint(PaintContext& context) const { #if defined(LEGACY_FUCHSIA_EMBEDDER) -void OpacityLayer::UpdateScene(SceneUpdateContext& context) { - float saved_alpha = context.alphaf(); - context.set_alphaf(context.alphaf() * (alpha_ / 255.f)); +void OpacityLayer::UpdateScene(std::shared_ptr context) { + float saved_alpha = context->alphaf(); + context->set_alphaf(context->alphaf() * (alpha_ / 255.f)); ContainerLayer::UpdateScene(context); - context.set_alphaf(saved_alpha); + context->set_alphaf(saved_alpha); } #endif diff --git a/flow/layers/opacity_layer.h b/flow/layers/opacity_layer.h index ed5f0283ad356..25f1c7944a829 100644 --- a/flow/layers/opacity_layer.h +++ b/flow/layers/opacity_layer.h @@ -32,7 +32,7 @@ class OpacityLayer : public MergedContainerLayer { void Paint(PaintContext& context) const override; #if defined(LEGACY_FUCHSIA_EMBEDDER) - void UpdateScene(SceneUpdateContext& context) override; + void UpdateScene(std::shared_ptr context) override; #endif private: diff --git a/flow/layers/platform_view_layer.cc b/flow/layers/platform_view_layer.cc index 80514b5213e18..0971f93db777e 100644 --- a/flow/layers/platform_view_layer.cc +++ b/flow/layers/platform_view_layer.cc @@ -47,10 +47,11 @@ void PlatformViewLayer::Paint(PaintContext& context) const { } #if defined(LEGACY_FUCHSIA_EMBEDDER) -void PlatformViewLayer::UpdateScene(SceneUpdateContext& context) { +void PlatformViewLayer::UpdateScene( + std::shared_ptr context) { TRACE_EVENT0("flutter", "PlatformViewLayer::UpdateScene"); FML_DCHECK(needs_system_composite()); - context.UpdateView(view_id_, offset_, size_); + context->UpdateView(view_id_, offset_, size_); } #endif diff --git a/flow/layers/platform_view_layer.h b/flow/layers/platform_view_layer.h index a75c69689dabf..e9d6fac42eb23 100644 --- a/flow/layers/platform_view_layer.h +++ b/flow/layers/platform_view_layer.h @@ -19,7 +19,7 @@ class PlatformViewLayer : public Layer { void Paint(PaintContext& context) const override; #if defined(LEGACY_FUCHSIA_EMBEDDER) // Updates the system composited scene. - void UpdateScene(SceneUpdateContext& context) override; + void UpdateScene(std::shared_ptr context) override; #endif private: diff --git a/flow/layers/transform_layer.cc b/flow/layers/transform_layer.cc index 8fe5dd32e1e85..3e26e525ac637 100644 --- a/flow/layers/transform_layer.cc +++ b/flow/layers/transform_layer.cc @@ -54,7 +54,7 @@ void TransformLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { #if defined(LEGACY_FUCHSIA_EMBEDDER) -void TransformLayer::UpdateScene(SceneUpdateContext& context) { +void TransformLayer::UpdateScene(std::shared_ptr context) { TRACE_EVENT0("flutter", "TransformLayer::UpdateScene"); FML_DCHECK(needs_system_composite()); diff --git a/flow/layers/transform_layer.h b/flow/layers/transform_layer.h index 63a212f9236de..7956e3906a680 100644 --- a/flow/layers/transform_layer.h +++ b/flow/layers/transform_layer.h @@ -20,7 +20,7 @@ class TransformLayer : public ContainerLayer { void Paint(PaintContext& context) const override; #if defined(LEGACY_FUCHSIA_EMBEDDER) - void UpdateScene(SceneUpdateContext& context) override; + void UpdateScene(std::shared_ptr context) override; #endif private: diff --git a/flow/scene_update_context.cc b/flow/scene_update_context.cc index 3edd9c4d9fe26..141e2caafeb35 100644 --- a/flow/scene_update_context.cc +++ b/flow/scene_update_context.cc @@ -215,29 +215,30 @@ void SceneUpdateContext::DestroyView(int64_t view_id) { ViewHolder::Destroy(view_id); } -SceneUpdateContext::Entity::Entity(SceneUpdateContext& context) +SceneUpdateContext::Entity::Entity(std::shared_ptr context) : context_(context), - previous_entity_(context.top_entity_), - entity_node_(context.session_.get()) { - context.top_entity_ = this; + previous_entity_(context->top_entity_), + entity_node_(context->session_.get()) { + context->top_entity_ = this; } SceneUpdateContext::Entity::~Entity() { if (previous_entity_) { previous_entity_->embedder_node().AddChild(entity_node_); } else { - context_.root_node_.AddChild(entity_node_); + context_->root_node_.AddChild(entity_node_); } - FML_DCHECK(context_.top_entity_ == this); - context_.top_entity_ = previous_entity_; + FML_DCHECK(context_->top_entity_ == this); + context_->top_entity_ = previous_entity_; } -SceneUpdateContext::Transform::Transform(SceneUpdateContext& context, - const SkMatrix& transform) +SceneUpdateContext::Transform::Transform( + std::shared_ptr context, + const SkMatrix& transform) : Entity(context), - previous_scale_x_(context.top_scale_x_), - previous_scale_y_(context.top_scale_y_) { + previous_scale_x_(context->top_scale_x_), + previous_scale_y_(context->top_scale_y_) { entity_node().SetLabel("flutter::Transform"); if (!transform.isIdentity()) { // TODO(SCN-192): The perspective and shear components in the matrix @@ -255,8 +256,8 @@ SceneUpdateContext::Transform::Transform(SceneUpdateContext& context, decomposition.scale().y, // 1.f // ); - context.top_scale_x_ *= decomposition.scale().x; - context.top_scale_y_ *= decomposition.scale().y; + context->top_scale_x_ *= decomposition.scale().x; + context->top_scale_y_ *= decomposition.scale().y; entity_node().SetRotation(decomposition.rotation().x, // decomposition.rotation().y, // @@ -267,45 +268,46 @@ SceneUpdateContext::Transform::Transform(SceneUpdateContext& context, } } -SceneUpdateContext::Transform::Transform(SceneUpdateContext& context, - float scale_x, - float scale_y, - float scale_z) +SceneUpdateContext::Transform::Transform( + std::shared_ptr context, + float scale_x, + float scale_y, + float scale_z) : Entity(context), - previous_scale_x_(context.top_scale_x_), - previous_scale_y_(context.top_scale_y_) { + previous_scale_x_(context->top_scale_x_), + previous_scale_y_(context->top_scale_y_) { entity_node().SetLabel("flutter::Transform"); if (scale_x != 1.f || scale_y != 1.f || scale_z != 1.f) { entity_node().SetScale(scale_x, scale_y, scale_z); - context.top_scale_x_ *= scale_x; - context.top_scale_y_ *= scale_y; + context->top_scale_x_ *= scale_x; + context->top_scale_y_ *= scale_y; } } SceneUpdateContext::Transform::~Transform() { - context().top_scale_x_ = previous_scale_x_; - context().top_scale_y_ = previous_scale_y_; + context()->top_scale_x_ = previous_scale_x_; + context()->top_scale_y_ = previous_scale_y_; } -SceneUpdateContext::Frame::Frame(SceneUpdateContext& context, +SceneUpdateContext::Frame::Frame(std::shared_ptr context, const SkRRect& rrect, SkColor color, SkAlpha opacity, std::string label) : Entity(context), - previous_elevation_(context.top_elevation_), + previous_elevation_(context->top_elevation_), rrect_(rrect), color_(color), opacity_(opacity), - opacity_node_(context.session_.get()), + opacity_node_(context->session_.get()), paint_bounds_(SkRect::MakeEmpty()) { // Increment elevation trackers before calculating any local elevation. - // |UpdateView| can modify context.next_elevation_, which is why it is + // |UpdateView| can modify context->next_elevation_, which is why it is // neccesary to track this addtional state. - context.top_elevation_ += kScenicZElevationBetweenLayers; - context.next_elevation_ += kScenicZElevationBetweenLayers; + context->top_elevation_ += kScenicZElevationBetweenLayers; + context->next_elevation_ += kScenicZElevationBetweenLayers; - float local_elevation = context.next_elevation_ - previous_elevation_; + float local_elevation = context->next_elevation_ - previous_elevation_; entity_node().SetTranslation(0.f, 0.f, -local_elevation); entity_node().SetLabel(label); entity_node().AddChild(opacity_node_); @@ -318,11 +320,11 @@ SceneUpdateContext::Frame::Frame(SceneUpdateContext& context, } SceneUpdateContext::Frame::~Frame() { - context().top_elevation_ = previous_elevation_; + context()->top_elevation_ = previous_elevation_; // Add a part which represents the frame's geometry for clipping purposes - context().CreateFrame(entity_node(), rrect_, color_, opacity_, paint_bounds_, - std::move(paint_layers_)); + context()->CreateFrame(entity_node(), rrect_, color_, opacity_, paint_bounds_, + std::move(paint_layers_)); } void SceneUpdateContext::Frame::AddPaintLayer(Layer* layer) { @@ -331,7 +333,7 @@ void SceneUpdateContext::Frame::AddPaintLayer(Layer* layer) { paint_bounds_.join(layer->paint_bounds()); } -SceneUpdateContext::Clip::Clip(SceneUpdateContext& context, +SceneUpdateContext::Clip::Clip(std::shared_ptr context, const SkRect& shape_bounds) : Entity(context) { entity_node().SetLabel("flutter::Clip"); diff --git a/flow/scene_update_context.h b/flow/scene_update_context.h index f15c59fa7f6ea..d95513bc259b5 100644 --- a/flow/scene_update_context.h +++ b/flow/scene_update_context.h @@ -46,15 +46,15 @@ class SceneUpdateContext : public flutter::ExternalViewEmbedder { public: class Entity { public: - Entity(SceneUpdateContext& context); + Entity(std::shared_ptr context); virtual ~Entity(); - SceneUpdateContext& context() { return context_; } + std::shared_ptr context() { return context_; } scenic::EntityNode& entity_node() { return entity_node_; } virtual scenic::ContainerNode& embedder_node() { return entity_node_; } private: - SceneUpdateContext& context_; + std::shared_ptr context_; Entity* const previous_entity_; scenic::EntityNode entity_node_; @@ -62,8 +62,9 @@ class SceneUpdateContext : public flutter::ExternalViewEmbedder { class Transform : public Entity { public: - Transform(SceneUpdateContext& context, const SkMatrix& transform); - Transform(SceneUpdateContext& context, + Transform(std::shared_ptr context, + const SkMatrix& transform); + Transform(std::shared_ptr context, float scale_x, float scale_y, float scale_z); @@ -79,7 +80,7 @@ class SceneUpdateContext : public flutter::ExternalViewEmbedder { // When layer is not nullptr, the frame is associated with a layer subtree // rooted with that layer. The frame may then create a surface that will be // retained for that layer. - Frame(SceneUpdateContext& context, + Frame(std::shared_ptr context, const SkRRect& rrect, SkColor color, SkAlpha opacity, @@ -104,7 +105,8 @@ class SceneUpdateContext : public flutter::ExternalViewEmbedder { class Clip : public Entity { public: - Clip(SceneUpdateContext& context, const SkRect& shape_bounds); + Clip(std::shared_ptr context, + const SkRect& shape_bounds); ~Clip() = default; }; diff --git a/shell/platform/fuchsia/flutter/compositor_context.cc b/shell/platform/fuchsia/flutter/compositor_context.cc index 005a9cca0705b..2f2a83eba345a 100644 --- a/shell/platform/fuchsia/flutter/compositor_context.cc +++ b/shell/platform/fuchsia/flutter/compositor_context.cc @@ -23,7 +23,7 @@ class ScopedFrame final : public flutter::CompositorContext::ScopedFrame { fml::RefPtr raster_thread_merger, SessionConnection& session_connection, VulkanSurfaceProducer& surface_producer, - flutter::SceneUpdateContext& scene_update_context) + std::shared_ptr scene_update_context) : flutter::CompositorContext::ScopedFrame(context, surface_producer.gr_context(), canvas, @@ -39,7 +39,7 @@ class ScopedFrame final : public flutter::CompositorContext::ScopedFrame { private: SessionConnection& session_connection_; VulkanSurfaceProducer& surface_producer_; - flutter::SceneUpdateContext& scene_update_context_; + std::shared_ptr scene_update_context_; flutter::RasterStatus Raster(flutter::LayerTree& layer_tree, bool ignore_raster_cache) override { @@ -64,7 +64,7 @@ class ScopedFrame final : public flutter::CompositorContext::ScopedFrame { // Flush all pending session ops: create surfaces and enqueue session // Image ops for the frame's paint tasks, then Present. TRACE_EVENT0("flutter", "SessionPresent"); - frame_paint_tasks = scene_update_context_.GetPaintTasks(); + frame_paint_tasks = scene_update_context_->GetPaintTasks(); for (auto& task : frame_paint_tasks) { SkISize physical_size = SkISize::Make(layer_tree.device_pixel_ratio() * task.scale_x * @@ -142,7 +142,7 @@ class ScopedFrame final : public flutter::CompositorContext::ScopedFrame { CompositorContext::CompositorContext( SessionConnection& session_connection, VulkanSurfaceProducer& surface_producer, - flutter::SceneUpdateContext& scene_update_context) + std::shared_ptr scene_update_context) : session_connection_(session_connection), surface_producer_(surface_producer), scene_update_context_(scene_update_context) {} diff --git a/shell/platform/fuchsia/flutter/compositor_context.h b/shell/platform/fuchsia/flutter/compositor_context.h index 542e5d314fa71..4a943a499ad63 100644 --- a/shell/platform/fuchsia/flutter/compositor_context.h +++ b/shell/platform/fuchsia/flutter/compositor_context.h @@ -21,16 +21,17 @@ namespace flutter_runner { // Fuchsia. class CompositorContext final : public flutter::CompositorContext { public: - CompositorContext(SessionConnection& session_connection, - VulkanSurfaceProducer& surface_producer, - flutter::SceneUpdateContext& scene_update_context); + CompositorContext( + SessionConnection& session_connection, + VulkanSurfaceProducer& surface_producer, + std::shared_ptr scene_update_context); ~CompositorContext() override; private: SessionConnection& session_connection_; VulkanSurfaceProducer& surface_producer_; - flutter::SceneUpdateContext& scene_update_context_; + std::shared_ptr scene_update_context_; // |flutter::CompositorContext| std::unique_ptr AcquireFrame( diff --git a/shell/platform/fuchsia/flutter/engine.cc b/shell/platform/fuchsia/flutter/engine.cc index 67af712aadb64..2cf60a87b9b59 100644 --- a/shell/platform/fuchsia/flutter/engine.cc +++ b/shell/platform/fuchsia/flutter/engine.cc @@ -8,6 +8,7 @@ #include #include "../runtime/dart/utils/files.h" +#include "flow/embedded_views.h" #include "flutter/common/task_runners.h" #include "flutter/fml/make_copyable.h" #include "flutter/fml/synchronization/waitable_event.h" @@ -137,15 +138,18 @@ Engine::Engine(Delegate& delegate, surface_producer_.emplace(session_connection_->get()); #if defined(LEGACY_FUCHSIA_EMBEDDER) if (use_legacy_renderer_) { - legacy_external_view_embedder_.emplace( - thread_label_, std::move(view_token), std::move(view_ref_pair), - session_connection_.value()); + legacy_external_view_embedder_ = + std::make_shared( + thread_label_, std::move(view_token), + std::move(view_ref_pair), session_connection_.value()); } else #endif { - external_view_embedder_.emplace( - thread_label_, std::move(view_token), std::move(view_ref_pair), - session_connection_.value(), surface_producer_.value()); + external_view_embedder_ = + std::make_shared( + thread_label_, std::move(view_token), + std::move(view_ref_pair), session_connection_.value(), + surface_producer_.value()); } })); @@ -205,6 +209,7 @@ Engine::Engine(Delegate& delegate, on_update_view_callback = std::move(on_update_view_callback), on_destroy_view_callback = std::move(on_destroy_view_callback), on_create_surface_callback = std::move(on_create_surface_callback), + external_view_embedder = GetExternalViewEmbedder(), vsync_offset = product_config.get_vsync_offset(), vsync_handle = vsync_event_.get()](flutter::Shell& shell) mutable { return std::make_unique( @@ -222,6 +227,7 @@ Engine::Engine(Delegate& delegate, std::move(on_update_view_callback), std::move(on_destroy_view_callback), std::move(on_create_surface_callback), + external_view_embedder, // external view embedder std::move(vsync_offset), // vsync offset vsync_handle); }); @@ -238,7 +244,7 @@ Engine::Engine(Delegate& delegate, auto compositor_context = std::make_unique( session_connection_.value(), surface_producer_.value(), - legacy_external_view_embedder_.value()); + legacy_external_view_embedder_); return std::make_unique( shell, std::move(compositor_context)); } else { @@ -577,22 +583,28 @@ void Engine::DestroyView(int64_t view_id) { } std::unique_ptr Engine::CreateSurface() { - flutter::ExternalViewEmbedder* external_view_embedder = nullptr; + return std::make_unique(thread_label_, GetExternalViewEmbedder(), + surface_producer_->gr_context()); +} + +std::shared_ptr +Engine::GetExternalViewEmbedder() { + std::shared_ptr external_view_embedder = + nullptr; #if defined(LEGACY_FUCHSIA_EMBEDDER) if (use_legacy_renderer_) { FML_CHECK(legacy_external_view_embedder_); - external_view_embedder = &legacy_external_view_embedder_.value(); + external_view_embedder = legacy_external_view_embedder_; } else #endif { FML_CHECK(external_view_embedder_); - external_view_embedder = &external_view_embedder_.value(); + external_view_embedder = external_view_embedder_; } FML_CHECK(external_view_embedder); - return std::make_unique(thread_label_, external_view_embedder, - surface_producer_->gr_context()); + return external_view_embedder; } #if !defined(DART_PRODUCT) diff --git a/shell/platform/fuchsia/flutter/engine.h b/shell/platform/fuchsia/flutter/engine.h index 4fc29e7cfac10..a1335c59c78e5 100644 --- a/shell/platform/fuchsia/flutter/engine.h +++ b/shell/platform/fuchsia/flutter/engine.h @@ -16,6 +16,7 @@ #include #include +#include "flow/embedded_views.h" #include "flutter/flow/surface.h" #include "flutter/fml/macros.h" #include "flutter/shell/common/shell.h" @@ -71,9 +72,9 @@ class Engine final { std::optional session_connection_; std::optional surface_producer_; - std::optional external_view_embedder_; + std::shared_ptr external_view_embedder_; #if defined(LEGACY_FUCHSIA_EMBEDDER) - std::optional legacy_external_view_embedder_; + std::shared_ptr legacy_external_view_embedder_; #endif std::unique_ptr isolate_configurator_; @@ -99,6 +100,7 @@ class Engine final { void CreateView(int64_t view_id, bool hit_testable, bool focusable); void UpdateView(int64_t view_id, bool hit_testable, bool focusable); void DestroyView(int64_t view_id); + std::shared_ptr GetExternalViewEmbedder(); std::unique_ptr CreateSurface(); diff --git a/shell/platform/fuchsia/flutter/platform_view.cc b/shell/platform/fuchsia/flutter/platform_view.cc index db227ffd336de..fa7e9a77c9357 100644 --- a/shell/platform/fuchsia/flutter/platform_view.cc +++ b/shell/platform/fuchsia/flutter/platform_view.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "flow/embedded_views.h" #define RAPIDJSON_HAS_STDSTRING 1 #include "platform_view.h" @@ -66,6 +67,7 @@ PlatformView::PlatformView( OnUpdateView on_update_view_callback, OnDestroyView on_destroy_view_callback, OnCreateSurface on_create_surface_callback, + std::shared_ptr external_view_embedder, fml::TimeDelta vsync_offset, zx_handle_t vsync_event_handle) : flutter::PlatformView(delegate, std::move(task_runners)), @@ -80,6 +82,7 @@ PlatformView::PlatformView( on_update_view_callback_(std::move(on_update_view_callback)), on_destroy_view_callback_(std::move(on_destroy_view_callback)), on_create_surface_callback_(std::move(on_create_surface_callback)), + external_view_embedder_(external_view_embedder), ime_client_(this), vsync_offset_(std::move(vsync_offset)), vsync_event_handle_(vsync_event_handle) { diff --git a/shell/platform/fuchsia/flutter/platform_view.h b/shell/platform/fuchsia/flutter/platform_view.h index a888298f9ef38..9f29b3397bf09 100644 --- a/shell/platform/fuchsia/flutter/platform_view.h +++ b/shell/platform/fuchsia/flutter/platform_view.h @@ -14,11 +14,13 @@ #include #include +#include "flow/embedded_views.h" #include "flutter/fml/macros.h" #include "flutter/fml/time/time_delta.h" #include "flutter/shell/common/platform_view.h" #include "accessibility_bridge.h" +#include "shell/platform/fuchsia/flutter/fuchsia_external_view_embedder.h" namespace flutter_runner { @@ -61,6 +63,7 @@ class PlatformView final : public flutter::PlatformView, OnUpdateView on_update_view_callback, OnDestroyView on_destroy_view_callback, OnCreateSurface on_create_surface_callback, + std::shared_ptr view_embedder, fml::TimeDelta vsync_offset, zx_handle_t vsync_event_handle); @@ -169,6 +172,7 @@ class PlatformView final : public flutter::PlatformView, OnUpdateView on_update_view_callback_; OnDestroyView on_destroy_view_callback_; OnCreateSurface on_create_surface_callback_; + std::shared_ptr external_view_embedder_; int current_text_input_client_ = 0; fidl::Binding ime_client_; diff --git a/shell/platform/fuchsia/flutter/platform_view_unittest.cc b/shell/platform/fuchsia/flutter/platform_view_unittest.cc index 63f010ed663c6..38f771ce257b9 100644 --- a/shell/platform/fuchsia/flutter/platform_view_unittest.cc +++ b/shell/platform/fuchsia/flutter/platform_view_unittest.cc @@ -184,10 +184,11 @@ TEST_F(PlatformViewTests, CreateSurfaceTest) { // Test create surface callback function. sk_sp gr_context = GrDirectContext::MakeMock(nullptr, GrContextOptions()); - MockExternalViewEmbedder view_embedder; + std::shared_ptr view_embedder = + std::make_shared(); auto CreateSurfaceCallback = [&view_embedder, gr_context]() { return std::make_unique( - "PlatformViewTest", &view_embedder, gr_context.get()); + "PlatformViewTest", view_embedder, gr_context.get()); }; auto platform_view = flutter_runner::PlatformView( @@ -205,6 +206,7 @@ TEST_F(PlatformViewTests, CreateSurfaceTest) { nullptr, // on_update_view_callback, nullptr, // on_destroy_view_callback, CreateSurfaceCallback, // on_create_surface_callback, + view_embedder, // external_view_embedder, fml::TimeDelta::Zero(), // vsync_offset ZX_HANDLE_INVALID // vsync_event_handle ); @@ -213,7 +215,7 @@ TEST_F(PlatformViewTests, CreateSurfaceTest) { RunLoopUntilIdle(); EXPECT_EQ(gr_context.get(), delegate.surface()->GetContext()); - EXPECT_EQ(&view_embedder, delegate.surface()->GetExternalViewEmbedder()); + EXPECT_EQ(view_embedder.get(), delegate.surface()->GetExternalViewEmbedder()); } // This test makes sure that the PlatformView correctly registers Scenic @@ -248,6 +250,7 @@ TEST_F(PlatformViewTests, SetViewportMetrics) { nullptr, // on_update_view_callback, nullptr, // on_destroy_view_callback, nullptr, // on_create_surface_callback, + nullptr, // external_view_embedder, fml::TimeDelta::Zero(), // vsync_offset ZX_HANDLE_INVALID // vsync_event_handle ); @@ -380,6 +383,7 @@ TEST_F(PlatformViewTests, ChangesAccessibilitySettings) { nullptr, // on_update_view_callback, nullptr, // on_destroy_view_callback, nullptr, // on_create_surface_callback, + nullptr, // external_view_embedder, fml::TimeDelta::Zero(), // vsync_offset ZX_HANDLE_INVALID // vsync_event_handle ); @@ -430,6 +434,7 @@ TEST_F(PlatformViewTests, EnableWireframeTest) { nullptr, // on_update_view_callback, nullptr, // on_destroy_view_callback, nullptr, // on_create_surface_callback, + nullptr, // external_view_embedder, fml::TimeDelta::Zero(), // vsync_offset ZX_HANDLE_INVALID // vsync_event_handle ); @@ -491,6 +496,7 @@ TEST_F(PlatformViewTests, CreateViewTest) { nullptr, // on_update_view_callback, nullptr, // on_destroy_view_callback, nullptr, // on_create_surface_callback, + nullptr, // external_view_embedder, fml::TimeDelta::Zero(), // vsync_offset ZX_HANDLE_INVALID // vsync_event_handle ); @@ -554,6 +560,7 @@ TEST_F(PlatformViewTests, UpdateViewTest) { UpdateViewCallback, // on_update_view_callback, nullptr, // on_destroy_view_callback, nullptr, // on_create_surface_callback, + nullptr, // external_view_embedder, fml::TimeDelta::Zero(), // vsync_offset ZX_HANDLE_INVALID // vsync_event_handle ); @@ -617,6 +624,7 @@ TEST_F(PlatformViewTests, DestroyViewTest) { nullptr, // on_update_view_callback, DestroyViewCallback, // on_destroy_view_callback, nullptr, // on_create_surface_callback, + nullptr, // external_view_embedder, fml::TimeDelta::Zero(), // vsync_offset ZX_HANDLE_INVALID // vsync_event_handle ); @@ -677,6 +685,7 @@ TEST_F(PlatformViewTests, ViewEventsTest) { nullptr, // on_update_view_callback, nullptr, // on_destroy_view_callback, nullptr, // on_create_surface_callback, + nullptr, // external_view_embedder, fml::TimeDelta::Zero(), // vsync_offset ZX_HANDLE_INVALID // vsync_event_handle ); @@ -759,6 +768,7 @@ TEST_F(PlatformViewTests, RequestFocusTest) { nullptr, // on_update_view_callback, nullptr, // on_destroy_view_callback, nullptr, // on_create_surface_callback, + nullptr, // external_view_embedder, fml::TimeDelta::Zero(), // vsync_offset ZX_HANDLE_INVALID // vsync_event_handle ); @@ -835,6 +845,7 @@ TEST_F(PlatformViewTests, RequestFocusFailTest) { nullptr, // on_update_view_callback, nullptr, // on_destroy_view_callback, nullptr, // on_create_surface_callback, + nullptr, // external_view_embedder, fml::TimeDelta::Zero(), // vsync_offset ZX_HANDLE_INVALID // vsync_event_handle ); diff --git a/shell/platform/fuchsia/flutter/surface.cc b/shell/platform/fuchsia/flutter/surface.cc index 61f2d25878598..27753721bcc1c 100644 --- a/shell/platform/fuchsia/flutter/surface.cc +++ b/shell/platform/fuchsia/flutter/surface.cc @@ -14,7 +14,7 @@ namespace flutter_runner { Surface::Surface(std::string debug_label, - flutter::ExternalViewEmbedder* view_embedder, + std::shared_ptr view_embedder, GrDirectContext* gr_context) : debug_label_(std::move(debug_label)), view_embedder_(view_embedder), @@ -53,7 +53,7 @@ SkMatrix Surface::GetRootTransformation() const { // |flutter::GetViewEmbedder| flutter::ExternalViewEmbedder* Surface::GetExternalViewEmbedder() { - return view_embedder_; + return view_embedder_.get(); } } // namespace flutter_runner diff --git a/shell/platform/fuchsia/flutter/surface.h b/shell/platform/fuchsia/flutter/surface.h index 96222c0f2d326..bc95d88cc10d4 100644 --- a/shell/platform/fuchsia/flutter/surface.h +++ b/shell/platform/fuchsia/flutter/surface.h @@ -16,14 +16,14 @@ namespace flutter_runner { class Surface final : public flutter::Surface { public: Surface(std::string debug_label, - flutter::ExternalViewEmbedder* view_embedder, + std::shared_ptr view_embedder, GrDirectContext* gr_context); ~Surface() override; private: const std::string debug_label_; - flutter::ExternalViewEmbedder* view_embedder_; + std::shared_ptr view_embedder_; GrDirectContext* gr_context_; // |flutter::Surface| From 7037fa98c3c76b996e7bcce9a4a97038c645f1e0 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Tue, 20 Oct 2020 12:44:18 -0700 Subject: [PATCH 2/2] wait for the external view embedder to be initialized before creating shell --- shell/platform/fuchsia/flutter/engine.cc | 8 ++++++-- shell/platform/fuchsia/flutter/platform_view.h | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/shell/platform/fuchsia/flutter/engine.cc b/shell/platform/fuchsia/flutter/engine.cc index 2cf60a87b9b59..822caa9ddb4c6 100644 --- a/shell/platform/fuchsia/flutter/engine.cc +++ b/shell/platform/fuchsia/flutter/engine.cc @@ -123,14 +123,16 @@ Engine::Engine(Delegate& delegate, }; // Set up the session connection and other Scenic helpers on the raster - // thread. + // thread. We also need to wait for the external view embedder to be setup + // before creating the shell. + fml::AutoResetWaitableEvent view_embedder_latch; task_runners.GetRasterTaskRunner()->PostTask(fml::MakeCopyable( [this, session = std::move(session), session_error_callback = std::move(session_error_callback), view_token = std::move(view_token), view_ref_pair = std::move(view_ref_pair), max_frames_in_flight = product_config.get_max_frames_in_flight(), - vsync_handle = vsync_event_.get()]() mutable { + vsync_handle = vsync_event_.get(), &view_embedder_latch]() mutable { session_connection_.emplace( thread_label_, std::move(session), std::move(session_error_callback), [](auto) {}, vsync_handle, @@ -151,7 +153,9 @@ Engine::Engine(Delegate& delegate, std::move(view_ref_pair), session_connection_.value(), surface_producer_.value()); } + view_embedder_latch.Signal(); })); + view_embedder_latch.Wait(); // Grab the parent environment services. The platform view may want to // access some of these services. diff --git a/shell/platform/fuchsia/flutter/platform_view.h b/shell/platform/fuchsia/flutter/platform_view.h index 9f29b3397bf09..092633f1dde0a 100644 --- a/shell/platform/fuchsia/flutter/platform_view.h +++ b/shell/platform/fuchsia/flutter/platform_view.h @@ -18,9 +18,9 @@ #include "flutter/fml/macros.h" #include "flutter/fml/time/time_delta.h" #include "flutter/shell/common/platform_view.h" +#include "flutter/shell/platform/fuchsia/flutter/fuchsia_external_view_embedder.h" #include "accessibility_bridge.h" -#include "shell/platform/fuchsia/flutter/fuchsia_external_view_embedder.h" namespace flutter_runner {