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

Commit 612f034

Browse files
committed
Addressing PR comments.
Renaming variables, created PresentPlatformView method and updated documentation
1 parent a4b8540 commit 612f034

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
@@ -86,6 +86,16 @@ - (void)postMainThreadTask:(FlutterTask)task targetTimeInNanoseconds:(uint64_t)t
8686
*/
8787
- (void)loadAOTData:(NSString*)assetsDir;
8888

89+
/**
90+
* Creates and returns a FlutterCompositor* to be used by the embedder.
91+
*/
92+
- (FlutterCompositor*)createFlutterCompositor;
93+
94+
/**
95+
* Create a platform view channel and setup a method call handler.
96+
*/
97+
- (void)setupPlatformViewChannel;
98+
8999
@end
90100

91101
#pragma mark -
@@ -322,7 +332,7 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
322332
}
323333

324334
[self setupPlatformViewChannel];
325-
[self createPlatformViewController];
335+
_platformViewController = [[FlutterPlatformViewController alloc] init];
326336

327337
flutterArguments.compositor = [self createFlutterCompositor];
328338

@@ -607,28 +617,24 @@ - (FlutterCompositor*)createFlutterCompositor {
607617
layers_count);
608618
};
609619

610-
__weak FlutterEngine* weak_self = self;
620+
__weak FlutterEngine* weakSelf = self;
611621
_macOSGLCompositor->SetPresentCallback(
612-
[weak_self]() { return [weak_self engineCallbackOnPresent]; });
622+
[weakSelf]() { return [weakSelf engineCallbackOnPresent]; });
613623

614624
_compositor.avoid_backing_store_cache = true;
615625

616626
return &_compositor;
617627
}
618628

619-
- (void)createPlatformViewController {
620-
_platformViewController = [[FlutterPlatformViewController alloc] init];
621-
}
622-
623629
- (void)setupPlatformViewChannel {
624630
_platformViewsChannel =
625631
[FlutterMethodChannel methodChannelWithName:@"flutter/platform_views"
626632
binaryMessenger:self.binaryMessenger
627633
codec:[FlutterStandardMethodCodec sharedInstance]];
628634

629-
__weak FlutterEngine* weak_self = self;
635+
__weak FlutterEngine* weakSelf = self;
630636
[_platformViewsChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
631-
[[weak_self platformViewController] handleMethodCall:call result:result];
637+
[[weakSelf platformViewController] handleMethodCall:call result:result];
632638
}];
633639
}
634640

@@ -737,11 +743,11 @@ - (void)unregisterTexture:(int64_t)textureID {
737743
- (void)postMainThreadTask:(FlutterTask)task targetTimeInNanoseconds:(uint64_t)targetTime {
738744
const auto engine_time = _embedderAPI.GetCurrentTime();
739745

740-
__weak FlutterEngine* weak_self = self;
746+
__weak FlutterEngine* weakSelf = self;
741747
auto worker = ^{
742-
FlutterEngine* strong_self = weak_self;
743-
if (strong_self && strong_self->_engine) {
744-
auto result = _embedderAPI.RunTask(strong_self->_engine, &task);
748+
FlutterEngine* strongSelf = weakSelf;
749+
if (strongSelf && strongSelf->_engine) {
750+
auto result = _embedderAPI.RunTask(strongSelf->_engine, &task);
745751
if (result != kSuccess) {
746752
NSLog(@"Could not post a task to the Flutter engine.");
747753
}

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
@@ -90,23 +90,7 @@
9090
break;
9191
}
9292
case kFlutterLayerContentTypePlatformView:
93-
FML_DCHECK([[NSThread currentThread] isMainThread])
94-
<< "Must be on the main thread to handle presenting platform views";
95-
96-
FML_DCHECK(platform_view_controller_.platformViews.count(layer->platform_view->identifier))
97-
<< "Platform view not found for id: " << layer->platform_view->identifier;
98-
99-
NSView* platform_view =
100-
platform_view_controller_.platformViews[layer->platform_view->identifier];
101-
102-
CGFloat scale = [[NSScreen mainScreen] backingScaleFactor];
103-
platform_view.frame = CGRectMake(layer->offset.x / scale, layer->offset.y / scale,
104-
layer->size.width / scale, layer->size.height / scale);
105-
if (platform_view.superview == nil) {
106-
[view_controller_.flutterView addSubview:platform_view];
107-
} else {
108-
platform_view.layer.zPosition = i;
109-
}
93+
PresentPlatformView(layer, i);
11094
break;
11195
};
11296
}
@@ -139,6 +123,25 @@
139123
[content_layer setContents:(__bridge id)io_surface_contents];
140124
}
141125

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