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

Commit b8f5837

Browse files
committed
Addressing PR comments.
Renaming variables, created PresentPlatformView method and updated documentation
1 parent 4dbbff9 commit b8f5837

File tree

5 files changed

+46
-33
lines changed

5 files changed

+46
-33
lines changed

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ - (void)postMainThreadTask:(FlutterTask)task targetTimeInNanoseconds:(uint64_t)t
5858
*/
5959
- (void)loadAOTData:(NSString*)assetsDir;
6060

61+
/**
62+
* Creates and returns a FlutterCompositor* to be used by the embedder.
63+
*/
64+
- (FlutterCompositor*)createFlutterCompositor;
65+
66+
/**
67+
* Create a platform view channel and setup a method call handler.
68+
*/
69+
- (void)setupPlatformViewChannel;
70+
6171
@end
6272

6373
#pragma mark -
@@ -257,7 +267,7 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
257267
}
258268

259269
[self setupPlatformViewChannel];
260-
[self createPlatformViewController];
270+
_platformViewController = [[FlutterPlatformViewController alloc] init];
261271

262272
flutterArguments.compositor = [self createFlutterCompositor];
263273

@@ -559,28 +569,24 @@ - (FlutterCompositor*)createFlutterCompositor {
559569
layers_count);
560570
};
561571

562-
__weak FlutterEngine* weak_self = self;
572+
__weak FlutterEngine* weakSelf = self;
563573
_macOSGLCompositor->SetPresentCallback(
564-
[weak_self]() { return [weak_self engineCallbackOnPresent]; });
574+
[weakSelf]() { return [weakSelf engineCallbackOnPresent]; });
565575

566576
_compositor.avoid_backing_store_cache = true;
567577

568578
return &_compositor;
569579
}
570580

571-
- (void)createPlatformViewController {
572-
_platformViewController = [[FlutterPlatformViewController alloc] init];
573-
}
574-
575581
- (void)setupPlatformViewChannel {
576582
_platformViewsChannel =
577583
[FlutterMethodChannel methodChannelWithName:@"flutter/platform_views"
578584
binaryMessenger:self.binaryMessenger
579585
codec:[FlutterStandardMethodCodec sharedInstance]];
580586

581-
__weak FlutterEngine* weak_self = self;
587+
__weak FlutterEngine* weakSelf = self;
582588
[_platformViewsChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
583-
[[weak_self platformViewController] handleMethodCall:call result:result];
589+
[[weakSelf platformViewController] handleMethodCall:call result:result];
584590
}];
585591
}
586592

@@ -690,11 +696,11 @@ - (BOOL)unregisterTextureWithID:(int64_t)textureID {
690696
- (void)postMainThreadTask:(FlutterTask)task targetTimeInNanoseconds:(uint64_t)targetTime {
691697
const auto engine_time = _embedderAPI.GetCurrentTime();
692698

693-
__weak FlutterEngine* weak_self = self;
699+
__weak FlutterEngine* weakSelf = self;
694700
auto worker = ^{
695-
FlutterEngine* strong_self = weak_self;
696-
if (strong_self && strong_self->_engine) {
697-
auto result = _embedderAPI.RunTask(strong_self->_engine, &task);
701+
FlutterEngine* strongSelf = weakSelf;
702+
if (strongSelf && strongSelf->_engine) {
703+
auto result = _embedderAPI.RunTask(strongSelf->_engine, &task);
698704
if (result != kSuccess) {
699705
NSLog(@"Could not post a task to the Flutter engine.");
700706
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ class FlutterGLCompositor {
7575
FlutterBackingStoreData* flutter_backing_store_data,
7676
size_t layer_position);
7777

78+
// Add the Platform View's content to the FlutterView at depth
79+
// layer_position.
80+
void PresentPlatformView(const FlutterLayer* layer, size_t layer_position);
81+
7882
// Set frame_started_ to true and reset all layer state.
7983
void StartFrame();
8084

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,7 @@
9393
break;
9494
}
9595
case kFlutterLayerContentTypePlatformView:
96-
FML_DCHECK([[NSThread currentThread] isMainThread])
97-
<< "Must be on the main thread to handle presenting platform views";
98-
99-
FML_DCHECK(platform_view_controller_.platformViews.count(layer->platform_view->identifier))
100-
<< "Platform view not found for id: " << layer->platform_view->identifier;
101-
102-
NSView* platform_view =
103-
platform_view_controller_.platformViews[layer->platform_view->identifier];
104-
105-
CGFloat scale = [[NSScreen mainScreen] backingScaleFactor];
106-
platform_view.frame = CGRectMake(layer->offset.x / scale, layer->offset.y / scale,
107-
layer->size.width / scale, layer->size.height / scale);
108-
if (platform_view.superview == nil) {
109-
[view_controller_.flutterView addSubview:platform_view];
110-
} else {
111-
platform_view.layer.zPosition = i;
112-
}
96+
PresentPlatformView(layer, i);
11397
break;
11498
};
11599
}
@@ -142,6 +126,25 @@
142126
[content_layer setContents:(__bridge id)io_surface_contents];
143127
}
144128

129+
void FlutterGLCompositor::PresentPlatformView(const FlutterLayer* layer, size_t layer_position) {
130+
FML_DCHECK([[NSThread currentThread] isMainThread])
131+
<< "Must be on the main thread to handle presenting platform views";
132+
133+
FML_DCHECK(platform_view_controller_.platformViews.count(layer->platform_view->identifier))
134+
<< "Platform view not found for id: " << layer->platform_view->identifier;
135+
136+
NSView* platform_view = platform_view_controller_.platformViews[layer->platform_view->identifier];
137+
138+
CGFloat scale = [[NSScreen mainScreen] backingScaleFactor];
139+
platform_view.frame = CGRectMake(layer->offset.x / scale, layer->offset.y / scale,
140+
layer->size.width / scale, layer->size.height / scale);
141+
if (platform_view.superview == nil) {
142+
[view_controller_.flutterView addSubview:platform_view];
143+
} else {
144+
platform_view.layer.zPosition = layer_position;
145+
}
146+
}
147+
145148
void FlutterGLCompositor::SetPresentCallback(
146149
const FlutterGLCompositor::PresentCallback& present_callback) {
147150
present_callback_ = present_callback;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ @implementation FlutterPlatformViewController
1010

1111
- (instancetype)init {
1212
self = [super init];
13-
14-
self->_platformViewFactories = [[NSMutableDictionary alloc] init];
13+
if (self) {
14+
_platformViewFactories = [[NSMutableDictionary alloc] init];
15+
}
1516
return self;
1617
}
1718

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// found in the LICENSE file.
44

55
#import <Foundation/Foundation.h>
6-
#import <Foundation/NSObject.h>
76

87
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformViews.h"
98

0 commit comments

Comments
 (0)