Add a macro for prefixing embedder.h symbols (flutter/engine#9851)

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.
This commit is contained in:
stuartmorgan
2019-07-23 05:48:48 -07:00
committed by GitHub
parent bc4058cb43
commit 1299da0e74
8 changed files with 141 additions and 100 deletions

View File

@@ -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

View File

@@ -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" ]

View File

@@ -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;

View File

@@ -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") {

View File

@@ -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);
@@ -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);
}
@@ -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);
@@ -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) {
@@ -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);
@@ -844,7 +847,7 @@ FlutterEngineResult FlutterEngineSendPlatformMessage(
}
FlutterEngineResult FlutterPlatformMessageCreateResponseHandle(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
FlutterDataCallback data_callback,
void* user_data,
FlutterPlatformMessageResponseHandle** response_out) {
@@ -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);
@@ -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) {
@@ -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);
@@ -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;
@@ -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);
@@ -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);
}
@@ -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);
@@ -981,7 +985,7 @@ FlutterEngineResult FlutterEngineUpdateAccessibilityFeatures(
}
FlutterEngineResult FlutterEngineDispatchSemanticsAction(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
uint64_t id,
FlutterSemanticsAction action,
const uint8_t* data,
@@ -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) {
@@ -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);
}
@@ -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);

View File

@@ -17,6 +17,16 @@ extern "C" {
#define FLUTTER_EXPORT
#endif // FLUTTER_EXPORT
#ifdef FLUTTER_API_SYMBOL_PREFIX
#define FLUTTER_EMBEDDING_CONCAT(a, b) a##b
#define FLUTTER_EMBEDDING_ADD_PREFIX(symbol, prefix) \
FLUTTER_EMBEDDING_CONCAT(prefix, symbol)
#define FLUTTER_API_SYMBOL(symbol) \
FLUTTER_EMBEDDING_ADD_PREFIX(symbol, FLUTTER_API_SYMBOL_PREFIX)
#else
#define FLUTTER_API_SYMBOL(symbol) symbol
#endif
#define FLUTTER_ENGINE_VERSION 1
typedef enum {
@@ -168,7 +178,7 @@ typedef enum {
kFlutterTextDirectionLTR = 2,
} FlutterTextDirection;
typedef struct _FlutterEngine* FlutterEngine;
typedef struct _FlutterEngine* FLUTTER_API_SYMBOL(FlutterEngine);
typedef struct {
// horizontal scale factor
@@ -692,25 +702,27 @@ FlutterEngineResult FlutterEngineRun(size_t version,
const FlutterRendererConfig* config,
const FlutterProjectArgs* args,
void* user_data,
FlutterEngine* engine_out);
FLUTTER_API_SYMBOL(FlutterEngine) *
engine_out);
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineShutdown(FlutterEngine engine);
FlutterEngineResult FlutterEngineShutdown(FLUTTER_API_SYMBOL(FlutterEngine)
engine);
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineSendWindowMetricsEvent(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
const FlutterWindowMetricsEvent* event);
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineSendPointerEvent(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
const FlutterPointerEvent* events,
size_t events_count);
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineSendPlatformMessage(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
const FlutterPlatformMessage* message);
// Creates a platform message response handle that allows the embedder to set a
@@ -728,7 +740,7 @@ FlutterEngineResult FlutterEngineSendPlatformMessage(
// call as the third argument.
FLUTTER_EXPORT
FlutterEngineResult FlutterPlatformMessageCreateResponseHandle(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
FlutterDataCallback data_callback,
void* user_data,
FlutterPlatformMessageResponseHandle** response_out);
@@ -737,12 +749,12 @@ FlutterEngineResult FlutterPlatformMessageCreateResponseHandle(
// |FlutterPlatformMessageCreateResponseHandle|.
FLUTTER_EXPORT
FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
FlutterPlatformMessageResponseHandle* response);
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineSendPlatformMessageResponse(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
const FlutterPlatformMessageResponseHandle* handle,
const uint8_t* data,
size_t data_length);
@@ -760,19 +772,19 @@ FlutterEngineResult __FlutterEngineFlushPendingTasksNow();
// |FlutterEngineMarkExternalTextureFrameAvailable|.
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineRegisterExternalTexture(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier);
// Unregister a previous texture registration.
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineUnregisterExternalTexture(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier);
// Mark that a new texture frame is available for a given texture identifier.
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineMarkExternalTextureFrameAvailable(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier);
// Enable or disable accessibility semantics.
@@ -781,19 +793,20 @@ FlutterEngineResult FlutterEngineMarkExternalTextureFrameAvailable(
// the |FlutterUpdateSemanticsNodeCallback| registered to
// |update_semantics_node_callback| in |FlutterProjectArgs|;
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineUpdateSemanticsEnabled(FlutterEngine engine,
bool enabled);
FlutterEngineResult FlutterEngineUpdateSemanticsEnabled(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
bool enabled);
// Sets additional accessibility features.
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineUpdateAccessibilityFeatures(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
FlutterAccessibilityFeature features);
// Dispatch a semantics action to the specified semantics node.
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineDispatchSemanticsAction(
FlutterEngine engine,
FLUTTER_API_SYMBOL(FlutterEngine) engine,
uint64_t id,
FlutterSemanticsAction action,
const uint8_t* data,
@@ -816,7 +829,8 @@ FlutterEngineResult FlutterEngineDispatchSemanticsAction(
//
// That frame timepoints are in nanoseconds.
FLUTTER_EXPORT
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);
@@ -851,9 +865,10 @@ void FlutterEngineTraceEventInstant(const char* name);
// from any thread as long as a |FlutterEngineShutdown| on the specific engine
// has not already been initiated.
FLUTTER_EXPORT
FlutterEngineResult FlutterEnginePostRenderThreadTask(FlutterEngine engine,
VoidCallback callback,
void* callback_data);
FlutterEngineResult FlutterEnginePostRenderThreadTask(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
VoidCallback callback,
void* callback_data);
// Get the current time in nanoseconds from the clock used by the flutter
// engine. This is the system monotonic clock.
@@ -865,7 +880,8 @@ uint64_t FlutterEngineGetCurrentTime();
// call must only be made at the target time specified in that callback. Running
// the task before that time is undefined behavior.
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineRunTask(FlutterEngine engine,
FlutterEngineResult FlutterEngineRunTask(FLUTTER_API_SYMBOL(FlutterEngine)
engine,
const FlutterTask* task);
#if defined(__cplusplus)

View File

@@ -54,7 +54,7 @@ source_set("flutter_glfw") {
":flutter_glfw_headers",
"$flutter_root/shell/platform/common/cpp:common_cpp",
"$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",
"$flutter_root/shell/platform/glfw/client_wrapper:client_wrapper_glfw",
"//build/secondary/third_party/glfw",
"//third_party/rapidjson",

View File

@@ -4,14 +4,14 @@
#include "flutter/shell/platform/glfw/public/flutter_glfw.h"
#include <GLFW/glfw3.h>
#include <assert.h>
#include <algorithm>
#include <chrono>
#include <cstdlib>
#include <iostream>
#include <GLFW/glfw3.h>
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h"
#include "flutter/shell/platform/common/cpp/incoming_message_dispatcher.h"
#include "flutter/shell/platform/embedder/embedder.h"
@@ -59,7 +59,7 @@ struct FlutterDesktopWindowControllerState {
UniqueGLFWwindowPtr(nullptr, glfwDestroyWindow);
// The handle to the Flutter engine instance.
FlutterEngine engine;
FLUTTER_API_SYMBOL(FlutterEngine) engine;
// The window handle given to API clients.
std::unique_ptr<FlutterDesktopWindow> window_wrapper;
@@ -113,7 +113,7 @@ struct FlutterDesktopWindow {
// Struct for storing state of a Flutter engine instance.
struct FlutterDesktopEngineState {
// The handle to the Flutter engine instance.
FlutterEngine engine;
FLUTTER_API_SYMBOL(FlutterEngine) engine;
};
// State associated with the plugin registrar.
@@ -128,7 +128,7 @@ struct FlutterDesktopPluginRegistrar {
// State associated with the messenger used to communicate with the engine.
struct FlutterDesktopMessenger {
// The Flutter engine this messenger sends outgoing messages to.
FlutterEngine engine;
FLUTTER_API_SYMBOL(FlutterEngine) engine;
// The message dispatcher for handling incoming messages.
flutter::IncomingMessageDispatcher* dispatcher;
@@ -493,13 +493,13 @@ static void GLFWErrorCallback(int error_code, const char* description) {
// provided).
//
// Returns a caller-owned pointer to the engine.
static FlutterEngine RunFlutterEngine(
GLFWwindow* window,
const char* assets_path,
const char* icu_data_path,
const char** arguments,
size_t arguments_count,
const FlutterCustomTaskRunners* custom_task_runners) {
static FLUTTER_API_SYMBOL(FlutterEngine)
RunFlutterEngine(GLFWwindow* window,
const char* assets_path,
const char* icu_data_path,
const char** arguments,
size_t arguments_count,
const FlutterCustomTaskRunners* custom_task_runners) {
// FlutterProjectArgs is expecting a full argv, so when processing it for
// flags the first item is treated as the executable and ignored. Add a dummy
// value so that all provided arguments are used.
@@ -535,7 +535,7 @@ static FlutterEngine RunFlutterEngine(
args.command_line_argv = &argv[0];
args.platform_message_callback = GLFWOnFlutterPlatformMessage;
args.custom_task_runners = custom_task_runners;
FlutterEngine engine = nullptr;
FLUTTER_API_SYMBOL(FlutterEngine) engine = nullptr;
auto result =
FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &args, window, &engine);
if (result != kSuccess || engine == nullptr) {