Skip to content

Commit

Permalink
Begin separating macOS engine from view controller (flutter#9654)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stuartmorgan committed Jul 3, 2019
1 parent d3616c7 commit 8dac2e9
Show file tree
Hide file tree
Showing 10 changed files with 444 additions and 307 deletions.
3 changes: 3 additions & 0 deletions ci/licenses_golden/licenses_flutter
Expand Up @@ -740,6 +740,7 @@ FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_software.mm
FILE: ../../../flutter/shell/platform/darwin/ios/platform_view_ios.h
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/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
Expand All @@ -748,6 +749,8 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FlutterMacO
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FlutterPluginMacOS.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Info.plist
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLEEngine.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLEEngine_Internal.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInputModel.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInputModel.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FLETextInputPlugin.h
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/darwin/macos/BUILD.gn
Expand Up @@ -33,6 +33,7 @@ _flutter_framework_headers = [
"framework/Headers/FlutterMacOS.h",
"framework/Headers/FlutterPluginMacOS.h",
"framework/Headers/FlutterPluginRegistrarMacOS.h",
"framework/Headers/FLEEngine.h",
"framework/Headers/FLEOpenGLContextHandling.h",
"framework/Headers/FLEReshapeListener.h",
"framework/Headers/FLEView.h",
Expand All @@ -48,6 +49,8 @@ shared_library("create_flutter_framework_dylib") {
output_name = "$_flutter_framework_name"

sources = [
"framework/Source/FLEEngine.mm",
"framework/Source/FLEEngine_Internal.h",
"framework/Source/FLETextInputModel.h",
"framework/Source/FLETextInputModel.mm",
"framework/Source/FLETextInputPlugin.h",
Expand Down
59 changes: 59 additions & 0 deletions shell/platform/darwin/macos/framework/Headers/FLEEngine.h
@@ -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.

#ifndef FLUTTER_FLEENGINE_H_
#define FLUTTER_FLEENGINE_H_

#import <Foundation/Foundation.h>

#include "FlutterBinaryMessenger.h"
#include "FlutterMacros.h"
#include "FlutterPluginRegistrarMacOS.h"

@class FLEViewController;

/**
* Coordinates a single instance of execution of a Flutter engine.
*
* TODO(stuartmorgan): Finish aligning this (and ideally merging) with FlutterEngine. Currently
* this is largely usable only as an implementation detail of FLEViewController.
*/
FLUTTER_EXPORT
@interface FLEEngine : NSObject <FlutterPluginRegistry>

/**
* Initializes an engine with the given viewController.
*
* @param viewController The view controller associated with this engine. If nil, the engine
* will be run headless.
*/
- (nonnull instancetype)initWithViewController:(nullable FLEViewController*)viewController;

/**
* Launches the Flutter engine with the provided configuration.
*
* @param assets The path to the flutter_assets folder for the Flutter application to be run.
* @param arguments Arguments to pass to the Flutter engine. See
* https://github.com/flutter/engine/blob/master/shell/common/switches.h
* for details. Not all arguments will apply to embedding mode.
* Note: This API layer will abstract arguments in the future, instead of
* providing a direct passthrough.
* @return YES if the engine launched successfully.
*/
- (BOOL)launchEngineWithAssetsPath:(nonnull NSURL*)assets
commandLineArguments:(nullable NSArray<NSString*>*)arguments;

/**
* The `FLEViewController` associated with this engine, if any.
*/
@property(nonatomic, nullable, readonly, weak) FLEViewController* viewController;

/**
* The `FlutterBinaryMessenger` for communicating with this engine.
*/
@property(nonatomic, nonnull, readonly) id<FlutterBinaryMessenger> binaryMessenger;

@end

#endif // FLUTTER_FLEENGINE_H_
37 changes: 13 additions & 24 deletions shell/platform/darwin/macos/framework/Headers/FLEViewController.h
Expand Up @@ -4,9 +4,9 @@

#import <Cocoa/Cocoa.h>

#import "FLEEngine.h"
#import "FLEOpenGLContextHandling.h"
#import "FLEReshapeListener.h"
#import "FlutterBinaryMessenger.h"
#import "FlutterMacros.h"
#import "FlutterPluginRegistrarMacOS.h"

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

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

/**
* The Flutter engine associated with this view controller.
*/
@property(nonatomic, nonnull, readonly) FLEEngine* engine;

/**
* The style of mouse tracking to use for the view. Defaults to
* FlutterMouseTrackingModeInKeyWindow.
Expand All @@ -49,28 +53,13 @@ FLUTTER_EXPORT
*
* @param assets The path to the flutter_assets folder for the Flutter application to be run.
* @param arguments Arguments to pass to the Flutter engine. See
* https://github.com/flutter/engine/blob/master/shell/common/switches.h
* for details. Not all arguments will apply to embedding mode.
* Note: This API layer will likely abstract arguments in the future, instead of
* providing a direct passthrough.
* https://github.com/flutter/engine/blob/master/shell/common/switches.h
* for details. Not all arguments will apply to embedding mode.
* Note: This API layer will abstract in the future, instead of providing a direct
* passthrough.
* @return YES if the engine launched successfully.
*/
- (BOOL)launchEngineWithAssetsPath:(nonnull NSURL*)assets
commandLineArguments:(nullable NSArray<NSString*>*)arguments;

/**
* Launches the Flutter engine in headless mode with the provided configuration. In headless mode,
* this controller's view should not be displayed.
*
* See launcheEngineWithAssetsPath:commandLineArguments: for details.
*/
- (BOOL)launchHeadlessEngineWithAssetsPath:(nonnull NSURL*)assets
commandLineArguments:(nullable NSArray<NSString*>*)arguments;

/**
* The `FlutterBinaryMessenger` associated with this FLEViewController (used for communicating
* with channels).
*/
@property(nonatomic, readonly) NSObject<FlutterBinaryMessenger>* _Nonnull binaryMessenger;

@end
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "FLEEngine.h"
#import "FLEOpenGLContextHandling.h"
#import "FLEReshapeListener.h"
#import "FLEView.h"
Expand Down

0 comments on commit 8dac2e9

Please sign in to comment.