Flutter Engine
embedder.cc File Reference
#include <cstring>
#include <iostream>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "flutter/fml/build_config.h"
#include "flutter/fml/closure.h"
#include "flutter/fml/make_copyable.h"
#include "flutter/fml/native_library.h"
#include "third_party/dart/runtime/bin/elf_loader.h"
#include "third_party/dart/runtime/include/dart_native_api.h"
#include "flutter/assets/directory_asset_bundle.h"
#include "flutter/common/graphics/persistent_cache.h"
#include "flutter/common/task_runners.h"
#include "flutter/fml/command_line.h"
#include "flutter/fml/file.h"
#include "flutter/fml/message_loop.h"
#include "flutter/fml/paths.h"
#include "flutter/fml/trace_event.h"
#include "flutter/shell/common/rasterizer.h"
#include "flutter/shell/common/switches.h"
#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/embedder/embedder_engine.h"
#include "flutter/shell/platform/embedder/embedder_external_texture_resolver.h"
#include "flutter/shell/platform/embedder/embedder_platform_message_response.h"
#include "flutter/shell/platform/embedder/embedder_render_target.h"
#include "flutter/shell/platform/embedder/embedder_struct_macros.h"
#include "flutter/shell/platform/embedder/embedder_task_runner.h"
#include "flutter/shell/platform/embedder/embedder_thread_host.h"
#include "flutter/shell/platform/embedder/platform_view_embedder.h"
#include "rapidjson/rapidjson.h"
#include "rapidjson/writer.h"

Go to the source code of this file.

Classes

struct  _FlutterPlatformMessageResponseHandle
 
struct  LoadedElfDeleter
 
struct  _FlutterEngineAOTData
 

Macros

#define FML_USED_ON_EMBEDDER
 
#define RAPIDJSON_HAS_STDSTRING   1
 
#define FLUTTER_EXPORT   __attribute__((visibility("default")))
 
#define LOG_EMBEDDER_ERROR(code, reason)   LogEmbedderError(code, reason, #code, __FUNCTION__, __FILE__, __LINE__)
 
#define SET_PROC(member, function)
 

Typedefs

using UniqueLoadedElf = std::unique_ptr< Dart_LoadedElf, LoadedElfDeleter >
 

Functions

static FlutterEngineResult LogEmbedderError (FlutterEngineResult code, const char *reason, const char *code_name, const char *function, const char *file, int line)
 
static bool IsOpenGLRendererConfigValid (const FlutterRendererConfig *config)
 
static bool IsSoftwareRendererConfigValid (const FlutterRendererConfig *config)
 
static bool IsMetalRendererConfigValid (const FlutterRendererConfig *config)
 
static bool IsRendererValid (const FlutterRendererConfig *config)
 
static flutter::Shell::CreateCallback< flutter::PlatformViewInferOpenGLPlatformViewCreationCallback (const FlutterRendererConfig *config, void *user_data, flutter::PlatformViewEmbedder::PlatformDispatchTable platform_dispatch_table, std::unique_ptr< flutter::EmbedderExternalViewEmbedder > external_view_embedder)
 
static flutter::Shell::CreateCallback< flutter::PlatformViewInferMetalPlatformViewCreationCallback (const FlutterRendererConfig *config, void *user_data, flutter::PlatformViewEmbedder::PlatformDispatchTable platform_dispatch_table, std::unique_ptr< flutter::EmbedderExternalViewEmbedder > external_view_embedder)
 
static flutter::Shell::CreateCallback< flutter::PlatformViewInferSoftwarePlatformViewCreationCallback (const FlutterRendererConfig *config, void *user_data, flutter::PlatformViewEmbedder::PlatformDispatchTable platform_dispatch_table, std::unique_ptr< flutter::EmbedderExternalViewEmbedder > external_view_embedder)
 
static flutter::Shell::CreateCallback< flutter::PlatformViewInferPlatformViewCreationCallback (const FlutterRendererConfig *config, void *user_data, flutter::PlatformViewEmbedder::PlatformDispatchTable platform_dispatch_table, std::unique_ptr< flutter::EmbedderExternalViewEmbedder > external_view_embedder)
 
static sk_sp< SkSurface > MakeSkSurfaceFromBackingStore (GrDirectContext *context, const FlutterBackingStoreConfig &config, const FlutterOpenGLTexture *texture)
 
static sk_sp< SkSurface > MakeSkSurfaceFromBackingStore (GrDirectContext *context, const FlutterBackingStoreConfig &config, const FlutterOpenGLFramebuffer *framebuffer)
 
static sk_sp< SkSurface > MakeSkSurfaceFromBackingStore (GrDirectContext *context, const FlutterBackingStoreConfig &config, const FlutterSoftwareBackingStore *software)
 
static sk_sp< SkSurface > MakeSkSurfaceFromBackingStore (GrDirectContext *context, const FlutterBackingStoreConfig &config, const FlutterMetalBackingStore *metal)
 
static std::unique_ptr< flutter::EmbedderRenderTargetCreateEmbedderRenderTarget (const FlutterCompositor *compositor, const FlutterBackingStoreConfig &config, GrDirectContext *context)
 
static std::pair< std::unique_ptr< flutter::EmbedderExternalViewEmbedder >, bool > InferExternalViewEmbedderFromArgs (const FlutterCompositor *compositor)
 
FlutterEngineResult FlutterEngineCreateAOTData (const FlutterEngineAOTDataSource *source, FlutterEngineAOTData *data_out)
 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. More...
 
FlutterEngineResult FlutterEngineCollectAOTData (FlutterEngineAOTData data)
 Collects the AOT data. More...
 
void PopulateSnapshotMappingCallbacks (const FlutterProjectArgs *args, flutter::Settings &settings)
 
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 for the pair of calls to FlutterEngineInitialize and FlutterEngineRunInitialized. More...
 
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 FlutterEngineRunInitialized call is made. Besides Flutter application code, no tasks are scheduled on embedder managed task runners either. This allows embedders providing custom task runners to the Flutter engine to obtain a handle to the Flutter engine before the engine can post tasks on these task runners. More...
 
FlutterEngineResult FlutterEngineRunInitialized (FLUTTER_API_SYMBOL(FlutterEngine) engine)
 Runs an initialized engine instance. An engine can be initialized via FlutterEngineInitialize. An initialized instance can only be run once. During and after this call, custom task runners supplied by the embedder are expected to start servicing tasks. More...
 
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 more calls to post tasks onto custom task runners specified by the embedder are made. The Flutter engine handle still needs to be collected via a call to FlutterEngineShutdown. More...
 
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 embedder API after this point. Making additional calls with this handle is undefined behavior. More...
 
FlutterEngineResult FlutterEngineSendWindowMetricsEvent (FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterWindowMetricsEvent *flutter_metrics)
 
flutter::PointerData::Change ToPointerDataChange (FlutterPointerPhase phase)
 
flutter::PointerData::DeviceKind ToPointerDataKind (FlutterPointerDeviceKind device_kind)
 
flutter::PointerData::SignalKind ToPointerDataSignalKind (FlutterPointerSignalKind kind)
 
int64_t PointerDataButtonsForLegacyEvent (flutter::PointerData::Change change)
 
FlutterEngineResult FlutterEngineSendPointerEvent (FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPointerEvent *pointers, size_t events_count)
 
static flutter::KeyEventType MapKeyEventType (FlutterKeyEventType event_kind)
 
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 synchronous fashion, although due to technical limitation, the result is always reported asynchronously. The callback is guaranteed to be called exactly once. More...
 
FlutterEngineResult FlutterEngineSendPlatformMessage (FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessage *flutter_message)
 
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 response to a message. This handle may be set on the response_handle field of any FlutterPlatformMessage sent to the engine. More...
 
FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle (FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterPlatformMessageResponseHandle *response)
 Collects the handle created using FlutterPlatformMessageCreateResponseHandle. More...
 
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. More...
 
FlutterEngineResult __FlutterEngineFlushPendingTasksNow ()
 This API is only meant to be used by platforms that need to flush tasks on a message loop not controlled by the Flutter engine. More...
 
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 support external textures accept external texture registrations. After the external texture is registered, the application can mark that a frame is available by calling FlutterEngineMarkExternalTextureFrameAvailable. More...
 
FlutterEngineResult FlutterEngineUnregisterExternalTexture (FLUTTER_API_SYMBOL(FlutterEngine) engine, int64_t texture_identifier)
 Unregister a previous texture registration. More...
 
FlutterEngineResult FlutterEngineMarkExternalTextureFrameAvailable (FLUTTER_API_SYMBOL(FlutterEngine) engine, int64_t texture_identifier)
 Mark that a new texture frame is available for a given texture identifier. More...
 
FlutterEngineResult FlutterEngineUpdateSemanticsEnabled (FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled)
 Enable or disable accessibility semantics. More...
 
FlutterEngineResult FlutterEngineUpdateAccessibilityFeatures (FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterAccessibilityFeature flags)
 Sets additional accessibility features. More...
 
FlutterEngineResult FlutterEngineDispatchSemanticsAction (FLUTTER_API_SYMBOL(FlutterEngine) engine, uint64_t id, FlutterSemanticsAction action, const uint8_t *data, size_t data_length)
 Dispatch a semantics action to the specified semantics node. More...
 
FlutterEngineResult FlutterEngineOnVsync (FLUTTER_API_SYMBOL(FlutterEngine) engine, intptr_t baton, uint64_t frame_start_time_nanos, uint64_t frame_target_time_nanos)
 Notify the engine that a vsync event occurred. A baton passed to the platform via the vsync callback must be returned. This call must be made on the thread on which the call to FlutterEngineRun was made. More...
 
FlutterEngineResult FlutterEngineReloadSystemFonts (FLUTTER_API_SYMBOL(FlutterEngine) engine)
 Reloads the system fonts in engine. More...
 
void FlutterEngineTraceEventDurationBegin (const char *name)
 A profiling utility. Logs a trace duration begin event to the timeline. If the timeline is unavailable or disabled, this has no effect. Must be balanced with an duration end event (via FlutterEngineTraceEventDurationEnd) with the same name on the same thread. Can be called on any thread. Strings passed into the function will NOT be copied when added to the timeline. Only string literals may be passed in. More...
 
void FlutterEngineTraceEventDurationEnd (const char *name)
 A profiling utility. Logs a trace duration end event to the timeline. If the timeline is unavailable or disabled, this has no effect. This call must be preceded by a trace duration begin call (via FlutterEngineTraceEventDurationBegin) with the same name on the same thread. Can be called on any thread. Strings passed into the function will NOT be copied when added to the timeline. Only string literals may be passed in. More...
 
void FlutterEngineTraceEventInstant (const char *name)
 A profiling utility. Logs a trace duration instant event to the timeline. If the timeline is unavailable or disabled, this has no effect. Can be called on any thread. Strings passed into the function will NOT be copied when added to the timeline. Only string literals may be passed in. More...
 
FlutterEngineResult FlutterEnginePostRenderThreadTask (FLUTTER_API_SYMBOL(FlutterEngine) engine, VoidCallback callback, void *baton)
 Posts a task onto the Flutter render thread. Typically, this may be called from any thread as long as a FlutterEngineShutdown on the specific engine has not already been initiated. More...
 
uint64_t FlutterEngineGetCurrentTime ()
 Get the current time in nanoseconds from the clock used by the flutter engine. This is the system monotonic clock. More...
 
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 FlutterTaskRunnerDescription.post_task_callback. This call must only be made at the target time specified in that callback. Running the task before that time is undefined behavior. More...
 
static bool DispatchJSONPlatformMessage (FLUTTER_API_SYMBOL(FlutterEngine) engine, rapidjson::Document document, const std::string &channel_name)
 
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 first item in the list of locales supplied. The other entries will be used as a fallback. More...
 
bool FlutterEngineRunsAOTCompiledDartCode (void)
 Returns if the Flutter engine instance will run AOT compiled Dart code. This call has no threading restrictions. More...
 
FlutterEngineResult FlutterEnginePostDartObject (FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterEngineDartPort port, const FlutterEngineDartObject *object)
 Posts a Dart object to specified send port. The corresponding receive port for send port can be in any isolate running in the VM. This isolate can also be the root isolate for an unrelated engine. The engine parameter is necessary only to ensure the call is not made when no engine (and hence no VM) is running. More...
 
FlutterEngineResult FlutterEngineNotifyLowMemoryWarning (FLUTTER_API_SYMBOL(FlutterEngine) raw_engine)
 Posts a low memory notification to a running engine instance. The engine will do its best to release non-critical resources in response. It is not guaranteed that the resource would have been collected by the time this call returns however. The notification is posted to engine subsystems that may be operating on other threads. More...
 
FlutterEngineResult FlutterEnginePostCallbackOnAllNativeThreads (FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterNativeThreadCallback callback, void *user_data)
 Schedule a callback to be run on all engine managed threads. The engine will attempt to service this callback the next time the message loop for each managed thread is idle. Since the engine manages the entire lifecycle of multiple threads, there is no opportunity for the embedders to finely tune the priorities of threads directly, or, perform other thread specific configuration (for example, setting thread names for tracing). This callback gives embedders a chance to affect such tuning. More...
 
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. More...
 
FlutterEngineResult FlutterEngineGetProcAddresses (FlutterEngineProcTable *table)
 Gets the table of engine function pointers. More...
 

Variables

const uint8_t kPlatformStrongDill []
 
const intptr_t kPlatformStrongDillSize
 
const int32_t kFlutterSemanticsNodeIdBatchEnd = -1
 
const int32_t kFlutterSemanticsCustomActionIdBatchEnd = -1
 

Macro Definition Documentation

◆ FLUTTER_EXPORT

#define FLUTTER_EXPORT   __attribute__((visibility("default")))

Definition at line 26 of file embedder.cc.

Referenced by FlutterEngineRunInitialized().

◆ FML_USED_ON_EMBEDDER

#define FML_USED_ON_EMBEDDER

Definition at line 5 of file embedder.cc.

◆ LOG_EMBEDDER_ERROR

◆ RAPIDJSON_HAS_STDSTRING

#define RAPIDJSON_HAS_STDSTRING   1

Definition at line 6 of file embedder.cc.

◆ SET_PROC

#define SET_PROC (   member,
  function 
)
Value:
if (STRUCT_HAS_MEMBER(table, member)) { \
table->member = &function; \
}
#define STRUCT_HAS_MEMBER(pointer, member)

Referenced by FlutterEngineGetProcAddresses().

Typedef Documentation

◆ UniqueLoadedElf

using UniqueLoadedElf = std::unique_ptr<Dart_LoadedElf, LoadedElfDeleter>

Definition at line 738 of file embedder.cc.

Function Documentation

◆ __FlutterEngineFlushPendingTasksNow()

FlutterEngineResult __FlutterEngineFlushPendingTasksNow ( )

This API is only meant to be used by platforms that need to flush tasks on a message loop not controlled by the Flutter engine.

Returns
The result of the call.

Definition at line 1754 of file embedder.cc.

References fml::MessageLoop::GetCurrent(), kSuccess, and fml::MessageLoop::RunExpiredTasksNow().

1754  {
1756  return kSuccess;
1757 }
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
void RunExpiredTasksNow()
Definition: message_loop.cc:72

◆ CreateEmbedderRenderTarget()

static std::unique_ptr<flutter::EmbedderRenderTarget> CreateEmbedderRenderTarget ( const FlutterCompositor compositor,
const FlutterBackingStoreConfig config,
GrDirectContext *  context 
)
static

Definition at line 608 of file embedder.cc.

References FlutterCompositor::collect_backing_store_callback, FlutterCompositor::create_backing_store_callback, FML_LOG, FlutterOpenGLBackingStore::framebuffer, kFlutterBackingStoreTypeMetal, kFlutterBackingStoreTypeOpenGL, kFlutterBackingStoreTypeSoftware, kFlutterOpenGLTargetTypeFramebuffer, kFlutterOpenGLTargetTypeTexture, MakeSkSurfaceFromBackingStore(), FlutterBackingStore::metal, FlutterBackingStore::open_gl, fml::ScopedCleanupClosure::Release(), FlutterBackingStore::software, FlutterBackingStore::struct_size, FlutterOpenGLBackingStore::texture, TRACE_EVENT0, FlutterOpenGLBackingStore::type, FlutterBackingStore::type, user_data, and FlutterCompositor::user_data.

Referenced by InferExternalViewEmbedderFromArgs().

610  {
611  FlutterBackingStore backing_store = {};
612  backing_store.struct_size = sizeof(backing_store);
613 
614  // Safe access checks on the compositor struct have been performed in
615  // InferExternalViewEmbedderFromArgs and are not necessary here.
616  auto c_create_callback = compositor->create_backing_store_callback;
617  auto c_collect_callback = compositor->collect_backing_store_callback;
618 
619  {
620  TRACE_EVENT0("flutter", "FlutterCompositorCreateBackingStore");
621  if (!c_create_callback(&config, &backing_store, compositor->user_data)) {
622  FML_LOG(ERROR) << "Could not create the embedder backing store.";
623  return nullptr;
624  }
625  }
626 
627  if (backing_store.struct_size != sizeof(backing_store)) {
628  FML_LOG(ERROR) << "Embedder modified the backing store struct size.";
629  return nullptr;
630  }
631 
632  // In case we return early without creating an embedder render target, the
633  // embedder has still given us ownership of its baton which we must return
634  // back to it. If this method is successful, the closure is released when the
635  // render target is eventually released.
636  fml::ScopedCleanupClosure collect_callback(
637  [c_collect_callback, backing_store, user_data = compositor->user_data]() {
638  TRACE_EVENT0("flutter", "FlutterCompositorCollectBackingStore");
639  c_collect_callback(&backing_store, user_data);
640  });
641 
642  // No safe access checks on the renderer are necessary since we allocated
643  // the struct.
644 
645  sk_sp<SkSurface> render_surface;
646 
647  switch (backing_store.type) {
649  switch (backing_store.open_gl.type) {
651  render_surface = MakeSkSurfaceFromBackingStore(
652  context, config, &backing_store.open_gl.texture);
653  break;
655  render_surface = MakeSkSurfaceFromBackingStore(
656  context, config, &backing_store.open_gl.framebuffer);
657  break;
658  }
659  break;
661  render_surface = MakeSkSurfaceFromBackingStore(context, config,
662  &backing_store.software);
663  break;
665  render_surface =
666  MakeSkSurfaceFromBackingStore(context, config, &backing_store.metal);
667  break;
668  };
669 
670  if (!render_surface) {
671  FML_LOG(ERROR) << "Could not create a surface from an embedder provided "
672  "render target.";
673  return nullptr;
674  }
675 
676  return std::make_unique<flutter::EmbedderRenderTarget>(
677  backing_store, std::move(render_surface), collect_callback.Release());
678 }
Specified an software allocation for Flutter to render into using the CPU.
Definition: embedder.h:1047
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
FlutterOpenGLFramebuffer framebuffer
Definition: embedder.h:959
void * user_data
Specifies a Metal backing store. This is backed by a Metal texture.
Definition: embedder.h:1049
#define FML_LOG(severity)
Definition: logging.h:65
Wraps a closure that is invoked in the destructor unless released by the caller.
Definition: closure.h:32
FlutterOpenGLTargetType type
Definition: embedder.h:953
FlutterSoftwareBackingStore software
The description of the software backing store.
Definition: embedder.h:1068
FlutterOpenGLBackingStore open_gl
The description of the OpenGL backing store.
Definition: embedder.h:1066
size_t struct_size
The size of this struct. Must be sizeof(FlutterBackingStore).
Definition: embedder.h:1054
FlutterBackingStoreCollectCallback collect_backing_store_callback
Definition: embedder.h:1141
FlutterBackingStoreType type
Specifies the type of backing store.
Definition: embedder.h:1060
FlutterMetalBackingStore metal
Definition: embedder.h:1070
static sk_sp< SkSurface > MakeSkSurfaceFromBackingStore(GrDirectContext *context, const FlutterBackingStoreConfig &config, const FlutterOpenGLTexture *texture)
Definition: embedder.cc:439
FlutterOpenGLTexture texture
A texture for Flutter to render into.
Definition: embedder.h:956
FlutterBackingStoreCreateCallback create_backing_store_callback
Definition: embedder.h:1138

◆ DispatchJSONPlatformMessage()

static bool DispatchJSONPlatformMessage ( FLUTTER_API_SYMBOL(FlutterEngine engine,
rapidjson::Document  document,
const std::string &  channel_name 
)
static

Definition at line 1960 of file embedder.cc.

References buffer, fml::MallocMapping::Copy(), and engine.

Referenced by FlutterEngineNotifyLowMemoryWarning(), and FlutterEngineUpdateLocales().

1963  {
1964  if (channel_name.size() == 0) {
1965  return false;
1966  }
1967 
1968  rapidjson::StringBuffer buffer;
1969  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
1970 
1971  if (!document.Accept(writer)) {
1972  return false;
1973  }
1974 
1975  const char* message = buffer.GetString();
1976 
1977  if (message == nullptr || buffer.GetSize() == 0) {
1978  return false;
1979  }
1980 
1981  auto platform_message = std::make_unique<flutter::PlatformMessage>(
1982  channel_name.c_str(), // channel
1983  fml::MallocMapping::Copy(message,
1984  buffer.GetSize()), // message
1985  nullptr // response
1986  );
1987 
1988  return reinterpret_cast<flutter::EmbedderEngine*>(engine)
1989  ->SendPlatformMessage(std::move(platform_message));
1990 }
static MallocMapping Copy(const T *begin, const T *end)
Definition: mapping.h:147
static const uint8_t buffer[]

◆ FlutterEngineCollectAOTData()

FlutterEngineResult FlutterEngineCollectAOTData ( FlutterEngineAOTData  data)

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.
Parameters
[in]dataThe data to collect.
Returns
Returns if the AOT data was successfully collected.

Definition at line 802 of file embedder.cc.

References kSuccess.

Referenced by FlutterEngineGetProcAddresses(), flutter::testing::AOTDataDeleter::operator()(), AOTDataDeleter::operator()(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

802  {
803  if (!data) {
804  // Deleting a null object should be a no-op.
805  return kSuccess;
806  }
807 
808  // Created in a unique pointer in `FlutterEngineCreateAOTData`.
809  delete data;
810  return kSuccess;
811 }

◆ FlutterEngineCreateAOTData()

FlutterEngineResult FlutterEngineCreateAOTData ( const FlutterEngineAOTDataSource source,
FlutterEngineAOTData data_out 
)

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.

Parameters
[in]sourceThe source of the AOT data.
[out]data_outThe AOT data on success. Unchanged on failure.
Returns
Returns if the AOT data could be successfully resolved.

Definition at line 748 of file embedder.cc.

References FlutterEngineAOTDataSource::elf_path, error, fml::IsFile(), flutter::DartVM::IsRunningPrecompiledCode(), kFlutterEngineAOTDataSourceTypeElfPath, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and FlutterEngineAOTDataSource::type.

Referenced by FlutterEngineGetProcAddresses(), LoadAotData(), flutter::testing::EmbedderTestContext::SetupAOTDataIfNecessary(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

750  {
753  "AOT data can only be created in AOT mode.");
754  } else if (!source) {
755  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Null source specified.");
756  } else if (!data_out) {
757  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Null data_out specified.");
758  }
759 
760  switch (source->type) {
762  if (!source->elf_path || !fml::IsFile(source->elf_path)) {
764  "Invalid ELF path specified.");
765  }
766 
767  auto aot_data = std::make_unique<_FlutterEngineAOTData>();
768  const char* error = nullptr;
769 
770 #if OS_FUCHSIA
771  // TODO(gw280): https://github.com/flutter/flutter/issues/50285
772  // Dart doesn't implement Dart_LoadELF on Fuchsia
773  Dart_LoadedElf* loaded_elf = nullptr;
774 #else
775  Dart_LoadedElf* loaded_elf = Dart_LoadELF(
776  source->elf_path, // file path
777  0, // file offset
778  &error, // error (out)
779  &aot_data->vm_snapshot_data, // vm snapshot data (out)
780  &aot_data->vm_snapshot_instrs, // vm snapshot instr (out)
781  &aot_data->vm_isolate_data, // vm isolate data (out)
782  &aot_data->vm_isolate_instrs // vm isolate instr (out)
783  );
784 #endif
785 
786  if (loaded_elf == nullptr) {
787  return LOG_EMBEDDER_ERROR(kInvalidArguments, error);
788  }
789 
790  aot_data->loaded_elf.reset(loaded_elf);
791 
792  *data_out = aot_data.release();
793  return kSuccess;
794  }
795  }
796 
797  return LOG_EMBEDDER_ERROR(
799  "Invalid FlutterEngineAOTDataSourceType type specified.");
800 }
const uint8_t uint32_t uint32_t GError ** error
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
static bool IsRunningPrecompiledCode()
Checks if VM instances in the process can run precompiled code. This call can be made at any time and...
Definition: dart_vm.cc:205
bool IsFile(const std::string &path)
Definition: file_posix.cc:145
FlutterEngineAOTDataSourceType type
Definition: embedder.h:1325
const char * elf_path
Absolute path to an ELF library file.
Definition: embedder.h:1328

◆ FlutterEngineDeinitialize()

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 more calls to post tasks onto custom task runners specified by the embedder are made. The Flutter engine handle still needs to be collected via a call to FlutterEngineShutdown.

Parameters
[in]engineThe running engine instance to de-initialize.
Returns
The result of the call to de-initialize the Flutter engine.

Definition at line 1356 of file embedder.cc.

References engine, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and flutter::EmbedderEngine::NotifyDestroyed().

Referenced by FlutterEngineGetProcAddresses(), FlutterEngineShutdown(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1357  {
1358  if (engine == nullptr) {
1359  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
1360  }
1361 
1362  auto embedder_engine = reinterpret_cast<flutter::EmbedderEngine*>(engine);
1363  embedder_engine->NotifyDestroyed();
1364  embedder_engine->CollectShell();
1365  return kSuccess;
1366 }
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93

◆ FlutterEngineDispatchSemanticsAction()

FlutterEngineResult FlutterEngineDispatchSemanticsAction ( FLUTTER_API_SYMBOL(FlutterEngine engine,
uint64_t  id,
FlutterSemanticsAction  action,
const uint8_t *  data,
size_t  data_length 
)

Dispatch a semantics action to the specified semantics node.

Parameters
[in]engineA running engine instance.
[in]identifierThe semantics action identifier.
[in]actionThe semantics action.
[in]dataData associated with the action.
[in]data_lengthThe data length.
Returns
The result of the call.

Definition at line 1845 of file embedder.cc.

References action, fml::MallocMapping::Copy(), kInternalInconsistency, kInvalidArguments, kSuccess, and LOG_EMBEDDER_ERROR.

Referenced by FlutterEngineGetProcAddresses(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1850  {
1851  if (engine == nullptr) {
1852  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
1853  }
1854  auto engine_action = static_cast<flutter::SemanticsAction>(action);
1855  if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)
1856  ->DispatchSemanticsAction(
1857  id, engine_action,
1858  fml::MallocMapping::Copy(data, data_length))) {
1860  "Could not dispatch semantics action.");
1861  }
1862  return kSuccess;
1863 }
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
SemanticsAction action
static MallocMapping Copy(const T *begin, const T *end)
Definition: mapping.h:147

◆ FlutterEngineGetCurrentTime()

uint64_t FlutterEngineGetCurrentTime ( )

Get the current time in nanoseconds from the clock used by the flutter engine. This is the system monotonic clock.

Returns
The current time in nanoseconds.

Definition at line 1943 of file embedder.cc.

References fml::TimePoint::Now(), fml::TimePoint::ToEpochDelta(), and fml::TimeDelta::ToNanoseconds().

Referenced by FlutterEngineGetProcAddresses(), flutter::testing::TEST(), and flutter::EventLoop::TimePointFromFlutterTime().

1943  {
1945 }
TimeDelta ToEpochDelta() const
Definition: time_point.h:47
constexpr int64_t ToNanoseconds() const
Definition: time_delta.h:61
static TimePoint Now()
Definition: time_point.cc:39

◆ FlutterEngineGetProcAddresses()

FlutterEngineResult FlutterEngineGetProcAddresses ( FlutterEngineProcTable table)

Gets the table of engine function pointers.

Parameters
[out]tableThe table to fill with pointers. This should be zero-initialized, except for struct_size.
Returns
Returns whether the table was successfully populated.

Definition at line 2282 of file embedder.cc.

Referenced by fl_engine_init(), flutter::FlutterWindowsEngine::FlutterWindowsEngine(), and flutter::testing::TEST().

2283  {
2284  if (!table) {
2285  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Null table specified.");
2286  }
2287 #define SET_PROC(member, function) \
2288  if (STRUCT_HAS_MEMBER(table, member)) { \
2289  table->member = &function; \
2290  }
2291 
2292  SET_PROC(CreateAOTData, FlutterEngineCreateAOTData);
2293  SET_PROC(CollectAOTData, FlutterEngineCollectAOTData);
2294  SET_PROC(Run, FlutterEngineRun);
2295  SET_PROC(Shutdown, FlutterEngineShutdown);
2297  SET_PROC(Deinitialize, FlutterEngineDeinitialize);
2298  SET_PROC(RunInitialized, FlutterEngineRunInitialized);
2299  SET_PROC(SendWindowMetricsEvent, FlutterEngineSendWindowMetricsEvent);
2300  SET_PROC(SendPointerEvent, FlutterEngineSendPointerEvent);
2301  SET_PROC(SendKeyEvent, FlutterEngineSendKeyEvent);
2302  SET_PROC(SendPlatformMessage, FlutterEngineSendPlatformMessage);
2303  SET_PROC(PlatformMessageCreateResponseHandle,
2305  SET_PROC(PlatformMessageReleaseResponseHandle,
2307  SET_PROC(SendPlatformMessageResponse,
2309  SET_PROC(RegisterExternalTexture, FlutterEngineRegisterExternalTexture);
2310  SET_PROC(UnregisterExternalTexture, FlutterEngineUnregisterExternalTexture);
2311  SET_PROC(MarkExternalTextureFrameAvailable,
2313  SET_PROC(UpdateSemanticsEnabled, FlutterEngineUpdateSemanticsEnabled);
2314  SET_PROC(UpdateAccessibilityFeatures,
2317  SET_PROC(OnVsync, FlutterEngineOnVsync);
2318  SET_PROC(ReloadSystemFonts, FlutterEngineReloadSystemFonts);
2319  SET_PROC(TraceEventDurationBegin, FlutterEngineTraceEventDurationBegin);
2320  SET_PROC(TraceEventDurationEnd, FlutterEngineTraceEventDurationEnd);
2321  SET_PROC(TraceEventInstant, FlutterEngineTraceEventInstant);
2322  SET_PROC(PostRenderThreadTask, FlutterEnginePostRenderThreadTask);
2324  SET_PROC(RunTask, FlutterEngineRunTask);
2325  SET_PROC(UpdateLocales, FlutterEngineUpdateLocales);
2326  SET_PROC(RunsAOTCompiledDartCode, FlutterEngineRunsAOTCompiledDartCode);
2327  SET_PROC(PostDartObject, FlutterEnginePostDartObject);
2329  SET_PROC(PostCallbackOnAllNativeThreads,
2331  SET_PROC(NotifyDisplayUpdate, FlutterEngineNotifyDisplayUpdate);
2332 #undef SET_PROC
2333 
2334  return kSuccess;
2335 }
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.
Definition: embedder.cc:2242
static void DispatchSemanticsAction(JNIEnv *env, jobject jcaller, jlong shell_holder, jint id, jint action, jobject args, jint args_position)
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...
Definition: embedder.cc:1356
FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterPlatformMessageResponseHandle *response)
Collects the handle created using FlutterPlatformMessageCreateResponseHandle.
Definition: embedder.cc:1713
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...
Definition: embedder.cc:1947
void FlutterEngineTraceEventDurationEnd(const char *name)
A profiling utility. Logs a trace duration end event to the timeline. If the timeline is unavailable ...
Definition: embedder.cc:1913
FlutterEngineResult FlutterEnginePostRenderThreadTask(FLUTTER_API_SYMBOL(FlutterEngine) engine, VoidCallback callback, void *baton)
Posts a task onto the Flutter render thread. Typically, this may be called from any thread as long as...
Definition: embedder.cc:1921
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.
Definition: embedder.cc:1727
FlutterEngineResult FlutterEngineDispatchSemanticsAction(FLUTTER_API_SYMBOL(FlutterEngine) engine, uint64_t id, FlutterSemanticsAction action, const uint8_t *data, size_t data_length)
Dispatch a semantics action to the specified semantics node.
Definition: embedder.cc:1845
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
FlutterEngineResult FlutterEngineUpdateAccessibilityFeatures(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterAccessibilityFeature flags)
Sets additional accessibility features.
Definition: embedder.cc:1831
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...
Definition: embedder.cc:1368
FlutterEngineResult FlutterEnginePostDartObject(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterEngineDartPort port, const FlutterEngineDartObject *object)
Posts a Dart object to specified send port. The corresponding receive port for send port can be in an...
Definition: embedder.cc:2056
FlutterEngineResult FlutterEngineMarkExternalTextureFrameAvailable(FLUTTER_API_SYMBOL(FlutterEngine) engine, int64_t texture_identifier)
Mark that a new texture frame is available for a given texture identifier.
Definition: embedder.cc:1799
FlutterEngineResult FlutterEngineNotifyLowMemoryWarning(FLUTTER_API_SYMBOL(FlutterEngine) raw_engine)
Posts a low memory notification to a running engine instance. The engine will do its best to release ...
Definition: embedder.cc:2180
void FlutterEngineTraceEventDurationBegin(const char *name)
A profiling utility. Logs a trace duration begin event to the timeline. If the timeline is unavailabl...
Definition: embedder.cc:1909
FlutterEngineResult FlutterEngineReloadSystemFonts(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Reloads the system fonts in engine.
Definition: embedder.cc:1892
void FlutterEngineTraceEventInstant(const char *name)
A profiling utility. Logs a trace duration instant event to the timeline. If the timeline is unavaila...
Definition: embedder.cc:1917
static void NotifyLowMemoryWarning(JNIEnv *env, jobject obj, jlong shell_holder)
FlutterEngineResult FlutterEngineUpdateSemanticsEnabled(FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled)
Enable or disable accessibility semantics.
Definition: embedder.cc:1817
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 ...
Definition: embedder.cc:869
FlutterEngineResult FlutterEngineCollectAOTData(FlutterEngineAOTData data)
Collects the AOT data.
Definition: embedder.cc:802
void Initialize(fidl::InterfaceHandle< fuchsia::sys::Environment > environment, zx::channel directory_request, std::optional< zx::eventpair > view_ref)
Initializes Dart bindings for the Fuchsia application model.
Definition: fuchsia.cc:103
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...
Definition: embedder.cc:1992
#define SET_PROC(member, function)
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...
Definition: embedder.cc:1587
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...
Definition: embedder.cc:1759
FlutterEngineResult FlutterEnginePostCallbackOnAllNativeThreads(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterNativeThreadCallback callback, void *user_data)
Schedule a callback to be run on all engine managed threads. The engine will attempt to service this ...
Definition: embedder.cc:2203
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...
Definition: embedder.cc:885
FlutterEngineResult FlutterEngineUnregisterExternalTexture(FLUTTER_API_SYMBOL(FlutterEngine) engine, int64_t texture_identifier)
Unregister a previous texture registration.
Definition: embedder.cc:1778
#define GetCurrentTime()
FlutterEngineResult FlutterEngineSendPointerEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPointerEvent *pointers, size_t events_count)
Definition: embedder.cc:1501
FlutterEngineResult FlutterEngineSendWindowMetricsEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterWindowMetricsEvent *flutter_metrics)
Definition: embedder.cc:1379
FlutterEngineResult FlutterEngineOnVsync(FLUTTER_API_SYMBOL(FlutterEngine) engine, intptr_t baton, uint64_t frame_start_time_nanos, uint64_t frame_target_time_nanos)
Notify the engine that a vsync event occurred. A baton passed to the platform via the vsync callback ...
Definition: embedder.cc:1865
FlutterEngineResult FlutterEngineRunInitialized(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Runs an initialized engine instance. An engine can be initialized via FlutterEngineInitialize. An initialized instance can only be run once. During and after this call, custom task runners supplied by the embedder are expected to start servicing tasks.
Definition: embedder.cc:1317
bool FlutterEngineRunsAOTCompiledDartCode(void)
Returns if the Flutter engine instance will run AOT compiled Dart code. This call has no threading re...
Definition: embedder.cc:2052
uint64_t FlutterEngineGetCurrentTime()
Get the current time in nanoseconds from the clock used by the flutter engine. This is the system mon...
Definition: embedder.cc:1943
FlutterEngineResult FlutterEngineSendPlatformMessage(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessage *flutter_message)
Definition: embedder.cc:1627
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...
Definition: embedder.cc:1678
FlutterEngineResult FlutterEngineCreateAOTData(const FlutterEngineAOTDataSource *source, FlutterEngineAOTData *data_out)
Creates the necessary data structures to launch a Flutter Dart application in AOT mode...
Definition: embedder.cc:748

◆ FlutterEngineInitialize()

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 FlutterEngineRunInitialized call is made. Besides Flutter application code, no tasks are scheduled on embedder managed task runners either. This allows embedders providing custom task runners to the Flutter engine to obtain a handle to the Flutter engine before the engine can post tasks on these task runners.

Parameters
[in]versionThe Flutter embedder API version. Must be FLUTTER_ENGINE_VERSION.
[in]configThe renderer configuration.
[in]argsThe Flutter project arguments.
user_dataA user data baton passed back to embedders in callbacks.
[out]engine_outThe engine handle on successful engine creation.
Returns
The result of the call to initialize the Flutter engine.

Definition at line 885 of file embedder.cc.

References action, FlutterSemanticsNode::actions, fml::MessageLoop::AddTaskObserver(), flutter::Settings::application_kernel_asset, flutter::Settings::assets_path, FlutterProjectArgs::assets_path, callback, FlutterPlatformMessage::channel, fml::CommandLineFromArgcArgv(), FlutterProjectArgs::compute_platform_resolved_locale_callback, flutter::EmbedderThreadHost::CreateEmbedderOrEngineManagedThreadHost(), FlutterProjectArgs::custom_dart_entrypoint, FlutterProjectArgs::dart_entrypoint_argc, flutter::Settings::dart_entrypoint_args, FlutterProjectArgs::dart_entrypoint_argv, FlutterSemanticsNode::elevation, FlutterMetalRendererConfig::external_texture_frame_callback, FlutterSemanticsNode::flags, FLUTTER_ENGINE_VERSION, FML_LOG, fml::MessageLoop::GetCurrent(), flutter::PersistentCache::gIsReadOnly, FlutterOpenGLRendererConfig::gl_external_texture_frame_callback, height, FlutterSemanticsNode::hint, flutter::Settings::icu_data_path, FlutterSemanticsNode::id, InferExternalViewEmbedderFromArgs(), flutter::RunConfiguration::InferFromSettings(), InferPlatformViewCreationCallback(), fml::IsFile(), IsRendererValid(), flutter::DartVM::IsRunningPrecompiledCode(), fml::paths::JoinPaths(), kApplicationKernelSnapshotFileName, key, kFlutterSemanticsCustomActionIdBatchEnd, kFlutterSemanticsNodeIdBatchEnd, kInternalInconsistency, kInvalidArguments, kInvalidLibraryVersion, kMetal, kOpenGL, kSuccess, FlutterSemanticsNode::label, flutter::Settings::leak_vm, LOG_EMBEDDER_ERROR, flutter::Settings::log_message_callback, flutter::Settings::log_tag, FlutterRendererConfig::metal, node, flutter::Settings::old_gen_heap_size, FlutterRendererConfig::open_gl, FlutterProjectArgs::platform_message_callback, PopulateSnapshotMappingCallbacks(), FlutterSemanticsNode::rect, fml::MessageLoop::RemoveTaskObserver(), result, flutter::Settings::root_isolate_create_callback, SAFE_ACCESS, flutter::PersistentCache::SetCacheDirectoryPath(), flutter::SettingsFromCommandLine(), flutter::Settings::task_observer_add, flutter::Settings::task_observer_remove, texture, FlutterSemanticsNode::thickness, flutter::transform, FlutterSemanticsNode::transform, FlutterRendererConfig::type, FlutterProjectArgs::update_semantics_custom_action_callback, FlutterProjectArgs::update_semantics_node_callback, user_data, value, FlutterSemanticsNode::value, FlutterProjectArgs::vsync_callback, and width.

Referenced by FlutterEngineGetProcAddresses(), FlutterEngineRun(), flutter::testing::EmbedderConfigBuilder::InitializeEngine(), and _FlutterTaskRunner::~_FlutterTaskRunner().

890  {
891  // Step 0: Figure out arguments for shell creation.
892  if (version != FLUTTER_ENGINE_VERSION) {
893  return LOG_EMBEDDER_ERROR(
895  "Flutter embedder version mismatch. There has been a breaking change. "
896  "Please consult the changelog and update the embedder.");
897  }
898 
899  if (engine_out == nullptr) {
901  "The engine out parameter was missing.");
902  }
903 
904  if (args == nullptr) {
906  "The Flutter project arguments were missing.");
907  }
908 
909  if (SAFE_ACCESS(args, assets_path, nullptr) == nullptr) {
910  return LOG_EMBEDDER_ERROR(
912  "The assets path in the Flutter project arguments was missing.");
913  }
914 
915  if (SAFE_ACCESS(args, main_path__unused__, nullptr) != nullptr) {
916  FML_LOG(WARNING)
917  << "FlutterProjectArgs.main_path is deprecated and should be set null.";
918  }
919 
920  if (SAFE_ACCESS(args, packages_path__unused__, nullptr) != nullptr) {
921  FML_LOG(WARNING) << "FlutterProjectArgs.packages_path is deprecated and "
922  "should be set null.";
923  }
924 
925  if (!IsRendererValid(config)) {
927  "The renderer configuration was invalid.");
928  }
929 
930  std::string icu_data_path;
931  if (SAFE_ACCESS(args, icu_data_path, nullptr) != nullptr) {
932  icu_data_path = SAFE_ACCESS(args, icu_data_path, nullptr);
933  }
934 
935  if (SAFE_ACCESS(args, persistent_cache_path, nullptr) != nullptr) {
936  std::string persistent_cache_path =
937  SAFE_ACCESS(args, persistent_cache_path, nullptr);
939  }
940 
941  if (SAFE_ACCESS(args, is_persistent_cache_read_only, false)) {
943  }
944 
945  fml::CommandLine command_line;
946  if (SAFE_ACCESS(args, command_line_argc, 0) != 0 &&
947  SAFE_ACCESS(args, command_line_argv, nullptr) != nullptr) {
948  command_line = fml::CommandLineFromArgcArgv(
949  SAFE_ACCESS(args, command_line_argc, 0),
950  SAFE_ACCESS(args, command_line_argv, nullptr));
951  }
952 
953  flutter::Settings settings = flutter::SettingsFromCommandLine(command_line);
954 
955  if (SAFE_ACCESS(args, aot_data, nullptr)) {
956  if (SAFE_ACCESS(args, vm_snapshot_data, nullptr) ||
957  SAFE_ACCESS(args, vm_snapshot_instructions, nullptr) ||
958  SAFE_ACCESS(args, isolate_snapshot_data, nullptr) ||
959  SAFE_ACCESS(args, isolate_snapshot_instructions, nullptr)) {
960  return LOG_EMBEDDER_ERROR(
962  "Multiple AOT sources specified. Embedders should provide either "
963  "*_snapshot_* buffers or aot_data, not both.");
964  }
965  }
966 
967  PopulateSnapshotMappingCallbacks(args, settings);
968 
969  settings.icu_data_path = icu_data_path;
970  settings.assets_path = args->assets_path;
971  settings.leak_vm = !SAFE_ACCESS(args, shutdown_dart_vm_when_done, false);
972  settings.old_gen_heap_size = SAFE_ACCESS(args, dart_old_gen_heap_size, -1);
973 
975  // Verify the assets path contains Dart 2 kernel assets.
976  const std::string kApplicationKernelSnapshotFileName = "kernel_blob.bin";
977  std::string application_kernel_path = fml::paths::JoinPaths(
978  {settings.assets_path, kApplicationKernelSnapshotFileName});
979  if (!fml::IsFile(application_kernel_path)) {
980  return LOG_EMBEDDER_ERROR(
982  "Not running in AOT mode but could not resolve the kernel binary.");
983  }
985  }
986 
987  settings.task_observer_add = [](intptr_t key, fml::closure callback) {
989  };
990  settings.task_observer_remove = [](intptr_t key) {
992  };
993  if (SAFE_ACCESS(args, root_isolate_create_callback, nullptr) != nullptr) {
995  SAFE_ACCESS(args, root_isolate_create_callback, nullptr);
997  [callback, user_data](const auto& isolate) { callback(user_data); };
998  }
999  if (SAFE_ACCESS(args, log_message_callback, nullptr) != nullptr) {
1001  SAFE_ACCESS(args, log_message_callback, nullptr);
1002  settings.log_message_callback = [callback, user_data](
1003  const std::string& tag,
1004  const std::string& message) {
1005  callback(tag.c_str(), message.c_str(), user_data);
1006  };
1007  }
1008  if (SAFE_ACCESS(args, log_tag, nullptr) != nullptr) {
1009  settings.log_tag = SAFE_ACCESS(args, log_tag, nullptr);
1010  }
1011 
1013  update_semantics_nodes_callback = nullptr;
1014  if (SAFE_ACCESS(args, update_semantics_node_callback, nullptr) != nullptr) {
1015  update_semantics_nodes_callback =
1016  [ptr = args->update_semantics_node_callback,
1018  for (const auto& value : update) {
1019  const auto& node = value.second;
1020  SkMatrix transform = node.transform.asM33();
1021  FlutterTransformation flutter_transform{
1022  transform.get(SkMatrix::kMScaleX),
1023  transform.get(SkMatrix::kMSkewX),
1024  transform.get(SkMatrix::kMTransX),
1025  transform.get(SkMatrix::kMSkewY),
1026  transform.get(SkMatrix::kMScaleY),
1027  transform.get(SkMatrix::kMTransY),
1028  transform.get(SkMatrix::kMPersp0),
1029  transform.get(SkMatrix::kMPersp1),
1030  transform.get(SkMatrix::kMPersp2)};
1031  const FlutterSemanticsNode embedder_node{
1032  sizeof(FlutterSemanticsNode),
1033  node.id,
1034  static_cast<FlutterSemanticsFlag>(node.flags),
1035  static_cast<FlutterSemanticsAction>(node.actions),
1036  node.textSelectionBase,
1037  node.textSelectionExtent,
1038  node.scrollChildren,
1039  node.scrollIndex,
1040  node.scrollPosition,
1041  node.scrollExtentMax,
1042  node.scrollExtentMin,
1043  node.elevation,
1044  node.thickness,
1045  node.label.c_str(),
1046  node.hint.c_str(),
1047  node.value.c_str(),
1048  node.increasedValue.c_str(),
1049  node.decreasedValue.c_str(),
1050  static_cast<FlutterTextDirection>(node.textDirection),
1051  FlutterRect{node.rect.fLeft, node.rect.fTop, node.rect.fRight,
1052  node.rect.fBottom},
1053  flutter_transform,
1054  node.childrenInTraversalOrder.size(),
1055  &node.childrenInTraversalOrder[0],
1056  &node.childrenInHitTestOrder[0],
1057  node.customAccessibilityActions.size(),
1058  &node.customAccessibilityActions[0],
1059  node.platformViewId,
1060  };
1061  ptr(&embedder_node, user_data);
1062  }
1063  const FlutterSemanticsNode batch_end_sentinel = {
1064  sizeof(FlutterSemanticsNode),
1066  };
1067  ptr(&batch_end_sentinel, user_data);
1068  };
1069  }
1070 
1072  update_semantics_custom_actions_callback = nullptr;
1073  if (SAFE_ACCESS(args, update_semantics_custom_action_callback, nullptr) !=
1074  nullptr) {
1075  update_semantics_custom_actions_callback =
1078  for (const auto& value : actions) {
1079  const auto& action = value.second;
1080  const FlutterSemanticsCustomAction embedder_action = {
1082  action.id,
1083  static_cast<FlutterSemanticsAction>(action.overrideId),
1084  action.label.c_str(),
1085  action.hint.c_str(),
1086  };
1087  ptr(&embedder_action, user_data);
1088  }
1089  const FlutterSemanticsCustomAction batch_end_sentinel = {
1092  };
1093  ptr(&batch_end_sentinel, user_data);
1094  };
1095  }
1096 
1098  platform_message_response_callback = nullptr;
1099  if (SAFE_ACCESS(args, platform_message_callback, nullptr) != nullptr) {
1100  platform_message_response_callback =
1101  [ptr = args->platform_message_callback,
1102  user_data](std::unique_ptr<flutter::PlatformMessage> message) {
1103  auto handle = new FlutterPlatformMessageResponseHandle();
1104  const FlutterPlatformMessage incoming_message = {
1105  sizeof(FlutterPlatformMessage), // struct_size
1106  message->channel().c_str(), // channel
1107  message->data().GetMapping(), // message
1108  message->data().GetSize(), // message_size
1109  handle, // response_handle
1110  };
1111  handle->message = std::move(message);
1112  return ptr(&incoming_message, user_data);
1113  };
1114  }
1115 
1116  flutter::VsyncWaiterEmbedder::VsyncCallback vsync_callback = nullptr;
1117  if (SAFE_ACCESS(args, vsync_callback, nullptr) != nullptr) {
1118  vsync_callback = [ptr = args->vsync_callback, user_data](intptr_t baton) {
1119  return ptr(user_data, baton);
1120  };
1121  }
1122 
1124  compute_platform_resolved_locale_callback = nullptr;
1125  if (SAFE_ACCESS(args, compute_platform_resolved_locale_callback, nullptr) !=
1126  nullptr) {
1127  compute_platform_resolved_locale_callback =
1129  const std::vector<std::string>& supported_locales_data) {
1130  const size_t number_of_strings_per_locale = 3;
1131  size_t locale_count =
1132  supported_locales_data.size() / number_of_strings_per_locale;
1133  std::vector<FlutterLocale> supported_locales;
1134  std::vector<const FlutterLocale*> supported_locales_ptr;
1135  for (size_t i = 0; i < locale_count; ++i) {
1136  supported_locales.push_back(
1137  {.struct_size = sizeof(FlutterLocale),
1138  .language_code =
1139  supported_locales_data[i * number_of_strings_per_locale +
1140  0]
1141  .c_str(),
1142  .country_code =
1143  supported_locales_data[i * number_of_strings_per_locale +
1144  1]
1145  .c_str(),
1146  .script_code =
1147  supported_locales_data[i * number_of_strings_per_locale +
1148  2]
1149  .c_str(),
1150  .variant_code = nullptr});
1151  supported_locales_ptr.push_back(&supported_locales[i]);
1152  }
1153 
1154  const FlutterLocale* result =
1155  ptr(supported_locales_ptr.data(), locale_count);
1156 
1157  std::unique_ptr<std::vector<std::string>> out =
1158  std::make_unique<std::vector<std::string>>();
1159  if (result) {
1160  std::string language_code(SAFE_ACCESS(result, language_code, ""));
1161  if (language_code != "") {
1162  out->push_back(language_code);
1163  out->emplace_back(SAFE_ACCESS(result, country_code, ""));
1164  out->emplace_back(SAFE_ACCESS(result, script_code, ""));
1165  }
1166  }
1167  return out;
1168  };
1169  }
1170 
1171  auto external_view_embedder_result =
1172  InferExternalViewEmbedderFromArgs(SAFE_ACCESS(args, compositor, nullptr));
1173  if (external_view_embedder_result.second) {
1175  "Compositor arguments were invalid.");
1176  }
1177 
1179  {
1180  update_semantics_nodes_callback, //
1181  update_semantics_custom_actions_callback, //
1182  platform_message_response_callback, //
1183  vsync_callback, //
1184  compute_platform_resolved_locale_callback, //
1185  };
1186 
1187  auto on_create_platform_view = InferPlatformViewCreationCallback(
1188  config, user_data, platform_dispatch_table,
1189  std::move(external_view_embedder_result.first));
1190 
1191  if (!on_create_platform_view) {
1192  return LOG_EMBEDDER_ERROR(
1194  "Could not infer platform view creation callback.");
1195  }
1196 
1198  [](flutter::Shell& shell) {
1199  return std::make_unique<flutter::Rasterizer>(shell);
1200  };
1201 
1202  using ExternalTextureResolver = flutter::EmbedderExternalTextureResolver;
1203  std::unique_ptr<ExternalTextureResolver> external_texture_resolver;
1204  external_texture_resolver = std::make_unique<ExternalTextureResolver>();
1205 
1206 #ifdef SHELL_ENABLE_GL
1208  external_texture_callback;
1209  if (config->type == kOpenGL) {
1210  const FlutterOpenGLRendererConfig* open_gl_config = &config->open_gl;
1211  if (SAFE_ACCESS(open_gl_config, gl_external_texture_frame_callback,
1212  nullptr) != nullptr) {
1213  external_texture_callback =
1214  [ptr = open_gl_config->gl_external_texture_frame_callback, user_data](
1215  int64_t texture_identifier, size_t width,
1216  size_t height) -> std::unique_ptr<FlutterOpenGLTexture> {
1217  std::unique_ptr<FlutterOpenGLTexture> texture =
1218  std::make_unique<FlutterOpenGLTexture>();
1219  if (!ptr(user_data, texture_identifier, width, height, texture.get())) {
1220  return nullptr;
1221  }
1222  return texture;
1223  };
1224  external_texture_resolver =
1225  std::make_unique<ExternalTextureResolver>(external_texture_callback);
1226  }
1227  }
1228 #endif
1229 #ifdef SHELL_ENABLE_METAL
1231  external_texture_metal_callback;
1232  if (config->type == kMetal) {
1233  const FlutterMetalRendererConfig* metal_config = &config->metal;
1234  if (SAFE_ACCESS(metal_config, external_texture_frame_callback, nullptr)) {
1235  external_texture_metal_callback =
1236  [ptr = metal_config->external_texture_frame_callback, user_data](
1237  int64_t texture_identifier, size_t width,
1238  size_t height) -> std::unique_ptr<FlutterMetalExternalTexture> {
1239  std::unique_ptr<FlutterMetalExternalTexture> texture =
1240  std::make_unique<FlutterMetalExternalTexture>();
1241  texture->struct_size = sizeof(FlutterMetalExternalTexture);
1242  if (!ptr(user_data, texture_identifier, width, height, texture.get())) {
1243  return nullptr;
1244  }
1245  return texture;
1246  };
1247  external_texture_resolver = std::make_unique<ExternalTextureResolver>(
1248  external_texture_metal_callback);
1249  }
1250  }
1251 #endif
1252 
1253  auto thread_host =
1255  SAFE_ACCESS(args, custom_task_runners, nullptr));
1256 
1257  if (!thread_host || !thread_host->IsValid()) {
1259  "Could not set up or infer thread configuration "
1260  "to run the Flutter engine on.");
1261  }
1262 
1263  auto task_runners = thread_host->GetTaskRunners();
1264 
1265  if (!task_runners.IsValid()) {
1267  "Task runner configuration was invalid.");
1268  }
1269 
1270  auto run_configuration =
1272 
1273  if (SAFE_ACCESS(args, custom_dart_entrypoint, nullptr) != nullptr) {
1274  auto dart_entrypoint = std::string{args->custom_dart_entrypoint};
1275  if (dart_entrypoint.size() != 0) {
1276  run_configuration.SetEntrypoint(std::move(dart_entrypoint));
1277  }
1278  }
1279 
1280  if (SAFE_ACCESS(args, dart_entrypoint_argc, 0) > 0) {
1281  if (SAFE_ACCESS(args, dart_entrypoint_argv, nullptr) == nullptr) {
1283  "Could not determine Dart entrypoint arguments "
1284  "as dart_entrypoint_argc "
1285  "was set, but dart_entrypoint_argv was null.");
1286  }
1287  std::vector<std::string> arguments(args->dart_entrypoint_argc);
1288  for (int i = 0; i < args->dart_entrypoint_argc; ++i) {
1289  arguments[i] = std::string{args->dart_entrypoint_argv[i]};
1290  }
1291  settings.dart_entrypoint_args = std::move(arguments);
1292  }
1293 
1294  if (!run_configuration.IsValid()) {
1295  return LOG_EMBEDDER_ERROR(
1297  "Could not infer the Flutter project to run from given arguments.");
1298  }
1299 
1300  // Create the engine but don't launch the shell or run the root isolate.
1301  auto embedder_engine = std::make_unique<flutter::EmbedderEngine>(
1302  std::move(thread_host), //
1303  std::move(task_runners), //
1304  std::move(settings), //
1305  std::move(run_configuration), //
1306  on_create_platform_view, //
1307  on_create_rasterizer, //
1308  std::move(external_texture_resolver) //
1309  );
1310 
1311  // Release the ownership of the embedder engine to the caller.
1312  *engine_out = reinterpret_cast<FLUTTER_API_SYMBOL(FlutterEngine)>(
1313  embedder_engine.release());
1314  return kSuccess;
1315 }
std::function< std::unique_ptr< FlutterMetalExternalTexture >(int64_t, size_t, size_t)> ExternalTextureCallback
const char * channel
Definition: embedder.h:757
struct _FlutterEngine * FLUTTER_API_SYMBOL(FlutterEngine)
Definition: embedder.h:228
LogMessageCallback log_message_callback
Definition: settings.h:243
G_BEGIN_DECLS FlTexture * texture
std::function< std::unique_ptr< T >(Shell &)> CreateCallback
Definition: shell.h:114
FlutterComputePlatformResolvedLocaleCallback compute_platform_resolved_locale_callback
Definition: embedder.h:1552
FlutterMetalTextureFrameCallback external_texture_frame_callback
Definition: embedder.h:540
std::vector< std::string > dart_entrypoint_args
Definition: settings.h:126
std::function< void(const DartIsolate &)> root_isolate_create_callback
Definition: settings.h:212
std::string application_kernel_asset
Definition: settings.h:119
void AddTaskObserver(intptr_t key, const fml::closure &callback)
Definition: message_loop.cc:64
CommandLine CommandLineFromArgcArgv(int argc, const char *const *argv)
Definition: command_line.h:222
FlutterRect rect
The bounding box for this node in its coordinate system.
Definition: embedder.h:838
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
int64_t old_gen_heap_size
Definition: settings.h:279
void(* FlutterLogMessageCallback)(const char *, const char *, void *)
Definition: embedder.h:1339
void * user_data
static bool IsRendererValid(const FlutterRendererConfig *config)
Definition: embedder.cc:147
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
GAsyncResult * result
Settings SettingsFromCommandLine(const fml::CommandLine &command_line)
Definition: switches.cc:228
#define FML_LOG(severity)
Definition: logging.h:65
FlutterPlatformMessageCallback platform_message_callback
Definition: embedder.h:1400
A structure to represent a rectangle.
Definition: embedder.h:332
FlKeyEvent FlKeyResponderAsyncCallback callback
static const char * kApplicationKernelSnapshotFileName
#define SAFE_ACCESS(pointer, member, default_value)
FlutterSemanticsAction
Definition: embedder.h:101
const char *const * dart_entrypoint_argv
Definition: embedder.h:1564
VsyncCallback vsync_callback
Definition: embedder.h:1477
std::function< void()> closure
Definition: closure.h:14
std::string JoinPaths(std::initializer_list< std::string > components)
Definition: paths.cc:14
FlutterSemanticsFlag flags
The set of semantics flags associated with this node.
Definition: embedder.h:799
static RunConfiguration InferFromSettings(const Settings &settings, fml::RefPtr< fml::TaskRunner > io_worker=nullptr)
Attempts to infer a run configuration from the settings object. This tries to create a run configurat...
#define FLUTTER_ENGINE_VERSION
Definition: embedder.h:63
FlutterRendererType type
Definition: embedder.h:554
uint8_t value
static void SetCacheDirectoryPath(std::string path)
double thickness
Describes how much space the semantics node takes up along the z-axis.
Definition: embedder.h:821
const FlutterSemanticsNode * node
Definition: fl_view.cc:78
FlutterUpdateSemanticsNodeCallback update_semantics_node_callback
Definition: embedder.h:1444
std::function< void(flutter::CustomAccessibilityActionUpdates actions)> UpdateSemanticsCustomActionsCallback
SemanticsAction action
int32_t id
The unique identifier for this node.
Definition: embedder.h:797
FlutterUpdateSemanticsCustomActionCallback update_semantics_custom_action_callback
Definition: embedder.h:1455
FlutterTransformation transform
Definition: embedder.h:841
static bool IsRunningPrecompiledCode()
Checks if VM instances in the process can run precompiled code. This call can be made at any time and...
Definition: dart_vm.cc:205
TextureFrameCallback gl_external_texture_frame_callback
Definition: embedder.h:428
const char * hint
A brief description of the result of performing an action on the node.
Definition: embedder.h:825
int32_t width
static std::pair< std::unique_ptr< flutter::EmbedderExternalViewEmbedder >, bool > InferExternalViewEmbedderFromArgs(const FlutterCompositor *compositor)
Definition: embedder.cc:682
TaskObserverAdd task_observer_add
Definition: settings.h:208
void PopulateSnapshotMappingCallbacks(const FlutterProjectArgs *args, flutter::Settings &settings)
Definition: embedder.cc:813
static std::unique_ptr< EmbedderThreadHost > CreateEmbedderOrEngineManagedThreadHost(const FlutterCustomTaskRunners *custom_task_runners)
std::string icu_data_path
Definition: settings.h:254
int32_t height
const char * custom_dart_entrypoint
Definition: embedder.h:1486
const char * assets_path
Definition: embedder.h:1353
FlutterOpenGLRendererConfig open_gl
Definition: embedder.h:556
std::function< void(std::unique_ptr< PlatformMessage >)> PlatformMessageResponseCallback
const int32_t kFlutterSemanticsNodeIdBatchEnd
Definition: embedder.cc:69
const char * value
A textual description of the current value of the node.
Definition: embedder.h:827
bool IsFile(const std::string &path)
Definition: file_posix.cc:145
std::function< void(flutter::SemanticsNodeUpdates update)> UpdateSemanticsNodesCallback
const char * label
A textual description of the node.
Definition: embedder.h:823
void RemoveTaskObserver(intptr_t key)
Definition: message_loop.cc:68
std::function< void(intptr_t)> VsyncCallback
FlutterSemanticsAction actions
The set of semantics actions applicable to this node.
Definition: embedder.h:801
void(* VoidCallback)(void *)
Definition: embedder.h:251
struct _FlutterPlatformMessageResponseHandle FlutterPlatformMessageResponseHandle
Definition: embedder.h:751
FlutterMetalRendererConfig metal
Definition: embedder.h:558
std::function< std::unique_ptr< FlutterOpenGLTexture >(int64_t, size_t, size_t)> ExternalTextureCallback
FlutterTextDirection
Definition: embedder.h:219
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
TaskObserverRemove task_observer_remove
Definition: settings.h:209
std::string assets_path
Definition: settings.h:260
std::string log_tag
Definition: settings.h:247
const int32_t kFlutterSemanticsCustomActionIdBatchEnd
Definition: embedder.cc:70
static flutter::Shell::CreateCallback< flutter::PlatformView > InferPlatformViewCreationCallback(const FlutterRendererConfig *config, void *user_data, flutter::PlatformViewEmbedder::PlatformDispatchTable platform_dispatch_table, std::unique_ptr< flutter::EmbedderExternalViewEmbedder > external_view_embedder)
Definition: embedder.cc:409
std::function< std::unique_ptr< std::vector< std::string > >(const std::vector< std::string > &supported_locale_data)> ComputePlatformResolvedLocaleCallback

◆ FlutterEngineMarkExternalTextureFrameAvailable()

FlutterEngineResult FlutterEngineMarkExternalTextureFrameAvailable ( FLUTTER_API_SYMBOL(FlutterEngine engine,
int64_t  texture_identifier 
)

Mark that a new texture frame is available for a given texture identifier.

See also
FlutterEngineRegisterExternalTexture()
FlutterEngineUnregisterExternalTexture()
Parameters
[in]engineA running engine instance.
[in]texture_identifierThe identifier of the texture whose frame has been updated.
Returns
The result of the call.

Definition at line 1799 of file embedder.cc.

References kInternalInconsistency, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and flutter::MarkTextureFrameAvailable().

Referenced by FlutterEngineGetProcAddresses(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1801  {
1802  if (engine == nullptr) {
1803  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
1804  }
1805  if (texture_identifier == 0) {
1806  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid texture identifier.");
1807  }
1808  if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)
1809  ->MarkTextureFrameAvailable(texture_identifier)) {
1810  return LOG_EMBEDDER_ERROR(
1812  "Could not mark the texture frame as being available.");
1813  }
1814  return kSuccess;
1815 }
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
static void MarkTextureFrameAvailable(JNIEnv *env, jobject jcaller, jlong shell_holder, jlong texture_id)

◆ FlutterEngineNotifyDisplayUpdate()

FlutterEngineResult FlutterEngineNotifyDisplayUpdate ( FLUTTER_API_SYMBOL(FlutterEngine engine,
FlutterEngineDisplaysUpdateType  update_type,
const FlutterEngineDisplay displays,
size_t  display_count 
)

Posts updates corresponding to display changes to a running engine instance.

Parameters
[in]update_typeThe type of update pushed to the engine.
[in]displaysThe displays affected by this update.
[in]display_countSize of the displays array, must be at least 1.
Returns
the result of the call made to the engine.

Definition at line 2242 of file embedder.cc.

References engine, kFlutterEngineDisplaysUpdateTypeStartup, kInvalidArguments, flutter::kStartup, kSuccess, and LOG_EMBEDDER_ERROR.

Referenced by FlutterEngineGetProcAddresses(), and flutter::testing::TEST_F().

2246  {
2247  if (raw_engine == nullptr) {
2248  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
2249  }
2250 
2251  if (!ValidDisplayConfiguration(embedder_displays, display_count)) {
2252  return LOG_EMBEDDER_ERROR(
2254  "Invalid FlutterEngineDisplay configuration specified.");
2255  }
2256 
2257  auto engine = reinterpret_cast<flutter::EmbedderEngine*>(raw_engine);
2258 
2259  switch (update_type) {
2261  std::vector<flutter::Display> displays;
2262  for (size_t i = 0; i < display_count; i++) {
2263  flutter::Display display =
2264  flutter::Display(embedder_displays[i].refresh_rate);
2265  if (!embedder_displays[i].single_display) {
2266  display = flutter::Display(embedder_displays[i].display_id,
2267  embedder_displays[i].refresh_rate);
2268  }
2269  displays.push_back(display);
2270  }
2271  engine->GetShell().OnDisplayUpdates(flutter::DisplayUpdateType::kStartup,
2272  displays);
2273  return kSuccess;
2274  }
2275  default:
2276  return LOG_EMBEDDER_ERROR(
2278  "Invalid FlutterEngineDisplaysUpdateType type specified.");
2279  }
2280 }
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93

◆ FlutterEngineNotifyLowMemoryWarning()

FlutterEngineResult FlutterEngineNotifyLowMemoryWarning ( FLUTTER_API_SYMBOL(FlutterEngine engine)

Posts a low memory notification to a running engine instance. The engine will do its best to release non-critical resources in response. It is not guaranteed that the resource would have been collected by the time this call returns however. The notification is posted to engine subsystems that may be operating on other threads.

Flutter applications can respond to these notifications by setting WidgetsBindingObserver.didHaveMemoryPressure observers.

Parameters
[in]engineA running engine instance.
Returns
If the low memory notification was sent to the running engine instance.

Definition at line 2180 of file embedder.cc.

References DispatchJSONPlatformMessage(), engine, kInternalInconsistency, kInvalidArguments, kSuccess, and LOG_EMBEDDER_ERROR.

Referenced by FlutterEngineGetProcAddresses(), and flutter::testing::TEST_F().

2181  {
2182  auto engine = reinterpret_cast<flutter::EmbedderEngine*>(raw_engine);
2183  if (engine == nullptr || !engine->IsValid()) {
2184  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine was invalid.");
2185  }
2186 
2187  engine->GetShell().NotifyLowMemoryWarning();
2188 
2189  rapidjson::Document document;
2190  auto& allocator = document.GetAllocator();
2191 
2192  document.SetObject();
2193  document.AddMember("type", "memoryPressure", allocator);
2194 
2195  return DispatchJSONPlatformMessage(raw_engine, std::move(document),
2196  "flutter/system")
2197  ? kSuccess
2200  "Could not dispatch the low memory notification message.");
2201 }
static bool DispatchJSONPlatformMessage(FLUTTER_API_SYMBOL(FlutterEngine) engine, rapidjson::Document document, const std::string &channel_name)
Definition: embedder.cc:1960
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93

◆ FlutterEngineOnVsync()

FlutterEngineResult FlutterEngineOnVsync ( FLUTTER_API_SYMBOL(FlutterEngine engine,
intptr_t  baton,
uint64_t  frame_start_time_nanos,
uint64_t  frame_target_time_nanos 
)

Notify the engine that a vsync event occurred. A baton passed to the platform via the vsync callback must be returned. This call must be made on the thread on which the call to FlutterEngineRun was made.

See also
FlutterEngineGetCurrentTime()
Attention
That frame timepoints are in nanoseconds.
The system monotonic clock is used as the timebase.
Parameters
[in]engine.A running engine instance.
[in]batonThe baton supplied by the engine.
[in]frame_start_time_nanosThe point at which the vsync event occurred or will occur. If the time point is in the future, the engine will wait till that point to begin its frame workload.
[in]frame_target_time_nanosThe point at which the embedder anticipates the next vsync to occur. This is a hint the engine uses to schedule Dart VM garbage collection in periods in which the various threads are most likely to be idle. For example, for a 60Hz display, embedders should add 16.6 * 1e6 to the frame time field.
Returns
The result of the call.

Definition at line 1865 of file embedder.cc.

References fml::TimePoint::FromEpochDelta(), fml::TimeDelta::FromNanoseconds(), kInternalInconsistency, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and TRACE_EVENT0.

Referenced by FlutterEngineGetProcAddresses().

1869  {
1870  if (engine == nullptr) {
1871  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
1872  }
1873 
1874  TRACE_EVENT0("flutter", "FlutterEngineOnVsync");
1875 
1876  auto start_time = fml::TimePoint::FromEpochDelta(
1877  fml::TimeDelta::FromNanoseconds(frame_start_time_nanos));
1878 
1879  auto target_time = fml::TimePoint::FromEpochDelta(
1880  fml::TimeDelta::FromNanoseconds(frame_target_time_nanos));
1881 
1882  if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->OnVsyncEvent(
1883  baton, start_time, target_time)) {
1884  return LOG_EMBEDDER_ERROR(
1886  "Could not notify the running engine instance of a Vsync event.");
1887  }
1888 
1889  return kSuccess;
1890 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
static constexpr TimeDelta FromNanoseconds(int64_t nanos)
Definition: time_delta.h:40
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
static constexpr TimePoint FromEpochDelta(TimeDelta ticks)
Definition: time_point.h:38

◆ FlutterEnginePostCallbackOnAllNativeThreads()

FlutterEngineResult FlutterEnginePostCallbackOnAllNativeThreads ( FLUTTER_API_SYMBOL(FlutterEngine engine,
FlutterNativeThreadCallback  callback,
void *  user_data 
)

Schedule a callback to be run on all engine managed threads. The engine will attempt to service this callback the next time the message loop for each managed thread is idle. Since the engine manages the entire lifecycle of multiple threads, there is no opportunity for the embedders to finely tune the priorities of threads directly, or, perform other thread specific configuration (for example, setting thread names for tracing). This callback gives embedders a chance to affect such tuning.

Attention
This call is expensive and must be made as few times as possible. The callback must also return immediately as not doing so may risk performance issues (especially for callbacks of type kFlutterNativeThreadTypeUI and kFlutterNativeThreadTypeRender).
Some callbacks (especially the ones of type kFlutterNativeThreadTypeWorker) may be called after the FlutterEngine instance has shut down. Embedders must be careful in handling the lifecycle of objects associated with the user data baton.
In case there are multiple running Flutter engine instances, their workers are shared.
Parameters
[in]engineA running engine instance.
[in]callbackThe callback that will get called multiple times on each engine managed thread.
[in]user_dataA baton passed by the engine to the callback. This baton is not interpreted by the engine in any way.
Returns
Returns if the callback was successfully posted to all threads.

Definition at line 2203 of file embedder.cc.

References callback, engine, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and type.

Referenced by FlutterEngineGetProcAddresses(), and flutter::testing::TEST_F().

2206  {
2207  if (engine == nullptr) {
2208  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
2209  }
2210 
2211  if (callback == nullptr) {
2213  "Invalid native thread callback.");
2214  }
2215 
2216  return reinterpret_cast<flutter::EmbedderEngine*>(engine)
2217  ->PostTaskOnEngineManagedNativeThreads(
2219  callback(type, user_data);
2220  })
2221  ? kSuccess
2223  "Internal error while attempting to post "
2224  "tasks to all threads.");
2225 }
KeyCallType type
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
void * user_data
FlKeyEvent FlKeyResponderAsyncCallback callback
FlutterNativeThreadType
Definition: embedder.h:1295

◆ FlutterEnginePostDartObject()

FlutterEngineResult FlutterEnginePostDartObject ( FLUTTER_API_SYMBOL(FlutterEngine engine,
FlutterEngineDartPort  port,
const FlutterEngineDartObject object 
)

Posts a Dart object to specified send port. The corresponding receive port for send port can be in any isolate running in the VM. This isolate can also be the root isolate for an unrelated engine. The engine parameter is necessary only to ensure the call is not made when no engine (and hence no VM) is running.

Unlike the platform messages mechanism, there are no threading restrictions when using this API. Message can be posted on any thread and they will be made available to isolate on which the corresponding send port is listening.

However, it is the embedders responsibility to ensure that the call is not made during an ongoing call the FlutterEngineDeinitialize or FlutterEngineShutdown on another thread.

Parameters
[in]engineA running engine instance.
[in]portThe send port to send the object to.
[in]objectThe object to send to the isolate with the corresponding receive port.
Returns
If the message was posted to the send port.

Definition at line 2056 of file embedder.cc.

References buffer, FlutterEngineDartObject::buffer_value, callback, flutter::IsValid(), kFlutterEngineDartObjectTypeBool, kFlutterEngineDartObjectTypeBuffer, kFlutterEngineDartObjectTypeDouble, kFlutterEngineDartObjectTypeInt32, kFlutterEngineDartObjectTypeInt64, kFlutterEngineDartObjectTypeNull, kFlutterEngineDartObjectTypeString, kInternalInconsistency, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, fml::ScopedCleanupClosure::Release(), SAFE_ACCESS, fml::ScopedCleanupClosure::SetClosure(), FlutterEngineDartObject::string_value, FlutterEngineDartObject::type, and user_data.

Referenced by FlutterEngineGetProcAddresses(), and flutter::testing::TEST_F().

2059  {
2060  if (engine == nullptr) {
2061  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
2062  }
2063 
2064  if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->IsValid()) {
2065  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine not running.");
2066  }
2067 
2068  if (port == ILLEGAL_PORT) {
2070  "Attempted to post to an illegal port.");
2071  }
2072 
2073  if (object == nullptr) {
2075  "Invalid Dart object to post.");
2076  }
2077 
2078  Dart_CObject dart_object = {};
2079  fml::ScopedCleanupClosure typed_data_finalizer;
2080 
2081  switch (object->type) {
2083  dart_object.type = Dart_CObject_kNull;
2084  break;
2086  dart_object.type = Dart_CObject_kBool;
2087  dart_object.value.as_bool = object->bool_value;
2088  break;
2090  dart_object.type = Dart_CObject_kInt32;
2091  dart_object.value.as_int32 = object->int32_value;
2092  break;
2094  dart_object.type = Dart_CObject_kInt64;
2095  dart_object.value.as_int64 = object->int64_value;
2096  break;
2098  dart_object.type = Dart_CObject_kDouble;
2099  dart_object.value.as_double = object->double_value;
2100  break;
2102  if (object->string_value == nullptr) {
2104  "kFlutterEngineDartObjectTypeString must be "
2105  "a null terminated string but was null.");
2106  }
2107  dart_object.type = Dart_CObject_kString;
2108  dart_object.value.as_string = const_cast<char*>(object->string_value);
2109  break;
2111  auto* buffer = SAFE_ACCESS(object->buffer_value, buffer, nullptr);
2112  if (buffer == nullptr) {
2114  "kFlutterEngineDartObjectTypeBuffer must "
2115  "specify a buffer but found nullptr.");
2116  }
2117  auto buffer_size = SAFE_ACCESS(object->buffer_value, buffer_size, 0);
2118  auto callback =
2119  SAFE_ACCESS(object->buffer_value, buffer_collect_callback, nullptr);
2120  auto user_data = SAFE_ACCESS(object->buffer_value, user_data, nullptr);
2121 
2122  // The user has provided a callback, let them manage the lifecycle of
2123  // the underlying data. If not, copy it out from the provided buffer.
2124 
2125  if (callback == nullptr) {
2126  dart_object.type = Dart_CObject_kTypedData;
2127  dart_object.value.as_typed_data.type = Dart_TypedData_kUint8;
2128  dart_object.value.as_typed_data.length = buffer_size;
2129  dart_object.value.as_typed_data.values = buffer;
2130  } else {
2131  struct ExternalTypedDataPeer {
2132  void* user_data = nullptr;
2133  VoidCallback trampoline = nullptr;
2134  };
2135  auto peer = new ExternalTypedDataPeer();
2136  peer->user_data = user_data;
2137  peer->trampoline = callback;
2138  // This finalizer is set so that in case of failure of the
2139  // Dart_PostCObject below, we collect the peer. The embedder is still
2140  // responsible for collecting the buffer in case of non-kSuccess
2141  // returns from this method. This finalizer must be released in case
2142  // of kSuccess returns from this method.
2143  typed_data_finalizer.SetClosure([peer]() {
2144  // This is the tiny object we use as the peer to the Dart call so
2145  // that we can attach the a trampoline to the embedder supplied
2146  // callback. In case of error, we need to collect this object lest
2147  // we introduce a tiny leak.
2148  delete peer;
2149  });
2150  dart_object.type = Dart_CObject_kExternalTypedData;
2151  dart_object.value.as_external_typed_data.type = Dart_TypedData_kUint8;
2152  dart_object.value.as_external_typed_data.length = buffer_size;
2153  dart_object.value.as_external_typed_data.data = buffer;
2154  dart_object.value.as_external_typed_data.peer = peer;
2155  dart_object.value.as_external_typed_data.callback =
2156  +[](void* unused_isolate_callback_data, void* peer) {
2157  auto typed_peer = reinterpret_cast<ExternalTypedDataPeer*>(peer);
2158  typed_peer->trampoline(typed_peer->user_data);
2159  delete typed_peer;
2160  };
2161  }
2162  } break;
2163  default:
2164  return LOG_EMBEDDER_ERROR(
2166  "Invalid FlutterEngineDartObjectType type specified.");
2167  }
2168 
2169  if (!Dart_PostCObject(port, &dart_object)) {
2171  "Could not post the object to the Dart VM.");
2172  }
2173 
2174  // On a successful call, the VM takes ownership of and is responsible for
2175  // invoking the finalizer.
2176  typed_data_finalizer.Release();
2177  return kSuccess;
2178 }
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
void * user_data
DEF_SWITCHES_START snapshot asset Path to the directory containing the four files specified by VmSnapshotInstructions and IsolateSnapshotInstructions vm snapshot The VM instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present isolate snapshot The isolate instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present icu symbol Prefix for the symbols representing ICU data linked into the Flutter library dart Flags passed directly to the Dart VM without being interpreted by the Flutter shell observatory port
Definition: switches.h:75
FlKeyEvent FlKeyResponderAsyncCallback callback
#define SAFE_ACCESS(pointer, member, default_value)
const char * string_value
Definition: embedder.h:1287
Wraps a closure that is invoked in the destructor unless released by the caller.
Definition: closure.h:32
static bool IsValid(double value)
fml::closure SetClosure(const fml::closure &closure)
Definition: closure.h:44
fml::closure Release()
Definition: closure.h:50
static const uint8_t buffer[]
void(* VoidCallback)(void *)
Definition: embedder.h:251
const FlutterEngineDartBuffer * buffer_value
Definition: embedder.h:1288
FlutterEngineDartObjectType type
Definition: embedder.h:1278

◆ FlutterEnginePostRenderThreadTask()

FlutterEngineResult FlutterEnginePostRenderThreadTask ( FLUTTER_API_SYMBOL(FlutterEngine engine,
VoidCallback  callback,
void *  callback_data 
)

Posts a task onto the Flutter render thread. Typically, this may be called from any thread as long as a FlutterEngineShutdown on the specific engine has not already been initiated.

Parameters
[in]engineA running engine instance.
[in]callbackThe callback to execute on the render thread.
callback_dataThe callback context.
Returns
The result of the call.

Definition at line 1921 of file embedder.cc.

References callback, engine, kInternalInconsistency, kInvalidArguments, kSuccess, and LOG_EMBEDDER_ERROR.

Referenced by FlutterEngineGetProcAddresses().

1924  {
1925  if (engine == nullptr) {
1926  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
1927  }
1928 
1929  if (callback == nullptr) {
1931  "Render thread callback was null.");
1932  }
1933 
1934  auto task = [callback, baton]() { callback(baton); };
1935 
1936  return reinterpret_cast<flutter::EmbedderEngine*>(engine)
1937  ->PostRenderThreadTask(task)
1938  ? kSuccess
1940  "Could not post the render thread task.");
1941 }
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
FlKeyEvent FlKeyResponderAsyncCallback callback

◆ FlutterEngineRegisterExternalTexture()

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 support external textures accept external texture registrations. After the external texture is registered, the application can mark that a frame is available by calling FlutterEngineMarkExternalTextureFrameAvailable.

See also
FlutterEngineUnregisterExternalTexture()
FlutterEngineMarkExternalTextureFrameAvailable()
Parameters
[in]engineA running engine instance.
[in]texture_identifierThe identifier of the texture to register with the engine. The embedder may supply new frames to this texture using the same identifier.
Returns
The result of the call.

Definition at line 1759 of file embedder.cc.

References kInternalInconsistency, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and flutter::RegisterTexture().

Referenced by FlutterEngineGetProcAddresses(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1761  {
1762  if (engine == nullptr) {
1763  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
1764  }
1765 
1766  if (texture_identifier == 0) {
1768  "Texture identifier was invalid.");
1769  }
1770  if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->RegisterTexture(
1771  texture_identifier)) {
1773  "Could not register the specified texture.");
1774  }
1775  return kSuccess;
1776 }
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
static void RegisterTexture(JNIEnv *env, jobject jcaller, jlong shell_holder, jlong texture_id, jobject surface_texture)

◆ FlutterEngineReloadSystemFonts()

FlutterEngineResult FlutterEngineReloadSystemFonts ( FLUTTER_API_SYMBOL(FlutterEngine engine)

Reloads the system fonts in engine.

Parameters
[in]engine.A running engine instance.
Returns
The result of the call.

Definition at line 1892 of file embedder.cc.

References kInternalInconsistency, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and TRACE_EVENT0.

Referenced by FlutterEngineGetProcAddresses(), and flutter::testing::TEST_F().

1893  {
1894  if (engine == nullptr) {
1895  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
1896  }
1897 
1898  TRACE_EVENT0("flutter", "FlutterEngineReloadSystemFonts");
1899 
1900  if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)
1901  ->ReloadSystemFonts()) {
1903  "Could not reload system fonts.");
1904  }
1905 
1906  return kSuccess;
1907 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93

◆ FlutterEngineRun()

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 for the pair of calls to FlutterEngineInitialize and FlutterEngineRunInitialized.

Note
This method of running a Flutter engine works well except in cases where the embedder specifies custom task runners via FlutterProjectArgs::custom_task_runners. In such cases, the engine may need the embedder to post tasks back to it before FlutterEngineRun has returned. Embedders can only post tasks to the engine if they have a handle to the engine. In such cases, embedders are advised to get the engine handle via the FlutterInitializeCall. Then they can call FlutterEngineRunInitialized knowing that they will be able to service custom tasks on other threads with the engine handle.
Parameters
[in]versionThe Flutter embedder API version. Must be FLUTTER_ENGINE_VERSION.
[in]configThe renderer configuration.
[in]argsThe Flutter project arguments.
user_dataA user data baton passed back to embedders in callbacks.
[out]engine_outThe engine handle on successful engine creation.
Returns
The result of the call to run the Flutter engine.

Definition at line 869 of file embedder.cc.

References FlutterEngineInitialize(), FlutterEngineRunInitialized(), kSuccess, and result.

Referenced by FlutterEngineGetProcAddresses(), flutter::testing::EmbedderConfigBuilder::InitializeEngine(), RunFlutter(), RunFlutterEngine(), and _FlutterTaskRunner::~_FlutterTaskRunner().

874  {
875  auto result =
876  FlutterEngineInitialize(version, config, args, user_data, engine_out);
877 
878  if (result != kSuccess) {
879  return result;
880  }
881 
882  return FlutterEngineRunInitialized(*engine_out);
883 }
void * user_data
GAsyncResult * result
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...
Definition: embedder.cc:885
FlutterEngineResult FlutterEngineRunInitialized(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Runs an initialized engine instance. An engine can be initialized via FlutterEngineInitialize. An initialized instance can only be run once. During and after this call, custom task runners supplied by the embedder are expected to start servicing tasks.
Definition: embedder.cc:1317

◆ FlutterEngineRunInitialized()

FlutterEngineResult FlutterEngineRunInitialized ( FLUTTER_API_SYMBOL(FlutterEngine engine)

Runs an initialized engine instance. An engine can be initialized via FlutterEngineInitialize. An initialized instance can only be run once. During and after this call, custom task runners supplied by the embedder are expected to start servicing tasks.

Parameters
[in]engineAn initialized engine instance that has not previously been run.
Returns
The result of the call to run the initialized Flutter engine instance.

Definition at line 1317 of file embedder.cc.

References engine, FLUTTER_EXPORT, kInternalInconsistency, kInvalidArguments, kSuccess, and LOG_EMBEDDER_ERROR.

Referenced by FlutterEngineGetProcAddresses(), FlutterEngineRun(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1318  {
1319  if (!engine) {
1320  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
1321  }
1322 
1323  auto embedder_engine = reinterpret_cast<flutter::EmbedderEngine*>(engine);
1324 
1325  // The engine must not already be running. Initialize may only be called
1326  // once on an engine instance.
1327  if (embedder_engine->IsValid()) {
1328  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
1329  }
1330 
1331  // Step 1: Launch the shell.
1332  if (!embedder_engine->LaunchShell()) {
1334  "Could not launch the engine using supplied "
1335  "initialization arguments.");
1336  }
1337 
1338  // Step 2: Tell the platform view to initialize itself.
1339  if (!embedder_engine->NotifyCreated()) {
1341  "Could not create platform view components.");
1342  }
1343 
1344  // Step 3: Launch the root isolate.
1345  if (!embedder_engine->RunRootIsolate()) {
1346  return LOG_EMBEDDER_ERROR(
1348  "Could not run the root isolate of the Flutter application using the "
1349  "project arguments specified.");
1350  }
1351 
1352  return kSuccess;
1353 }
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93

◆ FlutterEngineRunsAOTCompiledDartCode()

bool FlutterEngineRunsAOTCompiledDartCode ( void  )

Returns if the Flutter engine instance will run AOT compiled Dart code. This call has no threading restrictions.

For embedder code that is configured for both AOT and JIT mode Dart execution based on the Flutter engine being linked to, this runtime check may be used to appropriately configure the FlutterProjectArgs. In JIT mode execution, the kernel snapshots must be present in the Flutter assets directory specified in the FlutterProjectArgs. For AOT execution, the fields vm_snapshot_data, vm_snapshot_instructions, isolate_snapshot_data and isolate_snapshot_instructions (along with their size fields) must be specified in FlutterProjectArgs.

Returns
True, if AOT Dart code is run. JIT otherwise.

Definition at line 2052 of file embedder.cc.

References flutter::DartVM::IsRunningPrecompiledCode().

Referenced by FlutterEngineGetProcAddresses(), RunFlutterEngine(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

2052  {
2054 }
static bool IsRunningPrecompiledCode()
Checks if VM instances in the process can run precompiled code. This call can be made at any time and...
Definition: dart_vm.cc:205

◆ FlutterEngineRunTask()

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 FlutterTaskRunnerDescription.post_task_callback. This call must only be made at the target time specified in that callback. Running the task before that time is undefined behavior.

Parameters
[in]engineA running engine instance.
[in]taskthe task handle.
Returns
The result of the call.

Definition at line 1947 of file embedder.cc.

References engine, kInvalidArguments, kSuccess, and LOG_EMBEDDER_ERROR.

Referenced by FlutterDesktopCreateWindow(), FlutterDesktopRunEngine(), FlutterEngineGetProcAddresses(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1949  {
1950  if (engine == nullptr) {
1951  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
1952  }
1953 
1954  return reinterpret_cast<flutter::EmbedderEngine*>(engine)->RunTask(task)
1955  ? kSuccess
1957  "Could not run the specified task.");
1958 }
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93

◆ FlutterEngineSendKeyEvent()

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 synchronous fashion, although due to technical limitation, the result is always reported asynchronously. The callback is guaranteed to be called exactly once.

Parameters
[in]engineA running engine instance.
[in]eventThe event data to be sent. This function will no longer access event after returning.
[in]callbackThe callback invoked by the engine when the Flutter application has decided whether it handles this event. Accepts nullptr.
[in]user_dataThe context associated with the callback. The exact same value will used to invoke callback. Accepts nullptr.
Returns
The result of the call.

Definition at line 1587 of file embedder.cc.

References callback, character, flutter::KeyData::Clear(), engine, kFlutterKeyEventTypeUp, kInternalInconsistency, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, flutter::KeyData::logical, MapKeyEventType(), flutter::KeyData::physical, SAFE_ACCESS, flutter::KeyData::synthesized, flutter::KeyData::timestamp, flutter::KeyData::type, type, and user_data.

Referenced by FlutterEngineGetProcAddresses(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1591  {
1592  if (engine == nullptr) {
1593  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
1594  }
1595 
1596  if (event == nullptr) {
1597  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid key event.");
1598  }
1599 
1600  const char* character = SAFE_ACCESS(event, character, nullptr);
1601 
1602  flutter::KeyData key_data;
1603  key_data.Clear();
1604  key_data.timestamp = static_cast<uint64_t>(SAFE_ACCESS(event, timestamp, 0));
1605  key_data.type = MapKeyEventType(
1607  key_data.physical = SAFE_ACCESS(event, physical, 0);
1608  key_data.logical = SAFE_ACCESS(event, logical, 0);
1609  key_data.synthesized = SAFE_ACCESS(event, synthesized, false);
1610 
1611  auto packet = std::make_unique<flutter::KeyDataPacket>(key_data, character);
1612 
1613  auto response = [callback, user_data](bool handled) {
1614  if (callback != nullptr) {
1615  callback(handled, user_data);
1616  }
1617  };
1618 
1619  return reinterpret_cast<flutter::EmbedderEngine*>(engine)
1620  ->DispatchKeyDataPacket(std::move(packet), response)
1621  ? kSuccess
1623  "Could not dispatch the key event to the "
1624  "running Flutter application.");
1625 }
uint64_t timestamp
Definition: key_data.h:33
uint64_t synthesized
Definition: key_data.h:40
KeyCallType type
uint64_t logical
Definition: key_data.h:36
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
void * user_data
char32_t character
FlKeyEvent FlKeyResponderAsyncCallback callback
#define SAFE_ACCESS(pointer, member, default_value)
static flutter::KeyEventType MapKeyEventType(FlutterKeyEventType event_kind)
Definition: embedder.cc:1574
KeyEventType type
Definition: key_data.h:34
uint64_t physical
Definition: key_data.h:35

◆ FlutterEngineSendPlatformMessage()

FlutterEngineResult FlutterEngineSendPlatformMessage ( FLUTTER_API_SYMBOL(FlutterEngine engine,
const FlutterPlatformMessage flutter_message 
)

Definition at line 1627 of file embedder.cc.

References FlutterPlatformMessage::channel, fml::MallocMapping::Copy(), engine, kInternalInconsistency, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, _FlutterPlatformMessageResponseHandle::message, and SAFE_ACCESS.

Referenced by FlutterDesktopMessengerSendWithReply(), FlutterEngineGetProcAddresses(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1629  {
1630  if (engine == nullptr) {
1631  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
1632  }
1633 
1634  if (flutter_message == nullptr) {
1635  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid message argument.");
1636  }
1637 
1638  if (SAFE_ACCESS(flutter_message, channel, nullptr) == nullptr) {
1639  return LOG_EMBEDDER_ERROR(
1640  kInvalidArguments, "Message argument did not specify a valid channel.");
1641  }
1642 
1643  size_t message_size = SAFE_ACCESS(flutter_message, message_size, 0);
1644  const uint8_t* message_data = SAFE_ACCESS(flutter_message, message, nullptr);
1645 
1646  if (message_size != 0 && message_data == nullptr) {
1647  return LOG_EMBEDDER_ERROR(
1649  "Message size was non-zero but the message data was nullptr.");
1650  }
1651 
1652  const FlutterPlatformMessageResponseHandle* response_handle =
1653  SAFE_ACCESS(flutter_message, response_handle, nullptr);
1654 
1656  if (response_handle && response_handle->message) {
1657  response = response_handle->message->response();
1658  }
1659 
1660  std::unique_ptr<flutter::PlatformMessage> message;
1661  if (message_size == 0) {
1662  message = std::make_unique<flutter::PlatformMessage>(
1663  flutter_message->channel, response);
1664  } else {
1665  message = std::make_unique<flutter::PlatformMessage>(
1666  flutter_message->channel,
1667  fml::MallocMapping::Copy(message_data, message_size), response);
1668  }
1669 
1670  return reinterpret_cast<flutter::EmbedderEngine*>(engine)
1671  ->SendPlatformMessage(std::move(message))
1672  ? kSuccess
1674  "Could not send a message to the running "
1675  "Flutter application.");
1676 }
const char * channel
Definition: embedder.h:757
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
#define SAFE_ACCESS(pointer, member, default_value)
static MallocMapping Copy(const T *begin, const T *end)
Definition: mapping.h:147
std::unique_ptr< flutter::PlatformMessage > message
Definition: embedder.cc:727

◆ FlutterEngineSendPlatformMessageResponse()

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.

Parameters
[in]engineThe running engine instance.
[in]handleThe platform message response handle.
[in]dataThe data to associate with the platform message response.
[in]data_lengthThe length of the platform message response data.
Returns
The result of the call.

Definition at line 1727 of file embedder.cc.

References kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and _FlutterPlatformMessageResponseHandle::message.

Referenced by FlutterDesktopMessengerSendResponse(), FlutterEngineGetProcAddresses(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1731  {
1732  if (data_length != 0 && data == nullptr) {
1733  return LOG_EMBEDDER_ERROR(
1735  "Data size was non zero but the pointer to the data was null.");
1736  }
1737 
1738  auto response = handle->message->response();
1739 
1740  if (response) {
1741  if (data_length == 0) {
1742  response->CompleteEmpty();
1743  } else {
1744  response->Complete(std::make_unique<fml::DataMapping>(
1745  std::vector<uint8_t>({data, data + data_length})));
1746  }
1747  }
1748 
1749  delete handle;
1750 
1751  return kSuccess;
1752 }
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
std::unique_ptr< flutter::PlatformMessage > message
Definition: embedder.cc:727

◆ FlutterEngineSendPointerEvent()

FlutterEngineResult FlutterEngineSendPointerEvent ( FLUTTER_API_SYMBOL(FlutterEngine engine,
const FlutterPointerEvent pointers,
size_t  events_count 
)

Definition at line 1501 of file embedder.cc.

References flutter::PointerData::buttons, flutter::PointerData::change, flutter::PointerData::Clear(), flutter::PointerData::device, flutter::DispatchPointerDataPacket(), flutter::PointerData::embedder_id, engine, kCancel, flutter::PointerData::kDown, kFlutterPointerSignalKindNone, flutter::PointerData::kind, kInternalInconsistency, kInvalidArguments, flutter::PointerData::kMouse, flutter::PointerData::kMove, flutter::kPointerButtonTouchContact, kSuccess, flutter::PointerData::kTouch, LOG_EMBEDDER_ERROR, flutter::PointerData::physical_delta_x, flutter::PointerData::physical_delta_y, flutter::PointerData::physical_x, flutter::PointerData::physical_y, flutter::PointerData::pointer_identifier, PointerDataButtonsForLegacyEvent(), SAFE_ACCESS, flutter::PointerData::scroll_delta_x, flutter::PointerData::scroll_delta_y, flutter::PointerData::signal_kind, flutter::PointerData::time_stamp, ToPointerDataChange(), ToPointerDataKind(), and ToPointerDataSignalKind().

Referenced by FlutterEngineGetProcAddresses(), GLFWcursorPositionCallbackAtPhase(), SendPointerEventWithData(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1504  {
1505  if (engine == nullptr) {
1506  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
1507  }
1508 
1509  if (pointers == nullptr || events_count == 0) {
1510  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid pointer events.");
1511  }
1512 
1513  auto packet = std::make_unique<flutter::PointerDataPacket>(events_count);
1514 
1515  const FlutterPointerEvent* current = pointers;
1516 
1517  for (size_t i = 0; i < events_count; ++i) {
1518  flutter::PointerData pointer_data;
1519  pointer_data.Clear();
1520  // this is currely in use only on android embedding.
1521  pointer_data.embedder_id = 0;
1522  pointer_data.time_stamp = SAFE_ACCESS(current, timestamp, 0);
1523  pointer_data.change = ToPointerDataChange(
1524  SAFE_ACCESS(current, phase, FlutterPointerPhase::kCancel));
1525  pointer_data.physical_x = SAFE_ACCESS(current, x, 0.0);
1526  pointer_data.physical_y = SAFE_ACCESS(current, y, 0.0);
1527  // Delta will be generated in pointer_data_packet_converter.cc.
1528  pointer_data.physical_delta_x = 0.0;
1529  pointer_data.physical_delta_y = 0.0;
1530  pointer_data.device = SAFE_ACCESS(current, device, 0);
1531  // Pointer identifier will be generated in
1532  // pointer_data_packet_converter.cc.
1533  pointer_data.pointer_identifier = 0;
1534  pointer_data.signal_kind = ToPointerDataSignalKind(
1535  SAFE_ACCESS(current, signal_kind, kFlutterPointerSignalKindNone));
1536  pointer_data.scroll_delta_x = SAFE_ACCESS(current, scroll_delta_x, 0.0);
1537  pointer_data.scroll_delta_y = SAFE_ACCESS(current, scroll_delta_y, 0.0);
1538  FlutterPointerDeviceKind device_kind = SAFE_ACCESS(current, device_kind, 0);
1539  // For backwards compatibility with embedders written before the device
1540  // kind and buttons were exposed, if the device kind is not set treat it
1541  // as a mouse, with a synthesized primary button state based on the phase.
1542  if (device_kind == 0) {
1544  pointer_data.buttons =
1546 
1547  } else {
1548  pointer_data.kind = ToPointerDataKind(device_kind);
1549  if (pointer_data.kind == flutter::PointerData::DeviceKind::kTouch) {
1550  // For touch events, set the button internally rather than requiring
1551  // it at the API level, since it's a confusing construction to expose.
1552  if (pointer_data.change == flutter::PointerData::Change::kDown ||
1553  pointer_data.change == flutter::PointerData::Change::kMove) {
1555  }
1556  } else {
1557  // Buttons use the same mask values, so pass them through directly.
1558  pointer_data.buttons = SAFE_ACCESS(current, buttons, 0);
1559  }
1560  }
1561  packet->SetPointerData(i, pointer_data);
1562  current = reinterpret_cast<const FlutterPointerEvent*>(
1563  reinterpret_cast<const uint8_t*>(current) + current->struct_size);
1564  }
1565 
1566  return reinterpret_cast<flutter::EmbedderEngine*>(engine)
1567  ->DispatchPointerDataPacket(std::move(packet))
1568  ? kSuccess
1570  "Could not dispatch pointer events to the "
1571  "running Flutter application.");
1572 }
flutter::PointerData::SignalKind ToPointerDataSignalKind(FlutterPointerSignalKind kind)
Definition: embedder.cc:1470
flutter::PointerData::DeviceKind ToPointerDataKind(FlutterPointerDeviceKind device_kind)
Definition: embedder.cc:1455
SignalKind signal_kind
Definition: pointer_data.h:65
int64_t pointer_identifier
Definition: pointer_data.h:67
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
FlutterPointerDeviceKind
The device type that created a pointer event.
Definition: embedder.h:622
#define SAFE_ACCESS(pointer, member, default_value)
flutter::PointerData::Change ToPointerDataChange(FlutterPointerPhase phase)
Definition: embedder.cc:1432
int64_t PointerDataButtonsForLegacyEvent(flutter::PointerData::Change change)
Definition: embedder.cc:1483
static void DispatchPointerDataPacket(JNIEnv *env, jobject jcaller, jlong shell_holder, jobject buffer, jint position)

◆ FlutterEngineSendWindowMetricsEvent()

FlutterEngineResult FlutterEngineSendWindowMetricsEvent ( FLUTTER_API_SYMBOL(FlutterEngine engine,
const FlutterWindowMetricsEvent flutter_metrics 
)

Definition at line 1379 of file embedder.cc.

References flutter::ViewportMetrics::device_pixel_ratio, engine, height, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, flutter::ViewportMetrics::physical_height, flutter::ViewportMetrics::physical_view_inset_bottom, flutter::ViewportMetrics::physical_view_inset_left, flutter::ViewportMetrics::physical_view_inset_right, flutter::ViewportMetrics::physical_view_inset_top, flutter::ViewportMetrics::physical_width, SAFE_ACCESS, flutter::SetViewportMetrics(), and width.

Referenced by FlutterEngineGetProcAddresses(), GLFWwindowSizeCallback(), SendWindowMetrics(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1381  {
1382  if (engine == nullptr || flutter_metrics == nullptr) {
1383  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
1384  }
1385 
1386  flutter::ViewportMetrics metrics;
1387 
1388  metrics.physical_width = SAFE_ACCESS(flutter_metrics, width, 0.0);
1389  metrics.physical_height = SAFE_ACCESS(flutter_metrics, height, 0.0);
1390  metrics.device_pixel_ratio = SAFE_ACCESS(flutter_metrics, pixel_ratio, 1.0);
1391  metrics.physical_view_inset_top =
1392  SAFE_ACCESS(flutter_metrics, physical_view_inset_top, 0.0);
1393  metrics.physical_view_inset_right =
1394  SAFE_ACCESS(flutter_metrics, physical_view_inset_right, 0.0);
1395  metrics.physical_view_inset_bottom =
1396  SAFE_ACCESS(flutter_metrics, physical_view_inset_bottom, 0.0);
1397  metrics.physical_view_inset_left =
1398  SAFE_ACCESS(flutter_metrics, physical_view_inset_left, 0.0);
1399 
1400  if (metrics.device_pixel_ratio <= 0.0) {
1401  return LOG_EMBEDDER_ERROR(
1403  "Device pixel ratio was invalid. It must be greater than zero.");
1404  }
1405 
1406  if (metrics.physical_view_inset_top < 0 ||
1407  metrics.physical_view_inset_right < 0 ||
1408  metrics.physical_view_inset_bottom < 0 ||
1409  metrics.physical_view_inset_left < 0) {
1410  return LOG_EMBEDDER_ERROR(
1412  "Physical view insets are invalid. They must be non-negative.");
1413  }
1414 
1415  if (metrics.physical_view_inset_top > metrics.physical_height ||
1416  metrics.physical_view_inset_right > metrics.physical_width ||
1417  metrics.physical_view_inset_bottom > metrics.physical_height ||
1418  metrics.physical_view_inset_left > metrics.physical_width) {
1420  "Physical view insets are invalid. They cannot "
1421  "be greater than physical height or width.");
1422  }
1423 
1424  return reinterpret_cast<flutter::EmbedderEngine*>(engine)->SetViewportMetrics(
1425  std::move(metrics))
1426  ? kSuccess
1428  "Viewport metrics were invalid.");
1429 }
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
#define SAFE_ACCESS(pointer, member, default_value)
int32_t width
int32_t height
static void SetViewportMetrics(JNIEnv *env, jobject jcaller, jlong shell_holder, jfloat devicePixelRatio, jint physicalWidth, jint physicalHeight, jint physicalPaddingTop, jint physicalPaddingRight, jint physicalPaddingBottom, jint physicalPaddingLeft, jint physicalViewInsetTop, jint physicalViewInsetRight, jint physicalViewInsetBottom, jint physicalViewInsetLeft, jint systemGestureInsetTop, jint systemGestureInsetRight, jint systemGestureInsetBottom, jint systemGestureInsetLeft, jint physicalTouchSlop)

◆ FlutterEngineShutdown()

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 embedder API after this point. Making additional calls with this handle is undefined behavior.

Note
This de-initializes the Flutter engine instance (via an implicit call to FlutterEngineDeinitialize) if necessary.
Parameters
[in]engineThe Flutter engine instance to collect.
Returns
The result of the call to shutdown the Flutter engine instance.

Definition at line 1368 of file embedder.cc.

References engine, FlutterEngineDeinitialize(), kSuccess, and result.

Referenced by FlutterDesktopDestroyWindow(), FlutterDesktopShutDownEngine(), FlutterEngineGetProcAddresses(), flutter::testing::UniqueEngineTraits::Free(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1369  {
1371  if (result != kSuccess) {
1372  return result;
1373  }
1374  auto embedder_engine = reinterpret_cast<flutter::EmbedderEngine*>(engine);
1375  delete embedder_engine;
1376  return kSuccess;
1377 }
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...
Definition: embedder.cc:1356
GAsyncResult * result

◆ FlutterEngineTraceEventDurationBegin()

void FlutterEngineTraceEventDurationBegin ( const char *  name)

A profiling utility. Logs a trace duration begin event to the timeline. If the timeline is unavailable or disabled, this has no effect. Must be balanced with an duration end event (via FlutterEngineTraceEventDurationEnd) with the same name on the same thread. Can be called on any thread. Strings passed into the function will NOT be copied when added to the timeline. Only string literals may be passed in.

Parameters
[in]nameThe name of the trace event.

Definition at line 1909 of file embedder.cc.

References fml::tracing::TraceEvent0().

Referenced by FlutterEngineGetProcAddresses().

1909  {
1910  fml::tracing::TraceEvent0("flutter", name);
1911 }
const char * name
Definition: fuchsia.cc:50
void TraceEvent0(TraceArg category_group, TraceArg name)
Definition: trace_event.cc:317

◆ FlutterEngineTraceEventDurationEnd()

void FlutterEngineTraceEventDurationEnd ( const char *  name)

A profiling utility. Logs a trace duration end event to the timeline. If the timeline is unavailable or disabled, this has no effect. This call must be preceded by a trace duration begin call (via FlutterEngineTraceEventDurationBegin) with the same name on the same thread. Can be called on any thread. Strings passed into the function will NOT be copied when added to the timeline. Only string literals may be passed in.

Parameters
[in]nameThe name of the trace event.

Definition at line 1913 of file embedder.cc.

References fml::tracing::TraceEventEnd().

Referenced by FlutterEngineGetProcAddresses().

1913  {
1915 }
void TraceEventEnd(TraceArg name)
Definition: trace_event.cc:331
const char * name
Definition: fuchsia.cc:50

◆ FlutterEngineTraceEventInstant()

void FlutterEngineTraceEventInstant ( const char *  name)

A profiling utility. Logs a trace duration instant event to the timeline. If the timeline is unavailable or disabled, this has no effect. Can be called on any thread. Strings passed into the function will NOT be copied when added to the timeline. Only string literals may be passed in.

Parameters
[in]nameThe name of the trace event.

Definition at line 1917 of file embedder.cc.

References fml::tracing::TraceEventInstant0().

Referenced by FlutterEngineGetProcAddresses().

1917  {
1919 }
void TraceEventInstant0(TraceArg category_group, TraceArg name)
Definition: trace_event.cc:358
const char * name
Definition: fuchsia.cc:50

◆ FlutterEngineUnregisterExternalTexture()

FlutterEngineResult FlutterEngineUnregisterExternalTexture ( FLUTTER_API_SYMBOL(FlutterEngine engine,
int64_t  texture_identifier 
)

Unregister a previous texture registration.

See also
FlutterEngineRegisterExternalTexture()
FlutterEngineMarkExternalTextureFrameAvailable()
Parameters
[in]engineA running engine instance.
[in]texture_identifierThe identifier of the texture for which new frame will not be available.
Returns
The result of the call.

Definition at line 1778 of file embedder.cc.

References kInternalInconsistency, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and flutter::UnregisterTexture().

Referenced by FlutterEngineGetProcAddresses(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1780  {
1781  if (engine == nullptr) {
1782  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
1783  }
1784 
1785  if (texture_identifier == 0) {
1787  "Texture identifier was invalid.");
1788  }
1789 
1790  if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->UnregisterTexture(
1791  texture_identifier)) {
1793  "Could not un-register the specified texture.");
1794  }
1795 
1796  return kSuccess;
1797 }
static void UnregisterTexture(JNIEnv *env, jobject jcaller, jlong shell_holder, jlong texture_id)
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93

◆ FlutterEngineUpdateAccessibilityFeatures()

FlutterEngineResult FlutterEngineUpdateAccessibilityFeatures ( FLUTTER_API_SYMBOL(FlutterEngine engine,
FlutterAccessibilityFeature  features 
)

Sets additional accessibility features.

Parameters
[in]engineA running engine instance
[in]featuresThe accessibility features to set.
Returns
The result of the call.

Definition at line 1831 of file embedder.cc.

References kInternalInconsistency, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and flutter::SetAccessibilityFeatures().

Referenced by FlutterEngineGetProcAddresses(), and flutter::testing::TEST_F().

1833  {
1834  if (engine == nullptr) {
1835  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
1836  }
1837  if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)
1840  "Could not update accessibility features.");
1841  }
1842  return kSuccess;
1843 }
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
FlutterSemanticsFlag flags
static void SetAccessibilityFeatures(JNIEnv *env, jobject jcaller, jlong shell_holder, jint flags)

◆ FlutterEngineUpdateLocales()

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 first item in the list of locales supplied. The other entries will be used as a fallback.

Parameters
[in]engineA running engine instance.
[in]localesThe updated locales in the order of preference.
[in]locales_countThe count of locales supplied.
Returns
Whether the locale updates were applied.

Definition at line 1992 of file embedder.cc.

References args, DispatchJSONPlatformMessage(), kInternalInconsistency, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and SAFE_ACCESS.

Referenced by FlutterEngineGetProcAddresses(), SetUpLocales(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1995  {
1996  if (engine == nullptr) {
1997  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
1998  }
1999 
2000  if (locales_count == 0) {
2001  return kSuccess;
2002  }
2003 
2004  if (locales == nullptr) {
2005  return LOG_EMBEDDER_ERROR(kInvalidArguments, "No locales were specified.");
2006  }
2007 
2008  rapidjson::Document document;
2009  auto& allocator = document.GetAllocator();
2010 
2011  document.SetObject();
2012  document.AddMember("method", "setLocale", allocator);
2013 
2014  rapidjson::Value args(rapidjson::kArrayType);
2015  args.Reserve(locales_count * 4, allocator);
2016  for (size_t i = 0; i < locales_count; ++i) {
2017  const FlutterLocale* locale = locales[i];
2018  const char* language_code_str = SAFE_ACCESS(locale, language_code, nullptr);
2019  if (language_code_str == nullptr || ::strlen(language_code_str) == 0) {
2020  return LOG_EMBEDDER_ERROR(
2022  "Language code is required but not present in FlutterLocale.");
2023  }
2024 
2025  const char* country_code_str = SAFE_ACCESS(locale, country_code, "");
2026  const char* script_code_str = SAFE_ACCESS(locale, script_code, "");
2027  const char* variant_code_str = SAFE_ACCESS(locale, variant_code, "");
2028 
2029  rapidjson::Value language_code, country_code, script_code, variant_code;
2030 
2031  language_code.SetString(language_code_str, allocator);
2032  country_code.SetString(country_code_str ? country_code_str : "", allocator);
2033  script_code.SetString(script_code_str ? script_code_str : "", allocator);
2034  variant_code.SetString(variant_code_str ? variant_code_str : "", allocator);
2035 
2036  // Required.
2037  args.PushBack(language_code, allocator);
2038  args.PushBack(country_code, allocator);
2039  args.PushBack(script_code, allocator);
2040  args.PushBack(variant_code, allocator);
2041  }
2042  document.AddMember("args", args, allocator);
2043 
2044  return DispatchJSONPlatformMessage(engine, std::move(document),
2045  "flutter/localization")
2046  ? kSuccess
2048  "Could not send message to update locale of "
2049  "a running Flutter application.");
2050 }
G_BEGIN_DECLS FlValue * args
static bool DispatchJSONPlatformMessage(FLUTTER_API_SYMBOL(FlutterEngine) engine, rapidjson::Document document, const std::string &channel_name)
Definition: embedder.cc:1960
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
#define SAFE_ACCESS(pointer, member, default_value)

◆ FlutterEngineUpdateSemanticsEnabled()

FlutterEngineResult FlutterEngineUpdateSemanticsEnabled ( FLUTTER_API_SYMBOL(FlutterEngine engine,
bool  enabled 
)

Enable or disable accessibility semantics.

Parameters
[in]engineA running engine instance.
[in]enabledWhen enabled, changes to the semantic contents of the window are sent via the FlutterUpdateSemanticsNodeCallback registered to update_semantics_node_callback in FlutterProjectArgs.
Returns
The result of the call.

Definition at line 1817 of file embedder.cc.

References kInternalInconsistency, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, and flutter::SetSemanticsEnabled().

Referenced by FlutterEngineGetProcAddresses(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1819  {
1820  if (engine == nullptr) {
1821  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
1822  }
1823  if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->SetSemanticsEnabled(
1824  enabled)) {
1826  "Could not update semantics state.");
1827  }
1828  return kSuccess;
1829 }
static void SetSemanticsEnabled(JNIEnv *env, jobject jcaller, jlong shell_holder, jboolean enabled)
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93

◆ FlutterPlatformMessageCreateResponseHandle()

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 response to a message. This handle may be set on the response_handle field of any FlutterPlatformMessage sent to the engine.

The handle must be collected via a call to FlutterPlatformMessageReleaseResponseHandle. This may be done immediately after a call to FlutterEngineSendPlatformMessage with a platform message whose response handle contains the handle created using this call. In case a handle is created but never sent in a message, the release call must still be made. Not calling release on the handle results in a small memory leak.

The user data baton passed to the data callback is the one specified in this call as the third argument.

See also
FlutterPlatformMessageReleaseResponseHandle()
Parameters
[in]engineA running engine instance.
[in]data_callbackThe callback invoked by the engine when the Flutter application send a response on the handle.
[in]user_dataThe user data associated with the data callback.
[out]response_outThe response handle created when this call is successful.
Returns
The result of the call.

Definition at line 1678 of file embedder.cc.

References engine, kInvalidArguments, kSuccess, LOG_EMBEDDER_ERROR, fml::size(), and user_data.

Referenced by FlutterDesktopMessengerSendWithReply(), FlutterEngineGetProcAddresses(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1682  {
1683  if (engine == nullptr) {
1684  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
1685  }
1686 
1687  if (data_callback == nullptr || response_out == nullptr) {
1688  return LOG_EMBEDDER_ERROR(
1689  kInvalidArguments, "Data callback or the response handle was invalid.");
1690  }
1691 
1693  [user_data, data_callback](const uint8_t* data, size_t size) {
1694  data_callback(data, size, user_data);
1695  };
1696 
1697  auto platform_task_runner = reinterpret_cast<flutter::EmbedderEngine*>(engine)
1698  ->GetTaskRunners()
1699  .GetPlatformTaskRunner();
1700 
1701  auto handle = new FlutterPlatformMessageResponseHandle();
1702 
1703  handle->message = std::make_unique<flutter::PlatformMessage>(
1704  "", // The channel is empty and unused as the response handle is going
1705  // to referenced directly in the |FlutterEngineSendPlatformMessage|
1706  // with the container message discarded.
1707  fml::MakeRefCounted<flutter::EmbedderPlatformMessageResponse>(
1708  std::move(platform_task_runner), response_callback));
1709  *response_out = handle;
1710  return kSuccess;
1711 }
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93
void * user_data
std::function< void(const uint8_t *data, size_t size)> Callback
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
struct _FlutterPlatformMessageResponseHandle FlutterPlatformMessageResponseHandle
Definition: embedder.h:751

◆ FlutterPlatformMessageReleaseResponseHandle()

FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle ( FLUTTER_API_SYMBOL(FlutterEngine engine,
FlutterPlatformMessageResponseHandle response 
)

Collects the handle created using FlutterPlatformMessageCreateResponseHandle.

See also
FlutterPlatformMessageCreateResponseHandle()
Parameters
[in]engineA running engine instance.
[in]responseThe platform message response handle to collect. These handles are created using FlutterPlatformMessageCreateResponseHandle().
Returns
The result of the call.

Definition at line 1713 of file embedder.cc.

References kInvalidArguments, kSuccess, and LOG_EMBEDDER_ERROR.

Referenced by FlutterDesktopMessengerSendWithReply(), FlutterEngineGetProcAddresses(), flutter::testing::TEST_F(), and _FlutterTaskRunner::~_FlutterTaskRunner().

1715  {
1716  if (engine == nullptr) {
1717  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
1718  }
1719 
1720  if (response == nullptr) {
1721  return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid response handle.");
1722  }
1723  delete response;
1724  return kSuccess;
1725 }
#define LOG_EMBEDDER_ERROR(code, reason)
Definition: embedder.cc:93

◆ InferExternalViewEmbedderFromArgs()

static std::pair<std::unique_ptr<flutter::EmbedderExternalViewEmbedder>, bool > InferExternalViewEmbedderFromArgs ( const FlutterCompositor compositor)
static

Definition at line 682 of file embedder.cc.

References CreateEmbedderRenderTarget(), FML_LOG, SAFE_ACCESS, TRACE_EVENT0, user_data, and FlutterCompositor::user_data.

Referenced by FlutterEngineInitialize().

682  {
683  if (compositor == nullptr) {
684  return {nullptr, false};
685  }
686 
687  auto c_create_callback =
688  SAFE_ACCESS(compositor, create_backing_store_callback, nullptr);
689  auto c_collect_callback =
690  SAFE_ACCESS(compositor, collect_backing_store_callback, nullptr);
691  auto c_present_callback =
692  SAFE_ACCESS(compositor, present_layers_callback, nullptr);
693  bool avoid_backing_store_cache =
694  SAFE_ACCESS(compositor, avoid_backing_store_cache, false);
695 
696  // Make sure the required callbacks are present
697  if (!c_create_callback || !c_collect_callback || !c_present_callback) {
698  FML_LOG(ERROR) << "Required compositor callbacks absent.";
699  return {nullptr, true};
700  }
701 
702  FlutterCompositor captured_compositor = *compositor;
703 
705  create_render_target_callback =
706  [captured_compositor](GrDirectContext* context, const auto& config) {
707  return CreateEmbedderRenderTarget(&captured_compositor, config,
708  context);
709  };
710 
712  [c_present_callback,
713  user_data = compositor->user_data](const auto& layers) {
714  TRACE_EVENT0("flutter", "FlutterCompositorPresentLayers");
715  return c_present_callback(
716  const_cast<const FlutterLayer**>(layers.data()), layers.size(),
717  user_data);
718  };
719 
720  return {std::make_unique<flutter::EmbedderExternalViewEmbedder>(
721  avoid_backing_store_cache, create_render_target_callback,
722  present_callback),
723  false};
724 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
void * user_data
#define FML_LOG(severity)
Definition: logging.h:65
#define SAFE_ACCESS(pointer, member, default_value)
std::function< bool(const std::vector< const FlutterLayer * > &layers)> PresentCallback
static std::unique_ptr< flutter::EmbedderRenderTarget > CreateEmbedderRenderTarget(const FlutterCompositor *compositor, const FlutterBackingStoreConfig &config, GrDirectContext *context)
Definition: embedder.cc:608
std::function< std::unique_ptr< EmbedderRenderTarget >(GrDirectContext *context, const FlutterBackingStoreConfig &config)> CreateRenderTargetCallback

◆ InferMetalPlatformViewCreationCallback()

static flutter::Shell::CreateCallback<flutter::PlatformView> InferMetalPlatformViewCreationCallback ( const FlutterRendererConfig config,
void *  user_data,
flutter::PlatformViewEmbedder::PlatformDispatchTable  platform_dispatch_table,
std::unique_ptr< flutter::EmbedderExternalViewEmbedder external_view_embedder 
)
static

Definition at line 304 of file embedder.cc.

References FlutterMetalRendererConfig::device, FlutterMetalRendererConfig::get_next_drawable_callback, flutter::Shell::GetTaskRunners(), kMetal, fml::MakeCopyable(), FlutterRendererConfig::metal, flutter::EmbedderSurfaceMetal::MetalDispatchTable::present, FlutterMetalRendererConfig::present_command_queue, FlutterMetalRendererConfig::present_drawable_callback, FlutterFrameInfo::size, FlutterFrameInfo::struct_size, FlutterMetalTexture::struct_size, flutter::GPUMTLTextureInfo::texture, texture, FlutterMetalTexture::texture, flutter::GPUMTLTextureInfo::texture_id, FlutterMetalTexture::texture_id, FlutterRendererConfig::type, and user_data.

Referenced by InferPlatformViewCreationCallback().

310  {
311  if (config->type != kMetal) {
312  return nullptr;
313  }
314 
315 #ifdef SHELL_ENABLE_METAL
316  std::function<bool(flutter::GPUMTLTextureInfo texture)> metal_present =
317  [ptr = config->metal.present_drawable_callback,
319  FlutterMetalTexture embedder_texture;
320  embedder_texture.struct_size = sizeof(FlutterMetalTexture);
321  embedder_texture.texture = texture.texture;
322  embedder_texture.texture_id = texture.texture_id;
323  return ptr(user_data, &embedder_texture);
324  };
325  auto metal_get_texture =
326  [ptr = config->metal.get_next_drawable_callback,
327  user_data](const SkISize& frame_size) -> flutter::GPUMTLTextureInfo {
328  FlutterFrameInfo frame_info = {};
329  frame_info.struct_size = sizeof(FlutterFrameInfo);
330  frame_info.size = {static_cast<uint32_t>(frame_size.width()),
331  static_cast<uint32_t>(frame_size.height())};
332  flutter::GPUMTLTextureInfo texture_info;
333 
334  FlutterMetalTexture metal_texture = ptr(user_data, &frame_info);
335  texture_info.texture_id = metal_texture.texture_id;
336  texture_info.texture = metal_texture.texture;
337  return texture_info;
338  };
339 
341  .present = metal_present,
342  .get_texture = metal_get_texture,
343  };
344 
345  std::shared_ptr<flutter::EmbedderExternalViewEmbedder> view_embedder =
346  std::move(external_view_embedder);
347 
348  std::unique_ptr<flutter::EmbedderSurfaceMetal> embedder_surface =
349  std::make_unique<flutter::EmbedderSurfaceMetal>(
350  const_cast<flutter::GPUMTLDeviceHandle>(config->metal.device),
351  const_cast<flutter::GPUMTLCommandQueueHandle>(
352  config->metal.present_command_queue),
353  metal_dispatch_table, view_embedder);
354 
355  return fml::MakeCopyable(
356  [embedder_surface = std::move(embedder_surface), platform_dispatch_table,
357  external_view_embedder = view_embedder](flutter::Shell& shell) mutable {
358  return std::make_unique<flutter::PlatformViewEmbedder>(
359  shell, // delegate
360  shell.GetTaskRunners(), // task runners
361  std::move(embedder_surface), // embedder surface
362  platform_dispatch_table, // platform dispatch table
363  std::move(external_view_embedder) // external view embedder
364  );
365  });
366 #else
367  return nullptr;
368 #endif
369 }
int64_t texture_id
Definition: embedder.h:498
G_BEGIN_DECLS FlTexture * texture
size_t struct_size
The size of this struct. Must be sizeof(FlutterMetalTexture).
Definition: embedder.h:493
FlutterMetalCommandQueueHandle present_command_queue
Alias for id<MTLCommandQueue>.
Definition: embedder.h:529
const TaskRunners & GetTaskRunners() const override
If callers wish to interact directly with any shell subcomponents, they must (on the platform thread)...
Definition: shell.cc:669
void * user_data
FlutterMetalPresentCallback present_drawable_callback
Definition: embedder.h:535
FlutterUIntSize size
The size of the surface that will be backed by the fbo.
Definition: embedder.h:362
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition: make_copyable.h:57
size_t struct_size
The size of this struct. Must be sizeof(FlutterFrameInfo).
Definition: embedder.h:360
FlutterRendererType type
Definition: embedder.h:554
FlutterMetalTextureCallback get_next_drawable_callback
Definition: embedder.h:532
FlutterMetalTextureHandle texture
Definition: embedder.h:501
FlutterMetalRendererConfig metal
Definition: embedder.h:558
FlutterMetalDeviceHandle device
Alias for id<MTLDevice>.
Definition: embedder.h:527
std::function< bool(GPUMTLTextureInfo texture)> present

◆ InferOpenGLPlatformViewCreationCallback()

static flutter::Shell::CreateCallback<flutter::PlatformView> InferOpenGLPlatformViewCreationCallback ( const FlutterRendererConfig config,
void *  user_data,
flutter::PlatformViewEmbedder::PlatformDispatchTable  platform_dispatch_table,
std::unique_ptr< flutter::EmbedderExternalViewEmbedder external_view_embedder 
)
static

Definition at line 180 of file embedder.cc.

References FlutterOpenGLRendererConfig::clear_current, FlutterOpenGLRendererConfig::fbo_callback, FlutterPresentInfo::fbo_id, FlutterOpenGLRendererConfig::fbo_with_frame_info_callback, flutter::Shell::GetTaskRunners(), FlutterOpenGLRendererConfig::gl_proc_resolver, kOpenGL, FlutterOpenGLRendererConfig::make_current, FlutterOpenGLRendererConfig::make_resource_current, fml::MakeCopyable(), FlutterRendererConfig::open_gl, FlutterTransformation::pers0, FlutterTransformation::pers1, FlutterTransformation::pers2, FlutterOpenGLRendererConfig::present, FlutterOpenGLRendererConfig::present_with_info, SAFE_ACCESS, FlutterTransformation::scaleX, FlutterTransformation::scaleY, FlutterFrameInfo::size, FlutterTransformation::skewX, FlutterTransformation::skewY, FlutterFrameInfo::struct_size, FlutterPresentInfo::struct_size, FlutterOpenGLRendererConfig::surface_transformation, FlutterTransformation::transX, FlutterTransformation::transY, FlutterRendererConfig::type, user_data, and FlutterUIntSize::width.

Referenced by InferPlatformViewCreationCallback().

186  {
187 #ifdef SHELL_ENABLE_GL
188  if (config->type != kOpenGL) {
189  return nullptr;
190  }
191 
192  auto gl_make_current = [ptr = config->open_gl.make_current,
193  user_data]() -> bool { return ptr(user_data); };
194 
195  auto gl_clear_current = [ptr = config->open_gl.clear_current,
196  user_data]() -> bool { return ptr(user_data); };
197 
198  auto gl_present = [present = config->open_gl.present,
199  present_with_info = config->open_gl.present_with_info,
200  user_data](uint32_t fbo_id) -> bool {
201  if (present) {
202  return present(user_data);
203  } else {
204  FlutterPresentInfo present_info = {};
205  present_info.struct_size = sizeof(FlutterPresentInfo);
206  present_info.fbo_id = fbo_id;
207  return present_with_info(user_data, &present_info);
208  }
209  };
210 
211  auto gl_fbo_callback =
212  [fbo_callback = config->open_gl.fbo_callback,
213  fbo_with_frame_info_callback =
215  user_data](flutter::GLFrameInfo gl_frame_info) -> intptr_t {
216  if (fbo_callback) {
217  return fbo_callback(user_data);
218  } else {
219  FlutterFrameInfo frame_info = {};
220  frame_info.struct_size = sizeof(FlutterFrameInfo);
221  frame_info.size = {gl_frame_info.width, gl_frame_info.height};
222  return fbo_with_frame_info_callback(user_data, &frame_info);
223  }
224  };
225 
226  const FlutterOpenGLRendererConfig* open_gl_config = &config->open_gl;
227  std::function<bool()> gl_make_resource_current_callback = nullptr;
228  if (SAFE_ACCESS(open_gl_config, make_resource_current, nullptr) != nullptr) {
229  gl_make_resource_current_callback =
230  [ptr = config->open_gl.make_resource_current, user_data]() {
231  return ptr(user_data);
232  };
233  }
234 
235  std::function<SkMatrix(void)> gl_surface_transformation_callback = nullptr;
236  if (SAFE_ACCESS(open_gl_config, surface_transformation, nullptr) != nullptr) {
237  gl_surface_transformation_callback =
238  [ptr = config->open_gl.surface_transformation, user_data]() {
239  FlutterTransformation transformation = ptr(user_data);
240  return SkMatrix::MakeAll(transformation.scaleX, //
241  transformation.skewX, //
242  transformation.transX, //
243  transformation.skewY, //
244  transformation.scaleY, //
245  transformation.transY, //
246  transformation.pers0, //
247  transformation.pers1, //
248  transformation.pers2 //
249  );
250  };
251 
252  // If there is an external view embedder, ask it to apply the surface
253  // transformation to its surfaces as well.
254  if (external_view_embedder) {
255  external_view_embedder->SetSurfaceTransformationCallback(
256  gl_surface_transformation_callback);
257  }
258  }
259 
260  flutter::GPUSurfaceGLDelegate::GLProcResolver gl_proc_resolver = nullptr;
261  if (SAFE_ACCESS(open_gl_config, gl_proc_resolver, nullptr) != nullptr) {
262  gl_proc_resolver = [ptr = config->open_gl.gl_proc_resolver,
263  user_data](const char* gl_proc_name) {
264  return ptr(user_data, gl_proc_name);
265  };
266  } else {
267 #if OS_LINUX || OS_WIN
268  gl_proc_resolver = DefaultGLProcResolver;
269 #endif
270  }
271 
272  bool fbo_reset_after_present =
273  SAFE_ACCESS(open_gl_config, fbo_reset_after_present, false);
274 
275  flutter::EmbedderSurfaceGL::GLDispatchTable gl_dispatch_table = {
276  gl_make_current, // gl_make_current_callback
277  gl_clear_current, // gl_clear_current_callback
278  gl_present, // gl_present_callback
279  gl_fbo_callback, // gl_fbo_callback
280  gl_make_resource_current_callback, // gl_make_resource_current_callback
281  gl_surface_transformation_callback, // gl_surface_transformation_callback
282  gl_proc_resolver, // gl_proc_resolver
283  };
284 
285  return fml::MakeCopyable(
286  [gl_dispatch_table, fbo_reset_after_present, platform_dispatch_table,
287  external_view_embedder =
288  std::move(external_view_embedder)](flutter::Shell& shell) mutable {
289  return std::make_unique<flutter::PlatformViewEmbedder>(
290  shell, // delegate
291  shell.GetTaskRunners(), // task runners
292  gl_dispatch_table, // embedder GL dispatch table
293  fbo_reset_after_present, // fbo reset after present
294  platform_dispatch_table, // embedder platform dispatch table
295  std::move(external_view_embedder) // external view embedder
296  );
297  });
298 #else
299  return nullptr;
300 #endif
301 }
double skewY
vertical skew factor
Definition: embedder.h:238
uint32_t fbo_id
Id of the fbo backing the surface that was presented.
Definition: embedder.h:377
TransformationCallback surface_transformation
Definition: embedder.h:422
double skewX
horizontal skew factor
Definition: embedder.h:234
double pers1
input y-axis perspective factor
Definition: embedder.h:246
double pers2
perspective scale factor
Definition: embedder.h:248
uint32_t width
Definition: embedder.h:327
const TaskRunners & GetTaskRunners() const override
If callers wish to interact directly with any shell subcomponents, they must (on the platform thread)...
Definition: shell.cc:669
double pers0
input x-axis perspective factor
Definition: embedder.h:244
void * user_data
BoolPresentInfoCallback present_with_info
Definition: embedder.h:442
UIntFrameInfoCallback fbo_with_frame_info_callback
Definition: embedder.h:436
std::function< void *(const char *)> GLProcResolver
#define SAFE_ACCESS(pointer, member, default_value)
double scaleY
vertical scale factor
Definition: embedder.h:240
FlutterUIntSize size
The size of the surface that will be backed by the fbo.
Definition: embedder.h:362
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition: make_copyable.h:57
size_t struct_size
The size of this struct. Must be sizeof(FlutterFrameInfo).
Definition: embedder.h:360
FlutterRendererType type
Definition: embedder.h:554
double transX
horizontal translation
Definition: embedder.h:236
BoolCallback make_resource_current
Definition: embedder.h:406
BoolCallback clear_current
Definition: embedder.h:389
BoolCallback make_current
Definition: embedder.h:388
FlutterOpenGLRendererConfig open_gl
Definition: embedder.h:556
size_t struct_size
The size of this struct. Must be sizeof(FlutterFrameInfo).
Definition: embedder.h:375
UIntCallback fbo_callback
Definition: embedder.h:399
double transY
vertical translation
Definition: embedder.h:242
ProcResolver gl_proc_resolver
Definition: embedder.h:423
double scaleX
horizontal scale factor
Definition: embedder.h:232

◆ InferPlatformViewCreationCallback()

static flutter::Shell::CreateCallback<flutter::PlatformView> InferPlatformViewCreationCallback ( const FlutterRendererConfig config,
void *  user_data,
flutter::PlatformViewEmbedder::PlatformDispatchTable  platform_dispatch_table,
std::unique_ptr< flutter::EmbedderExternalViewEmbedder external_view_embedder 
)
static

Definition at line 409 of file embedder.cc.

References InferMetalPlatformViewCreationCallback(), InferOpenGLPlatformViewCreationCallback(), InferSoftwarePlatformViewCreationCallback(), kMetal, kOpenGL, kSoftware, and FlutterRendererConfig::type.

Referenced by FlutterEngineInitialize().

415  {
416  if (config == nullptr) {
417  return nullptr;
418  }
419 
420  switch (config->type) {
421  case kOpenGL:
423  config, user_data, platform_dispatch_table,
424  std::move(external_view_embedder));
425  case kSoftware:
427  config, user_data, platform_dispatch_table,
428  std::move(external_view_embedder));
429  case kMetal:
431  config, user_data, platform_dispatch_table,
432  std::move(external_view_embedder));
433  default:
434  return nullptr;
435  }
436  return nullptr;
437 }
static flutter::Shell::CreateCallback< flutter::PlatformView > InferSoftwarePlatformViewCreationCallback(const FlutterRendererConfig *config, void *user_data, flutter::PlatformViewEmbedder::PlatformDispatchTable platform_dispatch_table, std::unique_ptr< flutter::EmbedderExternalViewEmbedder > external_view_embedder)
Definition: embedder.cc:372
void * user_data
FlutterRendererType type
Definition: embedder.h:554
static flutter::Shell::CreateCallback< flutter::PlatformView > InferMetalPlatformViewCreationCallback(const FlutterRendererConfig *config, void *user_data, flutter::PlatformViewEmbedder::PlatformDispatchTable platform_dispatch_table, std::unique_ptr< flutter::EmbedderExternalViewEmbedder > external_view_embedder)
Definition: embedder.cc:304
static flutter::Shell::CreateCallback< flutter::PlatformView > InferOpenGLPlatformViewCreationCallback(const FlutterRendererConfig *config, void *user_data, flutter::PlatformViewEmbedder::PlatformDispatchTable platform_dispatch_table, std::unique_ptr< flutter::EmbedderExternalViewEmbedder > external_view_embedder)
Definition: embedder.cc:180

◆ InferSoftwarePlatformViewCreationCallback()

static flutter::Shell::CreateCallback<flutter::PlatformView> InferSoftwarePlatformViewCreationCallback ( const FlutterRendererConfig config,
void *  user_data,
flutter::PlatformViewEmbedder::PlatformDispatchTable  platform_dispatch_table,
std::unique_ptr< flutter::EmbedderExternalViewEmbedder external_view_embedder 
)
static

Definition at line 372 of file embedder.cc.

References flutter::Shell::GetTaskRunners(), height, kSoftware, fml::MakeCopyable(), FlutterRendererConfig::software, FlutterSoftwareRendererConfig::surface_present_callback, FlutterRendererConfig::type, and user_data.

Referenced by InferPlatformViewCreationCallback().

378  {
379  if (config->type != kSoftware) {
380  return nullptr;
381  }
382 
383  auto software_present_backing_store =
385  const void* allocation, size_t row_bytes, size_t height) -> bool {
386  return ptr(user_data, allocation, row_bytes, height);
387  };
388 
390  software_dispatch_table = {
391  software_present_backing_store, // required
392  };
393 
394  return fml::MakeCopyable(
395  [software_dispatch_table, platform_dispatch_table,
396  external_view_embedder =
397  std::move(external_view_embedder)](flutter::Shell& shell) mutable {
398  return std::make_unique<flutter::PlatformViewEmbedder>(
399  shell, // delegate
400  shell.GetTaskRunners(), // task runners
401  software_dispatch_table, // software dispatch table
402  platform_dispatch_table, // platform dispatch table
403  std::move(external_view_embedder) // external view embedder
404  );
405  });
406 }
FlutterSoftwareRendererConfig software
Definition: embedder.h:557
const TaskRunners & GetTaskRunners() const override
If callers wish to interact directly with any shell subcomponents, they must (on the platform thread)...
Definition: shell.cc:669
void * user_data
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition: make_copyable.h:57
FlutterRendererType type
Definition: embedder.h:554
int32_t height
SoftwareSurfacePresentCallback surface_present_callback
Definition: embedder.h:550

◆ IsMetalRendererConfigValid()

static bool IsMetalRendererConfigValid ( const FlutterRendererConfig config)
static

Definition at line 129 of file embedder.cc.

References kMetal, FlutterRendererConfig::metal, SAFE_ACCESS, and FlutterRendererConfig::type.

Referenced by IsRendererValid().

129  {
130  if (config->type != kMetal) {
131  return false;
132  }
133 
134  const FlutterMetalRendererConfig* metal_config = &config->metal;
135 
136  bool device = SAFE_ACCESS(metal_config, device, nullptr);
137  bool command_queue =
138  SAFE_ACCESS(metal_config, present_command_queue, nullptr);
139 
140  bool present = SAFE_ACCESS(metal_config, present_drawable_callback, nullptr);
141  bool get_texture =
142  SAFE_ACCESS(metal_config, get_next_drawable_callback, nullptr);
143 
144  return device && command_queue && present && get_texture;
145 }
#define SAFE_ACCESS(pointer, member, default_value)
FlutterRendererType type
Definition: embedder.h:554
FlutterMetalRendererConfig metal
Definition: embedder.h:558

◆ IsOpenGLRendererConfigValid()

static bool IsOpenGLRendererConfigValid ( const FlutterRendererConfig config)
static

Definition at line 96 of file embedder.cc.

References kOpenGL, FlutterRendererConfig::open_gl, SAFE_EXISTS, SAFE_EXISTS_ONE_OF, and FlutterRendererConfig::type.

Referenced by IsRendererValid().

96  {
97  if (config->type != kOpenGL) {
98  return false;
99  }
100 
101  const FlutterOpenGLRendererConfig* open_gl_config = &config->open_gl;
102 
103  if (!SAFE_EXISTS(open_gl_config, make_current) ||
104  !SAFE_EXISTS(open_gl_config, clear_current) ||
105  !SAFE_EXISTS_ONE_OF(open_gl_config, fbo_callback,
106  fbo_with_frame_info_callback) ||
107  !SAFE_EXISTS_ONE_OF(open_gl_config, present, present_with_info)) {
108  return false;
109  }
110 
111  return true;
112 }
FlutterRendererType type
Definition: embedder.h:554
FlutterOpenGLRendererConfig open_gl
Definition: embedder.h:556
#define SAFE_EXISTS(pointer, member)
Checks if the member exists and is non-null.
#define SAFE_EXISTS_ONE_OF(pointer, member1, member2)
Checks if exactly one of member1 or member2 exists and is non-null.

◆ IsRendererValid()

static bool IsRendererValid ( const FlutterRendererConfig config)
static

Definition at line 147 of file embedder.cc.

References fml::NativeLibrary::Create(), fml::NativeLibrary::CreateForCurrentProcess(), IsMetalRendererConfigValid(), IsOpenGLRendererConfigValid(), IsSoftwareRendererConfigValid(), kMetal, kOpenGL, kSoftware, name, fml::NativeLibrary::ResolveSymbol(), and FlutterRendererConfig::type.

Referenced by FlutterEngineInitialize().

147  {
148  if (config == nullptr) {
149  return false;
150  }
151 
152  switch (config->type) {
153  case kOpenGL:
154  return IsOpenGLRendererConfigValid(config);
155  case kSoftware:
156  return IsSoftwareRendererConfigValid(config);
157  case kMetal:
158  return IsMetalRendererConfigValid(config);
159  default:
160  return false;
161  }
162 
163  return false;
164 }
static bool IsMetalRendererConfigValid(const FlutterRendererConfig *config)
Definition: embedder.cc:129
static bool IsSoftwareRendererConfigValid(const FlutterRendererConfig *config)
Definition: embedder.cc:114
FlutterRendererType type
Definition: embedder.h:554
static bool IsOpenGLRendererConfigValid(const FlutterRendererConfig *config)
Definition: embedder.cc:96

◆ IsSoftwareRendererConfigValid()

static bool IsSoftwareRendererConfigValid ( const FlutterRendererConfig config)
static

Definition at line 114 of file embedder.cc.

References kSoftware, SAFE_ACCESS, FlutterRendererConfig::software, and FlutterRendererConfig::type.

Referenced by IsRendererValid().

114  {
115  if (config->type != kSoftware) {
116  return false;
117  }
118 
119  const FlutterSoftwareRendererConfig* software_config = &config->software;
120 
121  if (SAFE_ACCESS(software_config, surface_present_callback, nullptr) ==
122  nullptr) {
123  return false;
124  }
125 
126  return true;
127 }
FlutterSoftwareRendererConfig software
Definition: embedder.h:557
#define SAFE_ACCESS(pointer, member, default_value)
FlutterRendererType type
Definition: embedder.h:554

◆ LogEmbedderError()

static FlutterEngineResult LogEmbedderError ( FlutterEngineResult  code,
const char *  reason,
const char *  code_name,
const char *  function,
const char *  file,
int  line 
)
static

Definition at line 72 of file embedder.cc.

References error.

77  {
78 #if OS_WIN
79  constexpr char kSeparator = '\\';
80 #else
81  constexpr char kSeparator = '/';
82 #endif
83  const auto file_base =
84  (::strrchr(file, kSeparator) ? strrchr(file, kSeparator) + 1 : file);
85  char error[256] = {};
86  snprintf(error, (sizeof(error) / sizeof(char)),
87  "%s (%d): '%s' returned '%s'. %s", file_base, line, function,
88  code_name, reason);
89  std::cerr << error << std::endl;
90  return code;
91 }
const uint8_t uint32_t uint32_t GError ** error

◆ MakeSkSurfaceFromBackingStore() [1/4]

static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore ( GrDirectContext *  context,
const FlutterBackingStoreConfig config,
const FlutterOpenGLTexture texture 
)
static

Definition at line 439 of file embedder.cc.

References FlutterOpenGLTexture::destruction_callback, FML_LOG, FlutterOpenGLTexture::format, FlutterSize::height, FlutterOpenGLTexture::name, FlutterBackingStoreConfig::size, FlutterOpenGLTexture::target, FlutterOpenGLTexture::user_data, and FlutterSize::width.

Referenced by CreateEmbedderRenderTarget().

442  {
443 #ifdef SHELL_ENABLE_GL
444  GrGLTextureInfo texture_info;
445  texture_info.fTarget = texture->target;
446  texture_info.fID = texture->name;
447  texture_info.fFormat = texture->format;
448 
449  GrBackendTexture backend_texture(config.size.width, //
450  config.size.height, //
451  GrMipMapped::kNo, //
452  texture_info //
453  );
454 
455  SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
456 
457  auto surface = SkSurface::MakeFromBackendTexture(
458  context, // context
459  backend_texture, // back-end texture
460  kBottomLeft_GrSurfaceOrigin, // surface origin
461  1, // sample count
462  kN32_SkColorType, // color type
463  SkColorSpace::MakeSRGB(), // color space
464  &surface_properties, // surface properties
465  static_cast<SkSurface::TextureReleaseProc>(
466  texture->destruction_callback), // release proc
467  texture->user_data // release context
468  );
469 
470  if (!surface) {
471  FML_LOG(ERROR) << "Could not wrap embedder supplied render texture.";
472  return nullptr;
473  }
474 
475  return surface;
476 #else
477  return nullptr;
478 #endif
479 }
#define FML_LOG(severity)
Definition: logging.h:65
VoidCallback destruction_callback
Definition: embedder.h:274
double width
Definition: embedder.h:319
double height
Definition: embedder.h:320
uint32_t name
The name of the texture.
Definition: embedder.h:267
FlutterSize size
The size of the render target the engine expects to render into.
Definition: embedder.h:1078
void * user_data
User data to be returned on the invocation of the destruction callback.
Definition: embedder.h:271
uint32_t format
The texture format (example GL_RGBA8).
Definition: embedder.h:269

◆ MakeSkSurfaceFromBackingStore() [2/4]

static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore ( GrDirectContext *  context,
const FlutterBackingStoreConfig config,
const FlutterOpenGLFramebuffer framebuffer 
)
static

Definition at line 481 of file embedder.cc.

References FlutterOpenGLFramebuffer::destruction_callback, FML_LOG, FlutterSize::height, FlutterOpenGLFramebuffer::name, FlutterBackingStoreConfig::size, FlutterOpenGLFramebuffer::target, FlutterOpenGLFramebuffer::user_data, and FlutterSize::width.

484  {
485 #ifdef SHELL_ENABLE_GL
486  GrGLFramebufferInfo framebuffer_info = {};
487  framebuffer_info.fFormat = framebuffer->target;
488  framebuffer_info.fFBOID = framebuffer->name;
489 
490  GrBackendRenderTarget backend_render_target(
491  config.size.width, // width
492  config.size.height, // height
493  1, // sample count
494  0, // stencil bits
495  framebuffer_info // framebuffer info
496  );
497 
498  SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
499 
500  auto surface = SkSurface::MakeFromBackendRenderTarget(
501  context, // context
502  backend_render_target, // backend render target
503  kBottomLeft_GrSurfaceOrigin, // surface origin
504  kN32_SkColorType, // color type
505  SkColorSpace::MakeSRGB(), // color space
506  &surface_properties, // surface properties
507  static_cast<SkSurface::RenderTargetReleaseProc>(
508  framebuffer->destruction_callback), // release proc
509  framebuffer->user_data // release context
510  );
511 
512  if (!surface) {
513  FML_LOG(ERROR) << "Could not wrap embedder supplied frame-buffer.";
514  return nullptr;
515  }
516  return surface;
517 #else
518  return nullptr;
519 #endif
520 }
#define FML_LOG(severity)
Definition: logging.h:65
VoidCallback destruction_callback
Definition: embedder.h:299
double width
Definition: embedder.h:319
double height
Definition: embedder.h:320
FlutterSize size
The size of the render target the engine expects to render into.
Definition: embedder.h:1078
void * user_data
User data to be returned on the invocation of the destruction callback.
Definition: embedder.h:295
uint32_t name
The name of the framebuffer.
Definition: embedder.h:292

◆ MakeSkSurfaceFromBackingStore() [3/4]

static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore ( GrDirectContext *  context,
const FlutterBackingStoreConfig config,
const FlutterSoftwareBackingStore software 
)
static

Definition at line 522 of file embedder.cc.

References FlutterSoftwareBackingStore::allocation, FlutterSoftwareBackingStore::destruction_callback, FML_LOG, FlutterSize::height, FlutterSoftwareBackingStore::row_bytes, FlutterBackingStoreConfig::size, user_data, FlutterSoftwareBackingStore::user_data, and FlutterSize::width.

525  {
526  const auto image_info =
527  SkImageInfo::MakeN32Premul(config.size.width, config.size.height);
528 
529  struct Captures {
530  VoidCallback destruction_callback;
531  void* user_data;
532  };
533  auto captures = std::make_unique<Captures>();
534  captures->destruction_callback = software->destruction_callback;
535  captures->user_data = software->user_data;
536  auto release_proc = [](void* pixels, void* context) {
537  auto captures = reinterpret_cast<Captures*>(context);
538  if (captures->destruction_callback) {
539  captures->destruction_callback(captures->user_data);
540  }
541  };
542 
543  auto surface = SkSurface::MakeRasterDirectReleaseProc(
544  image_info, // image info
545  const_cast<void*>(software->allocation), // pixels
546  software->row_bytes, // row bytes
547  release_proc, // release proc
548  captures.release() // release context
549  );
550 
551  if (!surface) {
552  FML_LOG(ERROR)
553  << "Could not wrap embedder supplied software render buffer.";
554  if (software->destruction_callback) {
555  software->destruction_callback(software->user_data);
556  }
557  return nullptr;
558  }
559  return surface;
560 }
void * user_data
#define FML_LOG(severity)
Definition: logging.h:65
VoidCallback destruction_callback
Definition: embedder.h:977
size_t row_bytes
The number of bytes in a single row of the allocation.
Definition: embedder.h:968
double width
Definition: embedder.h:319
double height
Definition: embedder.h:320
void(* VoidCallback)(void *)
Definition: embedder.h:251
FlutterSize size
The size of the render target the engine expects to render into.
Definition: embedder.h:1078

◆ MakeSkSurfaceFromBackingStore() [4/4]

static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore ( GrDirectContext *  context,
const FlutterBackingStoreConfig config,
const FlutterMetalBackingStore metal 
)
static

Definition at line 562 of file embedder.cc.

References FlutterMetalTexture::destruction_callback, FML_LOG, FlutterSize::height, FlutterBackingStoreConfig::size, FlutterMetalTexture::texture, FlutterMetalBackingStore::texture, FlutterMetalTexture::user_data, and FlutterSize::width.

565  {
566 #ifdef SHELL_ENABLE_METAL
567  GrMtlTextureInfo texture_info;
568  if (!metal->texture.texture) {
569  FML_LOG(ERROR) << "Embedder supplied null Metal texture.";
570  return nullptr;
571  }
572  sk_cf_obj<FlutterMetalTextureHandle> mtl_texture;
573  mtl_texture.retain(metal->texture.texture);
574  texture_info.fTexture = mtl_texture;
575  GrBackendTexture backend_texture(config.size.width, //
576  config.size.height, //
577  GrMipMapped::kNo, //
578  texture_info //
579  );
580 
581  SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
582 
583  auto surface = SkSurface::MakeFromBackendTexture(
584  context, // context
585  backend_texture, // back-end texture
586  kTopLeft_GrSurfaceOrigin, // surface origin
587  1, // sample count
588  kBGRA_8888_SkColorType, // color type
589  nullptr, // color space
590  &surface_properties, // surface properties
591  static_cast<SkSurface::TextureReleaseProc>(
592  metal->texture.destruction_callback), // release proc
593  metal->texture.user_data // release context
594  );
595 
596  if (!surface) {
597  FML_LOG(ERROR) << "Could not wrap embedder supplied Metal render texture.";
598  return nullptr;
599  }
600 
601  return surface;
602 #else
603  return nullptr;
604 #endif
605 }
#define FML_LOG(severity)
Definition: logging.h:65
FlutterMetalTexture texture
Definition: embedder.h:987
VoidCallback destruction_callback
Definition: embedder.h:508
double width
Definition: embedder.h:319
FlutterMetalTextureHandle texture
Definition: embedder.h:501
double height
Definition: embedder.h:320
FlutterSize size
The size of the render target the engine expects to render into.
Definition: embedder.h:1078

◆ MapKeyEventType()

◆ PointerDataButtonsForLegacyEvent()

◆ PopulateSnapshotMappingCallbacks()

void PopulateSnapshotMappingCallbacks ( const FlutterProjectArgs args,
flutter::Settings settings 
)

Definition at line 813 of file embedder.cc.

References FlutterProjectArgs::aot_data, flutter::Settings::dart_library_sources_kernel, flutter::Settings::isolate_snapshot_data, FlutterProjectArgs::isolate_snapshot_data, flutter::Settings::isolate_snapshot_instr, FlutterProjectArgs::isolate_snapshot_instructions, flutter::DartVM::IsRunningPrecompiledCode(), kPlatformStrongDill, kPlatformStrongDillSize, SAFE_ACCESS, fml::size(), _FlutterEngineAOTData::vm_isolate_data, _FlutterEngineAOTData::vm_isolate_instrs, flutter::Settings::vm_snapshot_data, _FlutterEngineAOTData::vm_snapshot_data, FlutterProjectArgs::vm_snapshot_data, flutter::Settings::vm_snapshot_instr, _FlutterEngineAOTData::vm_snapshot_instrs, and FlutterProjectArgs::vm_snapshot_instructions.

Referenced by FlutterEngineInitialize().

815  { // NOLINT(google-runtime-references)
816  // There are no ownership concerns here as all mappings are owned by the
817  // embedder and not the engine.
818  auto make_mapping_callback = [](const uint8_t* mapping, size_t size) {
819  return [mapping, size]() {
820  return std::make_unique<fml::NonOwnedMapping>(mapping, size);
821  };
822  };
823 
825  if (SAFE_ACCESS(args, aot_data, nullptr) != nullptr) {
826  settings.vm_snapshot_data =
827  make_mapping_callback(args->aot_data->vm_snapshot_data, 0);
828 
829  settings.vm_snapshot_instr =
830  make_mapping_callback(args->aot_data->vm_snapshot_instrs, 0);
831 
832  settings.isolate_snapshot_data =
833  make_mapping_callback(args->aot_data->vm_isolate_data, 0);
834 
835  settings.isolate_snapshot_instr =
836  make_mapping_callback(args->aot_data->vm_isolate_instrs, 0);
837  }
838 
839  if (SAFE_ACCESS(args, vm_snapshot_data, nullptr) != nullptr) {
840  settings.vm_snapshot_data = make_mapping_callback(
841  args->vm_snapshot_data, SAFE_ACCESS(args, vm_snapshot_data_size, 0));
842  }
843 
844  if (SAFE_ACCESS(args, vm_snapshot_instructions, nullptr) != nullptr) {
845  settings.vm_snapshot_instr = make_mapping_callback(
847  SAFE_ACCESS(args, vm_snapshot_instructions_size, 0));
848  }
849 
850  if (SAFE_ACCESS(args, isolate_snapshot_data, nullptr) != nullptr) {
851  settings.isolate_snapshot_data = make_mapping_callback(
852  args->isolate_snapshot_data,
853  SAFE_ACCESS(args, isolate_snapshot_data_size, 0));
854  }
855 
856  if (SAFE_ACCESS(args, isolate_snapshot_instructions, nullptr) != nullptr) {
857  settings.isolate_snapshot_instr = make_mapping_callback(
859  SAFE_ACCESS(args, isolate_snapshot_instructions_size, 0));
860  }
861  }
862 
863 #if !OS_FUCHSIA && (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG)
864  settings.dart_library_sources_kernel =
865  make_mapping_callback(kPlatformStrongDill, kPlatformStrongDillSize);
866 #endif // !OS_FUCHSIA && (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG)
867 }
MappingCallback isolate_snapshot_instr
Definition: settings.h:108
const uint8_t * isolate_snapshot_data
Definition: embedder.h:1421
const uint8_t kPlatformStrongDill[]
const uint8_t * vm_isolate_data
Definition: embedder.cc:744
const intptr_t kPlatformStrongDillSize
MappingCallback vm_snapshot_data
Definition: settings.h:101
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
#define SAFE_ACCESS(pointer, member, default_value)
const uint8_t * vm_snapshot_instrs
Definition: embedder.cc:743
static bool IsRunningPrecompiledCode()
Checks if VM instances in the process can run precompiled code. This call can be made at any time and...
Definition: dart_vm.cc:205
const uint8_t * vm_snapshot_data
Definition: embedder.h:1405
const uint8_t * vm_snapshot_instructions
Definition: embedder.h:1413
MappingCallback isolate_snapshot_data
Definition: settings.h:106
const uint8_t * vm_isolate_instrs
Definition: embedder.cc:745
MappingCallback dart_library_sources_kernel
Definition: settings.h:112
MappingCallback vm_snapshot_instr
Definition: settings.h:103
FlutterEngineAOTData aot_data
Definition: embedder.h:1541
const uint8_t * isolate_snapshot_instructions
Definition: embedder.h:1429
const uint8_t * vm_snapshot_data
Definition: embedder.cc:742

◆ ToPointerDataChange()

flutter::PointerData::Change ToPointerDataChange ( FlutterPointerPhase  phase)
inline

◆ ToPointerDataKind()

◆ ToPointerDataSignalKind()

Variable Documentation

◆ kFlutterSemanticsCustomActionIdBatchEnd

const int32_t kFlutterSemanticsCustomActionIdBatchEnd = -1

FlutterSemanticsCustomAction ID used as a sentinel to signal the end of a batch of semantics custom action updates.

Definition at line 70 of file embedder.cc.

Referenced by fl_view_accessible_handle_update_semantics_node(), FlutterEngineInitialize(), and flutter::testing::TEST_F().

◆ kFlutterSemanticsNodeIdBatchEnd

const int32_t kFlutterSemanticsNodeIdBatchEnd = -1

FlutterSemanticsNode ID used as a sentinel to signal the end of a batch of semantics node updates.

Definition at line 69 of file embedder.cc.

Referenced by FlutterEngineInitialize(), FlutterEngine::shutDownEngine, and flutter::testing::TEST_F().

◆ kPlatformStrongDill

const uint8_t kPlatformStrongDill[]

◆ kPlatformStrongDillSize

const intptr_t kPlatformStrongDillSize