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