From 9e9da76387338bc478608f259853b4b0730bd2e2 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 7 Nov 2022 11:08:42 -0800 Subject: [PATCH 1/2] Impl and test --- .../darwin/macos/framework/Source/FlutterCompositor.h | 8 +++++--- .../darwin/macos/framework/Source/FlutterEngine.mm | 6 +++++- .../darwin/macos/framework/Source/FlutterGLCompositor.h | 8 +++++--- .../darwin/macos/framework/Source/FlutterGLCompositor.mm | 9 ++++----- .../framework/Source/FlutterGLCompositorUnittests.mm | 2 +- .../macos/framework/Source/FlutterMetalCompositor.h | 9 ++++++--- .../macos/framework/Source/FlutterMetalCompositor.mm | 9 ++++----- .../framework/Source/FlutterMetalCompositorUnittests.mm | 2 +- 8 files changed, 31 insertions(+), 22 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h index 498d8c85e378a..9a7249d7dc1d6 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h @@ -47,10 +47,12 @@ class FlutterCompositor { virtual bool CollectBackingStore( const FlutterBackingStore* backing_store) = 0; - // Presents the FlutterLayers by updating FlutterView(s) using the - // layer content. + // Presents the FlutterLayers by updating the FlutterView specified by + // `view_id` using the layer content. // Present sets frame_started_ to false. - virtual bool Present(const FlutterLayer** layers, size_t layers_count) = 0; + virtual bool Present(uint64_t view_id, + const FlutterLayer** layers, + size_t layers_count) = 0; using PresentCallback = std::function; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm index d8bf40e3b2cf9..8a1dcbcc0e46a 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm @@ -478,7 +478,11 @@ - (FlutterCompositor*)createFlutterCompositor { size_t layers_count, // void* user_data // ) { - return reinterpret_cast(user_data)->Present(layers, layers_count); + // TODO(dkwingsmt): The engine only supports single-view for now. As more + // classes are gradually converted to multi-view, it should get the view ID + // from somewhere, and send the ID to `Present`. + return reinterpret_cast(user_data)->Present(kFlutterDefaultViewId, + layers, layers_count); }; _compositor.avoid_backing_store_cache = true; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.h b/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.h index ef704134429d9..a7a88e672f058 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.h @@ -41,10 +41,12 @@ class FlutterGLCompositor : public FlutterCompositor { // Releases the memory for any state used by the backing store. bool CollectBackingStore(const FlutterBackingStore* backing_store) override; - // Presents the FlutterLayers by updating FlutterView(s) using the - // layer content. + // Presents the FlutterLayers by updating the FlutterView specified by + // `view_id` using the layer content. // Present sets frame_started_ to false. - bool Present(const FlutterLayer** layers, size_t layers_count) override; + bool Present(uint64_t view_id, + const FlutterLayer** layers, + size_t layers_count) override; private: const NSOpenGLContext* open_gl_context_; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.mm b/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.mm index 8ab6a993f8c86..e67cc28be8d05 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.mm @@ -77,11 +77,10 @@ return true; } -bool FlutterGLCompositor::Present(const FlutterLayer** layers, size_t layers_count) { - // TODO(dkwingsmt): This class only supports single-view for now. As more - // classes are gradually converted to multi-view, it should get the view ID - // from somewhere. - FlutterView* view = GetView(kFlutterDefaultViewId); +bool FlutterGLCompositor::Present(uint64_t view_id, + const FlutterLayer** layers, + size_t layers_count) { + FlutterView* view = GetView(view_id); if (!view) { return false; } diff --git a/shell/platform/darwin/macos/framework/Source/FlutterGLCompositorUnittests.mm b/shell/platform/darwin/macos/framework/Source/FlutterGLCompositorUnittests.mm index 82b9a629652db..46de7725298ff 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterGLCompositorUnittests.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterGLCompositorUnittests.mm @@ -56,7 +56,7 @@ - (nullable FlutterView*)getView:(uint64_t)viewId { return true; }); - ASSERT_TRUE(macos_compositor->Present(nil, 0)); + ASSERT_TRUE(macos_compositor->Present(0, nil, 0)); ASSERT_TRUE(flag); } diff --git a/shell/platform/darwin/macos/framework/Source/FlutterMetalCompositor.h b/shell/platform/darwin/macos/framework/Source/FlutterMetalCompositor.h index 9a4d462d81f2c..b2406baf91dea 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterMetalCompositor.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterMetalCompositor.h @@ -40,9 +40,12 @@ class FlutterMetalCompositor : public FlutterCompositor { // for this FlutterBackingStore object in CreateBackingStore. bool CollectBackingStore(const FlutterBackingStore* backing_store) override; - // Composites the provided FlutterLayer objects and presents the composited - // frame to the FlutterView(s). - bool Present(const FlutterLayer** layers, size_t layers_count) override; + // Presents the FlutterLayers by updating the FlutterView specified by + // `view_id` using the layer content. + // Present sets frame_started_ to false. + bool Present(uint64_t view_id, + const FlutterLayer** layers, + size_t layers_count) override; private: // Presents the platform view layer represented by `layer`. `layer_index` is diff --git a/shell/platform/darwin/macos/framework/Source/FlutterMetalCompositor.mm b/shell/platform/darwin/macos/framework/Source/FlutterMetalCompositor.mm index 74eae76f8e885..2e8ff9b176c5b 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterMetalCompositor.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterMetalCompositor.mm @@ -80,11 +80,10 @@ return true; } -bool FlutterMetalCompositor::Present(const FlutterLayer** layers, size_t layers_count) { - // TODO(dkwingsmt): This class only supports single-view for now. As more - // classes are gradually converted to multi-view, it should get the view ID - // from somewhere. - FlutterView* view = GetView(kFlutterDefaultViewId); +bool FlutterMetalCompositor::Present(uint64_t view_id, + const FlutterLayer** layers, + size_t layers_count) { + FlutterView* view = GetView(view_id); if (!view) { return false; } diff --git a/shell/platform/darwin/macos/framework/Source/FlutterMetalCompositorUnittests.mm b/shell/platform/darwin/macos/framework/Source/FlutterMetalCompositorUnittests.mm index 4a2884cf61432..4084a61395d3f 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterMetalCompositorUnittests.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterMetalCompositorUnittests.mm @@ -73,7 +73,7 @@ - (nullable FlutterView*)getView:(uint64_t)viewId { return true; }); - ASSERT_TRUE(macos_compositor->Present(nil, 0)); + ASSERT_TRUE(macos_compositor->Present(0, nil, 0)); ASSERT_TRUE(flag); } From 2f90ef4ac6dbc42248c5c2559b8392c8a12f3e0b Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 7 Nov 2022 16:43:38 -0800 Subject: [PATCH 2/2] Change to default view --- .../platform/darwin/macos/framework/Source/FlutterEngine.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm index 8a1dcbcc0e46a..8e7f4f53b922d 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm @@ -478,9 +478,9 @@ - (FlutterCompositor*)createFlutterCompositor { size_t layers_count, // void* user_data // ) { - // TODO(dkwingsmt): The engine only supports single-view for now. As more - // classes are gradually converted to multi-view, it should get the view ID - // from somewhere, and send the ID to `Present`. + // TODO(dkwingsmt): This callback only supports single-view, therefore it + // only operates on the default view. To support multi-view, we need a new + // callback that also receives a view ID. return reinterpret_cast(user_data)->Present(kFlutterDefaultViewId, layers, layers_count); };