diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 8d3693f1cc4cf..634d013bfd697 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -743,9 +743,6 @@ FILE: ../../../flutter/shell/platform/darwin/ios/platform_view_ios.mm FILE: ../../../flutter/shell/platform/darwin/macos/framework/FlutterMacOS.podspec FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEDartProject.h FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEEngine.h -FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEOpenGLContextHandling.h -FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEReshapeListener.h -FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEView.h FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEViewController.h FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FlutterMacOS.h FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FlutterPluginMacOS.h @@ -759,9 +756,10 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInput FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInputModel.mm FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInputPlugin.h FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInputPlugin.mm -FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLEView.mm FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLEViewController.mm FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLEViewController_Internal.h +FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h +FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm FILE: ../../../flutter/shell/platform/darwin/macos/framework/module.modulemap FILE: ../../../flutter/shell/platform/embedder/assets/EmbedderInfo.plist FILE: ../../../flutter/shell/platform/embedder/assets/embedder.modulemap diff --git a/shell/platform/darwin/macos/BUILD.gn b/shell/platform/darwin/macos/BUILD.gn index a4c3727a49e03..03990ede05c96 100644 --- a/shell/platform/darwin/macos/BUILD.gn +++ b/shell/platform/darwin/macos/BUILD.gn @@ -35,9 +35,6 @@ _flutter_framework_headers = [ "framework/Headers/FlutterPluginRegistrarMacOS.h", "framework/Headers/FLEDartProject.h", "framework/Headers/FLEEngine.h", - "framework/Headers/FLEOpenGLContextHandling.h", - "framework/Headers/FLEReshapeListener.h", - "framework/Headers/FLEView.h", "framework/Headers/FLEViewController.h", ] @@ -58,9 +55,10 @@ shared_library("create_flutter_framework_dylib") { "framework/Source/FLETextInputModel.mm", "framework/Source/FLETextInputPlugin.h", "framework/Source/FLETextInputPlugin.mm", - "framework/Source/FLEView.mm", "framework/Source/FLEViewController.mm", "framework/Source/FLEViewController_Internal.h", + "framework/Source/FlutterView.h", + "framework/Source/FlutterView.mm", ] sources += _flutter_framework_headers diff --git a/shell/platform/darwin/macos/framework/Headers/FLEOpenGLContextHandling.h b/shell/platform/darwin/macos/framework/Headers/FLEOpenGLContextHandling.h deleted file mode 100644 index 2e907fbbb5280..0000000000000 --- a/shell/platform/darwin/macos/framework/Headers/FLEOpenGLContextHandling.h +++ /dev/null @@ -1,25 +0,0 @@ -// 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. - -#import "FlutterMacros.h" - -/** - * Protocol for views owned by FLEViewController to handle context changes, specifically relating to - * OpenGL context changes. - */ -FLUTTER_EXPORT -@protocol FLEOpenGLContextHandling - -/** - * Sets the receiver as the current context object. - */ -- (void)makeCurrentContext; - -/** - * Called when the display is updated. In an NSOpenGLView this is best handled via a flushBuffer - * call. - */ -- (void)onPresent; - -@end diff --git a/shell/platform/darwin/macos/framework/Headers/FLEReshapeListener.h b/shell/platform/darwin/macos/framework/Headers/FLEReshapeListener.h deleted file mode 100644 index ef99267c88d3e..0000000000000 --- a/shell/platform/darwin/macos/framework/Headers/FLEReshapeListener.h +++ /dev/null @@ -1,19 +0,0 @@ -// 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. - -#import - -#import "FlutterMacros.h" - -/** - * Protocol for listening to reshape events on this FlutterView. - * Used to notify the underlying Flutter engine of the new screen dimensions. - * Reflected from [NSOpenGLView.reshape]. - */ -FLUTTER_EXPORT -@protocol FLEReshapeListener - -- (void)viewDidReshape:(nonnull NSOpenGLView*)view; - -@end diff --git a/shell/platform/darwin/macos/framework/Headers/FLEView.h b/shell/platform/darwin/macos/framework/Headers/FLEView.h deleted file mode 100644 index 4079e68b0c18e..0000000000000 --- a/shell/platform/darwin/macos/framework/Headers/FLEView.h +++ /dev/null @@ -1,23 +0,0 @@ -// 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. - -#import - -#import "FLEOpenGLContextHandling.h" -#import "FLEReshapeListener.h" -#import "FlutterMacros.h" - -/** - * View capable of acting as a rendering target and input source for the Flutter - * engine. - */ -FLUTTER_EXPORT -@interface FLEView : NSOpenGLView - -/** - * Listener for reshape events. See protocol description. - */ -@property(nonatomic, weak, nullable) IBOutlet id reshapeListener; - -@end diff --git a/shell/platform/darwin/macos/framework/Headers/FLEViewController.h b/shell/platform/darwin/macos/framework/Headers/FLEViewController.h index b127f045d65d4..2328ec5825c57 100644 --- a/shell/platform/darwin/macos/framework/Headers/FLEViewController.h +++ b/shell/platform/darwin/macos/framework/Headers/FLEViewController.h @@ -5,8 +5,6 @@ #import #import "FLEEngine.h" -#import "FLEOpenGLContextHandling.h" -#import "FLEReshapeListener.h" #import "FlutterMacros.h" #import "FlutterPluginRegistrarMacOS.h" @@ -29,13 +27,7 @@ typedef NS_ENUM(NSInteger, FlutterMouseTrackingMode) { * Flutter engine in non-interactive mode, or with a drawable Flutter canvas. */ FLUTTER_EXPORT -@interface FLEViewController : NSViewController - -/** - * The view this controller manages. Must be capable of handling text input events, and the OpenGL - * context handling protocols. - */ -@property(nullable) NSView* view; +@interface FLEViewController : NSViewController /** * The Flutter engine associated with this view controller. diff --git a/shell/platform/darwin/macos/framework/Headers/FlutterMacOS.h b/shell/platform/darwin/macos/framework/Headers/FlutterMacOS.h index a2c93777d436e..ab9ebdb3cdc64 100644 --- a/shell/platform/darwin/macos/framework/Headers/FlutterMacOS.h +++ b/shell/platform/darwin/macos/framework/Headers/FlutterMacOS.h @@ -4,9 +4,6 @@ #import "FLEDartProject.h" #import "FLEEngine.h" -#import "FLEOpenGLContextHandling.h" -#import "FLEReshapeListener.h" -#import "FLEView.h" #import "FLEViewController.h" #import "FlutterBinaryMessenger.h" #import "FlutterChannels.h" diff --git a/shell/platform/darwin/macos/framework/Source/FLEEngine.mm b/shell/platform/darwin/macos/framework/Source/FLEEngine.mm index 8a60b4f1d17a3..289ab47c4449e 100644 --- a/shell/platform/darwin/macos/framework/Source/FLEEngine.mm +++ b/shell/platform/darwin/macos/framework/Source/FLEEngine.mm @@ -210,15 +210,15 @@ - (void)sendPointerEvent:(const FlutterPointerEvent&)event { #pragma mark - Private methods - (bool)engineCallbackOnMakeCurrent { - if (!_viewController.view) { + if (!_viewController.flutterView) { return false; } - [_viewController.view makeCurrentContext]; + [_viewController.flutterView makeCurrentContext]; return true; } - (bool)engineCallbackOnClearCurrent { - if (!_viewController.view) { + if (!_viewController.flutterView) { return false; } [NSOpenGLContext clearCurrentContext]; @@ -226,15 +226,15 @@ - (bool)engineCallbackOnClearCurrent { } - (bool)engineCallbackOnPresent { - if (!_viewController.view) { + if (!_viewController.flutterView) { return false; } - [_viewController.view onPresent]; + [_viewController.flutterView onPresent]; return true; } - (bool)engineCallbackOnMakeResourceCurrent { - if (!_viewController.view) { + if (!_viewController.flutterView) { return false; } [_viewController makeResourceContextCurrent]; diff --git a/shell/platform/darwin/macos/framework/Source/FLEView.mm b/shell/platform/darwin/macos/framework/Source/FLEView.mm deleted file mode 100644 index 7d67fc33c0abc..0000000000000 --- a/shell/platform/darwin/macos/framework/Source/FLEView.mm +++ /dev/null @@ -1,43 +0,0 @@ -// 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. - -#import "flutter/shell/platform/darwin/macos/framework/Headers/FLEView.h" - -@implementation FLEView - -#pragma mark - -#pragma mark FLEContextHandlingProtocol - -- (void)makeCurrentContext { - [self.openGLContext makeCurrentContext]; -} - -- (void)onPresent { - [self.openGLContext flushBuffer]; -} - -#pragma mark - -#pragma mark Implementation - -/** - * Declares that the view uses a flipped coordinate system, consistent with Flutter conventions. - */ -- (BOOL)isFlipped { - return YES; -} - -- (BOOL)isOpaque { - return YES; -} - -- (void)reshape { - [super reshape]; - [_reshapeListener viewDidReshape:self]; -} - -- (BOOL)acceptsFirstResponder { - return YES; -} - -@end diff --git a/shell/platform/darwin/macos/framework/Source/FLEViewController.mm b/shell/platform/darwin/macos/framework/Source/FLEViewController.mm index 4c8d47abcfad8..91ad156f26c8f 100644 --- a/shell/platform/darwin/macos/framework/Source/FLEViewController.mm +++ b/shell/platform/darwin/macos/framework/Source/FLEViewController.mm @@ -8,10 +8,9 @@ #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h" #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterCodecs.h" #import "flutter/shell/platform/darwin/macos/framework/Headers/FLEEngine.h" -#import "flutter/shell/platform/darwin/macos/framework/Headers/FLEReshapeListener.h" -#import "flutter/shell/platform/darwin/macos/framework/Headers/FLEView.h" #import "flutter/shell/platform/darwin/macos/framework/Source/FLEEngine_Internal.h" #import "flutter/shell/platform/darwin/macos/framework/Source/FLETextInputPlugin.h" +#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h" #import "flutter/shell/platform/embedder/embedder.h" namespace { @@ -68,7 +67,7 @@ void Reset() { /** * Private interface declaration for FLEViewController. */ -@interface FLEViewController () +@interface FLEViewController () /** * A list of additional responders to keyboard events. Keybord events are forwarded to all of them. @@ -195,16 +194,13 @@ - (instancetype)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBun return self; } -- (void)setView:(NSView*)view { - if (_trackingArea) { - [self.view removeTrackingArea:_trackingArea]; - } - [super setView:view]; - [self configureTrackingArea]; +- (void)loadView { + FlutterView* flutterView = [[FlutterView alloc] initWithReshapeListener:self]; + self.view = flutterView; } -- (void)loadView { - self.view = [[FLEView alloc] init]; +- (void)viewDidLoad { + [self configureTrackingArea]; } #pragma mark - Public methods @@ -238,6 +234,10 @@ - (BOOL)launchEngineWithProject:(nullable FLEDartProject*)project { #pragma mark - Framework-internal methods +- (FlutterView*)flutterView { + return static_cast(self.view); +} + - (void)addKeyResponder:(NSResponder*)responder { [self.additionalKeyResponders addObject:responder]; } @@ -449,12 +449,12 @@ - (void)setClipboardData:(NSDictionary*)data { } } -#pragma mark - FLEReshapeListener +#pragma mark - FlutterViewReshapeListener /** * Responds to view reshape by notifying the engine of the change in dimensions. */ -- (void)viewDidReshape:(NSOpenGLView*)view { +- (void)viewDidReshape:(NSView*)view { CGSize scaledSize = [view convertRectToBacking:view.bounds].size; double pixelRatio = view.bounds.size.width == 0 ? 1 : scaledSize.width / view.bounds.size.width; [_engine updateWindowMetricsWithSize:scaledSize pixelRatio:pixelRatio]; diff --git a/shell/platform/darwin/macos/framework/Source/FLEViewController_Internal.h b/shell/platform/darwin/macos/framework/Source/FLEViewController_Internal.h index 540010db478e7..cf5804b706468 100644 --- a/shell/platform/darwin/macos/framework/Source/FLEViewController_Internal.h +++ b/shell/platform/darwin/macos/framework/Source/FLEViewController_Internal.h @@ -4,8 +4,13 @@ #import "flutter/shell/platform/darwin/macos/framework/Headers/FLEViewController.h" +#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h" + @interface FLEViewController () +// The FlutterView for this view controller. +@property(nonatomic, readonly, nullable) FlutterView* flutterView; + /** * Adds a responder for keyboard events. Key up and key down events are forwarded to all added * responders. diff --git a/shell/platform/darwin/macos/framework/Source/FlutterView.h b/shell/platform/darwin/macos/framework/Source/FlutterView.h new file mode 100644 index 0000000000000..404ce2442f82b --- /dev/null +++ b/shell/platform/darwin/macos/framework/Source/FlutterView.h @@ -0,0 +1,46 @@ +// 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. + +#import + +/** + * Listener for view resizing. + */ +@protocol FlutterViewReshapeListener +/** + * Called when the view's backing store changes size. + */ +- (void)viewDidReshape:(nonnull NSView*)view; +@end + +/** + * View capable of acting as a rendering target and input source for the Flutter + * engine. + */ +@interface FlutterView : NSOpenGLView + +- (nullable instancetype)initWithFrame:(NSRect)frame + reshapeListener:(nonnull id)reshapeListener + NS_DESIGNATED_INITIALIZER; + +- (nullable instancetype)initWithReshapeListener: + (nonnull id)reshapeListener; + +- (nullable instancetype)initWithFrame:(NSRect)frameRect + pixelFormat:(nullable NSOpenGLPixelFormat*)format NS_UNAVAILABLE; +- (nonnull instancetype)initWithFrame:(NSRect)frameRect NS_UNAVAILABLE; +- (nullable instancetype)initWithCoder:(nonnull NSCoder*)coder NS_UNAVAILABLE; +- (nonnull instancetype)init NS_UNAVAILABLE; + +/** + * Sets this view as the current context object for OpenGL drawing. + */ +- (void)makeCurrentContext; + +/** + * Called when the OpenGL display should be updated. + */ +- (void)onPresent; + +@end diff --git a/shell/platform/darwin/macos/framework/Source/FlutterView.mm b/shell/platform/darwin/macos/framework/Source/FlutterView.mm new file mode 100644 index 0000000000000..cbb93d063ad95 --- /dev/null +++ b/shell/platform/darwin/macos/framework/Source/FlutterView.mm @@ -0,0 +1,59 @@ +// 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. + +#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h" + +@implementation FlutterView { + __weak id _reshapeListener; +} + +- (instancetype)initWithReshapeListener:(id)reshapeListener { + return [self initWithFrame:NSZeroRect reshapeListener:reshapeListener]; +} + +- (instancetype)initWithFrame:(NSRect)frame + reshapeListener:(id)reshapeListener { + NSOpenGLPixelFormatAttribute attributes[] = { + NSOpenGLPFAColorSize, 24, NSOpenGLPFAAlphaSize, 8, NSOpenGLPFADoubleBuffer, 0, + }; + NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; + self = [super initWithFrame:frame pixelFormat:pixelFormat]; + if (self) { + _reshapeListener = reshapeListener; + self.wantsBestResolutionOpenGLSurface = YES; + } + return self; +} + +- (void)makeCurrentContext { + [self.openGLContext makeCurrentContext]; +} + +- (void)onPresent { + [self.openGLContext flushBuffer]; +} + +#pragma mark - NSView overrides + +/** + * Declares that the view uses a flipped coordinate system, consistent with Flutter conventions. + */ +- (BOOL)isFlipped { + return YES; +} + +- (BOOL)isOpaque { + return YES; +} + +- (void)reshape { + [super reshape]; + [_reshapeListener viewDidReshape:self]; +} + +- (BOOL)acceptsFirstResponder { + return YES; +} + +@end