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

Initial import of FDE macOS framework #7642

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,22 @@ FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_software.h
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/Headers/FLEOpenGLContextHandling.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEPlugin.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FLEPluginRegistrar.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/Flutter.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Info.plist
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
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/module.modulemap
FILE: ../../../flutter/shell/platform/embedder/assets/EmbedderInfo.plist
FILE: ../../../flutter/shell/platform/embedder/assets/embedder.modulemap
FILE: ../../../flutter/shell/platform/embedder/embedder.cc
Expand Down
23 changes: 23 additions & 0 deletions shell/platform/darwin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@

assert(is_mac || is_ios)

import("framework_shared.gni")

group("darwin") {
if (is_ios) {
deps = [
"ios:flutter_framework",
]
}
if (is_mac) {
deps = [
"macos:flutter_framework",
]
}
}

source_set("flutter_channels") {
Expand Down Expand Up @@ -40,6 +47,22 @@ source_set("flutter_channels") {
public_configs = [ "$flutter_root:config" ]
}

# Framework code shared between iOS and macOS.
source_set("framework_shared") {
set_sources_assignment_filter([])
sources = [
"ios/framework/Source/FlutterChannels.mm",
"ios/framework/Source/FlutterCodecs.mm",
"ios/framework/Source/FlutterStandardCodec.mm",
"ios/framework/Source/FlutterStandardCodec_Internal.h",
]

public = framework_shared_headers
set_sources_assignment_filter(sources_assignment_filter)

defines = [ "FLUTTER_FRAMEWORK" ]
}

executable("flutter_channels_unittests") {
testonly = true

Expand Down
14 changes: 14 additions & 0 deletions shell/platform/darwin/framework_shared.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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.

framework_shared_headers = get_path_info(
[
# TODO: Move these files, and their implementations, to a shared
# location.
"ios/framework/Headers/FlutterMacros.h",
"ios/framework/Headers/FlutterBinaryMessenger.h",
"ios/framework/Headers/FlutterChannels.h",
"ios/framework/Headers/FlutterCodecs.h",
],
"abspath")
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ FLUTTER_EXPORT
*/
- (void)sendOnChannel:(NSString*)channel
message:(NSData* _Nullable)message
binaryReply:(FlutterBinaryReply _Nullable)callback;
binaryReply:(FlutterBinaryReply _Nullable)callback
// TODO: Add macOS support for replies once
// https://github.com/flutter/flutter/issues/18852 is fixed.
API_UNAVAILABLE(macos);

/**
* Registers a message handler for incoming binary messages from the Flutter side
Expand Down
11 changes: 9 additions & 2 deletions shell/platform/darwin/ios/framework/Headers/FlutterChannels.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ FLUTTER_EXPORT
* @param message The message. Must be supported by the codec of this channel.
* @param callback A callback to be invoked with the message reply from Flutter.
*/
- (void)sendMessage:(id _Nullable)message reply:(FlutterReply _Nullable)callback;
- (void)sendMessage:(id _Nullable)message
reply:(FlutterReply _Nullable)callback
// TODO: Add macOS support for replies once
// https://github.com/flutter/flutter/issues/18852 is fixed.
API_UNAVAILABLE(macos);

/**
* Registers a message handler with this channel.
Expand Down Expand Up @@ -234,7 +238,10 @@ FLUTTER_EXPORT
*/
- (void)invokeMethod:(NSString*)method
arguments:(id _Nullable)arguments
result:(FlutterResult _Nullable)callback;
result:(FlutterResult _Nullable)callback
// TODO: Add macOS support for replies once
// https://github.com/flutter/flutter/issues/18852 is fixed.
API_UNAVAILABLE(macos);

/**
* Registers a handler for method calls from the Flutter side.
Expand Down
196 changes: 196 additions & 0 deletions shell/platform/darwin/macos/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# 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.

assert(is_mac)

import("//build/config/mac/mac_sdk.gni")
import("$flutter_root/common/config.gni")
import("$flutter_root/shell/platform/darwin/framework_shared.gni")

_flutter_framework_name = "Flutter"
_flutter_framework_out_dir_subpath = "macos/$_flutter_framework_name.framework"
_flutter_framework_dir = "$root_out_dir/$_flutter_framework_out_dir_subpath"

# The headers that will be copied to the Flutter.framework and be accessed
# from outside the Flutter engine source root.
_flutter_framework_headers = [
"framework/Headers/Flutter.h",
"framework/Headers/FLEOpenGLContextHandling.h",
"framework/Headers/FLEPlugin.h",
"framework/Headers/FLEPluginRegistrar.h",
"framework/Headers/FLEReshapeListener.h",
"framework/Headers/FLEView.h",
"framework/Headers/FLEViewController.h",
]

_flutter_framework_headers_copy_dir =
"$_flutter_framework_dir/Versions/A/Headers"

shared_library("create_flutter_framework_dylib") {
visibility = [ ":*" ]

output_name = "$_flutter_framework_name"

sources = [
"framework/Source/FLETextInputModel.h",
"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",
]

sources += _flutter_framework_headers

deps = [
"$flutter_root/shell/platform/darwin:framework_shared",
"$flutter_root/shell/platform/embedder:embedder",
]

public_configs = [ "$flutter_root:config" ]

defines = [ "FLUTTER_FRAMEWORK" ]

cflags_objcc = [ "-fobjc-arc" ]

libs = [ "Cocoa.framework" ]
}

copy("copy_framework_dylib") {
visibility = [ ":*" ]

sources = [
"$root_out_dir/lib$_flutter_framework_name.dylib",
]
outputs = [
"$_flutter_framework_dir/Versions/A/$_flutter_framework_name",
]

deps = [
":create_flutter_framework_dylib",
]
}

action("copy_dylib_and_update_framework_install_name") {
visibility = [ ":*" ]
stamp_file = "$root_out_dir/flutter_install_name_stamp"
script = "$flutter_root/sky/tools/change_install_name.py"

inputs = [
"$_flutter_framework_dir/Versions/A/$_flutter_framework_name",
]
outputs = [
stamp_file,
]

args = [
"--dylib",
rebase_path("$_flutter_framework_dir/Versions/A/$_flutter_framework_name"),
"--install_name",
"@rpath/$_flutter_framework_name.framework/Versions/A/$_flutter_framework_name",
"--stamp",
rebase_path(stamp_file),
]

deps = [
":copy_framework_dylib",
]
}

copy("copy_framework_info_plist") {
visibility = [ ":*" ]
sources = [
"framework/Info.plist",
]
outputs = [
"$_flutter_framework_dir/Versions/A/Resources/Info.plist",
]
}

copy("copy_framework_module_map") {
visibility = [ ":*" ]
sources = [
"framework/module.modulemap",
]
outputs = [
"$_flutter_framework_dir/Versions/A/Modules/module.modulemap",
]
}

action("copy_framework_headers") {
script = "$flutter_root/sky/tools/install_framework_headers.py"
visibility = [ ":*" ]
set_sources_assignment_filter([])
sources = get_path_info(_flutter_framework_headers, "abspath") +
framework_shared_headers
outputs = []
foreach(header, sources) {
header_basename = get_path_info(header, "file")
outputs += [ "$_flutter_framework_headers_copy_dir/$header_basename" ]
}
args = [
"--location",
rebase_path("$_flutter_framework_headers_copy_dir"),
"--headers",
] + rebase_path(sources, "", "//")
set_sources_assignment_filter(sources_assignment_filter)
}

copy("copy_framework_icu") {
visibility = [ ":*" ]
set_sources_assignment_filter([])
sources = [
"//third_party/icu/flutter/icudtl.dat",
]
set_sources_assignment_filter(sources_assignment_filter)
outputs = [
"$_flutter_framework_dir/Versions/A/Resources/{{source_file_part}}",
]
}

copy("copy_license") {
visibility = [ ":*" ]
sources = [
"//LICENSE",
]
outputs = [
"$root_out_dir/LICENSE",
]
}

action("_generate_symlinks") {
visibility = [ ":*" ]
script = "//build/config/mac/package_framework.py"
outputs = [
"$root_build_dir/$_flutter_framework_name.stamp",
]
args = [
"--framework",
"$_flutter_framework_out_dir_subpath",
"--version",
"A",
"--contents",
"$_flutter_framework_name",
"Resources",
"Headers",
"Modules",
"--stamp",
"$_flutter_framework_name.stamp",
]
deps = [
":copy_dylib_and_update_framework_install_name",
":copy_framework_headers",
":copy_framework_icu",
":copy_framework_info_plist",
":copy_framework_module_map",
":copy_license",
]
}

group("flutter_framework") {
deps = [
":_generate_symlinks",
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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.

#if defined(FLUTTER_FRAMEWORK)
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterMacros.h"
#else
#import "FlutterMacros.h"
#endif

/**
* 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
52 changes: 52 additions & 0 deletions shell/platform/darwin/macos/framework/Headers/FLEPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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 <Foundation/Foundation.h>

#if defined(FLUTTER_FRAMEWORK)
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterChannels.h"
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterCodecs.h"
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterMacros.h"
#else
#import "FlutterChannels.h"
#import "FlutterCodecs.h"
#import "FlutterMacros.h"
#endif

@protocol FLEPluginRegistrar;

/**
* Implemented by the platform side of a Flutter plugin.
*
* Defines a set of optional callback methods and a method to set up the plugin
* and register it to be called by other application components.
*
* Currently FLEPlugin has very limited functionality, but is expected to expand over time to
* more closely match the functionality of FlutterPlugin.
*/
FLUTTER_EXPORT
@protocol FLEPlugin <NSObject>

/**
* Creates an instance of the plugin to register with |registrar| using the desired
* FLEPluginRegistrar methods.
*/
+ (void)registerWithRegistrar:(nonnull id<FLEPluginRegistrar>)registrar;

@optional

/**
* Called when a message is sent from Flutter on a channel that a plugin instance has subscribed
* to via -[FLEPluginRegistrar addMethodCallDelegate:channel:].
*
* The |result| callback must be called exactly once, with one of:
* - FlutterMethodNotImplemented, if the method call is unknown.
* - A FlutterError, if the method call was understood but there was a
* problem handling it.
* - Any other value (including nil) to indicate success. The value will
* be returned to the Flutter caller, and must be serializable to JSON.
*/
- (void)handleMethodCall:(nonnull FlutterMethodCall*)call result:(nonnull FlutterResult)result;

@end
Loading