Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a proc table version of embedder API #21813

Merged
merged 9 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ group("flutter") {
"//flutter/lib/ui:ui_unittests",
"//flutter/runtime:runtime_unittests",
"//flutter/shell/common:shell_unittests",
"//flutter/shell/platform/embedder:embedder_proctable_unittests",
"//flutter/shell/platform/embedder:embedder_unittests",
"//flutter/testing:testing_unittests",
"//flutter/third_party/txt:txt_unittests",
Expand Down
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ FILE: ../../../flutter/shell/platform/embedder/fixtures/verifyb143464703.png
FILE: ../../../flutter/shell/platform/embedder/fixtures/verifyb143464703_soft_noxform.png
FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.cc
FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.h
FILE: ../../../flutter/shell/platform/embedder/test_utils/proc_table_replacement.h
FILE: ../../../flutter/shell/platform/embedder/vsync_waiter_embedder.cc
FILE: ../../../flutter/shell/platform/embedder/vsync_waiter_embedder.h
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart
Expand Down
35 changes: 35 additions & 0 deletions shell/platform/embedder/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ source_set("embedder_headers") {
public_configs = [ "//flutter:config" ]
}

source_set("embedder_test_utils") {
public = [ "test_utils/proc_table_replacement.h" ]

deps = [ ":embedder_headers" ]

public_configs = [ "//flutter:config" ]
}

# For using the embedder API as internal implementation detail of an
# embedding.
config("embedder_internal_library_config") {
Expand Down Expand Up @@ -200,6 +208,33 @@ if (enable_unittests) {
deps += [ "//flutter/testing:opengl" ]
}
}

# Tests the build in FLUTTER_ENGINE_NO_PROTOTYPES mode.
executable("embedder_proctable_unittests") {
testonly = true

configs += [
":embedder_gpu_configuration_config",
"//flutter:export_dynamic_symbols",
]

sources = [ "tests/embedder_unittests_proctable.cc" ]

defines = [ "FLUTTER_ENGINE_NO_PROTOTYPES" ]

deps = [
":embedder",
":embedder_gpu_configuration",
":fixtures",
"//flutter/testing",

#"//flutter/testing:dart",
#"//flutter/testing:skia",
#"//flutter/third_party/tonic",
#"//third_party/dart/runtime/bin:elf_loader",
#"//third_party/skia",
]
}
}

shared_library("flutter_engine_library") {
Expand Down
51 changes: 51 additions & 0 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2050,3 +2050,54 @@ FlutterEngineResult FlutterEngineNotifyDisplayUpdate(
"Invalid FlutterEngineDisplaysUpdateType type specified.");
}
}

FlutterEngineResult FlutterEngineGetProcAddresses(
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
FlutterEngineProcTable* table) {
#define SET_PROC(member, function) \
if (STRUCT_HAS_MEMBER(table, member)) { \
table->member = &function; \
}

SET_PROC(create_aot_data, FlutterEngineCreateAOTData);
SET_PROC(collect_aot_data, FlutterEngineCollectAOTData);
SET_PROC(run, FlutterEngineRun);
SET_PROC(shutdown, FlutterEngineShutdown);
SET_PROC(initialize, FlutterEngineInitialize);
SET_PROC(deinitialize, FlutterEngineDeinitialize);
SET_PROC(run_initialized, FlutterEngineRunInitialized);
SET_PROC(send_window_metrics_event, FlutterEngineSendWindowMetricsEvent);
SET_PROC(send_pointer_event, FlutterEngineSendPointerEvent);
SET_PROC(send_platform_message, FlutterEngineSendPlatformMessage);
SET_PROC(platform_message_create_response_handle,
FlutterPlatformMessageCreateResponseHandle);
SET_PROC(platform_message_release_response_handle,
FlutterPlatformMessageReleaseResponseHandle);
SET_PROC(send_platform_message_response,
FlutterEngineSendPlatformMessageResponse);
SET_PROC(register_external_texture, FlutterEngineRegisterExternalTexture);
SET_PROC(unregister_external_texture, FlutterEngineUnregisterExternalTexture);
SET_PROC(mark_external_texture_frame_available,
FlutterEngineMarkExternalTextureFrameAvailable);
SET_PROC(update_semantics_enabled, FlutterEngineUpdateSemanticsEnabled);
SET_PROC(update_accessibility_features,
FlutterEngineUpdateAccessibilityFeatures);
SET_PROC(dispatch_semantics_action, FlutterEngineDispatchSemanticsAction);
SET_PROC(on_vsync, FlutterEngineOnVsync);
SET_PROC(reload_system_fonts, FlutterEngineReloadSystemFonts);
SET_PROC(trace_event_duration_begin, FlutterEngineTraceEventDurationBegin);
SET_PROC(trace_event_duration_end, FlutterEngineTraceEventDurationEnd);
SET_PROC(trace_event_instant, FlutterEngineTraceEventInstant);
SET_PROC(post_render_thread_task, FlutterEnginePostRenderThreadTask);
SET_PROC(get_current_time, FlutterEngineGetCurrentTime);
SET_PROC(run_task, FlutterEngineRunTask);
SET_PROC(update_locales, FlutterEngineUpdateLocales);
SET_PROC(runs_aot_compiled_dart_code, FlutterEngineRunsAOTCompiledDartCode);
SET_PROC(post_dart_object, FlutterEnginePostDartObject);
SET_PROC(notify_low_memory_warning, FlutterEngineNotifyLowMemoryWarning);
SET_PROC(post_callback_on_all_native_threads,
FlutterEnginePostCallbackOnAllNativeThreads);
SET_PROC(notify_display_update, FlutterEngineNotifyDisplayUpdate);
#undef HAS_PROC
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This undefs an unset macro. I think you meant SET_PROC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦
Shame that's not a warning.


return kSuccess;
}
219 changes: 171 additions & 48 deletions shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -997,22 +997,6 @@ typedef enum {
kFlutterEngineDisplaysUpdateTypeCount,
} FlutterEngineDisplaysUpdateType;

//------------------------------------------------------------------------------
/// @brief Posts updates corresponding to display changes to a running engine
/// instance.
///
/// @param[in] update_type The type of update pushed to the engine.
/// @param[in] displays The displays affected by this update.
/// @param[in] display_count Size of the displays array, must be at least 1.
///
/// @return the result of the call made to the engine.
///
FlutterEngineResult FlutterEngineNotifyDisplayUpdate(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
FlutterEngineDisplaysUpdateType update_type,
const FlutterEngineDisplay* displays,
size_t display_count);

typedef int64_t FlutterEngineDartPort;

typedef enum {
Expand Down Expand Up @@ -1130,38 +1114,6 @@ typedef struct {
/// FlutterEngine instance in AOT mode.
typedef struct _FlutterEngineAOTData* FlutterEngineAOTData;

//------------------------------------------------------------------------------
/// @brief Creates the necessary data structures to launch a Flutter Dart
/// application in AOT mode. The data may only be collected after
/// all FlutterEngine instances launched using this data have been
/// terminated.
///
/// @param[in] source The source of the AOT data.
/// @param[out] data_out The AOT data on success. Unchanged on failure.
///
/// @return Returns if the AOT data could be successfully resolved.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineCreateAOTData(
const FlutterEngineAOTDataSource* source,
FlutterEngineAOTData* data_out);

//------------------------------------------------------------------------------
/// @brief Collects the AOT data.
///
/// @warning The embedder must ensure that this call is made only after all
/// FlutterEngine instances launched using this data have been
/// terminated, and that all of those instances were launched with
/// the FlutterProjectArgs::shutdown_dart_vm_when_done flag set to
/// true.
///
/// @param[in] data The data to collect.
///
/// @return Returns if the AOT data was successfully collected.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineCollectAOTData(FlutterEngineAOTData data);

typedef struct {
/// The size of this struct. Must be sizeof(FlutterProjectArgs).
size_t struct_size;
Expand Down Expand Up @@ -1383,6 +1335,40 @@ typedef struct {

} FlutterProjectArgs;

#ifndef FLUTTER_ENGINE_NO_PROTOTYPES

//------------------------------------------------------------------------------
/// @brief Creates the necessary data structures to launch a Flutter Dart
/// application in AOT mode. The data may only be collected after
/// all FlutterEngine instances launched using this data have been
/// terminated.
///
/// @param[in] source The source of the AOT data.
/// @param[out] data_out The AOT data on success. Unchanged on failure.
///
/// @return Returns if the AOT data could be successfully resolved.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineCreateAOTData(
const FlutterEngineAOTDataSource* source,
FlutterEngineAOTData* data_out);

//------------------------------------------------------------------------------
/// @brief Collects the AOT data.
///
/// @warning The embedder must ensure that this call is made only after all
/// FlutterEngine instances launched using this data have been
/// terminated, and that all of those instances were launched with
/// the FlutterProjectArgs::shutdown_dart_vm_when_done flag set to
/// true.
///
/// @param[in] data The data to collect.
///
/// @return Returns if the AOT data was successfully collected.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineCollectAOTData(FlutterEngineAOTData data);

//------------------------------------------------------------------------------
/// @brief Initialize and run a Flutter engine instance and return a handle
/// to it. This is a convenience method for the pair of calls to
Expand Down Expand Up @@ -1966,6 +1952,143 @@ FlutterEngineResult FlutterEnginePostCallbackOnAllNativeThreads(
FlutterNativeThreadCallback callback,
void* user_data);

//------------------------------------------------------------------------------
/// @brief Posts updates corresponding to display changes to a running engine
/// instance.
///
/// @param[in] update_type The type of update pushed to the engine.
/// @param[in] displays The displays affected by this update.
/// @param[in] display_count Size of the displays array, must be at least 1.
///
/// @return the result of the call made to the engine.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineNotifyDisplayUpdate(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
FlutterEngineDisplaysUpdateType update_type,
const FlutterEngineDisplay* displays,
size_t display_count);

#endif // !FLUTTER_ENGINE_NO_PROTOTYPES

/// Function-pointer-based versions of the APIs above.
typedef struct {
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
/// The size of this struct. Must be sizeof(FlutterEngineProcs).
size_t struct_size;

FlutterEngineResult (*create_aot_data)(
const FlutterEngineAOTDataSource* source,
FlutterEngineAOTData* data_out);
FlutterEngineResult (*collect_aot_data)(FlutterEngineAOTData data);
FlutterEngineResult (*run)(size_t version,
const FlutterRendererConfig* config,
const FlutterProjectArgs* args,
void* user_data,
FLUTTER_API_SYMBOL(FlutterEngine) * engine_out);
FlutterEngineResult (*shutdown)(FLUTTER_API_SYMBOL(FlutterEngine) engine);
FlutterEngineResult (*initialize)(size_t version,
const FlutterRendererConfig* config,
const FlutterProjectArgs* args,
void* user_data,
FLUTTER_API_SYMBOL(FlutterEngine) *
engine_out);
FlutterEngineResult (*deinitialize)(FLUTTER_API_SYMBOL(FlutterEngine) engine);
FlutterEngineResult (*run_initialized)(FLUTTER_API_SYMBOL(FlutterEngine)
engine);
FlutterEngineResult (*send_window_metrics_event)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
const FlutterWindowMetricsEvent* event);
FlutterEngineResult (*send_pointer_event)(FLUTTER_API_SYMBOL(FlutterEngine)
engine,
const FlutterPointerEvent* events,
size_t events_count);
FlutterEngineResult (*send_platform_message)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
const FlutterPlatformMessage* message);
FlutterEngineResult (*platform_message_create_response_handle)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
FlutterDataCallback data_callback,
void* user_data,
FlutterPlatformMessageResponseHandle** response_out);
FlutterEngineResult (*platform_message_release_response_handle)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
FlutterPlatformMessageResponseHandle* response);
FlutterEngineResult (*send_platform_message_response)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
const FlutterPlatformMessageResponseHandle* handle,
const uint8_t* data,
size_t data_length);
FlutterEngineResult (*register_external_texture)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier);
FlutterEngineResult (*unregister_external_texture)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier);
FlutterEngineResult (*mark_external_texture_frame_available)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier);
FlutterEngineResult (*update_semantics_enabled)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
bool enabled);
FlutterEngineResult (*update_accessibility_features)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
FlutterAccessibilityFeature features);
FlutterEngineResult (*dispatch_semantics_action)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
uint64_t id,
FlutterSemanticsAction action,
const uint8_t* data,
size_t data_length);
FlutterEngineResult (*on_vsync)(FLUTTER_API_SYMBOL(FlutterEngine) engine,
intptr_t baton,
uint64_t frame_start_time_nanos,
uint64_t frame_target_time_nanos);
FlutterEngineResult (*reload_system_fonts)(FLUTTER_API_SYMBOL(FlutterEngine)
engine);
void (*trace_event_duration_begin)(const char* name);
void (*trace_event_duration_end)(const char* name);
void (*trace_event_instant)(const char* name);
FlutterEngineResult (*post_render_thread_task)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
VoidCallback callback,
void* callback_data);
uint64_t (*get_current_time)();
FlutterEngineResult (*run_task)(FLUTTER_API_SYMBOL(FlutterEngine) engine,
const FlutterTask* task);
FlutterEngineResult (*update_locales)(FLUTTER_API_SYMBOL(FlutterEngine)
engine,
const FlutterLocale** locales,
size_t locales_count);
bool (*runs_aot_compiled_dart_code)(void);
FlutterEngineResult (*post_dart_object)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
FlutterEngineDartPort port,
const FlutterEngineDartObject* object);
FlutterEngineResult (*notify_low_memory_warning)(
FLUTTER_API_SYMBOL(FlutterEngine) engine);
FlutterEngineResult (*post_callback_on_all_native_threads)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
FlutterNativeThreadCallback callback,
void* user_data);
FlutterEngineResult (*notify_display_update)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
FlutterEngineDisplaysUpdateType update_type,
const FlutterEngineDisplay* displays,
size_t display_count);
} FlutterEngineProcTable;

//------------------------------------------------------------------------------
/// @brief Gets the table of engine function pointers.
///
/// @param[out] table The table to fill with pointers. This should be
/// zero-initialized, except for struct_size.
///
/// @return Returns whether the table was successfully populated.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineGetProcAddresses(
FlutterEngineProcTable* table);

#if defined(__cplusplus)
} // extern "C"
#endif
Expand Down
Loading