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

Commit b28f61f

Browse files
committed
Add experimental plist setting to enable experimental platform view support for MacOS.
Enabling the key disables smooth resizing.
1 parent a4b8540 commit b28f61f

File tree

6 files changed

+72
-8
lines changed

6 files changed

+72
-8
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,7 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Info.plist
10561056
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterAppDelegate.mm
10571057
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterBackingStoreData.h
10581058
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterBackingStoreData.mm
1059+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterConstants.h
10591060
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject.mm
10601061
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h
10611062
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// The name of the Info.plist flag to enable the embedded MacOS views preview.
6+
const char* const kEmbeddedViewsPreview = "io.flutter_embedded_views_preview";

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,17 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
310310
},
311311
.identifier = ++sTaskRunnerIdentifiers,
312312
};
313+
314+
bool embedded_views_preview_enabled = [FlutterPlatformViewController embeddedViewsEnabled];
315+
313316
const FlutterCustomTaskRunners custom_task_runners = {
314317
.struct_size = sizeof(FlutterCustomTaskRunners),
315318
.platform_task_runner = &cocoa_task_runner_description,
316-
};
319+
// If platform views are enabled, set the render thread to the platform thread.
320+
// Otherwise the render thread is created separately in embedder_thread_host.cc.
321+
.render_task_runner =
322+
embedded_views_preview_enabled ? &cocoa_task_runner_description : nullptr};
323+
317324
flutterArguments.custom_task_runners = &custom_task_runners;
318325

319326
[self loadAOTData:_project.assetsPath];

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,29 @@
44

55
#include "flutter/fml/logging.h"
66

7+
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterConstants.h"
78
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformViewController_Internal.h"
89

9-
@implementation FlutterPlatformViewController
10+
@implementation FlutterPlatformViewController {
11+
bool _embedded_views_preview_enabled;
12+
}
1013

1114
- (instancetype)init {
1215
self = [super init];
1316

14-
self->_platformViewFactories = [[NSMutableDictionary alloc] init];
17+
_platformViewFactories = [[NSMutableDictionary alloc] init];
18+
_embedded_views_preview_enabled = [FlutterPlatformViewController embeddedViewsEnabled];
1519
return self;
1620
}
1721

1822
- (void)onCreateWithViewId:(int64_t)viewId
1923
viewType:(nonnull NSString*)viewType
2024
result:(nonnull FlutterResult)result {
25+
if (!_embedded_views_preview_enabled) {
26+
NSLog(@"Must set `io.flutter_embedded_views_preview` to true in Info.plist to enable platform "
27+
@"views");
28+
return;
29+
}
2130
if (_platformViews.count(viewId) != 0) {
2231
result([FlutterError errorWithCode:@"recreating_view"
2332
message:@"trying to create an already created view"
@@ -42,6 +51,12 @@ - (void)onCreateWithViewId:(int64_t)viewId
4251
}
4352

4453
- (void)onDisposeWithViewId:(int64_t)viewId result:(nonnull FlutterResult)result {
54+
if (!_embedded_views_preview_enabled) {
55+
NSLog(@"Must set `io.flutter_embedded_views_preview` to true in Info.plist to enable platform "
56+
@"views");
57+
return;
58+
}
59+
4560
if (_platformViews.count(viewId) == 0) {
4661
result([FlutterError errorWithCode:@"unknown_view"
4762
message:@"trying to dispose an unknown"
@@ -56,6 +71,11 @@ - (void)onDisposeWithViewId:(int64_t)viewId result:(nonnull FlutterResult)result
5671

5772
- (void)registerViewFactory:(nonnull NSObject<FlutterPlatformViewFactory>*)factory
5873
withId:(nonnull NSString*)factoryId {
74+
if (!_embedded_views_preview_enabled) {
75+
NSLog(@"Must set `io.flutter_embedded_views_preview` to true in Info.plist to enable platform "
76+
@"views");
77+
return;
78+
}
5979
_platformViewFactories[factoryId] = factory;
6080
}
6181

@@ -89,4 +109,8 @@ - (void)disposePlatformViews {
89109
_platformViewsToDispose.clear();
90110
}
91111

112+
+ (bool)embeddedViewsEnabled {
113+
return [[[NSBundle mainBundle] objectForInfoDictionaryKey:@(kEmbeddedViewsPreview)] boolValue];
114+
}
115+
92116
@end

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,10 @@
5555
*/
5656
- (void)disposePlatformViews;
5757

58+
/**
59+
* Return whether or not platform views are enabled by looking for the
60+
* io.flutter_embedded_views_preview flag in Info.plist.
61+
*/
62+
+ (bool)embeddedViewsEnabled;
63+
5864
@end

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
66

7+
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformViewController_Internal.h"
78
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h"
89
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h"
910
#import "flutter/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h"
@@ -15,6 +16,7 @@ @interface FlutterView () <FlutterResizeSynchronizerDelegate> {
1516
__weak id<FlutterViewReshapeListener> _reshapeListener;
1617
FlutterResizeSynchronizer* _resizeSynchronizer;
1718
FlutterSurfaceManager* _surfaceManager;
19+
bool _embedded_views_preview_enabled;
1820
}
1921

2022
@end
@@ -42,6 +44,9 @@ - (instancetype)initWithFrame:(NSRect)frame
4244

4345
_reshapeListener = reshapeListener;
4446
}
47+
48+
_embedded_views_preview_enabled = [FlutterPlatformViewController embeddedViewsEnabled];
49+
4550
return self;
4651
}
4752

@@ -67,15 +72,30 @@ - (int)frameBufferIDForSize:(CGSize)size {
6772
}
6873

6974
- (void)present {
70-
[_resizeSynchronizer requestCommit];
75+
// If _embedded_views_preview_enabled is true, the main and raster
76+
// threads are merged. Thus we cannot call resizeSynchronizer::requestCommit
77+
// as it blocks on the raster thread.
78+
if (_embedded_views_preview_enabled) {
79+
[self resizeSynchronizerFlush:_resizeSynchronizer];
80+
[self resizeSynchronizerCommit:_resizeSynchronizer];
81+
} else {
82+
[_resizeSynchronizer requestCommit];
83+
}
7184
}
7285

7386
- (void)reshaped {
7487
CGSize scaledSize = [self convertSizeToBacking:self.bounds.size];
75-
[_resizeSynchronizer beginResize:scaledSize
76-
notify:^{
77-
[_reshapeListener viewDidReshape:self];
78-
}];
88+
// If _embedded_views_preview_enabled is true, the main and raster
89+
// threads are merged. Thus we cannot call resizeSynchronizer::beginResize
90+
// as it blocks on the main thread.
91+
if (_embedded_views_preview_enabled) {
92+
[_reshapeListener viewDidReshape:self];
93+
} else {
94+
[_resizeSynchronizer beginResize:scaledSize
95+
notify:^{
96+
[_reshapeListener viewDidReshape:self];
97+
}];
98+
}
7999
}
80100

81101
#pragma mark - NSView overrides

0 commit comments

Comments
 (0)