Flutter Engine
 
Loading...
Searching...
No Matches
embedder.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#define FML_USED_ON_EMBEDDER
6#define RAPIDJSON_HAS_STDSTRING 1
7
8#include <cstring>
9#include <iostream>
10#include <memory>
11#include <set>
12#include <string>
13#include <vector>
14
16#include "flutter/fml/closure.h"
20#include "flutter/fml/thread.h"
21#include "third_party/dart/runtime/bin/elf_loader.h"
22#include "third_party/dart/runtime/include/dart_native_api.h"
23#include "third_party/skia/include/core/SkSurface.h"
24#include "third_party/skia/include/gpu/GpuTypes.h"
25#include "third_party/skia/include/gpu/ganesh/GrBackendSurface.h"
26#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
27
28#if !defined(FLUTTER_NO_EXPORT)
29#if FML_OS_WIN
30#define FLUTTER_EXPORT __declspec(dllexport)
31#else // FML_OS_WIN
32#define FLUTTER_EXPORT __attribute__((visibility("default")))
33#endif // FML_OS_WIN
34#endif // !FLUTTER_NO_EXPORT
35
36extern "C" {
37#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
38// Used for debugging dart:* sources.
39extern const uint8_t kPlatformStrongDill[];
40extern const intptr_t kPlatformStrongDillSize;
41#endif // FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
42}
43
48#include "flutter/fml/file.h"
51#include "flutter/fml/paths.h"
67#include "rapidjson/rapidjson.h"
68#include "rapidjson/writer.h"
69
70// Note: the IMPELLER_SUPPORTS_RENDERING may be defined even when the
71// embedder/BUILD.gn variable impeller_supports_rendering is disabled.
72#ifdef SHELL_ENABLE_GL
74#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h"
75#include "third_party/skia/include/gpu/ganesh/gl/GrGLTypes.h"
76#ifdef IMPELLER_SUPPORTS_RENDERING
80#include "impeller/core/texture.h" // nogncheck
83#include "impeller/renderer/context.h" // nogncheck
84#include "impeller/renderer/render_target.h" // nogncheck
85#endif // IMPELLER_SUPPORTS_RENDERING
86#endif // SHELL_ENABLE_GL
87
88#ifdef SHELL_ENABLE_METAL
90#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlBackendSurface.h"
91#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlTypes.h"
92#include "third_party/skia/include/ports/SkCFObject.h"
93#ifdef IMPELLER_SUPPORTS_RENDERING
96#include "impeller/core/texture.h" // nogncheck
98#include "impeller/renderer/render_target.h" // nogncheck
99#endif // IMPELLER_SUPPORTS_RENDERING
100#endif // SHELL_ENABLE_METAL
101
102#ifdef SHELL_ENABLE_VULKAN
103#include "third_party/skia/include/gpu/ganesh/vk/GrVkBackendSurface.h"
104#include "third_party/skia/include/gpu/ganesh/vk/GrVkTypes.h"
105#endif // SHELL_ENABLE_VULKAN
106
109
111
112// A message channel to send platform-independent FlutterKeyData to the
113// framework.
114//
115// This should be kept in sync with the following variables:
116//
117// - lib/ui/platform_dispatcher.dart, _kFlutterKeyDataChannel
118// - shell/platform/darwin/ios/framework/Source/FlutterEngine.mm,
119// FlutterKeyDataChannel
120// - io/flutter/embedding/android/KeyData.java,
121// CHANNEL
122//
123// Not to be confused with "flutter/keyevent", which is used to send raw
124// key event data in a platform-dependent format.
125//
126// ## Format
127//
128// Send: KeyDataPacket.data().
129//
130// Expected reply: Whether the event is handled. Exactly 1 byte long, with value
131// 1 for handled, and 0 for not. Malformed value is considered false.
132const char* kFlutterKeyDataChannel = "flutter/keydata";
133
135 const char* reason,
136 const char* code_name,
137 const char* function,
138 const char* file,
139 int line) {
140#if FML_OS_WIN
141 constexpr char kSeparator = '\\';
142#else
143 constexpr char kSeparator = '/';
144#endif
145 const auto file_base =
146 (::strrchr(file, kSeparator) ? strrchr(file, kSeparator) + 1 : file);
147 char error[256] = {};
148 snprintf(error, (sizeof(error) / sizeof(char)),
149 "%s (%d): '%s' returned '%s'. %s", file_base, line, function,
150 code_name, reason);
151 std::cerr << error << std::endl;
152 return code;
153}
154
155#define LOG_EMBEDDER_ERROR(code, reason) \
156 LogEmbedderError(code, reason, #code, __FUNCTION__, __FILE__, __LINE__)
157
159 if (config->type != kOpenGL) {
160 return false;
161 }
162
163 const FlutterOpenGLRendererConfig* open_gl_config = &config->open_gl;
164
165 if (!SAFE_EXISTS(open_gl_config, make_current) ||
166 !SAFE_EXISTS(open_gl_config, clear_current) ||
167 !SAFE_EXISTS_ONE_OF(open_gl_config, fbo_callback,
168 fbo_with_frame_info_callback) ||
169 !SAFE_EXISTS_ONE_OF(open_gl_config, present, present_with_info)) {
170 return false;
171 }
172
173 return true;
174}
175
177 if (config->type != kSoftware) {
178 return false;
179 }
180
181 const FlutterSoftwareRendererConfig* software_config = &config->software;
182
183 if (SAFE_ACCESS(software_config, surface_present_callback, nullptr) ==
184 nullptr) {
185 return false;
186 }
187
188 return true;
189}
190
192 if (config->type != kMetal) {
193 return false;
194 }
195
196 const FlutterMetalRendererConfig* metal_config = &config->metal;
197
198 bool device = SAFE_ACCESS(metal_config, device, nullptr);
199 bool command_queue =
200 SAFE_ACCESS(metal_config, present_command_queue, nullptr);
201
202 bool present = SAFE_ACCESS(metal_config, present_drawable_callback, nullptr);
203 bool get_texture =
204 SAFE_ACCESS(metal_config, get_next_drawable_callback, nullptr);
205
206 return device && command_queue && present && get_texture;
207}
208
210 if (config->type != kVulkan) {
211 return false;
212 }
213
214 const FlutterVulkanRendererConfig* vulkan_config = &config->vulkan;
215
216 if (!SAFE_EXISTS(vulkan_config, instance) ||
217 !SAFE_EXISTS(vulkan_config, physical_device) ||
218 !SAFE_EXISTS(vulkan_config, device) ||
219 !SAFE_EXISTS(vulkan_config, queue) ||
220 !SAFE_EXISTS(vulkan_config, get_instance_proc_address_callback) ||
221 !SAFE_EXISTS(vulkan_config, get_next_image_callback) ||
222 !SAFE_EXISTS(vulkan_config, present_image_callback)) {
223 return false;
224 }
225
226 return true;
227}
228
229static bool IsRendererValid(const FlutterRendererConfig* config) {
230 if (config == nullptr) {
231 return false;
232 }
233
234 switch (config->type) {
235 case kOpenGL:
236 return IsOpenGLRendererConfigValid(config);
237 case kSoftware:
238 return IsSoftwareRendererConfigValid(config);
239 case kMetal:
240 return IsMetalRendererConfigValid(config);
241 case kVulkan:
242 return IsVulkanRendererConfigValid(config);
243 default:
244 return false;
245 }
246
247 return false;
248}
249
250#if FML_OS_LINUX || FML_OS_WIN
251static void* DefaultGLProcResolver(const char* name) {
252 static fml::RefPtr<fml::NativeLibrary> proc_library =
253#if FML_OS_LINUX
255#elif FML_OS_WIN // FML_OS_LINUX
256 fml::NativeLibrary::Create("opengl32.dll");
257#endif // FML_OS_WIN
258 return static_cast<void*>(
259 const_cast<uint8_t*>(proc_library->ResolveSymbol(name)));
260}
261#endif // FML_OS_LINUX || FML_OS_WIN
262
263#ifdef SHELL_ENABLE_GL
264// Auxiliary function used to translate rectangles of type SkIRect to
265// FlutterRect.
266static FlutterRect DlIRectToFlutterRect(const flutter::DlIRect& dl_rect) {
267 FlutterRect flutter_rect = {static_cast<double>(dl_rect.GetLeft()),
268 static_cast<double>(dl_rect.GetTop()),
269 static_cast<double>(dl_rect.GetRight()),
270 static_cast<double>(dl_rect.GetBottom())};
271 return flutter_rect;
272}
273
274// Auxiliary function used to translate rectangles of type FlutterRect to
275// SkIRect.
276static const flutter::DlIRect FlutterRectToDlIRect(FlutterRect flutter_rect) {
277 return flutter::DlIRect::MakeLTRB(static_cast<int32_t>(flutter_rect.left),
278 static_cast<int32_t>(flutter_rect.top),
279 static_cast<int32_t>(flutter_rect.right),
280 static_cast<int32_t>(flutter_rect.bottom));
281}
282
283// We need GL_BGRA8_EXT for creating SkSurfaces from FlutterOpenGLSurfaces
284// below.
285#ifndef GL_BGRA8_EXT
286#define GL_BGRA8_EXT 0x93A1
287#endif
288
289static std::optional<SkColorType> FlutterFormatToSkColorType(uint32_t format) {
290 switch (format) {
291 case GL_BGRA8_EXT:
292 return kBGRA_8888_SkColorType;
293 case GL_RGBA8:
294 return kRGBA_8888_SkColorType;
295 default:
296 FML_LOG(ERROR) << "Cannot convert format " << format
297 << " to SkColorType.";
298 return std::nullopt;
299 }
300}
301
302#endif
303
306 const FlutterRendererConfig* config,
307 void* user_data,
309 platform_dispatch_table,
310 std::unique_ptr<flutter::EmbedderExternalViewEmbedder>
311 external_view_embedder,
312 bool enable_impeller) {
313#ifdef SHELL_ENABLE_GL
314 if (config->type != kOpenGL) {
315 return nullptr;
316 }
317
318 auto gl_make_current = [ptr = config->open_gl.make_current,
319 user_data]() -> bool { return ptr(user_data); };
320
321 auto gl_clear_current = [ptr = config->open_gl.clear_current,
322 user_data]() -> bool { return ptr(user_data); };
323
324 auto gl_present =
325 [present = config->open_gl.present,
326 present_with_info = config->open_gl.present_with_info,
327 user_data](flutter::GLPresentInfo gl_present_info) -> bool {
328 if (present) {
329 return present(user_data);
330 } else {
331 // Format the frame and buffer damages accordingly. Note that, since the
332 // current compute damage algorithm only returns one rectangle for damage
333 // we are assuming the number of rectangles provided in frame and buffer
334 // damage are always 1. Once the function that computes damage implements
335 // support for multiple damage rectangles, GLPresentInfo should also
336 // contain the number of damage rectangles.
337
338 std::optional<FlutterRect> frame_damage_rect;
339 if (gl_present_info.frame_damage) {
340 frame_damage_rect =
341 DlIRectToFlutterRect(*(gl_present_info.frame_damage));
342 }
343 std::optional<FlutterRect> buffer_damage_rect;
344 if (gl_present_info.buffer_damage) {
345 buffer_damage_rect =
346 DlIRectToFlutterRect(*(gl_present_info.buffer_damage));
347 }
348
349 FlutterDamage frame_damage{
350 .struct_size = sizeof(FlutterDamage),
351 .num_rects = frame_damage_rect ? size_t{1} : size_t{0},
352 .damage = frame_damage_rect ? &frame_damage_rect.value() : nullptr,
353 };
354 FlutterDamage buffer_damage{
355 .struct_size = sizeof(FlutterDamage),
356 .num_rects = buffer_damage_rect ? size_t{1} : size_t{0},
357 .damage = buffer_damage_rect ? &buffer_damage_rect.value() : nullptr,
358 };
359
360 // Construct the present information concerning the frame being rendered.
361 FlutterPresentInfo present_info = {
363 .fbo_id = gl_present_info.fbo_id,
364 .frame_damage = frame_damage,
365 .buffer_damage = buffer_damage,
366 };
367
368 return present_with_info(user_data, &present_info);
369 }
370 };
371
372 auto gl_fbo_callback =
373 [fbo_callback = config->open_gl.fbo_callback,
374 fbo_with_frame_info_callback =
376 user_data](flutter::GLFrameInfo gl_frame_info) -> intptr_t {
377 if (fbo_callback) {
378 return fbo_callback(user_data);
379 } else {
380 FlutterFrameInfo frame_info = {};
381 frame_info.struct_size = sizeof(FlutterFrameInfo);
382 frame_info.size = {gl_frame_info.width, gl_frame_info.height};
383 return fbo_with_frame_info_callback(user_data, &frame_info);
384 }
385 };
386
387 auto gl_populate_existing_damage =
388 [populate_existing_damage = config->open_gl.populate_existing_damage,
389 user_data](intptr_t id) -> flutter::GLFBOInfo {
390 // If no populate_existing_damage was provided, disable partial
391 // repaint.
392 if (!populate_existing_damage) {
393 return flutter::GLFBOInfo{
394 .fbo_id = static_cast<uint32_t>(id),
395 .existing_damage = std::nullopt,
396 };
397 }
398
399 // Given the FBO's ID, get its existing damage.
400 FlutterDamage existing_damage;
401 populate_existing_damage(user_data, id, &existing_damage);
402
403 std::optional<flutter::DlIRect> existing_damage_rect = std::nullopt;
404
405 // Verify that at least one damage rectangle was provided.
406 if (existing_damage.num_rects <= 0 || existing_damage.damage == nullptr) {
407 FML_LOG(INFO) << "No damage was provided. Forcing full repaint.";
408 } else {
409 existing_damage_rect = flutter::DlIRect();
410 for (size_t i = 0; i < existing_damage.num_rects; i++) {
411 existing_damage_rect = existing_damage_rect->Union(
412 FlutterRectToDlIRect(existing_damage.damage[i]));
413 }
414 }
415
416 // Pass the information about this FBO to the rendering backend.
417 return flutter::GLFBOInfo{
418 .fbo_id = static_cast<uint32_t>(id),
419 .existing_damage = existing_damage_rect,
420 };
421 };
422
423 const FlutterOpenGLRendererConfig* open_gl_config = &config->open_gl;
424 std::function<bool()> gl_make_resource_current_callback = nullptr;
425 if (SAFE_ACCESS(open_gl_config, make_resource_current, nullptr) != nullptr) {
426 gl_make_resource_current_callback =
427 [ptr = config->open_gl.make_resource_current, user_data]() {
428 return ptr(user_data);
429 };
430 }
431
432 std::function<flutter::DlMatrix(void)> gl_surface_transformation_callback =
433 nullptr;
434 if (SAFE_ACCESS(open_gl_config, surface_transformation, nullptr) != nullptr) {
435 gl_surface_transformation_callback =
436 [ptr = config->open_gl.surface_transformation, user_data]() {
437 FlutterTransformation transformation = ptr(user_data);
438 // clang-format off
439 return flutter::DlMatrix(
440 transformation.scaleX, transformation.skewY, 0.0f, transformation.pers0,
441 transformation.skewX, transformation.scaleY, 0.0f, transformation.pers1,
442 0.0f, 0.0f, 1.0f, 0.0f,
443 transformation.transX, transformation.transY, 0.0f, transformation.pers2
444 );
445 // clang-format on
446 };
447
448 // If there is an external view embedder, ask it to apply the surface
449 // transformation to its surfaces as well.
450 if (external_view_embedder) {
451 external_view_embedder->SetSurfaceTransformationCallback(
452 gl_surface_transformation_callback);
453 }
454 }
455
456 flutter::GPUSurfaceGLDelegate::GLProcResolver gl_proc_resolver = nullptr;
457 if (SAFE_ACCESS(open_gl_config, gl_proc_resolver, nullptr) != nullptr) {
458 gl_proc_resolver = [ptr = config->open_gl.gl_proc_resolver,
459 user_data](const char* gl_proc_name) {
460 return ptr(user_data, gl_proc_name);
461 };
462 } else {
463#if FML_OS_LINUX || FML_OS_WIN
464 gl_proc_resolver = DefaultGLProcResolver;
465#endif // FML_OS_LINUX || FML_OS_WIN
466 }
467
468 bool fbo_reset_after_present =
469 SAFE_ACCESS(open_gl_config, fbo_reset_after_present, false);
470
472 gl_make_current, // gl_make_current_callback
473 gl_clear_current, // gl_clear_current_callback
474 gl_present, // gl_present_callback
475 gl_fbo_callback, // gl_fbo_callback
476 gl_make_resource_current_callback, // gl_make_resource_current_callback
477 gl_surface_transformation_callback, // gl_surface_transformation_callback
478 gl_proc_resolver, // gl_proc_resolver
479 gl_populate_existing_damage, // gl_populate_existing_damage
480 };
481
482 return fml::MakeCopyable(
483 [gl_dispatch_table, fbo_reset_after_present, platform_dispatch_table,
484 enable_impeller,
485 external_view_embedder =
486 std::move(external_view_embedder)](flutter::Shell& shell) mutable {
487 std::shared_ptr<flutter::EmbedderExternalViewEmbedder> view_embedder =
488 std::move(external_view_embedder);
489 if (enable_impeller) {
490 return std::make_unique<flutter::PlatformViewEmbedder>(
491 shell, // delegate
492 shell.GetTaskRunners(), // task runners
493 std::make_unique<flutter::EmbedderSurfaceGLImpeller>(
494 gl_dispatch_table, fbo_reset_after_present,
495 view_embedder), // embedder_surface
496 platform_dispatch_table, // embedder platform dispatch table
497 view_embedder // external view embedder
498 );
499 }
500 return std::make_unique<flutter::PlatformViewEmbedder>(
501 shell, // delegate
502 shell.GetTaskRunners(), // task runners
503 std::make_unique<flutter::EmbedderSurfaceGLSkia>(
504 gl_dispatch_table, fbo_reset_after_present,
505 view_embedder), // embedder_surface
506 platform_dispatch_table, // embedder platform dispatch table
507 view_embedder // external view embedder
508 );
509 });
510#else // SHELL_ENABLE_GL
511 FML_LOG(ERROR) << "This Flutter Engine does not support OpenGL rendering.";
512 return nullptr;
513#endif // SHELL_ENABLE_GL
514}
515
518 const FlutterRendererConfig* config,
519 void* user_data,
521 platform_dispatch_table,
522 std::unique_ptr<flutter::EmbedderExternalViewEmbedder>
523 external_view_embedder,
524 bool enable_impeller) {
525 if (config->type != kMetal) {
526 return nullptr;
527 }
528
529#ifdef SHELL_ENABLE_METAL
530 std::function<bool(flutter::GPUMTLTextureInfo texture)> metal_present =
531 [ptr = config->metal.present_drawable_callback,
533 FlutterMetalTexture embedder_texture;
534 embedder_texture.struct_size = sizeof(FlutterMetalTexture);
535 embedder_texture.texture = texture.texture;
536 embedder_texture.texture_id = texture.texture_id;
537 embedder_texture.user_data = texture.destruction_context;
538 embedder_texture.destruction_callback = texture.destruction_callback;
539 return ptr(user_data, &embedder_texture);
540 };
541 auto metal_get_texture =
543 const flutter::DlISize& frame_size) -> flutter::GPUMTLTextureInfo {
544 FlutterFrameInfo frame_info = {};
545 frame_info.struct_size = sizeof(FlutterFrameInfo);
546 frame_info.size = {static_cast<uint32_t>(frame_size.width),
547 static_cast<uint32_t>(frame_size.height)};
548 flutter::GPUMTLTextureInfo texture_info;
549
550 FlutterMetalTexture metal_texture = ptr(user_data, &frame_info);
551 texture_info.texture_id = metal_texture.texture_id;
552 texture_info.texture = metal_texture.texture;
553 texture_info.destruction_callback = metal_texture.destruction_callback;
554 texture_info.destruction_context = metal_texture.user_data;
555 return texture_info;
556 };
557
558 std::shared_ptr<flutter::EmbedderExternalViewEmbedder> view_embedder =
559 std::move(external_view_embedder);
560
561 std::unique_ptr<flutter::EmbedderSurface> embedder_surface;
562
563 if (enable_impeller) {
565 metal_dispatch_table = {
566 .present = metal_present,
567 .get_texture = metal_get_texture,
568 };
569 embedder_surface = std::make_unique<flutter::EmbedderSurfaceMetalImpeller>(
570 const_cast<flutter::GPUMTLDeviceHandle>(config->metal.device),
573 metal_dispatch_table, view_embedder);
574 } else {
575#if !SLIMPELLER
577 {
578 .present = metal_present,
579 .get_texture = metal_get_texture,
580 };
581 embedder_surface = std::make_unique<flutter::EmbedderSurfaceMetalSkia>(
582 const_cast<flutter::GPUMTLDeviceHandle>(config->metal.device),
585 metal_dispatch_table, view_embedder);
586#else // !SLIMPELLER
587 FML_LOG(FATAL) << "Impeller opt-out unavailable.";
588#endif // !SLIMPELLER
589 }
590
591 // The static leak checker gets confused by the use of fml::MakeCopyable.
592 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
593 return fml::MakeCopyable(
594 [embedder_surface = std::move(embedder_surface), platform_dispatch_table,
595 external_view_embedder = view_embedder](flutter::Shell& shell) mutable {
596 return std::make_unique<flutter::PlatformViewEmbedder>(
597 shell, // delegate
598 shell.GetTaskRunners(), // task runners
599 std::move(embedder_surface), // embedder surface
600 platform_dispatch_table, // platform dispatch table
601 std::move(external_view_embedder) // external view embedder
602 );
603 });
604#else // SHELL_ENABLE_METAL
605 FML_LOG(ERROR) << "This Flutter Engine does not support Metal rendering.";
606 return nullptr;
607#endif // SHELL_ENABLE_METAL
608}
609
612 const FlutterRendererConfig* config,
613 void* user_data,
615 platform_dispatch_table,
616 std::unique_ptr<flutter::EmbedderExternalViewEmbedder>
617 external_view_embedder,
618 bool enable_impeller) {
619 if (config->type != kVulkan) {
620 return nullptr;
621 }
622
623#ifdef SHELL_ENABLE_VULKAN
624 std::function<void*(VkInstance, const char*)>
625 vulkan_get_instance_proc_address =
627 VkInstance instance, const char* proc_name) -> void* {
628 return ptr(user_data, instance, proc_name);
629 };
630
631 auto vulkan_get_next_image =
632 [ptr = config->vulkan.get_next_image_callback,
633 user_data](const flutter::DlISize& frame_size) -> FlutterVulkanImage {
634 FlutterFrameInfo frame_info = {
635 .struct_size = sizeof(FlutterFrameInfo),
636 .size = {static_cast<uint32_t>(frame_size.width),
637 static_cast<uint32_t>(frame_size.height)},
638 };
639
640 return ptr(user_data, &frame_info);
641 };
642
643 auto vulkan_present_image_callback =
644 [ptr = config->vulkan.present_image_callback, user_data](
645 VkImage image, VkFormat format) -> bool {
646 FlutterVulkanImage image_desc = {
648 .image = reinterpret_cast<uint64_t>(image),
649 .format = static_cast<uint32_t>(format),
650 };
651 return ptr(user_data, &image_desc);
652 };
653
654 auto vk_instance = static_cast<VkInstance>(config->vulkan.instance);
655 auto proc_addr =
656 vulkan_get_instance_proc_address(vk_instance, "vkGetInstanceProcAddr");
657
658 std::shared_ptr<flutter::EmbedderExternalViewEmbedder> view_embedder =
659 std::move(external_view_embedder);
660
661#if IMPELLER_SUPPORTS_RENDERING
662 if (enable_impeller) {
664 vulkan_dispatch_table = {
666 reinterpret_cast<PFN_vkGetInstanceProcAddr>(proc_addr),
667 .get_next_image = vulkan_get_next_image,
668 .present_image = vulkan_present_image_callback,
669 };
670
671 std::unique_ptr<flutter::EmbedderSurfaceVulkanImpeller> embedder_surface =
672 std::make_unique<flutter::EmbedderSurfaceVulkanImpeller>(
673 config->vulkan.version, vk_instance,
678 static_cast<VkPhysicalDevice>(config->vulkan.physical_device),
679 static_cast<VkDevice>(config->vulkan.device),
681 static_cast<VkQueue>(config->vulkan.queue), vulkan_dispatch_table,
682 view_embedder);
683
684 return fml::MakeCopyable(
685 [embedder_surface = std::move(embedder_surface),
686 platform_dispatch_table,
687 external_view_embedder =
688 std::move(view_embedder)](flutter::Shell& shell) mutable {
689 return std::make_unique<flutter::PlatformViewEmbedder>(
690 shell, // delegate
691 shell.GetTaskRunners(), // task runners
692 std::move(embedder_surface), // embedder surface
693 platform_dispatch_table, // platform dispatch table
694 std::move(external_view_embedder) // external view embedder
695 );
696 });
697 } else {
699 {
701 reinterpret_cast<PFN_vkGetInstanceProcAddr>(proc_addr),
702 .get_next_image = vulkan_get_next_image,
703 .present_image = vulkan_present_image_callback,
704 };
705
706 std::unique_ptr<flutter::EmbedderSurfaceVulkan> embedder_surface =
707 std::make_unique<flutter::EmbedderSurfaceVulkan>(
708 config->vulkan.version, vk_instance,
713 static_cast<VkPhysicalDevice>(config->vulkan.physical_device),
714 static_cast<VkDevice>(config->vulkan.device),
716 static_cast<VkQueue>(config->vulkan.queue), vulkan_dispatch_table,
717 view_embedder);
718
719 return fml::MakeCopyable(
720 [embedder_surface = std::move(embedder_surface),
721 platform_dispatch_table,
722 external_view_embedder =
723 std::move(view_embedder)](flutter::Shell& shell) mutable {
724 return std::make_unique<flutter::PlatformViewEmbedder>(
725 shell, // delegate
726 shell.GetTaskRunners(), // task runners
727 std::move(embedder_surface), // embedder surface
728 platform_dispatch_table, // platform dispatch table
729 std::move(external_view_embedder) // external view embedder
730 );
731 });
732 }
733#else
736 reinterpret_cast<PFN_vkGetInstanceProcAddr>(proc_addr),
737 .get_next_image = vulkan_get_next_image,
738 .present_image = vulkan_present_image_callback,
739 };
740
741 std::unique_ptr<flutter::EmbedderSurfaceVulkan> embedder_surface =
742 std::make_unique<flutter::EmbedderSurfaceVulkan>(
743 config->vulkan.version, vk_instance,
748 static_cast<VkPhysicalDevice>(config->vulkan.physical_device),
749 static_cast<VkDevice>(config->vulkan.device),
751 static_cast<VkQueue>(config->vulkan.queue), vulkan_dispatch_table,
752 view_embedder);
753
754 return fml::MakeCopyable(
755 [embedder_surface = std::move(embedder_surface), platform_dispatch_table,
756 external_view_embedder =
757 std::move(view_embedder)](flutter::Shell& shell) mutable {
758 return std::make_unique<flutter::PlatformViewEmbedder>(
759 shell, // delegate
760 shell.GetTaskRunners(), // task runners
761 std::move(embedder_surface), // embedder surface
762 platform_dispatch_table, // platform dispatch table
763 std::move(external_view_embedder) // external view embedder
764 );
765 });
766#endif // // IMPELLER_SUPPORTS_RENDERING
767#else // SHELL_ENABLE_VULKAN
768 FML_LOG(ERROR) << "This Flutter Engine does not support Vulkan rendering.";
769 return nullptr;
770#endif // SHELL_ENABLE_VULKAN
771}
772
775 const FlutterRendererConfig* config,
776 void* user_data,
778 platform_dispatch_table,
779 std::unique_ptr<flutter::EmbedderExternalViewEmbedder>
780 external_view_embedder) {
781 if (config->type != kSoftware) {
782 return nullptr;
783 }
784
785 auto software_present_backing_store =
787 const void* allocation, size_t row_bytes, size_t height) -> bool {
788 return ptr(user_data, allocation, row_bytes, height);
789 };
790
792 software_dispatch_table = {
793 software_present_backing_store, // required
794 };
795
796 return fml::MakeCopyable(
797 [software_dispatch_table, platform_dispatch_table,
798 external_view_embedder =
799 std::move(external_view_embedder)](flutter::Shell& shell) mutable {
800 return std::make_unique<flutter::PlatformViewEmbedder>(
801 shell, // delegate
802 shell.GetTaskRunners(), // task runners
803 software_dispatch_table, // software dispatch table
804 platform_dispatch_table, // platform dispatch table
805 std::move(external_view_embedder) // external view embedder
806 );
807 });
808}
809
812 const FlutterRendererConfig* config,
813 void* user_data,
815 platform_dispatch_table,
816 std::unique_ptr<flutter::EmbedderExternalViewEmbedder>
817 external_view_embedder,
818 bool enable_impeller) {
819 if (config == nullptr) {
820 return nullptr;
821 }
822
823 switch (config->type) {
824 case kOpenGL:
826 config, user_data, platform_dispatch_table,
827 std::move(external_view_embedder), enable_impeller);
828 case kSoftware:
830 config, user_data, platform_dispatch_table,
831 std::move(external_view_embedder));
832 case kMetal:
834 config, user_data, platform_dispatch_table,
835 std::move(external_view_embedder), enable_impeller);
836 case kVulkan:
838 config, user_data, platform_dispatch_table,
839 std::move(external_view_embedder), enable_impeller);
840 default:
841 return nullptr;
842 }
843 return nullptr;
844}
845
846static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
847 GrDirectContext* context,
848 const FlutterBackingStoreConfig& config,
850#ifdef SHELL_ENABLE_GL
851 GrGLTextureInfo texture_info;
852 texture_info.fTarget = texture->target;
853 texture_info.fID = texture->name;
854 texture_info.fFormat = texture->format;
855
856 GrBackendTexture backend_texture =
857 GrBackendTextures::MakeGL(config.size.width, config.size.height,
858 skgpu::Mipmapped::kNo, texture_info);
859
860 SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
861
862 std::optional<SkColorType> color_type =
863 FlutterFormatToSkColorType(texture->format);
864 if (!color_type) {
865 return nullptr;
866 }
867
868 auto surface = SkSurfaces::WrapBackendTexture(
869 context, // context
870 backend_texture, // back-end texture
871 kBottomLeft_GrSurfaceOrigin, // surface origin
872 1, // sample count
873 color_type.value(), // color type
874 SkColorSpace::MakeSRGB(), // color space
875 &surface_properties, // surface properties
876 static_cast<SkSurfaces::TextureReleaseProc>(
877 texture->destruction_callback), // release proc
878 texture->user_data // release context
879 );
880
881 if (!surface) {
882 FML_LOG(ERROR) << "Could not wrap embedder supplied render texture.";
883 return nullptr;
884 }
885
886 return surface;
887#else
888 return nullptr;
889#endif
890}
891
892static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
893 GrDirectContext* context,
894 const FlutterBackingStoreConfig& config,
895 const FlutterOpenGLFramebuffer* framebuffer) {
896#ifdef SHELL_ENABLE_GL
897 GrGLFramebufferInfo framebuffer_info = {};
898 framebuffer_info.fFormat = framebuffer->target;
899 framebuffer_info.fFBOID = framebuffer->name;
900
901 auto backend_render_target =
902 GrBackendRenderTargets::MakeGL(config.size.width, // width
903 config.size.height, // height
904 1, // sample count
905 0, // stencil bits
906 framebuffer_info // framebuffer info
907 );
908
909 SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
910
911 std::optional<SkColorType> color_type =
912 FlutterFormatToSkColorType(framebuffer->target);
913 if (!color_type) {
914 return nullptr;
915 }
916
917 auto surface = SkSurfaces::WrapBackendRenderTarget(
918 context, // context
919 backend_render_target, // backend render target
920 kBottomLeft_GrSurfaceOrigin, // surface origin
921 color_type.value(), // color type
922 SkColorSpace::MakeSRGB(), // color space
923 &surface_properties, // surface properties
924 static_cast<SkSurfaces::RenderTargetReleaseProc>(
925 framebuffer->destruction_callback), // release proc
926 framebuffer->user_data // release context
927 );
928
929 if (!surface) {
930 FML_LOG(ERROR) << "Could not wrap embedder supplied frame-buffer.";
931 return nullptr;
932 }
933 return surface;
934#else
935 return nullptr;
936#endif
937}
938
939static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
940 GrDirectContext* context,
941 const FlutterBackingStoreConfig& config,
942 const FlutterOpenGLSurface* surface) {
943#ifdef SHELL_ENABLE_GL
944 GrGLFramebufferInfo framebuffer_info = {};
945 framebuffer_info.fFormat = SAFE_ACCESS(surface, format, GL_BGRA8_EXT);
946 framebuffer_info.fFBOID = 0;
947
948 auto backend_render_target =
949 GrBackendRenderTargets::MakeGL(config.size.width, // width
950 config.size.height, // height
951 1, // sample count
952 0, // stencil bits
953 framebuffer_info // framebuffer info
954 );
955
956 SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
957
958 std::optional<SkColorType> color_type =
959 FlutterFormatToSkColorType(surface->format);
960 if (!color_type) {
961 return nullptr;
962 }
963
964 auto sk_surface = SkSurfaces::WrapBackendRenderTarget(
965 context, // context
966 backend_render_target, // backend render target
967 kBottomLeft_GrSurfaceOrigin, // surface origin
968 color_type.value(), // color type
969 SkColorSpace::MakeSRGB(), // color space
970 &surface_properties, // surface properties
971 static_cast<SkSurfaces::RenderTargetReleaseProc>(
972 surface->destruction_callback), // release proc
973 surface->user_data // release context
974 );
975
976 if (!sk_surface) {
977 FML_LOG(ERROR) << "Could not wrap embedder supplied frame-buffer.";
978 return nullptr;
979 }
980 return sk_surface;
981#else
982 return nullptr;
983#endif
984}
985
986static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
987 GrDirectContext* context,
988 const FlutterBackingStoreConfig& config,
989 const FlutterSoftwareBackingStore* software) {
990 const auto image_info =
991 SkImageInfo::MakeN32Premul(config.size.width, config.size.height);
992
993 struct Captures {
994 VoidCallback destruction_callback;
995 void* user_data;
996 };
997 auto captures = std::make_unique<Captures>();
998 captures->destruction_callback = software->destruction_callback;
999 captures->user_data = software->user_data;
1000 auto release_proc = [](void* pixels, void* context) {
1001 auto captures = reinterpret_cast<Captures*>(context);
1002 if (captures->destruction_callback) {
1003 captures->destruction_callback(captures->user_data);
1004 }
1005 delete captures;
1006 };
1007
1008 auto surface =
1009 SkSurfaces::WrapPixels(image_info, // image info
1010 const_cast<void*>(software->allocation), // pixels
1011 software->row_bytes, // row bytes
1012 release_proc, // release proc
1013 captures.get() // get context
1014 );
1015
1016 if (!surface) {
1017 FML_LOG(ERROR)
1018 << "Could not wrap embedder supplied software render buffer.";
1019 if (software->destruction_callback) {
1020 software->destruction_callback(software->user_data);
1021 }
1022 return nullptr;
1023 }
1024 if (surface) {
1025 captures.release(); // Skia has assumed ownership of the struct.
1026 }
1027 return surface;
1028}
1029
1030static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
1031 GrDirectContext* context,
1032 const FlutterBackingStoreConfig& config,
1033 const FlutterSoftwareBackingStore2* software) {
1034 const auto color_info = getSkColorInfo(software->pixel_format);
1035 if (!color_info) {
1036 return nullptr;
1037 }
1038
1039 const auto image_info = SkImageInfo::Make(
1040 SkISize::Make(config.size.width, config.size.height), *color_info);
1041
1042 struct Captures {
1043 VoidCallback destruction_callback;
1044 void* user_data;
1045 };
1046 auto captures = std::make_unique<Captures>();
1047 captures->destruction_callback = software->destruction_callback;
1048 captures->user_data = software->user_data;
1049 auto release_proc = [](void* pixels, void* context) {
1050 auto captures = reinterpret_cast<Captures*>(context);
1051 if (captures->destruction_callback) {
1052 captures->destruction_callback(captures->user_data);
1053 }
1054 };
1055
1056 auto surface =
1057 SkSurfaces::WrapPixels(image_info, // image info
1058 const_cast<void*>(software->allocation), // pixels
1059 software->row_bytes, // row bytes
1060 release_proc, // release proc
1061 captures.release() // release context
1062 );
1063
1064 if (!surface) {
1065 FML_LOG(ERROR)
1066 << "Could not wrap embedder supplied software render buffer.";
1067 if (software->destruction_callback) {
1068 software->destruction_callback(software->user_data);
1069 }
1070 return nullptr;
1071 }
1072 return surface;
1073}
1074
1075static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
1076 GrDirectContext* context,
1077 const FlutterBackingStoreConfig& config,
1078 const FlutterMetalBackingStore* metal) {
1079#if defined(SHELL_ENABLE_METAL) && !SLIMPELLER
1080 GrMtlTextureInfo texture_info;
1081 if (!metal->texture.texture) {
1082 FML_LOG(ERROR) << "Embedder supplied null Metal texture.";
1083 return nullptr;
1084 }
1085 sk_cfp<FlutterMetalTextureHandle> mtl_texture;
1086 mtl_texture.retain(metal->texture.texture);
1087 texture_info.fTexture = mtl_texture;
1088 GrBackendTexture backend_texture =
1089 GrBackendTextures::MakeMtl(config.size.width, //
1090 config.size.height, //
1091 skgpu::Mipmapped::kNo, //
1092 texture_info //
1093 );
1094
1095 SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
1096
1097 auto surface = SkSurfaces::WrapBackendTexture(
1098 context, // context
1099 backend_texture, // back-end texture
1100 kTopLeft_GrSurfaceOrigin, // surface origin
1101 1, // sample count
1102 kBGRA_8888_SkColorType, // color type
1103 nullptr, // color space
1104 &surface_properties, // surface properties
1105 static_cast<SkSurfaces::TextureReleaseProc>(
1106 metal->texture.destruction_callback), // release proc
1107 metal->texture.user_data // release context
1108 );
1109
1110 if (!surface) {
1111 FML_LOG(ERROR) << "Could not wrap embedder supplied Metal render texture.";
1112 return nullptr;
1113 }
1114
1115 return surface;
1116#else
1117 return nullptr;
1118#endif
1119}
1120
1121#if defined(SHELL_ENABLE_GL) && defined(IMPELLER_SUPPORTS_RENDERING)
1122static std::optional<impeller::PixelFormat> FlutterFormatToImpellerPixelFormat(
1123 uint32_t format) {
1124 switch (format) {
1125 case GL_BGRA8_EXT:
1127 case GL_RGBA8:
1129 default:
1130 FML_LOG(ERROR) << "Cannot convert format " << format
1131 << " to impeller::PixelFormat.";
1132 return std::nullopt;
1133 }
1134}
1135
1136#endif // defined(SHELL_ENABLE_GL) && defined(IMPELLER_SUPPORTS_RENDERING)
1137
1138static std::unique_ptr<flutter::EmbedderRenderTarget>
1140 FlutterBackingStore backing_store,
1141 const fml::closure& on_release,
1142 const std::shared_ptr<impeller::AiksContext>& aiks_context,
1143 const FlutterBackingStoreConfig& config,
1144 const FlutterOpenGLFramebuffer* framebuffer) {
1145#if defined(SHELL_ENABLE_GL) && defined(IMPELLER_SUPPORTS_RENDERING)
1146 auto format = FlutterFormatToImpellerPixelFormat(framebuffer->target);
1147 if (!format.has_value()) {
1148 return nullptr;
1149 }
1150
1151 const auto& gl_context =
1152 impeller::ContextGLES::Cast(*aiks_context->GetContext());
1153 const bool implicit_msaa = aiks_context->GetContext()
1154 ->GetCapabilities()
1155 ->SupportsImplicitResolvingMSAA();
1156 const auto size = impeller::ISize(config.size.width, config.size.height);
1157
1158 impeller::TextureDescriptor color0_tex;
1159 if (implicit_msaa) {
1162 } else {
1165 }
1166 color0_tex.format = format.value();
1167 color0_tex.size = size;
1168 color0_tex.usage = static_cast<impeller::TextureUsageMask>(
1171
1174 gl_context.GetReactor(), color0_tex, framebuffer->name);
1177 if (implicit_msaa) {
1179 color0.resolve_texture = color0.texture;
1180 } else {
1182 }
1183
1184 impeller::TextureDescriptor depth_stencil_texture_desc;
1185 depth_stencil_texture_desc.format = impeller::PixelFormat::kD24UnormS8Uint;
1186 depth_stencil_texture_desc.size = size;
1187 depth_stencil_texture_desc.usage = static_cast<impeller::TextureUsageMask>(
1189 if (implicit_msaa) {
1190 depth_stencil_texture_desc.type =
1192 depth_stencil_texture_desc.sample_count = impeller::SampleCount::kCount4;
1193 } else {
1194 depth_stencil_texture_desc.type = impeller::TextureType::kTexture2D;
1195 depth_stencil_texture_desc.sample_count = impeller::SampleCount::kCount1;
1196 }
1197
1198 auto depth_stencil_tex = impeller::TextureGLES::CreatePlaceholder(
1199 gl_context.GetReactor(), depth_stencil_texture_desc);
1200
1202 depth0.clear_depth = 0;
1203 depth0.texture = depth_stencil_tex;
1206
1208 stencil0.clear_stencil = 0;
1209 stencil0.texture = depth_stencil_tex;
1212
1213 impeller::RenderTarget render_target_desc;
1214
1215 render_target_desc.SetColorAttachment(color0, 0u);
1216 render_target_desc.SetDepthAttachment(depth0);
1217 render_target_desc.SetStencilAttachment(stencil0);
1218
1219 fml::closure framebuffer_destruct =
1220 [callback = framebuffer->destruction_callback,
1221 user_data = framebuffer->user_data]() { callback(user_data); };
1222
1223 return std::make_unique<flutter::EmbedderRenderTargetImpeller>(
1224 backing_store, aiks_context,
1225 std::make_unique<impeller::RenderTarget>(std::move(render_target_desc)),
1226 on_release, framebuffer_destruct);
1227#else
1228 return nullptr;
1229#endif
1230}
1231
1232static std::unique_ptr<flutter::EmbedderRenderTarget>
1234 FlutterBackingStore backing_store,
1235 const fml::closure& on_release,
1236 const std::shared_ptr<impeller::AiksContext>& aiks_context,
1237 const FlutterBackingStoreConfig& config,
1238 const FlutterMetalBackingStore* metal) {
1239#if defined(SHELL_ENABLE_METAL) && defined(IMPELLER_SUPPORTS_RENDERING)
1240 if (!metal->texture.texture) {
1241 FML_LOG(ERROR) << "Embedder supplied null Metal texture.";
1242 return nullptr;
1243 }
1244
1245 const auto size = impeller::ISize(config.size.width, config.size.height);
1246
1247 impeller::TextureDescriptor resolve_tex_desc;
1248 resolve_tex_desc.size = size;
1251 resolve_tex_desc.usage = impeller::TextureUsage::kRenderTarget |
1253
1254 auto resolve_tex = impeller::WrapTextureMTL(
1255 resolve_tex_desc, metal->texture.texture,
1257 user_data = metal->texture.user_data]() { callback(user_data); });
1258 if (!resolve_tex) {
1259 FML_LOG(ERROR) << "Could not wrap embedder supplied Metal render texture.";
1260 return nullptr;
1261 }
1262 resolve_tex->SetLabel("ImpellerBackingStoreResolve");
1263
1264 impeller::TextureDescriptor msaa_tex_desc;
1268 msaa_tex_desc.format = resolve_tex->GetTextureDescriptor().format;
1269 msaa_tex_desc.size = size;
1271
1272 auto msaa_tex =
1273 aiks_context->GetContext()->GetResourceAllocator()->CreateTexture(
1274 msaa_tex_desc);
1275 if (!msaa_tex) {
1276 FML_LOG(ERROR) << "Could not allocate MSAA color texture.";
1277 return nullptr;
1278 }
1279 msaa_tex->SetLabel("ImpellerBackingStoreColorMSAA");
1280
1282 color0.texture = msaa_tex;
1286 color0.resolve_texture = resolve_tex;
1287
1288 impeller::RenderTarget render_target_desc;
1289 render_target_desc.SetColorAttachment(color0, 0u);
1290
1291 return std::make_unique<flutter::EmbedderRenderTargetImpeller>(
1292 backing_store, aiks_context,
1293 std::make_unique<impeller::RenderTarget>(std::move(render_target_desc)),
1294 on_release, fml::closure());
1295#else
1296 return nullptr;
1297#endif
1298}
1299
1300static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
1301 GrDirectContext* context,
1302 const FlutterBackingStoreConfig& config,
1304#ifdef SHELL_ENABLE_VULKAN
1305 if (!vulkan->image) {
1306 FML_LOG(ERROR) << "Embedder supplied null Vulkan image.";
1307 return nullptr;
1308 }
1309 GrVkImageInfo image_info = {
1310 .fImage = reinterpret_cast<VkImage>(vulkan->image->image),
1311 .fImageTiling = VK_IMAGE_TILING_OPTIMAL,
1312 .fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED,
1313 .fFormat = static_cast<VkFormat>(vulkan->image->format),
1314 .fImageUsageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
1315 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1316 VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1317 VK_IMAGE_USAGE_SAMPLED_BIT,
1318 .fSampleCount = 1,
1319 .fLevelCount = 1,
1320 };
1321 auto backend_texture = GrBackendTextures::MakeVk(
1322 config.size.width, config.size.height, image_info);
1323
1324 SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
1325
1326 auto surface = SkSurfaces::WrapBackendTexture(
1327 context, // context
1328 backend_texture, // back-end texture
1329 kTopLeft_GrSurfaceOrigin, // surface origin
1330 1, // sample count
1332 static_cast<VkFormat>(vulkan->image->format)), // color type
1333 SkColorSpace::MakeSRGB(), // color space
1334 &surface_properties, // surface properties
1335 static_cast<SkSurfaces::TextureReleaseProc>(
1336 vulkan->destruction_callback), // release proc
1337 vulkan->user_data // release context
1338 );
1339
1340 if (!surface) {
1341 FML_LOG(ERROR) << "Could not wrap embedder supplied Vulkan render texture.";
1342 return nullptr;
1343 }
1344
1345 return surface;
1346#else
1347 return nullptr;
1348#endif
1349}
1350
1351static std::unique_ptr<flutter::EmbedderRenderTarget>
1353 FlutterBackingStore backing_store,
1354 sk_sp<SkSurface> skia_surface,
1355 fml::closure on_release,
1358 on_clear_current) {
1359 if (!skia_surface) {
1360 return nullptr;
1361 }
1362 return std::make_unique<flutter::EmbedderRenderTargetSkia>(
1363 backing_store, std::move(skia_surface), std::move(on_release),
1364 std::move(on_make_current), std::move(on_clear_current));
1365}
1366
1367static std::unique_ptr<flutter::EmbedderRenderTarget>
1369 sk_sp<SkSurface> skia_surface,
1370 fml::closure on_release) {
1371 return MakeRenderTargetFromSkSurface(backing_store, std::move(skia_surface),
1372 std::move(on_release), nullptr, nullptr);
1373}
1374
1375static std::unique_ptr<flutter::EmbedderRenderTarget>
1377 const FlutterCompositor* compositor,
1378 const FlutterBackingStoreConfig& config,
1379 GrDirectContext* context,
1380 const std::shared_ptr<impeller::AiksContext>& aiks_context,
1381 bool enable_impeller) {
1382 FlutterBackingStore backing_store = {};
1383 backing_store.struct_size = sizeof(backing_store);
1384
1385 // Safe access checks on the compositor struct have been performed in
1386 // InferExternalViewEmbedderFromArgs and are not necessary here.
1387 auto c_create_callback = compositor->create_backing_store_callback;
1388 auto c_collect_callback = compositor->collect_backing_store_callback;
1389
1390 {
1391 TRACE_EVENT0("flutter", "FlutterCompositorCreateBackingStore");
1392 if (!c_create_callback(&config, &backing_store, compositor->user_data)) {
1393 FML_LOG(ERROR) << "Could not create the embedder backing store.";
1394 return nullptr;
1395 }
1396 }
1397
1398 if (backing_store.struct_size != sizeof(backing_store)) {
1399 FML_LOG(ERROR) << "Embedder modified the backing store struct size.";
1400 return nullptr;
1401 }
1402
1403 // In case we return early without creating an embedder render target, the
1404 // embedder has still given us ownership of its baton which we must return
1405 // back to it. If this method is successful, the closure is released when the
1406 // render target is eventually released.
1407 fml::ScopedCleanupClosure collect_callback(
1408 [c_collect_callback, backing_store, user_data = compositor->user_data]() {
1409 TRACE_EVENT0("flutter", "FlutterCompositorCollectBackingStore");
1410 c_collect_callback(&backing_store, user_data);
1411 });
1412
1413 // No safe access checks on the renderer are necessary since we allocated
1414 // the struct.
1415
1416 std::unique_ptr<flutter::EmbedderRenderTarget> render_target;
1417
1418 switch (backing_store.type) {
1420 switch (backing_store.open_gl.type) {
1422 auto skia_surface = MakeSkSurfaceFromBackingStore(
1423 context, config, &backing_store.open_gl.texture);
1424 render_target = MakeRenderTargetFromSkSurface(
1425 backing_store, std::move(skia_surface),
1426 collect_callback.Release());
1427 break;
1428 }
1430 if (enable_impeller) {
1432 backing_store, collect_callback.Release(), aiks_context, config,
1433 &backing_store.open_gl.framebuffer);
1434 break;
1435 } else {
1436 auto skia_surface = MakeSkSurfaceFromBackingStore(
1437 context, config, &backing_store.open_gl.framebuffer);
1438 render_target = MakeRenderTargetFromSkSurface(
1439 backing_store, std::move(skia_surface),
1440 collect_callback.Release());
1441 break;
1442 }
1443 }
1444
1446 auto on_make_current =
1448 context = backing_store.open_gl.surface.user_data]()
1450 bool invalidate_api_state = false;
1451 bool ok = callback(context, &invalidate_api_state);
1452 return {ok, invalidate_api_state};
1453 };
1454
1455 auto on_clear_current =
1457 context = backing_store.open_gl.surface.user_data]()
1459 bool invalidate_api_state = false;
1460 bool ok = callback(context, &invalidate_api_state);
1461 return {ok, invalidate_api_state};
1462 };
1463
1464 if (enable_impeller) {
1465 // TODO(https://github.com/flutter/flutter/issues/151670): Implement
1466 // GL Surface backing stores for Impeller.
1467 FML_LOG(ERROR) << "Unimplemented";
1468 break;
1469 } else {
1470 auto skia_surface = MakeSkSurfaceFromBackingStore(
1471 context, config, &backing_store.open_gl.surface);
1472
1473 render_target = MakeRenderTargetFromSkSurface(
1474 backing_store, std::move(skia_surface),
1475 collect_callback.Release(), on_make_current, on_clear_current);
1476 break;
1477 }
1478 }
1479 }
1480 break;
1481 }
1482
1484 auto skia_surface = MakeSkSurfaceFromBackingStore(
1485 context, config, &backing_store.software);
1486 render_target = MakeRenderTargetFromSkSurface(
1487 backing_store, std::move(skia_surface), collect_callback.Release());
1488 break;
1489 }
1491 auto skia_surface = MakeSkSurfaceFromBackingStore(
1492 context, config, &backing_store.software2);
1493 render_target = MakeRenderTargetFromSkSurface(
1494 backing_store, std::move(skia_surface), collect_callback.Release());
1495 break;
1496 }
1498 if (enable_impeller) {
1500 backing_store, collect_callback.Release(), aiks_context, config,
1501 &backing_store.metal);
1502 } else {
1503 auto skia_surface = MakeSkSurfaceFromBackingStore(context, config,
1504 &backing_store.metal);
1505 render_target = MakeRenderTargetFromSkSurface(
1506 backing_store, std::move(skia_surface), collect_callback.Release());
1507 }
1508 break;
1509 }
1511 if (enable_impeller) {
1512 FML_LOG(ERROR) << "Unimplemented";
1513 break;
1514 } else {
1515 auto skia_surface = MakeSkSurfaceFromBackingStore(
1516 context, config, &backing_store.vulkan);
1517 render_target = MakeRenderTargetFromSkSurface(
1518 backing_store, std::move(skia_surface), collect_callback.Release());
1519 break;
1520 }
1521 }
1522 };
1523
1524 if (!render_target) {
1525 FML_LOG(ERROR) << "Could not create a surface from an embedder provided "
1526 "render target.";
1527 }
1528 return render_target;
1529}
1530
1531/// Creates an EmbedderExternalViewEmbedder.
1532///
1533/// When a non-OK status is returned, engine startup should be halted.
1536 bool enable_impeller) {
1537 if (compositor == nullptr) {
1538 return std::unique_ptr<flutter::EmbedderExternalViewEmbedder>{nullptr};
1539 }
1540
1541 auto c_create_callback =
1542 SAFE_ACCESS(compositor, create_backing_store_callback, nullptr);
1543 auto c_collect_callback =
1544 SAFE_ACCESS(compositor, collect_backing_store_callback, nullptr);
1545 auto c_present_callback =
1546 SAFE_ACCESS(compositor, present_layers_callback, nullptr);
1547 auto c_present_view_callback =
1548 SAFE_ACCESS(compositor, present_view_callback, nullptr);
1549 bool avoid_backing_store_cache =
1550 SAFE_ACCESS(compositor, avoid_backing_store_cache, false);
1551
1552 // Make sure the required callbacks are present
1553 if (!c_create_callback || !c_collect_callback) {
1555 "Required compositor callbacks absent.");
1556 }
1557 // Either the present view or the present layers callback must be provided.
1558 if ((!c_present_view_callback && !c_present_callback) ||
1559 (c_present_view_callback && c_present_callback)) {
1561 "Either present_layers_callback or "
1562 "present_view_callback must be provided but not both.");
1563 }
1564
1565 FlutterCompositor captured_compositor = *compositor;
1566
1568 create_render_target_callback =
1569 [captured_compositor, enable_impeller](
1570 GrDirectContext* context,
1571 const std::shared_ptr<impeller::AiksContext>& aiks_context,
1572 const auto& config) {
1573 return CreateEmbedderRenderTarget(&captured_compositor, config,
1574 context, aiks_context,
1575 enable_impeller);
1576 };
1577
1579 if (c_present_callback) {
1580 present_callback = [c_present_callback, user_data = compositor->user_data](
1581 FlutterViewId view_id, const auto& layers) {
1582 TRACE_EVENT0("flutter", "FlutterCompositorPresentLayers");
1583 return c_present_callback(const_cast<const FlutterLayer**>(layers.data()),
1584 layers.size(), user_data);
1585 };
1586 } else {
1587 FML_DCHECK(c_present_view_callback != nullptr);
1588 present_callback = [c_present_view_callback,
1589 user_data = compositor->user_data](
1590 FlutterViewId view_id, const auto& layers) {
1591 TRACE_EVENT0("flutter", "FlutterCompositorPresentLayers");
1592
1593 FlutterPresentViewInfo info = {
1595 .view_id = view_id,
1596 .layers = const_cast<const FlutterLayer**>(layers.data()),
1598 .user_data = user_data,
1599 };
1600
1601 return c_present_view_callback(&info);
1602 };
1603 }
1604
1605 return std::make_unique<flutter::EmbedderExternalViewEmbedder>(
1606 avoid_backing_store_cache, create_render_target_callback,
1607 present_callback);
1608}
1609
1610// Translates embedder metrics to engine metrics, or returns a string on error.
1611static std::variant<flutter::ViewportMetrics, std::string>
1613 const FlutterWindowMetricsEvent* flutter_metrics) {
1614 if (flutter_metrics == nullptr) {
1615 return "Invalid metrics handle.";
1616 }
1617
1619
1620 metrics.physical_width = SAFE_ACCESS(flutter_metrics, width, 0.0);
1621 metrics.physical_height = SAFE_ACCESS(flutter_metrics, height, 0.0);
1622 metrics.device_pixel_ratio = SAFE_ACCESS(flutter_metrics, pixel_ratio, 1.0);
1623 metrics.physical_view_inset_top =
1624 SAFE_ACCESS(flutter_metrics, physical_view_inset_top, 0.0);
1626 SAFE_ACCESS(flutter_metrics, physical_view_inset_right, 0.0);
1628 SAFE_ACCESS(flutter_metrics, physical_view_inset_bottom, 0.0);
1629 metrics.physical_view_inset_left =
1630 SAFE_ACCESS(flutter_metrics, physical_view_inset_left, 0.0);
1631 metrics.display_id = SAFE_ACCESS(flutter_metrics, display_id, 0);
1632
1633 if (metrics.device_pixel_ratio <= 0.0) {
1634 return "Device pixel ratio was invalid. It must be greater than zero.";
1635 }
1636
1637 if (metrics.physical_view_inset_top < 0 ||
1638 metrics.physical_view_inset_right < 0 ||
1639 metrics.physical_view_inset_bottom < 0 ||
1640 metrics.physical_view_inset_left < 0) {
1641 return "Physical view insets are invalid. They must be non-negative.";
1642 }
1643
1644 if (metrics.physical_view_inset_top > metrics.physical_height ||
1645 metrics.physical_view_inset_right > metrics.physical_width ||
1646 metrics.physical_view_inset_bottom > metrics.physical_height ||
1647 metrics.physical_view_inset_left > metrics.physical_width) {
1648 return "Physical view insets are invalid. They cannot be greater than "
1649 "physical height or width.";
1650 }
1651
1656
1657 return metrics;
1658}
1659
1661 std::unique_ptr<flutter::PlatformMessage> message;
1662};
1663
1665 void operator()(Dart_LoadedElf* elf) {
1666 if (elf) {
1667 ::Dart_UnloadELF(elf);
1668 }
1669 }
1670};
1671
1672using UniqueLoadedElf = std::unique_ptr<Dart_LoadedElf, LoadedElfDeleter>;
1673
1676 const uint8_t* vm_snapshot_data = nullptr;
1677 const uint8_t* vm_snapshot_instrs = nullptr;
1678 const uint8_t* vm_isolate_data = nullptr;
1679 const uint8_t* vm_isolate_instrs = nullptr;
1680};
1681
1683 const FlutterEngineAOTDataSource* source,
1684 FlutterEngineAOTData* data_out) {
1687 "AOT data can only be created in AOT mode.");
1688 } else if (!source) {
1689 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Null source specified.");
1690 } else if (!data_out) {
1691 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Null data_out specified.");
1692 }
1693
1694 switch (source->type) {
1696 if (!source->elf_path || !fml::IsFile(source->elf_path)) {
1698 "Invalid ELF path specified.");
1699 }
1700
1701 auto aot_data = std::make_unique<_FlutterEngineAOTData>();
1702 const char* error = nullptr;
1703
1704#if OS_FUCHSIA
1705 // TODO(gw280): https://github.com/flutter/flutter/issues/50285
1706 // Dart doesn't implement Dart_LoadELF on Fuchsia
1707 Dart_LoadedElf* loaded_elf = nullptr;
1708#else
1709 Dart_LoadedElf* loaded_elf = Dart_LoadELF(
1710 source->elf_path, // file path
1711 0, // file offset
1712 &error, // error (out)
1713 &aot_data->vm_snapshot_data, // vm snapshot data (out)
1714 &aot_data->vm_snapshot_instrs, // vm snapshot instr (out)
1715 &aot_data->vm_isolate_data, // vm isolate data (out)
1716 &aot_data->vm_isolate_instrs // vm isolate instr (out)
1717 );
1718#endif
1719
1720 if (loaded_elf == nullptr) {
1722 }
1723
1724 aot_data->loaded_elf.reset(loaded_elf);
1725
1726 *data_out = aot_data.release();
1727 return kSuccess;
1728 }
1729 }
1730
1731 return LOG_EMBEDDER_ERROR(
1733 "Invalid FlutterEngineAOTDataSourceType type specified.");
1734}
1735
1737 if (!data) {
1738 // Deleting a null object should be a no-op.
1739 return kSuccess;
1740 }
1741
1742 // Created in a unique pointer in `FlutterEngineCreateAOTData`.
1743 delete data;
1744 return kSuccess;
1745}
1746
1747// Constructs appropriate mapping callbacks if JIT snapshot locations have been
1748// explictly specified.
1750 flutter::Settings& settings) {
1751 auto make_mapping_callback = [](const char* path, bool executable) {
1752 return [path, executable]() {
1753 if (executable) {
1755 } else {
1757 }
1758 };
1759 };
1760
1761 // Users are allowed to specify only certain snapshots if they so desire.
1762 if (SAFE_ACCESS(args, vm_snapshot_data, nullptr) != nullptr) {
1763 settings.vm_snapshot_data = make_mapping_callback(
1764 reinterpret_cast<const char*>(args->vm_snapshot_data), false);
1765 }
1766
1767 if (SAFE_ACCESS(args, vm_snapshot_instructions, nullptr) != nullptr) {
1768 settings.vm_snapshot_instr = make_mapping_callback(
1769 reinterpret_cast<const char*>(args->vm_snapshot_instructions), true);
1770 }
1771
1772 if (SAFE_ACCESS(args, isolate_snapshot_data, nullptr) != nullptr) {
1773 settings.isolate_snapshot_data = make_mapping_callback(
1774 reinterpret_cast<const char*>(args->isolate_snapshot_data), false);
1775 }
1776
1777 if (SAFE_ACCESS(args, isolate_snapshot_instructions, nullptr) != nullptr) {
1778 settings.isolate_snapshot_instr = make_mapping_callback(
1779 reinterpret_cast<const char*>(args->isolate_snapshot_instructions),
1780 true);
1781 }
1782
1783#if !OS_FUCHSIA && (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG)
1784 settings.dart_library_sources_kernel = []() {
1785 return std::make_unique<fml::NonOwnedMapping>(kPlatformStrongDill,
1787 };
1788#endif // !OS_FUCHSIA && (FLUTTER_RUNTIME_MODE ==
1789 // FLUTTER_RUNTIME_MODE_DEBUG)
1790}
1791
1793 const FlutterProjectArgs* args,
1794 flutter::Settings& settings) { // NOLINT(google-runtime-references)
1795 // There are no ownership concerns here as all mappings are owned by the
1796 // embedder and not the engine.
1797 auto make_mapping_callback = [](const uint8_t* mapping, size_t size) {
1798 return [mapping, size]() {
1799 return std::make_unique<fml::NonOwnedMapping>(mapping, size);
1800 };
1801 };
1802
1803 if (SAFE_ACCESS(args, aot_data, nullptr) != nullptr) {
1804 settings.vm_snapshot_data =
1805 make_mapping_callback(args->aot_data->vm_snapshot_data, 0);
1806
1807 settings.vm_snapshot_instr =
1808 make_mapping_callback(args->aot_data->vm_snapshot_instrs, 0);
1809
1810 settings.isolate_snapshot_data =
1811 make_mapping_callback(args->aot_data->vm_isolate_data, 0);
1812
1813 settings.isolate_snapshot_instr =
1814 make_mapping_callback(args->aot_data->vm_isolate_instrs, 0);
1815 }
1816
1817 if (SAFE_ACCESS(args, vm_snapshot_data, nullptr) != nullptr) {
1818 settings.vm_snapshot_data = make_mapping_callback(
1819 args->vm_snapshot_data, SAFE_ACCESS(args, vm_snapshot_data_size, 0));
1820 }
1821
1822 if (SAFE_ACCESS(args, vm_snapshot_instructions, nullptr) != nullptr) {
1823 settings.vm_snapshot_instr = make_mapping_callback(
1824 args->vm_snapshot_instructions,
1825 SAFE_ACCESS(args, vm_snapshot_instructions_size, 0));
1826 }
1827
1828 if (SAFE_ACCESS(args, isolate_snapshot_data, nullptr) != nullptr) {
1829 settings.isolate_snapshot_data =
1830 make_mapping_callback(args->isolate_snapshot_data,
1831 SAFE_ACCESS(args, isolate_snapshot_data_size, 0));
1832 }
1833
1834 if (SAFE_ACCESS(args, isolate_snapshot_instructions, nullptr) != nullptr) {
1835 settings.isolate_snapshot_instr = make_mapping_callback(
1836 args->isolate_snapshot_instructions,
1837 SAFE_ACCESS(args, isolate_snapshot_instructions_size, 0));
1838 }
1839}
1840
1841// Create a callback to notify the embedder of semantic updates
1842// using the legacy embedder callbacks 'update_semantics_node_callback' and
1843// 'update_semantics_custom_action_callback'.
1846 FlutterUpdateSemanticsNodeCallback update_semantics_node_callback,
1848 update_semantics_custom_action_callback,
1849 void* user_data) {
1850 return [update_semantics_node_callback,
1851 update_semantics_custom_action_callback, user_data](
1852 int64_t view_id, const flutter::SemanticsNodeUpdates& nodes,
1854 flutter::EmbedderSemanticsUpdate update{nodes, actions};
1855 FlutterSemanticsUpdate* update_ptr = update.get();
1856
1857 // First, queue all node and custom action updates.
1858 if (update_semantics_node_callback != nullptr) {
1859 for (size_t i = 0; i < update_ptr->nodes_count; i++) {
1860 update_semantics_node_callback(&update_ptr->nodes[i], user_data);
1861 }
1862 }
1863
1864 if (update_semantics_custom_action_callback != nullptr) {
1865 for (size_t i = 0; i < update_ptr->custom_actions_count; i++) {
1866 update_semantics_custom_action_callback(&update_ptr->custom_actions[i],
1867 user_data);
1868 }
1869 }
1870
1871 // Second, mark node and action batches completed now that all
1872 // updates are queued.
1873 if (update_semantics_node_callback != nullptr) {
1874 const FlutterSemanticsNode batch_end_sentinel = {
1875 sizeof(FlutterSemanticsNode),
1877 };
1878 update_semantics_node_callback(&batch_end_sentinel, user_data);
1879 }
1880
1881 if (update_semantics_custom_action_callback != nullptr) {
1882 const FlutterSemanticsCustomAction batch_end_sentinel = {
1885 };
1886 update_semantics_custom_action_callback(&batch_end_sentinel, user_data);
1887 }
1888 };
1889}
1890
1891// Create a callback to notify the embedder of semantic updates
1892// using the deprecated embedder callback 'update_semantics_callback'.
1895 FlutterUpdateSemanticsCallback update_semantics_callback,
1896 void* user_data) {
1897 return [update_semantics_callback, user_data](
1898 int64_t view_id, const flutter::SemanticsNodeUpdates& nodes,
1900 flutter::EmbedderSemanticsUpdate update{nodes, actions};
1901
1902 update_semantics_callback(update.get(), user_data);
1903 };
1904}
1905
1906// Create a callback to notify the embedder of semantic updates
1907// using the new embedder callback 'update_semantics_callback2'.
1910 FlutterUpdateSemanticsCallback2 update_semantics_callback,
1911 void* user_data) {
1912 return [update_semantics_callback, user_data](
1913 int64_t view_id, const flutter::SemanticsNodeUpdates& nodes,
1915 flutter::EmbedderSemanticsUpdate2 update{view_id, nodes, actions};
1916
1917 update_semantics_callback(update.get(), user_data);
1918 };
1919}
1920
1921// Creates a callback that receives semantic updates from the engine
1922// and notifies the embedder's callback(s). Returns null if the embedder
1923// did not register any callbacks.
1926 void* user_data) {
1927 // There are three variants for the embedder API's semantic update callbacks.
1928 // Create a callback that maps to the embedder's desired semantic update API.
1929 //
1930 // Handle the case where the embedder registered the callback
1931 // 'updated_semantics_callback2'
1932 if (SAFE_ACCESS(args, update_semantics_callback2, nullptr) != nullptr) {
1934 args->update_semantics_callback2, user_data);
1935 }
1936
1937 // Handle the case where the embedder registered the deprecated callback
1938 // 'update_semantics_callback'.
1939 if (SAFE_ACCESS(args, update_semantics_callback, nullptr) != nullptr) {
1941 args->update_semantics_callback, user_data);
1942 }
1943
1944 // Handle the case where the embedder registered the deprecated callbacks
1945 // 'update_semantics_node_callback' and
1946 // 'update_semantics_custom_action_callback'.
1947 FlutterUpdateSemanticsNodeCallback update_semantics_node_callback = nullptr;
1948 if (SAFE_ACCESS(args, update_semantics_node_callback, nullptr) != nullptr) {
1949 update_semantics_node_callback = args->update_semantics_node_callback;
1950 }
1951
1953 update_semantics_custom_action_callback = nullptr;
1954 if (SAFE_ACCESS(args, update_semantics_custom_action_callback, nullptr) !=
1955 nullptr) {
1956 update_semantics_custom_action_callback =
1957 args->update_semantics_custom_action_callback;
1958 }
1959
1960 if (update_semantics_node_callback != nullptr ||
1961 update_semantics_custom_action_callback != nullptr) {
1963 update_semantics_node_callback, update_semantics_custom_action_callback,
1964 user_data);
1965 }
1966
1967 // Handle the case where the embedder registered no callbacks.
1968 return nullptr;
1969}
1970
1972 const FlutterRendererConfig* config,
1973 const FlutterProjectArgs* args,
1974 void* user_data,
1976 engine_out) {
1977 auto result =
1978 FlutterEngineInitialize(version, config, args, user_data, engine_out);
1979
1980 if (result != kSuccess) {
1981 return result;
1982 }
1983
1984 return FlutterEngineRunInitialized(*engine_out);
1985}
1986
1988 const FlutterRendererConfig* config,
1989 const FlutterProjectArgs* args,
1990 void* user_data,
1992 engine_out) {
1993 // Step 0: Figure out arguments for shell creation.
1994 if (version != FLUTTER_ENGINE_VERSION) {
1995 return LOG_EMBEDDER_ERROR(
1997 "Flutter embedder version mismatch. There has been a breaking change. "
1998 "Please consult the changelog and update the embedder.");
1999 }
2000
2001 if (engine_out == nullptr) {
2003 "The engine out parameter was missing.");
2004 }
2005
2006 if (args == nullptr) {
2008 "The Flutter project arguments were missing.");
2009 }
2010
2011 if (SAFE_ACCESS(args, assets_path, nullptr) == nullptr) {
2012 return LOG_EMBEDDER_ERROR(
2014 "The assets path in the Flutter project arguments was missing.");
2015 }
2016
2017 if (SAFE_ACCESS(args, main_path__unused__, nullptr) != nullptr) {
2018 FML_LOG(WARNING)
2019 << "FlutterProjectArgs.main_path is deprecated and should be set null.";
2020 }
2021
2022 if (SAFE_ACCESS(args, packages_path__unused__, nullptr) != nullptr) {
2023 FML_LOG(WARNING) << "FlutterProjectArgs.packages_path is deprecated and "
2024 "should be set null.";
2025 }
2026
2027 if (!IsRendererValid(config)) {
2029 "The renderer configuration was invalid.");
2030 }
2031
2032 std::string icu_data_path;
2033 if (SAFE_ACCESS(args, icu_data_path, nullptr) != nullptr) {
2034 icu_data_path = SAFE_ACCESS(args, icu_data_path, nullptr);
2035 }
2036
2037#if !SLIMPELLER
2038 if (SAFE_ACCESS(args, persistent_cache_path, nullptr) != nullptr) {
2039 std::string persistent_cache_path =
2040 SAFE_ACCESS(args, persistent_cache_path, nullptr);
2042 }
2043
2044 if (SAFE_ACCESS(args, is_persistent_cache_read_only, false)) {
2046 }
2047#endif // !SLIMPELLER
2048
2049 fml::CommandLine command_line;
2050 if (SAFE_ACCESS(args, command_line_argc, 0) != 0 &&
2051 SAFE_ACCESS(args, command_line_argv, nullptr) != nullptr) {
2052 command_line = fml::CommandLineFromArgcArgv(
2053 SAFE_ACCESS(args, command_line_argc, 0),
2054 SAFE_ACCESS(args, command_line_argv, nullptr));
2055 }
2056
2057 flutter::Settings settings = flutter::SettingsFromCommandLine(command_line);
2058
2059 if (SAFE_ACCESS(args, aot_data, nullptr)) {
2060 if (SAFE_ACCESS(args, vm_snapshot_data, nullptr) ||
2061 SAFE_ACCESS(args, vm_snapshot_instructions, nullptr) ||
2062 SAFE_ACCESS(args, isolate_snapshot_data, nullptr) ||
2063 SAFE_ACCESS(args, isolate_snapshot_instructions, nullptr)) {
2064 return LOG_EMBEDDER_ERROR(
2066 "Multiple AOT sources specified. Embedders should provide either "
2067 "*_snapshot_* buffers or aot_data, not both.");
2068 }
2069 }
2070
2073 } else {
2075 }
2076
2077 settings.icu_data_path = icu_data_path;
2078 settings.assets_path = args->assets_path;
2079 settings.leak_vm = !SAFE_ACCESS(args, shutdown_dart_vm_when_done, false);
2080 settings.old_gen_heap_size = SAFE_ACCESS(args, dart_old_gen_heap_size, -1);
2081
2083 // Verify the assets path contains Dart 2 kernel assets.
2084 const std::string kApplicationKernelSnapshotFileName = "kernel_blob.bin";
2085 std::string application_kernel_path = fml::paths::JoinPaths(
2087 if (!fml::IsFile(application_kernel_path)) {
2088 return LOG_EMBEDDER_ERROR(
2090 "Not running in AOT mode but could not resolve the kernel binary.");
2091 }
2093 }
2094
2095 if (SAFE_ACCESS(args, root_isolate_create_callback, nullptr) != nullptr) {
2097 SAFE_ACCESS(args, root_isolate_create_callback, nullptr);
2099 [callback, user_data](const auto& isolate) { callback(user_data); };
2100 }
2101
2102 // Wire up callback for engine and print logging.
2103 if (SAFE_ACCESS(args, log_message_callback, nullptr) != nullptr) {
2105 SAFE_ACCESS(args, log_message_callback, nullptr);
2107 const std::string& tag,
2108 const std::string& message) {
2109 callback(tag.c_str(), message.c_str(), user_data);
2110 };
2111 } else {
2112 settings.log_message_callback = [](const std::string& tag,
2113 const std::string& message) {
2114 // Fall back to logging to stdout if unspecified.
2115 if (tag.empty()) {
2116 std::cout << tag << ": ";
2117 }
2118 std::cout << message << std::endl;
2119 };
2120 }
2121
2122 if (SAFE_ACCESS(args, log_tag, nullptr) != nullptr) {
2123 settings.log_tag = SAFE_ACCESS(args, log_tag, nullptr);
2124 }
2125
2126 bool has_update_semantics_2_callback =
2127 SAFE_ACCESS(args, update_semantics_callback2, nullptr) != nullptr;
2128 bool has_update_semantics_callback =
2129 SAFE_ACCESS(args, update_semantics_callback, nullptr) != nullptr;
2130 bool has_legacy_update_semantics_callback =
2131 SAFE_ACCESS(args, update_semantics_node_callback, nullptr) != nullptr ||
2132 SAFE_ACCESS(args, update_semantics_custom_action_callback, nullptr) !=
2133 nullptr;
2134
2135 int semantic_callback_count = (has_update_semantics_2_callback ? 1 : 0) +
2136 (has_update_semantics_callback ? 1 : 0) +
2137 (has_legacy_update_semantics_callback ? 1 : 0);
2138
2139 if (semantic_callback_count > 1) {
2140 return LOG_EMBEDDER_ERROR(
2142 "Multiple semantics update callbacks provided. "
2143 "Embedders should provide either `update_semantics_callback2`, "
2144 "`update_semantics_callback`, or both "
2145 "`update_semantics_node_callback` and "
2146 "`update_semantics_custom_action_callback`.");
2147 }
2148
2150 update_semantics_callback =
2152
2154 platform_message_response_callback = nullptr;
2155 if (SAFE_ACCESS(args, platform_message_callback, nullptr) != nullptr) {
2156 platform_message_response_callback =
2157 [ptr = args->platform_message_callback,
2158 user_data](std::unique_ptr<flutter::PlatformMessage> message) {
2159 auto handle = new FlutterPlatformMessageResponseHandle();
2160 const FlutterPlatformMessage incoming_message = {
2161 sizeof(FlutterPlatformMessage), // struct_size
2162 message->channel().c_str(), // channel
2163 message->data().GetMapping(), // message
2164 message->data().GetSize(), // message_size
2165 handle, // response_handle
2166 };
2167 handle->message = std::move(message);
2168 return ptr(&incoming_message, user_data);
2169 };
2170 }
2171
2172 flutter::VsyncWaiterEmbedder::VsyncCallback vsync_callback = nullptr;
2173 if (SAFE_ACCESS(args, vsync_callback, nullptr) != nullptr) {
2174 vsync_callback = [ptr = args->vsync_callback, user_data](intptr_t baton) {
2175 return ptr(user_data, baton);
2176 };
2177 }
2178
2180 compute_platform_resolved_locale_callback = nullptr;
2181 if (SAFE_ACCESS(args, compute_platform_resolved_locale_callback, nullptr) !=
2182 nullptr) {
2183 compute_platform_resolved_locale_callback =
2184 [ptr = args->compute_platform_resolved_locale_callback](
2185 const std::vector<std::string>& supported_locales_data) {
2186 const size_t number_of_strings_per_locale = 3;
2187 size_t locale_count =
2188 supported_locales_data.size() / number_of_strings_per_locale;
2189 std::vector<FlutterLocale> supported_locales;
2190 std::vector<const FlutterLocale*> supported_locales_ptr;
2191 for (size_t i = 0; i < locale_count; ++i) {
2192 supported_locales.push_back(
2193 {.struct_size = sizeof(FlutterLocale),
2194 .language_code =
2195 supported_locales_data[i * number_of_strings_per_locale +
2196 0]
2197 .c_str(),
2198 .country_code =
2199 supported_locales_data[i * number_of_strings_per_locale +
2200 1]
2201 .c_str(),
2202 .script_code =
2203 supported_locales_data[i * number_of_strings_per_locale +
2204 2]
2205 .c_str(),
2206 .variant_code = nullptr});
2207 supported_locales_ptr.push_back(&supported_locales[i]);
2208 }
2209
2210 const FlutterLocale* result =
2211 ptr(supported_locales_ptr.data(), locale_count);
2212
2213 std::unique_ptr<std::vector<std::string>> out =
2214 std::make_unique<std::vector<std::string>>();
2215 if (result) {
2216 std::string language_code(SAFE_ACCESS(result, language_code, ""));
2217 if (language_code != "") {
2218 out->push_back(language_code);
2219 out->emplace_back(SAFE_ACCESS(result, country_code, ""));
2220 out->emplace_back(SAFE_ACCESS(result, script_code, ""));
2221 }
2222 }
2223 return out;
2224 };
2225 }
2226
2228 on_pre_engine_restart_callback = nullptr;
2229 if (SAFE_ACCESS(args, on_pre_engine_restart_callback, nullptr) != nullptr) {
2230 on_pre_engine_restart_callback = [ptr =
2231 args->on_pre_engine_restart_callback,
2232 user_data]() { return ptr(user_data); };
2233 }
2234
2236 nullptr;
2237 if (SAFE_ACCESS(args, channel_update_callback, nullptr) != nullptr) {
2238 channel_update_callback = [ptr = args->channel_update_callback, user_data](
2239 const std::string& name, bool listening) {
2240 FlutterChannelUpdate update{sizeof(FlutterChannelUpdate), name.c_str(),
2241 listening};
2242 ptr(&update, user_data);
2243 };
2244 }
2245
2247 view_focus_change_request_callback = nullptr;
2248 if (SAFE_ACCESS(args, view_focus_change_request_callback, nullptr) !=
2249 nullptr) {
2250 view_focus_change_request_callback =
2251 [ptr = args->view_focus_change_request_callback,
2253 FlutterViewFocusChangeRequest embedder_request{
2255 .view_id = request.view_id(),
2256 .state = static_cast<FlutterViewFocusState>(request.state()),
2257 .direction =
2258 static_cast<FlutterViewFocusDirection>(request.direction()),
2259 };
2260 ptr(&embedder_request, user_data);
2261 };
2262 }
2263
2264 auto external_view_embedder_result = InferExternalViewEmbedderFromArgs(
2265 SAFE_ACCESS(args, compositor, nullptr), settings.enable_impeller);
2266 if (!external_view_embedder_result.ok()) {
2267 FML_LOG(ERROR) << external_view_embedder_result.status().message();
2269 "Compositor arguments were invalid.");
2270 }
2271
2273 {
2274 update_semantics_callback, //
2275 platform_message_response_callback, //
2276 vsync_callback, //
2277 compute_platform_resolved_locale_callback, //
2278 on_pre_engine_restart_callback, //
2279 channel_update_callback, //
2280 view_focus_change_request_callback, //
2281 };
2282
2283 auto on_create_platform_view = InferPlatformViewCreationCallback(
2284 config, user_data, platform_dispatch_table,
2285 std::move(external_view_embedder_result.value()),
2286 settings.enable_impeller);
2287
2288 if (!on_create_platform_view) {
2289 return LOG_EMBEDDER_ERROR(
2291 "Could not infer platform view creation callback.");
2292 }
2293
2295 [](flutter::Shell& shell) {
2296 return std::make_unique<flutter::Rasterizer>(shell);
2297 };
2298
2299 using ExternalTextureResolver = flutter::EmbedderExternalTextureResolver;
2300 std::unique_ptr<ExternalTextureResolver> external_texture_resolver;
2301 external_texture_resolver = std::make_unique<ExternalTextureResolver>();
2302
2303#ifdef SHELL_ENABLE_GL
2305 external_texture_callback;
2306 if (config->type == kOpenGL) {
2307 const FlutterOpenGLRendererConfig* open_gl_config = &config->open_gl;
2308 if (SAFE_ACCESS(open_gl_config, gl_external_texture_frame_callback,
2309 nullptr) != nullptr) {
2310 external_texture_callback =
2311 [ptr = open_gl_config->gl_external_texture_frame_callback, user_data](
2312 int64_t texture_identifier, size_t width,
2313 size_t height) -> std::unique_ptr<FlutterOpenGLTexture> {
2314 std::unique_ptr<FlutterOpenGLTexture> texture =
2315 std::make_unique<FlutterOpenGLTexture>();
2316 if (!ptr(user_data, texture_identifier, width, height, texture.get())) {
2317 return nullptr;
2318 }
2319 return texture;
2320 };
2321 external_texture_resolver =
2322 std::make_unique<ExternalTextureResolver>(external_texture_callback);
2323 }
2324 }
2325#endif
2326#ifdef SHELL_ENABLE_METAL
2328 external_texture_metal_callback;
2329 if (config->type == kMetal) {
2330 const FlutterMetalRendererConfig* metal_config = &config->metal;
2331 if (SAFE_ACCESS(metal_config, external_texture_frame_callback, nullptr)) {
2332 external_texture_metal_callback =
2333 [ptr = metal_config->external_texture_frame_callback, user_data](
2334 int64_t texture_identifier, size_t width,
2335 size_t height) -> std::unique_ptr<FlutterMetalExternalTexture> {
2336 std::unique_ptr<FlutterMetalExternalTexture> texture =
2337 std::make_unique<FlutterMetalExternalTexture>();
2338 texture->struct_size = sizeof(FlutterMetalExternalTexture);
2339 if (!ptr(user_data, texture_identifier, width, height, texture.get())) {
2340 return nullptr;
2341 }
2342 return texture;
2343 };
2344 external_texture_resolver = std::make_unique<ExternalTextureResolver>(
2345 external_texture_metal_callback);
2346 }
2347 }
2348#endif
2349 auto custom_task_runners = SAFE_ACCESS(args, custom_task_runners, nullptr);
2350 auto thread_config_callback = [&custom_task_runners](
2351 const fml::Thread::ThreadConfig& config) {
2353 if (!custom_task_runners || !custom_task_runners->thread_priority_setter) {
2354 return;
2355 }
2357 switch (config.priority) {
2360 break;
2363 break;
2366 break;
2369 break;
2370 }
2371 custom_task_runners->thread_priority_setter(priority);
2372 };
2373 auto thread_host =
2375 custom_task_runners, thread_config_callback);
2376
2377 if (!thread_host || !thread_host->IsValid()) {
2379 "Could not set up or infer thread configuration "
2380 "to run the Flutter engine on.");
2381 }
2382
2383 auto task_runners = thread_host->GetTaskRunners();
2384
2385 if (!task_runners.IsValid()) {
2387 "Task runner configuration was invalid.");
2388 }
2389
2390 // Embedder supplied UI task runner runner does not have a message loop.
2391 bool has_ui_thread_message_loop =
2392 task_runners.GetUITaskRunner()->GetTaskQueueId().is_valid();
2393 // Message loop observers are used to flush the microtask queue.
2394 // If there is no message loop the queue is flushed from
2395 // EmbedderEngine::RunTask.
2396 settings.task_observer_add = [has_ui_thread_message_loop](
2397 intptr_t key, const fml::closure& callback) {
2398 if (has_ui_thread_message_loop) {
2400 }
2402 };
2403 settings.task_observer_remove = [has_ui_thread_message_loop](
2404 fml::TaskQueueId queue_id, intptr_t key) {
2405 if (has_ui_thread_message_loop) {
2407 }
2408 };
2409
2410 auto run_configuration =
2412
2413 if (SAFE_ACCESS(args, custom_dart_entrypoint, nullptr) != nullptr) {
2414 auto dart_entrypoint = std::string{args->custom_dart_entrypoint};
2415 if (!dart_entrypoint.empty()) {
2416 run_configuration.SetEntrypoint(std::move(dart_entrypoint));
2417 }
2418 }
2419
2420 if (SAFE_ACCESS(args, dart_entrypoint_argc, 0) > 0) {
2421 if (SAFE_ACCESS(args, dart_entrypoint_argv, nullptr) == nullptr) {
2423 "Could not determine Dart entrypoint arguments "
2424 "as dart_entrypoint_argc "
2425 "was set, but dart_entrypoint_argv was null.");
2426 }
2427 std::vector<std::string> arguments(args->dart_entrypoint_argc);
2428 for (int i = 0; i < args->dart_entrypoint_argc; ++i) {
2429 arguments[i] = std::string{args->dart_entrypoint_argv[i]};
2430 }
2431 run_configuration.SetEntrypointArgs(std::move(arguments));
2432 }
2433
2434 if (SAFE_ACCESS(args, engine_id, 0) != 0) {
2435 run_configuration.SetEngineId(args->engine_id);
2436 }
2437
2438 if (!run_configuration.IsValid()) {
2439 return LOG_EMBEDDER_ERROR(
2441 "Could not infer the Flutter project to run from given arguments.");
2442 }
2443
2444 // Create the engine but don't launch the shell or run the root isolate.
2445 auto embedder_engine = std::make_unique<flutter::EmbedderEngine>(
2446 std::move(thread_host), //
2447 std::move(task_runners), //
2448 std::move(settings), //
2449 std::move(run_configuration), //
2450 on_create_platform_view, //
2451 on_create_rasterizer, //
2452 std::move(external_texture_resolver) //
2453 );
2454
2455 // Release the ownership of the embedder engine to the caller.
2456 *engine_out = reinterpret_cast<FLUTTER_API_SYMBOL(FlutterEngine)>(
2457 embedder_engine.release());
2458 return kSuccess;
2459}
2460
2463 if (!engine) {
2464 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2465 }
2466
2467 auto embedder_engine = reinterpret_cast<flutter::EmbedderEngine*>(engine);
2468
2469 // The engine must not already be running. Initialize may only be called
2470 // once on an engine instance.
2471 if (embedder_engine->IsValid()) {
2472 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2473 }
2474
2475 // Step 1: Launch the shell.
2476 if (!embedder_engine->LaunchShell()) {
2478 "Could not launch the engine using supplied "
2479 "initialization arguments.");
2480 }
2481
2482 // Step 2: Tell the platform view to initialize itself.
2483 if (!embedder_engine->NotifyCreated()) {
2485 "Could not create platform view components.");
2486 }
2487
2488 // Step 3: Launch the root isolate.
2489 if (!embedder_engine->RunRootIsolate()) {
2490 return LOG_EMBEDDER_ERROR(
2492 "Could not run the root isolate of the Flutter application using the "
2493 "project arguments specified.");
2494 }
2495
2496 return kSuccess;
2497}
2498
2501 engine,
2502 const FlutterAddViewInfo* info) {
2503 if (!engine) {
2504 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2505 }
2506 if (!info || !info->view_metrics || !info->add_view_callback) {
2508 "Add view info handle was invalid.");
2509 }
2510
2513 return LOG_EMBEDDER_ERROR(
2515 "Add view info was invalid. The implicit view cannot be added.");
2516 }
2518 view_id) {
2521 "Add view info was invalid. The info and "
2522 "window metric view IDs must match.");
2523 }
2524 }
2525
2526 // TODO(loicsharma): Return an error if the engine was initialized with
2527 // callbacks that are incompatible with multiple views.
2528 // https://github.com/flutter/flutter/issues/144806
2529
2530 std::variant<flutter::ViewportMetrics, std::string> metrics_or_error =
2532
2533 if (const std::string* error = std::get_if<std::string>(&metrics_or_error)) {
2534 return LOG_EMBEDDER_ERROR(kInvalidArguments, error->c_str());
2535 }
2536
2537 auto metrics = std::get<flutter::ViewportMetrics>(metrics_or_error);
2538
2539 // The engine must be running to add a view.
2540 auto embedder_engine = reinterpret_cast<flutter::EmbedderEngine*>(engine);
2541 if (!embedder_engine->IsValid()) {
2542 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2543 }
2544
2546 [c_callback = info->add_view_callback,
2547 user_data = info->user_data](bool added) {
2548 FlutterAddViewResult result = {};
2549 result.struct_size = sizeof(FlutterAddViewResult);
2550 result.added = added;
2551 result.user_data = user_data;
2552 c_callback(&result);
2553 };
2554
2555 embedder_engine->GetShell().GetPlatformView()->AddView(view_id, metrics,
2556 callback);
2557 return kSuccess;
2558}
2559
2562 engine,
2563 const FlutterRemoveViewInfo* info) {
2564 if (!engine) {
2565 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2566 }
2567 if (!info || !info->remove_view_callback) {
2569 "Remove view info handle was invalid.");
2570 }
2571
2572 if (info->view_id == kFlutterImplicitViewId) {
2573 return LOG_EMBEDDER_ERROR(
2575 "Remove view info was invalid. The implicit view cannot be removed.");
2576 }
2577
2578 // TODO(loicsharma): Return an error if the engine was initialized with
2579 // callbacks that are incompatible with multiple views.
2580 // https://github.com/flutter/flutter/issues/144806
2581
2582 // The engine must be running to remove a view.
2583 auto embedder_engine = reinterpret_cast<flutter::EmbedderEngine*>(engine);
2584 if (!embedder_engine->IsValid()) {
2585 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2586 }
2587
2589 [c_callback = info->remove_view_callback,
2590 user_data = info->user_data](bool removed) {
2591 FlutterRemoveViewResult result = {};
2592 result.struct_size = sizeof(FlutterRemoveViewResult);
2593 result.removed = removed;
2594 result.user_data = user_data;
2595 c_callback(&result);
2596 };
2597
2598 embedder_engine->GetShell().GetPlatformView()->RemoveView(info->view_id,
2599 callback);
2600 return kSuccess;
2601}
2602
2605 const FlutterViewFocusEvent* event) {
2606 if (!engine) {
2607 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2608 }
2609 if (!event) {
2611 "View focus event must not be null.");
2612 }
2613 // The engine must be running to focus a view.
2614 auto embedder_engine = reinterpret_cast<flutter::EmbedderEngine*>(engine);
2615 if (!embedder_engine->IsValid()) {
2616 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2617 }
2618
2619 if (!STRUCT_HAS_MEMBER(event, direction)) {
2621 "The event struct has invalid size.");
2622 }
2623
2624 flutter::ViewFocusEvent flutter_event(
2625 event->view_id, //
2626 static_cast<flutter::ViewFocusState>(event->state),
2627 static_cast<flutter::ViewFocusDirection>(event->direction));
2628
2629 embedder_engine->GetShell().GetPlatformView()->SendViewFocusEvent(
2630 flutter_event);
2631
2632 return kSuccess;
2633}
2634
2637 engine) {
2638 if (engine == nullptr) {
2639 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2640 }
2641
2642 auto embedder_engine = reinterpret_cast<flutter::EmbedderEngine*>(engine);
2643 embedder_engine->NotifyDestroyed();
2644 embedder_engine->CollectShell();
2645 embedder_engine->CollectThreadHost();
2646 return kSuccess;
2647}
2648
2650 engine) {
2651 auto result = FlutterEngineDeinitialize(engine);
2652 if (result != kSuccess) {
2653 return result;
2654 }
2655 auto embedder_engine = reinterpret_cast<flutter::EmbedderEngine*>(engine);
2656 delete embedder_engine;
2657 return kSuccess;
2658}
2659
2662 const FlutterWindowMetricsEvent* flutter_metrics) {
2663 if (engine == nullptr || flutter_metrics == nullptr) {
2664 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2665 }
2667 SAFE_ACCESS(flutter_metrics, view_id, kFlutterImplicitViewId);
2668
2669 std::variant<flutter::ViewportMetrics, std::string> metrics_or_error =
2670 MakeViewportMetricsFromWindowMetrics(flutter_metrics);
2671 if (const std::string* error = std::get_if<std::string>(&metrics_or_error)) {
2672 return LOG_EMBEDDER_ERROR(kInvalidArguments, error->c_str());
2673 }
2674
2675 auto metrics = std::get<flutter::ViewportMetrics>(metrics_or_error);
2676
2677 return reinterpret_cast<flutter::EmbedderEngine*>(engine)->SetViewportMetrics(
2678 view_id, metrics)
2679 ? kSuccess
2681 "Viewport metrics were invalid.");
2682}
2683
2684// Returns the flutter::PointerData::Change for the given FlutterPointerPhase.
2711
2712// Returns the flutter::PointerData::DeviceKind for the given
2713// FlutterPointerDeviceKind.
2728
2729// Returns the flutter::PointerData::SignalKind for the given
2730// FlutterPointerSignaKind.
2745
2746// Returns the buttons to synthesize for a PointerData from a
2747// FlutterPointerEvent with no type or buttons set.
2750 switch (change) {
2753 // These kinds of change must have a non-zero `buttons`, otherwise
2754 // gesture recognizers will ignore these events.
2764 return 0;
2765 }
2766 return 0;
2767}
2768
2771 const FlutterPointerEvent* pointers,
2772 size_t events_count) {
2773 if (engine == nullptr) {
2774 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2775 }
2776
2777 if (pointers == nullptr || events_count == 0) {
2778 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid pointer events.");
2779 }
2780
2781 auto packet = std::make_unique<flutter::PointerDataPacket>(events_count);
2782
2783 const FlutterPointerEvent* current = pointers;
2784
2785 for (size_t i = 0; i < events_count; ++i) {
2786 flutter::PointerData pointer_data;
2787 pointer_data.Clear();
2788 // this is currely in use only on android embedding.
2789 pointer_data.embedder_id = 0;
2790 pointer_data.time_stamp = SAFE_ACCESS(current, timestamp, 0);
2791 pointer_data.change = ToPointerDataChange(
2792 SAFE_ACCESS(current, phase, FlutterPointerPhase::kCancel));
2793 pointer_data.physical_x = SAFE_ACCESS(current, x, 0.0);
2794 pointer_data.physical_y = SAFE_ACCESS(current, y, 0.0);
2795 // Delta will be generated in pointer_data_packet_converter.cc.
2796 pointer_data.physical_delta_x = 0.0;
2797 pointer_data.physical_delta_y = 0.0;
2798 pointer_data.device = SAFE_ACCESS(current, device, 0);
2799 // Pointer identifier will be generated in
2800 // pointer_data_packet_converter.cc.
2801 pointer_data.pointer_identifier = 0;
2802 pointer_data.signal_kind = ToPointerDataSignalKind(
2803 SAFE_ACCESS(current, signal_kind, kFlutterPointerSignalKindNone));
2804 pointer_data.scroll_delta_x = SAFE_ACCESS(current, scroll_delta_x, 0.0);
2805 pointer_data.scroll_delta_y = SAFE_ACCESS(current, scroll_delta_y, 0.0);
2806 FlutterPointerDeviceKind device_kind =
2807 SAFE_ACCESS(current, device_kind, kFlutterPointerDeviceKindMouse);
2808 // For backwards compatibility with embedders written before the device
2809 // kind and buttons were exposed, if the device kind is not set treat it
2810 // as a mouse, with a synthesized primary button state based on the phase.
2811 if (device_kind == 0) {
2813 pointer_data.buttons =
2815
2816 } else {
2817 pointer_data.kind = ToPointerDataKind(device_kind);
2818 if (pointer_data.kind == flutter::PointerData::DeviceKind::kTouch) {
2819 // For touch events, set the button internally rather than requiring
2820 // it at the API level, since it's a confusing construction to expose.
2821 if (pointer_data.change == flutter::PointerData::Change::kDown ||
2824 }
2825 } else {
2826 // Buttons use the same mask values, so pass them through directly.
2827 pointer_data.buttons = SAFE_ACCESS(current, buttons, 0);
2828 }
2829 }
2830 pointer_data.pan_x = SAFE_ACCESS(current, pan_x, 0.0);
2831 pointer_data.pan_y = SAFE_ACCESS(current, pan_y, 0.0);
2832 // Delta will be generated in pointer_data_packet_converter.cc.
2833 pointer_data.pan_delta_x = 0.0;
2834 pointer_data.pan_delta_y = 0.0;
2835 pointer_data.scale = SAFE_ACCESS(current, scale, 0.0);
2836 pointer_data.rotation = SAFE_ACCESS(current, rotation, 0.0);
2837 pointer_data.view_id =
2839 packet->SetPointerData(i, pointer_data);
2840 current = reinterpret_cast<const FlutterPointerEvent*>(
2841 reinterpret_cast<const uint8_t*>(current) + current->struct_size);
2842 }
2843
2844 return reinterpret_cast<flutter::EmbedderEngine*>(engine)
2845 ->DispatchPointerDataPacket(std::move(packet))
2846 ? kSuccess
2848 "Could not dispatch pointer events to the "
2849 "running Flutter application.");
2850}
2851
2853 FlutterKeyEventType event_kind) {
2854 switch (event_kind) {
2861 }
2863}
2864
2881
2882// Send a platform message to the framework.
2883//
2884// The `data_callback` will be invoked with `user_data`, and must not be empty.
2887 const char* channel,
2888 const uint8_t* data,
2889 size_t size,
2890 FlutterDataCallback data_callback,
2891 void* user_data) {
2892 FlutterEngineResult result;
2893
2894 FlutterPlatformMessageResponseHandle* response_handle;
2896 engine, data_callback, user_data, &response_handle);
2897 if (result != kSuccess) {
2898 return result;
2899 }
2900
2902 sizeof(FlutterPlatformMessage), // struct_size
2903 channel, // channel
2904 data, // message
2905 size, // message_size
2906 response_handle, // response_handle
2907 };
2908
2910 // Whether `SendPlatformMessage` succeeds or not, the response handle must be
2911 // released.
2912 FlutterEngineResult release_result =
2914 if (result != kSuccess) {
2915 return result;
2916 }
2917
2918 return release_result;
2919}
2920
2922 engine,
2923 const FlutterKeyEvent* event,
2925 void* user_data) {
2926 if (engine == nullptr) {
2927 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2928 }
2929
2930 if (event == nullptr) {
2931 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid key event.");
2932 }
2933
2934 const char* character = SAFE_ACCESS(event, character, nullptr);
2935
2936 flutter::KeyData key_data;
2937 key_data.Clear();
2938 key_data.timestamp = static_cast<uint64_t>(SAFE_ACCESS(event, timestamp, 0));
2939 key_data.type = MapKeyEventType(
2941 key_data.physical = SAFE_ACCESS(event, physical, 0);
2942 key_data.logical = SAFE_ACCESS(event, logical, 0);
2943 key_data.synthesized = SAFE_ACCESS(event, synthesized, false);
2945 event, device_type,
2947
2948 auto packet = std::make_unique<flutter::KeyDataPacket>(key_data, character);
2949
2950 struct MessageData {
2952 void* user_data;
2953 };
2954
2955 MessageData* message_data =
2956 new MessageData{.callback = callback, .user_data = user_data};
2957
2958 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
2960 engine, kFlutterKeyDataChannel, packet->data().data(),
2961 packet->data().size(),
2962 [](const uint8_t* data, size_t size, void* user_data) {
2963 auto message_data = std::unique_ptr<MessageData>(
2964 reinterpret_cast<MessageData*>(user_data));
2965 if (message_data->callback == nullptr) {
2966 return;
2967 }
2968 bool handled = false;
2969 if (size == 1) {
2970 handled = *data != 0;
2971 }
2972 message_data->callback(handled, message_data->user_data);
2973 },
2974 message_data);
2975}
2976
2979 const FlutterPlatformMessage* flutter_message) {
2980 if (engine == nullptr) {
2981 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
2982 }
2983
2984 if (flutter_message == nullptr) {
2985 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid message argument.");
2986 }
2987
2988 if (SAFE_ACCESS(flutter_message, channel, nullptr) == nullptr) {
2989 return LOG_EMBEDDER_ERROR(
2990 kInvalidArguments, "Message argument did not specify a valid channel.");
2991 }
2992
2993 size_t message_size = SAFE_ACCESS(flutter_message, message_size, 0);
2994 const uint8_t* message_data = SAFE_ACCESS(flutter_message, message, nullptr);
2995
2996 if (message_size != 0 && message_data == nullptr) {
2997 return LOG_EMBEDDER_ERROR(
2999 "Message size was non-zero but the message data was nullptr.");
3000 }
3001
3002 const FlutterPlatformMessageResponseHandle* response_handle =
3003 SAFE_ACCESS(flutter_message, response_handle, nullptr);
3004
3006 if (response_handle && response_handle->message) {
3007 response = response_handle->message->response();
3008 }
3009
3010 std::unique_ptr<flutter::PlatformMessage> message;
3011 if (message_size == 0) {
3012 message = std::make_unique<flutter::PlatformMessage>(
3013 flutter_message->channel, response);
3014 } else {
3015 message = std::make_unique<flutter::PlatformMessage>(
3016 flutter_message->channel,
3017 fml::MallocMapping::Copy(message_data, message_size), response);
3018 }
3019
3020 return reinterpret_cast<flutter::EmbedderEngine*>(engine)
3021 ->SendPlatformMessage(std::move(message))
3022 ? kSuccess
3024 "Could not send a message to the running "
3025 "Flutter application.");
3026}
3027
3030 FlutterDataCallback data_callback,
3031 void* user_data,
3032 FlutterPlatformMessageResponseHandle** response_out) {
3033 if (engine == nullptr) {
3034 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
3035 }
3036
3037 if (data_callback == nullptr || response_out == nullptr) {
3038 return LOG_EMBEDDER_ERROR(
3039 kInvalidArguments, "Data callback or the response handle was invalid.");
3040 }
3041
3043 [user_data, data_callback](const uint8_t* data, size_t size) {
3044 data_callback(data, size, user_data);
3045 };
3046
3047 auto platform_task_runner = reinterpret_cast<flutter::EmbedderEngine*>(engine)
3048 ->GetTaskRunners()
3049 .GetPlatformTaskRunner();
3050
3051 auto handle = new FlutterPlatformMessageResponseHandle();
3052
3053 handle->message = std::make_unique<flutter::PlatformMessage>(
3054 "", // The channel is empty and unused as the response handle is going
3055 // to referenced directly in the |FlutterEngineSendPlatformMessage|
3056 // with the container message discarded.
3057 fml::MakeRefCounted<flutter::EmbedderPlatformMessageResponse>(
3058 std::move(platform_task_runner), response_callback));
3059 *response_out = handle;
3060 return kSuccess;
3061}
3062
3066 if (engine == nullptr) {
3067 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3068 }
3069
3070 if (response == nullptr) {
3071 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid response handle.");
3072 }
3073 delete response;
3074 return kSuccess;
3075}
3076
3077// Note: This can execute on any thread.
3081 const uint8_t* data,
3082 size_t data_length) {
3083 if (data_length != 0 && data == nullptr) {
3084 return LOG_EMBEDDER_ERROR(
3086 "Data size was non zero but the pointer to the data was null.");
3087 }
3088
3089 auto response = handle->message->response();
3090
3091 if (response) {
3092 if (data_length == 0) {
3093 response->CompleteEmpty();
3094 } else {
3095 response->Complete(std::make_unique<fml::DataMapping>(
3096 std::vector<uint8_t>({data, data + data_length})));
3097 }
3098 }
3099
3100 delete handle;
3101
3102 return kSuccess;
3103}
3104
3109
3112 int64_t texture_identifier) {
3113 if (engine == nullptr) {
3114 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
3115 }
3116
3117 if (texture_identifier == 0) {
3119 "Texture identifier was invalid.");
3120 }
3121 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->RegisterTexture(
3122 texture_identifier)) {
3124 "Could not register the specified texture.");
3125 }
3126 return kSuccess;
3127}
3128
3131 int64_t texture_identifier) {
3132 if (engine == nullptr) {
3133 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
3134 }
3135
3136 if (texture_identifier == 0) {
3138 "Texture identifier was invalid.");
3139 }
3140
3141 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->UnregisterTexture(
3142 texture_identifier)) {
3144 "Could not un-register the specified texture.");
3145 }
3146
3147 return kSuccess;
3148}
3149
3152 int64_t texture_identifier) {
3153 if (engine == nullptr) {
3154 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3155 }
3156 if (texture_identifier == 0) {
3157 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid texture identifier.");
3158 }
3159 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)
3160 ->MarkTextureFrameAvailable(texture_identifier)) {
3161 return LOG_EMBEDDER_ERROR(
3163 "Could not mark the texture frame as being available.");
3164 }
3165 return kSuccess;
3166}
3167
3170 bool enabled) {
3171 if (engine == nullptr) {
3172 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3173 }
3174 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->SetSemanticsEnabled(
3175 enabled)) {
3177 "Could not update semantics state.");
3178 }
3179 return kSuccess;
3180}
3181
3185 if (engine == nullptr) {
3186 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3187 }
3188 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)
3189 ->SetAccessibilityFeatures(flags)) {
3191 "Could not update accessibility features.");
3192 }
3193 return kSuccess;
3194}
3195
3198 uint64_t node_id,
3200 const uint8_t* data,
3201 size_t data_length) {
3205 .node_id = node_id,
3206 .action = action,
3207 .data = data,
3208 .data_length = data_length};
3210}
3211
3214 const FlutterSendSemanticsActionInfo* info) {
3215 if (engine == nullptr) {
3216 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3217 }
3218 auto engine_action = static_cast<flutter::SemanticsAction>(info->action);
3219 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)
3221 info->view_id, info->node_id, engine_action,
3222 fml::MallocMapping::Copy(info->data, info->data_length))) {
3224 "Could not dispatch semantics action.");
3225 }
3226 return kSuccess;
3227}
3228
3230 engine,
3231 intptr_t baton,
3232 uint64_t frame_start_time_nanos,
3233 uint64_t frame_target_time_nanos) {
3234 if (engine == nullptr) {
3235 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3236 }
3237
3238 TRACE_EVENT0("flutter", "FlutterEngineOnVsync");
3239
3240 auto start_time = fml::TimePoint::FromEpochDelta(
3241 fml::TimeDelta::FromNanoseconds(frame_start_time_nanos));
3242
3243 auto target_time = fml::TimePoint::FromEpochDelta(
3244 fml::TimeDelta::FromNanoseconds(frame_target_time_nanos));
3245
3246 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->OnVsyncEvent(
3247 baton, start_time, target_time)) {
3248 return LOG_EMBEDDER_ERROR(
3250 "Could not notify the running engine instance of a Vsync event.");
3251 }
3252
3253 return kSuccess;
3254}
3255
3258 if (engine == nullptr) {
3259 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3260 }
3261
3262 TRACE_EVENT0("flutter", "FlutterEngineReloadSystemFonts");
3263
3264 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)
3265 ->ReloadSystemFonts()) {
3267 "Could not reload system fonts.");
3268 }
3269
3270 return kSuccess;
3271}
3272
3274 fml::tracing::TraceEvent0("flutter", name, /*flow_id_count=*/0,
3275 /*flow_ids=*/nullptr);
3276}
3277
3281
3283 fml::tracing::TraceEventInstant0("flutter", name, /*flow_id_count=*/0,
3284 /*flow_ids=*/nullptr);
3285}
3286
3290 void* baton) {
3291 if (engine == nullptr) {
3292 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3293 }
3294
3295 if (callback == nullptr) {
3297 "Render thread callback was null.");
3298 }
3299
3300 auto task = [callback, baton]() { callback(baton); };
3301
3302 return reinterpret_cast<flutter::EmbedderEngine*>(engine)
3303 ->PostRenderThreadTask(task)
3304 ? kSuccess
3306 "Could not post the render thread task.");
3307}
3308
3312
3314 engine,
3315 const FlutterTask* task) {
3316 if (engine == nullptr) {
3317 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3318 }
3319
3321 reinterpret_cast<intptr_t>(task->runner))) {
3322 // This task came too late, the embedder has already been destroyed.
3323 // This is not an error, just ignore the task.
3324 return kSuccess;
3325 }
3326
3327 return reinterpret_cast<flutter::EmbedderEngine*>(engine)->RunTask(task)
3328 ? kSuccess
3330 "Could not run the specified task.");
3331}
3332
3334 engine,
3335 const rapidjson::Document& document,
3336 const std::string& channel_name) {
3337 if (channel_name.empty()) {
3338 return false;
3339 }
3340
3341 rapidjson::StringBuffer buffer;
3342 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
3343
3344 if (!document.Accept(writer)) {
3345 return false;
3346 }
3347
3348 const char* message = buffer.GetString();
3349
3350 if (message == nullptr || buffer.GetSize() == 0) {
3351 return false;
3352 }
3353
3354 auto platform_message = std::make_unique<flutter::PlatformMessage>(
3355 channel_name.c_str(), // channel
3357 buffer.GetSize()), // message
3358 nullptr // response
3359 );
3360
3361 return reinterpret_cast<flutter::EmbedderEngine*>(engine)
3362 ->SendPlatformMessage(std::move(platform_message));
3363}
3364
3366 engine,
3367 const FlutterLocale** locales,
3368 size_t locales_count) {
3369 if (engine == nullptr) {
3370 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3371 }
3372
3373 if (locales_count == 0) {
3374 return kSuccess;
3375 }
3376
3377 if (locales == nullptr) {
3378 return LOG_EMBEDDER_ERROR(kInvalidArguments, "No locales were specified.");
3379 }
3380
3381 rapidjson::Document document;
3382 auto& allocator = document.GetAllocator();
3383
3384 document.SetObject();
3385 document.AddMember("method", "setLocale", allocator);
3386
3387 rapidjson::Value args(rapidjson::kArrayType);
3388 args.Reserve(locales_count * 4, allocator);
3389 for (size_t i = 0; i < locales_count; ++i) {
3390 const FlutterLocale* locale = locales[i];
3391 const char* language_code_str = SAFE_ACCESS(locale, language_code, nullptr);
3392 if (language_code_str == nullptr || ::strlen(language_code_str) == 0) {
3393 return LOG_EMBEDDER_ERROR(
3395 "Language code is required but not present in FlutterLocale.");
3396 }
3397
3398 const char* country_code_str = SAFE_ACCESS(locale, country_code, "");
3399 const char* script_code_str = SAFE_ACCESS(locale, script_code, "");
3400 const char* variant_code_str = SAFE_ACCESS(locale, variant_code, "");
3401
3402 rapidjson::Value language_code, country_code, script_code, variant_code;
3403
3404 language_code.SetString(language_code_str, allocator);
3405 country_code.SetString(country_code_str ? country_code_str : "", allocator);
3406 script_code.SetString(script_code_str ? script_code_str : "", allocator);
3407 variant_code.SetString(variant_code_str ? variant_code_str : "", allocator);
3408
3409 // Required.
3410 args.PushBack(language_code, allocator);
3411 args.PushBack(country_code, allocator);
3412 args.PushBack(script_code, allocator);
3413 args.PushBack(variant_code, allocator);
3414 }
3415 document.AddMember("args", args, allocator);
3416
3417 return DispatchJSONPlatformMessage(engine, document, "flutter/localization")
3418 ? kSuccess
3420 "Could not send message to update locale of "
3421 "a running Flutter application.");
3422}
3423
3427
3431 const FlutterEngineDartObject* object) {
3432 if (engine == nullptr) {
3433 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3434 }
3435
3436 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->IsValid()) {
3437 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine not running.");
3438 }
3439
3440 if (port == ILLEGAL_PORT) {
3442 "Attempted to post to an illegal port.");
3443 }
3444
3445 if (object == nullptr) {
3447 "Invalid Dart object to post.");
3448 }
3449
3450 Dart_CObject dart_object = {};
3451 fml::ScopedCleanupClosure typed_data_finalizer;
3452
3453 switch (object->type) {
3455 dart_object.type = Dart_CObject_kNull;
3456 break;
3458 dart_object.type = Dart_CObject_kBool;
3459 dart_object.value.as_bool = object->bool_value;
3460 break;
3462 dart_object.type = Dart_CObject_kInt32;
3463 dart_object.value.as_int32 = object->int32_value;
3464 break;
3466 dart_object.type = Dart_CObject_kInt64;
3467 dart_object.value.as_int64 = object->int64_value;
3468 break;
3470 dart_object.type = Dart_CObject_kDouble;
3471 dart_object.value.as_double = object->double_value;
3472 break;
3474 if (object->string_value == nullptr) {
3476 "kFlutterEngineDartObjectTypeString must be "
3477 "a null terminated string but was null.");
3478 }
3479 dart_object.type = Dart_CObject_kString;
3480 dart_object.value.as_string = const_cast<char*>(object->string_value);
3481 break;
3483 auto* buffer = SAFE_ACCESS(object->buffer_value, buffer, nullptr);
3484 if (buffer == nullptr) {
3486 "kFlutterEngineDartObjectTypeBuffer must "
3487 "specify a buffer but found nullptr.");
3488 }
3489 auto buffer_size = SAFE_ACCESS(object->buffer_value, buffer_size, 0);
3490 auto callback =
3491 SAFE_ACCESS(object->buffer_value, buffer_collect_callback, nullptr);
3492 auto user_data = SAFE_ACCESS(object->buffer_value, user_data, nullptr);
3493
3494 // The user has provided a callback, let them manage the lifecycle of
3495 // the underlying data. If not, copy it out from the provided buffer.
3496
3497 if (callback == nullptr) {
3498 dart_object.type = Dart_CObject_kTypedData;
3499 dart_object.value.as_typed_data.type = Dart_TypedData_kUint8;
3500 dart_object.value.as_typed_data.length = buffer_size;
3501 dart_object.value.as_typed_data.values = buffer;
3502 } else {
3503 struct ExternalTypedDataPeer {
3504 void* user_data = nullptr;
3505 VoidCallback trampoline = nullptr;
3506 };
3507 auto peer = new ExternalTypedDataPeer();
3508 peer->user_data = user_data;
3509 peer->trampoline = callback;
3510 // This finalizer is set so that in case of failure of the
3511 // Dart_PostCObject below, we collect the peer. The embedder is still
3512 // responsible for collecting the buffer in case of non-kSuccess
3513 // returns from this method. This finalizer must be released in case
3514 // of kSuccess returns from this method.
3515 typed_data_finalizer.SetClosure([peer]() {
3516 // This is the tiny object we use as the peer to the Dart call so
3517 // that we can attach the a trampoline to the embedder supplied
3518 // callback. In case of error, we need to collect this object lest
3519 // we introduce a tiny leak.
3520 delete peer;
3521 });
3522 dart_object.type = Dart_CObject_kExternalTypedData;
3523 dart_object.value.as_external_typed_data.type = Dart_TypedData_kUint8;
3524 dart_object.value.as_external_typed_data.length = buffer_size;
3525 dart_object.value.as_external_typed_data.data = buffer;
3526 dart_object.value.as_external_typed_data.peer = peer;
3527 dart_object.value.as_external_typed_data.callback =
3528 +[](void* unused_isolate_callback_data, void* peer) {
3529 auto typed_peer = reinterpret_cast<ExternalTypedDataPeer*>(peer);
3530 typed_peer->trampoline(typed_peer->user_data);
3531 delete typed_peer;
3532 };
3533 }
3534 } break;
3535 default:
3536 return LOG_EMBEDDER_ERROR(
3538 "Invalid FlutterEngineDartObjectType type specified.");
3539 }
3540
3541 if (!Dart_PostCObject(port, &dart_object)) {
3543 "Could not post the object to the Dart VM.");
3544 }
3545
3546 // On a successful call, the VM takes ownership of and is responsible for
3547 // invoking the finalizer.
3548 typed_data_finalizer.Release();
3549 return kSuccess;
3550}
3551
3553 FLUTTER_API_SYMBOL(FlutterEngine) raw_engine) {
3554 auto engine = reinterpret_cast<flutter::EmbedderEngine*>(raw_engine);
3555 if (engine == nullptr || !engine->IsValid()) {
3556 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine was invalid.");
3557 }
3558
3559 engine->GetShell().NotifyLowMemoryWarning();
3560
3561 rapidjson::Document document;
3562 auto& allocator = document.GetAllocator();
3563
3564 document.SetObject();
3565 document.AddMember("type", "memoryPressure", allocator);
3566
3567 return DispatchJSONPlatformMessage(raw_engine, document, "flutter/system")
3568 ? kSuccess
3571 "Could not dispatch the low memory notification message.");
3572}
3573
3577 void* user_data) {
3578 if (engine == nullptr) {
3579 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3580 }
3581
3582 if (callback == nullptr) {
3584 "Invalid native thread callback.");
3585 }
3586
3587 return reinterpret_cast<flutter::EmbedderEngine*>(engine)
3588 ->PostTaskOnEngineManagedNativeThreads(
3591 })
3592 ? kSuccess
3594 "Internal error while attempting to post "
3595 "tasks to all threads.");
3596}
3597
3598namespace {
3599static bool ValidDisplayConfiguration(const FlutterEngineDisplay* displays,
3600 size_t display_count) {
3601 std::set<FlutterEngineDisplayId> display_ids;
3602 for (size_t i = 0; i < display_count; i++) {
3603 if (displays[i].single_display && display_count != 1) {
3604 return false;
3605 }
3606 display_ids.insert(displays[i].display_id);
3607 }
3608
3609 return display_ids.size() == display_count;
3610}
3611} // namespace
3612
3615 const FlutterEngineDisplaysUpdateType update_type,
3616 const FlutterEngineDisplay* embedder_displays,
3617 size_t display_count) {
3618 if (raw_engine == nullptr) {
3619 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3620 }
3621
3622 if (!ValidDisplayConfiguration(embedder_displays, display_count)) {
3623 return LOG_EMBEDDER_ERROR(
3625 "Invalid FlutterEngineDisplay configuration specified.");
3626 }
3627
3628 auto engine = reinterpret_cast<flutter::EmbedderEngine*>(raw_engine);
3629
3630 switch (update_type) {
3632 std::vector<std::unique_ptr<flutter::Display>> displays;
3633 const auto* display = embedder_displays;
3634 for (size_t i = 0; i < display_count; i++) {
3635 displays.push_back(std::make_unique<flutter::Display>(
3636 SAFE_ACCESS(display, display_id, i), //
3637 SAFE_ACCESS(display, refresh_rate, 0), //
3638 SAFE_ACCESS(display, width, 0), //
3639 SAFE_ACCESS(display, height, 0), //
3640 SAFE_ACCESS(display, device_pixel_ratio, 1)));
3641 display = reinterpret_cast<const FlutterEngineDisplay*>(
3642 reinterpret_cast<const uint8_t*>(display) + display->struct_size);
3643 }
3644 engine->GetShell().OnDisplayUpdates(std::move(displays));
3645 return kSuccess;
3646 }
3647 default:
3648 return LOG_EMBEDDER_ERROR(
3650 "Invalid FlutterEngineDisplaysUpdateType type specified.");
3651 }
3652}
3653
3655 engine) {
3656 if (engine == nullptr) {
3657 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3658 }
3659
3660 return reinterpret_cast<flutter::EmbedderEngine*>(engine)->ScheduleFrame()
3661 ? kSuccess
3663 "Could not schedule frame.");
3664}
3665
3669 void* user_data) {
3670 if (engine == nullptr) {
3671 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3672 }
3673
3674 if (callback == nullptr) {
3676 "Next frame callback was null.");
3677 }
3678
3679 flutter::EmbedderEngine* embedder_engine =
3680 reinterpret_cast<flutter::EmbedderEngine*>(engine);
3681
3682 fml::WeakPtr<flutter::PlatformView> weak_platform_view =
3683 embedder_engine->GetShell().GetPlatformView();
3684
3685 if (!weak_platform_view) {
3687 "Platform view unavailable.");
3688 }
3689
3690 weak_platform_view->SetNextFrameCallback(
3692
3693 return kSuccess;
3694}
3695
3697 FlutterEngineProcTable* table) {
3698 if (!table) {
3699 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Null table specified.");
3700 }
3701#define SET_PROC(member, function) \
3702 if (STRUCT_HAS_MEMBER(table, member)) { \
3703 table->member = &function; \
3704 }
3705
3706 SET_PROC(CreateAOTData, FlutterEngineCreateAOTData);
3707 SET_PROC(CollectAOTData, FlutterEngineCollectAOTData);
3710 SET_PROC(Initialize, FlutterEngineInitialize);
3711 SET_PROC(Deinitialize, FlutterEngineDeinitialize);
3712 SET_PROC(RunInitialized, FlutterEngineRunInitialized);
3713 SET_PROC(SendWindowMetricsEvent, FlutterEngineSendWindowMetricsEvent);
3714 SET_PROC(SendPointerEvent, FlutterEngineSendPointerEvent);
3715 SET_PROC(SendKeyEvent, FlutterEngineSendKeyEvent);
3716 SET_PROC(SendPlatformMessage, FlutterEngineSendPlatformMessage);
3717 SET_PROC(PlatformMessageCreateResponseHandle,
3719 SET_PROC(PlatformMessageReleaseResponseHandle,
3721 SET_PROC(SendPlatformMessageResponse,
3723 SET_PROC(RegisterExternalTexture, FlutterEngineRegisterExternalTexture);
3724 SET_PROC(UnregisterExternalTexture, FlutterEngineUnregisterExternalTexture);
3725 SET_PROC(MarkExternalTextureFrameAvailable,
3727 SET_PROC(UpdateSemanticsEnabled, FlutterEngineUpdateSemanticsEnabled);
3728 SET_PROC(UpdateAccessibilityFeatures,
3730 SET_PROC(DispatchSemanticsAction, FlutterEngineDispatchSemanticsAction);
3731 SET_PROC(SendSemanticsAction, FlutterEngineSendSemanticsAction);
3733 SET_PROC(ReloadSystemFonts, FlutterEngineReloadSystemFonts);
3734 SET_PROC(TraceEventDurationBegin, FlutterEngineTraceEventDurationBegin);
3735 SET_PROC(TraceEventDurationEnd, FlutterEngineTraceEventDurationEnd);
3736 SET_PROC(TraceEventInstant, FlutterEngineTraceEventInstant);
3737 SET_PROC(PostRenderThreadTask, FlutterEnginePostRenderThreadTask);
3740 SET_PROC(UpdateLocales, FlutterEngineUpdateLocales);
3741 SET_PROC(RunsAOTCompiledDartCode, FlutterEngineRunsAOTCompiledDartCode);
3742 SET_PROC(PostDartObject, FlutterEnginePostDartObject);
3743 SET_PROC(NotifyLowMemoryWarning, FlutterEngineNotifyLowMemoryWarning);
3744 SET_PROC(PostCallbackOnAllNativeThreads,
3746 SET_PROC(NotifyDisplayUpdate, FlutterEngineNotifyDisplayUpdate);
3747 SET_PROC(ScheduleFrame, FlutterEngineScheduleFrame);
3748 SET_PROC(SetNextFrameCallback, FlutterEngineSetNextFrameCallback);
3750 SET_PROC(RemoveView, FlutterEngineRemoveView);
3751 SET_PROC(SendViewFocusEvent, FlutterEngineSendViewFocusEvent);
3752#undef SET_PROC
3753
3754 return kSuccess;
3755}
GLenum type
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:176
bool DispatchSemanticsAction(int64_t view_id, int node_id, flutter::SemanticsAction action, fml::MallocMapping args)
std::function< std::unique_ptr< FlutterOpenGLTexture >(int64_t, size_t, size_t)> ExternalTextureCallback
std::function< std::unique_ptr< FlutterMetalExternalTexture >(int64_t, size_t, size_t)> ExternalTextureCallback
std::function< bool(FlutterViewId view_id, const std::vector< const FlutterLayer * > &layers)> PresentCallback
std::function< std::unique_ptr< EmbedderRenderTarget >(GrDirectContext *context, const std::shared_ptr< impeller::AiksContext > &aiks_context, const FlutterBackingStoreConfig &config)> CreateRenderTargetCallback
std::function< void(const uint8_t *data, size_t size)> Callback
std::function< SetCurrentResult()> MakeOrClearCurrentCallback
static bool RunnerIsValid(intptr_t runner)
static std::unique_ptr< EmbedderThreadHost > CreateEmbedderOrEngineManagedThreadHost(const FlutterCustomTaskRunners *custom_task_runners, const flutter::ThreadConfigSetter &config_setter=fml::Thread::SetCurrentThreadName)
std::function< void *(const char *)> GLProcResolver
static SkColorType ColorTypeFromFormat(const VkFormat format)
static void SetCacheDirectoryPath(std::string path)
std::function< void()> OnPreEngineRestartCallback
std::function< void(int64_t view_id, flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates actions)> UpdateSemanticsCallback
std::function< void(std::unique_ptr< PlatformMessage >)> PlatformMessageResponseCallback
std::function< std::unique_ptr< std::vector< std::string > >(const std::vector< std::string > &supported_locale_data)> ComputePlatformResolvedLocaleCallback
std::function< void(const std::string &, bool)> ChanneUpdateCallback
std::function< void(const ViewFocusChangeRequest &)> ViewFocusChangeRequestCallback
std::function< void(bool removed)> RemoveViewCallback
std::function< void(bool added)> AddViewCallback
static RunConfiguration InferFromSettings(const Settings &settings, const fml::RefPtr< fml::TaskRunner > &io_worker=nullptr, IsolateLaunchType launch_type=IsolateLaunchType::kNewGroup)
Attempts to infer a run configuration from the settings object. This tries to create a run configurat...
const TaskRunners & GetTaskRunners() const override
If callers wish to interact directly with any shell subcomponents, they must (on the platform thread)...
Definition shell.cc:911
std::function< std::unique_ptr< T >(Shell &)> CreateCallback
Definition shell.h:121
fml::WeakPtr< PlatformView > GetPlatformView()
Platform views may only be accessed on the platform task runner.
Definition shell.cc:930
std::function< void(intptr_t)> VsyncCallback
static std::unique_ptr< FileMapping > CreateReadExecute(const std::string &path)
Definition mapping.cc:44
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
Definition mapping.cc:20
static MallocMapping Copy(const T *begin, const T *end)
Definition mapping.h:162
void RemoveTaskObserver(intptr_t key)
void AddTaskObserver(intptr_t key, const fml::closure &callback)
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
void RunExpiredTasksNow()
static fml::RefPtr< NativeLibrary > CreateForCurrentProcess()
static fml::RefPtr< NativeLibrary > Create(const char *path)
Wraps a closure that is invoked in the destructor unless released by the caller.
Definition closure.h:32
fml::closure SetClosure(const fml::closure &closure)
Definition closure.h:50
fml::closure Release()
Definition closure.h:56
static TaskQueueId Invalid()
@ kNormal
Default priority level.
@ kRaster
Suitable for thread which raster data.
@ kBackground
Suitable for threads that shouldn't disrupt high priority work.
@ kDisplay
Suitable for threads which generate data for the display.
static void SetCurrentThreadName(const ThreadConfig &config)
Definition thread.cc:135
static constexpr TimeDelta FromNanoseconds(int64_t nanos)
Definition time_delta.h:40
constexpr int64_t ToNanoseconds() const
Definition time_delta.h:61
constexpr TimeDelta ToEpochDelta() const
Definition time_point.h:52
static TimePoint Now()
Definition time_point.cc:49
static constexpr TimePoint FromEpochDelta(TimeDelta ticks)
Definition time_point.h:43
static ContextGLES & Cast(Context &base)
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
RenderTarget & SetDepthAttachment(std::optional< DepthAttachment > attachment)
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
static std::shared_ptr< TextureGLES > WrapFBO(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, GLuint fbo)
Create a texture by wrapping an external framebuffer object whose lifecycle is owned by the caller.
static std::shared_ptr< TextureGLES > CreatePlaceholder(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc)
Create a "texture" that is never expected to be bound/unbound explicitly or initialized in any way....
int32_t x
#define SET_PROC(member, function)
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:3282
static FlutterEngineResult InternalSendPlatformMessage(FLUTTER_API_SYMBOL(FlutterEngine) engine, const char *channel, const uint8_t *data, size_t size, FlutterDataCallback data_callback, void *user_data)
Definition embedder.cc:2885
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:3150
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 embedder via the Flutter...
Definition embedder.cc:3313
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:3229
const int32_t kFlutterSemanticsNodeIdBatchEnd
Definition embedder.cc:107
const int32_t kFlutterSemanticsCustomActionIdBatchEnd
Definition embedder.cc:108
static bool IsMetalRendererConfigValid(const FlutterRendererConfig *config)
Definition embedder.cc:191
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:1971
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:3110
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:3365
const uint8_t kPlatformStrongDill[]
static flutter::Shell::CreateCallback< flutter::PlatformView > InferPlatformViewCreationCallback(const FlutterRendererConfig *config, void *user_data, const flutter::PlatformViewEmbedder::PlatformDispatchTable &platform_dispatch_table, std::unique_ptr< flutter::EmbedderExternalViewEmbedder > external_view_embedder, bool enable_impeller)
Definition embedder.cc:811
FlutterEngineResult FlutterEngineSendViewFocusEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterViewFocusEvent *event)
Notifies the engine that platform view focus state has changed.
Definition embedder.cc:2603
FlutterEngineResult FlutterEngineGetProcAddresses(FlutterEngineProcTable *table)
Gets the table of engine function pointers.
Definition embedder.cc:3696
static bool DispatchJSONPlatformMessage(FLUTTER_API_SYMBOL(FlutterEngine) engine, const rapidjson::Document &document, const std::string &channel_name)
Definition embedder.cc:3333
FlutterEngineResult FlutterEngineScheduleFrame(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Schedule a new frame to redraw the content.
Definition embedder.cc:3654
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:3273
FlutterEngineResult FlutterEngineSendWindowMetricsEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterWindowMetricsEvent *flutter_metrics)
Definition embedder.cc:2660
flutter::PointerData::SignalKind ToPointerDataSignalKind(FlutterPointerSignalKind kind)
Definition embedder.cc:2731
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:3309
static bool IsOpenGLRendererConfigValid(const FlutterRendererConfig *config)
Definition embedder.cc:158
FlutterEngineResult FlutterEngineSetNextFrameCallback(FLUTTER_API_SYMBOL(FlutterEngine) engine, VoidCallback callback, void *user_data)
Schedule a callback to be called after the next frame is drawn. This must be called from the platform...
Definition embedder.cc:3666
FlutterEngineResult __FlutterEngineFlushPendingTasksNow()
This API is only meant to be used by platforms that need to flush tasks on a message loop not control...
Definition embedder.cc:3105
#define LOG_EMBEDDER_ERROR(code, reason)
Definition embedder.cc:155
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:3287
static flutter::Shell::CreateCallback< flutter::PlatformView > InferVulkanPlatformViewCreationCallback(const FlutterRendererConfig *config, void *user_data, const flutter::PlatformViewEmbedder::PlatformDispatchTable &platform_dispatch_table, std::unique_ptr< flutter::EmbedderExternalViewEmbedder > external_view_embedder, bool enable_impeller)
Definition embedder.cc:611
static flutter::KeyEventDeviceType MapKeyEventDeviceType(FlutterKeyEventDeviceType event_kind)
Definition embedder.cc:2865
static bool IsRendererValid(const FlutterRendererConfig *config)
Definition embedder.cc:229
static std::unique_ptr< flutter::EmbedderRenderTarget > MakeRenderTargetFromBackingStoreImpeller(FlutterBackingStore backing_store, const fml::closure &on_release, const std::shared_ptr< impeller::AiksContext > &aiks_context, const FlutterBackingStoreConfig &config, const FlutterOpenGLFramebuffer *framebuffer)
Definition embedder.cc:1139
std::unique_ptr< Dart_LoadedElf, LoadedElfDeleter > UniqueLoadedElf
Definition embedder.cc:1672
FlutterEngineResult FlutterEngineDispatchSemanticsAction(FLUTTER_API_SYMBOL(FlutterEngine) engine, uint64_t node_id, FlutterSemanticsAction action, const uint8_t *data, size_t data_length)
Dispatch a semantics action to the specified semantics node in the implicit view.
Definition embedder.cc:3196
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:3428
flutter::PointerData::DeviceKind ToPointerDataKind(FlutterPointerDeviceKind device_kind)
Definition embedder.cc:2714
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:2636
static sk_sp< SkSurface > MakeSkSurfaceFromBackingStore(GrDirectContext *context, const FlutterBackingStoreConfig &config, const FlutterOpenGLTexture *texture)
Definition embedder.cc:846
flutter::PointerData::Change ToPointerDataChange(FlutterPointerPhase phase)
Definition embedder.cc:2685
static constexpr FlutterViewId kFlutterImplicitViewId
Definition embedder.cc:110
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:3574
FLUTTER_EXPORT FlutterEngineResult FlutterEngineAddView(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterAddViewInfo *info)
Adds a view.
Definition embedder.cc:2500
static std::unique_ptr< flutter::EmbedderRenderTarget > MakeRenderTargetFromSkSurface(FlutterBackingStore backing_store, sk_sp< SkSurface > skia_surface, fml::closure on_release, flutter::EmbedderRenderTarget::MakeOrClearCurrentCallback on_make_current, flutter::EmbedderRenderTarget::MakeOrClearCurrentCallback on_clear_current)
Definition embedder.cc:1352
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:1987
static std::unique_ptr< flutter::EmbedderRenderTarget > CreateEmbedderRenderTarget(const FlutterCompositor *compositor, const FlutterBackingStoreConfig &config, GrDirectContext *context, const std::shared_ptr< impeller::AiksContext > &aiks_context, bool enable_impeller)
Definition embedder.cc:1376
flutter::PlatformViewEmbedder::UpdateSemanticsCallback CreateEmbedderSemanticsUpdateCallbackV3(FlutterUpdateSemanticsCallback2 update_semantics_callback, void *user_data)
Definition embedder.cc:1909
FlutterEngineResult FlutterEngineUpdateAccessibilityFeatures(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterAccessibilityFeature flags)
Sets additional accessibility features.
Definition embedder.cc:3182
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:2649
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:3028
FlutterEngineResult FlutterEngineCollectAOTData(FlutterEngineAOTData data)
Collects the AOT data.
Definition embedder.cc:1736
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:3613
FlutterEngineResult FlutterEngineSendPlatformMessage(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessage *flutter_message)
Definition embedder.cc:2977
bool FlutterEngineRunsAOTCompiledDartCode(void)
Returns if the Flutter engine instance will run AOT compiled Dart code. This call has no threading re...
Definition embedder.cc:3424
FlutterEngineResult FlutterEngineReloadSystemFonts(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Reloads the system fonts in engine.
Definition embedder.cc:3256
static flutter::KeyEventType MapKeyEventType(FlutterKeyEventType event_kind)
Definition embedder.cc:2852
flutter::PlatformViewEmbedder::UpdateSemanticsCallback CreateEmbedderSemanticsUpdateCallback(const FlutterProjectArgs *args, void *user_data)
Definition embedder.cc:1925
static flutter::Shell::CreateCallback< flutter::PlatformView > InferSoftwarePlatformViewCreationCallback(const FlutterRendererConfig *config, void *user_data, const flutter::PlatformViewEmbedder::PlatformDispatchTable &platform_dispatch_table, std::unique_ptr< flutter::EmbedderExternalViewEmbedder > external_view_embedder)
Definition embedder.cc:774
static fml::StatusOr< std::unique_ptr< flutter::EmbedderExternalViewEmbedder > > InferExternalViewEmbedderFromArgs(const FlutterCompositor *compositor, bool enable_impeller)
Definition embedder.cc:1535
const intptr_t kPlatformStrongDillSize
#define FLUTTER_EXPORT
Definition embedder.cc:32
flutter::PlatformViewEmbedder::UpdateSemanticsCallback CreateEmbedderSemanticsUpdateCallbackV1(FlutterUpdateSemanticsNodeCallback update_semantics_node_callback, FlutterUpdateSemanticsCustomActionCallback update_semantics_custom_action_callback, void *user_data)
Definition embedder.cc:1845
FlutterEngineResult FlutterEngineSendPointerEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPointerEvent *pointers, size_t events_count)
Definition embedder.cc:2769
FlutterEngineResult FlutterEngineRunInitialized(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Runs an initialized engine instance. An engine can be initialized via FlutterEngineInitialize....
Definition embedder.cc:2461
static bool IsSoftwareRendererConfigValid(const FlutterRendererConfig *config)
Definition embedder.cc:176
static flutter::Shell::CreateCallback< flutter::PlatformView > InferOpenGLPlatformViewCreationCallback(const FlutterRendererConfig *config, void *user_data, const flutter::PlatformViewEmbedder::PlatformDispatchTable &platform_dispatch_table, std::unique_ptr< flutter::EmbedderExternalViewEmbedder > external_view_embedder, bool enable_impeller)
Definition embedder.cc:305
void PopulateJITSnapshotMappingCallbacks(const FlutterProjectArgs *args, flutter::Settings &settings)
Definition embedder.cc:1749
static bool IsVulkanRendererConfigValid(const FlutterRendererConfig *config)
Definition embedder.cc:209
FlutterEngineResult FlutterEngineSendSemanticsAction(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterSendSemanticsActionInfo *info)
Dispatch a semantics action to the specified semantics node within a specific view.
Definition embedder.cc:3212
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:3552
FlutterEngineResult FlutterEngineUnregisterExternalTexture(FLUTTER_API_SYMBOL(FlutterEngine) engine, int64_t texture_identifier)
Unregister a previous texture registration.
Definition embedder.cc:3129
FlutterEngineResult FlutterEngineUpdateSemanticsEnabled(FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled)
Enable or disable accessibility semantics.
Definition embedder.cc:3168
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:2921
static flutter::Shell::CreateCallback< flutter::PlatformView > InferMetalPlatformViewCreationCallback(const FlutterRendererConfig *config, void *user_data, const flutter::PlatformViewEmbedder::PlatformDispatchTable &platform_dispatch_table, std::unique_ptr< flutter::EmbedderExternalViewEmbedder > external_view_embedder, bool enable_impeller)
Definition embedder.cc:517
static FlutterEngineResult LogEmbedderError(FlutterEngineResult code, const char *reason, const char *code_name, const char *function, const char *file, int line)
Definition embedder.cc:134
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:3278
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:3078
const char * kFlutterKeyDataChannel
Definition embedder.cc:132
FLUTTER_EXPORT FlutterEngineResult FlutterEngineRemoveView(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterRemoveViewInfo *info)
Removes a view.
Definition embedder.cc:2561
int64_t PointerDataButtonsForLegacyEvent(flutter::PointerData::Change change)
Definition embedder.cc:2748
void PopulateAOTSnapshotMappingCallbacks(const FlutterProjectArgs *args, flutter::Settings &settings)
Definition embedder.cc:1792
FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterPlatformMessageResponseHandle *response)
Collects the handle created using FlutterPlatformMessageCreateResponseHandle.
Definition embedder.cc:3063
flutter::PlatformViewEmbedder::UpdateSemanticsCallback CreateEmbedderSemanticsUpdateCallbackV2(FlutterUpdateSemanticsCallback update_semantics_callback, void *user_data)
Definition embedder.cc:1894
static std::variant< flutter::ViewportMetrics, std::string > MakeViewportMetricsFromWindowMetrics(const FlutterWindowMetricsEvent *flutter_metrics)
Definition embedder.cc:1612
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:1682
#define FLUTTER_API_SYMBOL(symbol)
Definition embedder.h:67
FlutterKeyEventDeviceType
Definition embedder.h:1352
@ kFlutterKeyEventDeviceTypeKeyboard
Definition embedder.h:1353
@ kFlutterKeyEventDeviceTypeDirectionalPad
Definition embedder.h:1354
@ kFlutterKeyEventDeviceTypeHdmi
Definition embedder.h:1357
@ kFlutterKeyEventDeviceTypeJoystick
Definition embedder.h:1356
@ kFlutterKeyEventDeviceTypeGamepad
Definition embedder.h:1355
void(* FlutterUpdateSemanticsCustomActionCallback)(const FlutterSemanticsCustomAction *, void *)
Definition embedder.h:1816
void(* FlutterUpdateSemanticsCallback)(const FlutterSemanticsUpdate *, void *)
Definition embedder.h:1820
FlutterViewFocusState
Represents the focus state of a given [FlutterView].
Definition embedder.h:1189
@ kFlutterEngineAOTDataSourceTypeElfPath
Definition embedder.h:2428
FlutterViewFocusDirection
Definition embedder.h:1170
struct _FlutterPlatformMessageResponseHandle FlutterPlatformMessageResponseHandle
Definition embedder.h:1431
@ kVulkan
Definition embedder.h:86
@ kOpenGL
Definition embedder.h:80
@ kMetal
Definition embedder.h:85
@ kSoftware
Definition embedder.h:81
void(* FlutterDataCallback)(const uint8_t *, size_t, void *)
Definition embedder.h:1453
FlutterPointerPhase
The phase of the pointer event.
Definition embedder.h:1237
@ kPanZoomUpdate
The pan/zoom updated.
Definition embedder.h:1273
@ kHover
The pointer moved while up.
Definition embedder.h:1269
@ kUp
Definition embedder.h:1245
@ kPanZoomStart
A pan/zoom started on this pointer.
Definition embedder.h:1271
@ kRemove
Definition embedder.h:1267
@ kCancel
Definition embedder.h:1238
@ kDown
Definition embedder.h:1252
@ kAdd
Definition embedder.h:1262
@ kMove
Definition embedder.h:1257
@ kPanZoomEnd
The pan/zoom ended.
Definition embedder.h:1275
FlutterAccessibilityFeature
Definition embedder.h:91
void(* FlutterNativeThreadCallback)(FlutterNativeThreadType type, void *user_data)
Definition embedder.h:2423
@ kFlutterEngineDartObjectTypeString
Definition embedder.h:2336
@ kFlutterEngineDartObjectTypeBool
Definition embedder.h:2332
@ kFlutterEngineDartObjectTypeDouble
Definition embedder.h:2335
@ kFlutterEngineDartObjectTypeInt32
Definition embedder.h:2333
@ kFlutterEngineDartObjectTypeBuffer
Definition embedder.h:2339
@ kFlutterEngineDartObjectTypeInt64
Definition embedder.h:2334
@ kFlutterEngineDartObjectTypeNull
Definition embedder.h:2331
void(* FlutterLogMessageCallback)(const char *, const char *, void *)
Definition embedder.h:2448
FlutterEngineResult
Definition embedder.h:72
@ kInternalInconsistency
Definition embedder.h:76
@ kInvalidLibraryVersion
Definition embedder.h:74
@ kInvalidArguments
Definition embedder.h:75
@ kSuccess
Definition embedder.h:73
FlutterNativeThreadType
Definition embedder.h:2404
FlutterPointerSignalKind
The type of a pointer signal.
Definition embedder.h:1299
@ kFlutterPointerSignalKindScale
Definition embedder.h:1303
@ kFlutterPointerSignalKindScrollInertiaCancel
Definition embedder.h:1302
@ kFlutterPointerSignalKindScroll
Definition embedder.h:1301
@ kFlutterPointerSignalKindNone
Definition embedder.h:1300
void(* FlutterUpdateSemanticsNodeCallback)(const FlutterSemanticsNode *, void *)
Definition embedder.h:1812
void(* VoidCallback)(void *)
Definition embedder.h:409
FlutterEngineDisplaysUpdateType
Definition embedder.h:2318
@ kFlutterEngineDisplaysUpdateTypeStartup
Definition embedder.h:2324
FlutterThreadPriority
Valid values for priority of Thread.
Definition embedder.h:369
@ kBackground
Suitable for threads that shouldn't disrupt high priority work.
Definition embedder.h:371
@ kDisplay
Suitable for threads which generate data for the display.
Definition embedder.h:375
@ kNormal
Default priority level.
Definition embedder.h:373
@ kRaster
Suitable for thread which raster data.
Definition embedder.h:377
FlutterSemanticsAction
Definition embedder.h:115
void(* FlutterKeyEventCallback)(bool, void *)
Definition embedder.h:1427
int64_t FlutterViewId
Definition embedder.h:386
FlutterKeyEventType
Definition embedder.h:1346
@ kFlutterKeyEventTypeDown
Definition embedder.h:1348
@ kFlutterKeyEventTypeUp
Definition embedder.h:1347
@ kFlutterKeyEventTypeRepeat
Definition embedder.h:1349
void(* FlutterUpdateSemanticsCallback2)(const FlutterSemanticsUpdate2 *, void *)
Definition embedder.h:1824
int64_t FlutterEngineDartPort
Definition embedder.h:2328
@ kFlutterOpenGLTargetTypeFramebuffer
Definition embedder.h:417
@ kFlutterOpenGLTargetTypeSurface
Definition embedder.h:420
@ kFlutterOpenGLTargetTypeTexture
Definition embedder.h:414
@ kFlutterBackingStoreTypeSoftware2
Definition embedder.h:2060
@ kFlutterBackingStoreTypeMetal
Specifies a Metal backing store. This is backed by a Metal texture.
Definition embedder.h:2055
@ kFlutterBackingStoreTypeVulkan
Specifies a Vulkan backing store. This is backed by a Vulkan VkImage.
Definition embedder.h:2057
@ kFlutterBackingStoreTypeSoftware
Specified an software allocation for Flutter to render into using the CPU.
Definition embedder.h:2053
@ kFlutterBackingStoreTypeOpenGL
Definition embedder.h:2051
#define FLUTTER_ENGINE_VERSION
Definition embedder.h:70
FlutterPointerDeviceKind
The device type that created a pointer event.
Definition embedder.h:1279
@ kFlutterPointerDeviceKindTouch
Definition embedder.h:1281
@ kFlutterPointerDeviceKindTrackpad
Definition embedder.h:1283
@ kFlutterPointerDeviceKindStylus
Definition embedder.h:1282
@ kFlutterPointerDeviceKindMouse
Definition embedder.h:1280
#define SAFE_EXISTS(pointer, member)
Checks if the member exists and is non-null.
#define SAFE_ACCESS(pointer, member, default_value)
#define STRUCT_HAS_MEMBER(pointer, member)
#define SAFE_EXISTS_ONE_OF(pointer, member1, member2)
Checks if exactly one of member1 or member2 exists and is non-null.
FlutterVulkanImage * image
VkPhysicalDevice physical_device
Definition main.cc:67
VkDevice device
Definition main.cc:69
FlutterEngine engine
Definition main.cc:84
VkInstance instance
Definition main.cc:64
VkQueue queue
Definition main.cc:71
VkSurfaceKHR surface
Definition main.cc:65
const FlutterLayer size_t layers_count
const FlutterLayer ** layers
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const gchar * channel
G_BEGIN_DECLS GBytes * message
const uint8_t uint32_t uint32_t GError ** error
uint32_t uint32_t * format
G_BEGIN_DECLS FlutterViewId view_id
FlutterDesktopBinaryReply callback
#define FML_LOG(severity)
Definition logging.h:101
#define FML_DCHECK(condition)
Definition logging.h:122
Dart_NativeFunction function
Definition fuchsia.cc:50
const char * name
Definition fuchsia.cc:49
static const char * kApplicationKernelSnapshotFileName
FlTexture * texture
double y
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
impeller::Matrix DlMatrix
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
@ kPointerButtonMousePrimary
@ kPointerButtonTouchContact
KeyEventType
Definition key_data.h:22
impeller::IRect32 DlIRect
ViewFocusDirection
Definition view_focus.h:22
Settings SettingsFromCommandLine(const fml::CommandLine &command_line, bool require_merged_platform_ui_thread)
Definition switches.cc:230
KeyEventDeviceType
Definition key_data.h:34
std::string JoinPaths(std::initializer_list< std::string > components)
Definition paths.cc:14
void TraceEventInstant0(TraceArg category_group, TraceArg name, size_t flow_id_count, const uint64_t *flow_ids)
void TraceEvent0(TraceArg category_group, TraceArg name, size_t flow_id_count, const uint64_t *flow_ids)
void TraceEventEnd(TraceArg name)
CommandLine CommandLineFromArgcArgv(int argc, const char *const *argv)
internal::CopyableLambda< T > MakeCopyable(T lambda)
bool IsFile(const std::string &path)
std::function< void()> closure
Definition closure.h:14
std::shared_ptr< Texture > WrapTextureMTL(TextureDescriptor desc, const void *mtl_texture, std::function< void()> deletion_proc=nullptr)
ISize64 ISize
Definition size.h:162
std::optional< SkColorInfo > getSkColorInfo(FlutterSoftwarePixelFormat pixfmt)
std::vector< FlutterEngineDisplay > * displays
uint32_t color_type
int32_t height
int32_t width
UniqueLoadedElf loaded_elf
Definition embedder.cc:1675
const uint8_t * vm_isolate_instrs
Definition embedder.cc:1679
const uint8_t * vm_snapshot_instrs
Definition embedder.cc:1677
const uint8_t * vm_snapshot_data
Definition embedder.cc:1676
const uint8_t * vm_isolate_data
Definition embedder.cc:1678
std::unique_ptr< flutter::PlatformMessage > message
Definition embedder.cc:1661
FlutterAddViewCallback add_view_callback
Definition embedder.h:1117
FlutterViewId view_id
The identifier for the view to add. This must be unique.
Definition embedder.h:1097
const FlutterWindowMetricsEvent * view_metrics
Definition embedder.h:1102
void * user_data
The |FlutterAddViewInfo.user_data|.
Definition embedder.h:1081
bool added
True if the add view operation succeeded.
Definition embedder.h:1078
FlutterSize size
The size of the render target the engine expects to render into.
Definition embedder.h:2093
FlutterVulkanBackingStore vulkan
Definition embedder.h:2085
FlutterMetalBackingStore metal
Definition embedder.h:2083
FlutterBackingStoreType type
Specifies the type of backing store.
Definition embedder.h:2071
FlutterOpenGLBackingStore open_gl
The description of the OpenGL backing store.
Definition embedder.h:2077
FlutterSoftwareBackingStore software
The description of the software backing store.
Definition embedder.h:2079
FlutterSoftwareBackingStore2 software2
The description of the software backing store.
Definition embedder.h:2081
size_t struct_size
The size of this struct. Must be sizeof(FlutterBackingStore).
Definition embedder.h:2065
An update to whether a message channel has a listener set or not.
Definition embedder.h:1829
FlutterBackingStoreCreateCallback create_backing_store_callback
Definition embedder.h:2213
FlutterBackingStoreCollectCallback collect_backing_store_callback
Definition embedder.h:2218
A structure to represent a damage region.
Definition embedder.h:664
size_t num_rects
The number of rectangles within the damage region.
Definition embedder.h:668
size_t struct_size
The size of this struct. Must be sizeof(FlutterDamage).
Definition embedder.h:666
FlutterRect * damage
The actual damage region(s) in question.
Definition embedder.h:670
FlutterEngineAOTDataSourceType type
Definition embedder.h:2434
const char * elf_path
Absolute path to an ELF library file.
Definition embedder.h:2437
FlutterEngineDartObjectType type
Definition embedder.h:2387
const char * string_value
Definition embedder.h:2396
const FlutterEngineDartBuffer * buffer_value
Definition embedder.h:2397
Function-pointer-based versions of the APIs above.
Definition embedder.h:3704
size_t struct_size
The size of this struct. Must be sizeof(FlutterFrameInfo).
Definition embedder.h:681
FlutterUIntSize size
The size of the surface that will be backed by the fbo.
Definition embedder.h:683
FlutterSize size
The size of the layer (in physical pixels).
Definition embedder.h:2147
FlutterMetalTexture texture
Definition embedder.h:1974
FlutterMetalTextureFrameCallback external_texture_frame_callback
Definition embedder.h:908
FlutterMetalCommandQueueHandle present_command_queue
Alias for id<MTLCommandQueue>.
Definition embedder.h:893
FlutterMetalDeviceHandle device
Alias for id<MTLDevice>.
Definition embedder.h:891
FlutterMetalPresentCallback present_drawable_callback
Definition embedder.h:903
FlutterMetalTextureCallback get_next_drawable_callback
Definition embedder.h:898
FlutterMetalTextureHandle texture
Definition embedder.h:865
size_t struct_size
The size of this struct. Must be sizeof(FlutterMetalTexture).
Definition embedder.h:855
VoidCallback destruction_callback
Definition embedder.h:872
FlutterOpenGLSurface surface
Definition embedder.h:1923
FlutterOpenGLTexture texture
A texture for Flutter to render into.
Definition embedder.h:1917
FlutterOpenGLTargetType type
Definition embedder.h:1914
FlutterOpenGLFramebuffer framebuffer
Definition embedder.h:1920
uint32_t name
The name of the framebuffer.
Definition embedder.h:544
VoidCallback destruction_callback
Definition embedder.h:551
void * user_data
User data to be returned on the invocation of the destruction callback.
Definition embedder.h:547
ProcResolver gl_proc_resolver
Definition embedder.h:758
BoolPresentInfoCallback present_with_info
Definition embedder.h:782
TextureFrameCallback gl_external_texture_frame_callback
Definition embedder.h:763
FlutterFrameBufferWithDamageCallback populate_existing_damage
Definition embedder.h:796
TransformationCallback surface_transformation
Definition embedder.h:757
BoolCallback make_resource_current
Definition embedder.h:741
UIntFrameInfoCallback fbo_with_frame_info_callback
Definition embedder.h:771
FlutterOpenGLSurfaceCallback clear_current_callback
Definition embedder.h:594
FlutterOpenGLSurfaceCallback make_current_callback
Definition embedder.h:577
const char * channel
Definition embedder.h:1437
size_t struct_size
The size of this struct. Must be sizeof(FlutterPointerEvent).
Definition embedder.h:1308
size_t struct_size
The size of this struct. Must be sizeof(FlutterPresentInfo).
Definition embedder.h:703
A structure to represent a rectangle.
Definition embedder.h:641
double bottom
Definition embedder.h:645
double top
Definition embedder.h:643
double left
Definition embedder.h:642
double right
Definition embedder.h:644
FlutterRemoveViewCallback remove_view_callback
Definition embedder.h:1165
FlutterViewId view_id
Definition embedder.h:1148
void * user_data
The |FlutterRemoveViewInfo.user_data|.
Definition embedder.h:1129
bool removed
True if the remove view operation succeeded.
Definition embedder.h:1126
FlutterVulkanRendererConfig vulkan
Definition embedder.h:1036
FlutterMetalRendererConfig metal
Definition embedder.h:1035
FlutterSoftwareRendererConfig software
Definition embedder.h:1034
FlutterOpenGLRendererConfig open_gl
Definition embedder.h:1033
FlutterRendererType type
Definition embedder.h:1031
FlutterSemanticsNode * nodes
Definition embedder.h:1788
size_t nodes_count
The number of semantics node updates.
Definition embedder.h:1786
size_t custom_actions_count
The number of semantics custom action updates.
Definition embedder.h:1790
FlutterSemanticsCustomAction * custom_actions
Array of semantics custom actions. Has length custom_actions_count.
Definition embedder.h:1792
FlutterViewId view_id
The ID of the view that includes the node.
Definition embedder.h:2774
FlutterSemanticsAction action
The semantics action.
Definition embedder.h:2780
size_t data_length
The data length.
Definition embedder.h:2786
uint64_t node_id
The semantics node identifier.
Definition embedder.h:2777
const uint8_t * data
Data associated with the action.
Definition embedder.h:2783
double height
Definition embedder.h:629
double width
Definition embedder.h:628
VoidCallback destruction_callback
Definition embedder.h:1960
size_t row_bytes
The number of bytes in a single row of the allocation.
Definition embedder.h:1951
FlutterSoftwarePixelFormat pixel_format
Definition embedder.h:1964
VoidCallback destruction_callback
Definition embedder.h:1941
size_t row_bytes
The number of bytes in a single row of the allocation.
Definition embedder.h:1932
SoftwareSurfacePresentCallback surface_present_callback
Definition embedder.h:1027
FlutterTaskRunner runner
Definition embedder.h:1849
double transY
vertical translation
Definition embedder.h:400
double pers2
perspective scale factor
Definition embedder.h:406
double skewX
horizontal skew factor
Definition embedder.h:392
double pers0
input x-axis perspective factor
Definition embedder.h:402
double scaleX
horizontal scale factor
Definition embedder.h:390
double skewY
vertical skew factor
Definition embedder.h:396
double scaleY
vertical scale factor
Definition embedder.h:398
double pers1
input y-axis perspective factor
Definition embedder.h:404
double transX
horizontal translation
Definition embedder.h:394
uint32_t width
Definition embedder.h:636
FlutterViewFocusState state
The focus state of the view.
Definition embedder.h:1210
FlutterViewFocusDirection direction
The direction in which the focus transitioned across [FlutterView]s.
Definition embedder.h:1213
FlutterViewId view_id
The identifier of the view that received the focus event.
Definition embedder.h:1207
size_t struct_size
The size of this struct. Must be sizeof(FlutterVulkanImage).
Definition embedder.h:928
uint32_t format
The VkFormat of the image (for example: VK_FORMAT_R8G8B8A8_UNORM).
Definition embedder.h:933
FlutterVulkanQueueHandle queue
Definition embedder.h:977
FlutterVulkanDeviceHandle device
Definition embedder.h:968
FlutterVulkanInstanceProcAddressCallback get_instance_proc_address_callback
Definition embedder.h:1006
size_t enabled_instance_extension_count
Definition embedder.h:980
uint32_t queue_family_index
The queue family index of the VkQueue supplied in the next field.
Definition embedder.h:970
FlutterVulkanImageCallback get_next_image_callback
Definition embedder.h:1010
const char ** enabled_instance_extensions
Definition embedder.h:987
const char ** enabled_device_extensions
Definition embedder.h:998
FlutterVulkanInstanceHandle instance
Definition embedder.h:963
FlutterVulkanPresentCallback present_image_callback
Definition embedder.h:1016
FlutterVulkanPhysicalDeviceHandle physical_device
VkPhysicalDevice handle.
Definition embedder.h:965
void operator()(Dart_LoadedElf *elf)
Definition embedder.cc:1665
std::function< bool(GPUMTLTextureInfo texture)> present
GPUMTLDestructionCallback destruction_callback
uint64_t synthesized
Definition key_data.h:70
KeyEventDeviceType device_type
Definition key_data.h:71
uint64_t logical
Definition key_data.h:66
uint64_t physical
Definition key_data.h:65
KeyEventType type
Definition key_data.h:64
uint64_t timestamp
Definition key_data.h:63
std::string application_kernel_asset
Definition settings.h:140
LogMessageCallback log_message_callback
Definition settings.h:316
MappingCallback isolate_snapshot_instr
Definition settings.h:123
std::function< void(const DartIsolate &)> root_isolate_create_callback
Definition settings.h:285
std::string assets_path
Definition settings.h:333
TaskObserverRemove task_observer_remove
Definition settings.h:282
MappingCallback isolate_snapshot_data
Definition settings.h:121
MappingCallback vm_snapshot_data
Definition settings.h:116
TaskObserverAdd task_observer_add
Definition settings.h:281
std::string log_tag
Definition settings.h:320
std::string icu_data_path
Definition settings.h:327
MappingCallback vm_snapshot_instr
Definition settings.h:118
MappingCallback dart_library_sources_kernel
Definition settings.h:129
int64_t old_gen_heap_size
Definition settings.h:352
The ThreadConfig is the thread info include thread name, thread priority.
Definition thread.h:35
std::shared_ptr< Texture > resolve_texture
Definition formats.h:658
LoadAction load_action
Definition formats.h:659
std::shared_ptr< Texture > texture
Definition formats.h:657
StoreAction store_action
Definition formats.h:660
static constexpr Color DarkSlateGray()
Definition color.h:418
constexpr auto GetBottom() const
Definition rect.h:357
constexpr auto GetTop() const
Definition rect.h:353
constexpr auto GetLeft() const
Definition rect.h:351
constexpr auto GetRight() const
Definition rect.h:355
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
std::shared_ptr< const fml::Mapping > data
const uintptr_t id
#define TRACE_EVENT0(category_group, name)
#define GetCurrentTime()