Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1925716

Browse files
committed
Address pr comments
1 parent 9ee9d45 commit 1925716

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
}
7272

7373
bool FlutterGLCompositor::Present(const FlutterLayer** layers, size_t layers_count) {
74+
DisposePlatformViews();
7475
for (size_t i = 0; i < layers_count; ++i) {
7576
const auto* layer = layers[i];
7677
FlutterBackingStore* backing_store = const_cast<FlutterBackingStore*>(layer->backing_store);
@@ -114,7 +115,6 @@
114115
// The frame has been presented, prepare FlutterGLCompositor to
115116
// render a new frame.
116117
frame_started_ = false;
117-
DisposePlatformViews();
118118
return present_callback_();
119119
}
120120

shell/platform/darwin/macos/framework/Source/FlutterPlatformViews.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ NS_ASSUME_NONNULL_BEGIN
1818
@protocol FlutterPlatformView <NSObject>
1919
/**
2020
* Returns a reference to the `NSView` that is wrapped by this `FlutterPlatformView`.
21+
*
22+
* It is recommended to return a cached view instance in this method.
23+
* Constructing a new view instance and return in this method might cause undefined behavior.
24+
*
25+
* TODO(richardjcai): Prevent [FlutterPlatformView view] to be called multiple times
26+
* in a single frame.
2127
*/
2228
- (NSView*)view;
2329
@end
@@ -27,16 +33,16 @@ FLUTTER_EXPORT
2733
/**
2834
* Create a `FlutterPlatformView`.
2935
*
30-
* Implemented by MacOS code that expose a `NSView` for embedding in a Flutter app.
36+
* Implemented by MacOS code that expose a `FlutterPlatformView` for embedding in a Flutter app.
3137
*
32-
* The implementation of this method should create a new `NSView` and return it.
38+
* The implementation of this method should create a new `FlutterPlatformView` and return it.
3339
*
34-
* @param frame The rectangle for the newly created `NSView` measured in points.
35-
* @param viewId A unique identifier for this `NSView`.
36-
* @param args Parameters for creating the `NSView` sent from the Dart side of the Flutter app.
37-
* If `createArgsCodec` is not implemented, or if no creation arguments were sent from the Dart
38-
* code, this will be null. Otherwise this will be the value sent from the Dart code as decoded by
39-
* `createArgsCodec`.
40+
* @param frame The rectangle for the newly created `FlutterPlatformView` measured in points.
41+
* @param viewId A unique identifier for this `FlutterPlatformView`.
42+
* @param args Parameters for creating the `FlutterPlatformView` sent from the Dart side of the
43+
* Flutter app. If `createArgsCodec` is not implemented, or if no creation arguments were sent from
44+
* the Dart code, this will be null. Otherwise this will be the value sent from the Dart code as
45+
* decoded by `createArgsCodec`.
4046
*/
4147
- (NSObject<FlutterPlatformView>*)createWithFrame:(CGRect)frame
4248
viewIdentifier:(int64_t)viewId

shell/platform/darwin/macos/framework/Source/FlutterViewController.mm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ - (void)addInternalPlugins {
397397
[weakSelf onCreate:call result:result];
398398
} else if ([[call method] isEqualToString:@"dispose"]) {
399399
[weakSelf onDispose:call result:result];
400+
} else {
401+
result(FlutterMethodNotImplemented);
400402
}
401403
}];
402404
}
@@ -406,7 +408,7 @@ - (void)onCreate:(nonnull FlutterMethodCall*)call result:(nonnull FlutterResult)
406408
int64_t viewId = [args[@"id"] longValue];
407409
NSString* viewType = [NSString stringWithUTF8String:([args[@"viewType"] UTF8String])];
408410

409-
if (self->_platformViews.count(viewId) != 0) {
411+
if (_platformViews.count(viewId) != 0) {
410412
result([FlutterError errorWithCode:@"recreating_view"
411413
message:@"trying to create an already created view"
412414
details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
@@ -425,7 +427,7 @@ - (void)onCreate:(nonnull FlutterMethodCall*)call result:(nonnull FlutterResult)
425427
viewIdentifier:viewId
426428
arguments:nil];
427429

428-
self->_platformViews[viewId] = [platform_view view];
430+
_platformViews[viewId] = [platform_view view];
429431
result(nil);
430432
}
431433

@@ -434,15 +436,15 @@ - (void)onDispose:(nonnull FlutterMethodCall*)call result:(nonnull FlutterResult
434436
int64_t viewId = [arg longLongValue];
435437
NSLog(@"onDispose ViewId: %lld", viewId);
436438

437-
if (self->_platformViews.count(viewId) == 0) {
439+
if (_platformViews.count(viewId) == 0) {
438440
result([FlutterError errorWithCode:@"unknown_view"
439441
message:@"trying to dispose an unknown"
440442
details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
441443
return;
442444
}
443445

444446
// The following FlutterGLCompositor::Present call will dispose the views.
445-
self->_platformViewsToDispose.insert(viewId);
447+
_platformViewsToDispose.insert(viewId);
446448
result(nil);
447449
}
448450

shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
@property(nonatomic, readonly, nullable) FlutterView* flutterView;
1616

1717
// NSDictionary maps strings to FlutterPlatformViewFactorys.
18-
@property(nonnull) NSMutableDictionary<NSString*, NSObject<FlutterPlatformViewFactory>*>* factories;
18+
@property(nonnull, nonatomic)
19+
NSMutableDictionary<NSString*, NSObject<FlutterPlatformViewFactory>*>* factories;
1920

2021
// A map of platform view ids to views.
21-
@property() std::map<int, NSView*> platformViews;
22+
@property(nonatomic) std::map<int, NSView*> platformViews;
2223

2324
// View ids that are going to be disposed on the next present call.
24-
@property() std::unordered_set<int64_t> platformViewsToDispose;
25+
@property(nonatomic) std::unordered_set<int64_t> platformViewsToDispose;
2526

2627
/**
2728
* This just returns the NSPasteboard so that it can be mocked in the tests.

0 commit comments

Comments
 (0)