-
Notifications
You must be signed in to change notification settings - Fork 6k
Add an Info.plist flag to enable MacOS platform views preview support #22929
Changes from 1 commit
182b975
ac08def
8fbb288
a4b8540
b33da83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| // The name of the Info.plist flag to enable the embedded MacOS views preview. | ||
| const char* const kEmbeddedViewsPreview = "io.flutter_embedded_views_preview"; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,20 +4,29 @@ | |
|
|
||
| #include "flutter/fml/logging.h" | ||
|
|
||
| #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterConstants.h" | ||
| #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformViewController_Internal.h" | ||
|
|
||
| @implementation FlutterPlatformViewController | ||
| @implementation FlutterPlatformViewController { | ||
| bool _embeddedViewsEnabled; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this instance method. |
||
| } | ||
|
|
||
| - (instancetype)init { | ||
| self = [super init]; | ||
|
|
||
| self->_platformViewFactories = [[NSMutableDictionary alloc] init]; | ||
| _platformViewFactories = [[NSMutableDictionary alloc] init]; | ||
| [self setEmbeddedViewsEnabled:[FlutterPlatformViewController embeddedViewsEnabled]]; | ||
| return self; | ||
| } | ||
|
|
||
| - (void)onCreateWithViewId:(int64_t)viewId | ||
| viewType:(nonnull NSString*)viewType | ||
| result:(nonnull FlutterResult)result { | ||
| if (!_embeddedViewsEnabled) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this, the |
||
| NSLog(@"Must set `io.flutter_embedded_views_preview` to true in Info.plist to enable platform " | ||
| @"views"); | ||
| return; | ||
| } | ||
| if (_platformViews.count(viewId) != 0) { | ||
| result([FlutterError errorWithCode:@"recreating_view" | ||
| message:@"trying to create an already created view" | ||
|
|
@@ -42,6 +51,12 @@ - (void)onCreateWithViewId:(int64_t)viewId | |
| } | ||
|
|
||
| - (void)onDisposeWithViewId:(int64_t)viewId result:(nonnull FlutterResult)result { | ||
| if (!_embeddedViewsEnabled) { | ||
| NSLog(@"Must set `io.flutter_embedded_views_preview` to true in Info.plist to enable platform " | ||
| @"views"); | ||
| return; | ||
| } | ||
|
|
||
| if (_platformViews.count(viewId) == 0) { | ||
| result([FlutterError errorWithCode:@"unknown_view" | ||
| message:@"trying to dispose an unknown" | ||
|
|
@@ -56,6 +71,11 @@ - (void)onDisposeWithViewId:(int64_t)viewId result:(nonnull FlutterResult)result | |
|
|
||
| - (void)registerViewFactory:(nonnull NSObject<FlutterPlatformViewFactory>*)factory | ||
| withId:(nonnull NSString*)factoryId { | ||
| if (!_embeddedViewsEnabled) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can just be if (![self embeddedViewsEnabled]) |
||
| NSLog(@"Must set `io.flutter_embedded_views_preview` to true in Info.plist to enable platform " | ||
| @"views"); | ||
| return; | ||
| } | ||
| _platformViewFactories[factoryId] = factory; | ||
| } | ||
|
|
||
|
|
@@ -89,4 +109,12 @@ - (void)disposePlatformViews { | |
| _platformViewsToDispose.clear(); | ||
| } | ||
|
|
||
| - (void)setEmbeddedViewsEnabled:(bool)embeddedViewsEnabled { | ||
| _embeddedViewsEnabled = embeddedViewsEnabled; | ||
| } | ||
|
|
||
| + (bool)embeddedViewsEnabled { | ||
| return [[[NSBundle mainBundle] objectForInfoDictionaryKey:@(kEmbeddedViewsPreview)] boolValue]; | ||
| } | ||
|
|
||
| @end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h" | ||
|
|
||
| #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformViewController_Internal.h" | ||
| #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h" | ||
| #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h" | ||
| #import "flutter/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h" | ||
|
|
@@ -15,6 +16,7 @@ @interface FlutterView () <FlutterResizeSynchronizerDelegate> { | |
| __weak id<FlutterViewReshapeListener> _reshapeListener; | ||
| FlutterResizeSynchronizer* _resizeSynchronizer; | ||
| FlutterSurfaceManager* _surfaceManager; | ||
| bool _embedded_views_preview_enabled; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need this ivar, can just use [FlutterPlatformViewController embeddedViewsEnabled] when necessary.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ivars should be camelCase. |
||
| } | ||
|
|
||
| @end | ||
|
|
@@ -42,6 +44,9 @@ - (instancetype)initWithFrame:(NSRect)frame | |
|
|
||
| _reshapeListener = reshapeListener; | ||
| } | ||
|
|
||
| _embedded_views_preview_enabled = [FlutterPlatformViewController embeddedViewsEnabled]; | ||
|
|
||
| return self; | ||
| } | ||
|
|
||
|
|
@@ -67,15 +72,30 @@ - (int)frameBufferIDForSize:(CGSize)size { | |
| } | ||
|
|
||
| - (void)present { | ||
| [_resizeSynchronizer requestCommit]; | ||
| // If _embedded_views_preview_enabled is true, the main and raster | ||
| // threads are merged. Thus we cannot call resizeSynchronizer::requestCommit | ||
| // as it blocks on the raster thread. | ||
| if (_embedded_views_preview_enabled) { | ||
| [self resizeSynchronizerFlush:_resizeSynchronizer]; | ||
| [self resizeSynchronizerCommit:_resizeSynchronizer]; | ||
| } else { | ||
| [_resizeSynchronizer requestCommit]; | ||
| } | ||
| } | ||
|
|
||
| - (void)reshaped { | ||
| CGSize scaledSize = [self convertSizeToBacking:self.bounds.size]; | ||
| [_resizeSynchronizer beginResize:scaledSize | ||
| notify:^{ | ||
| [_reshapeListener viewDidReshape:self]; | ||
| }]; | ||
| // If _embedded_views_preview_enabled is true, the main and raster | ||
| // threads are merged. Thus we cannot call resizeSynchronizer::beginResize | ||
| // as it blocks on the main thread. | ||
| if (_embedded_views_preview_enabled) { | ||
| [_reshapeListener viewDidReshape:self]; | ||
| } else { | ||
| [_resizeSynchronizer beginResize:scaledSize | ||
| notify:^{ | ||
| [_reshapeListener viewDidReshape:self]; | ||
| }]; | ||
| } | ||
| } | ||
|
|
||
| #pragma mark - NSView overrides | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need the constant in a separate file, can move it to
FlutterPlatformViewController.mm