Skip to content

Commit 8dac2e9

Browse files
Begin separating macOS engine from view controller (flutter#9654)
Creates an initial, minimal FLEEngine that parallels the iOS FlutterEngine, and moves engine launch, plugin registration, and binary messenger functionality from FLEViewController to there. Uses the FLE prefix since the current APIs will change to better match FlutterEngine; the current APIs are intended to minimize conceptual changes relative to the current FLEViewController APIs since it's already a substantial change. Further changes will move channels from FLEViewController to FLEEngine, and further align the APIs and functionality with the iOS version. Part of flutter#32421
1 parent d3616c7 commit 8dac2e9

10 files changed

Lines changed: 444 additions & 307 deletions

File tree

‎ci/licenses_golden/licenses_flutter‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_software.mm
740740
FILE: ../../../flutter/shell/platform/darwin/ios/platform_view_ios.h
741741
FILE: ../../../flutter/shell/platform/darwin/ios/platform_view_ios.mm
742742
FILE: ../../../flutter/shell/platform/darwin/macos/framework/FlutterMacOS.podspec
743+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEEngine.h
743744
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEOpenGLContextHandling.h
744745
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEReshapeListener.h
745746
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEView.h
@@ -748,6 +749,8 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FlutterMacO
748749
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FlutterPluginMacOS.h
749750
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h
750751
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Info.plist
752+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLEEngine.mm
753+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLEEngine_Internal.h
751754
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInputModel.h
752755
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInputModel.mm
753756
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInputPlugin.h

‎shell/platform/darwin/macos/BUILD.gn‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ _flutter_framework_headers = [
3333
"framework/Headers/FlutterMacOS.h",
3434
"framework/Headers/FlutterPluginMacOS.h",
3535
"framework/Headers/FlutterPluginRegistrarMacOS.h",
36+
"framework/Headers/FLEEngine.h",
3637
"framework/Headers/FLEOpenGLContextHandling.h",
3738
"framework/Headers/FLEReshapeListener.h",
3839
"framework/Headers/FLEView.h",
@@ -48,6 +49,8 @@ shared_library("create_flutter_framework_dylib") {
4849
output_name = "$_flutter_framework_name"
4950

5051
sources = [
52+
"framework/Source/FLEEngine.mm",
53+
"framework/Source/FLEEngine_Internal.h",
5154
"framework/Source/FLETextInputModel.h",
5255
"framework/Source/FLETextInputModel.mm",
5356
"framework/Source/FLETextInputPlugin.h",
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
#ifndef FLUTTER_FLEENGINE_H_
6+
#define FLUTTER_FLEENGINE_H_
7+
8+
#import <Foundation/Foundation.h>
9+
10+
#include "FlutterBinaryMessenger.h"
11+
#include "FlutterMacros.h"
12+
#include "FlutterPluginRegistrarMacOS.h"
13+
14+
@class FLEViewController;
15+
16+
/**
17+
* Coordinates a single instance of execution of a Flutter engine.
18+
*
19+
* TODO(stuartmorgan): Finish aligning this (and ideally merging) with FlutterEngine. Currently
20+
* this is largely usable only as an implementation detail of FLEViewController.
21+
*/
22+
FLUTTER_EXPORT
23+
@interface FLEEngine : NSObject <FlutterPluginRegistry>
24+
25+
/**
26+
* Initializes an engine with the given viewController.
27+
*
28+
* @param viewController The view controller associated with this engine. If nil, the engine
29+
* will be run headless.
30+
*/
31+
- (nonnull instancetype)initWithViewController:(nullable FLEViewController*)viewController;
32+
33+
/**
34+
* Launches the Flutter engine with the provided configuration.
35+
*
36+
* @param assets The path to the flutter_assets folder for the Flutter application to be run.
37+
* @param arguments Arguments to pass to the Flutter engine. See
38+
* https://github.com/flutter/engine/blob/master/shell/common/switches.h
39+
* for details. Not all arguments will apply to embedding mode.
40+
* Note: This API layer will abstract arguments in the future, instead of
41+
* providing a direct passthrough.
42+
* @return YES if the engine launched successfully.
43+
*/
44+
- (BOOL)launchEngineWithAssetsPath:(nonnull NSURL*)assets
45+
commandLineArguments:(nullable NSArray<NSString*>*)arguments;
46+
47+
/**
48+
* The `FLEViewController` associated with this engine, if any.
49+
*/
50+
@property(nonatomic, nullable, readonly, weak) FLEViewController* viewController;
51+
52+
/**
53+
* The `FlutterBinaryMessenger` for communicating with this engine.
54+
*/
55+
@property(nonatomic, nonnull, readonly) id<FlutterBinaryMessenger> binaryMessenger;
56+
57+
@end
58+
59+
#endif // FLUTTER_FLEENGINE_H_

‎shell/platform/darwin/macos/framework/Headers/FLEViewController.h‎

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
#import <Cocoa/Cocoa.h>
66

7+
#import "FLEEngine.h"
78
#import "FLEOpenGLContextHandling.h"
89
#import "FLEReshapeListener.h"
9-
#import "FlutterBinaryMessenger.h"
1010
#import "FlutterMacros.h"
1111
#import "FlutterPluginRegistrarMacOS.h"
1212

@@ -29,15 +29,19 @@ typedef NS_ENUM(NSInteger, FlutterMouseTrackingMode) {
2929
* Flutter engine in non-interactive mode, or with a drawable Flutter canvas.
3030
*/
3131
FLUTTER_EXPORT
32-
@interface FLEViewController
33-
: NSViewController <FlutterPluginRegistrar, FlutterPluginRegistry, FLEReshapeListener>
32+
@interface FLEViewController : NSViewController <FlutterPluginRegistry, FLEReshapeListener>
3433

3534
/**
36-
* The view this controller manages when launched in interactive mode (headless set to false). Must
37-
* be capable of handling text input events, and the OpenGL context handling protocols.
35+
* The view this controller manages. Must be capable of handling text input events, and the OpenGL
36+
* context handling protocols.
3837
*/
3938
@property(nullable) NSView<FLEOpenGLContextHandling>* view;
4039

40+
/**
41+
* The Flutter engine associated with this view controller.
42+
*/
43+
@property(nonatomic, nonnull, readonly) FLEEngine* engine;
44+
4145
/**
4246
* The style of mouse tracking to use for the view. Defaults to
4347
* FlutterMouseTrackingModeInKeyWindow.
@@ -49,28 +53,13 @@ FLUTTER_EXPORT
4953
*
5054
* @param assets The path to the flutter_assets folder for the Flutter application to be run.
5155
* @param arguments Arguments to pass to the Flutter engine. See
52-
* https://github.com/flutter/engine/blob/master/shell/common/switches.h
53-
* for details. Not all arguments will apply to embedding mode.
54-
* Note: This API layer will likely abstract arguments in the future, instead of
55-
* providing a direct passthrough.
56+
* https://github.com/flutter/engine/blob/master/shell/common/switches.h
57+
* for details. Not all arguments will apply to embedding mode.
58+
* Note: This API layer will abstract in the future, instead of providing a direct
59+
* passthrough.
5660
* @return YES if the engine launched successfully.
5761
*/
5862
- (BOOL)launchEngineWithAssetsPath:(nonnull NSURL*)assets
5963
commandLineArguments:(nullable NSArray<NSString*>*)arguments;
6064

61-
/**
62-
* Launches the Flutter engine in headless mode with the provided configuration. In headless mode,
63-
* this controller's view should not be displayed.
64-
*
65-
* See launcheEngineWithAssetsPath:commandLineArguments: for details.
66-
*/
67-
- (BOOL)launchHeadlessEngineWithAssetsPath:(nonnull NSURL*)assets
68-
commandLineArguments:(nullable NSArray<NSString*>*)arguments;
69-
70-
/**
71-
* The `FlutterBinaryMessenger` associated with this FLEViewController (used for communicating
72-
* with channels).
73-
*/
74-
@property(nonatomic, readonly) NSObject<FlutterBinaryMessenger>* _Nonnull binaryMessenger;
75-
7665
@end

‎shell/platform/darwin/macos/framework/Headers/FlutterMacOS.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#import "FLEEngine.h"
56
#import "FLEOpenGLContextHandling.h"
67
#import "FLEReshapeListener.h"
78
#import "FLEView.h"

0 commit comments

Comments
 (0)