From 363045886d499de653cbab1f9fd9678d72ba5da2 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Fri, 30 Jun 2023 13:05:11 -0700 Subject: [PATCH 01/17] Impl --- runtime/runtime_controller.cc | 4 +- .../Headers/FlutterPluginRegistrarMacOS.h | 4 +- .../framework/Source/FlutterCompositor.mm | 2 +- .../framework/Source/FlutterCompositorTest.mm | 18 ++++----- .../macos/framework/Source/FlutterEngine.mm | 38 +++++++++---------- .../framework/Source/FlutterEngineTest.mm | 6 +-- .../framework/Source/FlutterEngine_Internal.h | 8 ++-- .../macos/framework/Source/FlutterView.h | 2 +- .../Source/FlutterViewEngineProviderTest.mm | 2 +- .../macos/framework/Source/FlutterViewTest.mm | 4 +- 10 files changed, 43 insertions(+), 45 deletions(-) diff --git a/runtime/runtime_controller.cc b/runtime/runtime_controller.cc index 5ffd02d099139..4837c5946c532 100644 --- a/runtime/runtime_controller.cc +++ b/runtime/runtime_controller.cc @@ -20,7 +20,7 @@ namespace flutter { -const uint64_t kFlutterDefaultViewId = 0llu; +const uint64_t kFlutterImplicitViewId = 0llu; RuntimeController::RuntimeController(RuntimeDelegate& p_client, const TaskRunners& task_runners) @@ -320,7 +320,7 @@ void RuntimeController::ScheduleFrame() { // |PlatformConfigurationClient| void RuntimeController::Render(Scene* scene) { // TODO(dkwingsmt): Currently only supports a single window. - int64_t view_id = kFlutterDefaultViewId; + int64_t view_id = kFlutterImplicitViewId; auto window = UIDartState::Current()->platform_configuration()->get_window(view_id); if (window == nullptr) { diff --git a/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h b/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h index 8e99ad83eba3f..0a5ae5dd695a8 100644 --- a/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h +++ b/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h @@ -36,11 +36,9 @@ FLUTTER_DARWIN_EXPORT @property(nonnull, readonly) id textures; /** - * The default view displaying Flutter content. + * The view displaying Flutter content. * * This method may return |nil|, for instance in a headless environment. - * - * The default view is a special view operated by single-view APIs. */ @property(nullable, readonly) NSView* view; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm index 3da1c44edf0c4..b40234c5b3bc8 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm @@ -22,7 +22,7 @@ // 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 = [view_provider_ viewForId:kFlutterDefaultViewId]; + FlutterView* view = [view_provider_ viewForId:kFlutterImplicitViewId]; if (!view) { return false; } diff --git a/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm index f7ac37e01be68..081c3e22e86eb 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm @@ -12,27 +12,27 @@ #import "flutter/testing/testing.h" @interface FlutterViewMockProvider : NSObject { - FlutterView* _defaultView; + FlutterView* _implicitView; } /** - * Create a FlutterViewMockProvider with the provided view as the default view. + * Create a FlutterViewMockProvider with the provided view as the implicit view. */ -- (nonnull instancetype)initWithDefaultView:(nonnull FlutterView*)view; +- (nonnull instancetype)initWithImplicitView:(nonnull FlutterView*)view; @end @implementation FlutterViewMockProvider -- (nonnull instancetype)initWithDefaultView:(nonnull FlutterView*)view { +- (nonnull instancetype)initWithImplicitView:(nonnull FlutterView*)view { self = [super init]; if (self != nil) { - _defaultView = view; + _implicitView = view; } return self; } - (nullable FlutterView*)viewForId:(FlutterViewId)viewId { - if (viewId == kFlutterDefaultViewId) { - return _defaultView; + if (viewId == kFlutterImplicitViewId) { + return _implicitView; } return nil; } @@ -81,7 +81,7 @@ - (nullable FlutterView*)viewForId:(FlutterViewId)viewId { OCMStub([surfaceMock asFlutterMetalTexture]).andReturn(texture); - return [[FlutterViewMockProvider alloc] initWithDefaultView:viewMock]; + return [[FlutterViewMockProvider alloc] initWithImplicitView:viewMock]; } } // namespace @@ -131,7 +131,7 @@ - (nullable FlutterView*)viewForId:(FlutterViewId)viewId { }}; const FlutterLayer* layers_ptr = layers; - macos_compositor->Present(kFlutterDefaultViewId, &layers_ptr, 1); + macos_compositor->Present(kFlutterImplicitViewId, &layers_ptr, 1); ASSERT_EQ(presentedSurfaces.count, 1ul); } diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm index 138ebdc1c6be7..caab9c1852d53 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm @@ -95,7 +95,7 @@ - (nullable FlutterViewController*)viewControllerForId:(FlutterViewId)viewId; * An internal method that adds the view controller with the given ID. * * This method assigns the controller with the ID, puts the controller into the - * map, and does assertions related to the default view ID. + * map, and does assertions related to the implicit view ID. */ - (void)registerViewController:(FlutterViewController*)controller forId:(FlutterViewId)viewId; @@ -296,7 +296,7 @@ - (instancetype)initWithPlugin:(NSString*)pluginKey flutterEngine:(FlutterEngine } - (NSView*)view { - return [self viewForId:kFlutterDefaultViewId]; + return [self viewForId:kFlutterImplicitViewId]; } - (NSView*)viewForId:(FlutterViewId)viewId { @@ -422,9 +422,9 @@ - (instancetype)initWithName:(NSString*)labelPrefix [_isResponseValid addObject:@YES]; _terminationHandler = [[FlutterEngineTerminationHandler alloc] initWithEngine:self terminator:nil]; - // kFlutterDefaultViewId is reserved for the default view. + // kFlutterImplicitViewId is reserved for the implicit view. // All IDs above it are for regular views. - _nextViewId = kFlutterDefaultViewId + 1; + _nextViewId = kFlutterImplicitViewId + 1; _embedderAPI.struct_size = sizeof(FlutterEngineProcTable); FlutterEngineGetProcAddresses(&_embedderAPI); @@ -506,10 +506,10 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint { flutterArguments.update_semantics_callback2 = [](const FlutterSemanticsUpdate2* update, void* user_data) { // TODO(dkwingsmt): This callback only supports single-view, therefore it - // only operates on the default view. To support multi-view, we need a + // only operates on the implicit view. To support multi-view, we need a // way to pass in the ID (probably through FlutterSemanticsUpdate). FlutterEngine* engine = (__bridge FlutterEngine*)user_data; - [[engine viewControllerForId:kFlutterDefaultViewId] updateSemantics:update]; + [[engine viewControllerForId:kFlutterImplicitViewId] updateSemantics:update]; }; flutterArguments.custom_dart_entrypoint = entrypoint.UTF8String; flutterArguments.shutdown_dart_vm_when_done = true; @@ -645,7 +645,7 @@ - (FlutterViewController*)viewControllerForId:(FlutterViewId)viewId { - (void)setViewController:(FlutterViewController*)controller { FlutterViewController* currentController = - [_viewControllers objectForKey:@(kFlutterDefaultViewId)]; + [_viewControllers objectForKey:@(kFlutterImplicitViewId)]; if (currentController == controller) { // From nil to nil, or from non-nil to the same controller. return; @@ -658,26 +658,26 @@ - (void)setViewController:(FlutterViewController*)controller { @"If you wanted to create an FlutterViewController and set it to an existing engine, " @"you should use FlutterViewController#init(engine:, nibName, bundle:) instead.", controller.engine); - [self registerViewController:controller forId:kFlutterDefaultViewId]; + [self registerViewController:controller forId:kFlutterImplicitViewId]; } else if (currentController != nil && controller == nil) { - NSAssert(currentController.viewId == kFlutterDefaultViewId, + NSAssert(currentController.viewId == kFlutterImplicitViewId, @"The default controller has an unexpected ID %llu", currentController.viewId); // From non-nil to nil. - [self deregisterViewControllerForId:kFlutterDefaultViewId]; + [self deregisterViewControllerForId:kFlutterImplicitViewId]; [self shutDownIfNeeded]; } else { // From non-nil to a different non-nil view controller. NSAssert(NO, @"Failed to set view controller to the engine: " - @"The engine already has a default view controller %@. " - @"If you wanted to make the default view render in a different window, " + @"The engine already has an implicit view controller %@. " + @"If you wanted to make the implicit view render in a different window, " @"you should attach the current view controller to the window instead.", - [_viewControllers objectForKey:@(kFlutterDefaultViewId)]); + [_viewControllers objectForKey:@(kFlutterImplicitViewId)]); } } - (FlutterViewController*)viewController { - return [self viewControllerForId:kFlutterDefaultViewId]; + return [self viewControllerForId:kFlutterImplicitViewId]; } - (FlutterCompositor*)createFlutterCompositor { @@ -705,9 +705,9 @@ - (FlutterCompositor*)createFlutterCompositor { void* user_data // ) { // TODO(dkwingsmt): This callback only supports single-view, therefore it - // only operates on the default view. To support multi-view, we need a new + // only operates on the implicit view. To support multi-view, we need a new // callback that also receives a view ID. - return reinterpret_cast(user_data)->Present(kFlutterDefaultViewId, + return reinterpret_cast(user_data)->Present(kFlutterImplicitViewId, layers, layers_count); }; @@ -725,7 +725,7 @@ - (FlutterCompositor*)createFlutterCompositor { #pragma mark - Framework-internal methods - (void)addViewController:(FlutterViewController*)controller { - [self registerViewController:controller forId:kFlutterDefaultViewId]; + [self registerViewController:controller forId:kFlutterImplicitViewId]; } - (void)removeViewController:(nonnull FlutterViewController*)viewController { @@ -812,7 +812,7 @@ - (nonnull NSString*)executableName { } - (void)updateWindowMetricsForViewController:(FlutterViewController*)viewController { - if (viewController.viewId != kFlutterDefaultViewId) { + if (viewController.viewId != kFlutterImplicitViewId) { // TODO(dkwingsmt): The embedder API only supports single-view for now. As // embedder APIs are converted to multi-view, this method should support any // views. @@ -1078,7 +1078,7 @@ - (void)handleAccessibilityEvent:(NSDictionary*)annotatedEvent { - (void)announceAccessibilityMessage:(NSString*)message withPriority:(NSAccessibilityPriorityLevel)priority { NSAccessibilityPostNotificationWithUserInfo( - [self viewControllerForId:kFlutterDefaultViewId].flutterView, + [self viewControllerForId:kFlutterImplicitViewId].flutterView, NSAccessibilityAnnouncementRequestedNotification, @{NSAccessibilityAnnouncementKey : message, NSAccessibilityPriorityKey : @(priority)}); } diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm index 60e8bc363f8df..4fccfa0dedc9b 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm @@ -25,7 +25,7 @@ // CREATE_NATIVE_ENTRY and MOCK_ENGINE_PROC are leaky by design // NOLINTBEGIN(clang-analyzer-core.StackAddressEscape) -constexpr int64_t kDefaultViewId = 0ll; +constexpr int64_t kImplicitViewId = 0ll; @interface FlutterEngine (Test) /** @@ -354,7 +354,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable FlutterSemanticsNode2* nodes[] = {&root, &child1}; update.nodes = nodes; update.custom_action_count = 0; - // This call updates semantics for the default view, which does not exist, + // This call updates semantics for the implicit view, which does not exist, // and therefore this call is invalid. But the engine should not crash. update_semantics_callback(&update, (__bridge void*)engine); @@ -632,7 +632,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable [threadSynchronizer shutdown]; std::thread rasterThread([&threadSynchronizer] { - [threadSynchronizer performCommitForView:kDefaultViewId + [threadSynchronizer performCommitForView:kImplicitViewId size:CGSizeMake(100, 100) notify:^{ }]; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h b/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h index 71fe5481cf72b..6b1a4e50e3c5a 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h @@ -115,7 +115,7 @@ typedef NS_ENUM(NSInteger, FlutterAppExitResponse) { * * Practically, since FlutterEngine can only be attached with one controller, * the given controller, if successfully attached, will always have the default - * view ID kFlutterDefaultViewId. + * view ID kFlutterImplicitViewId. * * The engine holds a weak reference to the attached view controller. * @@ -127,11 +127,11 @@ typedef NS_ENUM(NSInteger, FlutterAppExitResponse) { /** * Dissociate the given view controller from this engine. * - * Practically, since FlutterEngine can only be attached with one controller, - * the given controller must be the default view controller. - * * If the view controller is not associated with this engine, this call throws an * assertion. + * + * Practically, since FlutterEngine can only be attached with one controller for + * now, the given controller must be the current view controller. */ - (void)removeViewController:(FlutterViewController*)viewController; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterView.h b/shell/platform/darwin/macos/framework/Source/FlutterView.h index 0c468d4c58d08..6948b880fcf9b 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterView.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterView.h @@ -20,7 +20,7 @@ typedef int64_t FlutterViewId; * backward compatibility, single-view APIs will always operate on the view with * this ID. Also, the first view assigned to the engine will also have this ID. */ -constexpr FlutterViewId kFlutterDefaultViewId = 0ll; +constexpr FlutterViewId kFlutterImplicitViewId = 0ll; /** * Listener for view resizing. diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm index 403639b79e62a..aa14b70fc4b2b 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm @@ -27,7 +27,7 @@ .andDo(^(NSInvocation* invocation) { FlutterViewId viewId; [invocation getArgument:&viewId atIndex:2]; - if (viewId == kFlutterDefaultViewId) { + if (viewId == kFlutterImplicitViewId) { if (mockFlutterViewController != nil) { [invocation setReturnValue:&mockFlutterViewController]; } diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterViewTest.mm index 7599b66e8b0ec..0d6e7cb550400 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewTest.mm @@ -8,7 +8,7 @@ #import "flutter/testing/testing.h" -constexpr int64_t kDefaultViewId = 0ll; +constexpr int64_t kImplicitViewId = 0ll; @interface TestReshapeListener : NSObject @@ -30,6 +30,6 @@ - (void)viewDidReshape:(nonnull NSView*)view { commandQueue:queue reshapeListener:listener threadSynchronizer:threadSynchronizer - viewId:kDefaultViewId]; + viewId:kImplicitViewId]; EXPECT_EQ([view layer:view.layer shouldInheritContentsScale:3.0 fromWindow:view.window], YES); } From d0a43cd774956d291ab321e6957f7962b856bf3c Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Fri, 30 Jun 2023 15:29:56 -0700 Subject: [PATCH 02/17] Impl --- lib/ui/window/platform_configuration.h | 9 +++- runtime/runtime_controller.cc | 19 ++++--- runtime/runtime_controller.h | 2 +- shell/common/engine.cc | 5 +- shell/common/engine.h | 2 +- shell/common/engine_unittests.cc | 5 +- shell/common/platform_view.cc | 5 +- shell/common/platform_view.h | 3 +- shell/common/shell.cc | 7 +-- shell/common/shell.h | 1 + shell/common/shell_test.cc | 6 ++- shell/common/shell_unittests.cc | 54 +++++++++++-------- .../android/platform_view_android_jni_impl.cc | 5 +- .../ios/framework/Source/FlutterEngine.mm | 4 +- .../Source/FlutterEnginePlatformViewTest.mm | 2 +- .../Source/FlutterPlatformViewsTest.mm | 2 +- .../Source/accessibility_bridge_test.mm | 2 +- shell/platform/embedder/embedder.cc | 6 ++- shell/platform/embedder/embedder_engine.cc | 3 +- shell/platform/embedder/embedder_engine.h | 3 +- .../platform_view_embedder_unittests.cc | 4 +- .../fuchsia/flutter/flatland_platform_view.cc | 51 +++++++++--------- .../fuchsia/flutter/gfx_platform_view.cc | 48 +++++++++-------- .../fuchsia/flutter/platform_view_unittest.cc | 1 + .../tests/flatland_platform_view_unittest.cc | 1 + shell/testing/tester_main.cc | 4 +- 26 files changed, 156 insertions(+), 98 deletions(-) diff --git a/lib/ui/window/platform_configuration.h b/lib/ui/window/platform_configuration.h index c03f38194bf50..77836717809e8 100644 --- a/lib/ui/window/platform_configuration.h +++ b/lib/ui/window/platform_configuration.h @@ -415,7 +415,14 @@ class PlatformConfiguration final { /// /// @return a pointer to the Window. /// - Window* get_window(int window_id) { return windows_[window_id].get(); } + Window* get_window(int window_id) { + auto found = windows_.find(window_id); + if (found != windows_.end()) { + return found->second.get(); + } else { + return nullptr; + } + } //---------------------------------------------------------------------------- /// @brief Responds to a previous platform message to the engine from the diff --git a/runtime/runtime_controller.cc b/runtime/runtime_controller.cc index 5ffd02d099139..9cc704a8e7077 100644 --- a/runtime/runtime_controller.cc +++ b/runtime/runtime_controller.cc @@ -20,7 +20,7 @@ namespace flutter { -const uint64_t kFlutterDefaultViewId = 0llu; +constexpr uint64_t kFlutterImplicitViewId = 0ll; RuntimeController::RuntimeController(RuntimeDelegate& p_client, const TaskRunners& task_runners) @@ -115,7 +115,10 @@ std::unique_ptr RuntimeController::Clone() const { } bool RuntimeController::FlushRuntimeStateToIsolate() { - return SetViewportMetrics(platform_data_.viewport_metrics) && + // TODO(dkwingsmt): Needs a view ID here (or platform_data should probably + // have multiple view metrics). + return SetViewportMetrics(kFlutterImplicitViewId, + platform_data_.viewport_metrics) && SetLocales(platform_data_.locale_data) && SetSemanticsEnabled(platform_data_.semantics_enabled) && SetAccessibilityFeatures( @@ -125,13 +128,17 @@ bool RuntimeController::FlushRuntimeStateToIsolate() { SetDisplays(platform_data_.displays); } -bool RuntimeController::SetViewportMetrics(const ViewportMetrics& metrics) { +bool RuntimeController::SetViewportMetrics(int64_t view_id, + const ViewportMetrics& metrics) { TRACE_EVENT0("flutter", "SetViewportMetrics"); platform_data_.viewport_metrics = metrics; if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) { - platform_configuration->get_window(0)->UpdateWindowMetrics(metrics); - return true; + Window* window = platform_configuration->get_window(view_id); + if (window) { + window->UpdateWindowMetrics(metrics); + return true; + } } return false; @@ -320,7 +327,7 @@ void RuntimeController::ScheduleFrame() { // |PlatformConfigurationClient| void RuntimeController::Render(Scene* scene) { // TODO(dkwingsmt): Currently only supports a single window. - int64_t view_id = kFlutterDefaultViewId; + int64_t view_id = kFlutterImplicitViewId; auto window = UIDartState::Current()->platform_configuration()->get_window(view_id); if (window == nullptr) { diff --git a/runtime/runtime_controller.h b/runtime/runtime_controller.h index 1df085262f605..b4b1fcc8d3c8d 100644 --- a/runtime/runtime_controller.h +++ b/runtime/runtime_controller.h @@ -172,7 +172,7 @@ class RuntimeController : public PlatformConfigurationClient { /// /// @return If the window metrics were forwarded to the running isolate. /// - bool SetViewportMetrics(const ViewportMetrics& metrics); + bool SetViewportMetrics(int64_t view_id, const ViewportMetrics& metrics); //---------------------------------------------------------------------------- /// @brief Forward the specified display metrics to the running isolate. diff --git a/shell/common/engine.cc b/shell/common/engine.cc index 2c0b22d1863f8..33d8e52baf40d 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -292,8 +292,9 @@ tonic::DartErrorHandleType Engine::GetUIIsolateLastError() { return runtime_controller_->GetLastError(); } -void Engine::SetViewportMetrics(const ViewportMetrics& metrics) { - runtime_controller_->SetViewportMetrics(metrics); +void Engine::SetViewportMetrics(int64_t view_id, + const ViewportMetrics& metrics) { + runtime_controller_->SetViewportMetrics(view_id, metrics); ScheduleFrame(); } diff --git a/shell/common/engine.h b/shell/common/engine.h index 1890589729b04..d141ffa0cc28a 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -686,7 +686,7 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate { /// /// @param[in] metrics The metrics /// - void SetViewportMetrics(const ViewportMetrics& metrics); + void SetViewportMetrics(int64_t view_id, const ViewportMetrics& metrics); //---------------------------------------------------------------------------- /// @brief Updates the display metrics for the currently running Flutter diff --git a/shell/common/engine_unittests.cc b/shell/common/engine_unittests.cc index 5011f266557c8..995c408247ef4 100644 --- a/shell/common/engine_unittests.cc +++ b/shell/common/engine_unittests.cc @@ -21,6 +21,8 @@ namespace flutter { namespace { +constexpr int64_t kDefaultViewId = 0ll; + class MockDelegate : public Engine::Delegate { public: MOCK_METHOD2(OnEngineUpdateSemantics, @@ -330,7 +332,8 @@ TEST_F(EngineTest, SpawnResetsViewportMetrics) { const double kViewHeight = 1024; old_viewport_metrics.physical_width = kViewWidth; old_viewport_metrics.physical_height = kViewHeight; - mock_runtime_controller->SetViewportMetrics(old_viewport_metrics); + mock_runtime_controller->SetViewportMetrics(kDefaultViewId, + old_viewport_metrics); auto engine = std::make_unique( /*delegate=*/delegate_, /*dispatcher_maker=*/dispatcher_maker_, diff --git a/shell/common/platform_view.cc b/shell/common/platform_view.cc index 7cb0b091d5bcd..77a33bfb76e2a 100644 --- a/shell/common/platform_view.cc +++ b/shell/common/platform_view.cc @@ -51,8 +51,9 @@ void PlatformView::SetAccessibilityFeatures(int32_t flags) { delegate_.OnPlatformViewSetAccessibilityFeatures(flags); } -void PlatformView::SetViewportMetrics(const ViewportMetrics& metrics) { - delegate_.OnPlatformViewSetViewportMetrics(metrics); +void PlatformView::SetViewportMetrics(int64_t view_id, + const ViewportMetrics& metrics) { + delegate_.OnPlatformViewSetViewportMetrics(view_id, metrics); } void PlatformView::NotifyCreated() { diff --git a/shell/common/platform_view.h b/shell/common/platform_view.h index 9ec848e34568d..3e5aab515ccd8 100644 --- a/shell/common/platform_view.h +++ b/shell/common/platform_view.h @@ -112,6 +112,7 @@ class PlatformView { /// @param[in] metrics The updated viewport metrics. /// virtual void OnPlatformViewSetViewportMetrics( + int64_t view_id, const ViewportMetrics& metrics) = 0; //-------------------------------------------------------------------------- @@ -474,7 +475,7 @@ class PlatformView { /// /// @param[in] metrics The updated viewport metrics. /// - void SetViewportMetrics(const ViewportMetrics& metrics); + void SetViewportMetrics(int64_t view_id, const ViewportMetrics& metrics); //---------------------------------------------------------------------------- /// @brief Used by embedders to notify the shell that a platform view diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 859a2668c3762..23de5bea8f0fd 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -954,7 +954,8 @@ void Shell::OnPlatformViewScheduleFrame() { } // |PlatformView::Delegate| -void Shell::OnPlatformViewSetViewportMetrics(const ViewportMetrics& metrics) { +void Shell::OnPlatformViewSetViewportMetrics(int64_t view_id, + const ViewportMetrics& metrics) { FML_DCHECK(is_setup_); FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread()); @@ -978,9 +979,9 @@ void Shell::OnPlatformViewSetViewportMetrics(const ViewportMetrics& metrics) { }); task_runners_.GetUITaskRunner()->PostTask( - [engine = engine_->GetWeakPtr(), metrics]() { + [engine = engine_->GetWeakPtr(), metrics, view_id]() { if (engine) { - engine->SetViewportMetrics(metrics); + engine->SetViewportMetrics(view_id, metrics); } }); diff --git a/shell/common/shell.h b/shell/common/shell.h index d913c3e9c84a6..6c104f8558f4a 100644 --- a/shell/common/shell.h +++ b/shell/common/shell.h @@ -544,6 +544,7 @@ class Shell final : public PlatformView::Delegate, // |PlatformView::Delegate| void OnPlatformViewSetViewportMetrics( + int64_t view_id, const ViewportMetrics& metrics) override; // |PlatformView::Delegate| diff --git a/shell/common/shell_test.cc b/shell/common/shell_test.cc index 5e5d38d2b2b94..b892faefcef84 100644 --- a/shell/common/shell_test.cc +++ b/shell/common/shell_test.cc @@ -20,6 +20,8 @@ namespace flutter { namespace testing { +constexpr int64_t kDefaultViewId = 0; + ShellTest::ShellTest() : thread_host_("io.flutter.test." + GetCurrentTestName() + ".", ThreadHost::Type::Platform | ThreadHost::Type::IO | @@ -144,7 +146,7 @@ void ShellTest::SetViewportMetrics(Shell* shell, double width, double height) { shell->GetTaskRunners().GetUITaskRunner()->PostTask( [&latch, engine = shell->weak_engine_, viewport_metrics]() { if (engine) { - engine->SetViewportMetrics(viewport_metrics); + engine->SetViewportMetrics(kDefaultViewId, viewport_metrics); const auto frame_begin_time = fml::TimePoint::Now(); const auto frame_end_time = frame_begin_time + fml::TimeDelta::FromSecondsF(1.0 / 60.0); @@ -186,7 +188,7 @@ void ShellTest::PumpOneFrame(Shell* shell, fml::AutoResetWaitableEvent latch; shell->GetTaskRunners().GetUITaskRunner()->PostTask( [&latch, engine = shell->weak_engine_, viewport_metrics]() { - engine->SetViewportMetrics(viewport_metrics); + engine->SetViewportMetrics(kDefaultViewId, viewport_metrics); const auto frame_begin_time = fml::TimePoint::Now(); const auto frame_end_time = frame_begin_time + fml::TimeDelta::FromSecondsF(1.0 / 60.0); diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index 16abef0dbc0f3..e9c606b704743 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -60,6 +60,8 @@ namespace flutter { namespace testing { +constexpr int64_t kDefaultViewId = 0ll; + using ::testing::_; using ::testing::Return; @@ -74,8 +76,8 @@ class MockPlatformViewDelegate : public PlatformView::Delegate { MOCK_METHOD1(OnPlatformViewSetNextFrameCallback, void(const fml::closure& closure)); - MOCK_METHOD1(OnPlatformViewSetViewportMetrics, - void(const ViewportMetrics& metrics)); + MOCK_METHOD2(OnPlatformViewSetViewportMetrics, + void(int64_t view_id, const ViewportMetrics& metrics)); MOCK_METHOD1(OnPlatformViewDispatchPlatformMessage, void(std::unique_ptr message)); @@ -1637,7 +1639,8 @@ TEST_F(ShellTest, MultipleFluttersSetResourceCacheBytes) { RunEngine(shell.get(), std::move(configuration)); PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { - shell->GetPlatformView()->SetViewportMetrics({1.0, 100, 100, 22, 0}); + shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + {1.0, 100, 100, 22, 0}); }); // first cache bytes @@ -1666,7 +1669,7 @@ TEST_F(ShellTest, MultipleFluttersSetResourceCacheBytes) { PostSync(second_shell->GetTaskRunners().GetPlatformTaskRunner(), [&second_shell]() { second_shell->GetPlatformView()->SetViewportMetrics( - {1.0, 100, 100, 22, 0}); + kDefaultViewId, {1.0, 100, 100, 22, 0}); }); // first cache bytes + second cache bytes EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), @@ -1675,7 +1678,7 @@ TEST_F(ShellTest, MultipleFluttersSetResourceCacheBytes) { PostSync(second_shell->GetTaskRunners().GetPlatformTaskRunner(), [&second_shell]() { second_shell->GetPlatformView()->SetViewportMetrics( - {1.0, 100, 300, 22, 0}); + kDefaultViewId, {1.0, 100, 300, 22, 0}); }); // first cache bytes + second cache bytes EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), @@ -1686,7 +1689,7 @@ TEST_F(ShellTest, MultipleFluttersSetResourceCacheBytes) { PostSync(third_shell->GetTaskRunners().GetPlatformTaskRunner(), [&third_shell]() { third_shell->GetPlatformView()->SetViewportMetrics( - {1.0, 400, 100, 22, 0}); + kDefaultViewId, {1.0, 400, 100, 22, 0}); }); // first cache bytes + second cache bytes + third cache bytes EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), @@ -1695,7 +1698,7 @@ TEST_F(ShellTest, MultipleFluttersSetResourceCacheBytes) { PostSync(third_shell->GetTaskRunners().GetPlatformTaskRunner(), [&third_shell]() { third_shell->GetPlatformView()->SetViewportMetrics( - {1.0, 800, 100, 22, 0}); + kDefaultViewId, {1.0, 800, 100, 22, 0}); }); // max bytes threshold EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), @@ -1708,7 +1711,7 @@ TEST_F(ShellTest, MultipleFluttersSetResourceCacheBytes) { PostSync(second_shell->GetTaskRunners().GetPlatformTaskRunner(), [&second_shell]() { second_shell->GetPlatformView()->SetViewportMetrics( - {1.0, 100, 100, 22, 0}); + kDefaultViewId, {1.0, 100, 100, 22, 0}); }); // first cache bytes + second cache bytes EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), @@ -1752,7 +1755,8 @@ TEST_F(ShellTest, SetResourceCacheSize) { fml::TaskRunner::RunNowOrPostTask( shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { - shell->GetPlatformView()->SetViewportMetrics({1.0, 400, 200, 22, 0}); + shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + {1.0, 400, 200, 22, 0}); }); PumpOneFrame(shell.get()); @@ -1772,7 +1776,8 @@ TEST_F(ShellTest, SetResourceCacheSize) { fml::TaskRunner::RunNowOrPostTask( shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { - shell->GetPlatformView()->SetViewportMetrics({1.0, 800, 400, 22, 0}); + shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + {1.0, 800, 400, 22, 0}); }); PumpOneFrame(shell.get()); @@ -1789,7 +1794,8 @@ TEST_F(ShellTest, SetResourceCacheSizeEarly) { fml::TaskRunner::RunNowOrPostTask( shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { - shell->GetPlatformView()->SetViewportMetrics({1.0, 400, 200, 22, 0}); + shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + {1.0, 400, 200, 22, 0}); }); PumpOneFrame(shell.get()); @@ -1816,7 +1822,8 @@ TEST_F(ShellTest, SetResourceCacheSizeNotifiesDart) { fml::TaskRunner::RunNowOrPostTask( shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { - shell->GetPlatformView()->SetViewportMetrics({1.0, 400, 200, 22, 0}); + shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + {1.0, 400, 200, 22, 0}); }); PumpOneFrame(shell.get()); @@ -2683,6 +2690,7 @@ TEST_F(ShellTest, DISABLED_DiscardLayerTreeOnResize) { shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell, &expected_size]() { shell->GetPlatformView()->SetViewportMetrics( + kDefaultViewId, {1.0, static_cast(expected_size.width()), static_cast(expected_size.height()), 22, 0}); }); @@ -2760,8 +2768,8 @@ TEST_F(ShellTest, DISABLED_DiscardResubmittedLayerTreeOnResize) { shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell, &origin_size]() { shell->GetPlatformView()->SetViewportMetrics( - {1.0, static_cast(origin_size.width()), - static_cast(origin_size.height()), 22, 0}); + kDefaultViewId, {1.0, static_cast(origin_size.width()), + static_cast(origin_size.height()), 22, 0}); }); auto configuration = RunConfiguration::InferFromSettings(settings); @@ -2779,8 +2787,8 @@ TEST_F(ShellTest, DISABLED_DiscardResubmittedLayerTreeOnResize) { shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell, &new_size, &resize_latch]() { shell->GetPlatformView()->SetViewportMetrics( - {1.0, static_cast(new_size.width()), - static_cast(new_size.height()), 22, 0}); + kDefaultViewId, {1.0, static_cast(new_size.width()), + static_cast(new_size.height()), 22, 0}); resize_latch.Signal(); }); @@ -2843,14 +2851,17 @@ TEST_F(ShellTest, IgnoresInvalidMetrics) { RunEngine(shell.get(), std::move(configuration)); task_runner->PostTask([&]() { - shell->GetPlatformView()->SetViewportMetrics({0.0, 400, 200, 22, 0}); + shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + {0.0, 400, 200, 22, 0}); task_runner->PostTask([&]() { - shell->GetPlatformView()->SetViewportMetrics({0.8, 0.0, 200, 22, 0}); + shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + {0.8, 0.0, 200, 22, 0}); task_runner->PostTask([&]() { - shell->GetPlatformView()->SetViewportMetrics({0.8, 400, 0.0, 22, 0}); + shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + {0.8, 400, 0.0, 22, 0}); task_runner->PostTask([&]() { shell->GetPlatformView()->SetViewportMetrics( - {0.8, 400, 200.0, 22, 0}); + kDefaultViewId, {0.8, 400, 200.0, 22, 0}); }); }); }); @@ -2862,7 +2873,8 @@ TEST_F(ShellTest, IgnoresInvalidMetrics) { latch.Reset(); task_runner->PostTask([&]() { - shell->GetPlatformView()->SetViewportMetrics({1.2, 600, 300, 22, 0}); + shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + {1.2, 600, 300, 22, 0}); }); latch.Wait(); ASSERT_EQ(last_device_pixel_ratio, 1.2); diff --git a/shell/platform/android/platform_view_android_jni_impl.cc b/shell/platform/android/platform_view_android_jni_impl.cc index c4580bc0562d7..72abd446061b0 100644 --- a/shell/platform/android/platform_view_android_jni_impl.cc +++ b/shell/platform/android/platform_view_android_jni_impl.cc @@ -37,6 +37,8 @@ namespace flutter { +static constexpr int64_t kFlutterImplicitViewId = 0ll; + static fml::jni::ScopedJavaGlobalRef* g_flutter_callback_info_class = nullptr; @@ -338,7 +340,8 @@ static void SetViewportMetrics(JNIEnv* env, 0, // Display ID }; - ANDROID_SHELL_HOLDER->GetPlatformView()->SetViewportMetrics(metrics); + ANDROID_SHELL_HOLDER->GetPlatformView()->SetViewportMetrics( + kFlutterImplicitViewId, metrics); } static void UpdateDisplayMetrics(JNIEnv* env, diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 52e6af116b079..1130dcccf7efe 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -38,6 +38,8 @@ #import "flutter/shell/platform/darwin/ios/rendering_api_selection.h" #include "flutter/shell/profiling/sampling_profiler.h" +static constexpr int64_t kFlutterImplicitViewId = 0ll; + /// Inheriting ThreadConfigurer and use iOS platform thread API to configure the thread priorities /// Using iOS platform thread API to configure thread priority static void IOSPlatformThreadConfigSetter(const fml::Thread::ThreadConfig& config) { @@ -308,7 +310,7 @@ - (void)updateViewportMetrics:(flutter::ViewportMetrics)viewportMetrics { if (!self.platformView) { return; } - self.platformView->SetViewportMetrics(viewportMetrics); + self.platformView->SetViewportMetrics(kFlutterImplicitViewId, viewportMetrics); } - (void)dispatchPointerDataPacket:(std::unique_ptr)packet { diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm index e4341a065c2af..0b5526a5341a2 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm @@ -24,7 +24,7 @@ void OnPlatformViewCreated(std::unique_ptr surface) override {} void OnPlatformViewDestroyed() override {} void OnPlatformViewScheduleFrame() override {} void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override {} - void OnPlatformViewSetViewportMetrics(const ViewportMetrics& metrics) override {} + void OnPlatformViewSetViewportMetrics(int64_t view_id, const ViewportMetrics& metrics) override {} const flutter::Settings& OnPlatformViewGetSettings() const override { return settings_; } void OnPlatformViewDispatchPlatformMessage(std::unique_ptr message) override {} void OnPlatformViewDispatchPointerDataPacket(std::unique_ptr packet) override { diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 974eb31de9f44..bba450217747a 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -93,7 +93,7 @@ void OnPlatformViewCreated(std::unique_ptr surface) override {} void OnPlatformViewDestroyed() override {} void OnPlatformViewScheduleFrame() override {} void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override {} - void OnPlatformViewSetViewportMetrics(const ViewportMetrics& metrics) override {} + void OnPlatformViewSetViewportMetrics(int64_t view_id, const ViewportMetrics& metrics) override {} const flutter::Settings& OnPlatformViewGetSettings() const override { return settings_; } void OnPlatformViewDispatchPlatformMessage(std::unique_ptr message) override {} void OnPlatformViewDispatchPointerDataPacket(std::unique_ptr packet) override { diff --git a/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm b/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm index 40995c9111284..283d4fe02decd 100644 --- a/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm +++ b/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm @@ -77,7 +77,7 @@ void OnPlatformViewCreated(std::unique_ptr surface) override {} void OnPlatformViewDestroyed() override {} void OnPlatformViewScheduleFrame() override {} void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override {} - void OnPlatformViewSetViewportMetrics(const ViewportMetrics& metrics) override {} + void OnPlatformViewSetViewportMetrics(int64_t view_id, const ViewportMetrics& metrics) override {} const flutter::Settings& OnPlatformViewGetSettings() const override { return settings_; } void OnPlatformViewDispatchPlatformMessage(std::unique_ptr message) override {} void OnPlatformViewDispatchPointerDataPacket(std::unique_ptr packet) override { diff --git a/shell/platform/embedder/embedder.cc b/shell/platform/embedder/embedder.cc index c9d1ce9866744..008ea576482d5 100644 --- a/shell/platform/embedder/embedder.cc +++ b/shell/platform/embedder/embedder.cc @@ -83,6 +83,8 @@ extern const intptr_t kPlatformStrongDillSize; const int32_t kFlutterSemanticsNodeIdBatchEnd = -1; const int32_t kFlutterSemanticsCustomActionIdBatchEnd = -1; +static constexpr int64_t kFlutterImplicitViewId = 0; + // A message channel to send platform-independent FlutterKeyData to the // framework. // @@ -2186,6 +2188,8 @@ FlutterEngineResult FlutterEngineSendWindowMetricsEvent( if (engine == nullptr || flutter_metrics == nullptr) { return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid."); } + // TODO(dkwingsmt): Use a real view ID when multiview is supported. + int64_t view_id = kFlutterImplicitViewId; flutter::ViewportMetrics metrics; @@ -2227,7 +2231,7 @@ FlutterEngineResult FlutterEngineSendWindowMetricsEvent( } return reinterpret_cast(engine)->SetViewportMetrics( - metrics) + view_id, metrics) ? kSuccess : LOG_EMBEDDER_ERROR(kInvalidArguments, "Viewport metrics were invalid."); diff --git a/shell/platform/embedder/embedder_engine.cc b/shell/platform/embedder/embedder_engine.cc index cc4da738f72fc..b34da8a287f4e 100644 --- a/shell/platform/embedder/embedder_engine.cc +++ b/shell/platform/embedder/embedder_engine.cc @@ -100,6 +100,7 @@ bool EmbedderEngine::NotifyDestroyed() { } bool EmbedderEngine::SetViewportMetrics( + int64_t view_id, const flutter::ViewportMetrics& metrics) { if (!IsValid()) { return false; @@ -109,7 +110,7 @@ bool EmbedderEngine::SetViewportMetrics( if (!platform_view) { return false; } - platform_view->SetViewportMetrics(metrics); + platform_view->SetViewportMetrics(view_id, metrics); return true; } diff --git a/shell/platform/embedder/embedder_engine.h b/shell/platform/embedder/embedder_engine.h index 60d33ba76e652..a587eeb3eaa74 100644 --- a/shell/platform/embedder/embedder_engine.h +++ b/shell/platform/embedder/embedder_engine.h @@ -48,7 +48,8 @@ class EmbedderEngine { bool IsValid() const; - bool SetViewportMetrics(const flutter::ViewportMetrics& metrics); + bool SetViewportMetrics(int64_t view_id, + const flutter::ViewportMetrics& metrics); bool DispatchPointerDataPacket( std::unique_ptr packet); diff --git a/shell/platform/embedder/platform_view_embedder_unittests.cc b/shell/platform/embedder/platform_view_embedder_unittests.cc index 3e795f1fb530f..d22dc030e7292 100644 --- a/shell/platform/embedder/platform_view_embedder_unittests.cc +++ b/shell/platform/embedder/platform_view_embedder_unittests.cc @@ -21,8 +21,8 @@ class MockDelegate : public PlatformView::Delegate { MOCK_METHOD0(OnPlatformViewScheduleFrame, void()); MOCK_METHOD1(OnPlatformViewSetNextFrameCallback, void(const fml::closure& closure)); - MOCK_METHOD1(OnPlatformViewSetViewportMetrics, - void(const ViewportMetrics& metrics)); + MOCK_METHOD2(OnPlatformViewSetViewportMetrics, + void(int64_t view_id, const ViewportMetrics& metrics)); MOCK_METHOD1(OnPlatformViewDispatchPlatformMessage, void(std::unique_ptr message)); MOCK_METHOD1(OnPlatformViewDispatchPointerDataPacket, diff --git a/shell/platform/fuchsia/flutter/flatland_platform_view.cc b/shell/platform/fuchsia/flutter/flatland_platform_view.cc index cbadf9d47b6e0..e9c55f87f539e 100644 --- a/shell/platform/fuchsia/flutter/flatland_platform_view.cc +++ b/shell/platform/fuchsia/flutter/flatland_platform_view.cc @@ -8,6 +8,8 @@ namespace flutter_runner { +static constexpr int64_t kFlutterDefaultViewId = 0ll; + FlatlandPlatformView::FlatlandPlatformView( flutter::PlatformView::Delegate& delegate, flutter::TaskRunners task_runners, @@ -85,30 +87,31 @@ void FlatlandPlatformView::OnGetLayout( float pixel_ratio = view_pixel_ratio_ ? *view_pixel_ratio_ : 1.0f; - SetViewportMetrics({ - pixel_ratio, // device_pixel_ratio - std::round(view_logical_size_.value()[0] * - pixel_ratio), // physical_width - std::round(view_logical_size_.value()[1] * - pixel_ratio), // physical_height - 0.0f, // physical_padding_top - 0.0f, // physical_padding_right - 0.0f, // physical_padding_bottom - 0.0f, // physical_padding_left - 0.0f, // physical_view_inset_top - 0.0f, // physical_view_inset_right - 0.0f, // physical_view_inset_bottom - 0.0f, // physical_view_inset_left - 0.0f, // p_physical_system_gesture_inset_top - 0.0f, // p_physical_system_gesture_inset_right - 0.0f, // p_physical_system_gesture_inset_bottom - 0.0f, // p_physical_system_gesture_inset_left, - -1.0, // p_physical_touch_slop, - {}, // p_physical_display_features_bounds - {}, // p_physical_display_features_type - {}, // p_physical_display_features_state - 0, // p_display_id - }); + SetViewportMetrics(kFlutterDefaultViewId, + { + pixel_ratio, // device_pixel_ratio + std::round(view_logical_size_.value()[0] * + pixel_ratio), // physical_width + std::round(view_logical_size_.value()[1] * + pixel_ratio), // physical_height + 0.0f, // physical_padding_top + 0.0f, // physical_padding_right + 0.0f, // physical_padding_bottom + 0.0f, // physical_padding_left + 0.0f, // physical_view_inset_top + 0.0f, // physical_view_inset_right + 0.0f, // physical_view_inset_bottom + 0.0f, // physical_view_inset_left + 0.0f, // p_physical_system_gesture_inset_top + 0.0f, // p_physical_system_gesture_inset_right + 0.0f, // p_physical_system_gesture_inset_bottom + 0.0f, // p_physical_system_gesture_inset_left, + -1.0, // p_physical_touch_slop, + {}, // p_physical_display_features_bounds + {}, // p_physical_display_features_type + {}, // p_physical_display_features_state + 0, // p_display_id + }); parent_viewport_watcher_->GetLayout( fit::bind_member(this, &FlatlandPlatformView::OnGetLayout)); diff --git a/shell/platform/fuchsia/flutter/gfx_platform_view.cc b/shell/platform/fuchsia/flutter/gfx_platform_view.cc index df0e9906caf50..149e91d7135af 100644 --- a/shell/platform/fuchsia/flutter/gfx_platform_view.cc +++ b/shell/platform/fuchsia/flutter/gfx_platform_view.cc @@ -8,6 +8,8 @@ namespace flutter_runner { +static constexpr int64_t kFlutterDefaultViewId = 0ll; + GfxPlatformView::GfxPlatformView( flutter::PlatformView::Delegate& delegate, flutter::TaskRunners task_runners, @@ -213,28 +215,30 @@ void GfxPlatformView::OnScenicEvent( metrics_changed) { const float pixel_ratio = *view_pixel_ratio_; const std::array logical_size = *view_logical_size_; - SetViewportMetrics({ - pixel_ratio, // device_pixel_ratio - std::round(logical_size[0] * pixel_ratio), // physical_width - std::round(logical_size[1] * pixel_ratio), // physical_height - 0.0f, // physical_padding_top - 0.0f, // physical_padding_right - 0.0f, // physical_padding_bottom - 0.0f, // physical_padding_left - 0.0f, // physical_view_inset_top - 0.0f, // physical_view_inset_right - 0.0f, // physical_view_inset_bottom - 0.0f, // physical_view_inset_left - 0.0f, // p_physical_system_gesture_inset_top - 0.0f, // p_physical_system_gesture_inset_right - 0.0f, // p_physical_system_gesture_inset_bottom - 0.0f, // p_physical_system_gesture_inset_left, - -1.0, // p_physical_touch_slop, - {}, // p_physical_display_features_bounds - {}, // p_physical_display_features_type - {}, // p_physical_display_features_state - 0, // pdisplay_id - }); + SetViewportMetrics( + kFlutterDefaultViewId, + { + pixel_ratio, // device_pixel_ratio + std::round(logical_size[0] * pixel_ratio), // physical_width + std::round(logical_size[1] * pixel_ratio), // physical_height + 0.0f, // physical_padding_top + 0.0f, // physical_padding_right + 0.0f, // physical_padding_bottom + 0.0f, // physical_padding_left + 0.0f, // physical_view_inset_top + 0.0f, // physical_view_inset_right + 0.0f, // physical_view_inset_bottom + 0.0f, // physical_view_inset_left + 0.0f, // p_physical_system_gesture_inset_top + 0.0f, // p_physical_system_gesture_inset_right + 0.0f, // p_physical_system_gesture_inset_bottom + 0.0f, // p_physical_system_gesture_inset_left, + -1.0, // p_physical_touch_slop, + {}, // p_physical_display_features_bounds + {}, // p_physical_display_features_type + {}, // p_physical_display_features_state + 0, // pdisplay_id + }); } } diff --git a/shell/platform/fuchsia/flutter/platform_view_unittest.cc b/shell/platform/fuchsia/flutter/platform_view_unittest.cc index c0aa42e0a5dbf..54a9c7a593f3b 100644 --- a/shell/platform/fuchsia/flutter/platform_view_unittest.cc +++ b/shell/platform/fuchsia/flutter/platform_view_unittest.cc @@ -90,6 +90,7 @@ class MockPlatformViewDelegate : public flutter::PlatformView::Delegate { void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) {} // |flutter::PlatformView::Delegate| void OnPlatformViewSetViewportMetrics( + int64_t view_id, const flutter::ViewportMetrics& metrics) { metrics_ = metrics; } diff --git a/shell/platform/fuchsia/flutter/tests/flatland_platform_view_unittest.cc b/shell/platform/fuchsia/flutter/tests/flatland_platform_view_unittest.cc index 78f6f9588958a..ff4347015eb49 100644 --- a/shell/platform/fuchsia/flutter/tests/flatland_platform_view_unittest.cc +++ b/shell/platform/fuchsia/flutter/tests/flatland_platform_view_unittest.cc @@ -89,6 +89,7 @@ class MockPlatformViewDelegate : public flutter::PlatformView::Delegate { void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) {} // |flutter::PlatformView::Delegate| void OnPlatformViewSetViewportMetrics( + int64_t view_id, const flutter::ViewportMetrics& metrics) { metrics_ = metrics; } diff --git a/shell/testing/tester_main.cc b/shell/testing/tester_main.cc index 342b4ea7aebe9..a6719ede8ffdf 100644 --- a/shell/testing/tester_main.cc +++ b/shell/testing/tester_main.cc @@ -39,6 +39,8 @@ namespace flutter { +static constexpr int64_t kDefaultViewId = 0ll; + class TesterExternalViewEmbedder : public ExternalViewEmbedder { // |ExternalViewEmbedder| DlCanvas* GetRootCanvas() override { return nullptr; } @@ -353,7 +355,7 @@ int RunTester(const flutter::Settings& settings, metrics.physical_width = physical_width; metrics.physical_height = physical_height; metrics.display_id = 0; - shell->GetPlatformView()->SetViewportMetrics(metrics); + shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, metrics); // Run the message loop and wait for the script to do its thing. fml::MessageLoop::GetCurrent().Run(); From 3d86303df29bf2f69cc543c1ab5e03d4aae54649 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Wed, 5 Jul 2023 08:45:15 -0700 Subject: [PATCH 03/17] Fix doc --- .../framework/Headers/FlutterPluginRegistrarMacOS.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h b/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h index 0a5ae5dd695a8..ef4868469f951 100644 --- a/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h +++ b/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h @@ -38,7 +38,14 @@ FLUTTER_DARWIN_EXPORT /** * The view displaying Flutter content. * - * This method may return |nil|, for instance in a headless environment. + * Some single-view APIs will eventually be replaced by their multi-view + * variant. During the deprecation period, the single-view APIs will coexist + * with and work with the multi-view APIs as if the other views don't exist. + * For backward compatibility, single-view APIs will always operate on this + * view, which is the first view assigned to the engine. + * + * This method may return |nil|, for instance in a headless environment, or when + * multi-view is supported in the future and the compatible mode is disabled. */ @property(nullable, readonly) NSView* view; From 1a69ee9fcb742e7032931e7f909757b1315b47f8 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Wed, 5 Jul 2023 10:36:52 -0700 Subject: [PATCH 04/17] Move get_window to cc --- lib/ui/window/platform_configuration.cc | 9 +++++++++ lib/ui/window/platform_configuration.h | 14 ++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/ui/window/platform_configuration.cc b/lib/ui/window/platform_configuration.cc index b1cd11fad30e7..fe6ff03d62b69 100644 --- a/lib/ui/window/platform_configuration.cc +++ b/lib/ui/window/platform_configuration.cc @@ -308,6 +308,15 @@ void PlatformConfiguration::ReportTimings(std::vector timings) { })); } +Window* PlatformConfiguration::get_window(int window_id) { + auto found = windows_.find(window_id); + if (found != windows_.end()) { + return found->second.get(); + } else { + return nullptr; + } +} + void PlatformConfiguration::CompletePlatformMessageEmptyResponse( int response_id) { if (!response_id) { diff --git a/lib/ui/window/platform_configuration.h b/lib/ui/window/platform_configuration.h index 77836717809e8..9226b457d07e8 100644 --- a/lib/ui/window/platform_configuration.h +++ b/lib/ui/window/platform_configuration.h @@ -413,16 +413,10 @@ class PlatformConfiguration final { /// /// @param[in] window_id The id of the window to find and return. /// - /// @return a pointer to the Window. - /// - Window* get_window(int window_id) { - auto found = windows_.find(window_id); - if (found != windows_.end()) { - return found->second.get(); - } else { - return nullptr; - } - } + /// @return a pointer to the Window. Returns nullptr if the ID is not + /// found. + /// + Window* get_window(int window_id); //---------------------------------------------------------------------------- /// @brief Responds to a previous platform message to the engine from the From a293b8e35da0de772eaf0810ed3b03ba09d6fcc9 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Wed, 5 Jul 2023 22:18:48 -0700 Subject: [PATCH 05/17] Fix doc --- .../Headers/FlutterPluginRegistrarMacOS.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h b/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h index ef4868469f951..dea07ed530929 100644 --- a/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h +++ b/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h @@ -38,11 +38,15 @@ FLUTTER_DARWIN_EXPORT /** * The view displaying Flutter content. * - * Some single-view APIs will eventually be replaced by their multi-view - * variant. During the deprecation period, the single-view APIs will coexist - * with and work with the multi-view APIs as if the other views don't exist. - * For backward compatibility, single-view APIs will always operate on this - * view, which is the first view assigned to the engine. + * Currently Flutter only supports one view, and this is the view. Flutter + * plans to support multiple views in the future. Although single-view APIs + * will eventually be replaced by their multi-view variant, there will be + * a deprecation period, during the single-view APIs coexist with and work with + * the multi-view APIs as if the other views don't exist. This + * field therefore guarantees backward-compatible behavior in that: + * + * - The first view attached to the engine becomes the value of this field. + * - Single-view Flutter APIs operate the value of this field. * * This method may return |nil|, for instance in a headless environment, or when * multi-view is supported in the future and the compatible mode is disabled. From 7699ee816aec141407108995cfa75b6f07d75e96 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Wed, 5 Jul 2023 22:38:25 -0700 Subject: [PATCH 06/17] Better doc --- .../Headers/FlutterPluginRegistrarMacOS.h | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h b/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h index dea07ed530929..d129f870ecb11 100644 --- a/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h +++ b/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h @@ -38,18 +38,28 @@ FLUTTER_DARWIN_EXPORT /** * The view displaying Flutter content. * - * Currently Flutter only supports one view, and this is the view. Flutter - * plans to support multiple views in the future. Although single-view APIs - * will eventually be replaced by their multi-view variant, there will be - * a deprecation period, during the single-view APIs coexist with and work with - * the multi-view APIs as if the other views don't exist. This - * field therefore guarantees backward-compatible behavior in that: + * Currently Flutter only supports one view, and this is the view. * - * - The first view attached to the engine becomes the value of this field. - * - Single-view Flutter APIs operate the value of this field. + * Flutter plans to support multiple views in the future. Although single-view + * APIs will eventually be replaced by their multi-view variants, during the + * deprecation period, the single-view APIs will coexist with and work with the + * multi-view APIs as if the other views don't exist. To achieve this, + * all behaviors of "the single view" (which is called "the implicit view") are + * preserved, allowing legacy single-view APIs to continue working, while + * new-style views created by new ways must be operated by the upcoming + * multi-view APIs. * - * This method may return |nil|, for instance in a headless environment, or when - * multi-view is supported in the future and the compatible mode is disabled. + * Plugins written for a single view can keep operating on this view and expect + * unchanged behavior for the implicit view. This includes that: + * + * - The first view controller attached to the engine will be linked to the + * implicit view. + * - Single-view Flutter APIs will operate the implicit view. + * + * This method may return |nil| if the view is not assigned. In single-view + * apps, this means that the app is running headlessly. In multi-view apps, + * this means that the compatible mode is disabled, or that the compatible mode + * is on but no view controller has been attached to the engine yet. */ @property(nullable, readonly) NSView* view; From 85adee8f9102321d5c4dbc4862a03102661656c9 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Thu, 6 Jul 2023 09:54:01 -0700 Subject: [PATCH 07/17] Add view update test --- .../platform_configuration_unittests.cc | 66 +++++++++++++++++-- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/lib/ui/window/platform_configuration_unittests.cc b/lib/ui/window/platform_configuration_unittests.cc index e89a5cc7d381c..a9146790c2dc2 100644 --- a/lib/ui/window/platform_configuration_unittests.cc +++ b/lib/ui/window/platform_configuration_unittests.cc @@ -19,7 +19,7 @@ namespace flutter { namespace testing { -TEST_F(ShellTest, PlatformConfigurationInitialization) { +TEST_F(PlatformConfigurationTest, Initialization) { auto message_latch = std::make_shared(); auto nativeValidateConfiguration = [message_latch]( @@ -63,7 +63,7 @@ TEST_F(ShellTest, PlatformConfigurationInitialization) { DestroyShell(std::move(shell), task_runners); } -TEST_F(ShellTest, PlatformConfigurationWindowMetricsUpdate) { +TEST_F(PlatformConfigurationTest, WindowMetricsUpdate) { auto message_latch = std::make_shared(); auto nativeValidateConfiguration = [message_latch]( @@ -113,7 +113,61 @@ TEST_F(ShellTest, PlatformConfigurationWindowMetricsUpdate) { DestroyShell(std::move(shell), task_runners); } -TEST_F(ShellTest, PlatformConfigurationOnErrorHandlesError) { +TEST_F(PlatformConfigurationTest, + RegularWindowIsUnavailableUntilMetricsUpdate) { + auto message_latch = std::make_shared(); + + auto nativeValidateConfiguration = [message_latch]( + Dart_NativeArguments args) { + PlatformConfiguration* configuration = + UIDartState::Current()->platform_configuration(); + + // Non-implicit views should not be created at startup + ASSERT_EQ(configuration->get_window(1), nullptr); + configuration->get_window(1)->UpdateWindowMetrics( + ViewportMetrics{2.0, 10.0, 20.0, 22, 0}); + ASSERT_EQ( + configuration->get_window(1)->viewport_metrics().device_pixel_ratio, + 2.0); + ASSERT_EQ(configuration->get_window(1)->viewport_metrics().physical_width, + 10.0); + ASSERT_EQ(configuration->get_window(1)->viewport_metrics().physical_height, + 20.0); + ASSERT_EQ( + configuration->get_window(1)->viewport_metrics().physical_touch_slop, + 22); + ASSERT_NE(configuration->get_window(1), nullptr); + ASSERT_EQ(configuration->get_window(2), nullptr); + + message_latch->Signal(); + }; + + Settings settings = CreateSettingsForFixture(); + TaskRunners task_runners("test", // label + GetCurrentTaskRunner(), // platform + CreateNewThread(), // raster + CreateNewThread(), // ui + CreateNewThread() // io + ); + + AddNativeCallback("ValidateConfiguration", + CREATE_NATIVE_ENTRY(nativeValidateConfiguration)); + + std::unique_ptr shell = CreateShell(settings, task_runners); + + ASSERT_TRUE(shell->IsSetup()); + auto run_configuration = RunConfiguration::InferFromSettings(settings); + run_configuration.SetEntrypoint("validateConfiguration"); + + shell->RunEngine(std::move(run_configuration), [&](auto result) { + ASSERT_EQ(result, Engine::RunStatus::Success); + }); + + message_latch->Wait(); + DestroyShell(std::move(shell), task_runners); +} + +TEST_F(PlatformConfigurationTest, OnErrorHandlesError) { auto message_latch = std::make_shared(); bool did_throw = false; @@ -159,7 +213,7 @@ TEST_F(ShellTest, PlatformConfigurationOnErrorHandlesError) { DestroyShell(std::move(shell), task_runners); } -TEST_F(ShellTest, PlatformConfigurationOnErrorDoesNotHandleError) { +TEST_F(PlatformConfigurationTest, OnErrorDoesNotHandleError) { auto message_latch = std::make_shared(); std::string ex; std::string st; @@ -211,7 +265,7 @@ TEST_F(ShellTest, PlatformConfigurationOnErrorDoesNotHandleError) { DestroyShell(std::move(shell), task_runners); } -TEST_F(ShellTest, PlatformConfigurationOnErrorThrows) { +TEST_F(PlatformConfigurationTest, OnErrorThrows) { auto message_latch = std::make_shared(); std::vector errors; size_t throw_count = 0; @@ -266,7 +320,7 @@ TEST_F(ShellTest, PlatformConfigurationOnErrorThrows) { DestroyShell(std::move(shell), task_runners); } -TEST_F(ShellTest, PlatformConfigurationSetDartPerformanceMode) { +TEST_F(PlatformConfigurationTest, SetDartPerformanceMode) { auto message_latch = std::make_shared(); auto finish = [message_latch](Dart_NativeArguments args) { // call needs to happen on the UI thread. From ad0a0d6165f889df0159841c498f953f6622d3d5 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Thu, 6 Jul 2023 09:55:47 -0700 Subject: [PATCH 08/17] Extractg get_window --- lib/ui/window/platform_configuration.cc | 9 +++++++++ lib/ui/window/platform_configuration.h | 9 +-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/ui/window/platform_configuration.cc b/lib/ui/window/platform_configuration.cc index b1cd11fad30e7..fe6ff03d62b69 100644 --- a/lib/ui/window/platform_configuration.cc +++ b/lib/ui/window/platform_configuration.cc @@ -308,6 +308,15 @@ void PlatformConfiguration::ReportTimings(std::vector timings) { })); } +Window* PlatformConfiguration::get_window(int window_id) { + auto found = windows_.find(window_id); + if (found != windows_.end()) { + return found->second.get(); + } else { + return nullptr; + } +} + void PlatformConfiguration::CompletePlatformMessageEmptyResponse( int response_id) { if (!response_id) { diff --git a/lib/ui/window/platform_configuration.h b/lib/ui/window/platform_configuration.h index 77836717809e8..41a9708c814c8 100644 --- a/lib/ui/window/platform_configuration.h +++ b/lib/ui/window/platform_configuration.h @@ -415,14 +415,7 @@ class PlatformConfiguration final { /// /// @return a pointer to the Window. /// - Window* get_window(int window_id) { - auto found = windows_.find(window_id); - if (found != windows_.end()) { - return found->second.get(); - } else { - return nullptr; - } - } + Window* get_window(int window_id); //---------------------------------------------------------------------------- /// @brief Responds to a previous platform message to the engine from the From d397d551a4eaa05168ed6b28129ddf0fa3c564bf Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Thu, 6 Jul 2023 10:19:48 -0700 Subject: [PATCH 09/17] Fix test --- lib/ui/window/platform_configuration.h | 3 +- .../platform_configuration_unittests.cc | 35 ++++++------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/lib/ui/window/platform_configuration.h b/lib/ui/window/platform_configuration.h index 41a9708c814c8..5722c1ce5a42f 100644 --- a/lib/ui/window/platform_configuration.h +++ b/lib/ui/window/platform_configuration.h @@ -413,7 +413,8 @@ class PlatformConfiguration final { /// /// @param[in] window_id The id of the window to find and return. /// - /// @return a pointer to the Window. + /// @return a pointer to the Window. Nullptr if the ID is not registered + /// yet. /// Window* get_window(int window_id); diff --git a/lib/ui/window/platform_configuration_unittests.cc b/lib/ui/window/platform_configuration_unittests.cc index a9146790c2dc2..92cb0b8bcd1fa 100644 --- a/lib/ui/window/platform_configuration_unittests.cc +++ b/lib/ui/window/platform_configuration_unittests.cc @@ -19,6 +19,8 @@ namespace flutter { namespace testing { +class PlatformConfigurationTest : public ShellTest {}; + TEST_F(PlatformConfigurationTest, Initialization) { auto message_latch = std::make_shared(); @@ -113,34 +115,19 @@ TEST_F(PlatformConfigurationTest, WindowMetricsUpdate) { DestroyShell(std::move(shell), task_runners); } -TEST_F(PlatformConfigurationTest, - RegularWindowIsUnavailableUntilMetricsUpdate) { +TEST_F(PlatformConfigurationTest, RegularWindowIsUnavailableAtStartup) { auto message_latch = std::make_shared(); - auto nativeValidateConfiguration = [message_latch]( - Dart_NativeArguments args) { - PlatformConfiguration* configuration = - UIDartState::Current()->platform_configuration(); + auto nativeValidateConfiguration = + [message_latch](Dart_NativeArguments args) { + PlatformConfiguration* configuration = + UIDartState::Current()->platform_configuration(); - // Non-implicit views should not be created at startup - ASSERT_EQ(configuration->get_window(1), nullptr); - configuration->get_window(1)->UpdateWindowMetrics( - ViewportMetrics{2.0, 10.0, 20.0, 22, 0}); - ASSERT_EQ( - configuration->get_window(1)->viewport_metrics().device_pixel_ratio, - 2.0); - ASSERT_EQ(configuration->get_window(1)->viewport_metrics().physical_width, - 10.0); - ASSERT_EQ(configuration->get_window(1)->viewport_metrics().physical_height, - 20.0); - ASSERT_EQ( - configuration->get_window(1)->viewport_metrics().physical_touch_slop, - 22); - ASSERT_NE(configuration->get_window(1), nullptr); - ASSERT_EQ(configuration->get_window(2), nullptr); + ASSERT_EQ(configuration->get_window(1), nullptr); + ASSERT_EQ(configuration->get_window(2), nullptr); - message_latch->Signal(); - }; + message_latch->Signal(); + }; Settings settings = CreateSettingsForFixture(); TaskRunners task_runners("test", // label From 57e705e149d11376e4aedbec7e221591b5a34a3c Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Fri, 7 Jul 2023 10:41:56 -0700 Subject: [PATCH 10/17] Back to current --- .../Headers/FlutterPluginRegistrarMacOS.h | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h b/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h index d129f870ecb11..0a5ae5dd695a8 100644 --- a/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h +++ b/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h @@ -38,28 +38,7 @@ FLUTTER_DARWIN_EXPORT /** * The view displaying Flutter content. * - * Currently Flutter only supports one view, and this is the view. - * - * Flutter plans to support multiple views in the future. Although single-view - * APIs will eventually be replaced by their multi-view variants, during the - * deprecation period, the single-view APIs will coexist with and work with the - * multi-view APIs as if the other views don't exist. To achieve this, - * all behaviors of "the single view" (which is called "the implicit view") are - * preserved, allowing legacy single-view APIs to continue working, while - * new-style views created by new ways must be operated by the upcoming - * multi-view APIs. - * - * Plugins written for a single view can keep operating on this view and expect - * unchanged behavior for the implicit view. This includes that: - * - * - The first view controller attached to the engine will be linked to the - * implicit view. - * - Single-view Flutter APIs will operate the implicit view. - * - * This method may return |nil| if the view is not assigned. In single-view - * apps, this means that the app is running headlessly. In multi-view apps, - * this means that the compatible mode is disabled, or that the compatible mode - * is on but no view controller has been attached to the engine yet. + * This method may return |nil|, for instance in a headless environment. */ @property(nullable, readonly) NSView* view; From 13764d791ec57306ffa7d0d3dd7b9fdff442be1f Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Fri, 7 Jul 2023 10:49:18 -0700 Subject: [PATCH 11/17] More default->implicit --- shell/common/engine_unittests.cc | 4 +- shell/common/shell_test.cc | 6 +-- shell/common/shell_unittests.cc | 38 +++++++++---------- .../fuchsia/flutter/flatland_platform_view.cc | 4 +- .../fuchsia/flutter/gfx_platform_view.cc | 4 +- shell/testing/tester_main.cc | 4 +- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/shell/common/engine_unittests.cc b/shell/common/engine_unittests.cc index 995c408247ef4..d1a7d24d39cbc 100644 --- a/shell/common/engine_unittests.cc +++ b/shell/common/engine_unittests.cc @@ -21,7 +21,7 @@ namespace flutter { namespace { -constexpr int64_t kDefaultViewId = 0ll; +constexpr int64_t kImplicitViewId = 0ll; class MockDelegate : public Engine::Delegate { public: @@ -332,7 +332,7 @@ TEST_F(EngineTest, SpawnResetsViewportMetrics) { const double kViewHeight = 1024; old_viewport_metrics.physical_width = kViewWidth; old_viewport_metrics.physical_height = kViewHeight; - mock_runtime_controller->SetViewportMetrics(kDefaultViewId, + mock_runtime_controller->SetViewportMetrics(kImplicitViewId, old_viewport_metrics); auto engine = std::make_unique( /*delegate=*/delegate_, diff --git a/shell/common/shell_test.cc b/shell/common/shell_test.cc index b892faefcef84..1ea8c7f0b3248 100644 --- a/shell/common/shell_test.cc +++ b/shell/common/shell_test.cc @@ -20,7 +20,7 @@ namespace flutter { namespace testing { -constexpr int64_t kDefaultViewId = 0; +constexpr int64_t kImplicitViewId = 0; ShellTest::ShellTest() : thread_host_("io.flutter.test." + GetCurrentTestName() + ".", @@ -146,7 +146,7 @@ void ShellTest::SetViewportMetrics(Shell* shell, double width, double height) { shell->GetTaskRunners().GetUITaskRunner()->PostTask( [&latch, engine = shell->weak_engine_, viewport_metrics]() { if (engine) { - engine->SetViewportMetrics(kDefaultViewId, viewport_metrics); + engine->SetViewportMetrics(kImplicitViewId, viewport_metrics); const auto frame_begin_time = fml::TimePoint::Now(); const auto frame_end_time = frame_begin_time + fml::TimeDelta::FromSecondsF(1.0 / 60.0); @@ -188,7 +188,7 @@ void ShellTest::PumpOneFrame(Shell* shell, fml::AutoResetWaitableEvent latch; shell->GetTaskRunners().GetUITaskRunner()->PostTask( [&latch, engine = shell->weak_engine_, viewport_metrics]() { - engine->SetViewportMetrics(kDefaultViewId, viewport_metrics); + engine->SetViewportMetrics(kImplicitViewId, viewport_metrics); const auto frame_begin_time = fml::TimePoint::Now(); const auto frame_end_time = frame_begin_time + fml::TimeDelta::FromSecondsF(1.0 / 60.0); diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index e9c606b704743..c96f525777291 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -60,7 +60,7 @@ namespace flutter { namespace testing { -constexpr int64_t kDefaultViewId = 0ll; +constexpr int64_t kImplicitViewId = 0ll; using ::testing::_; using ::testing::Return; @@ -1639,7 +1639,7 @@ TEST_F(ShellTest, MultipleFluttersSetResourceCacheBytes) { RunEngine(shell.get(), std::move(configuration)); PostSync(shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { - shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId, {1.0, 100, 100, 22, 0}); }); @@ -1669,7 +1669,7 @@ TEST_F(ShellTest, MultipleFluttersSetResourceCacheBytes) { PostSync(second_shell->GetTaskRunners().GetPlatformTaskRunner(), [&second_shell]() { second_shell->GetPlatformView()->SetViewportMetrics( - kDefaultViewId, {1.0, 100, 100, 22, 0}); + kImplicitViewId, {1.0, 100, 100, 22, 0}); }); // first cache bytes + second cache bytes EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), @@ -1678,7 +1678,7 @@ TEST_F(ShellTest, MultipleFluttersSetResourceCacheBytes) { PostSync(second_shell->GetTaskRunners().GetPlatformTaskRunner(), [&second_shell]() { second_shell->GetPlatformView()->SetViewportMetrics( - kDefaultViewId, {1.0, 100, 300, 22, 0}); + kImplicitViewId, {1.0, 100, 300, 22, 0}); }); // first cache bytes + second cache bytes EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), @@ -1689,7 +1689,7 @@ TEST_F(ShellTest, MultipleFluttersSetResourceCacheBytes) { PostSync(third_shell->GetTaskRunners().GetPlatformTaskRunner(), [&third_shell]() { third_shell->GetPlatformView()->SetViewportMetrics( - kDefaultViewId, {1.0, 400, 100, 22, 0}); + kImplicitViewId, {1.0, 400, 100, 22, 0}); }); // first cache bytes + second cache bytes + third cache bytes EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), @@ -1698,7 +1698,7 @@ TEST_F(ShellTest, MultipleFluttersSetResourceCacheBytes) { PostSync(third_shell->GetTaskRunners().GetPlatformTaskRunner(), [&third_shell]() { third_shell->GetPlatformView()->SetViewportMetrics( - kDefaultViewId, {1.0, 800, 100, 22, 0}); + kImplicitViewId, {1.0, 800, 100, 22, 0}); }); // max bytes threshold EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), @@ -1711,7 +1711,7 @@ TEST_F(ShellTest, MultipleFluttersSetResourceCacheBytes) { PostSync(second_shell->GetTaskRunners().GetPlatformTaskRunner(), [&second_shell]() { second_shell->GetPlatformView()->SetViewportMetrics( - kDefaultViewId, {1.0, 100, 100, 22, 0}); + kImplicitViewId, {1.0, 100, 100, 22, 0}); }); // first cache bytes + second cache bytes EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell), @@ -1755,7 +1755,7 @@ TEST_F(ShellTest, SetResourceCacheSize) { fml::TaskRunner::RunNowOrPostTask( shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { - shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId, {1.0, 400, 200, 22, 0}); }); PumpOneFrame(shell.get()); @@ -1776,7 +1776,7 @@ TEST_F(ShellTest, SetResourceCacheSize) { fml::TaskRunner::RunNowOrPostTask( shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { - shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId, {1.0, 800, 400, 22, 0}); }); PumpOneFrame(shell.get()); @@ -1794,7 +1794,7 @@ TEST_F(ShellTest, SetResourceCacheSizeEarly) { fml::TaskRunner::RunNowOrPostTask( shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { - shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId, {1.0, 400, 200, 22, 0}); }); PumpOneFrame(shell.get()); @@ -1822,7 +1822,7 @@ TEST_F(ShellTest, SetResourceCacheSizeNotifiesDart) { fml::TaskRunner::RunNowOrPostTask( shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() { - shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId, {1.0, 400, 200, 22, 0}); }); PumpOneFrame(shell.get()); @@ -2690,7 +2690,7 @@ TEST_F(ShellTest, DISABLED_DiscardLayerTreeOnResize) { shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell, &expected_size]() { shell->GetPlatformView()->SetViewportMetrics( - kDefaultViewId, + kImplicitViewId, {1.0, static_cast(expected_size.width()), static_cast(expected_size.height()), 22, 0}); }); @@ -2768,7 +2768,7 @@ TEST_F(ShellTest, DISABLED_DiscardResubmittedLayerTreeOnResize) { shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell, &origin_size]() { shell->GetPlatformView()->SetViewportMetrics( - kDefaultViewId, {1.0, static_cast(origin_size.width()), + kImplicitViewId, {1.0, static_cast(origin_size.width()), static_cast(origin_size.height()), 22, 0}); }); @@ -2787,7 +2787,7 @@ TEST_F(ShellTest, DISABLED_DiscardResubmittedLayerTreeOnResize) { shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell, &new_size, &resize_latch]() { shell->GetPlatformView()->SetViewportMetrics( - kDefaultViewId, {1.0, static_cast(new_size.width()), + kImplicitViewId, {1.0, static_cast(new_size.width()), static_cast(new_size.height()), 22, 0}); resize_latch.Signal(); }); @@ -2851,17 +2851,17 @@ TEST_F(ShellTest, IgnoresInvalidMetrics) { RunEngine(shell.get(), std::move(configuration)); task_runner->PostTask([&]() { - shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId, {0.0, 400, 200, 22, 0}); task_runner->PostTask([&]() { - shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId, {0.8, 0.0, 200, 22, 0}); task_runner->PostTask([&]() { - shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId, {0.8, 400, 0.0, 22, 0}); task_runner->PostTask([&]() { shell->GetPlatformView()->SetViewportMetrics( - kDefaultViewId, {0.8, 400, 200.0, 22, 0}); + kImplicitViewId, {0.8, 400, 200.0, 22, 0}); }); }); }); @@ -2873,7 +2873,7 @@ TEST_F(ShellTest, IgnoresInvalidMetrics) { latch.Reset(); task_runner->PostTask([&]() { - shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, + shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId, {1.2, 600, 300, 22, 0}); }); latch.Wait(); diff --git a/shell/platform/fuchsia/flutter/flatland_platform_view.cc b/shell/platform/fuchsia/flutter/flatland_platform_view.cc index e9c55f87f539e..e7c4067210a2e 100644 --- a/shell/platform/fuchsia/flutter/flatland_platform_view.cc +++ b/shell/platform/fuchsia/flutter/flatland_platform_view.cc @@ -8,7 +8,7 @@ namespace flutter_runner { -static constexpr int64_t kFlutterDefaultViewId = 0ll; +static constexpr int64_t kFlutterImplicitViewId = 0ll; FlatlandPlatformView::FlatlandPlatformView( flutter::PlatformView::Delegate& delegate, @@ -87,7 +87,7 @@ void FlatlandPlatformView::OnGetLayout( float pixel_ratio = view_pixel_ratio_ ? *view_pixel_ratio_ : 1.0f; - SetViewportMetrics(kFlutterDefaultViewId, + SetViewportMetrics(kFlutterImplicitViewId, { pixel_ratio, // device_pixel_ratio std::round(view_logical_size_.value()[0] * diff --git a/shell/platform/fuchsia/flutter/gfx_platform_view.cc b/shell/platform/fuchsia/flutter/gfx_platform_view.cc index 149e91d7135af..a951938e390d6 100644 --- a/shell/platform/fuchsia/flutter/gfx_platform_view.cc +++ b/shell/platform/fuchsia/flutter/gfx_platform_view.cc @@ -8,7 +8,7 @@ namespace flutter_runner { -static constexpr int64_t kFlutterDefaultViewId = 0ll; +static constexpr int64_t kFlutterImplicitViewId = 0ll; GfxPlatformView::GfxPlatformView( flutter::PlatformView::Delegate& delegate, @@ -216,7 +216,7 @@ void GfxPlatformView::OnScenicEvent( const float pixel_ratio = *view_pixel_ratio_; const std::array logical_size = *view_logical_size_; SetViewportMetrics( - kFlutterDefaultViewId, + kFlutterImplicitViewId, { pixel_ratio, // device_pixel_ratio std::round(logical_size[0] * pixel_ratio), // physical_width diff --git a/shell/testing/tester_main.cc b/shell/testing/tester_main.cc index a6719ede8ffdf..3bb48710c8bb1 100644 --- a/shell/testing/tester_main.cc +++ b/shell/testing/tester_main.cc @@ -39,7 +39,7 @@ namespace flutter { -static constexpr int64_t kDefaultViewId = 0ll; +static constexpr int64_t kImplicitViewId = 0ll; class TesterExternalViewEmbedder : public ExternalViewEmbedder { // |ExternalViewEmbedder| @@ -355,7 +355,7 @@ int RunTester(const flutter::Settings& settings, metrics.physical_width = physical_width; metrics.physical_height = physical_height; metrics.display_id = 0; - shell->GetPlatformView()->SetViewportMetrics(kDefaultViewId, metrics); + shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId, metrics); // Run the message loop and wait for the script to do its thing. fml::MessageLoop::GetCurrent().Run(); From a71e5b582b556227c2d6273d07eba3cc43162c7e Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Fri, 7 Jul 2023 10:56:41 -0700 Subject: [PATCH 12/17] Update FlutterPluginRegistrarMacOS.h --- .../macos/framework/Headers/FlutterPluginRegistrarMacOS.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h b/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h index 0a5ae5dd695a8..86746c8bb30e1 100644 --- a/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h +++ b/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h @@ -38,6 +38,10 @@ FLUTTER_DARWIN_EXPORT /** * The view displaying Flutter content. * + * This property is provided for backwards compatibility for apps + * that assume a single view. This will eventually be replaced by + * a multi-view API variant. + * * This method may return |nil|, for instance in a headless environment. */ @property(nullable, readonly) NSView* view; From 65171322aebe3a60321cfe8a35db3bac1edf63c0 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Fri, 7 Jul 2023 11:52:18 -0700 Subject: [PATCH 13/17] Format --- shell/common/shell_unittests.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index 7a1d7f4621c64..ce9feb8b4c6a8 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -2768,8 +2768,9 @@ TEST_F(ShellTest, DISABLED_DiscardResubmittedLayerTreeOnResize) { shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell, &origin_size]() { shell->GetPlatformView()->SetViewportMetrics( - kImplicitViewId, {1.0, static_cast(origin_size.width()), - static_cast(origin_size.height()), 22, 0}); + kImplicitViewId, + {1.0, static_cast(origin_size.width()), + static_cast(origin_size.height()), 22, 0}); }); auto configuration = RunConfiguration::InferFromSettings(settings); @@ -2788,7 +2789,7 @@ TEST_F(ShellTest, DISABLED_DiscardResubmittedLayerTreeOnResize) { [&shell, &new_size, &resize_latch]() { shell->GetPlatformView()->SetViewportMetrics( kImplicitViewId, {1.0, static_cast(new_size.width()), - static_cast(new_size.height()), 22, 0}); + static_cast(new_size.height()), 22, 0}); resize_latch.Signal(); }); From 19f24b213719f2be1ab452ddf86a861e57500052 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Fri, 7 Jul 2023 12:04:25 -0700 Subject: [PATCH 14/17] Update parameter docs --- lib/ui/window/platform_configuration_unittests.cc | 2 +- runtime/runtime_controller.h | 1 + shell/common/engine.h | 10 +++++----- shell/common/platform_view.h | 15 ++++++++------- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/ui/window/platform_configuration_unittests.cc b/lib/ui/window/platform_configuration_unittests.cc index 92cb0b8bcd1fa..017055a41d91e 100644 --- a/lib/ui/window/platform_configuration_unittests.cc +++ b/lib/ui/window/platform_configuration_unittests.cc @@ -115,7 +115,7 @@ TEST_F(PlatformConfigurationTest, WindowMetricsUpdate) { DestroyShell(std::move(shell), task_runners); } -TEST_F(PlatformConfigurationTest, RegularWindowIsUnavailableAtStartup) { +TEST_F(PlatformConfigurationTest, GetWindowReturnsNullForNonexistentId) { auto message_latch = std::make_shared(); auto nativeValidateConfiguration = diff --git a/runtime/runtime_controller.h b/runtime/runtime_controller.h index b4b1fcc8d3c8d..aaef6da631694 100644 --- a/runtime/runtime_controller.h +++ b/runtime/runtime_controller.h @@ -168,6 +168,7 @@ class RuntimeController : public PlatformConfigurationClient { /// If the isolate is not running, these metrics will be saved and /// flushed to the isolate when it starts. /// + /// @param[in] view_id The ID for the view that `metrics` describes. /// @param[in] metrics The window's viewport metrics. /// /// @return If the window metrics were forwarded to the running isolate. diff --git a/shell/common/engine.h b/shell/common/engine.h index d141ffa0cc28a..ca258ac392159 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -677,14 +677,14 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate { std::optional GetUIIsolateReturnCode(); //---------------------------------------------------------------------------- - /// @brief Updates the viewport metrics for the currently running Flutter - /// application. The viewport metrics detail the size of the - /// rendering viewport in texels as well as edge insets if - /// present. + /// @brief Updates the viewport metrics for a view. The viewport metrics + /// detail the size of the rendering viewport in texels as well as + /// edge insets if present. /// /// @see `ViewportMetrics` /// - /// @param[in] metrics The metrics + /// @param[in] view_id The ID for the view that `metrics` describes. + /// @param[in] metrics The metrics. /// void SetViewportMetrics(int64_t view_id, const ViewportMetrics& metrics); diff --git a/shell/common/platform_view.h b/shell/common/platform_view.h index 3e5aab515ccd8..e6c7dab924e5c 100644 --- a/shell/common/platform_view.h +++ b/shell/common/platform_view.h @@ -104,11 +104,11 @@ class PlatformView { const fml::closure& closure) = 0; //-------------------------------------------------------------------------- - /// @brief Notifies the delegate the viewport metrics of the platform - /// view have been updated. The rasterizer will need to be - /// reconfigured to render the frame in the updated viewport - /// metrics. + /// @brief Notifies the delegate the viewport metrics of a view have + /// been updated. The rasterizer will need to be reconfigured to + /// render the frame in the updated viewport metrics. /// + /// @param[in] view_id The ID for the view that `metrics` describes. /// @param[in] metrics The updated viewport metrics. /// virtual void OnPlatformViewSetViewportMetrics( @@ -466,13 +466,14 @@ class PlatformView { CustomAccessibilityActionUpdates actions); //---------------------------------------------------------------------------- - /// @brief Used by embedders to specify the updated viewport metrics. In - /// response to this call, on the raster thread, the rasterizer - /// may need to be reconfigured to the updated viewport + /// @brief Used by embedders to specify the updated viewport metrics for + /// a view. In response to this call, on the raster thread, the + /// rasterizer may need to be reconfigured to the updated viewport /// dimensions. On the UI thread, the framework may need to start /// generating a new frame for the updated viewport metrics as /// well. /// + /// @param[in] view_id The ID for the view that `metrics` describes. /// @param[in] metrics The updated viewport metrics. /// void SetViewportMetrics(int64_t view_id, const ViewportMetrics& metrics); From 73790caccfb4acf48b29e401f8c83212c7e8b03a Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Fri, 7 Jul 2023 12:07:09 -0700 Subject: [PATCH 15/17] Fix format for fuchsia --- .../fuchsia/flutter/flatland_platform_view.cc | 51 +++++++++---------- .../fuchsia/flutter/gfx_platform_view.cc | 47 +++++++++-------- 2 files changed, 48 insertions(+), 50 deletions(-) diff --git a/shell/platform/fuchsia/flutter/flatland_platform_view.cc b/shell/platform/fuchsia/flutter/flatland_platform_view.cc index e7c4067210a2e..39febd8c6db64 100644 --- a/shell/platform/fuchsia/flutter/flatland_platform_view.cc +++ b/shell/platform/fuchsia/flutter/flatland_platform_view.cc @@ -86,32 +86,31 @@ void FlatlandPlatformView::OnGetLayout( } float pixel_ratio = view_pixel_ratio_ ? *view_pixel_ratio_ : 1.0f; - - SetViewportMetrics(kFlutterImplicitViewId, - { - pixel_ratio, // device_pixel_ratio - std::round(view_logical_size_.value()[0] * - pixel_ratio), // physical_width - std::round(view_logical_size_.value()[1] * - pixel_ratio), // physical_height - 0.0f, // physical_padding_top - 0.0f, // physical_padding_right - 0.0f, // physical_padding_bottom - 0.0f, // physical_padding_left - 0.0f, // physical_view_inset_top - 0.0f, // physical_view_inset_right - 0.0f, // physical_view_inset_bottom - 0.0f, // physical_view_inset_left - 0.0f, // p_physical_system_gesture_inset_top - 0.0f, // p_physical_system_gesture_inset_right - 0.0f, // p_physical_system_gesture_inset_bottom - 0.0f, // p_physical_system_gesture_inset_left, - -1.0, // p_physical_touch_slop, - {}, // p_physical_display_features_bounds - {}, // p_physical_display_features_type - {}, // p_physical_display_features_state - 0, // p_display_id - }); + flutter::ViewportMetrics metrics{ + pixel_ratio, // device_pixel_ratio + std::round(view_logical_size_.value()[0] * + pixel_ratio), // physical_width + std::round(view_logical_size_.value()[1] * + pixel_ratio), // physical_height + 0.0f, // physical_padding_top + 0.0f, // physical_padding_right + 0.0f, // physical_padding_bottom + 0.0f, // physical_padding_left + 0.0f, // physical_view_inset_top + 0.0f, // physical_view_inset_right + 0.0f, // physical_view_inset_bottom + 0.0f, // physical_view_inset_left + 0.0f, // p_physical_system_gesture_inset_top + 0.0f, // p_physical_system_gesture_inset_right + 0.0f, // p_physical_system_gesture_inset_bottom + 0.0f, // p_physical_system_gesture_inset_left, + -1.0, // p_physical_touch_slop, + {}, // p_physical_display_features_bounds + {}, // p_physical_display_features_type + {}, // p_physical_display_features_state + 0, // p_display_id + }; + SetViewportMetrics(kFlutterImplicitViewId, metrics); parent_viewport_watcher_->GetLayout( fit::bind_member(this, &FlatlandPlatformView::OnGetLayout)); diff --git a/shell/platform/fuchsia/flutter/gfx_platform_view.cc b/shell/platform/fuchsia/flutter/gfx_platform_view.cc index a951938e390d6..ddb0ce029e2a1 100644 --- a/shell/platform/fuchsia/flutter/gfx_platform_view.cc +++ b/shell/platform/fuchsia/flutter/gfx_platform_view.cc @@ -215,30 +215,29 @@ void GfxPlatformView::OnScenicEvent( metrics_changed) { const float pixel_ratio = *view_pixel_ratio_; const std::array logical_size = *view_logical_size_; - SetViewportMetrics( - kFlutterImplicitViewId, - { - pixel_ratio, // device_pixel_ratio - std::round(logical_size[0] * pixel_ratio), // physical_width - std::round(logical_size[1] * pixel_ratio), // physical_height - 0.0f, // physical_padding_top - 0.0f, // physical_padding_right - 0.0f, // physical_padding_bottom - 0.0f, // physical_padding_left - 0.0f, // physical_view_inset_top - 0.0f, // physical_view_inset_right - 0.0f, // physical_view_inset_bottom - 0.0f, // physical_view_inset_left - 0.0f, // p_physical_system_gesture_inset_top - 0.0f, // p_physical_system_gesture_inset_right - 0.0f, // p_physical_system_gesture_inset_bottom - 0.0f, // p_physical_system_gesture_inset_left, - -1.0, // p_physical_touch_slop, - {}, // p_physical_display_features_bounds - {}, // p_physical_display_features_type - {}, // p_physical_display_features_state - 0, // pdisplay_id - }); + flutter::ViewportMetrics metrics{ + pixel_ratio, // device_pixel_ratio + std::round(logical_size[0] * pixel_ratio), // physical_width + std::round(logical_size[1] * pixel_ratio), // physical_height + 0.0f, // physical_padding_top + 0.0f, // physical_padding_right + 0.0f, // physical_padding_bottom + 0.0f, // physical_padding_left + 0.0f, // physical_view_inset_top + 0.0f, // physical_view_inset_right + 0.0f, // physical_view_inset_bottom + 0.0f, // physical_view_inset_left + 0.0f, // p_physical_system_gesture_inset_top + 0.0f, // p_physical_system_gesture_inset_right + 0.0f, // p_physical_system_gesture_inset_bottom + 0.0f, // p_physical_system_gesture_inset_left, + -1.0, // p_physical_touch_slop, + {}, // p_physical_display_features_bounds + {}, // p_physical_display_features_type + {}, // p_physical_display_features_state + 0, // pdisplay_id + }; + SetViewportMetrics(kFlutterImplicitViewId, metrics); } } From 4b57af3b2ad61d8ff652f0d929f25e24145a44de Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Fri, 7 Jul 2023 13:32:33 -0700 Subject: [PATCH 16/17] Address feedback --- shell/common/shell.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 23de5bea8f0fd..82b3b831ebb68 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -979,7 +979,7 @@ void Shell::OnPlatformViewSetViewportMetrics(int64_t view_id, }); task_runners_.GetUITaskRunner()->PostTask( - [engine = engine_->GetWeakPtr(), metrics, view_id]() { + [engine = engine_->GetWeakPtr(), view_id, metrics]() { if (engine) { engine->SetViewportMetrics(view_id, metrics); } From f3cb395c778ae23e282f3a93a1afc509ec172023 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Fri, 7 Jul 2023 14:34:09 -0700 Subject: [PATCH 17/17] Add test IgnoresMetricsUpdateToInvalidView --- runtime/runtime_controller.cc | 2 ++ shell/common/shell_unittests.cc | 50 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/runtime/runtime_controller.cc b/runtime/runtime_controller.cc index 9cc704a8e7077..751fa696a5719 100644 --- a/runtime/runtime_controller.cc +++ b/runtime/runtime_controller.cc @@ -138,6 +138,8 @@ bool RuntimeController::SetViewportMetrics(int64_t view_id, if (window) { window->UpdateWindowMetrics(metrics); return true; + } else { + FML_LOG(WARNING) << "View ID " << view_id << " does not exist."; } } diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index ce9feb8b4c6a8..4c4c85f8b768b 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -2852,15 +2852,19 @@ TEST_F(ShellTest, IgnoresInvalidMetrics) { RunEngine(shell.get(), std::move(configuration)); task_runner->PostTask([&]() { + // This one is invalid for having 0 pixel ratio. shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId, {0.0, 400, 200, 22, 0}); task_runner->PostTask([&]() { + // This one is invalid for having 0 width. shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId, {0.8, 0.0, 200, 22, 0}); task_runner->PostTask([&]() { + // This one is invalid for having 0 height. shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId, {0.8, 400, 0.0, 22, 0}); task_runner->PostTask([&]() { + // This one makes it through. shell->GetPlatformView()->SetViewportMetrics( kImplicitViewId, {0.8, 400, 200.0, 22, 0}); }); @@ -2885,6 +2889,52 @@ TEST_F(ShellTest, IgnoresInvalidMetrics) { DestroyShell(std::move(shell), task_runners); } +TEST_F(ShellTest, IgnoresMetricsUpdateToInvalidView) { + fml::AutoResetWaitableEvent latch; + double last_device_pixel_ratio; + // This callback will be called whenever any view's metrics change. + auto native_report_device_pixel_ratio = [&](Dart_NativeArguments args) { + // The correct call will have a DPR of 3. + auto dpr_handle = Dart_GetNativeArgument(args, 0); + ASSERT_TRUE(Dart_IsDouble(dpr_handle)); + Dart_DoubleValue(dpr_handle, &last_device_pixel_ratio); + ASSERT_TRUE(last_device_pixel_ratio > 2.5); + + latch.Signal(); + }; + + Settings settings = CreateSettingsForFixture(); + auto task_runner = CreateNewThread(); + TaskRunners task_runners("test", task_runner, task_runner, task_runner, + task_runner); + + AddNativeCallback("ReportMetrics", + CREATE_NATIVE_ENTRY(native_report_device_pixel_ratio)); + + std::unique_ptr shell = CreateShell(settings, task_runners); + + auto configuration = RunConfiguration::InferFromSettings(settings); + configuration.SetEntrypoint("reportMetrics"); + + RunEngine(shell.get(), std::move(configuration)); + + task_runner->PostTask([&]() { + // This one is invalid for having an nonexistent view ID. + // Also, it has a DPR of 2.0 for detection. + shell->GetPlatformView()->SetViewportMetrics(2, {2.0, 400, 200, 22, 0}); + task_runner->PostTask([&]() { + // This one is valid with DPR 3.0. + shell->GetPlatformView()->SetViewportMetrics(kImplicitViewId, + {3.0, 400, 200, 22, 0}); + }); + }); + latch.Wait(); + ASSERT_EQ(last_device_pixel_ratio, 3.0); + latch.Reset(); + + DestroyShell(std::move(shell), task_runners); +} + TEST_F(ShellTest, OnServiceProtocolSetAssetBundlePathWorks) { Settings settings = CreateSettingsForFixture(); std::unique_ptr shell = CreateShell(settings);