From a6cf2c35f2cd07247b5cc04daf673a4611ef0cf5 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 1 May 2023 16:04:40 -0700 Subject: [PATCH 1/5] Impl --- .../macos/framework/Headers/FlutterEngine.h | 11 -------- .../Headers/FlutterPluginRegistrarMacOS.h | 5 ---- .../framework/Headers/FlutterViewController.h | 10 ------- .../framework/Source/FlutterCompositor.h | 2 +- .../framework/Source/FlutterCompositor.mm | 2 +- .../framework/Source/FlutterCompositorTest.mm | 4 +-- .../macos/framework/Source/FlutterEngine.mm | 28 +++++++++++++------ .../framework/Source/FlutterEngineTest.mm | 10 +++---- .../framework/Source/FlutterEngine_Internal.h | 2 +- .../FlutterPlatformNodeDelegateMacTest.mm | 2 +- .../macos/framework/Source/FlutterRenderer.h | 4 +-- .../macos/framework/Source/FlutterRenderer.mm | 8 +++--- .../framework/Source/FlutterViewController.mm | 6 ++-- .../Source/FlutterViewController_Internal.h | 12 +++++++- .../Source/FlutterViewEngineProvider.mm | 2 +- .../Source/FlutterViewEngineProviderTest.mm | 2 +- .../framework/Source/FlutterViewProvider.h | 4 +-- 17 files changed, 56 insertions(+), 58 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Headers/FlutterEngine.h b/shell/platform/darwin/macos/framework/Headers/FlutterEngine.h index 7c7bea715893b..f854976ebd611 100644 --- a/shell/platform/darwin/macos/framework/Headers/FlutterEngine.h +++ b/shell/platform/darwin/macos/framework/Headers/FlutterEngine.h @@ -17,17 +17,6 @@ // TODO: Merge this file with the iOS FlutterEngine.h. -/** - * The view ID for APIs that don't support multi-view. - * - * 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 the view with - * this ID. Also, the first view assigned to the engine will also have this ID. - */ -extern const uint64_t kFlutterDefaultViewId; - @class FlutterViewController; /** diff --git a/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h b/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h index 39fbba1b43bd3..b67d6b87c8021 100644 --- a/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h +++ b/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h @@ -44,11 +44,6 @@ FLUTTER_DARWIN_EXPORT */ @property(nullable, readonly) NSView* view; -/** - * The `NSView` associated with the given view ID, if any. - */ -- (nullable NSView*)viewForId:(uint64_t)viewId; - /** * Registers |delegate| to receive handleMethodCall:result: callbacks for the given |channel|. */ diff --git a/shell/platform/darwin/macos/framework/Headers/FlutterViewController.h b/shell/platform/darwin/macos/framework/Headers/FlutterViewController.h index eb3c0a0f5984a..77856862eb980 100644 --- a/shell/platform/darwin/macos/framework/Headers/FlutterViewController.h +++ b/shell/platform/darwin/macos/framework/Headers/FlutterViewController.h @@ -53,16 +53,6 @@ FLUTTER_DARWIN_EXPORT */ @property(nonatomic, nonnull, readonly) FlutterEngine* engine; -/** - * The identifier for this view controller. - * - * The ID is assigned by FlutterEngine when the view controller is attached. - * - * If the view controller is unattached (see FlutterViewController#attached), - * reading this property throws an assertion. - */ -@property(nonatomic, readonly) uint64_t viewId; - /** * The style of mouse tracking to use for the view. Defaults to * FlutterMouseTrackingModeInKeyWindow. diff --git a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h index 575742df2c8ef..2e3828016174d 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h @@ -49,7 +49,7 @@ class FlutterCompositor { // Presents the FlutterLayers by updating the FlutterView specified by // `view_id` using the layer content. Sets frame_started_ to false. - bool Present(uint64_t view_id, const FlutterLayer** layers, size_t layers_count); + bool Present(int64_t view_id, const FlutterLayer** layers, size_t layers_count); private: void PresentPlatformViews(FlutterView* default_base_view, diff --git a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm index 96acf4bb2a189..836662785e85a 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm @@ -37,7 +37,7 @@ return true; } -bool FlutterCompositor::Present(uint64_t view_id, +bool FlutterCompositor::Present(int64_t view_id, const FlutterLayer** layers, size_t layers_count) { FlutterView* view = [view_provider_ viewForId:view_id]; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm index 4005b176aaf24..8755ae3f14132 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm @@ -11,7 +11,7 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h" #import "flutter/testing/testing.h" -extern const uint64_t kFlutterDefaultViewId; +extern const int64_t kFlutterDefaultViewId; @interface FlutterViewMockProvider : NSObject { FlutterView* _defaultView; @@ -32,7 +32,7 @@ - (nonnull instancetype)initWithDefaultView:(nonnull FlutterView*)view { return self; } -- (nullable FlutterView*)viewForId:(uint64_t)viewId { +- (nullable FlutterView*)viewForId:(int64_t)viewId { if (viewId == kFlutterDefaultViewId) { return _defaultView; } diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm index 913b9a64f3ae5..6bf07c0519d5a 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm @@ -23,7 +23,17 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h" #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.h" -const uint64_t kFlutterDefaultViewId = 0; + +/** + * The view ID for APIs that don't support multi-view. + * + * 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 the view with + * this ID. Also, the first view assigned to the engine will also have this ID. + */ +const int64_t kFlutterDefaultViewId = 0; NSString* const kFlutterPlatformChannel = @"flutter/platform"; @@ -88,7 +98,7 @@ @interface FlutterEngine () */ @property(nonatomic, strong) NSMutableArray* isResponseValid; -- (nullable FlutterViewController*)viewControllerForId:(uint64_t)viewId; +- (nullable FlutterViewController*)viewControllerForId:(int64_t)viewId; /** * An internal method that adds the view controller with the given ID. @@ -96,7 +106,7 @@ - (nullable FlutterViewController*)viewControllerForId:(uint64_t)viewId; * This method assigns the controller with the ID, puts the controller into the * map, and does assertions related to the default view ID. */ -- (void)registerViewController:(FlutterViewController*)controller forId:(uint64_t)viewId; +- (void)registerViewController:(FlutterViewController*)controller forId:(int64_t)viewId; /** * An internal method that removes the view controller with the given ID. @@ -105,7 +115,7 @@ - (void)registerViewController:(FlutterViewController*)controller forId:(uint64_ * map. This is an no-op if the view ID is not associated with any view * controllers. */ -- (void)deregisterViewControllerForId:(uint64_t)viewId; +- (void)deregisterViewControllerForId:(int64_t)viewId; /** * Shuts down the engine if view requirement is not met, and headless execution @@ -259,6 +269,8 @@ - (void)requestApplicationTermination:(id)sender @interface FlutterEngineRegistrar : NSObject - (instancetype)initWithPlugin:(nonnull NSString*)pluginKey flutterEngine:(nonnull FlutterEngine*)flutterEngine; + +- (NSView*)viewForId:(int64_t)viewId; @end @implementation FlutterEngineRegistrar { @@ -291,7 +303,7 @@ - (NSView*)view { return [self viewForId:kFlutterDefaultViewId]; } -- (NSView*)viewForId:(uint64_t)viewId { +- (NSView*)viewForId:(int64_t)viewId { FlutterViewController* controller = [_flutterEngine viewControllerForId:viewId]; if (controller == nil) { return nil; @@ -570,7 +582,7 @@ - (void)loadAOTData:(NSString*)assetsDir { } } -- (void)registerViewController:(FlutterViewController*)controller forId:(uint64_t)viewId { +- (void)registerViewController:(FlutterViewController*)controller forId:(int64_t)viewId { NSAssert(controller != nil, @"The controller must not be nil."); NSAssert(![controller attached], @"The incoming view controller is already attached to an engine."); @@ -580,7 +592,7 @@ - (void)registerViewController:(FlutterViewController*)controller forId:(uint64_ [_viewControllers setObject:controller forKey:@(viewId)]; } -- (void)deregisterViewControllerForId:(uint64_t)viewId { +- (void)deregisterViewControllerForId:(int64_t)viewId { FlutterViewController* oldController = [self viewControllerForId:viewId]; if (oldController != nil) { [oldController detachFromEngine]; @@ -594,7 +606,7 @@ - (void)shutDownIfNeeded { } } -- (FlutterViewController*)viewControllerForId:(uint64_t)viewId { +- (FlutterViewController*)viewControllerForId:(int64_t)viewId { FlutterViewController* controller = [_viewControllers objectForKey:@(viewId)]; NSAssert(controller == nil || controller.viewId == viewId, @"The stored controller has unexpected view ID."); diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm index af2cc140f909f..d7aa813ca2fbf 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm @@ -646,7 +646,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable @autoreleasepool { // Create FVC1. viewController1 = [[FlutterViewController alloc] initWithProject:project]; - EXPECT_EQ(viewController1.viewId, 0ull); + EXPECT_EQ(viewController1.viewId, 0ll); engine = viewController1.engine; engine.viewController = nil; @@ -663,7 +663,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable engine.viewController = viewController1; EXPECT_EQ(engine.viewController, viewController1); - EXPECT_EQ(viewController1.viewId, 0ull); + EXPECT_EQ(viewController1.viewId, 0ll); } TEST_F(FlutterEngineTest, ManageControllersIfInitiatedByEngine) { @@ -677,7 +677,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable @autoreleasepool { viewController1 = [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil]; - EXPECT_EQ(viewController1.viewId, 0ull); + EXPECT_EQ(viewController1.viewId, 0ll); EXPECT_EQ(engine.viewController, viewController1); engine.viewController = nil; @@ -685,7 +685,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable FlutterViewController* viewController2 = [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil]; - EXPECT_EQ(viewController2.viewId, 0ull); + EXPECT_EQ(viewController2.viewId, 0ll); EXPECT_EQ(engine.viewController, viewController2); } // FVC2 is deallocated but FVC1 is retained. @@ -694,7 +694,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable engine.viewController = viewController1; EXPECT_EQ(engine.viewController, viewController1); - EXPECT_EQ(viewController1.viewId, 0ull); + EXPECT_EQ(viewController1.viewId, 0ll); } TEST_F(FlutterEngineTest, HandlesTerminationRequest) { diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h b/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h index 13c47f239ab69..48899813f2aac 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h @@ -135,7 +135,7 @@ typedef NS_ENUM(NSInteger, FlutterAppExitResponse) { /** * The |FlutterViewController| associated with the given view ID, if any. */ -- (nullable FlutterViewController*)viewControllerForId:(uint64_t)viewId; +- (nullable FlutterViewController*)viewControllerForId:(int64_t)viewId; /** * Informs the engine that the specified view controller's window metrics have changed. diff --git a/shell/platform/darwin/macos/framework/Source/FlutterPlatformNodeDelegateMacTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterPlatformNodeDelegateMacTest.mm index d7c12689fe729..f05210012ed3c 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterPlatformNodeDelegateMacTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterPlatformNodeDelegateMacTest.mm @@ -192,7 +192,7 @@ // Set up embedder API mock. FlutterSemanticsAction called_action; - uint64_t called_id; + int64_t called_id; engine.embedderAPI.DispatchSemanticsAction = MOCK_ENGINE_PROC( DispatchSemanticsAction, diff --git a/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h b/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h index 483a858032bc8..47e280296ae80 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h @@ -38,12 +38,12 @@ /** * Called by the engine when the given view's buffers should be swapped. */ -- (BOOL)present:(uint64_t)viewId texture:(nonnull const FlutterMetalTexture*)texture; +- (BOOL)present:(int64_t)viewId texture:(nonnull const FlutterMetalTexture*)texture; /** * Creates a Metal texture for the given view with the given size. */ -- (FlutterMetalTexture)createTextureForView:(uint64_t)viewId size:(CGSize)size; +- (FlutterMetalTexture)createTextureForView:(int64_t)viewId size:(CGSize)size; /** * Populates the texture registry with the provided metalTexture. diff --git a/shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm b/shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm index d7d2c2fc7d6ac..fcee537f3b404 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm @@ -17,7 +17,7 @@ static FlutterMetalTexture OnGetNextDrawableForDefaultView(FlutterEngine* engine // TODO(dkwingsmt): This callback only supports single-view, therefore it only // operates on the default view. To support multi-view, we need a new callback // that also receives a view ID, or pass the ID via FlutterFrameInfo. - uint64_t viewId = kFlutterDefaultViewId; + int64_t viewId = kFlutterDefaultViewId; CGSize size = CGSizeMake(frameInfo->size.width, frameInfo->size.height); return [engine.renderer createTextureForView:viewId size:size]; } @@ -27,7 +27,7 @@ static bool OnPresentDrawableOfDefaultView(FlutterEngine* engine, // TODO(dkwingsmt): This callback only supports single-view, therefore it only // operates on the default view. To support multi-view, we need a new callback // that also receives a view ID. - uint64_t viewId = kFlutterDefaultViewId; + int64_t viewId = kFlutterDefaultViewId; return [engine.renderer present:viewId texture:texture]; } @@ -88,7 +88,7 @@ - (FlutterRendererConfig)createRendererConfig { #pragma mark - Embedder callback implementations. -- (FlutterMetalTexture)createTextureForView:(uint64_t)viewId size:(CGSize)size { +- (FlutterMetalTexture)createTextureForView:(int64_t)viewId size:(CGSize)size { FlutterView* view = [_viewProvider viewForId:viewId]; NSAssert(view != nil, @"Can't create texture on a non-existent view 0x%llx.", viewId); if (view == nil) { @@ -98,7 +98,7 @@ - (FlutterMetalTexture)createTextureForView:(uint64_t)viewId size:(CGSize)size { return [view.surfaceManager surfaceForSize:size].asFlutterMetalTexture; } -- (BOOL)present:(uint64_t)viewId texture:(const FlutterMetalTexture*)texture { +- (BOOL)present:(int64_t)viewId texture:(const FlutterMetalTexture*)texture { FlutterView* view = [_viewProvider viewForId:viewId]; if (view == nil) { return NO; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm b/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm index acd07a827c569..793e6d000eb74 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm @@ -370,6 +370,8 @@ @implementation FlutterViewController { FlutterDartProject* _project; std::shared_ptr _bridge; + + int64_t _id; } @synthesize viewId = _viewId; @@ -510,7 +512,7 @@ - (void)setBackgroundColor:(NSColor*)color { [_flutterView setBackgroundColor:_backgroundColor]; } -- (uint64_t)viewId { +- (int64_t)viewId { NSAssert([self attached], @"This view controller is not attched."); return _viewId; } @@ -539,7 +541,7 @@ - (void)notifySemanticsEnabledChanged { return _bridge; } -- (void)attachToEngine:(nonnull FlutterEngine*)engine withId:(uint64_t)viewId { +- (void)attachToEngine:(nonnull FlutterEngine*)engine withId:(int64_t)viewId { NSAssert(_engine == nil, @"Already attached to an engine %@.", _engine); _engine = engine; _viewId = viewId; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h b/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h index 1281b60694765..d266855cdd00f 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h @@ -13,6 +13,16 @@ @interface FlutterViewController () +/** + * The identifier for this view controller. + * + * The ID is assigned by FlutterEngine when the view controller is attached. + * + * If the view controller is unattached (see FlutterViewController#attached), + * reading this property throws an assertion. + */ +@property(nonatomic, readonly) int64_t viewId; + // The FlutterView for this view controller. @property(nonatomic, readonly, nullable) FlutterView* flutterView; @@ -33,7 +43,7 @@ * * This method is called by FlutterEngine. */ -- (void)attachToEngine:(nonnull FlutterEngine*)engine withId:(uint64_t)viewId; +- (void)attachToEngine:(nonnull FlutterEngine*)engine withId:(int64_t)viewId; /** * Reset the `engine` and `id` of this controller. diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.mm b/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.mm index 95c3aa53e0ee5..a4915a0cb88e1 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.mm @@ -22,7 +22,7 @@ - (instancetype)initWithEngine:(FlutterEngine*)engine { return self; } -- (nullable FlutterView*)viewForId:(uint64_t)viewId { +- (nullable FlutterView*)viewForId:(int64_t)viewId { return [_engine viewControllerForId:viewId].flutterView; } diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm index 86c94a70caa60..1e9dcdf11ab5d 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm @@ -25,7 +25,7 @@ OCMStub([mockEngine viewControllerForId:0]) .ignoringNonObjectArgs() .andDo(^(NSInvocation* invocation) { - uint64_t viewId; + int64_t viewId; [invocation getArgument:&viewId atIndex:2]; if (viewId == 0 /* kFlutterDefaultViewId */) { if (mockFlutterViewController != nil) { diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h b/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h index 9548b7afab1b8..e772573518650 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h @@ -4,7 +4,7 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h" -extern const uint64_t kFlutterDefaultViewId; +extern const int64_t kFlutterDefaultViewId; /** * An interface to query FlutterView. @@ -20,6 +20,6 @@ extern const uint64_t kFlutterDefaultViewId; * * Returns nil if the ID is invalid. */ -- (nullable FlutterView*)viewForId:(uint64_t)id; +- (nullable FlutterView*)viewForId:(int64_t)id; @end From 2845b2a528480f892375f532addc65232b51ec8a Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 1 May 2023 16:05:04 -0700 Subject: [PATCH 2/5] Format --- .../darwin/macos/framework/Source/FlutterCompositor.mm | 4 +--- shell/platform/darwin/macos/framework/Source/FlutterEngine.mm | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm index 836662785e85a..890114de9d5da 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm @@ -37,9 +37,7 @@ return true; } -bool FlutterCompositor::Present(int64_t view_id, - const FlutterLayer** layers, - size_t layers_count) { +bool FlutterCompositor::Present(int64_t view_id, const FlutterLayer** layers, size_t layers_count) { FlutterView* view = [view_provider_ viewForId:view_id]; if (!view) { return false; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm index 6bf07c0519d5a..1c489e73504af 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm @@ -23,7 +23,6 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h" #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.h" - /** * The view ID for APIs that don't support multi-view. * From 9275a316e5d441ed4a98755d0dc1dbb065d4d1de Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 1 May 2023 16:29:12 -0700 Subject: [PATCH 3/5] Change to typedef --- .../framework/Source/FlutterCompositorTest.mm | 4 +-- .../macos/framework/Source/FlutterEngine.mm | 27 ++++++------------- .../framework/Source/FlutterEngine_Internal.h | 2 +- .../macos/framework/Source/FlutterRenderer.h | 4 +-- .../macos/framework/Source/FlutterRenderer.mm | 8 +++--- .../macos/framework/Source/FlutterView.h | 13 +++++++++ .../framework/Source/FlutterViewController.mm | 4 +-- .../Source/FlutterViewController_Internal.h | 4 +-- .../Source/FlutterViewEngineProvider.mm | 2 +- .../Source/FlutterViewEngineProviderTest.mm | 4 +-- .../framework/Source/FlutterViewProvider.h | 2 -- 11 files changed, 36 insertions(+), 38 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm index 8755ae3f14132..f7ac37e01be68 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm @@ -11,8 +11,6 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h" #import "flutter/testing/testing.h" -extern const int64_t kFlutterDefaultViewId; - @interface FlutterViewMockProvider : NSObject { FlutterView* _defaultView; } @@ -32,7 +30,7 @@ - (nonnull instancetype)initWithDefaultView:(nonnull FlutterView*)view { return self; } -- (nullable FlutterView*)viewForId:(int64_t)viewId { +- (nullable FlutterView*)viewForId:(FlutterViewId)viewId { if (viewId == kFlutterDefaultViewId) { return _defaultView; } diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm index 1c489e73504af..7107b4024ad14 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm @@ -23,17 +23,6 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h" #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.h" -/** - * The view ID for APIs that don't support multi-view. - * - * 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 the view with - * this ID. Also, the first view assigned to the engine will also have this ID. - */ -const int64_t kFlutterDefaultViewId = 0; - NSString* const kFlutterPlatformChannel = @"flutter/platform"; /** @@ -97,7 +86,7 @@ @interface FlutterEngine () */ @property(nonatomic, strong) NSMutableArray* isResponseValid; -- (nullable FlutterViewController*)viewControllerForId:(int64_t)viewId; +- (nullable FlutterViewController*)viewControllerForId:(FlutterViewId)viewId; /** * An internal method that adds the view controller with the given ID. @@ -105,7 +94,7 @@ - (nullable FlutterViewController*)viewControllerForId:(int64_t)viewId; * This method assigns the controller with the ID, puts the controller into the * map, and does assertions related to the default view ID. */ -- (void)registerViewController:(FlutterViewController*)controller forId:(int64_t)viewId; +- (void)registerViewController:(FlutterViewController*)controller forId:(FlutterViewId)viewId; /** * An internal method that removes the view controller with the given ID. @@ -114,7 +103,7 @@ - (void)registerViewController:(FlutterViewController*)controller forId:(int64_t * map. This is an no-op if the view ID is not associated with any view * controllers. */ -- (void)deregisterViewControllerForId:(int64_t)viewId; +- (void)deregisterViewControllerForId:(FlutterViewId)viewId; /** * Shuts down the engine if view requirement is not met, and headless execution @@ -269,7 +258,7 @@ @interface FlutterEngineRegistrar : NSObject - (instancetype)initWithPlugin:(nonnull NSString*)pluginKey flutterEngine:(nonnull FlutterEngine*)flutterEngine; -- (NSView*)viewForId:(int64_t)viewId; +- (NSView*)viewForId:(FlutterViewId)viewId; @end @implementation FlutterEngineRegistrar { @@ -302,7 +291,7 @@ - (NSView*)view { return [self viewForId:kFlutterDefaultViewId]; } -- (NSView*)viewForId:(int64_t)viewId { +- (NSView*)viewForId:(FlutterViewId)viewId { FlutterViewController* controller = [_flutterEngine viewControllerForId:viewId]; if (controller == nil) { return nil; @@ -581,7 +570,7 @@ - (void)loadAOTData:(NSString*)assetsDir { } } -- (void)registerViewController:(FlutterViewController*)controller forId:(int64_t)viewId { +- (void)registerViewController:(FlutterViewController*)controller forId:(FlutterViewId)viewId { NSAssert(controller != nil, @"The controller must not be nil."); NSAssert(![controller attached], @"The incoming view controller is already attached to an engine."); @@ -591,7 +580,7 @@ - (void)registerViewController:(FlutterViewController*)controller forId:(int64_t [_viewControllers setObject:controller forKey:@(viewId)]; } -- (void)deregisterViewControllerForId:(int64_t)viewId { +- (void)deregisterViewControllerForId:(FlutterViewId)viewId { FlutterViewController* oldController = [self viewControllerForId:viewId]; if (oldController != nil) { [oldController detachFromEngine]; @@ -605,7 +594,7 @@ - (void)shutDownIfNeeded { } } -- (FlutterViewController*)viewControllerForId:(int64_t)viewId { +- (FlutterViewController*)viewControllerForId:(FlutterViewId)viewId { FlutterViewController* controller = [_viewControllers objectForKey:@(viewId)]; NSAssert(controller == nil || controller.viewId == viewId, @"The stored controller has unexpected view ID."); diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h b/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h index 48899813f2aac..e291094eaa342 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h @@ -135,7 +135,7 @@ typedef NS_ENUM(NSInteger, FlutterAppExitResponse) { /** * The |FlutterViewController| associated with the given view ID, if any. */ -- (nullable FlutterViewController*)viewControllerForId:(int64_t)viewId; +- (nullable FlutterViewController*)viewControllerForId:(FlutterViewId)viewId; /** * Informs the engine that the specified view controller's window metrics have changed. diff --git a/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h b/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h index 47e280296ae80..1665008d20840 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h @@ -38,12 +38,12 @@ /** * Called by the engine when the given view's buffers should be swapped. */ -- (BOOL)present:(int64_t)viewId texture:(nonnull const FlutterMetalTexture*)texture; +- (BOOL)present:(FlutterViewId)viewId texture:(nonnull const FlutterMetalTexture*)texture; /** * Creates a Metal texture for the given view with the given size. */ -- (FlutterMetalTexture)createTextureForView:(int64_t)viewId size:(CGSize)size; +- (FlutterMetalTexture)createTextureForView:(FlutterViewId)viewId size:(CGSize)size; /** * Populates the texture registry with the provided metalTexture. diff --git a/shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm b/shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm index fcee537f3b404..cf05690f5254c 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm @@ -17,7 +17,7 @@ static FlutterMetalTexture OnGetNextDrawableForDefaultView(FlutterEngine* engine // TODO(dkwingsmt): This callback only supports single-view, therefore it only // operates on the default view. To support multi-view, we need a new callback // that also receives a view ID, or pass the ID via FlutterFrameInfo. - int64_t viewId = kFlutterDefaultViewId; + FlutterViewId viewId = kFlutterDefaultViewId; CGSize size = CGSizeMake(frameInfo->size.width, frameInfo->size.height); return [engine.renderer createTextureForView:viewId size:size]; } @@ -27,7 +27,7 @@ static bool OnPresentDrawableOfDefaultView(FlutterEngine* engine, // TODO(dkwingsmt): This callback only supports single-view, therefore it only // operates on the default view. To support multi-view, we need a new callback // that also receives a view ID. - int64_t viewId = kFlutterDefaultViewId; + FlutterViewId viewId = kFlutterDefaultViewId; return [engine.renderer present:viewId texture:texture]; } @@ -88,7 +88,7 @@ - (FlutterRendererConfig)createRendererConfig { #pragma mark - Embedder callback implementations. -- (FlutterMetalTexture)createTextureForView:(int64_t)viewId size:(CGSize)size { +- (FlutterMetalTexture)createTextureForView:(FlutterViewId)viewId size:(CGSize)size { FlutterView* view = [_viewProvider viewForId:viewId]; NSAssert(view != nil, @"Can't create texture on a non-existent view 0x%llx.", viewId); if (view == nil) { @@ -98,7 +98,7 @@ - (FlutterMetalTexture)createTextureForView:(int64_t)viewId size:(CGSize)size { return [view.surfaceManager surfaceForSize:size].asFlutterMetalTexture; } -- (BOOL)present:(int64_t)viewId texture:(const FlutterMetalTexture*)texture { +- (BOOL)present:(FlutterViewId)viewId texture:(const FlutterMetalTexture*)texture { FlutterView* view = [_viewProvider viewForId:viewId]; if (view == nil) { return NO; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterView.h b/shell/platform/darwin/macos/framework/Source/FlutterView.h index 73425737fbd3a..f581079574bdc 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterView.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterView.h @@ -9,6 +9,19 @@ #include +typedef int64_t FlutterViewId; + +/** + * The view ID for APIs that don't support multi-view. + * + * 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 the view with + * this ID. Also, the first view assigned to the engine will also have this ID. + */ +constexpr FlutterViewId kFlutterDefaultViewId = 0ll; + /** * Listener for view resizing. */ diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm b/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm index 793e6d000eb74..08e547c65e506 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm @@ -512,7 +512,7 @@ - (void)setBackgroundColor:(NSColor*)color { [_flutterView setBackgroundColor:_backgroundColor]; } -- (int64_t)viewId { +- (FlutterViewId)viewId { NSAssert([self attached], @"This view controller is not attched."); return _viewId; } @@ -541,7 +541,7 @@ - (void)notifySemanticsEnabledChanged { return _bridge; } -- (void)attachToEngine:(nonnull FlutterEngine*)engine withId:(int64_t)viewId { +- (void)attachToEngine:(nonnull FlutterEngine*)engine withId:(FlutterViewId)viewId { NSAssert(_engine == nil, @"Already attached to an engine %@.", _engine); _engine = engine; _viewId = viewId; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h b/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h index d266855cdd00f..62801f9bce739 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h @@ -21,7 +21,7 @@ * If the view controller is unattached (see FlutterViewController#attached), * reading this property throws an assertion. */ -@property(nonatomic, readonly) int64_t viewId; +@property(nonatomic, readonly) FlutterViewId viewId; // The FlutterView for this view controller. @property(nonatomic, readonly, nullable) FlutterView* flutterView; @@ -43,7 +43,7 @@ * * This method is called by FlutterEngine. */ -- (void)attachToEngine:(nonnull FlutterEngine*)engine withId:(int64_t)viewId; +- (void)attachToEngine:(nonnull FlutterEngine*)engine withId:(FlutterViewId)viewId; /** * Reset the `engine` and `id` of this controller. diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.mm b/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.mm index a4915a0cb88e1..eabf7e13d938b 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.mm @@ -22,7 +22,7 @@ - (instancetype)initWithEngine:(FlutterEngine*)engine { return self; } -- (nullable FlutterView*)viewForId:(int64_t)viewId { +- (nullable FlutterView*)viewForId:(FlutterViewId)viewId { return [_engine viewControllerForId:viewId].flutterView; } diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm index 1e9dcdf11ab5d..403639b79e62a 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm @@ -25,9 +25,9 @@ OCMStub([mockEngine viewControllerForId:0]) .ignoringNonObjectArgs() .andDo(^(NSInvocation* invocation) { - int64_t viewId; + FlutterViewId viewId; [invocation getArgument:&viewId atIndex:2]; - if (viewId == 0 /* kFlutterDefaultViewId */) { + if (viewId == kFlutterDefaultViewId) { if (mockFlutterViewController != nil) { [invocation setReturnValue:&mockFlutterViewController]; } diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h b/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h index e772573518650..65df8af72fe85 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h @@ -4,8 +4,6 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h" -extern const int64_t kFlutterDefaultViewId; - /** * An interface to query FlutterView. * From ba9d6f7bb331154ba9214bda5d08670b73f18f26 Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 1 May 2023 16:37:59 -0700 Subject: [PATCH 4/5] Fix more types --- .../platform/darwin/macos/framework/Source/FlutterCompositor.h | 2 +- .../platform/darwin/macos/framework/Source/FlutterCompositor.mm | 2 +- .../framework/Source/FlutterPlatformNodeDelegateMacTest.mm | 2 +- .../darwin/macos/framework/Source/FlutterViewController.mm | 2 +- .../darwin/macos/framework/Source/FlutterViewProvider.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h index 2e3828016174d..ce22bb9f54916 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h @@ -49,7 +49,7 @@ class FlutterCompositor { // Presents the FlutterLayers by updating the FlutterView specified by // `view_id` using the layer content. Sets frame_started_ to false. - bool Present(int64_t view_id, const FlutterLayer** layers, size_t layers_count); + bool Present(FlutterViewId view_id, const FlutterLayer** layers, size_t layers_count); private: void PresentPlatformViews(FlutterView* default_base_view, diff --git a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm index 890114de9d5da..7159dca3aff2a 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm @@ -37,7 +37,7 @@ return true; } -bool FlutterCompositor::Present(int64_t view_id, const FlutterLayer** layers, size_t layers_count) { +bool FlutterCompositor::Present(FlutterViewId view_id, const FlutterLayer** layers, size_t layers_count) { FlutterView* view = [view_provider_ viewForId:view_id]; if (!view) { return false; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterPlatformNodeDelegateMacTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterPlatformNodeDelegateMacTest.mm index f05210012ed3c..d7c12689fe729 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterPlatformNodeDelegateMacTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterPlatformNodeDelegateMacTest.mm @@ -192,7 +192,7 @@ // Set up embedder API mock. FlutterSemanticsAction called_action; - int64_t called_id; + uint64_t called_id; engine.embedderAPI.DispatchSemanticsAction = MOCK_ENGINE_PROC( DispatchSemanticsAction, diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm b/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm index 08e547c65e506..a441a1affed45 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm @@ -371,7 +371,7 @@ @implementation FlutterViewController { std::shared_ptr _bridge; - int64_t _id; + FlutterViewId _id; } @synthesize viewId = _viewId; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h b/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h index 65df8af72fe85..0e78c2bdf0a2d 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h @@ -18,6 +18,6 @@ * * Returns nil if the ID is invalid. */ -- (nullable FlutterView*)viewForId:(int64_t)id; +- (nullable FlutterView*)viewForId:(FlutterViewId)id; @end From 7234de10769d75848be2aa1aec20a91bdb70a57b Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 1 May 2023 16:38:16 -0700 Subject: [PATCH 5/5] Format --- .../darwin/macos/framework/Source/FlutterCompositor.mm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm index 7159dca3aff2a..3da1c44edf0c4 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm @@ -37,7 +37,9 @@ return true; } -bool FlutterCompositor::Present(FlutterViewId view_id, const FlutterLayer** layers, size_t layers_count) { +bool FlutterCompositor::Present(FlutterViewId view_id, + const FlutterLayer** layers, + size_t layers_count) { FlutterView* view = [view_provider_ viewForId:view_id]; if (!view) { return false;