Skip to content

Commit

Permalink
Add a macro for prefixing embedder.h symbols (#9851)
Browse files Browse the repository at this point in the history
embedder.h is a C API, so has no namespace, and only uses 'Flutter' as a
prefix for most symbol names. This creates potential collisions with
other code; for instance, FlutterEngine is the name of a type in
embedder.h, but also an ObjC class in the iOS Flutter API.

This adds a macro that can be set to prefix symbol names, allowing
clients (notably, the macOS embedding) to adjust the names used by the
embedding API internally without breaking ABI or API compatibility for
the standard engine build.

Currently the macro is only applied to FlutterEngine, since that's the
symbol that is currently at issue, but it can be expanded to other
symbols in the future.
  • Loading branch information
stuartmorgan authored Jul 23, 2019
1 parent 1f30131 commit 7d320c4
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 100 deletions.
2 changes: 1 addition & 1 deletion shell/platform/common/cpp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ source_set("common_cpp") {
deps = [
":common_cpp_library_headers",
"$flutter_root/shell/platform/common/cpp/client_wrapper:client_wrapper",
"$flutter_root/shell/platform/embedder:embedder",
"$flutter_root/shell/platform/embedder:embedder_with_symbol_prefix",
]

# TODO: Remove once text input model refactor lands, at which point this code
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/darwin/macos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ shared_library("create_flutter_framework_dylib") {

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

public_configs = [ "$flutter_root:config" ]
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/darwin/macos/framework/Source/FLEEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FLEEngine*

@implementation FLEEngine {
// The embedding-API-level engine object.
FlutterEngine _engine;
FLUTTER_API_SYMBOL(FlutterEngine) _engine;

// The project being run by this engine.
FLEDartProject* _project;
Expand Down
100 changes: 59 additions & 41 deletions shell/platform/embedder/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,67 @@ shell_gpu_configuration("embedder_gpu_configuration") {
enable_metal = false
}

source_set("embedder") {
sources = [
"embedder.cc",
"embedder.h",
"embedder_engine.cc",
"embedder_engine.h",
"embedder_external_texture_gl.cc",
"embedder_external_texture_gl.h",
"embedder_include.c",
"embedder_platform_message_response.cc",
"embedder_platform_message_response.h",
"embedder_safe_access.h",
"embedder_surface.cc",
"embedder_surface.h",
"embedder_surface_gl.cc",
"embedder_surface_gl.h",
"embedder_surface_software.cc",
"embedder_surface_software.h",
"embedder_task_runner.cc",
"embedder_task_runner.h",
"embedder_thread_host.cc",
"embedder_thread_host.h",
"platform_view_embedder.cc",
"platform_view_embedder.h",
"vsync_waiter_embedder.cc",
"vsync_waiter_embedder.h",
]
# Template for the embedder build. Used to allow building it multiple times with
# different flags.
template("embedder_source_set") {
forward_variables_from(invoker, "*")

deps = [
":embedder_gpu_configuration",
"$flutter_root/assets",
"$flutter_root/common",
"$flutter_root/flow",
"$flutter_root/fml",
"$flutter_root/lib/ui",
"$flutter_root/runtime:libdart",
"$flutter_root/shell/common",
"//third_party/dart/runtime/bin:dart_io_api",
"//third_party/skia",
"//third_party/tonic",
]
source_set(target_name) {
sources = [
"embedder.cc",
"embedder.h",
"embedder_engine.cc",
"embedder_engine.h",
"embedder_external_texture_gl.cc",
"embedder_external_texture_gl.h",
"embedder_include.c",
"embedder_platform_message_response.cc",
"embedder_platform_message_response.h",
"embedder_safe_access.h",
"embedder_surface.cc",
"embedder_surface.h",
"embedder_surface_gl.cc",
"embedder_surface_gl.h",
"embedder_surface_software.cc",
"embedder_surface_software.h",
"embedder_task_runner.cc",
"embedder_task_runner.h",
"embedder_thread_host.cc",
"embedder_thread_host.h",
"platform_view_embedder.cc",
"platform_view_embedder.h",
"vsync_waiter_embedder.cc",
"vsync_waiter_embedder.h",
]

public_configs = [ "$flutter_root:config" ]
deps = [
":embedder_gpu_configuration",
"$flutter_root/assets",
"$flutter_root/common",
"$flutter_root/flow",
"$flutter_root/fml",
"$flutter_root/lib/ui",
"$flutter_root/runtime:libdart",
"$flutter_root/shell/common",
"//third_party/dart/runtime/bin:dart_io_api",
"//third_party/skia",
"//third_party/tonic",
]

public_configs += [ "$flutter_root:config" ]
}
}

embedder_source_set("embedder") {
public_configs = []
}

embedder_source_set("embedder_with_symbol_prefix") {
public_configs = [ ":embedder_prefix_config" ]
}

config("embedder_prefix_config") {
defines = [ "FLUTTER_API_SYMBOL_PREFIX=Embedder" ]
}

test_fixtures("fixtures") {
Expand Down
49 changes: 28 additions & 21 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ FlutterEngineResult FlutterEngineRun(size_t version,
const FlutterRendererConfig* config,
const FlutterProjectArgs* args,
void* user_data,
FlutterEngine* engine_out) {
FLUTTER_API_SYMBOL(FlutterEngine) *
engine_out) {
// Step 0: Figure out arguments for shell creation.
if (version != FLUTTER_ENGINE_VERSION) {
return LOG_EMBEDDER_ERROR(kInvalidLibraryVersion);
Expand Down Expand Up @@ -640,11 +641,13 @@ FlutterEngineResult FlutterEngineRun(size_t version,
}

// Finally! Release the ownership of the embedder engine to the caller.
*engine_out = reinterpret_cast<FlutterEngine>(embedder_engine.release());
*engine_out = reinterpret_cast<FLUTTER_API_SYMBOL(FlutterEngine)>(
embedder_engine.release());
return kSuccess;
}

FlutterEngineResult FlutterEngineShutdown(FlutterEngine engine) {
FlutterEngineResult FlutterEngineShutdown(FLUTTER_API_SYMBOL(FlutterEngine)
engine) {
if (engine == nullptr) {
return LOG_EMBEDDER_ERROR(kInvalidArguments);
}
Expand All @@ -655,7 +658,7 @@ FlutterEngineResult FlutterEngineShutdown(FlutterEngine engine) {
}

FlutterEngineResult FlutterEngineSendWindowMetricsEvent(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
const FlutterWindowMetricsEvent* flutter_metrics) {
if (engine == nullptr || flutter_metrics == nullptr) {
return LOG_EMBEDDER_ERROR(kInvalidArguments);
Expand Down Expand Up @@ -742,7 +745,7 @@ inline int64_t PointerDataButtonsForLegacyEvent(
}

FlutterEngineResult FlutterEngineSendPointerEvent(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
const FlutterPointerEvent* pointers,
size_t events_count) {
if (engine == nullptr || pointers == nullptr || events_count == 0) {
Expand Down Expand Up @@ -801,7 +804,7 @@ FlutterEngineResult FlutterEngineSendPointerEvent(
}

FlutterEngineResult FlutterEngineSendPlatformMessage(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
const FlutterPlatformMessage* flutter_message) {
if (engine == nullptr || flutter_message == nullptr) {
return LOG_EMBEDDER_ERROR(kInvalidArguments);
Expand Down Expand Up @@ -844,7 +847,7 @@ FlutterEngineResult FlutterEngineSendPlatformMessage(
}

FlutterEngineResult FlutterPlatformMessageCreateResponseHandle(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
FlutterDataCallback data_callback,
void* user_data,
FlutterPlatformMessageResponseHandle** response_out) {
Expand Down Expand Up @@ -875,7 +878,7 @@ FlutterEngineResult FlutterPlatformMessageCreateResponseHandle(
}

FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
FlutterPlatformMessageResponseHandle* response) {
if (engine == nullptr || response == nullptr) {
return LOG_EMBEDDER_ERROR(kInvalidArguments);
Expand All @@ -885,7 +888,7 @@ FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle(
}

FlutterEngineResult FlutterEngineSendPlatformMessageResponse(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
const FlutterPlatformMessageResponseHandle* handle,
const uint8_t* data,
size_t data_length) {
Expand Down Expand Up @@ -915,7 +918,7 @@ FlutterEngineResult __FlutterEngineFlushPendingTasksNow() {
}

FlutterEngineResult FlutterEngineRegisterExternalTexture(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier) {
if (engine == nullptr || texture_identifier == 0) {
return LOG_EMBEDDER_ERROR(kInvalidArguments);
Expand All @@ -928,7 +931,7 @@ FlutterEngineResult FlutterEngineRegisterExternalTexture(
}

FlutterEngineResult FlutterEngineUnregisterExternalTexture(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier) {
if (engine == nullptr || texture_identifier == 0) {
return kInvalidArguments;
Expand All @@ -943,7 +946,7 @@ FlutterEngineResult FlutterEngineUnregisterExternalTexture(
}

FlutterEngineResult FlutterEngineMarkExternalTextureFrameAvailable(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier) {
if (engine == nullptr || texture_identifier == 0) {
return LOG_EMBEDDER_ERROR(kInvalidArguments);
Expand All @@ -955,8 +958,9 @@ FlutterEngineResult FlutterEngineMarkExternalTextureFrameAvailable(
return kSuccess;
}

FlutterEngineResult FlutterEngineUpdateSemanticsEnabled(FlutterEngine engine,
bool enabled) {
FlutterEngineResult FlutterEngineUpdateSemanticsEnabled(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
bool enabled) {
if (engine == nullptr) {
return LOG_EMBEDDER_ERROR(kInvalidArguments);
}
Expand All @@ -968,7 +972,7 @@ FlutterEngineResult FlutterEngineUpdateSemanticsEnabled(FlutterEngine engine,
}

FlutterEngineResult FlutterEngineUpdateAccessibilityFeatures(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
FlutterAccessibilityFeature flags) {
if (engine == nullptr) {
return LOG_EMBEDDER_ERROR(kInvalidArguments);
Expand All @@ -981,7 +985,7 @@ FlutterEngineResult FlutterEngineUpdateAccessibilityFeatures(
}

FlutterEngineResult FlutterEngineDispatchSemanticsAction(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
uint64_t id,
FlutterSemanticsAction action,
const uint8_t* data,
Expand All @@ -999,7 +1003,8 @@ FlutterEngineResult FlutterEngineDispatchSemanticsAction(
return kSuccess;
}

FlutterEngineResult FlutterEngineOnVsync(FlutterEngine engine,
FlutterEngineResult FlutterEngineOnVsync(FLUTTER_API_SYMBOL(FlutterEngine)
engine,
intptr_t baton,
uint64_t frame_start_time_nanos,
uint64_t frame_target_time_nanos) {
Expand Down Expand Up @@ -1035,9 +1040,10 @@ void FlutterEngineTraceEventInstant(const char* name) {
fml::tracing::TraceEventInstant0("flutter", name);
}

FlutterEngineResult FlutterEnginePostRenderThreadTask(FlutterEngine engine,
VoidCallback callback,
void* baton) {
FlutterEngineResult FlutterEnginePostRenderThreadTask(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
VoidCallback callback,
void* baton) {
if (engine == nullptr || callback == nullptr) {
return LOG_EMBEDDER_ERROR(kInvalidArguments);
}
Expand All @@ -1054,7 +1060,8 @@ uint64_t FlutterEngineGetCurrentTime() {
return fml::TimePoint::Now().ToEpochDelta().ToNanoseconds();
}

FlutterEngineResult FlutterEngineRunTask(FlutterEngine engine,
FlutterEngineResult FlutterEngineRunTask(FLUTTER_API_SYMBOL(FlutterEngine)
engine,
const FlutterTask* task) {
if (engine == nullptr) {
return LOG_EMBEDDER_ERROR(kInvalidArguments);
Expand Down
Loading

0 comments on commit 7d320c4

Please sign in to comment.