13#include <unordered_map>
16#include "flutter/shell/platform/embedder/embedder.h"
17#include "flutter/shell/platform/linux/fl_method_codec_private.h"
18#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_message_codec.h"
19#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_response.h"
20#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"
21#include "gtest/gtest.h"
35 std::unordered_map<int64_t, _FlutterEngineTexture>
textures;
85 this->message =
nullptr;
102 const std::string& channel,
105 size_t message_size) {
106 if (response_handle ==
nullptr) {
114 engine->platform_post_task_callback(task, 0,
engine->user_data);
119 const std::string& channel,
121 size_t message_size) {
126 engine->platform_post_task_callback(task, 0,
engine->user_data);
130 const std::string& channel,
134 g_autoptr(GError)
error =
nullptr;
138 EXPECT_EQ(
error,
nullptr);
142 1234, channel,
nullptr,
143 static_cast<const uint8_t*
>(g_bytes_get_data(
message,
nullptr)),
146 engine->platform_post_task_callback(task, 0,
engine->user_data);
166 EXPECT_NE(config,
nullptr);
168 EXPECT_NE(
args,
nullptr);
169 EXPECT_NE(
args->platform_message_callback,
nullptr);
170 EXPECT_NE(
args->custom_task_runners,
nullptr);
171 EXPECT_NE(
args->custom_task_runners->platform_task_runner,
nullptr);
172 EXPECT_NE(
args->custom_task_runners->platform_task_runner->post_task_callback,
180 args->platform_message_callback,
181 args->custom_task_runners->platform_task_runner->post_task_callback,
198 EXPECT_NE(config,
nullptr);
199 EXPECT_NE(
args,
nullptr);
201 EXPECT_NE(engine_out,
nullptr);
232 size_t events_count) {
250 if (strcmp(
message->channel,
"test/echo") == 0) {
254 }
else if (strcmp(
message->channel,
"test/send-message") == 0) {
260 }
else if (strcmp(
message->channel,
"test/standard-method") == 0) {
262 g_autoptr(GBytes)
m = g_bytes_new(
message->message,
message->message_size);
263 g_autofree gchar*
name =
nullptr;
265 g_autoptr(GError)
error =
nullptr;
268 EXPECT_EQ(
error,
nullptr);
270 g_autoptr(GBytes) response =
nullptr;
271 if (strcmp(
name,
"Echo") == 0) {
275 EXPECT_EQ(
error,
nullptr);
276 }
else if (strcmp(
name,
"Error") == 0) {
278 const gchar*
code =
nullptr;
279 const gchar*
message =
nullptr;
295 EXPECT_EQ(
error,
nullptr);
296 }
else if (strcmp(
name,
"InvokeMethod") == 0) {
306 invoke_method(
engine, channel,
name, method_args);
310 EXPECT_EQ(
error,
nullptr);
313 response = g_bytes_new(
nullptr, 0);
318 static_cast<const uint8_t*
>(g_bytes_get_data(response,
nullptr)),
319 g_bytes_get_size(response));
320 }
else if (strcmp(
message->channel,
"test/nullptr-response") == 0) {
324 }
else if (strcmp(
message->channel,
"test/standard-event") == 0) {
328 }
else if (strcmp(
message->channel,
"test/failure") == 0) {
331 }
else if (strcmp(
message->channel,
"test/key-event-handled") == 0 ||
332 strcmp(
message->channel,
"test/key-event-not-handled") == 0) {
333 bool value = strcmp(
message->channel,
"test/key-event-handled") == 0;
338 FL_MESSAGE_CODEC(codec), handledValue,
nullptr);
341 static_cast<const uint8_t*
>(g_bytes_get_data(response,
nullptr)),
342 g_bytes_get_size(response));
343 }
else if (strcmp(
message->channel,
"test/key-event-delayed") == 0) {
344 static std::unique_ptr<const FlutterPlatformMessageResponseHandle>
345 delayed_response_handle =
nullptr;
350 FL_MESSAGE_CODEC(codec), handledValue,
nullptr);
351 if (delayed_response_handle ==
nullptr) {
352 delayed_response_handle.reset(
message->response_handle);
356 static_cast<const uint8_t*
>(g_bytes_get_data(response,
nullptr)),
357 g_bytes_get_size(response));
360 static_cast<const uint8_t*
>(g_bytes_get_data(response,
nullptr)),
361 g_bytes_get_size(response));
374 EXPECT_NE(data_callback,
nullptr);
380 *response_out = handle;
387 EXPECT_NE(
engine,
nullptr);
388 EXPECT_NE(response,
nullptr);
402 size_t data_length) {
403 EXPECT_NE(
engine,
nullptr);
404 EXPECT_NE(handle,
nullptr);
409 if (handle->
channel !=
"test/responses") {
410 send_message(
engine,
"test/responses",
data, data_length);
423 EXPECT_NE(
engine,
nullptr);
424 EXPECT_NE(task,
nullptr);
425 EXPECT_NE(task->
runner,
nullptr);
428 EXPECT_NE(runner,
nullptr);
431 if (response_handle !=
nullptr) {
444 message.response_handle = handle;
460 size_t locales_count) {
481 size_t data_length) {
487 int64_t texture_identifier) {
496 int64_t texture_identifier) {
497 auto val =
engine->textures.find(texture_identifier);
498 if (val == std::end(
engine->textures)) {
501 val->second.has_new_frame =
true;
507 int64_t texture_identifier) {
508 auto val =
engine->textures.find(texture_identifier);
509 if (val == std::end(
engine->textures)) {
512 engine->textures.erase(texture_identifier);
520 size_t display_count) {
533 *
table = empty_table;
546 table->PlatformMessageCreateResponseHandle =
548 table->PlatformMessageReleaseResponseHandle =
550 table->SendPlatformMessageResponse =
558 table->MarkExternalTextureFrameAvailable =
561 table->UpdateAccessibilityFeatures =
FlutterEngineResult FlutterEngineMarkExternalTextureFrameAvailable(FLUTTER_API_SYMBOL(FlutterEngine) engine, int64_t texture_identifier)
Mark that a new texture frame is available for a given texture identifier.
FlutterEngineResult FlutterEngineRunTask(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterTask *task)
Inform the engine to run the specified task. This task has been given to the engine via the FlutterTa...
FlutterEngineResult FlutterEngineRun(size_t version, const FlutterRendererConfig *config, const FlutterProjectArgs *args, void *user_data, FLUTTER_API_SYMBOL(FlutterEngine) *engine_out)
Initialize and run a Flutter engine instance and return a handle to it. This is a convenience method ...
FlutterEngineResult FlutterEngineRegisterExternalTexture(FLUTTER_API_SYMBOL(FlutterEngine) engine, int64_t texture_identifier)
Register an external texture with a unique (per engine) identifier. Only rendering backends that supp...
FlutterEngineResult FlutterEngineUpdateLocales(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterLocale **locales, size_t locales_count)
Notify a running engine instance that the locale has been updated. The preferred locale must be the f...
FlutterEngineResult FlutterEngineSendWindowMetricsEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterWindowMetricsEvent *flutter_metrics)
FlutterEngineResult FlutterEngineDispatchSemanticsAction(FLUTTER_API_SYMBOL(FlutterEngine) engine, uint64_t node_id, FlutterSemanticsAction action, const uint8_t *data, size_t data_length)
Dispatch a semantics action to the specified semantics node.
FLUTTER_EXPORT FlutterEngineResult FlutterEngineDeinitialize(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Stops running the Flutter engine instance. After this call, the embedder is also guaranteed that no m...
FlutterEngineResult FlutterEngineInitialize(size_t version, const FlutterRendererConfig *config, const FlutterProjectArgs *args, void *user_data, FLUTTER_API_SYMBOL(FlutterEngine) *engine_out)
Initialize a Flutter engine instance. This does not run the Flutter application code till the Flutter...
FlutterEngineResult FlutterEngineUpdateAccessibilityFeatures(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterAccessibilityFeature flags)
Sets additional accessibility features.
FlutterEngineResult FlutterEngineShutdown(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Shuts down a Flutter engine instance. The engine handle is no longer valid for any calls in the embed...
FlutterEngineResult FlutterPlatformMessageCreateResponseHandle(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterDataCallback data_callback, void *user_data, FlutterPlatformMessageResponseHandle **response_out)
Creates a platform message response handle that allows the embedder to set a native callback for a re...
FlutterEngineResult FlutterEngineCollectAOTData(FlutterEngineAOTData data)
Collects the AOT data.
FlutterEngineResult FlutterEngineNotifyDisplayUpdate(FLUTTER_API_SYMBOL(FlutterEngine) raw_engine, const FlutterEngineDisplaysUpdateType update_type, const FlutterEngineDisplay *embedder_displays, size_t display_count)
Posts updates corresponding to display changes to a running engine instance.
FlutterEngineResult FlutterEngineSendPlatformMessage(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessage *flutter_message)
bool FlutterEngineRunsAOTCompiledDartCode(void)
Returns if the Flutter engine instance will run AOT compiled Dart code. This call has no threading re...
FlutterEngineResult FlutterEngineSendPointerEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPointerEvent *pointers, size_t events_count)
FlutterEngineResult FlutterEngineRunInitialized(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Runs an initialized engine instance. An engine can be initialized via FlutterEngineInitialize....
FlutterEngineResult FlutterEngineUnregisterExternalTexture(FLUTTER_API_SYMBOL(FlutterEngine) engine, int64_t texture_identifier)
Unregister a previous texture registration.
FlutterEngineResult FlutterEngineUpdateSemanticsEnabled(FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled)
Enable or disable accessibility semantics.
FlutterEngineResult FlutterEngineSendKeyEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterKeyEvent *event, FlutterKeyEventCallback callback, void *user_data)
Sends a key event to the engine. The framework will decide whether to handle this event in a synchron...
FlutterEngineResult FlutterEngineSendPlatformMessageResponse(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
Send a response from the native side to a platform message from the Dart Flutter application.
FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterPlatformMessageResponseHandle *response)
Collects the handle created using FlutterPlatformMessageCreateResponseHandle.
FlutterEngineResult FlutterEngineCreateAOTData(const FlutterEngineAOTDataSource *source, FlutterEngineAOTData *data_out)
Creates the necessary data structures to launch a Flutter Dart application in AOT mode....
void(* FlutterPlatformMessageCallback)(const FlutterPlatformMessage *, void *)
struct _FlutterEngine * FLUTTER_API_SYMBOL(FlutterEngine)
void(* FlutterDataCallback)(const uint8_t *, size_t, void *)
FlutterAccessibilityFeature
void(* FlutterTaskRunnerPostTaskCallback)(FlutterTask, uint64_t, void *)
FlutterEngineDisplaysUpdateType
void(* FlutterKeyEventCallback)(bool, void *)
static gboolean send_response(FlBinaryMessenger *messenger, FlBinaryMessengerResponseHandle *response_handle_, GBytes *response, GError **error)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_MODULE_EXPORT FlJsonMessageCodec * fl_json_message_codec_new()
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
G_MODULE_EXPORT GBytes * fl_message_codec_encode_message(FlMessageCodec *self, FlValue *message, GError **error)
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)
GBytes * fl_method_codec_encode_success_envelope(FlMethodCodec *self, FlValue *result, GError **error)
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
GBytes * fl_method_codec_encode_error_envelope(FlMethodCodec *self, const gchar *code, const gchar *message, FlValue *details, GError **error)
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
G_MODULE_EXPORT FlValue * fl_value_new_map()
G_MODULE_EXPORT void fl_value_set_string_take(FlValue *self, const gchar *key, FlValue *value)
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
typedefG_BEGIN_DECLS struct _FlValue FlValue
const int32_t kFlutterSemanticsNodeIdBatchEnd
const int32_t kFlutterSemanticsCustomActionIdBatchEnd
FlutterEngineResult FlutterEngineGetProcAddresses(FlutterEngineProcTable *table)
Gets the table of engine function pointers.
void * malloc(size_t size)
DEF_SWITCHES_START aot vmservice shared library name
Function-pointer-based versions of the APIs above.
FlutterTaskRunnerPostTaskCallback platform_post_task_callback
_FlutterEngine(FlutterPlatformMessageCallback platform_message_callback, FlutterTaskRunnerPostTaskCallback platform_post_task_callback, void *user_data)
FlutterPlatformMessageCallback platform_message_callback
std::unordered_map< int64_t, _FlutterEngineTexture > textures
_FlutterTaskRunner(uint64_t task, const std::string &channel, const FlutterPlatformMessageResponseHandle *response_handle, const uint8_t *message, size_t message_size)
const FlutterPlatformMessageResponseHandle * response_handle
std::shared_ptr< const fml::Mapping > data
#define EXPECT_TRUE(handle)