From 324cc1cd54e9bdce2e6b102a72076880024d4f55 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Thu, 2 Nov 2023 14:01:03 -0700 Subject: [PATCH 01/17] Cleanup impl --- flow/embedded_views.cc | 14 +-- flow/embedded_views.h | 10 +- flow/testing/mock_embedder.cc | 7 +- flow/testing/mock_embedder.h | 7 +- shell/common/rasterizer.cc | 13 ++- shell/common/rasterizer_unittests.cc | 93 ++++++++++++------- .../shell_test_external_view_embedder.cc | 11 ++- .../shell_test_external_view_embedder.h | 15 +-- .../external_view_embedder.cc | 24 +++-- .../external_view_embedder.h | 13 ++- .../external_view_embedder_unittests.cc | 74 ++++++++------- .../darwin/ios/ios_external_view_embedder.h | 13 ++- .../darwin/ios/ios_external_view_embedder.mm | 22 +++-- .../embedder_external_view_embedder.cc | 15 ++- .../embedder_external_view_embedder.h | 13 ++- .../fuchsia/flutter/external_view_embedder.cc | 4 +- .../fuchsia/flutter/external_view_embedder.h | 6 +- .../tests/external_view_embedder_unittests.cc | 10 +- .../flutter/tests/platform_view_unittest.cc | 6 +- shell/testing/tester_main.cc | 7 +- 20 files changed, 232 insertions(+), 145 deletions(-) diff --git a/flow/embedded_views.cc b/flow/embedded_views.cc index 086882b76adf4..054bbe8cee953 100644 --- a/flow/embedded_views.cc +++ b/flow/embedded_views.cc @@ -42,13 +42,19 @@ bool DisplayListEmbedderViewSlice::recording_ended() { return builder_ == nullptr; } -void ExternalViewEmbedder::SubmitFrame( +void ExternalViewEmbedder::SubmitView( GrDirectContext* context, const std::shared_ptr& aiks_context, std::unique_ptr frame) { frame->Submit(); } +bool ExternalViewEmbedder::SupportsDynamicThreadMerging() { + return false; +} + +void ExternalViewEmbedder::Teardown() {} + void MutatorsStack::PushClipRect(const SkRect& rect) { std::shared_ptr element = std::make_shared(rect); vector_.push_back(element); @@ -112,10 +118,4 @@ const std::vector>::const_iterator MutatorsStack::End() return vector_.end(); } -bool ExternalViewEmbedder::SupportsDynamicThreadMerging() { - return false; -} - -void ExternalViewEmbedder::Teardown() {} - } // namespace flutter diff --git a/flow/embedded_views.h b/flow/embedded_views.h index 6985c37e5b8c0..36e1d5e0ac0e8 100644 --- a/flow/embedded_views.h +++ b/flow/embedded_views.h @@ -379,7 +379,7 @@ class ExternalViewEmbedder { // from the on-screen render target. virtual DlCanvas* GetRootCanvas() = 0; - // Call this in-lieu of |SubmitFrame| to clear pre-roll state and + // Call this in-lieu of |SubmitView| to clear pre-roll state and // sets the stage for the next pre-roll. virtual void CancelFrame() = 0; @@ -388,9 +388,7 @@ class ExternalViewEmbedder { // The `raster_thread_merger` will be null if |SupportsDynamicThreadMerging| // returns false. virtual void BeginFrame( - SkISize frame_size, GrDirectContext* context, - double device_pixel_ratio, fml::RefPtr raster_thread_merger) = 0; virtual void PrerollCompositeEmbeddedView( @@ -409,12 +407,16 @@ class ExternalViewEmbedder { // Must be called on the UI thread. virtual DlCanvas* CompositeEmbeddedView(int64_t view_id) = 0; + virtual void PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) = 0; + // Implementers must submit the frame by calling frame.Submit(). // // This method can mutate the root Skia canvas before submitting the frame. // // It can also allocate frames for overlay surfaces to compose hybrid views. - virtual void SubmitFrame( + virtual void SubmitView( GrDirectContext* context, const std::shared_ptr& aiks_context, std::unique_ptr frame); diff --git a/flow/testing/mock_embedder.cc b/flow/testing/mock_embedder.cc index ae41675b6f771..c0234bc16478f 100644 --- a/flow/testing/mock_embedder.cc +++ b/flow/testing/mock_embedder.cc @@ -25,11 +25,14 @@ void MockViewEmbedder::CancelFrame() {} // |ExternalViewEmbedder| void MockViewEmbedder::BeginFrame( - SkISize frame_size, GrDirectContext* context, - double device_pixel_ratio, fml::RefPtr raster_thread_merger) {} +// |ExternalViewEmbedder| +void MockViewEmbedder::PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) {} + // |ExternalViewEmbedder| void MockViewEmbedder::PrerollCompositeEmbeddedView( int64_t view_id, diff --git a/flow/testing/mock_embedder.h b/flow/testing/mock_embedder.h index 164d7baff79e3..12920f6c0df02 100644 --- a/flow/testing/mock_embedder.h +++ b/flow/testing/mock_embedder.h @@ -26,11 +26,14 @@ class MockViewEmbedder : public ExternalViewEmbedder { // |ExternalViewEmbedder| void BeginFrame( - SkISize frame_size, GrDirectContext* context, - double device_pixel_ratio, fml::RefPtr raster_thread_merger) override; + // |ExternalViewEmbedder| + void PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) override; + // |ExternalViewEmbedder| void PrerollCompositeEmbeddedView( int64_t view_id, diff --git a/shell/common/rasterizer.cc b/shell/common/rasterizer.cc index 523bf53d350b6..6a0e95d2f7b10 100644 --- a/shell/common/rasterizer.cc +++ b/shell/common/rasterizer.cc @@ -595,11 +595,8 @@ std::unique_ptr Rasterizer::DrawToSurfacesUnsafe( if (external_view_embedder_) { FML_DCHECK(!external_view_embedder_->GetUsedThisFrame()); external_view_embedder_->SetUsedThisFrame(true); - external_view_embedder_->BeginFrame( - // TODO(dkwingsmt): Add all views here. - // See https://github.com/flutter/flutter/issues/135530, item 4. - tasks.front()->layer_tree->frame_size(), surface_->GetContext(), - tasks.front()->device_pixel_ratio, raster_thread_merger_); + external_view_embedder_->BeginFrame(surface_->GetContext(), + raster_thread_merger_); } std::optional presentation_time = std::nullopt; @@ -666,6 +663,8 @@ DrawSurfaceStatus Rasterizer::DrawToSurfaceUnsafe( DlCanvas* embedder_root_canvas = nullptr; if (external_view_embedder_) { + external_view_embedder_->PrepareView(view_id, layer_tree.frame_size(), + device_pixel_ratio); // TODO(dkwingsmt): Add view ID here. embedder_root_canvas = external_view_embedder_->GetRootCanvas(); } @@ -706,7 +705,7 @@ DrawSurfaceStatus Rasterizer::DrawToSurfaceUnsafe( // for accurate performance metrics. if (frame->framebuffer_info().supports_partial_repaint && !layer_tree.is_leaf_layer_tracing_enabled()) { - // Disable partial repaint if external_view_embedder_ SubmitFrame is + // Disable partial repaint if external_view_embedder_ SubmitView is // involved - ExternalViewEmbedder unconditionally clears the entire // surface and also partial repaint with platform view present is // something that still need to be figured out. @@ -752,7 +751,7 @@ DrawSurfaceStatus Rasterizer::DrawToSurfaceUnsafe( if (external_view_embedder_ && (!raster_thread_merger_ || raster_thread_merger_->IsMerged())) { FML_DCHECK(!frame->IsSubmitted()); - external_view_embedder_->SubmitFrame( + external_view_embedder_->SubmitView( surface_->GetContext(), surface_->GetAiksContext(), std::move(frame)); } else { frame->Submit(); diff --git a/shell/common/rasterizer_unittests.cc b/shell/common/rasterizer_unittests.cc index 1e21d0d8f1ecb..3e8e199e8c810 100644 --- a/shell/common/rasterizer_unittests.cc +++ b/shell/common/rasterizer_unittests.cc @@ -91,11 +91,15 @@ class MockExternalViewEmbedder : public ExternalViewEmbedder { MOCK_METHOD(void, CancelFrame, (), (override)); MOCK_METHOD(void, BeginFrame, - (SkISize frame_size, - GrDirectContext* context, - double device_pixel_ratio, + (GrDirectContext * context, fml::RefPtr raster_thread_merger), (override)); + MOCK_METHOD(void, + PrepareView, + (int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio), + (override)); MOCK_METHOD(void, PrerollCompositeEmbeddedView, (int64_t view_id, std::unique_ptr params), @@ -106,7 +110,7 @@ class MockExternalViewEmbedder : public ExternalViewEmbedder { (override)); MOCK_METHOD(DlCanvas*, CompositeEmbeddedView, (int64_t view_id), (override)); MOCK_METHOD(void, - SubmitFrame, + SubmitView, (GrDirectContext * context, const std::shared_ptr& aiks_context, std::unique_ptr frame), @@ -199,7 +203,8 @@ TEST(RasterizerTest, framebuffer_info.supports_readback = true; auto surface_frame = std::make_unique( - /*surface=*/nullptr, framebuffer_info, + /*surface=*/ + nullptr, framebuffer_info, /*submit_callback=*/[](const SurfaceFrame&, DlCanvas*) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()).WillOnce(Return(true)); @@ -209,12 +214,15 @@ TEST(RasterizerTest, .WillOnce(Return(ByMove(std::make_unique(true)))); EXPECT_CALL(*external_view_embedder, - BeginFrame(/*frame_size=*/SkISize(), /*context=*/nullptr, - /*device_pixel_ratio=*/2.0, + BeginFrame(/*context=*/nullptr, /*raster_thread_merger=*/ fml::RefPtr(nullptr))) .Times(1); - EXPECT_CALL(*external_view_embedder, SubmitFrame).Times(1); + EXPECT_CALL(*external_view_embedder, + PrepareView(/*view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/2.0)) + .Times(1); + EXPECT_CALL(*external_view_embedder, SubmitView).Times(1); EXPECT_CALL( *external_view_embedder, EndFrame(/*should_resubmit_frame=*/false, @@ -271,7 +279,8 @@ TEST( SurfaceFrame::FramebufferInfo framebuffer_info; framebuffer_info.supports_readback = true; auto surface_frame = std::make_unique( - /*surface=*/nullptr, framebuffer_info, + /*surface=*/ + nullptr, framebuffer_info, /*submit_callback=*/[](const SurfaceFrame&, DlCanvas*) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()).WillOnce(Return(true)); @@ -280,12 +289,14 @@ TEST( EXPECT_CALL(*surface, MakeRenderContextCurrent()) .WillOnce(Return(ByMove(std::make_unique(true)))); + EXPECT_CALL(*external_view_embedder, BeginFrame(/*context=*/nullptr, + /*raster_thread_merger=*/_)) + .Times(1); EXPECT_CALL(*external_view_embedder, - BeginFrame(/*frame_size=*/SkISize(), /*context=*/nullptr, - /*device_pixel_ratio=*/2.0, - /*raster_thread_merger=*/_)) + PrepareView(/*view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/2.0)) .Times(1); - EXPECT_CALL(*external_view_embedder, SubmitFrame).Times(0); + EXPECT_CALL(*external_view_embedder, SubmitView).Times(0); EXPECT_CALL(*external_view_embedder, EndFrame(/*should_resubmit_frame=*/false, /*raster_thread_merger=*/_)) .Times(1); @@ -343,7 +354,8 @@ TEST( framebuffer_info.supports_readback = true; auto surface_frame = std::make_unique( - /*surface=*/nullptr, framebuffer_info, + /*surface=*/ + nullptr, framebuffer_info, /*submit_callback=*/[](const SurfaceFrame&, DlCanvas*) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()).WillOnce(Return(true)); @@ -354,12 +366,14 @@ TEST( EXPECT_CALL(*external_view_embedder, SupportsDynamicThreadMerging) .WillRepeatedly(Return(true)); + EXPECT_CALL(*external_view_embedder, BeginFrame(/*context=*/nullptr, + /*raster_thread_merger=*/_)) + .Times(1); EXPECT_CALL(*external_view_embedder, - BeginFrame(/*frame_size=*/SkISize(), /*context=*/nullptr, - /*device_pixel_ratio=*/2.0, - /*raster_thread_merger=*/_)) + PrepareView(/*view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/2.0)) .Times(1); - EXPECT_CALL(*external_view_embedder, SubmitFrame).Times(1); + EXPECT_CALL(*external_view_embedder, SubmitView).Times(1); EXPECT_CALL(*external_view_embedder, EndFrame(/*should_resubmit_frame=*/false, /*raster_thread_merger=*/_)) .Times(1); @@ -412,11 +426,13 @@ TEST(RasterizerTest, framebuffer_info.supports_readback = true; auto surface_frame1 = std::make_unique( - /*surface=*/nullptr, framebuffer_info, + /*surface=*/ + nullptr, framebuffer_info, /*submit_callback=*/[](const SurfaceFrame&, DlCanvas*) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); auto surface_frame2 = std::make_unique( - /*surface=*/nullptr, framebuffer_info, + /*surface=*/ + nullptr, framebuffer_info, /*submit_callback=*/[](const SurfaceFrame&, DlCanvas*) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()) @@ -430,12 +446,14 @@ TEST(RasterizerTest, EXPECT_CALL(*external_view_embedder, SupportsDynamicThreadMerging) .WillRepeatedly(Return(true)); + EXPECT_CALL(*external_view_embedder, BeginFrame(/*context=*/nullptr, + /*raster_thread_merger=*/_)) + .Times(2); EXPECT_CALL(*external_view_embedder, - BeginFrame(/*frame_size=*/SkISize(), /*context=*/nullptr, - /*device_pixel_ratio=*/2.0, - /*raster_thread_merger=*/_)) + PrepareView(/*view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/2.0)) .Times(2); - EXPECT_CALL(*external_view_embedder, SubmitFrame).Times(2); + EXPECT_CALL(*external_view_embedder, SubmitView).Times(2); EXPECT_CALL(*external_view_embedder, EndFrame(/*should_resubmit_frame=*/false, /*raster_thread_merger=*/_)) .Times(2); @@ -453,12 +471,12 @@ TEST(RasterizerTest, pipeline->Produce().Complete(std::move(layer_tree_item)); EXPECT_TRUE(result.success); - // The Draw() will respectively call BeginFrame(), SubmitFrame() and + // The Draw() will respectively call BeginFrame(), SubmitView() and // EndFrame() one time. ON_CALL(delegate, ShouldDiscardLayerTree).WillByDefault(Return(false)); rasterizer->Draw(pipeline); - // The DrawLastLayerTrees() will respectively call BeginFrame(), SubmitFrame() + // The DrawLastLayerTrees() will respectively call BeginFrame(), SubmitView() // and EndFrame() one more time, totally 2 times. rasterizer->DrawLastLayerTrees(CreateFinishedBuildRecorder()); } @@ -540,10 +558,12 @@ TEST(RasterizerTest, externalViewEmbedderDoesntEndFrameWhenNotUsedThisFrame) { rasterizer->SetExternalViewEmbedder(external_view_embedder); rasterizer->Setup(std::move(surface)); + EXPECT_CALL(*external_view_embedder, BeginFrame(/*context=*/nullptr, + /*raster_thread_merger=*/_)) + .Times(0); EXPECT_CALL(*external_view_embedder, - BeginFrame(/*frame_size=*/SkISize(), /*context=*/nullptr, - /*device_pixel_ratio=*/2.0, - /*raster_thread_merger=*/_)) + PrepareView(/*view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/2.0)) .Times(0); EXPECT_CALL( *external_view_embedder, @@ -645,7 +665,8 @@ TEST(RasterizerTest, SurfaceFrame::FramebufferInfo framebuffer_info; framebuffer_info.supports_readback = true; auto surface_frame = std::make_unique( - /*surface=*/nullptr, /*framebuffer_info=*/framebuffer_info, + /*surface=*/ + nullptr, /*framebuffer_info=*/framebuffer_info, /*submit_callback=*/[](const SurfaceFrame&, DlCanvas*) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()).WillOnce(Return(true)); @@ -704,7 +725,8 @@ TEST( framebuffer_info.supports_readback = true; auto surface_frame = std::make_unique( - /*surface=*/nullptr, /*framebuffer_info=*/framebuffer_info, + /*surface=*/ + nullptr, /*framebuffer_info=*/framebuffer_info, /*submit_callback=*/[](const SurfaceFrame&, DlCanvas*) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()).WillOnce(Return(true)); @@ -764,7 +786,8 @@ TEST( framebuffer_info.supports_readback = true; auto surface_frame = std::make_unique( - /*surface=*/nullptr, /*framebuffer_info=*/framebuffer_info, + /*surface=*/ + nullptr, /*framebuffer_info=*/framebuffer_info, /*submit_callback=*/[](const SurfaceFrame&, DlCanvas*) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()).WillOnce(Return(false)); @@ -823,7 +846,8 @@ TEST( framebuffer_info.supports_readback = true; auto surface_frame = std::make_unique( - /*surface=*/nullptr, /*framebuffer_info=*/framebuffer_info, + /*surface=*/ + nullptr, /*framebuffer_info=*/framebuffer_info, /*submit_callback=*/[](const SurfaceFrame&, DlCanvas*) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()).WillOnce(Return(false)); @@ -945,7 +969,8 @@ TEST(RasterizerTest, SurfaceFrame::FramebufferInfo framebuffer_info; framebuffer_info.supports_readback = true; return std::make_unique( - /*surface=*/nullptr, framebuffer_info, + /*surface=*/ + nullptr, framebuffer_info, /*submit_callback=*/ [](const SurfaceFrame& frame, DlCanvas*) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); diff --git a/shell/common/shell_test_external_view_embedder.cc b/shell/common/shell_test_external_view_embedder.cc index 22b9bfe13554b..98fb50a174450 100644 --- a/shell/common/shell_test_external_view_embedder.cc +++ b/shell/common/shell_test_external_view_embedder.cc @@ -41,10 +41,13 @@ void ShellTestExternalViewEmbedder::CancelFrame() {} // |ExternalViewEmbedder| void ShellTestExternalViewEmbedder::BeginFrame( - SkISize frame_size, GrDirectContext* context, - double device_pixel_ratio, - fml::RefPtr raster_thread_merger) { + fml::RefPtr raster_thread_merger) {} + +// |ExternalViewEmbedder| +void ShellTestExternalViewEmbedder::PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) { visited_platform_views_.clear(); mutators_stacks_.clear(); current_composition_params_.clear(); @@ -89,7 +92,7 @@ DlCanvas* ShellTestExternalViewEmbedder::CompositeEmbeddedView( } // |ExternalViewEmbedder| -void ShellTestExternalViewEmbedder::SubmitFrame( +void ShellTestExternalViewEmbedder::SubmitView( GrDirectContext* context, const std::shared_ptr& aiks_context, std::unique_ptr frame) { diff --git a/shell/common/shell_test_external_view_embedder.h b/shell/common/shell_test_external_view_embedder.h index b2e8c48d0ccf0..064e8c95cbb2e 100644 --- a/shell/common/shell_test_external_view_embedder.h +++ b/shell/common/shell_test_external_view_embedder.h @@ -28,7 +28,7 @@ class ShellTestExternalViewEmbedder final : public ExternalViewEmbedder { // returns the new `post_preroll_result`. void UpdatePostPrerollResult(PostPrerollResult post_preroll_result); - // Gets the number of times the SubmitFrame method has been called in + // Gets the number of times the SubmitView method has been called in // the external view embedder. int GetSubmittedFrameCount(); @@ -47,11 +47,14 @@ class ShellTestExternalViewEmbedder final : public ExternalViewEmbedder { // |ExternalViewEmbedder| void BeginFrame( - SkISize frame_size, GrDirectContext* context, - double device_pixel_ratio, fml::RefPtr raster_thread_merger) override; + // |ExternalViewEmbedder| + void PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) override; + // |ExternalViewEmbedder| void PrerollCompositeEmbeddedView( int64_t view_id, @@ -73,9 +76,9 @@ class ShellTestExternalViewEmbedder final : public ExternalViewEmbedder { const SkRect& filter_rect) override; // |ExternalViewEmbedder| - void SubmitFrame(GrDirectContext* context, - const std::shared_ptr& aiks_context, - std::unique_ptr frame) override; + void SubmitView(GrDirectContext* context, + const std::shared_ptr& aiks_context, + std::unique_ptr frame) override; // |ExternalViewEmbedder| void EndFrame( diff --git a/shell/platform/android/external_view_embedder/external_view_embedder.cc b/shell/platform/android/external_view_embedder/external_view_embedder.cc index a0e516e4c10a2..5ca5fa79b8b25 100644 --- a/shell/platform/android/external_view_embedder/external_view_embedder.cc +++ b/shell/platform/android/external_view_embedder/external_view_embedder.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h" +#include "flutter/common/constants.h" #include "flutter/fml/synchronization/waitable_event.h" #include "flutter/fml/trace_event.h" @@ -62,11 +63,11 @@ SkRect AndroidExternalViewEmbedder::GetViewRect(int64_t view_id) const { } // |ExternalViewEmbedder| -void AndroidExternalViewEmbedder::SubmitFrame( +void AndroidExternalViewEmbedder::SubmitView( GrDirectContext* context, const std::shared_ptr& aiks_context, std::unique_ptr frame) { - TRACE_EVENT0("flutter", "AndroidExternalViewEmbedder::SubmitFrame"); + TRACE_EVENT0("flutter", "AndroidExternalViewEmbedder::SubmitView"); if (!FrameHasPlatformLayers()) { frame->Submit(); @@ -257,10 +258,21 @@ void AndroidExternalViewEmbedder::Reset() { // |ExternalViewEmbedder| void AndroidExternalViewEmbedder::BeginFrame( - SkISize frame_size, GrDirectContext* context, - double device_pixel_ratio, fml::RefPtr raster_thread_merger) { + // JNI method must be called on the platform thread. + if (raster_thread_merger->IsOnPlatformThread()) { + jni_facade_->FlutterViewBeginFrame(); + } +} + +// |ExternalViewEmbedder| +void AndroidExternalViewEmbedder::PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) { + // TODO(dkwingsmt): This class only supports rendering into the implicit view. + // Properly support multi-view in the future. + FML_DCHECK(native_view_id == kFlutterImplicitViewId); Reset(); // The surface size changed. Therefore, destroy existing surfaces as @@ -269,10 +281,6 @@ void AndroidExternalViewEmbedder::BeginFrame( DestroySurfaces(); } surface_pool_->SetFrameSize(frame_size); - // JNI method must be called on the platform thread. - if (raster_thread_merger->IsOnPlatformThread()) { - jni_facade_->FlutterViewBeginFrame(); - } frame_size_ = frame_size; device_pixel_ratio_ = device_pixel_ratio; diff --git a/shell/platform/android/external_view_embedder/external_view_embedder.h b/shell/platform/android/external_view_embedder/external_view_embedder.h index 400b43fb91a89..652a88bf95af8 100644 --- a/shell/platform/android/external_view_embedder/external_view_embedder.h +++ b/shell/platform/android/external_view_embedder/external_view_embedder.h @@ -43,9 +43,9 @@ class AndroidExternalViewEmbedder final : public ExternalViewEmbedder { DlCanvas* CompositeEmbeddedView(int64_t view_id) override; // |ExternalViewEmbedder| - void SubmitFrame(GrDirectContext* context, - const std::shared_ptr& aiks_context, - std::unique_ptr frame) override; + void SubmitView(GrDirectContext* context, + const std::shared_ptr& aiks_context, + std::unique_ptr frame) override; // |ExternalViewEmbedder| PostPrerollResult PostPrerollAction( @@ -56,11 +56,14 @@ class AndroidExternalViewEmbedder final : public ExternalViewEmbedder { // |ExternalViewEmbedder| void BeginFrame( - SkISize frame_size, GrDirectContext* context, - double device_pixel_ratio, fml::RefPtr raster_thread_merger) override; + // |ExternalViewEmbedder| + void PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) override; + // |ExternalViewEmbedder| void CancelFrame() override; diff --git a/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc b/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc index e6417a08f0800..7225d2e198008 100644 --- a/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc +++ b/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc @@ -27,6 +27,8 @@ namespace testing { using ::testing::ByMove; using ::testing::Return; +constexpr int64_t kImplicitViewId = 0; + class TestAndroidSurfaceFactory : public AndroidSurfaceFactory { public: using TestSurfaceProducer = @@ -144,8 +146,9 @@ TEST(AndroidExternalViewEmbedder, RasterizerRunsOnPlatformThread) { ASSERT_FALSE(raster_thread_merger->IsMerged()); EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()); - embedder->BeginFrame(SkISize::Make(10, 20), nullptr, 1.0, - raster_thread_merger); + embedder->BeginFrame(nullptr, raster_thread_merger); + embedder->PrepareView(kImplicitViewId, SkISize::Make(10, 20), 1.0); + // Push a platform view. embedder->PrerollCompositeEmbeddedView( 0, std::make_unique()); @@ -197,8 +200,8 @@ TEST(AndroidExternalViewEmbedder, PlatformViewRect) { GetThreadMergerFromPlatformThread(&rasterizer_thread); EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()); - embedder->BeginFrame(SkISize::Make(100, 100), nullptr, 1.5, - raster_thread_merger); + embedder->BeginFrame(nullptr, raster_thread_merger); + embedder->PrepareView(kImplicitViewId, SkISize::Make(100, 100), 1.5); MutatorsStack stack; SkMatrix matrix; @@ -225,8 +228,8 @@ TEST(AndroidExternalViewEmbedder, PlatformViewRectChangedParams) { GetThreadMergerFromPlatformThread(&rasterizer_thread); EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()); - embedder->BeginFrame(SkISize::Make(100, 100), nullptr, 1.5, - raster_thread_merger); + embedder->BeginFrame(nullptr, raster_thread_merger); + embedder->PrepareView(kImplicitViewId, SkISize::Make(100, 100), 1.5); auto view_id = 0; @@ -254,7 +257,7 @@ TEST(AndroidExternalViewEmbedder, PlatformViewRectChangedParams) { ASSERT_EQ(SkRect::MakeXYWH(75, 90, 105, 120), embedder->GetViewRect(view_id)); } -TEST(AndroidExternalViewEmbedder, SubmitFrame) { +TEST(AndroidExternalViewEmbedder, SubmitView) { auto jni_mock = std::make_shared(); auto android_context = std::make_shared(AndroidRenderingAPI::kSoftware); @@ -313,7 +316,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) { }, /*frame_size=*/SkISize::Make(800, 600)); - embedder->SubmitFrame(gr_context.get(), nullptr, std::move(surface_frame)); + embedder->SubmitView(gr_context.get(), nullptr, std::move(surface_frame)); // Submits frame if no Android view in the current frame. EXPECT_TRUE(did_submit_frame); // Doesn't resubmit frame. @@ -327,7 +330,8 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) { // ------------------ Second frame ------------------ // { EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()); - embedder->BeginFrame(frame_size, nullptr, 1.5, raster_thread_merger); + embedder->BeginFrame(nullptr, raster_thread_merger); + embedder->PrepareView(kImplicitViewId, frame_size, 1.5); // Add an Android view. MutatorsStack stack1; @@ -381,7 +385,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) { }, /*frame_size=*/SkISize::Make(800, 600)); - embedder->SubmitFrame(gr_context.get(), nullptr, std::move(surface_frame)); + embedder->SubmitView(gr_context.get(), nullptr, std::move(surface_frame)); // Doesn't submit frame if there aren't Android views in the previous frame. EXPECT_FALSE(did_submit_frame); // Resubmits frame. @@ -395,7 +399,8 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) { // ------------------ Third frame ------------------ // { EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()); - embedder->BeginFrame(frame_size, nullptr, 1.5, raster_thread_merger); + embedder->BeginFrame(nullptr, raster_thread_merger); + embedder->PrepareView(kImplicitViewId, frame_size, 1.5); // Add an Android view. MutatorsStack stack1; @@ -446,7 +451,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); - embedder->SubmitFrame(gr_context.get(), nullptr, std::move(surface_frame)); + embedder->SubmitView(gr_context.get(), nullptr, std::move(surface_frame)); // Submits frame if there are Android views in the previous frame. EXPECT_TRUE(did_submit_frame); // Doesn't resubmit frame. @@ -499,7 +504,8 @@ TEST(AndroidExternalViewEmbedder, OverlayCoverTwoPlatformViews) { auto raster_thread_merger = GetThreadMergerFromPlatformThread(); EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()); - embedder->BeginFrame(frame_size, nullptr, 1.5, raster_thread_merger); + embedder->BeginFrame(nullptr, raster_thread_merger); + embedder->PrepareView(kImplicitViewId, frame_size, 1.5); { // Add first Android view. @@ -553,7 +559,7 @@ TEST(AndroidExternalViewEmbedder, OverlayCoverTwoPlatformViews) { }, /*frame_size=*/SkISize::Make(800, 600)); - embedder->SubmitFrame(gr_context.get(), nullptr, std::move(surface_frame)); + embedder->SubmitView(gr_context.get(), nullptr, std::move(surface_frame)); EXPECT_CALL(*jni_mock, FlutterViewEndFrame()); embedder->EndFrame(/*should_resubmit_frame=*/false, raster_thread_merger); @@ -597,7 +603,8 @@ TEST(AndroidExternalViewEmbedder, SubmitFrameOverlayComposition) { auto raster_thread_merger = GetThreadMergerFromPlatformThread(); EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()); - embedder->BeginFrame(frame_size, nullptr, 1.5, raster_thread_merger); + embedder->BeginFrame(nullptr, raster_thread_merger); + embedder->PrepareView(kImplicitViewId, frame_size, 1.5); { // Add first Android view. @@ -656,7 +663,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFrameOverlayComposition) { }, /*frame_size=*/SkISize::Make(800, 600)); - embedder->SubmitFrame(gr_context.get(), nullptr, std::move(surface_frame)); + embedder->SubmitView(gr_context.get(), nullptr, std::move(surface_frame)); EXPECT_CALL(*jni_mock, FlutterViewEndFrame()); embedder->EndFrame(/*should_resubmit_frame=*/false, raster_thread_merger); @@ -700,7 +707,8 @@ TEST(AndroidExternalViewEmbedder, SubmitFramePlatformViewWithoutAnyOverlay) { auto raster_thread_merger = GetThreadMergerFromPlatformThread(); EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()); - embedder->BeginFrame(frame_size, nullptr, 1.5, raster_thread_merger); + embedder->BeginFrame(nullptr, raster_thread_merger); + embedder->PrepareView(kImplicitViewId, frame_size, 1.5); { // Add Android view. @@ -724,7 +732,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFramePlatformViewWithoutAnyOverlay) { }, /*frame_size=*/SkISize::Make(800, 600)); - embedder->SubmitFrame(gr_context.get(), nullptr, std::move(surface_frame)); + embedder->SubmitView(gr_context.get(), nullptr, std::move(surface_frame)); EXPECT_CALL(*jni_mock, FlutterViewEndFrame()); embedder->EndFrame(/*should_resubmit_frame=*/false, raster_thread_merger); @@ -743,8 +751,8 @@ TEST(AndroidExternalViewEmbedder, DoesNotCallJNIPlatformThreadOnlyMethods) { auto raster_thread_merger = GetThreadMergerFromRasterThread(&platform_thread); EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()).Times(0); - embedder->BeginFrame(SkISize::Make(10, 20), nullptr, 1.0, - raster_thread_merger); + embedder->BeginFrame(nullptr, raster_thread_merger); + embedder->PrepareView(kImplicitViewId, SkISize::Make(10, 20), 1.0); EXPECT_CALL(*jni_mock, FlutterViewEndFrame()).Times(0); embedder->EndFrame(/*should_resubmit_frame=*/false, raster_thread_merger); @@ -792,7 +800,8 @@ TEST(AndroidExternalViewEmbedder, DestroyOverlayLayersOnSizeChange) { // ------------------ First frame ------------------ // { EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()); - embedder->BeginFrame(frame_size, nullptr, 1.5, raster_thread_merger); + embedder->BeginFrame(nullptr, raster_thread_merger); + embedder->PrepareView(kImplicitViewId, frame_size, 1.5); // Add an Android view. MutatorsStack stack1; @@ -825,7 +834,7 @@ TEST(AndroidExternalViewEmbedder, DestroyOverlayLayersOnSizeChange) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); - embedder->SubmitFrame(gr_context.get(), nullptr, std::move(surface_frame)); + embedder->SubmitView(gr_context.get(), nullptr, std::move(surface_frame)); EXPECT_CALL(*jni_mock, FlutterViewEndFrame()); embedder->EndFrame(/*should_resubmit_frame=*/false, raster_thread_merger); @@ -834,8 +843,8 @@ TEST(AndroidExternalViewEmbedder, DestroyOverlayLayersOnSizeChange) { EXPECT_CALL(*jni_mock, FlutterViewDestroyOverlaySurfaces()); EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()); // Change the frame size. - embedder->BeginFrame(SkISize::Make(30, 40), nullptr, 1.0, - raster_thread_merger); + embedder->BeginFrame(nullptr, raster_thread_merger); + embedder->PrepareView(kImplicitViewId, SkISize::Make(30, 40), 1.0); } TEST(AndroidExternalViewEmbedder, DoesNotDestroyOverlayLayersOnSizeChange) { @@ -880,7 +889,8 @@ TEST(AndroidExternalViewEmbedder, DoesNotDestroyOverlayLayersOnSizeChange) { auto raster_thread_merger = GetThreadMergerFromPlatformThread(&rasterizer_thread); EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()); - embedder->BeginFrame(frame_size, nullptr, 1.5, raster_thread_merger); + embedder->BeginFrame(nullptr, raster_thread_merger); + embedder->PrepareView(kImplicitViewId, frame_size, 1.5); // Add an Android view. MutatorsStack stack1; @@ -912,7 +922,7 @@ TEST(AndroidExternalViewEmbedder, DoesNotDestroyOverlayLayersOnSizeChange) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); - embedder->SubmitFrame(gr_context.get(), nullptr, std::move(surface_frame)); + embedder->SubmitView(gr_context.get(), nullptr, std::move(surface_frame)); EXPECT_CALL(*jni_mock, FlutterViewEndFrame()); embedder->EndFrame(/*should_resubmit_frame=*/false, raster_thread_merger); @@ -922,8 +932,9 @@ TEST(AndroidExternalViewEmbedder, DoesNotDestroyOverlayLayersOnSizeChange) { EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()).Times(0); fml::Thread platform_thread("platform"); - embedder->BeginFrame(SkISize::Make(30, 40), nullptr, 1.0, + embedder->BeginFrame(nullptr, GetThreadMergerFromRasterThread(&platform_thread)); + embedder->PrepareView(kImplicitViewId, SkISize::Make(30, 40), 1.0); } TEST(AndroidExternalViewEmbedder, SupportsDynamicThreadMerging) { @@ -949,8 +960,8 @@ TEST(AndroidExternalViewEmbedder, DisableThreadMerger) { EXPECT_CALL(*jni_mock, FlutterViewBeginFrame()).Times(0); - embedder->BeginFrame(SkISize::Make(10, 20), nullptr, 1.0, - raster_thread_merger); + embedder->BeginFrame(nullptr, raster_thread_merger); + embedder->PrepareView(kImplicitViewId, SkISize::Make(10, 20), 1.0); // Push a platform view. embedder->PrerollCompositeEmbeddedView( 0, std::make_unique()); @@ -999,7 +1010,8 @@ TEST(AndroidExternalViewEmbedder, Teardown) { auto raster_thread_merger = GetThreadMergerFromPlatformThread(&rasterizer_thread); - embedder->BeginFrame(frame_size, nullptr, 1.5, raster_thread_merger); + embedder->BeginFrame(nullptr, raster_thread_merger); + embedder->PrepareView(kImplicitViewId, frame_size, 1.5); // Add an Android view. MutatorsStack stack; @@ -1023,7 +1035,7 @@ TEST(AndroidExternalViewEmbedder, Teardown) { SkSurfaces::Null(1000, 1000), framebuffer_info, [](const SurfaceFrame& surface_frame, DlCanvas* canvas) { return true; }, /*frame_size=*/SkISize::Make(800, 600)); - embedder->SubmitFrame(gr_context.get(), nullptr, std::move(surface_frame)); + embedder->SubmitView(gr_context.get(), nullptr, std::move(surface_frame)); embedder->EndFrame(/*should_resubmit_frame=*/false, raster_thread_merger); diff --git a/shell/platform/darwin/ios/ios_external_view_embedder.h b/shell/platform/darwin/ios/ios_external_view_embedder.h index d83b435930f21..a28b2efc0de8c 100644 --- a/shell/platform/darwin/ios/ios_external_view_embedder.h +++ b/shell/platform/darwin/ios/ios_external_view_embedder.h @@ -32,11 +32,14 @@ class IOSExternalViewEmbedder : public ExternalViewEmbedder { // |ExternalViewEmbedder| void BeginFrame( - SkISize frame_size, GrDirectContext* context, - double device_pixel_ratio, fml::RefPtr raster_thread_merger) override; + // |ExternalViewEmbedder| + void PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) override; + // |ExternalViewEmbedder| void PrerollCompositeEmbeddedView( int64_t view_id, @@ -50,9 +53,9 @@ class IOSExternalViewEmbedder : public ExternalViewEmbedder { DlCanvas* CompositeEmbeddedView(int64_t view_id) override; // |ExternalViewEmbedder| - void SubmitFrame(GrDirectContext* context, - const std::shared_ptr& aiks_context, - std::unique_ptr frame) override; + void SubmitView(GrDirectContext* context, + const std::shared_ptr& aiks_context, + std::unique_ptr frame) override; // |ExternalViewEmbedder| void EndFrame( diff --git a/shell/platform/darwin/ios/ios_external_view_embedder.mm b/shell/platform/darwin/ios/ios_external_view_embedder.mm index 67112e999d13d..0cfabfd8f0517 100644 --- a/shell/platform/darwin/ios/ios_external_view_embedder.mm +++ b/shell/platform/darwin/ios/ios_external_view_embedder.mm @@ -4,6 +4,8 @@ #import "flutter/shell/platform/darwin/ios/ios_external_view_embedder.h" +#include "flutter/common/constants.h" + namespace flutter { IOSExternalViewEmbedder::IOSExternalViewEmbedder( @@ -31,11 +33,18 @@ // |ExternalViewEmbedder| void IOSExternalViewEmbedder::BeginFrame( - SkISize frame_size, GrDirectContext* context, - double device_pixel_ratio, fml::RefPtr raster_thread_merger) { TRACE_EVENT0("flutter", "IOSExternalViewEmbedder::BeginFrame"); +} + +// |ExternalViewEmbedder| +void IOSExternalViewEmbedder::PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) { + // TODO(dkwingsmt): This class only supports rendering into the implicit view. + // Properly support multi-view in the future. + FML_DCHECK(native_view_id == kFlutterImplicitViewId); FML_CHECK(platform_views_controller_); platform_views_controller_->BeginFrame(frame_size); } @@ -66,11 +75,10 @@ } // |ExternalViewEmbedder| -void IOSExternalViewEmbedder::SubmitFrame( - GrDirectContext* context, - const std::shared_ptr& aiks_context, - std::unique_ptr frame) { - TRACE_EVENT0("flutter", "IOSExternalViewEmbedder::SubmitFrame"); +void IOSExternalViewEmbedder::SubmitView(GrDirectContext* context, + const std::shared_ptr& aiks_context, + std::unique_ptr frame) { + TRACE_EVENT0("flutter", "IOSExternalViewEmbedder::SubmitView"); FML_CHECK(platform_views_controller_); platform_views_controller_->SubmitFrame(context, ios_context_, std::move(frame)); TRACE_EVENT0("flutter", "IOSExternalViewEmbedder::DidSubmitFrame"); diff --git a/shell/platform/embedder/embedder_external_view_embedder.cc b/shell/platform/embedder/embedder_external_view_embedder.cc index ca38e86af4826..b68085b2a55f9 100644 --- a/shell/platform/embedder/embedder_external_view_embedder.cc +++ b/shell/platform/embedder/embedder_external_view_embedder.cc @@ -7,6 +7,7 @@ #include #include +#include "flutter/common/constants.h" #include "flutter/shell/platform/embedder/embedder_layers.h" #include "flutter/shell/platform/embedder/embedder_render_target.h" #include "third_party/skia/include/gpu/GrDirectContext.h" @@ -51,10 +52,16 @@ void EmbedderExternalViewEmbedder::CancelFrame() { // |ExternalViewEmbedder| void EmbedderExternalViewEmbedder::BeginFrame( - SkISize frame_size, GrDirectContext* context, - double device_pixel_ratio, - fml::RefPtr raster_thread_merger) { + fml::RefPtr raster_thread_merger) {} + +// |ExternalViewEmbedder| +void EmbedderExternalViewEmbedder::PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) { + // TODO(dkwingsmt): This class only supports rendering into the implicit view. + // Properly support multi-view in the future. + FML_DCHECK(native_view_id == kFlutterImplicitViewId); Reset(); pending_frame_size_ = frame_size; @@ -123,7 +130,7 @@ static FlutterBackingStoreConfig MakeBackingStoreConfig( } // |ExternalViewEmbedder| -void EmbedderExternalViewEmbedder::SubmitFrame( +void EmbedderExternalViewEmbedder::SubmitView( GrDirectContext* context, const std::shared_ptr& aiks_context, std::unique_ptr frame) { diff --git a/shell/platform/embedder/embedder_external_view_embedder.h b/shell/platform/embedder/embedder_external_view_embedder.h index 014f7393c416e..2e41d36c5de93 100644 --- a/shell/platform/embedder/embedder_external_view_embedder.h +++ b/shell/platform/embedder/embedder_external_view_embedder.h @@ -82,11 +82,14 @@ class EmbedderExternalViewEmbedder final : public ExternalViewEmbedder { // |ExternalViewEmbedder| void BeginFrame( - SkISize frame_size, GrDirectContext* context, - double device_pixel_ratio, fml::RefPtr raster_thread_merger) override; + // |ExternalViewEmbedder| + void PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) override; + // |ExternalViewEmbedder| void PrerollCompositeEmbeddedView( int64_t view_id, @@ -96,9 +99,9 @@ class EmbedderExternalViewEmbedder final : public ExternalViewEmbedder { DlCanvas* CompositeEmbeddedView(int64_t view_id) override; // |ExternalViewEmbedder| - void SubmitFrame(GrDirectContext* context, - const std::shared_ptr& aiks_context, - std::unique_ptr frame) override; + void SubmitView(GrDirectContext* context, + const std::shared_ptr& aiks_context, + std::unique_ptr frame) override; // |ExternalViewEmbedder| DlCanvas* GetRootCanvas() override; diff --git a/shell/platform/fuchsia/flutter/external_view_embedder.cc b/shell/platform/fuchsia/flutter/external_view_embedder.cc index 6a5604015e69f..1ce578ba7e857 100644 --- a/shell/platform/fuchsia/flutter/external_view_embedder.cc +++ b/shell/platform/fuchsia/flutter/external_view_embedder.cc @@ -132,11 +132,11 @@ void ExternalViewEmbedder::EndFrame( TRACE_EVENT0("flutter", "ExternalViewEmbedder::EndFrame"); } -void ExternalViewEmbedder::SubmitFrame( +void ExternalViewEmbedder::SubmitView( GrDirectContext* context, const std::shared_ptr& aiks_context, std::unique_ptr frame) { - TRACE_EVENT0("flutter", "ExternalViewEmbedder::SubmitFrame"); + TRACE_EVENT0("flutter", "ExternalViewEmbedder::SubmitView"); std::vector> frame_surfaces; std::unordered_map frame_surface_indices; diff --git a/shell/platform/fuchsia/flutter/external_view_embedder.h b/shell/platform/fuchsia/flutter/external_view_embedder.h index a5771a9ce4bfc..da12862162a71 100644 --- a/shell/platform/fuchsia/flutter/external_view_embedder.h +++ b/shell/platform/fuchsia/flutter/external_view_embedder.h @@ -83,9 +83,9 @@ class ExternalViewEmbedder final : public flutter::ExternalViewEmbedder { fml::RefPtr raster_thread_merger) override; // |ExternalViewEmbedder| - void SubmitFrame(GrDirectContext* context, - const std::shared_ptr& aiks_context, - std::unique_ptr frame) override; + void SubmitView(GrDirectContext* context, + const std::shared_ptr& aiks_context, + std::unique_ptr frame) override; // |ExternalViewEmbedder| void CancelFrame() override { Reset(); } diff --git a/shell/platform/fuchsia/flutter/tests/external_view_embedder_unittests.cc b/shell/platform/fuchsia/flutter/tests/external_view_embedder_unittests.cc index 97581fa2a0464..e5c0333025341 100644 --- a/shell/platform/fuchsia/flutter/tests/external_view_embedder_unittests.cc +++ b/shell/platform/fuchsia/flutter/tests/external_view_embedder_unittests.cc @@ -326,7 +326,8 @@ void DrawSimpleFrame(ExternalViewEmbedder& external_view_embedder, SkISize frame_size, float frame_dpr, std::function draw_callback) { - external_view_embedder.BeginFrame(frame_size, nullptr, frame_dpr, nullptr); + external_view_embedder.BeginFrame(nullptr, nullptr); + external_view_embedder.PrepareView(kImplicitViewId, frame_size, frame_dpr); { flutter::DlCanvas* root_canvas = external_view_embedder.GetRootCanvas(); external_view_embedder.PostPrerollAction(nullptr); @@ -335,7 +336,7 @@ void DrawSimpleFrame(ExternalViewEmbedder& external_view_embedder, external_view_embedder.EndFrame(false, nullptr); flutter::SurfaceFrame::FramebufferInfo framebuffer_info; framebuffer_info.supports_readback = true; - external_view_embedder.SubmitFrame( + external_view_embedder.SubmitView( nullptr, nullptr, std::make_unique( nullptr, std::move(framebuffer_info), @@ -352,7 +353,8 @@ void DrawFrameWithView( flutter::EmbeddedViewParams& view_params, std::function background_draw_callback, std::function overlay_draw_callback) { - external_view_embedder.BeginFrame(frame_size, nullptr, frame_dpr, nullptr); + external_view_embedder.BeginFrame(nullptr, nullptr); + external_view_embedder.PrepareView(kImplicitViewId, frame_size, frame_dpr); { flutter::DlCanvas* root_canvas = external_view_embedder.GetRootCanvas(); external_view_embedder.PrerollCompositeEmbeddedView( @@ -366,7 +368,7 @@ void DrawFrameWithView( external_view_embedder.EndFrame(false, nullptr); flutter::SurfaceFrame::FramebufferInfo framebuffer_info; framebuffer_info.supports_readback = true; - external_view_embedder.SubmitFrame( + external_view_embedder.SubmitView( nullptr, nullptr, std::make_unique( nullptr, std::move(framebuffer_info), diff --git a/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc b/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc index f19c04ba56bc2..7ac6cc41b9188 100644 --- a/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc +++ b/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc @@ -51,9 +51,9 @@ class MockExternalViewEmbedder : public flutter::ExternalViewEmbedder { double device_pixel_ratio, fml::RefPtr raster_thread_merger) override {} - void SubmitFrame(GrDirectContext* context, - const std::shared_ptr& aiks_context, - std::unique_ptr frame) override {} + void SubmitView(GrDirectContext* context, + const std::shared_ptr& aiks_context, + std::unique_ptr frame) override {} void PrerollCompositeEmbeddedView( int64_t view_id, diff --git a/shell/testing/tester_main.cc b/shell/testing/tester_main.cc index 4be39c4d70b41..7f6930e6f5754 100644 --- a/shell/testing/tester_main.cc +++ b/shell/testing/tester_main.cc @@ -139,11 +139,14 @@ class TesterExternalViewEmbedder : public ExternalViewEmbedder { // |ExternalViewEmbedder| void BeginFrame( - SkISize frame_size, GrDirectContext* context, - double device_pixel_ratio, fml::RefPtr raster_thread_merger) override {} + // |ExternalViewEmbedder| + void PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) override {} + // |ExternalViewEmbedder| void PrerollCompositeEmbeddedView( int64_t view_id, From c7d50226ae510bcd9116a39e5c209fca83a148e1 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Fri, 3 Nov 2023 11:48:33 -0700 Subject: [PATCH 02/17] Format --- flow/testing/mock_embedder.cc | 4 ++-- shell/testing/tester_main.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/flow/testing/mock_embedder.cc b/flow/testing/mock_embedder.cc index c0234bc16478f..0131aeeff2a57 100644 --- a/flow/testing/mock_embedder.cc +++ b/flow/testing/mock_embedder.cc @@ -30,8 +30,8 @@ void MockViewEmbedder::BeginFrame( // |ExternalViewEmbedder| void MockViewEmbedder::PrepareView(int64_t native_view_id, - SkISize frame_size, - double device_pixel_ratio) {} + SkISize frame_size, + double device_pixel_ratio) {} // |ExternalViewEmbedder| void MockViewEmbedder::PrerollCompositeEmbeddedView( diff --git a/shell/testing/tester_main.cc b/shell/testing/tester_main.cc index 7f6930e6f5754..d0eab5281e33f 100644 --- a/shell/testing/tester_main.cc +++ b/shell/testing/tester_main.cc @@ -144,8 +144,8 @@ class TesterExternalViewEmbedder : public ExternalViewEmbedder { // |ExternalViewEmbedder| void PrepareView(int64_t native_view_id, - SkISize frame_size, - double device_pixel_ratio) override {} + SkISize frame_size, + double device_pixel_ratio) override {} // |ExternalViewEmbedder| void PrerollCompositeEmbeddedView( From da8694ecd5274dd2a6fd6ac92a7075e183613506 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 6 Nov 2023 14:19:47 -0800 Subject: [PATCH 03/17] Fix lint --- shell/common/rasterizer_unittests.cc | 35 ++++++++++++++++------------ 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/shell/common/rasterizer_unittests.cc b/shell/common/rasterizer_unittests.cc index 3e8e199e8c810..a79395034d160 100644 --- a/shell/common/rasterizer_unittests.cc +++ b/shell/common/rasterizer_unittests.cc @@ -218,9 +218,10 @@ TEST(RasterizerTest, /*raster_thread_merger=*/ fml::RefPtr(nullptr))) .Times(1); - EXPECT_CALL(*external_view_embedder, - PrepareView(/*view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), - /*device_pixel_ratio=*/2.0)) + EXPECT_CALL( + *external_view_embedder, + PrepareView(/*native_view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/2.0)) .Times(1); EXPECT_CALL(*external_view_embedder, SubmitView).Times(1); EXPECT_CALL( @@ -292,9 +293,10 @@ TEST( EXPECT_CALL(*external_view_embedder, BeginFrame(/*context=*/nullptr, /*raster_thread_merger=*/_)) .Times(1); - EXPECT_CALL(*external_view_embedder, - PrepareView(/*view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), - /*device_pixel_ratio=*/2.0)) + EXPECT_CALL( + *external_view_embedder, + PrepareView(/*native_view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/2.0)) .Times(1); EXPECT_CALL(*external_view_embedder, SubmitView).Times(0); EXPECT_CALL(*external_view_embedder, EndFrame(/*should_resubmit_frame=*/false, @@ -369,9 +371,10 @@ TEST( EXPECT_CALL(*external_view_embedder, BeginFrame(/*context=*/nullptr, /*raster_thread_merger=*/_)) .Times(1); - EXPECT_CALL(*external_view_embedder, - PrepareView(/*view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), - /*device_pixel_ratio=*/2.0)) + EXPECT_CALL( + *external_view_embedder, + PrepareView(/*native_view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/2.0)) .Times(1); EXPECT_CALL(*external_view_embedder, SubmitView).Times(1); EXPECT_CALL(*external_view_embedder, EndFrame(/*should_resubmit_frame=*/false, @@ -449,9 +452,10 @@ TEST(RasterizerTest, EXPECT_CALL(*external_view_embedder, BeginFrame(/*context=*/nullptr, /*raster_thread_merger=*/_)) .Times(2); - EXPECT_CALL(*external_view_embedder, - PrepareView(/*view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), - /*device_pixel_ratio=*/2.0)) + EXPECT_CALL( + *external_view_embedder, + PrepareView(/*native_view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/2.0)) .Times(2); EXPECT_CALL(*external_view_embedder, SubmitView).Times(2); EXPECT_CALL(*external_view_embedder, EndFrame(/*should_resubmit_frame=*/false, @@ -561,9 +565,10 @@ TEST(RasterizerTest, externalViewEmbedderDoesntEndFrameWhenNotUsedThisFrame) { EXPECT_CALL(*external_view_embedder, BeginFrame(/*context=*/nullptr, /*raster_thread_merger=*/_)) .Times(0); - EXPECT_CALL(*external_view_embedder, - PrepareView(/*view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), - /*device_pixel_ratio=*/2.0)) + EXPECT_CALL( + *external_view_embedder, + PrepareView(/*native_view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/2.0)) .Times(0); EXPECT_CALL( *external_view_embedder, From a715ed5755c9d1cc1fad8d42708753c43feffca8 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 6 Nov 2023 14:36:14 -0800 Subject: [PATCH 04/17] Add doc --- flow/embedded_views.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/flow/embedded_views.h b/flow/embedded_views.h index 36e1d5e0ac0e8..20b5799509c3a 100644 --- a/flow/embedded_views.h +++ b/flow/embedded_views.h @@ -365,6 +365,13 @@ class DisplayListEmbedderViewSlice : public EmbedderViewSlice { // // Used on iOS, Android (hybrid composite mode), and on embedded platforms // that provide a system compositor as part of the project arguments. +// +// The lifecycle of drawing a frame using ExternalViewEmbedder is: +// +// 1. At the start of a frame, call |BeginFrame|, then |SetUsedThisFrame| to +// true. +// 2. For each view to be drawn, call |PrepareView|, then |SubmitView|. +// 3. At the end of a frame, if |GetUsedThisFrame| is true, call |EndFrame|. class ExternalViewEmbedder { // TODO(cyanglaz): Make embedder own the `EmbeddedViewParams`. @@ -407,6 +414,7 @@ class ExternalViewEmbedder { // Must be called on the UI thread. virtual DlCanvas* CompositeEmbeddedView(int64_t view_id) = 0; + // Prepare for a view to be drawn. virtual void PrepareView(int64_t native_view_id, SkISize frame_size, double device_pixel_ratio) = 0; From f483d8cecf244fa3840a2553ed06fbc3629a0422 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 6 Nov 2023 16:08:37 -0800 Subject: [PATCH 05/17] Add a test --- shell/common/rasterizer.cc | 7 --- shell/common/rasterizer_unittests.cc | 77 ++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 7 deletions(-) diff --git a/shell/common/rasterizer.cc b/shell/common/rasterizer.cc index 6a0e95d2f7b10..14eb0a82db421 100644 --- a/shell/common/rasterizer.cc +++ b/shell/common/rasterizer.cc @@ -564,13 +564,6 @@ Rasterizer::DoDrawResult Rasterizer::DrawToSurfaces( std::unique_ptr Rasterizer::DrawToSurfacesUnsafe( FrameTimingsRecorder& frame_timings_recorder, std::vector> tasks) { - // TODO(dkwingsmt): The rasterizer only supports rendering a single view - // and that view must be the implicit view. Properly support multi-view - // in the future. - // See https://github.com/flutter/flutter/issues/135530, item 2 & 4. - FML_CHECK(tasks.size() == 1u) << "Unexpected size of " << tasks.size(); - FML_DCHECK(tasks.front()->view_id == kFlutterImplicitViewId); - compositor_context_->ui_time().SetLapTime( frame_timings_recorder.GetBuildDuration()); diff --git a/shell/common/rasterizer_unittests.cc b/shell/common/rasterizer_unittests.cc index a79395034d160..4bfc6369762e8 100644 --- a/shell/common/rasterizer_unittests.cc +++ b/shell/common/rasterizer_unittests.cc @@ -644,6 +644,83 @@ TEST(RasterizerTest, externalViewEmbedderDoesntEndFrameWhenPipelineIsEmpty) { latch.Wait(); } +TEST(RasterizerTest, drawMultipleViewsWithExternalViewEmbedder) { + std::string test_name = + ::testing::UnitTest::GetInstance()->current_test_info()->name(); + ThreadHost thread_host("io.flutter.test." + test_name + ".", + ThreadHost::Type::Platform | ThreadHost::Type::RASTER | + ThreadHost::Type::IO | ThreadHost::Type::UI); + TaskRunners task_runners("test", thread_host.platform_thread->GetTaskRunner(), + thread_host.raster_thread->GetTaskRunner(), + thread_host.ui_thread->GetTaskRunner(), + thread_host.io_thread->GetTaskRunner()); + NiceMock delegate; + Settings settings; + ON_CALL(delegate, GetSettings()).WillByDefault(ReturnRef(settings)); + EXPECT_CALL(delegate, GetTaskRunners()) + .WillRepeatedly(ReturnRef(task_runners)); + EXPECT_CALL(delegate, OnFrameRasterized(_)); + auto rasterizer = std::make_unique(delegate); + auto surface = std::make_unique>(); + std::shared_ptr> external_view_embedder = + std::make_shared>(); + rasterizer->SetExternalViewEmbedder(external_view_embedder); + EXPECT_CALL(*external_view_embedder, SupportsDynamicThreadMerging) + .WillRepeatedly(Return(false)); + EXPECT_CALL(*surface, AllowsDrawingWhenGpuDisabled()).WillOnce(Return(true)); + EXPECT_CALL(*surface, AcquireFrame(SkISize())).Times(2); + ON_CALL(*surface, AcquireFrame).WillByDefault([](const SkISize& size) { + SurfaceFrame::FramebufferInfo framebuffer_info; + framebuffer_info.supports_readback = true; + return std::make_unique( + /*surface=*/ + nullptr, framebuffer_info, + /*submit_callback=*/[](const SurfaceFrame&, DlCanvas*) { return true; }, + /*frame_size=*/SkISize::Make(800, 600)); + }); + EXPECT_CALL(*surface, MakeRenderContextCurrent()) + .WillOnce(Return(ByMove(std::make_unique(true)))); + + EXPECT_CALL(*external_view_embedder, BeginFrame(/*context=*/nullptr, + /*raster_thread_merger=*/_)) + .Times(1); + EXPECT_CALL( + *external_view_embedder, + PrepareView(/*native_view_id=*/0, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/1.5)) + .Times(1); + EXPECT_CALL( + *external_view_embedder, + PrepareView(/*native_view_id=*/1, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/2.0)) + .Times(1); + EXPECT_CALL(*external_view_embedder, SubmitView).Times(2); + EXPECT_CALL(*external_view_embedder, EndFrame(/*should_resubmit_frame=*/false, + /*raster_thread_merger=*/_)) + .Times(1); + + rasterizer->Setup(std::move(surface)); + fml::AutoResetWaitableEvent latch; + thread_host.raster_thread->GetTaskRunner()->PostTask([&] { + auto pipeline = std::make_shared(/*depth=*/10); + std::vector> tasks; + tasks.push_back(std::make_unique( + 0, std::make_unique(LayerTree::Config(), SkISize()), 1.5)); + tasks.push_back(std::make_unique( + 1, std::make_unique(LayerTree::Config(), SkISize()), 2.0)); + auto layer_tree_item = std::make_unique( + std::move(tasks), + CreateFinishedBuildRecorder()); + PipelineProduceResult result = + pipeline->Produce().Complete(std::move(layer_tree_item)); + EXPECT_TRUE(result.success); + ON_CALL(delegate, ShouldDiscardLayerTree).WillByDefault(Return(false)); + rasterizer->Draw(pipeline); + latch.Signal(); + }); + latch.Wait(); +} + TEST(RasterizerTest, drawWithGpuEnabledAndSurfaceAllowsDrawingWhenGpuDisabledDoesAcquireFrame) { std::string test_name = From 0d2be4e5945404db70a7b428b8f999bef186312e Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 6 Nov 2023 16:21:24 -0800 Subject: [PATCH 06/17] Format --- shell/common/rasterizer_unittests.cc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/shell/common/rasterizer_unittests.cc b/shell/common/rasterizer_unittests.cc index 4bfc6369762e8..b6338405fb19f 100644 --- a/shell/common/rasterizer_unittests.cc +++ b/shell/common/rasterizer_unittests.cc @@ -684,15 +684,13 @@ TEST(RasterizerTest, drawMultipleViewsWithExternalViewEmbedder) { EXPECT_CALL(*external_view_embedder, BeginFrame(/*context=*/nullptr, /*raster_thread_merger=*/_)) .Times(1); - EXPECT_CALL( - *external_view_embedder, - PrepareView(/*native_view_id=*/0, /*frame_size=*/SkISize(), - /*device_pixel_ratio=*/1.5)) + EXPECT_CALL(*external_view_embedder, + PrepareView(/*native_view_id=*/0, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/1.5)) .Times(1); - EXPECT_CALL( - *external_view_embedder, - PrepareView(/*native_view_id=*/1, /*frame_size=*/SkISize(), - /*device_pixel_ratio=*/2.0)) + EXPECT_CALL(*external_view_embedder, + PrepareView(/*native_view_id=*/1, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/2.0)) .Times(1); EXPECT_CALL(*external_view_embedder, SubmitView).Times(2); EXPECT_CALL(*external_view_embedder, EndFrame(/*should_resubmit_frame=*/false, @@ -709,8 +707,7 @@ TEST(RasterizerTest, drawMultipleViewsWithExternalViewEmbedder) { tasks.push_back(std::make_unique( 1, std::make_unique(LayerTree::Config(), SkISize()), 2.0)); auto layer_tree_item = std::make_unique( - std::move(tasks), - CreateFinishedBuildRecorder()); + std::move(tasks), CreateFinishedBuildRecorder()); PipelineProduceResult result = pipeline->Produce().Complete(std::move(layer_tree_item)); EXPECT_TRUE(result.success); From 89eceb15d2b64429db2136c9adb02fa66dc157e8 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Thu, 9 Nov 2023 00:07:25 -0800 Subject: [PATCH 07/17] Add TODO --- shell/platform/embedder/embedder_external_view_embedder.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/platform/embedder/embedder_external_view_embedder.cc b/shell/platform/embedder/embedder_external_view_embedder.cc index b68085b2a55f9..04adc8562cd1e 100644 --- a/shell/platform/embedder/embedder_external_view_embedder.cc +++ b/shell/platform/embedder/embedder_external_view_embedder.cc @@ -61,6 +61,7 @@ void EmbedderExternalViewEmbedder::PrepareView(int64_t native_view_id, double device_pixel_ratio) { // TODO(dkwingsmt): This class only supports rendering into the implicit view. // Properly support multi-view in the future. + // https://github.com/flutter/flutter/issues/135530 item 4 FML_DCHECK(native_view_id == kFlutterImplicitViewId); Reset(); From cadb2f391b76bbb4db82d3e1bdcf8dc06ff0a2dc Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Thu, 16 Nov 2023 16:58:04 -0800 Subject: [PATCH 08/17] Compile --- .../shell_test_external_view_embedder.cc | 139 +++--- .../embedder_external_view_embedder.cc | 404 +++++++++--------- 2 files changed, 273 insertions(+), 270 deletions(-) diff --git a/shell/common/shell_test_external_view_embedder.cc b/shell/common/shell_test_external_view_embedder.cc index 859387734c7c5..1e17c19394bde 100644 --- a/shell/common/shell_test_external_view_embedder.cc +++ b/shell/common/shell_test_external_view_embedder.cc @@ -42,84 +42,87 @@ void ShellTestExternalViewEmbedder::CancelFrame() {} // |ExternalViewEmbedder| void ShellTestExternalViewEmbedder::BeginFrame( GrDirectContext* context, - const fml::RefPtr& raster_thread_merger) { - // |ExternalViewEmbedder| - void ShellTestExternalViewEmbedder::PrepareView( - int64_t native_view_id, SkISize frame_size, double device_pixel_ratio) { - visited_platform_views_.clear(); - mutators_stacks_.clear(); - current_composition_params_.clear(); - } + const fml::RefPtr& raster_thread_merger) {} - // |ExternalViewEmbedder| - void ShellTestExternalViewEmbedder::PrerollCompositeEmbeddedView( - int64_t view_id, std::unique_ptr params) { - SkRect view_bounds = SkRect::Make(frame_size_); - auto view = std::make_unique(view_bounds); - slices_.insert_or_assign(view_id, std::move(view)); - } +// |ExternalViewEmbedder| +void ShellTestExternalViewEmbedder::PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) { + visited_platform_views_.clear(); + mutators_stacks_.clear(); + current_composition_params_.clear(); +} - // |ExternalViewEmbedder| - PostPrerollResult ShellTestExternalViewEmbedder::PostPrerollAction( - const fml::RefPtr& raster_thread_merger) { - FML_DCHECK(raster_thread_merger); - return post_preroll_result_; - } +// |ExternalViewEmbedder| +void ShellTestExternalViewEmbedder::PrerollCompositeEmbeddedView( + int64_t view_id, + std::unique_ptr params) { + SkRect view_bounds = SkRect::Make(frame_size_); + auto view = std::make_unique(view_bounds); + slices_.insert_or_assign(view_id, std::move(view)); +} - // |ExternalViewEmbedder| - void ShellTestExternalViewEmbedder::PushVisitedPlatformView(int64_t view_id) { - visited_platform_views_.push_back(view_id); - } +// |ExternalViewEmbedder| +PostPrerollResult ShellTestExternalViewEmbedder::PostPrerollAction( + const fml::RefPtr& raster_thread_merger) { + FML_DCHECK(raster_thread_merger); + return post_preroll_result_; +} - // |ExternalViewEmbedder| - void ShellTestExternalViewEmbedder::PushFilterToVisitedPlatformViews( - const std::shared_ptr& filter, - const SkRect& filter_rect) { - for (int64_t id : visited_platform_views_) { - EmbeddedViewParams params = current_composition_params_[id]; - params.PushImageFilter(filter, filter_rect); - current_composition_params_[id] = params; - mutators_stacks_[id] = params.mutatorsStack(); - } - } +// |ExternalViewEmbedder| +void ShellTestExternalViewEmbedder::PushVisitedPlatformView(int64_t view_id) { + visited_platform_views_.push_back(view_id); +} - DlCanvas* ShellTestExternalViewEmbedder::CompositeEmbeddedView( - int64_t view_id) { - return slices_[view_id]->canvas(); +// |ExternalViewEmbedder| +void ShellTestExternalViewEmbedder::PushFilterToVisitedPlatformViews( + const std::shared_ptr& filter, + const SkRect& filter_rect) { + for (int64_t id : visited_platform_views_) { + EmbeddedViewParams params = current_composition_params_[id]; + params.PushImageFilter(filter, filter_rect); + current_composition_params_[id] = params; + mutators_stacks_[id] = params.mutatorsStack(); } +} - // |ExternalViewEmbedder| - void ShellTestExternalViewEmbedder::SubmitView( - GrDirectContext * context, - const std::shared_ptr& aiks_context, - std::unique_ptr frame) { - if (!frame) { - return; - } - frame->Submit(); - if (frame->SkiaSurface()) { - last_submitted_frame_size_ = SkISize::Make( - frame->SkiaSurface()->width(), frame->SkiaSurface()->height()); - } else { - last_submitted_frame_size_ = SkISize::MakeEmpty(); - } - submitted_frame_count_++; - } +DlCanvas* ShellTestExternalViewEmbedder::CompositeEmbeddedView( + int64_t view_id) { + return slices_[view_id]->canvas(); +} - // |ExternalViewEmbedder| - void ShellTestExternalViewEmbedder::EndFrame( - bool should_resubmit_frame, - const fml::RefPtr& raster_thread_merger) { - end_frame_call_back_(should_resubmit_frame, raster_thread_merger); +// |ExternalViewEmbedder| +void ShellTestExternalViewEmbedder::SubmitView( + GrDirectContext* context, + const std::shared_ptr& aiks_context, + std::unique_ptr frame) { + if (!frame) { + return; } - - // |ExternalViewEmbedder| - DlCanvas* ShellTestExternalViewEmbedder::GetRootCanvas() { - return nullptr; + frame->Submit(); + if (frame->SkiaSurface()) { + last_submitted_frame_size_ = SkISize::Make(frame->SkiaSurface()->width(), + frame->SkiaSurface()->height()); + } else { + last_submitted_frame_size_ = SkISize::MakeEmpty(); } + submitted_frame_count_++; +} - bool ShellTestExternalViewEmbedder::SupportsDynamicThreadMerging() { - return support_thread_merging_; - } +// |ExternalViewEmbedder| +void ShellTestExternalViewEmbedder::EndFrame( + bool should_resubmit_frame, + const fml::RefPtr& raster_thread_merger) { + end_frame_call_back_(should_resubmit_frame, raster_thread_merger); +} + +// |ExternalViewEmbedder| +DlCanvas* ShellTestExternalViewEmbedder::GetRootCanvas() { + return nullptr; +} + +bool ShellTestExternalViewEmbedder::SupportsDynamicThreadMerging() { + return support_thread_merging_; +} } // namespace flutter diff --git a/shell/platform/embedder/embedder_external_view_embedder.cc b/shell/platform/embedder/embedder_external_view_embedder.cc index 395478ff63e48..d8ab3306ebddd 100644 --- a/shell/platform/embedder/embedder_external_view_embedder.cc +++ b/shell/platform/embedder/embedder_external_view_embedder.cc @@ -53,235 +53,235 @@ void EmbedderExternalViewEmbedder::CancelFrame() { // |ExternalViewEmbedder| void EmbedderExternalViewEmbedder::BeginFrame( GrDirectContext* context, - const fml::RefPtr& raster_thread_merger) { - // |ExternalViewEmbedder| - void EmbedderExternalViewEmbedder::PrepareView( - int64_t native_view_id, SkISize frame_size, double device_pixel_ratio) { - // TODO(dkwingsmt): This class only supports rendering into the implicit - // view. Properly support multi-view in the future. - // https://github.com/flutter/flutter/issues/135530 item 4 - FML_DCHECK(native_view_id == kFlutterImplicitViewId); - Reset(); - - pending_frame_size_ = frame_size; - pending_device_pixel_ratio_ = device_pixel_ratio; - pending_surface_transformation_ = GetSurfaceTransformation(); - - static const auto kRootViewIdentifier = - EmbedderExternalView::ViewIdentifier{}; - - pending_views_[kRootViewIdentifier] = - std::make_unique(pending_frame_size_, - pending_surface_transformation_); - composition_order_.push_back(kRootViewIdentifier); - } + const fml::RefPtr& raster_thread_merger) {} - // |ExternalViewEmbedder| - void EmbedderExternalViewEmbedder::PrerollCompositeEmbeddedView( - int64_t view_id, std::unique_ptr params) { - auto vid = EmbedderExternalView::ViewIdentifier(view_id); - FML_DCHECK(pending_views_.count(vid) == 0); - - pending_views_[vid] = std::make_unique( - pending_frame_size_, // frame size - pending_surface_transformation_, // surface xformation - vid, // view identifier - std::move(params) // embedded view params - ); - composition_order_.push_back(vid); - } +// |ExternalViewEmbedder| +void EmbedderExternalViewEmbedder::PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) { + // TODO(dkwingsmt): This class only supports rendering into the implicit + // view. Properly support multi-view in the future. + // https://github.com/flutter/flutter/issues/135530 item 4 + FML_DCHECK(native_view_id == kFlutterImplicitViewId); + Reset(); - // |ExternalViewEmbedder| - DlCanvas* EmbedderExternalViewEmbedder::GetRootCanvas() { - auto found = pending_views_.find(EmbedderExternalView::ViewIdentifier{}); - if (found == pending_views_.end()) { - FML_DLOG(WARNING) - << "No root canvas could be found. This is extremely unlikely and " - "indicates that the external view embedder did not receive the " - "notification to begin the frame."; - return nullptr; - } - return found->second->GetCanvas(); + pending_frame_size_ = frame_size; + pending_device_pixel_ratio_ = device_pixel_ratio; + pending_surface_transformation_ = GetSurfaceTransformation(); + + static const auto kRootViewIdentifier = + EmbedderExternalView::ViewIdentifier{}; + + pending_views_[kRootViewIdentifier] = std::make_unique( + pending_frame_size_, pending_surface_transformation_); + composition_order_.push_back(kRootViewIdentifier); +} + +// |ExternalViewEmbedder| +void EmbedderExternalViewEmbedder::PrerollCompositeEmbeddedView( + int64_t view_id, + std::unique_ptr params) { + auto vid = EmbedderExternalView::ViewIdentifier(view_id); + FML_DCHECK(pending_views_.count(vid) == 0); + + pending_views_[vid] = std::make_unique( + pending_frame_size_, // frame size + pending_surface_transformation_, // surface xformation + vid, // view identifier + std::move(params) // embedded view params + ); + composition_order_.push_back(vid); +} + +// |ExternalViewEmbedder| +DlCanvas* EmbedderExternalViewEmbedder::GetRootCanvas() { + auto found = pending_views_.find(EmbedderExternalView::ViewIdentifier{}); + if (found == pending_views_.end()) { + FML_DLOG(WARNING) + << "No root canvas could be found. This is extremely unlikely and " + "indicates that the external view embedder did not receive the " + "notification to begin the frame."; + return nullptr; } + return found->second->GetCanvas(); +} - // |ExternalViewEmbedder| - DlCanvas* EmbedderExternalViewEmbedder::CompositeEmbeddedView( - int64_t view_id) { - auto vid = EmbedderExternalView::ViewIdentifier(view_id); - auto found = pending_views_.find(vid); - if (found == pending_views_.end()) { - FML_DCHECK(false) << "Attempted to composite a view that was not " - "pre-rolled."; - return nullptr; - } - return found->second->GetCanvas(); +// |ExternalViewEmbedder| +DlCanvas* EmbedderExternalViewEmbedder::CompositeEmbeddedView(int64_t view_id) { + auto vid = EmbedderExternalView::ViewIdentifier(view_id); + auto found = pending_views_.find(vid); + if (found == pending_views_.end()) { + FML_DCHECK(false) << "Attempted to composite a view that was not " + "pre-rolled."; + return nullptr; } + return found->second->GetCanvas(); +} - static FlutterBackingStoreConfig MakeBackingStoreConfig( - const SkISize& backing_store_size) { - FlutterBackingStoreConfig config = {}; +static FlutterBackingStoreConfig MakeBackingStoreConfig( + const SkISize& backing_store_size) { + FlutterBackingStoreConfig config = {}; - config.struct_size = sizeof(config); + config.struct_size = sizeof(config); - config.size.width = backing_store_size.width(); - config.size.height = backing_store_size.height(); + config.size.width = backing_store_size.width(); + config.size.height = backing_store_size.height(); - return config; - } + return config; +} - // |ExternalViewEmbedder| - void EmbedderExternalViewEmbedder::SubmitView( - GrDirectContext * context, - const std::shared_ptr& aiks_context, - std::unique_ptr frame) { - auto [matched_render_targets, pending_keys] = - render_target_cache_.GetExistingTargetsInCache(pending_views_); - - // This is where unused render targets will be collected. Control may flow - // to the embedder. Here, the embedder has the opportunity to trample on the - // OpenGL context. - // - // For optimum performance, we should tell the render target cache to clear - // its unused entries before allocating new ones. This collection step - // before allocating new render targets ameliorates peak memory usage within - // the frame. But, this causes an issue in a known internal embedder. To - // work around this issue while that embedder migrates, collection of render - // targets is deferred after the presentation. +// |ExternalViewEmbedder| +void EmbedderExternalViewEmbedder::SubmitView( + GrDirectContext* context, + const std::shared_ptr& aiks_context, + std::unique_ptr frame) { + auto [matched_render_targets, pending_keys] = + render_target_cache_.GetExistingTargetsInCache(pending_views_); + + // This is where unused render targets will be collected. Control may flow + // to the embedder. Here, the embedder has the opportunity to trample on the + // OpenGL context. + // + // For optimum performance, we should tell the render target cache to clear + // its unused entries before allocating new ones. This collection step + // before allocating new render targets ameliorates peak memory usage within + // the frame. But, this causes an issue in a known internal embedder. To + // work around this issue while that embedder migrates, collection of render + // targets is deferred after the presentation. + // + // @warning: Embedder may trample on our OpenGL context here. + auto deferred_cleanup_render_targets = + render_target_cache_.ClearAllRenderTargetsInCache(); + + for (const auto& pending_key : pending_keys) { + const auto& external_view = pending_views_.at(pending_key); + + // If the external view does not have engine rendered contents, it makes + // no sense to ask to embedder to create a render target for us as we + // don't intend to render into it and ask the embedder for presentation + // anyway. Save some memory. + if (!external_view->HasEngineRenderedContents()) { + continue; + } + + // This is the size of render surface we want the embedder to create for + // us. As or right now, this is going to always be equal to the frame size + // post transformation. But, in case optimizations are applied that make + // it so that embedder rendered into surfaces that aren't full screen, + // this assumption will break. So it's just best to ask view for its size + // directly. + const auto render_surface_size = external_view->GetRenderSurfaceSize(); + + const auto backing_store_config = + MakeBackingStoreConfig(render_surface_size); + + // This is where the embedder will create render targets for us. Control + // flow to the embedder makes the engine susceptible to having the + // embedder trample on the OpenGL context. Before any Skia operations are + // performed, the context must be reset. // // @warning: Embedder may trample on our OpenGL context here. - auto deferred_cleanup_render_targets = - render_target_cache_.ClearAllRenderTargetsInCache(); - - for (const auto& pending_key : pending_keys) { - const auto& external_view = pending_views_.at(pending_key); - - // If the external view does not have engine rendered contents, it makes - // no sense to ask to embedder to create a render target for us as we - // don't intend to render into it and ask the embedder for presentation - // anyway. Save some memory. - if (!external_view->HasEngineRenderedContents()) { - continue; - } + auto render_target = create_render_target_callback_(context, aiks_context, + backing_store_config); - // This is the size of render surface we want the embedder to create for - // us. As or right now, this is going to always be equal to the frame size - // post transformation. But, in case optimizations are applied that make - // it so that embedder rendered into surfaces that aren't full screen, - // this assumption will break. So it's just best to ask view for its size - // directly. - const auto render_surface_size = external_view->GetRenderSurfaceSize(); - - const auto backing_store_config = - MakeBackingStoreConfig(render_surface_size); - - // This is where the embedder will create render targets for us. Control - // flow to the embedder makes the engine susceptible to having the - // embedder trample on the OpenGL context. Before any Skia operations are - // performed, the context must be reset. - // - // @warning: Embedder may trample on our OpenGL context here. - auto render_target = create_render_target_callback_(context, aiks_context, - backing_store_config); - - if (!render_target) { - FML_LOG(ERROR) << "Embedder did not return a valid render target."; - return; - } - matched_render_targets[pending_key] = std::move(render_target); + if (!render_target) { + FML_LOG(ERROR) << "Embedder did not return a valid render target."; + return; } + matched_render_targets[pending_key] = std::move(render_target); + } - // The OpenGL context could have been trampled by the embedder at this point - // as it attempted to collect old render targets and create new ones. Tell - // Skia to not rely on existing bindings. - if (context) { - context->resetContext(kAll_GrBackendState); - } + // The OpenGL context could have been trampled by the embedder at this point + // as it attempted to collect old render targets and create new ones. Tell + // Skia to not rely on existing bindings. + if (context) { + context->resetContext(kAll_GrBackendState); + } - // Scribble embedder provide render targets. The order in which we scribble - // into the buffers is irrelevant to the presentation order. - for (const auto& render_target : matched_render_targets) { - if (!pending_views_.at(render_target.first) - ->Render(*render_target.second)) { - FML_LOG(ERROR) - << "Could not render into the embedder supplied render target."; - return; - } + // Scribble embedder provide render targets. The order in which we scribble + // into the buffers is irrelevant to the presentation order. + for (const auto& render_target : matched_render_targets) { + if (!pending_views_.at(render_target.first) + ->Render(*render_target.second)) { + FML_LOG(ERROR) + << "Could not render into the embedder supplied render target."; + return; } + } - // We are going to be transferring control back over to the embedder there - // the context may be trampled upon again. Flush all operations to the - // underlying rendering API. - // - // @warning: Embedder may trample on our OpenGL context here. - if (context) { - context->flushAndSubmit(); - } + // We are going to be transferring control back over to the embedder there + // the context may be trampled upon again. Flush all operations to the + // underlying rendering API. + // + // @warning: Embedder may trample on our OpenGL context here. + if (context) { + context->flushAndSubmit(); + } - // Submit the scribbled layer to the embedder for presentation. - // - // @warning: Embedder may trample on our OpenGL context here. - { - EmbedderLayers presented_layers(pending_frame_size_, - pending_device_pixel_ratio_, - pending_surface_transformation_); - // In composition order, submit backing stores and platform views to the - // embedder. - for (const auto& view_id : composition_order_) { - // If the external view has a platform view, ask the emebdder to place - // it before the Flutter rendered contents for that interleaving level. - const auto& external_view = pending_views_.at(view_id); - if (external_view->HasPlatformView()) { - presented_layers.PushPlatformViewLayer( - // Covered by HasPlatformView(). - // NOLINTNEXTLINE(bugprone-unchecked-optional-access) - external_view->GetViewIdentifier() - .platform_view_id.value(), // view id - *external_view->GetEmbeddedViewParams() // view params - ); - } + // Submit the scribbled layer to the embedder for presentation. + // + // @warning: Embedder may trample on our OpenGL context here. + { + EmbedderLayers presented_layers(pending_frame_size_, + pending_device_pixel_ratio_, + pending_surface_transformation_); + // In composition order, submit backing stores and platform views to the + // embedder. + for (const auto& view_id : composition_order_) { + // If the external view has a platform view, ask the emebdder to place + // it before the Flutter rendered contents for that interleaving level. + const auto& external_view = pending_views_.at(view_id); + if (external_view->HasPlatformView()) { + presented_layers.PushPlatformViewLayer( + // Covered by HasPlatformView(). + // NOLINTNEXTLINE(bugprone-unchecked-optional-access) + external_view->GetViewIdentifier() + .platform_view_id.value(), // view id + *external_view->GetEmbeddedViewParams() // view params + ); + } - // If the view has engine rendered contents, ask the embedder to place - // Flutter rendered contents for this interleaving level on top of a - // platform view. - if (external_view->HasEngineRenderedContents()) { - const auto& exteral_render_target = - matched_render_targets.at(view_id); - const auto& external_view = pending_views_.at(view_id); - auto rect_list = - external_view->GetEngineRenderedContentsRegion(SkRect::MakeIWH( - pending_frame_size_.width(), pending_frame_size_.height())); - std::vector rects; - rects.reserve(rect_list.size()); - for (const auto& rect : rect_list) { - rects.push_back(rect.roundOut()); - } - presented_layers.PushBackingStoreLayer( - exteral_render_target->GetBackingStore(), rects); + // If the view has engine rendered contents, ask the embedder to place + // Flutter rendered contents for this interleaving level on top of a + // platform view. + if (external_view->HasEngineRenderedContents()) { + const auto& exteral_render_target = matched_render_targets.at(view_id); + const auto& external_view = pending_views_.at(view_id); + auto rect_list = + external_view->GetEngineRenderedContentsRegion(SkRect::MakeIWH( + pending_frame_size_.width(), pending_frame_size_.height())); + std::vector rects; + rects.reserve(rect_list.size()); + for (const auto& rect : rect_list) { + rects.push_back(rect.roundOut()); } + presented_layers.PushBackingStoreLayer( + exteral_render_target->GetBackingStore(), rects); } - - // Flush the layer description down to the embedder for presentation. - // - // @warning: Embedder may trample on our OpenGL context here. - presented_layers.InvokePresentCallback(present_callback_); } - // See why this is necessary in the comment where this collection in - // realized. + // Flush the layer description down to the embedder for presentation. // // @warning: Embedder may trample on our OpenGL context here. - deferred_cleanup_render_targets.clear(); - - // Hold all rendered layers in the render target cache for one frame to - // see if they may be reused next frame. - for (auto& render_target : matched_render_targets) { - if (!avoid_backing_store_cache_) { - render_target_cache_.CacheRenderTarget(render_target.first, - std::move(render_target.second)); - } - } + presented_layers.InvokePresentCallback(present_callback_); + } - frame->Submit(); + // See why this is necessary in the comment where this collection in + // realized. + // + // @warning: Embedder may trample on our OpenGL context here. + deferred_cleanup_render_targets.clear(); + + // Hold all rendered layers in the render target cache for one frame to + // see if they may be reused next frame. + for (auto& render_target : matched_render_targets) { + if (!avoid_backing_store_cache_) { + render_target_cache_.CacheRenderTarget(render_target.first, + std::move(render_target.second)); + } } + frame->Submit(); +} + } // namespace flutter From cba9869c1a92ef32e4beab9bca250340eb973f48 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Thu, 16 Nov 2023 17:08:02 -0800 Subject: [PATCH 09/17] fuchsia compile --- shell/platform/fuchsia/flutter/external_view_embedder.cc | 9 ++++++--- shell/platform/fuchsia/flutter/external_view_embedder.h | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/shell/platform/fuchsia/flutter/external_view_embedder.cc b/shell/platform/fuchsia/flutter/external_view_embedder.cc index ff4d551a99280..8537aea480e29 100644 --- a/shell/platform/fuchsia/flutter/external_view_embedder.cc +++ b/shell/platform/fuchsia/flutter/external_view_embedder.cc @@ -108,13 +108,16 @@ flutter::PostPrerollResult ExternalViewEmbedder::PostPrerollAction( } void ExternalViewEmbedder::BeginFrame( - SkISize frame_size, GrDirectContext* context, - double device_pixel_ratio, const fml::RefPtr& raster_thread_merger) { TRACE_EVENT0("flutter", "ExternalViewEmbedder::BeginFrame"); +} - // Reset for new frame. +// |ExternalViewEmbedder| +void ExternalViewEmbedder::PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) { + // Reset for new view. Reset(); frame_size_ = frame_size; frame_dpr_ = device_pixel_ratio; diff --git a/shell/platform/fuchsia/flutter/external_view_embedder.h b/shell/platform/fuchsia/flutter/external_view_embedder.h index f844a40c7c57f..1078d714c5c8b 100644 --- a/shell/platform/fuchsia/flutter/external_view_embedder.h +++ b/shell/platform/fuchsia/flutter/external_view_embedder.h @@ -72,12 +72,15 @@ class ExternalViewEmbedder final : public flutter::ExternalViewEmbedder { override; // |ExternalViewEmbedder| - void BeginFrame(SkISize frame_size, - GrDirectContext* context, - double device_pixel_ratio, + void BeginFrame(GrDirectContext* context, const fml::RefPtr& raster_thread_merger) override; + // |ExternalViewEmbedder| + void PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio); + // |ExternalViewEmbedder| void EndFrame(bool should_resubmit_frame, const fml::RefPtr& From 17293b017e952a054322b676d82b9a7a4aa72e15 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Thu, 16 Nov 2023 17:45:28 -0800 Subject: [PATCH 10/17] Fix fuchsia compile --- shell/platform/fuchsia/flutter/external_view_embedder.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/fuchsia/flutter/external_view_embedder.h b/shell/platform/fuchsia/flutter/external_view_embedder.h index 1078d714c5c8b..4aca359fc3dd0 100644 --- a/shell/platform/fuchsia/flutter/external_view_embedder.h +++ b/shell/platform/fuchsia/flutter/external_view_embedder.h @@ -79,7 +79,7 @@ class ExternalViewEmbedder final : public flutter::ExternalViewEmbedder { // |ExternalViewEmbedder| void PrepareView(int64_t native_view_id, SkISize frame_size, - double device_pixel_ratio); + double device_pixel_ratio) override; // |ExternalViewEmbedder| void EndFrame(bool should_resubmit_frame, From d4aeba7d1a06a084cf03cf27cb92e8feee9f49e3 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Thu, 16 Nov 2023 20:29:48 -0800 Subject: [PATCH 11/17] Fuchsia compile --- .../flutter/tests/external_view_embedder_unittests.cc | 1 + .../fuchsia/flutter/tests/platform_view_unittest.cc | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/shell/platform/fuchsia/flutter/tests/external_view_embedder_unittests.cc b/shell/platform/fuchsia/flutter/tests/external_view_embedder_unittests.cc index e5c0333025341..5d797e2f1ab95 100644 --- a/shell/platform/fuchsia/flutter/tests/external_view_embedder_unittests.cc +++ b/shell/platform/fuchsia/flutter/tests/external_view_embedder_unittests.cc @@ -58,6 +58,7 @@ constexpr static fuchsia::ui::composition::BlendMode kFirstLayerBlendMode{ fuchsia::ui::composition::BlendMode::SRC}; constexpr static fuchsia::ui::composition::BlendMode kUpperLayerBlendMode{ fuchsia::ui::composition::BlendMode::SRC_OVER}; +constexpr static int64_t kImplicitViewId = 0; class FakeSurfaceProducerSurface : public SurfaceProducerSurface { public: diff --git a/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc b/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc index a3dcb77704fcf..d839ce2313ef1 100644 --- a/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc +++ b/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc @@ -45,12 +45,14 @@ class MockExternalViewEmbedder : public flutter::ExternalViewEmbedder { flutter::DlCanvas* GetRootCanvas() override { return nullptr; } void CancelFrame() override {} - void BeginFrame(SkISize frame_size, - GrDirectContext* context, - double device_pixel_ratio, + void BeginFrame(GrDirectContext* context, const fml::RefPtr& raster_thread_merger) override {} + void PrepareView(int64_t native_view_id, + SkISize frame_size, + double device_pixel_ratio) override {} + void SubmitView(GrDirectContext* context, const std::shared_ptr& aiks_context, std::unique_ptr frame) override {} From 94cff6175e81815c89a83e76b7bb166cb1ff9708 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Tue, 21 Nov 2023 12:05:09 -0800 Subject: [PATCH 12/17] Explain the two IDs --- flow/embedded_views.h | 23 +++++++++++++++---- .../shell_test_external_view_embedder.cc | 2 +- .../shell_test_external_view_embedder.h | 2 +- .../darwin/ios/ios_external_view_embedder.h | 2 +- .../darwin/ios/ios_external_view_embedder.mm | 4 ++-- .../embedder_external_view_embedder.cc | 4 ++-- .../embedder_external_view_embedder.h | 2 +- .../fuchsia/flutter/external_view_embedder.cc | 2 +- .../fuchsia/flutter/external_view_embedder.h | 2 +- .../flutter/tests/platform_view_unittest.cc | 2 +- 10 files changed, 30 insertions(+), 15 deletions(-) diff --git a/flow/embedded_views.h b/flow/embedded_views.h index 528643cd749e8..63c2c6c4bfca3 100644 --- a/flow/embedded_views.h +++ b/flow/embedded_views.h @@ -367,6 +367,21 @@ class DisplayListEmbedderViewSlice : public EmbedderViewSlice { // Used on iOS, Android (hybrid composite mode), and on embedded platforms // that provide a system compositor as part of the project arguments. // +// There are two kinds of "view IDs" in the context of ExternalViewEmbedder, and +// specific names are used to avoid ambiguation: +// +// * ExternalViewEmbedder composites a stack of layers. Each layer's content +// might be from Flutter widgets, or a platform view, which displays platform +// native components. Each platform view is labeled by a view ID, which +// corresponds to the ID from `PlatformViewsRegistry.getNextPlatformViewId` +// from the framework. In the context of `ExternalViewEmbedder`, this ID is +// called platform_view_id. +// * The layers are compositied into a single rectangular surface, displayed by +// taking up an entire native window or part of a window. Each such surface +// is labeled by a view ID, which corresponds to `FlutterView.viewID` from +// dart:ui. In the context of `ExternalViewEmbedder`, this ID is called +// flutter_view_id. +// // The lifecycle of drawing a frame using ExternalViewEmbedder is: // // 1. At the start of a frame, call |BeginFrame|, then |SetUsedThisFrame| to @@ -400,7 +415,7 @@ class ExternalViewEmbedder { const fml::RefPtr& raster_thread_merger) = 0; virtual void PrerollCompositeEmbeddedView( - int64_t view_id, + int64_t platform_view_id, std::unique_ptr params) = 0; // This needs to get called after |Preroll| finishes on the layer tree. @@ -413,10 +428,10 @@ class ExternalViewEmbedder { } // Must be called on the UI thread. - virtual DlCanvas* CompositeEmbeddedView(int64_t view_id) = 0; + virtual DlCanvas* CompositeEmbeddedView(int64_t platform_view_id) = 0; // Prepare for a view to be drawn. - virtual void PrepareView(int64_t native_view_id, + virtual void PrepareView(int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio) = 0; @@ -469,7 +484,7 @@ class ExternalViewEmbedder { // Pushes the platform view id of a visited platform view to a list of // visited platform views. - virtual void PushVisitedPlatformView(int64_t view_id) {} + virtual void PushVisitedPlatformView(int64_t platform_view_id) {} // Pushes a DlImageFilter object to each platform view within a list of // visited platform views. diff --git a/shell/common/shell_test_external_view_embedder.cc b/shell/common/shell_test_external_view_embedder.cc index 1e17c19394bde..add119d9b0386 100644 --- a/shell/common/shell_test_external_view_embedder.cc +++ b/shell/common/shell_test_external_view_embedder.cc @@ -45,7 +45,7 @@ void ShellTestExternalViewEmbedder::BeginFrame( const fml::RefPtr& raster_thread_merger) {} // |ExternalViewEmbedder| -void ShellTestExternalViewEmbedder::PrepareView(int64_t native_view_id, +void ShellTestExternalViewEmbedder::PrepareView(int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio) { visited_platform_views_.clear(); diff --git a/shell/common/shell_test_external_view_embedder.h b/shell/common/shell_test_external_view_embedder.h index 4022319a28271..c0471b4b083e6 100644 --- a/shell/common/shell_test_external_view_embedder.h +++ b/shell/common/shell_test_external_view_embedder.h @@ -51,7 +51,7 @@ class ShellTestExternalViewEmbedder final : public ExternalViewEmbedder { raster_thread_merger) override; // |ExternalViewEmbedder| - void PrepareView(int64_t native_view_id, + void PrepareView(int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio) override; diff --git a/shell/platform/darwin/ios/ios_external_view_embedder.h b/shell/platform/darwin/ios/ios_external_view_embedder.h index e9a1d9347d1a3..bf75c04df239d 100644 --- a/shell/platform/darwin/ios/ios_external_view_embedder.h +++ b/shell/platform/darwin/ios/ios_external_view_embedder.h @@ -36,7 +36,7 @@ class IOSExternalViewEmbedder : public ExternalViewEmbedder { raster_thread_merger) override; // |ExternalViewEmbedder| - void PrepareView(int64_t native_view_id, + void PrepareView(int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio) override; diff --git a/shell/platform/darwin/ios/ios_external_view_embedder.mm b/shell/platform/darwin/ios/ios_external_view_embedder.mm index 619fb96ea6106..2d6aa8d30c049 100644 --- a/shell/platform/darwin/ios/ios_external_view_embedder.mm +++ b/shell/platform/darwin/ios/ios_external_view_embedder.mm @@ -39,12 +39,12 @@ } // |ExternalViewEmbedder| -void IOSExternalViewEmbedder::PrepareView(int64_t native_view_id, +void IOSExternalViewEmbedder::PrepareView(int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio) { // TODO(dkwingsmt): This class only supports rendering into the implicit view. // Properly support multi-view in the future. - FML_DCHECK(native_view_id == kFlutterImplicitViewId); + FML_DCHECK(flutter_view_id == kFlutterImplicitViewId); FML_CHECK(platform_views_controller_); platform_views_controller_->BeginFrame(frame_size); } diff --git a/shell/platform/embedder/embedder_external_view_embedder.cc b/shell/platform/embedder/embedder_external_view_embedder.cc index d8ab3306ebddd..0038a4c30e9e0 100644 --- a/shell/platform/embedder/embedder_external_view_embedder.cc +++ b/shell/platform/embedder/embedder_external_view_embedder.cc @@ -56,13 +56,13 @@ void EmbedderExternalViewEmbedder::BeginFrame( const fml::RefPtr& raster_thread_merger) {} // |ExternalViewEmbedder| -void EmbedderExternalViewEmbedder::PrepareView(int64_t native_view_id, +void EmbedderExternalViewEmbedder::PrepareView(int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio) { // TODO(dkwingsmt): This class only supports rendering into the implicit // view. Properly support multi-view in the future. // https://github.com/flutter/flutter/issues/135530 item 4 - FML_DCHECK(native_view_id == kFlutterImplicitViewId); + FML_DCHECK(flutter_view_id == kFlutterImplicitViewId); Reset(); pending_frame_size_ = frame_size; diff --git a/shell/platform/embedder/embedder_external_view_embedder.h b/shell/platform/embedder/embedder_external_view_embedder.h index e7b3d7dfa6b5c..48db4a6601cd4 100644 --- a/shell/platform/embedder/embedder_external_view_embedder.h +++ b/shell/platform/embedder/embedder_external_view_embedder.h @@ -86,7 +86,7 @@ class EmbedderExternalViewEmbedder final : public ExternalViewEmbedder { raster_thread_merger) override; // |ExternalViewEmbedder| - void PrepareView(int64_t native_view_id, + void PrepareView(int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio) override; diff --git a/shell/platform/fuchsia/flutter/external_view_embedder.cc b/shell/platform/fuchsia/flutter/external_view_embedder.cc index 8537aea480e29..1fc8405e3bb2d 100644 --- a/shell/platform/fuchsia/flutter/external_view_embedder.cc +++ b/shell/platform/fuchsia/flutter/external_view_embedder.cc @@ -114,7 +114,7 @@ void ExternalViewEmbedder::BeginFrame( } // |ExternalViewEmbedder| -void ExternalViewEmbedder::PrepareView(int64_t native_view_id, +void ExternalViewEmbedder::PrepareView(int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio) { // Reset for new view. diff --git a/shell/platform/fuchsia/flutter/external_view_embedder.h b/shell/platform/fuchsia/flutter/external_view_embedder.h index 4aca359fc3dd0..9ed9681a867ca 100644 --- a/shell/platform/fuchsia/flutter/external_view_embedder.h +++ b/shell/platform/fuchsia/flutter/external_view_embedder.h @@ -77,7 +77,7 @@ class ExternalViewEmbedder final : public flutter::ExternalViewEmbedder { raster_thread_merger) override; // |ExternalViewEmbedder| - void PrepareView(int64_t native_view_id, + void PrepareView(int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio) override; diff --git a/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc b/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc index d839ce2313ef1..41a1006edcb67 100644 --- a/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc +++ b/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc @@ -49,7 +49,7 @@ class MockExternalViewEmbedder : public flutter::ExternalViewEmbedder { const fml::RefPtr& raster_thread_merger) override {} - void PrepareView(int64_t native_view_id, + void PrepareView(int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio) override {} From 068793b3af672b9964e9a63e482a9974a8b0efb6 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Tue, 21 Nov 2023 12:08:02 -0800 Subject: [PATCH 13/17] Prepare/SubmitFlutterView --- flow/embedded_views.cc | 2 +- flow/embedded_views.h | 13 +++++++------ shell/common/rasterizer.cc | 8 ++++---- shell/common/shell_test_external_view_embedder.cc | 9 +++++---- shell/common/shell_test_external_view_embedder.h | 15 ++++++++------- .../darwin/ios/ios_external_view_embedder.h | 13 +++++++------ .../darwin/ios/ios_external_view_embedder.mm | 15 ++++++++------- .../embedder/embedder_external_view_embedder.cc | 9 +++++---- .../embedder/embedder_external_view_embedder.h | 13 +++++++------ .../fuchsia/flutter/external_view_embedder.cc | 10 +++++----- .../fuchsia/flutter/external_view_embedder.h | 13 +++++++------ .../flutter/tests/platform_view_unittest.cc | 15 ++++++++------- 12 files changed, 72 insertions(+), 63 deletions(-) diff --git a/flow/embedded_views.cc b/flow/embedded_views.cc index 054bbe8cee953..79893bb001f38 100644 --- a/flow/embedded_views.cc +++ b/flow/embedded_views.cc @@ -42,7 +42,7 @@ bool DisplayListEmbedderViewSlice::recording_ended() { return builder_ == nullptr; } -void ExternalViewEmbedder::SubmitView( +void ExternalViewEmbedder::SubmitFlutterView( GrDirectContext* context, const std::shared_ptr& aiks_context, std::unique_ptr frame) { diff --git a/flow/embedded_views.h b/flow/embedded_views.h index 63c2c6c4bfca3..ed3e6d387e11e 100644 --- a/flow/embedded_views.h +++ b/flow/embedded_views.h @@ -386,7 +386,8 @@ class DisplayListEmbedderViewSlice : public EmbedderViewSlice { // // 1. At the start of a frame, call |BeginFrame|, then |SetUsedThisFrame| to // true. -// 2. For each view to be drawn, call |PrepareView|, then |SubmitView|. +// 2. For each view to be drawn, call |PrepareFlutterView|, then +// |SubmitFlutterView|. // 3. At the end of a frame, if |GetUsedThisFrame| is true, call |EndFrame|. class ExternalViewEmbedder { // TODO(cyanglaz): Make embedder own the `EmbeddedViewParams`. @@ -402,7 +403,7 @@ class ExternalViewEmbedder { // from the on-screen render target. virtual DlCanvas* GetRootCanvas() = 0; - // Call this in-lieu of |SubmitView| to clear pre-roll state and + // Call this in-lieu of |SubmitFlutterView| to clear pre-roll state and // sets the stage for the next pre-roll. virtual void CancelFrame() = 0; @@ -431,16 +432,16 @@ class ExternalViewEmbedder { virtual DlCanvas* CompositeEmbeddedView(int64_t platform_view_id) = 0; // Prepare for a view to be drawn. - virtual void PrepareView(int64_t flutter_view_id, - SkISize frame_size, - double device_pixel_ratio) = 0; + virtual void PrepareFlutterView(int64_t flutter_view_id, + SkISize frame_size, + double device_pixel_ratio) = 0; // Implementers must submit the frame by calling frame.Submit(). // // This method can mutate the root Skia canvas before submitting the frame. // // It can also allocate frames for overlay surfaces to compose hybrid views. - virtual void SubmitView( + virtual void SubmitFlutterView( GrDirectContext* context, const std::shared_ptr& aiks_context, std::unique_ptr frame); diff --git a/shell/common/rasterizer.cc b/shell/common/rasterizer.cc index 14eb0a82db421..d8daf99bc4637 100644 --- a/shell/common/rasterizer.cc +++ b/shell/common/rasterizer.cc @@ -656,8 +656,8 @@ DrawSurfaceStatus Rasterizer::DrawToSurfaceUnsafe( DlCanvas* embedder_root_canvas = nullptr; if (external_view_embedder_) { - external_view_embedder_->PrepareView(view_id, layer_tree.frame_size(), - device_pixel_ratio); + external_view_embedder_->PrepareFlutterView( + view_id, layer_tree.frame_size(), device_pixel_ratio); // TODO(dkwingsmt): Add view ID here. embedder_root_canvas = external_view_embedder_->GetRootCanvas(); } @@ -698,7 +698,7 @@ DrawSurfaceStatus Rasterizer::DrawToSurfaceUnsafe( // for accurate performance metrics. if (frame->framebuffer_info().supports_partial_repaint && !layer_tree.is_leaf_layer_tracing_enabled()) { - // Disable partial repaint if external_view_embedder_ SubmitView is + // Disable partial repaint if external_view_embedder_ SubmitFlutterView is // involved - ExternalViewEmbedder unconditionally clears the entire // surface and also partial repaint with platform view present is // something that still need to be figured out. @@ -744,7 +744,7 @@ DrawSurfaceStatus Rasterizer::DrawToSurfaceUnsafe( if (external_view_embedder_ && (!raster_thread_merger_ || raster_thread_merger_->IsMerged())) { FML_DCHECK(!frame->IsSubmitted()); - external_view_embedder_->SubmitView( + external_view_embedder_->SubmitFlutterView( surface_->GetContext(), surface_->GetAiksContext(), std::move(frame)); } else { frame->Submit(); diff --git a/shell/common/shell_test_external_view_embedder.cc b/shell/common/shell_test_external_view_embedder.cc index add119d9b0386..d03a2a57cde89 100644 --- a/shell/common/shell_test_external_view_embedder.cc +++ b/shell/common/shell_test_external_view_embedder.cc @@ -45,9 +45,10 @@ void ShellTestExternalViewEmbedder::BeginFrame( const fml::RefPtr& raster_thread_merger) {} // |ExternalViewEmbedder| -void ShellTestExternalViewEmbedder::PrepareView(int64_t flutter_view_id, - SkISize frame_size, - double device_pixel_ratio) { +void ShellTestExternalViewEmbedder::PrepareFlutterView( + int64_t flutter_view_id, + SkISize frame_size, + double device_pixel_ratio) { visited_platform_views_.clear(); mutators_stacks_.clear(); current_composition_params_.clear(); @@ -92,7 +93,7 @@ DlCanvas* ShellTestExternalViewEmbedder::CompositeEmbeddedView( } // |ExternalViewEmbedder| -void ShellTestExternalViewEmbedder::SubmitView( +void ShellTestExternalViewEmbedder::SubmitFlutterView( GrDirectContext* context, const std::shared_ptr& aiks_context, std::unique_ptr frame) { diff --git a/shell/common/shell_test_external_view_embedder.h b/shell/common/shell_test_external_view_embedder.h index c0471b4b083e6..f378dce348555 100644 --- a/shell/common/shell_test_external_view_embedder.h +++ b/shell/common/shell_test_external_view_embedder.h @@ -28,7 +28,7 @@ class ShellTestExternalViewEmbedder final : public ExternalViewEmbedder { // returns the new `post_preroll_result`. void UpdatePostPrerollResult(PostPrerollResult post_preroll_result); - // Gets the number of times the SubmitView method has been called in + // Gets the number of times the SubmitFlutterView method has been called in // the external view embedder. int GetSubmittedFrameCount(); @@ -51,9 +51,9 @@ class ShellTestExternalViewEmbedder final : public ExternalViewEmbedder { raster_thread_merger) override; // |ExternalViewEmbedder| - void PrepareView(int64_t flutter_view_id, - SkISize frame_size, - double device_pixel_ratio) override; + void PrepareFlutterView(int64_t flutter_view_id, + SkISize frame_size, + double device_pixel_ratio) override; // |ExternalViewEmbedder| void PrerollCompositeEmbeddedView( @@ -77,9 +77,10 @@ class ShellTestExternalViewEmbedder final : public ExternalViewEmbedder { const SkRect& filter_rect) override; // |ExternalViewEmbedder| - void SubmitView(GrDirectContext* context, - const std::shared_ptr& aiks_context, - std::unique_ptr frame) override; + void SubmitFlutterView( + GrDirectContext* context, + const std::shared_ptr& aiks_context, + std::unique_ptr frame) override; // |ExternalViewEmbedder| void EndFrame(bool should_resubmit_frame, diff --git a/shell/platform/darwin/ios/ios_external_view_embedder.h b/shell/platform/darwin/ios/ios_external_view_embedder.h index bf75c04df239d..8a47eaea31639 100644 --- a/shell/platform/darwin/ios/ios_external_view_embedder.h +++ b/shell/platform/darwin/ios/ios_external_view_embedder.h @@ -36,9 +36,9 @@ class IOSExternalViewEmbedder : public ExternalViewEmbedder { raster_thread_merger) override; // |ExternalViewEmbedder| - void PrepareView(int64_t flutter_view_id, - SkISize frame_size, - double device_pixel_ratio) override; + void PrepareFlutterView(int64_t flutter_view_id, + SkISize frame_size, + double device_pixel_ratio) override; // |ExternalViewEmbedder| void PrerollCompositeEmbeddedView( @@ -54,9 +54,10 @@ class IOSExternalViewEmbedder : public ExternalViewEmbedder { DlCanvas* CompositeEmbeddedView(int64_t view_id) override; // |ExternalViewEmbedder| - void SubmitView(GrDirectContext* context, - const std::shared_ptr& aiks_context, - std::unique_ptr frame) override; + void SubmitFlutterView( + GrDirectContext* context, + const std::shared_ptr& aiks_context, + std::unique_ptr frame) override; // |ExternalViewEmbedder| void EndFrame(bool should_resubmit_frame, diff --git a/shell/platform/darwin/ios/ios_external_view_embedder.mm b/shell/platform/darwin/ios/ios_external_view_embedder.mm index 2d6aa8d30c049..79298c3290017 100644 --- a/shell/platform/darwin/ios/ios_external_view_embedder.mm +++ b/shell/platform/darwin/ios/ios_external_view_embedder.mm @@ -39,9 +39,9 @@ } // |ExternalViewEmbedder| -void IOSExternalViewEmbedder::PrepareView(int64_t flutter_view_id, - SkISize frame_size, - double device_pixel_ratio) { +void IOSExternalViewEmbedder::PrepareFlutterView(int64_t flutter_view_id, + SkISize frame_size, + double device_pixel_ratio) { // TODO(dkwingsmt): This class only supports rendering into the implicit view. // Properly support multi-view in the future. FML_DCHECK(flutter_view_id == kFlutterImplicitViewId); @@ -75,10 +75,11 @@ } // |ExternalViewEmbedder| -void IOSExternalViewEmbedder::SubmitView(GrDirectContext* context, - const std::shared_ptr& aiks_context, - std::unique_ptr frame) { - TRACE_EVENT0("flutter", "IOSExternalViewEmbedder::SubmitView"); +void IOSExternalViewEmbedder::SubmitFlutterView( + GrDirectContext* context, + const std::shared_ptr& aiks_context, + std::unique_ptr frame) { + TRACE_EVENT0("flutter", "IOSExternalViewEmbedder::SubmitFlutterView"); FML_CHECK(platform_views_controller_); platform_views_controller_->SubmitFrame(context, ios_context_, std::move(frame)); TRACE_EVENT0("flutter", "IOSExternalViewEmbedder::DidSubmitFrame"); diff --git a/shell/platform/embedder/embedder_external_view_embedder.cc b/shell/platform/embedder/embedder_external_view_embedder.cc index 0038a4c30e9e0..a3bbb383b2699 100644 --- a/shell/platform/embedder/embedder_external_view_embedder.cc +++ b/shell/platform/embedder/embedder_external_view_embedder.cc @@ -56,9 +56,10 @@ void EmbedderExternalViewEmbedder::BeginFrame( const fml::RefPtr& raster_thread_merger) {} // |ExternalViewEmbedder| -void EmbedderExternalViewEmbedder::PrepareView(int64_t flutter_view_id, - SkISize frame_size, - double device_pixel_ratio) { +void EmbedderExternalViewEmbedder::PrepareFlutterView( + int64_t flutter_view_id, + SkISize frame_size, + double device_pixel_ratio) { // TODO(dkwingsmt): This class only supports rendering into the implicit // view. Properly support multi-view in the future. // https://github.com/flutter/flutter/issues/135530 item 4 @@ -131,7 +132,7 @@ static FlutterBackingStoreConfig MakeBackingStoreConfig( } // |ExternalViewEmbedder| -void EmbedderExternalViewEmbedder::SubmitView( +void EmbedderExternalViewEmbedder::SubmitFlutterView( GrDirectContext* context, const std::shared_ptr& aiks_context, std::unique_ptr frame) { diff --git a/shell/platform/embedder/embedder_external_view_embedder.h b/shell/platform/embedder/embedder_external_view_embedder.h index 48db4a6601cd4..ae7cd4fecd318 100644 --- a/shell/platform/embedder/embedder_external_view_embedder.h +++ b/shell/platform/embedder/embedder_external_view_embedder.h @@ -86,9 +86,9 @@ class EmbedderExternalViewEmbedder final : public ExternalViewEmbedder { raster_thread_merger) override; // |ExternalViewEmbedder| - void PrepareView(int64_t flutter_view_id, - SkISize frame_size, - double device_pixel_ratio) override; + void PrepareFlutterView(int64_t flutter_view_id, + SkISize frame_size, + double device_pixel_ratio) override; // |ExternalViewEmbedder| void PrerollCompositeEmbeddedView( @@ -99,9 +99,10 @@ class EmbedderExternalViewEmbedder final : public ExternalViewEmbedder { DlCanvas* CompositeEmbeddedView(int64_t view_id) override; // |ExternalViewEmbedder| - void SubmitView(GrDirectContext* context, - const std::shared_ptr& aiks_context, - std::unique_ptr frame) override; + void SubmitFlutterView( + GrDirectContext* context, + const std::shared_ptr& aiks_context, + std::unique_ptr frame) override; // |ExternalViewEmbedder| DlCanvas* GetRootCanvas() override; diff --git a/shell/platform/fuchsia/flutter/external_view_embedder.cc b/shell/platform/fuchsia/flutter/external_view_embedder.cc index 1fc8405e3bb2d..8edaa41366e61 100644 --- a/shell/platform/fuchsia/flutter/external_view_embedder.cc +++ b/shell/platform/fuchsia/flutter/external_view_embedder.cc @@ -114,9 +114,9 @@ void ExternalViewEmbedder::BeginFrame( } // |ExternalViewEmbedder| -void ExternalViewEmbedder::PrepareView(int64_t flutter_view_id, - SkISize frame_size, - double device_pixel_ratio) { +void ExternalViewEmbedder::PrepareFlutterView(int64_t flutter_view_id, + SkISize frame_size, + double device_pixel_ratio) { // Reset for new view. Reset(); frame_size_ = frame_size; @@ -135,11 +135,11 @@ void ExternalViewEmbedder::EndFrame( TRACE_EVENT0("flutter", "ExternalViewEmbedder::EndFrame"); } -void ExternalViewEmbedder::SubmitView( +void ExternalViewEmbedder::SubmitFlutterView( GrDirectContext* context, const std::shared_ptr& aiks_context, std::unique_ptr frame) { - TRACE_EVENT0("flutter", "ExternalViewEmbedder::SubmitView"); + TRACE_EVENT0("flutter", "ExternalViewEmbedder::SubmitFlutterView"); std::vector> frame_surfaces; std::unordered_map frame_surface_indices; diff --git a/shell/platform/fuchsia/flutter/external_view_embedder.h b/shell/platform/fuchsia/flutter/external_view_embedder.h index 9ed9681a867ca..382cadce9c0a2 100644 --- a/shell/platform/fuchsia/flutter/external_view_embedder.h +++ b/shell/platform/fuchsia/flutter/external_view_embedder.h @@ -77,9 +77,9 @@ class ExternalViewEmbedder final : public flutter::ExternalViewEmbedder { raster_thread_merger) override; // |ExternalViewEmbedder| - void PrepareView(int64_t flutter_view_id, - SkISize frame_size, - double device_pixel_ratio) override; + void PrepareFlutterView(int64_t flutter_view_id, + SkISize frame_size, + double device_pixel_ratio) override; // |ExternalViewEmbedder| void EndFrame(bool should_resubmit_frame, @@ -87,9 +87,10 @@ class ExternalViewEmbedder final : public flutter::ExternalViewEmbedder { raster_thread_merger) override; // |ExternalViewEmbedder| - void SubmitView(GrDirectContext* context, - const std::shared_ptr& aiks_context, - std::unique_ptr frame) override; + void SubmitFlutterView( + GrDirectContext* context, + const std::shared_ptr& aiks_context, + std::unique_ptr frame) override; // |ExternalViewEmbedder| void CancelFrame() override { Reset(); } diff --git a/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc b/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc index 41a1006edcb67..ec494d2bf5320 100644 --- a/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc +++ b/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc @@ -49,13 +49,14 @@ class MockExternalViewEmbedder : public flutter::ExternalViewEmbedder { const fml::RefPtr& raster_thread_merger) override {} - void PrepareView(int64_t flutter_view_id, - SkISize frame_size, - double device_pixel_ratio) override {} - - void SubmitView(GrDirectContext* context, - const std::shared_ptr& aiks_context, - std::unique_ptr frame) override {} + void PrepareFlutterView(int64_t flutter_view_id, + SkISize frame_size, + double device_pixel_ratio) override {} + + void SubmitFlutterView( + GrDirectContext* context, + const std::shared_ptr& aiks_context, + std::unique_ptr frame) override {} void PrerollCompositeEmbeddedView( int64_t view_id, From de5f205694fb49191701dd9b0c7c916fa54769a4 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 27 Nov 2023 13:18:52 -0800 Subject: [PATCH 14/17] Fix lint error --- flow/testing/mock_embedder.cc | 2 +- flow/testing/mock_embedder.h | 2 +- shell/common/rasterizer_unittests.cc | 26 ++++++++++--------- .../external_view_embedder.cc | 4 +-- .../external_view_embedder.h | 2 +- shell/testing/tester_main.cc | 2 +- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/flow/testing/mock_embedder.cc b/flow/testing/mock_embedder.cc index a7a4ade27e4d0..3cec9fecdbf34 100644 --- a/flow/testing/mock_embedder.cc +++ b/flow/testing/mock_embedder.cc @@ -29,7 +29,7 @@ void MockViewEmbedder::BeginFrame( const fml::RefPtr& raster_thread_merger) {} // |ExternalViewEmbedder| -void MockViewEmbedder::PrepareFlutterView(int64_t native_view_id, +void MockViewEmbedder::PrepareFlutterView(int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio) {} diff --git a/flow/testing/mock_embedder.h b/flow/testing/mock_embedder.h index ed06e82a45d4e..cd16358234095 100644 --- a/flow/testing/mock_embedder.h +++ b/flow/testing/mock_embedder.h @@ -30,7 +30,7 @@ class MockViewEmbedder : public ExternalViewEmbedder { raster_thread_merger) override; // |ExternalViewEmbedder| - void PrepareFlutterView(int64_t native_view_id, + void PrepareFlutterView(int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio) override; diff --git a/shell/common/rasterizer_unittests.cc b/shell/common/rasterizer_unittests.cc index 5f21da62ed147..7265bb887578f 100644 --- a/shell/common/rasterizer_unittests.cc +++ b/shell/common/rasterizer_unittests.cc @@ -97,7 +97,7 @@ class MockExternalViewEmbedder : public ExternalViewEmbedder { (override)); MOCK_METHOD(void, PrepareFlutterView, - (int64_t native_view_id, + (int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio), (override)); @@ -224,7 +224,7 @@ TEST(RasterizerTest, fml::RefPtr(nullptr))) .Times(1); EXPECT_CALL(*external_view_embedder, - PrepareFlutterView(/*native_view_id=*/kImplicitViewId, + PrepareFlutterView(/*flutter_view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), /*device_pixel_ratio=*/2.0)) .Times(1); @@ -300,7 +300,7 @@ TEST( /*raster_thread_merger=*/_)) .Times(1); EXPECT_CALL(*external_view_embedder, - PrepareFlutterView(/*native_view_id=*/kImplicitViewId, + PrepareFlutterView(/*flutter_view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), /*device_pixel_ratio=*/2.0)) .Times(1); @@ -379,7 +379,7 @@ TEST( /*raster_thread_merger=*/_)) .Times(1); EXPECT_CALL(*external_view_embedder, - PrepareFlutterView(/*native_view_id=*/kImplicitViewId, + PrepareFlutterView(/*flutter_view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), /*device_pixel_ratio=*/2.0)) .Times(1); @@ -461,7 +461,7 @@ TEST(RasterizerTest, /*raster_thread_merger=*/_)) .Times(2); EXPECT_CALL(*external_view_embedder, - PrepareFlutterView(/*native_view_id=*/kImplicitViewId, + PrepareFlutterView(/*flutter_view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), /*device_pixel_ratio=*/2.0)) .Times(2); @@ -576,7 +576,7 @@ TEST(RasterizerTest, externalViewEmbedderDoesntEndFrameWhenNotUsedThisFrame) { /*raster_thread_merger=*/_)) .Times(0); EXPECT_CALL(*external_view_embedder, - PrepareFlutterView(/*native_view_id=*/kImplicitViewId, + PrepareFlutterView(/*flutter_view_id=*/kImplicitViewId, /*frame_size=*/SkISize(), /*device_pixel_ratio=*/2.0)) .Times(0); @@ -696,13 +696,15 @@ TEST(RasterizerTest, drawMultipleViewsWithExternalViewEmbedder) { EXPECT_CALL(*external_view_embedder, BeginFrame(/*context=*/nullptr, /*raster_thread_merger=*/_)) .Times(1); - EXPECT_CALL(*external_view_embedder, - PrepareFlutterView(/*native_view_id=*/0, /*frame_size=*/SkISize(), - /*device_pixel_ratio=*/1.5)) + EXPECT_CALL( + *external_view_embedder, + PrepareFlutterView(/*flutter_view_id=*/0, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/1.5)) .Times(1); - EXPECT_CALL(*external_view_embedder, - PrepareFlutterView(/*native_view_id=*/1, /*frame_size=*/SkISize(), - /*device_pixel_ratio=*/2.0)) + EXPECT_CALL( + *external_view_embedder, + PrepareFlutterView(/*flutter_view_id=*/1, /*frame_size=*/SkISize(), + /*device_pixel_ratio=*/2.0)) .Times(1); EXPECT_CALL(*external_view_embedder, SubmitFlutterView).Times(2); EXPECT_CALL(*external_view_embedder, EndFrame(/*should_resubmit_frame=*/false, diff --git a/shell/platform/android/external_view_embedder/external_view_embedder.cc b/shell/platform/android/external_view_embedder/external_view_embedder.cc index ed58c0286f5f0..2ec5a9ac198a7 100644 --- a/shell/platform/android/external_view_embedder/external_view_embedder.cc +++ b/shell/platform/android/external_view_embedder/external_view_embedder.cc @@ -268,12 +268,12 @@ void AndroidExternalViewEmbedder::BeginFrame( // |ExternalViewEmbedder| void AndroidExternalViewEmbedder::PrepareFlutterView( - int64_t native_view_id, + int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio) { // TODO(dkwingsmt): This class only supports rendering into the implicit view. // Properly support multi-view in the future. - FML_DCHECK(native_view_id == kFlutterImplicitViewId); + FML_DCHECK(flutter_view_id == kFlutterImplicitViewId); Reset(); // The surface size changed. Therefore, destroy existing surfaces as diff --git a/shell/platform/android/external_view_embedder/external_view_embedder.h b/shell/platform/android/external_view_embedder/external_view_embedder.h index 84f8802c949b6..98b02daa80b7e 100644 --- a/shell/platform/android/external_view_embedder/external_view_embedder.h +++ b/shell/platform/android/external_view_embedder/external_view_embedder.h @@ -62,7 +62,7 @@ class AndroidExternalViewEmbedder final : public ExternalViewEmbedder { raster_thread_merger) override; // |ExternalViewEmbedder| - void PrepareFlutterView(int64_t native_view_id, + void PrepareFlutterView(int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio) override; diff --git a/shell/testing/tester_main.cc b/shell/testing/tester_main.cc index 2a79d372d03a0..f04cbde7f9700 100644 --- a/shell/testing/tester_main.cc +++ b/shell/testing/tester_main.cc @@ -143,7 +143,7 @@ class TesterExternalViewEmbedder : public ExternalViewEmbedder { raster_thread_merger) override {} // |ExternalViewEmbedder| - void PrepareFlutterView(int64_t native_view_id, + void PrepareFlutterView(int64_t flutter_view_id, SkISize frame_size, double device_pixel_ratio) override {} From 559a043d134e69cdc52500b0405aa3b18e3ae9ce Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 27 Nov 2023 13:46:30 -0800 Subject: [PATCH 15/17] Fix fuchsia --- .../flutter/tests/external_view_embedder_unittests.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/shell/platform/fuchsia/flutter/tests/external_view_embedder_unittests.cc b/shell/platform/fuchsia/flutter/tests/external_view_embedder_unittests.cc index 5d797e2f1ab95..93b20a5edc6c8 100644 --- a/shell/platform/fuchsia/flutter/tests/external_view_embedder_unittests.cc +++ b/shell/platform/fuchsia/flutter/tests/external_view_embedder_unittests.cc @@ -328,7 +328,8 @@ void DrawSimpleFrame(ExternalViewEmbedder& external_view_embedder, float frame_dpr, std::function draw_callback) { external_view_embedder.BeginFrame(nullptr, nullptr); - external_view_embedder.PrepareView(kImplicitViewId, frame_size, frame_dpr); + external_view_embedder.PrepareFlutterView(kImplicitViewId, frame_size, + frame_dpr); { flutter::DlCanvas* root_canvas = external_view_embedder.GetRootCanvas(); external_view_embedder.PostPrerollAction(nullptr); @@ -337,7 +338,7 @@ void DrawSimpleFrame(ExternalViewEmbedder& external_view_embedder, external_view_embedder.EndFrame(false, nullptr); flutter::SurfaceFrame::FramebufferInfo framebuffer_info; framebuffer_info.supports_readback = true; - external_view_embedder.SubmitView( + external_view_embedder.SubmitFlutterView( nullptr, nullptr, std::make_unique( nullptr, std::move(framebuffer_info), @@ -355,7 +356,8 @@ void DrawFrameWithView( std::function background_draw_callback, std::function overlay_draw_callback) { external_view_embedder.BeginFrame(nullptr, nullptr); - external_view_embedder.PrepareView(kImplicitViewId, frame_size, frame_dpr); + external_view_embedder.PrepareFlutterView(kImplicitViewId, frame_size, + frame_dpr); { flutter::DlCanvas* root_canvas = external_view_embedder.GetRootCanvas(); external_view_embedder.PrerollCompositeEmbeddedView( @@ -369,7 +371,7 @@ void DrawFrameWithView( external_view_embedder.EndFrame(false, nullptr); flutter::SurfaceFrame::FramebufferInfo framebuffer_info; framebuffer_info.supports_readback = true; - external_view_embedder.SubmitView( + external_view_embedder.SubmitFlutterView( nullptr, nullptr, std::make_unique( nullptr, std::move(framebuffer_info), From 5ad5661d1c6f984b4c57dc74e495a01264cc1dbc Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 4 Dec 2023 11:55:28 -0800 Subject: [PATCH 16/17] ignore deprecated member on hashvalues --- lib/web_ui/test/engine/hash_codes_test.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/web_ui/test/engine/hash_codes_test.dart b/lib/web_ui/test/engine/hash_codes_test.dart index 7e34ed20db30d..7c0c7afbbdc93 100644 --- a/lib/web_ui/test/engine/hash_codes_test.dart +++ b/lib/web_ui/test/engine/hash_codes_test.dart @@ -16,6 +16,10 @@ void main() { internalBootstrapBrowserTest(() => testMain); } +// Ignoring the deprecated member use because we're specifically testing +// deprecated API. +// ignore: deprecated_member_use + void testMain() { test('hashValues and hashList can hash lots of huge values effectively', () { final int hashValueFromArgs = hashValues( From 830ad4ca9401ca619c55afc16ad95ad4a344b02a Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 4 Dec 2023 11:56:50 -0800 Subject: [PATCH 17/17] Remove empty trace --- shell/platform/darwin/ios/ios_external_view_embedder.mm | 4 +--- shell/platform/fuchsia/flutter/external_view_embedder.cc | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/shell/platform/darwin/ios/ios_external_view_embedder.mm b/shell/platform/darwin/ios/ios_external_view_embedder.mm index 79298c3290017..2e13055c2de01 100644 --- a/shell/platform/darwin/ios/ios_external_view_embedder.mm +++ b/shell/platform/darwin/ios/ios_external_view_embedder.mm @@ -34,9 +34,7 @@ // |ExternalViewEmbedder| void IOSExternalViewEmbedder::BeginFrame( GrDirectContext* context, - const fml::RefPtr& raster_thread_merger) { - TRACE_EVENT0("flutter", "IOSExternalViewEmbedder::BeginFrame"); -} + const fml::RefPtr& raster_thread_merger) {} // |ExternalViewEmbedder| void IOSExternalViewEmbedder::PrepareFlutterView(int64_t flutter_view_id, diff --git a/shell/platform/fuchsia/flutter/external_view_embedder.cc b/shell/platform/fuchsia/flutter/external_view_embedder.cc index 8edaa41366e61..5900799c8c577 100644 --- a/shell/platform/fuchsia/flutter/external_view_embedder.cc +++ b/shell/platform/fuchsia/flutter/external_view_embedder.cc @@ -109,9 +109,7 @@ flutter::PostPrerollResult ExternalViewEmbedder::PostPrerollAction( void ExternalViewEmbedder::BeginFrame( GrDirectContext* context, - const fml::RefPtr& raster_thread_merger) { - TRACE_EVENT0("flutter", "ExternalViewEmbedder::BeginFrame"); -} + const fml::RefPtr& raster_thread_merger) {} // |ExternalViewEmbedder| void ExternalViewEmbedder::PrepareFlutterView(int64_t flutter_view_id,