mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[macOS] Change view ID's type to signed and a typedef (flutter/engine#41653)
This PR changes the view ID type to `int64_t` and typedef it to `FlutterViewId` ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on writing and running engine tests. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I signed the [CLA]. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
parent
71c4831258
commit
0d1d5a7d34
@ -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(FlutterViewId view_id, const FlutterLayer** layers, size_t layers_count);
|
||||
|
||||
private:
|
||||
void PresentPlatformViews(FlutterView* default_base_view,
|
||||
|
||||
@ -37,7 +37,7 @@ bool FlutterCompositor::CreateBackingStore(const FlutterBackingStoreConfig* conf
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FlutterCompositor::Present(uint64_t view_id,
|
||||
bool FlutterCompositor::Present(FlutterViewId view_id,
|
||||
const FlutterLayer** layers,
|
||||
size_t layers_count) {
|
||||
FlutterView* view = [view_provider_ viewForId:view_id];
|
||||
|
||||
@ -11,8 +11,6 @@
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h"
|
||||
#import "flutter/testing/testing.h"
|
||||
|
||||
extern const uint64_t kFlutterDefaultViewId;
|
||||
|
||||
@interface FlutterViewMockProvider : NSObject <FlutterViewProvider> {
|
||||
FlutterView* _defaultView;
|
||||
}
|
||||
@ -32,7 +30,7 @@ extern const uint64_t kFlutterDefaultViewId;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable FlutterView*)viewForId:(uint64_t)viewId {
|
||||
- (nullable FlutterView*)viewForId:(FlutterViewId)viewId {
|
||||
if (viewId == kFlutterDefaultViewId) {
|
||||
return _defaultView;
|
||||
}
|
||||
|
||||
@ -23,8 +23,6 @@
|
||||
#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;
|
||||
|
||||
NSString* const kFlutterPlatformChannel = @"flutter/platform";
|
||||
|
||||
/**
|
||||
@ -88,7 +86,7 @@ constexpr char kTextPlainFormat[] = "text/plain";
|
||||
*/
|
||||
@property(nonatomic, strong) NSMutableArray<NSNumber*>* isResponseValid;
|
||||
|
||||
- (nullable FlutterViewController*)viewControllerForId:(uint64_t)viewId;
|
||||
- (nullable FlutterViewController*)viewControllerForId:(FlutterViewId)viewId;
|
||||
|
||||
/**
|
||||
* An internal method that adds the view controller with the given ID.
|
||||
@ -96,7 +94,7 @@ constexpr char kTextPlainFormat[] = "text/plain";
|
||||
* 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:(FlutterViewId)viewId;
|
||||
|
||||
/**
|
||||
* An internal method that removes the view controller with the given ID.
|
||||
@ -105,7 +103,7 @@ constexpr char kTextPlainFormat[] = "text/plain";
|
||||
* map. This is an no-op if the view ID is not associated with any view
|
||||
* controllers.
|
||||
*/
|
||||
- (void)deregisterViewControllerForId:(uint64_t)viewId;
|
||||
- (void)deregisterViewControllerForId:(FlutterViewId)viewId;
|
||||
|
||||
/**
|
||||
* Shuts down the engine if view requirement is not met, and headless execution
|
||||
@ -259,6 +257,8 @@ constexpr char kTextPlainFormat[] = "text/plain";
|
||||
@interface FlutterEngineRegistrar : NSObject <FlutterPluginRegistrar>
|
||||
- (instancetype)initWithPlugin:(nonnull NSString*)pluginKey
|
||||
flutterEngine:(nonnull FlutterEngine*)flutterEngine;
|
||||
|
||||
- (NSView*)viewForId:(FlutterViewId)viewId;
|
||||
@end
|
||||
|
||||
@implementation FlutterEngineRegistrar {
|
||||
@ -291,7 +291,7 @@ constexpr char kTextPlainFormat[] = "text/plain";
|
||||
return [self viewForId:kFlutterDefaultViewId];
|
||||
}
|
||||
|
||||
- (NSView*)viewForId:(uint64_t)viewId {
|
||||
- (NSView*)viewForId:(FlutterViewId)viewId {
|
||||
FlutterViewController* controller = [_flutterEngine viewControllerForId:viewId];
|
||||
if (controller == nil) {
|
||||
return nil;
|
||||
@ -578,7 +578,7 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
}
|
||||
}
|
||||
|
||||
- (void)registerViewController:(FlutterViewController*)controller forId:(uint64_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.");
|
||||
@ -588,7 +588,7 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
[_viewControllers setObject:controller forKey:@(viewId)];
|
||||
}
|
||||
|
||||
- (void)deregisterViewControllerForId:(uint64_t)viewId {
|
||||
- (void)deregisterViewControllerForId:(FlutterViewId)viewId {
|
||||
FlutterViewController* oldController = [self viewControllerForId:viewId];
|
||||
if (oldController != nil) {
|
||||
[oldController detachFromEngine];
|
||||
@ -602,7 +602,7 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
}
|
||||
}
|
||||
|
||||
- (FlutterViewController*)viewControllerForId:(uint64_t)viewId {
|
||||
- (FlutterViewController*)viewControllerForId:(FlutterViewId)viewId {
|
||||
FlutterViewController* controller = [_viewControllers objectForKey:@(viewId)];
|
||||
NSAssert(controller == nil || controller.viewId == viewId,
|
||||
@"The stored controller has unexpected view ID.");
|
||||
|
||||
@ -646,7 +646,7 @@ TEST_F(FlutterEngineTest, ManageControllersIfInitiatedByController) {
|
||||
@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 @@ TEST_F(FlutterEngineTest, ManageControllersIfInitiatedByController) {
|
||||
|
||||
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 @@ TEST_F(FlutterEngineTest, ManageControllersIfInitiatedByEngine) {
|
||||
|
||||
@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 @@ TEST_F(FlutterEngineTest, ManageControllersIfInitiatedByEngine) {
|
||||
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 @@ TEST_F(FlutterEngineTest, ManageControllersIfInitiatedByEngine) {
|
||||
|
||||
engine.viewController = viewController1;
|
||||
EXPECT_EQ(engine.viewController, viewController1);
|
||||
EXPECT_EQ(viewController1.viewId, 0ull);
|
||||
EXPECT_EQ(viewController1.viewId, 0ll);
|
||||
}
|
||||
|
||||
TEST_F(FlutterEngineTest, HandlesTerminationRequest) {
|
||||
|
||||
@ -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:(FlutterViewId)viewId;
|
||||
|
||||
/**
|
||||
* Informs the engine that the specified view controller's window metrics have changed.
|
||||
|
||||
@ -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:(FlutterViewId)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:(FlutterViewId)viewId size:(CGSize)size;
|
||||
|
||||
/**
|
||||
* Populates the texture registry with the provided metalTexture.
|
||||
|
||||
@ -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;
|
||||
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.
|
||||
uint64_t viewId = kFlutterDefaultViewId;
|
||||
FlutterViewId viewId = kFlutterDefaultViewId;
|
||||
return [engine.renderer present:viewId texture:texture];
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
|
||||
|
||||
#pragma mark - Embedder callback implementations.
|
||||
|
||||
- (FlutterMetalTexture)createTextureForView:(uint64_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 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
|
||||
return [view.surfaceManager surfaceForSize:size].asFlutterMetalTexture;
|
||||
}
|
||||
|
||||
- (BOOL)present:(uint64_t)viewId texture:(const FlutterMetalTexture*)texture {
|
||||
- (BOOL)present:(FlutterViewId)viewId texture:(const FlutterMetalTexture*)texture {
|
||||
FlutterView* view = [_viewProvider viewForId:viewId];
|
||||
if (view == nil) {
|
||||
return NO;
|
||||
|
||||
@ -9,6 +9,19 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
@ -370,6 +370,8 @@ void OnKeyboardLayoutChanged(CFNotificationCenterRef center,
|
||||
FlutterDartProject* _project;
|
||||
|
||||
std::shared_ptr<flutter::AccessibilityBridgeMac> _bridge;
|
||||
|
||||
FlutterViewId _id;
|
||||
}
|
||||
|
||||
@synthesize viewId = _viewId;
|
||||
@ -510,7 +512,7 @@ static void CommonInit(FlutterViewController* controller, FlutterEngine* engine)
|
||||
[_flutterView setBackgroundColor:_backgroundColor];
|
||||
}
|
||||
|
||||
- (uint64_t)viewId {
|
||||
- (FlutterViewId)viewId {
|
||||
NSAssert([self attached], @"This view controller is not attched.");
|
||||
return _viewId;
|
||||
}
|
||||
@ -539,7 +541,7 @@ static void CommonInit(FlutterViewController* controller, FlutterEngine* engine)
|
||||
return _bridge;
|
||||
}
|
||||
|
||||
- (void)attachToEngine:(nonnull FlutterEngine*)engine withId:(uint64_t)viewId {
|
||||
- (void)attachToEngine:(nonnull FlutterEngine*)engine withId:(FlutterViewId)viewId {
|
||||
NSAssert(_engine == nil, @"Already attached to an engine %@.", _engine);
|
||||
_engine = engine;
|
||||
_viewId = viewId;
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
* If the view controller is unattached (see FlutterViewController#attached),
|
||||
* reading this property throws an assertion.
|
||||
*/
|
||||
@property(nonatomic, readonly) uint64_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:(uint64_t)viewId;
|
||||
- (void)attachToEngine:(nonnull FlutterEngine*)engine withId:(FlutterViewId)viewId;
|
||||
|
||||
/**
|
||||
* Reset the `engine` and `id` of this controller.
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable FlutterView*)viewForId:(uint64_t)viewId {
|
||||
- (nullable FlutterView*)viewForId:(FlutterViewId)viewId {
|
||||
return [_engine viewControllerForId:viewId].flutterView;
|
||||
}
|
||||
|
||||
|
||||
@ -25,9 +25,9 @@ TEST(FlutterViewEngineProviderUnittests, GetViewReturnsTheCorrectView) {
|
||||
OCMStub([mockEngine viewControllerForId:0])
|
||||
.ignoringNonObjectArgs()
|
||||
.andDo(^(NSInvocation* invocation) {
|
||||
uint64_t viewId;
|
||||
FlutterViewId viewId;
|
||||
[invocation getArgument:&viewId atIndex:2];
|
||||
if (viewId == 0 /* kFlutterDefaultViewId */) {
|
||||
if (viewId == kFlutterDefaultViewId) {
|
||||
if (mockFlutterViewController != nil) {
|
||||
[invocation setReturnValue:&mockFlutterViewController];
|
||||
}
|
||||
|
||||
@ -4,8 +4,6 @@
|
||||
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
|
||||
|
||||
extern const uint64_t kFlutterDefaultViewId;
|
||||
|
||||
/**
|
||||
* An interface to query FlutterView.
|
||||
*
|
||||
@ -20,6 +18,6 @@ extern const uint64_t kFlutterDefaultViewId;
|
||||
*
|
||||
* Returns nil if the ID is invalid.
|
||||
*/
|
||||
- (nullable FlutterView*)viewForId:(uint64_t)id;
|
||||
- (nullable FlutterView*)viewForId:(FlutterViewId)id;
|
||||
|
||||
@end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user