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,
499 impeller_flags), // embedder_surface
500 platform_dispatch_table, // embedder platform dispatch table
501 view_embedder // external view embedder
502 );
503 }
504 return std::make_unique<flutter::PlatformViewEmbedder>(
505 shell, // delegate
506 shell.GetTaskRunners(), // task runners
507 std::make_unique<flutter::EmbedderSurfaceGLSkia>(
508 gl_dispatch_table, fbo_reset_after_present,
509 view_embedder), // embedder_surface
510 platform_dispatch_table, // embedder platform dispatch table
511 view_embedder // external view embedder
512 );
513 });
514#else // SHELL_ENABLE_GL
515 FML_LOG(ERROR) << "This Flutter Engine does not support OpenGL rendering.";
516 return nullptr;
517#endif // SHELL_ENABLE_GL
518}
519
522 const FlutterRendererConfig* config,
523 void* user_data,
525 platform_dispatch_table,
526 std::unique_ptr<flutter::EmbedderExternalViewEmbedder>
527 external_view_embedder,
528 bool enable_impeller,
529 impeller::Flags impeller_flags) {
530 if (config->type != kMetal) {
531 return nullptr;
532 }
533
534#ifdef SHELL_ENABLE_METAL
535 std::function<bool(flutter::GPUMTLTextureInfo texture)> metal_present =
536 [ptr = config->metal.present_drawable_callback,
538 FlutterMetalTexture embedder_texture;
539 embedder_texture.struct_size = sizeof(FlutterMetalTexture);
540 embedder_texture.texture = texture.texture;
541 embedder_texture.texture_id = texture.texture_id;
542 embedder_texture.user_data = texture.destruction_context;
543 embedder_texture.destruction_callback = texture.destruction_callback;
544 return ptr(user_data, &embedder_texture);
545 };
546 auto metal_get_texture =
548 const flutter::DlISize& frame_size) -> flutter::GPUMTLTextureInfo {
549 FlutterFrameInfo frame_info = {};
550 frame_info.struct_size = sizeof(FlutterFrameInfo);
551 frame_info.size = {static_cast<uint32_t>(frame_size.width),
552 static_cast<uint32_t>(frame_size.height)};
553 flutter::GPUMTLTextureInfo texture_info;
554
555 FlutterMetalTexture metal_texture = ptr(user_data, &frame_info);
556 texture_info.texture_id = metal_texture.texture_id;
557 texture_info.texture = metal_texture.texture;
558 texture_info.destruction_callback = metal_texture.destruction_callback;
559 texture_info.destruction_context = metal_texture.user_data;
560 return texture_info;
561 };
562
563 std::shared_ptr<flutter::EmbedderExternalViewEmbedder> view_embedder =
564 std::move(external_view_embedder);
565
566 // The static leak checker gets confused by the use of fml::MakeCopyable.
567 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
568 return fml::MakeCopyable([config, metal_present, metal_get_texture,
569 view_embedder, platform_dispatch_table,
570 enable_impeller](flutter::Shell& shell) mutable {
571 std::unique_ptr<flutter::EmbedderSurface> embedder_surface;
572
573 if (enable_impeller) {
575 metal_dispatch_table = {
576 .present = metal_present,
577 .get_texture = metal_get_texture,
578 };
579 impeller::Flags impeller_flags;
580 impeller_flags.use_sdfs = shell.GetSettings().impeller_use_sdfs;
581 embedder_surface =
582 std::make_unique<flutter::EmbedderSurfaceMetalImpeller>(
583 const_cast<flutter::GPUMTLDeviceHandle>(config->metal.device),
586 metal_dispatch_table, view_embedder, impeller_flags);
587 } else {
588#if !SLIMPELLER
590 metal_dispatch_table = {
591 .present = metal_present,
592 .get_texture = metal_get_texture,
593 };
594 embedder_surface = std::make_unique<flutter::EmbedderSurfaceMetalSkia>(
595 const_cast<flutter::GPUMTLDeviceHandle>(config->metal.device),
598 metal_dispatch_table, view_embedder);
599#else // !SLIMPELLER
600 FML_LOG(FATAL) << "Impeller opt-out unavailable.";
601#endif // !SLIMPELLER
602 }
603
604 return std::make_unique<flutter::PlatformViewEmbedder>(
605 shell, // delegate
606 shell.GetTaskRunners(), // task runners
607 std::move(embedder_surface), // embedder surface
608 platform_dispatch_table, // platform dispatch table
609 std::move(view_embedder) // external view embedder
610 );
611 });
612#else // SHELL_ENABLE_METAL
613 FML_LOG(ERROR) << "This Flutter Engine does not support Metal rendering.";
614 return nullptr;
615#endif // SHELL_ENABLE_METAL
616}
617
620 const FlutterRendererConfig* config,
621 void* user_data,
623 platform_dispatch_table,
624 std::unique_ptr<flutter::EmbedderExternalViewEmbedder>
625 external_view_embedder,
626 bool enable_impeller,
627 impeller::Flags impeller_flags) {
628 if (config->type != kVulkan) {
629 return nullptr;
630 }
631
632#ifdef SHELL_ENABLE_VULKAN
633 std::function<void*(VkInstance, const char*)>
634 vulkan_get_instance_proc_address =
636 VkInstance instance, const char* proc_name) -> void* {
637 return ptr(user_data, instance, proc_name);
638 };
639
640 auto vulkan_get_next_image =
641 [ptr = config->vulkan.get_next_image_callback,
642 user_data](const flutter::DlISize& frame_size) -> FlutterVulkanImage {
643 FlutterFrameInfo frame_info = {
644 .struct_size = sizeof(FlutterFrameInfo),
645 .size = {static_cast<uint32_t>(frame_size.width),
646 static_cast<uint32_t>(frame_size.height)},
647 };
648
649 return ptr(user_data, &frame_info);
650 };
651
652 auto vulkan_present_image_callback =
653 [ptr = config->vulkan.present_image_callback, user_data](
654 VkImage image, VkFormat format) -> bool {
655 FlutterVulkanImage image_desc = {
657 .image = reinterpret_cast<uint64_t>(image),
658 .format = static_cast<uint32_t>(format),
659 };
660 return ptr(user_data, &image_desc);
661 };
662
663 auto vk_instance = static_cast<VkInstance>(config->vulkan.instance);
664 auto proc_addr =
665 vulkan_get_instance_proc_address(vk_instance, "vkGetInstanceProcAddr");
666
667 std::shared_ptr<flutter::EmbedderExternalViewEmbedder> view_embedder =
668 std::move(external_view_embedder);
669
670#if IMPELLER_SUPPORTS_RENDERING
671 if (enable_impeller) {
673 vulkan_dispatch_table = {
675 reinterpret_cast<PFN_vkGetInstanceProcAddr>(proc_addr),
676 .get_next_image = vulkan_get_next_image,
677 .present_image = vulkan_present_image_callback,
678 };
679
680 std::unique_ptr<flutter::EmbedderSurfaceVulkanImpeller> embedder_surface =
681 std::make_unique<flutter::EmbedderSurfaceVulkanImpeller>(
682 config->vulkan.version, vk_instance,
687 static_cast<VkPhysicalDevice>(config->vulkan.physical_device),
688 static_cast<VkDevice>(config->vulkan.device),
690 static_cast<VkQueue>(config->vulkan.queue), vulkan_dispatch_table,
691 view_embedder, impeller_flags);
692
693 return fml::MakeCopyable(
694 [embedder_surface = std::move(embedder_surface),
695 platform_dispatch_table,
696 external_view_embedder =
697 std::move(view_embedder)](flutter::Shell& shell) mutable {
698 return std::make_unique<flutter::PlatformViewEmbedder>(
699 shell, // delegate
700 shell.GetTaskRunners(), // task runners
701 std::move(embedder_surface), // embedder surface
702 platform_dispatch_table, // platform dispatch table
703 std::move(external_view_embedder) // external view embedder
704 );
705 });
706 } else {
708 {
710 reinterpret_cast<PFN_vkGetInstanceProcAddr>(proc_addr),
711 .get_next_image = vulkan_get_next_image,
712 .present_image = vulkan_present_image_callback,
713 };
714
715 std::unique_ptr<flutter::EmbedderSurfaceVulkan> embedder_surface =
716 std::make_unique<flutter::EmbedderSurfaceVulkan>(
717 config->vulkan.version, vk_instance,
722 static_cast<VkPhysicalDevice>(config->vulkan.physical_device),
723 static_cast<VkDevice>(config->vulkan.device),
725 static_cast<VkQueue>(config->vulkan.queue), vulkan_dispatch_table,
726 view_embedder);
727
728 return fml::MakeCopyable(
729 [embedder_surface = std::move(embedder_surface),
730 platform_dispatch_table,
731 external_view_embedder =
732 std::move(view_embedder)](flutter::Shell& shell) mutable {
733 return std::make_unique<flutter::PlatformViewEmbedder>(
734 shell, // delegate
735 shell.GetTaskRunners(), // task runners
736 std::move(embedder_surface), // embedder surface
737 platform_dispatch_table, // platform dispatch table
738 std::move(external_view_embedder) // external view embedder
739 );
740 });
741 }
742#else
745 reinterpret_cast<PFN_vkGetInstanceProcAddr>(proc_addr),
746 .get_next_image = vulkan_get_next_image,
747 .present_image = vulkan_present_image_callback,
748 };
749
750 std::unique_ptr<flutter::EmbedderSurfaceVulkan> embedder_surface =
751 std::make_unique<flutter::EmbedderSurfaceVulkan>(
752 config->vulkan.version, vk_instance,
757 static_cast<VkPhysicalDevice>(config->vulkan.physical_device),
758 static_cast<VkDevice>(config->vulkan.device),
760 static_cast<VkQueue>(config->vulkan.queue), vulkan_dispatch_table,
761 view_embedder);
762
763 return fml::MakeCopyable(
764 [embedder_surface = std::move(embedder_surface), platform_dispatch_table,
765 external_view_embedder =
766 std::move(view_embedder)](flutter::Shell& shell) mutable {
767 return std::make_unique<flutter::PlatformViewEmbedder>(
768 shell, // delegate
769 shell.GetTaskRunners(), // task runners
770 std::move(embedder_surface), // embedder surface
771 platform_dispatch_table, // platform dispatch table
772 std::move(external_view_embedder) // external view embedder
773 );
774 });
775#endif // // IMPELLER_SUPPORTS_RENDERING
776#else // SHELL_ENABLE_VULKAN
777 FML_LOG(ERROR) << "This Flutter Engine does not support Vulkan rendering.";
778 return nullptr;
779#endif // SHELL_ENABLE_VULKAN
780}
781
784 const FlutterRendererConfig* config,
785 void* user_data,
787 platform_dispatch_table,
788 std::unique_ptr<flutter::EmbedderExternalViewEmbedder>
789 external_view_embedder) {
790 if (config->type != kSoftware) {
791 return nullptr;
792 }
793
794 auto software_present_backing_store =
796 const void* allocation, size_t row_bytes, size_t height) -> bool {
797 return ptr(user_data, allocation, row_bytes, height);
798 };
799
801 software_dispatch_table = {
802 software_present_backing_store, // required
803 };
804
805 return fml::MakeCopyable(
806 [software_dispatch_table, platform_dispatch_table,
807 external_view_embedder =
808 std::move(external_view_embedder)](flutter::Shell& shell) mutable {
809 return std::make_unique<flutter::PlatformViewEmbedder>(
810 shell, // delegate
811 shell.GetTaskRunners(), // task runners
812 software_dispatch_table, // software dispatch table
813 platform_dispatch_table, // platform dispatch table
814 std::move(external_view_embedder) // external view embedder
815 );
816 });
817}
818
821 const FlutterRendererConfig* config,
822 void* user_data,
824 platform_dispatch_table,
825 std::unique_ptr<flutter::EmbedderExternalViewEmbedder>
826 external_view_embedder,
827 bool enable_impeller,
828 impeller::Flags impeller_flags) {
829 if (config == nullptr) {
830 return nullptr;
831 }
832
833 switch (config->type) {
834 case kOpenGL:
836 config, user_data, platform_dispatch_table,
837 std::move(external_view_embedder), enable_impeller, impeller_flags);
838 case kSoftware:
840 config, user_data, platform_dispatch_table,
841 std::move(external_view_embedder));
842 case kMetal:
844 config, user_data, platform_dispatch_table,
845 std::move(external_view_embedder), enable_impeller, impeller_flags);
846 case kVulkan:
848 config, user_data, platform_dispatch_table,
849 std::move(external_view_embedder), enable_impeller, impeller_flags);
850 default:
851 return nullptr;
852 }
853 return nullptr;
854}
855
856static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
857 GrDirectContext* context,
858 const FlutterBackingStoreConfig& config,
860#ifdef SHELL_ENABLE_GL
861 GrGLTextureInfo texture_info;
862 texture_info.fTarget = texture->target;
863 texture_info.fID = texture->name;
864 texture_info.fFormat = texture->format;
865
866 GrBackendTexture backend_texture =
867 GrBackendTextures::MakeGL(config.size.width, config.size.height,
868 skgpu::Mipmapped::kNo, texture_info);
869
870 SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
871
872 std::optional<SkColorType> color_type =
873 FlutterFormatToSkColorType(texture->format);
874 if (!color_type) {
875 return nullptr;
876 }
877
878 auto surface = SkSurfaces::WrapBackendTexture(
879 context, // context
880 backend_texture, // back-end texture
881 kBottomLeft_GrSurfaceOrigin, // surface origin
882 1, // sample count
883 color_type.value(), // color type
884 SkColorSpace::MakeSRGB(), // color space
885 &surface_properties, // surface properties
886 static_cast<SkSurfaces::TextureReleaseProc>(
887 texture->destruction_callback), // release proc
888 texture->user_data // release context
889 );
890
891 if (!surface) {
892 FML_LOG(ERROR) << "Could not wrap embedder supplied render texture.";
893 return nullptr;
894 }
895
896 return surface;
897#else
898 return nullptr;
899#endif
900}
901
902static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
903 GrDirectContext* context,
904 const FlutterBackingStoreConfig& config,
905 const FlutterOpenGLFramebuffer* framebuffer) {
906#ifdef SHELL_ENABLE_GL
907 GrGLFramebufferInfo framebuffer_info = {};
908 framebuffer_info.fFormat = framebuffer->target;
909 framebuffer_info.fFBOID = framebuffer->name;
910
911 auto backend_render_target =
912 GrBackendRenderTargets::MakeGL(config.size.width, // width
913 config.size.height, // height
914 1, // sample count
915 0, // stencil bits
916 framebuffer_info // framebuffer info
917 );
918
919 SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
920
921 std::optional<SkColorType> color_type =
922 FlutterFormatToSkColorType(framebuffer->target);
923 if (!color_type) {
924 return nullptr;
925 }
926
927 auto surface = SkSurfaces::WrapBackendRenderTarget(
928 context, // context
929 backend_render_target, // backend render target
930 kBottomLeft_GrSurfaceOrigin, // surface origin
931 color_type.value(), // color type
932 SkColorSpace::MakeSRGB(), // color space
933 &surface_properties, // surface properties
934 static_cast<SkSurfaces::RenderTargetReleaseProc>(
935 framebuffer->destruction_callback), // release proc
936 framebuffer->user_data // release context
937 );
938
939 if (!surface) {
940 FML_LOG(ERROR) << "Could not wrap embedder supplied frame-buffer.";
941 return nullptr;
942 }
943 return surface;
944#else
945 return nullptr;
946#endif
947}
948
949static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
950 GrDirectContext* context,
951 const FlutterBackingStoreConfig& config,
952 const FlutterOpenGLSurface* surface) {
953#ifdef SHELL_ENABLE_GL
954 GrGLFramebufferInfo framebuffer_info = {};
955 framebuffer_info.fFormat = SAFE_ACCESS(surface, format, GL_BGRA8_EXT);
956 framebuffer_info.fFBOID = 0;
957
958 auto backend_render_target =
959 GrBackendRenderTargets::MakeGL(config.size.width, // width
960 config.size.height, // height
961 1, // sample count
962 0, // stencil bits
963 framebuffer_info // framebuffer info
964 );
965
966 SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
967
968 std::optional<SkColorType> color_type =
969 FlutterFormatToSkColorType(surface->format);
970 if (!color_type) {
971 return nullptr;
972 }
973
974 auto sk_surface = SkSurfaces::WrapBackendRenderTarget(
975 context, // context
976 backend_render_target, // backend render target
977 kBottomLeft_GrSurfaceOrigin, // surface origin
978 color_type.value(), // color type
979 SkColorSpace::MakeSRGB(), // color space
980 &surface_properties, // surface properties
981 static_cast<SkSurfaces::RenderTargetReleaseProc>(
982 surface->destruction_callback), // release proc
983 surface->user_data // release context
984 );
985
986 if (!sk_surface) {
987 FML_LOG(ERROR) << "Could not wrap embedder supplied frame-buffer.";
988 return nullptr;
989 }
990 return sk_surface;
991#else
992 return nullptr;
993#endif
994}
995
996static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
997 GrDirectContext* context,
998 const FlutterBackingStoreConfig& config,
999 const FlutterSoftwareBackingStore* software) {
1000 const auto image_info =
1001 SkImageInfo::MakeN32Premul(config.size.width, config.size.height);
1002
1003 struct Captures {
1004 VoidCallback destruction_callback;
1005 void* user_data;
1006 };
1007 auto captures = std::make_unique<Captures>();
1008 captures->destruction_callback = software->destruction_callback;
1009 captures->user_data = software->user_data;
1010 auto release_proc = [](void* pixels, void* context) {
1011 auto captures = reinterpret_cast<Captures*>(context);
1012 if (captures->destruction_callback) {
1013 captures->destruction_callback(captures->user_data);
1014 }
1015 delete captures;
1016 };
1017
1018 auto surface =
1019 SkSurfaces::WrapPixels(image_info, // image info
1020 const_cast<void*>(software->allocation), // pixels
1021 software->row_bytes, // row bytes
1022 release_proc, // release proc
1023 captures.get() // get context
1024 );
1025
1026 if (!surface) {
1027 FML_LOG(ERROR)
1028 << "Could not wrap embedder supplied software render buffer.";
1029 if (software->destruction_callback) {
1030 software->destruction_callback(software->user_data);
1031 }
1032 return nullptr;
1033 }
1034 if (surface) {
1035 captures.release(); // Skia has assumed ownership of the struct.
1036 }
1037 return surface;
1038}
1039
1040static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
1041 GrDirectContext* context,
1042 const FlutterBackingStoreConfig& config,
1043 const FlutterSoftwareBackingStore2* software) {
1044 const auto color_info = getSkColorInfo(software->pixel_format);
1045 if (!color_info) {
1046 return nullptr;
1047 }
1048
1049 const auto image_info = SkImageInfo::Make(
1050 SkISize::Make(config.size.width, config.size.height), *color_info);
1051
1052 struct Captures {
1053 VoidCallback destruction_callback;
1054 void* user_data;
1055 };
1056 auto captures = std::make_unique<Captures>();
1057 captures->destruction_callback = software->destruction_callback;
1058 captures->user_data = software->user_data;
1059 auto release_proc = [](void* pixels, void* context) {
1060 auto captures = reinterpret_cast<Captures*>(context);
1061 if (captures->destruction_callback) {
1062 captures->destruction_callback(captures->user_data);
1063 }
1064 };
1065
1066 auto surface =
1067 SkSurfaces::WrapPixels(image_info, // image info
1068 const_cast<void*>(software->allocation), // pixels
1069 software->row_bytes, // row bytes
1070 release_proc, // release proc
1071 captures.release() // release context
1072 );
1073
1074 if (!surface) {
1075 FML_LOG(ERROR)
1076 << "Could not wrap embedder supplied software render buffer.";
1077 if (software->destruction_callback) {
1078 software->destruction_callback(software->user_data);
1079 }
1080 return nullptr;
1081 }
1082 return surface;
1083}
1084
1085static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
1086 GrDirectContext* context,
1087 const FlutterBackingStoreConfig& config,
1088 const FlutterMetalBackingStore* metal) {
1089#if defined(SHELL_ENABLE_METAL) && !SLIMPELLER
1090 GrMtlTextureInfo texture_info;
1091 if (!metal->texture.texture) {
1092 FML_LOG(ERROR) << "Embedder supplied null Metal texture.";
1093 return nullptr;
1094 }
1095 sk_cfp<FlutterMetalTextureHandle> mtl_texture;
1096 mtl_texture.retain(metal->texture.texture);
1097 texture_info.fTexture = mtl_texture;
1098 GrBackendTexture backend_texture =
1099 GrBackendTextures::MakeMtl(config.size.width, //
1100 config.size.height, //
1101 skgpu::Mipmapped::kNo, //
1102 texture_info //
1103 );
1104
1105 SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
1106
1107 auto surface = SkSurfaces::WrapBackendTexture(
1108 context, // context
1109 backend_texture, // back-end texture
1110 kTopLeft_GrSurfaceOrigin, // surface origin
1111 1, // sample count
1112 kBGRA_8888_SkColorType, // color type
1113 nullptr, // color space
1114 &surface_properties, // surface properties
1115 static_cast<SkSurfaces::TextureReleaseProc>(
1116 metal->texture.destruction_callback), // release proc
1117 metal->texture.user_data // release context
1118 );
1119
1120 if (!surface) {
1121 FML_LOG(ERROR) << "Could not wrap embedder supplied Metal render texture.";
1122 return nullptr;
1123 }
1124
1125 return surface;
1126#else
1127 return nullptr;
1128#endif
1129}
1130
1131#if defined(SHELL_ENABLE_GL) && defined(IMPELLER_SUPPORTS_RENDERING)
1132static std::optional<impeller::PixelFormat> FlutterFormatToImpellerPixelFormat(
1133 uint32_t format) {
1134 switch (format) {
1135 case GL_BGRA8_EXT:
1137 case GL_RGBA8:
1139 default:
1140 FML_LOG(ERROR) << "Cannot convert format " << format
1141 << " to impeller::PixelFormat.";
1142 return std::nullopt;
1143 }
1144}
1145
1146#endif // defined(SHELL_ENABLE_GL) && defined(IMPELLER_SUPPORTS_RENDERING)
1147
1148static std::unique_ptr<flutter::EmbedderRenderTarget>
1150 FlutterBackingStore backing_store,
1151 const fml::closure& on_release,
1152 const std::shared_ptr<impeller::AiksContext>& aiks_context,
1153 const FlutterBackingStoreConfig& config,
1154 const FlutterOpenGLFramebuffer* framebuffer) {
1155#if defined(SHELL_ENABLE_GL) && defined(IMPELLER_SUPPORTS_RENDERING)
1156 auto format = FlutterFormatToImpellerPixelFormat(framebuffer->target);
1157 if (!format.has_value()) {
1158 return nullptr;
1159 }
1160
1161 const auto& gl_context =
1162 impeller::ContextGLES::Cast(*aiks_context->GetContext());
1163 const bool implicit_msaa = aiks_context->GetContext()
1164 ->GetCapabilities()
1165 ->SupportsImplicitResolvingMSAA();
1166 const auto size = impeller::ISize(config.size.width, config.size.height);
1167
1168 impeller::TextureDescriptor color0_tex;
1169 if (implicit_msaa) {
1172 } else {
1175 }
1176 color0_tex.format = format.value();
1177 color0_tex.size = size;
1178 color0_tex.usage = static_cast<impeller::TextureUsageMask>(
1181
1184 gl_context.GetReactor(), color0_tex, framebuffer->name);
1187 if (implicit_msaa) {
1189 color0.resolve_texture = color0.texture;
1190 } else {
1192 }
1193
1194 impeller::TextureDescriptor depth_stencil_texture_desc;
1195 depth_stencil_texture_desc.format = impeller::PixelFormat::kD24UnormS8Uint;
1196 depth_stencil_texture_desc.size = size;
1197 depth_stencil_texture_desc.usage = static_cast<impeller::TextureUsageMask>(
1199 if (implicit_msaa) {
1200 depth_stencil_texture_desc.type =
1202 depth_stencil_texture_desc.sample_count = impeller::SampleCount::kCount4;
1203 } else {
1204 depth_stencil_texture_desc.type = impeller::TextureType::kTexture2D;
1205 depth_stencil_texture_desc.sample_count = impeller::SampleCount::kCount1;
1206 }
1207
1208 auto depth_stencil_tex = impeller::TextureGLES::CreatePlaceholder(
1209 gl_context.GetReactor(), depth_stencil_texture_desc);
1210
1212 depth0.clear_depth = 0;
1213 depth0.texture = depth_stencil_tex;
1216
1218 stencil0.clear_stencil = 0;
1219 stencil0.texture = depth_stencil_tex;
1222
1223 impeller::RenderTarget render_target_desc;
1224
1225 render_target_desc.SetColorAttachment(color0, 0u);
1226 render_target_desc.SetDepthAttachment(depth0);
1227 render_target_desc.SetStencilAttachment(stencil0);
1228
1229 fml::closure framebuffer_destruct =
1230 [callback = framebuffer->destruction_callback,
1231 user_data = framebuffer->user_data]() { callback(user_data); };
1232
1233 return std::make_unique<flutter::EmbedderRenderTargetImpeller>(
1234 backing_store, aiks_context,
1235 std::make_unique<impeller::RenderTarget>(std::move(render_target_desc)),
1236 on_release, framebuffer_destruct);
1237#else
1238 return nullptr;
1239#endif
1240}
1241
1242static std::unique_ptr<flutter::EmbedderRenderTarget>
1244 FlutterBackingStore backing_store,
1245 const fml::closure& on_release,
1246 const std::shared_ptr<impeller::AiksContext>& aiks_context,
1247 const FlutterBackingStoreConfig& config,
1248 const FlutterMetalBackingStore* metal) {
1249#if defined(SHELL_ENABLE_METAL) && defined(IMPELLER_SUPPORTS_RENDERING)
1250 if (!metal->texture.texture) {
1251 FML_LOG(ERROR) << "Embedder supplied null Metal texture.";
1252 return nullptr;
1253 }
1254
1255 const auto size = impeller::ISize(config.size.width, config.size.height);
1256
1257 impeller::TextureDescriptor resolve_tex_desc;
1258 resolve_tex_desc.size = size;
1261 resolve_tex_desc.usage = impeller::TextureUsage::kRenderTarget |
1263
1264 auto resolve_tex = impeller::WrapTextureMTL(
1265 resolve_tex_desc, metal->texture.texture,
1267 user_data = metal->texture.user_data]() { callback(user_data); });
1268 if (!resolve_tex) {
1269 FML_LOG(ERROR) << "Could not wrap embedder supplied Metal render texture.";
1270 return nullptr;
1271 }
1272
1273 aiks_context->GetContext()->UpdateOffscreenLayerPixelFormat(
1274 resolve_tex->GetTextureDescriptor().format);
1275
1276 resolve_tex->SetLabel("ImpellerBackingStoreResolve");
1277
1278 impeller::TextureDescriptor msaa_tex_desc;
1282 msaa_tex_desc.format = resolve_tex->GetTextureDescriptor().format;
1283 msaa_tex_desc.size = size;
1285
1286 auto msaa_tex =
1287 aiks_context->GetContext()->GetResourceAllocator()->CreateTexture(
1288 msaa_tex_desc);
1289 if (!msaa_tex) {
1290 FML_LOG(ERROR) << "Could not allocate MSAA color texture.";
1291 return nullptr;
1292 }
1293 msaa_tex->SetLabel("ImpellerBackingStoreColorMSAA");
1294
1296 color0.texture = msaa_tex;
1300 color0.resolve_texture = resolve_tex;
1301
1302 impeller::RenderTarget render_target_desc;
1303 render_target_desc.SetColorAttachment(color0, 0u);
1304
1305 return std::make_unique<flutter::EmbedderRenderTargetImpeller>(
1306 backing_store, aiks_context,
1307 std::make_unique<impeller::RenderTarget>(std::move(render_target_desc)),
1308 on_release, fml::closure());
1309#else
1310 return nullptr;
1311#endif
1312}
1313
1314static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
1315 GrDirectContext* context,
1316 const FlutterBackingStoreConfig& config,
1318#ifdef SHELL_ENABLE_VULKAN
1319 if (!vulkan->image) {
1320 FML_LOG(ERROR) << "Embedder supplied null Vulkan image.";
1321 return nullptr;
1322 }
1323 GrVkImageInfo image_info = {
1324 .fImage = reinterpret_cast<VkImage>(vulkan->image->image),
1325 .fImageTiling = VK_IMAGE_TILING_OPTIMAL,
1326 .fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED,
1327 .fFormat = static_cast<VkFormat>(vulkan->image->format),
1328 .fImageUsageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
1329 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1330 VK_IMAGE_USAGE_TRANSFER_DST_BIT |
1331 VK_IMAGE_USAGE_SAMPLED_BIT,
1332 .fSampleCount = 1,
1333 .fLevelCount = 1,
1334 };
1335 auto backend_texture = GrBackendTextures::MakeVk(
1336 config.size.width, config.size.height, image_info);
1337
1338 SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
1339
1340 auto surface = SkSurfaces::WrapBackendTexture(
1341 context, // context
1342 backend_texture, // back-end texture
1343 kTopLeft_GrSurfaceOrigin, // surface origin
1344 1, // sample count
1346 static_cast<VkFormat>(vulkan->image->format)), // color type
1347 SkColorSpace::MakeSRGB(), // color space
1348 &surface_properties, // surface properties
1349 static_cast<SkSurfaces::TextureReleaseProc>(
1350 vulkan->destruction_callback), // release proc
1351 vulkan->user_data // release context
1352 );
1353
1354 if (!surface) {
1355 FML_LOG(ERROR) << "Could not wrap embedder supplied Vulkan render texture.";
1356 return nullptr;
1357 }
1358
1359 return surface;
1360#else
1361 return nullptr;
1362#endif
1363}
1364
1365static std::unique_ptr<flutter::EmbedderRenderTarget>
1367 FlutterBackingStore backing_store,
1368 sk_sp<SkSurface> skia_surface,
1369 fml::closure on_release,
1372 on_clear_current) {
1373 if (!skia_surface) {
1374 return nullptr;
1375 }
1376 return std::make_unique<flutter::EmbedderRenderTargetSkia>(
1377 backing_store, std::move(skia_surface), std::move(on_release),
1378 std::move(on_make_current), std::move(on_clear_current));
1379}
1380
1381static std::unique_ptr<flutter::EmbedderRenderTarget>
1383 sk_sp<SkSurface> skia_surface,
1384 fml::closure on_release) {
1385 return MakeRenderTargetFromSkSurface(backing_store, std::move(skia_surface),
1386 std::move(on_release), nullptr, nullptr);
1387}
1388
1389static std::unique_ptr<flutter::EmbedderRenderTarget>
1391 const FlutterCompositor* compositor,
1392 const FlutterBackingStoreConfig& config,
1393 GrDirectContext* context,
1394 const std::shared_ptr<impeller::AiksContext>& aiks_context,
1395 bool enable_impeller) {
1396 FlutterBackingStore backing_store = {};
1397 backing_store.struct_size = sizeof(backing_store);
1398
1399 // Safe access checks on the compositor struct have been performed in
1400 // InferExternalViewEmbedderFromArgs and are not necessary here.
1401 auto c_create_callback = compositor->create_backing_store_callback;
1402 auto c_collect_callback = compositor->collect_backing_store_callback;
1403
1404 {
1405 TRACE_EVENT0("flutter", "FlutterCompositorCreateBackingStore");
1406 if (!c_create_callback(&config, &backing_store, compositor->user_data)) {
1407 FML_LOG(ERROR) << "Could not create the embedder backing store.";
1408 return nullptr;
1409 }
1410 }
1411
1412 if (backing_store.struct_size != sizeof(backing_store)) {
1413 FML_LOG(ERROR) << "Embedder modified the backing store struct size.";
1414 return nullptr;
1415 }
1416
1417 // In case we return early without creating an embedder render target, the
1418 // embedder has still given us ownership of its baton which we must return
1419 // back to it. If this method is successful, the closure is released when the
1420 // render target is eventually released.
1421 fml::ScopedCleanupClosure collect_callback(
1422 [c_collect_callback, backing_store, user_data = compositor->user_data]() {
1423 TRACE_EVENT0("flutter", "FlutterCompositorCollectBackingStore");
1424 c_collect_callback(&backing_store, user_data);
1425 });
1426
1427 // No safe access checks on the renderer are necessary since we allocated
1428 // the struct.
1429
1430 std::unique_ptr<flutter::EmbedderRenderTarget> render_target;
1431
1432 switch (backing_store.type) {
1434 switch (backing_store.open_gl.type) {
1436 auto skia_surface = MakeSkSurfaceFromBackingStore(
1437 context, config, &backing_store.open_gl.texture);
1438 render_target = MakeRenderTargetFromSkSurface(
1439 backing_store, std::move(skia_surface),
1440 collect_callback.Release());
1441 break;
1442 }
1444 if (enable_impeller) {
1446 backing_store, collect_callback.Release(), aiks_context, config,
1447 &backing_store.open_gl.framebuffer);
1448 break;
1449 } else {
1450 auto skia_surface = MakeSkSurfaceFromBackingStore(
1451 context, config, &backing_store.open_gl.framebuffer);
1452 render_target = MakeRenderTargetFromSkSurface(
1453 backing_store, std::move(skia_surface),
1454 collect_callback.Release());
1455 break;
1456 }
1457 }
1458
1460 auto on_make_current =
1462 context = backing_store.open_gl.surface.user_data]()
1464 bool invalidate_api_state = false;
1465 bool ok = callback(context, &invalidate_api_state);
1466 return {ok, invalidate_api_state};
1467 };
1468
1469 auto on_clear_current =
1471 context = backing_store.open_gl.surface.user_data]()
1473 bool invalidate_api_state = false;
1474 bool ok = callback(context, &invalidate_api_state);
1475 return {ok, invalidate_api_state};
1476 };
1477
1478 if (enable_impeller) {
1479 // TODO(https://github.com/flutter/flutter/issues/151670): Implement
1480 // GL Surface backing stores for Impeller.
1481 FML_LOG(ERROR) << "Unimplemented";
1482 break;
1483 } else {
1484 auto skia_surface = MakeSkSurfaceFromBackingStore(
1485 context, config, &backing_store.open_gl.surface);
1486
1487 render_target = MakeRenderTargetFromSkSurface(
1488 backing_store, std::move(skia_surface),
1489 collect_callback.Release(), on_make_current, on_clear_current);
1490 break;
1491 }
1492 }
1493 }
1494 break;
1495 }
1496
1498 auto skia_surface = MakeSkSurfaceFromBackingStore(
1499 context, config, &backing_store.software);
1500 render_target = MakeRenderTargetFromSkSurface(
1501 backing_store, std::move(skia_surface), collect_callback.Release());
1502 break;
1503 }
1505 auto skia_surface = MakeSkSurfaceFromBackingStore(
1506 context, config, &backing_store.software2);
1507 render_target = MakeRenderTargetFromSkSurface(
1508 backing_store, std::move(skia_surface), collect_callback.Release());
1509 break;
1510 }
1512 if (enable_impeller) {
1514 backing_store, collect_callback.Release(), aiks_context, config,
1515 &backing_store.metal);
1516 } else {
1517 auto skia_surface = MakeSkSurfaceFromBackingStore(context, config,
1518 &backing_store.metal);
1519 render_target = MakeRenderTargetFromSkSurface(
1520 backing_store, std::move(skia_surface), collect_callback.Release());
1521 }
1522 break;
1523 }
1525 if (enable_impeller) {
1526 FML_LOG(ERROR) << "Unimplemented";
1527 break;
1528 } else {
1529 auto skia_surface = MakeSkSurfaceFromBackingStore(
1530 context, config, &backing_store.vulkan);
1531 render_target = MakeRenderTargetFromSkSurface(
1532 backing_store, std::move(skia_surface), collect_callback.Release());
1533 break;
1534 }
1535 }
1536 };
1537
1538 if (!render_target) {
1539 FML_LOG(ERROR) << "Could not create a surface from an embedder provided "
1540 "render target.";
1541 }
1542 return render_target;
1543}
1544
1545/// Creates an EmbedderExternalViewEmbedder.
1546///
1547/// When a non-OK status is returned, engine startup should be halted.
1550 bool enable_impeller) {
1551 if (compositor == nullptr) {
1552 return std::unique_ptr<flutter::EmbedderExternalViewEmbedder>{nullptr};
1553 }
1554
1555 auto c_create_callback =
1556 SAFE_ACCESS(compositor, create_backing_store_callback, nullptr);
1557 auto c_collect_callback =
1558 SAFE_ACCESS(compositor, collect_backing_store_callback, nullptr);
1559 auto c_present_callback =
1560 SAFE_ACCESS(compositor, present_layers_callback, nullptr);
1561 auto c_present_view_callback =
1562 SAFE_ACCESS(compositor, present_view_callback, nullptr);
1563 bool avoid_backing_store_cache =
1564 SAFE_ACCESS(compositor, avoid_backing_store_cache, false);
1565
1566 // Make sure the required callbacks are present
1567 if (!c_create_callback || !c_collect_callback) {
1569 "Required compositor callbacks absent.");
1570 }
1571 // Either the present view or the present layers callback must be provided.
1572 if ((!c_present_view_callback && !c_present_callback) ||
1573 (c_present_view_callback && c_present_callback)) {
1575 "Either present_layers_callback or "
1576 "present_view_callback must be provided but not both.");
1577 }
1578
1579 FlutterCompositor captured_compositor = *compositor;
1580
1582 create_render_target_callback =
1583 [captured_compositor, enable_impeller](
1584 GrDirectContext* context,
1585 const std::shared_ptr<impeller::AiksContext>& aiks_context,
1586 const auto& config) {
1587 return CreateEmbedderRenderTarget(&captured_compositor, config,
1588 context, aiks_context,
1589 enable_impeller);
1590 };
1591
1593 if (c_present_callback) {
1594 present_callback = [c_present_callback, user_data = compositor->user_data](
1595 FlutterViewId view_id, const auto& layers) {
1596 TRACE_EVENT0("flutter", "FlutterCompositorPresentLayers");
1597 return c_present_callback(const_cast<const FlutterLayer**>(layers.data()),
1598 layers.size(), user_data);
1599 };
1600 } else {
1601 FML_DCHECK(c_present_view_callback != nullptr);
1602 present_callback = [c_present_view_callback,
1603 user_data = compositor->user_data](
1604 FlutterViewId view_id, const auto& layers) {
1605 TRACE_EVENT0("flutter", "FlutterCompositorPresentLayers");
1606
1607 FlutterPresentViewInfo info = {
1609 .view_id = view_id,
1610 .layers = const_cast<const FlutterLayer**>(layers.data()),
1612 .user_data = user_data,
1613 };
1614
1615 return c_present_view_callback(&info);
1616 };
1617 }
1618
1619 return std::make_unique<flutter::EmbedderExternalViewEmbedder>(
1620 avoid_backing_store_cache, create_render_target_callback,
1621 present_callback);
1622}
1623
1624// Translates embedder metrics to engine metrics, or returns a string on error.
1625static std::variant<flutter::ViewportMetrics, std::string>
1627 const FlutterWindowMetricsEvent* flutter_metrics) {
1628 if (flutter_metrics == nullptr) {
1629 return "Invalid metrics handle.";
1630 }
1631
1633
1634 metrics.physical_width = SAFE_ACCESS(flutter_metrics, width, 0.0);
1635 metrics.physical_height = SAFE_ACCESS(flutter_metrics, height, 0.0);
1636
1637 if (SAFE_ACCESS(flutter_metrics, has_constraints, false)) {
1639 flutter_metrics, min_width_constraint, metrics.physical_width);
1641 flutter_metrics, max_width_constraint, metrics.physical_width);
1643 flutter_metrics, min_height_constraint, metrics.physical_height);
1645 flutter_metrics, max_height_constraint, metrics.physical_height);
1646 } else {
1651 }
1652
1653 if (metrics.physical_width < metrics.physical_min_width_constraint ||
1657 return "Window metrics are invalid. Width and height must be within the "
1658 "specified constraints.";
1659 }
1660
1661 metrics.device_pixel_ratio = SAFE_ACCESS(flutter_metrics, pixel_ratio, 1.0);
1662 metrics.physical_view_inset_top =
1663 SAFE_ACCESS(flutter_metrics, physical_view_inset_top, 0.0);
1665 SAFE_ACCESS(flutter_metrics, physical_view_inset_right, 0.0);
1667 SAFE_ACCESS(flutter_metrics, physical_view_inset_bottom, 0.0);
1668 metrics.physical_view_inset_left =
1669 SAFE_ACCESS(flutter_metrics, physical_view_inset_left, 0.0);
1670 metrics.display_id = SAFE_ACCESS(flutter_metrics, display_id, 0);
1671
1672 if (metrics.device_pixel_ratio <= 0.0) {
1673 return "Device pixel ratio was invalid. It must be greater than zero.";
1674 }
1675
1676 if (metrics.physical_view_inset_top < 0 ||
1677 metrics.physical_view_inset_right < 0 ||
1678 metrics.physical_view_inset_bottom < 0 ||
1679 metrics.physical_view_inset_left < 0) {
1680 return "Physical view insets are invalid. They must be non-negative.";
1681 }
1682
1683 if (metrics.physical_view_inset_top > metrics.physical_height ||
1684 metrics.physical_view_inset_right > metrics.physical_width ||
1685 metrics.physical_view_inset_bottom > metrics.physical_height ||
1686 metrics.physical_view_inset_left > metrics.physical_width) {
1687 return "Physical view insets are invalid. They cannot be greater than "
1688 "physical height or width.";
1689 }
1690
1691 return metrics;
1692}
1693
1695 std::unique_ptr<flutter::PlatformMessage> message;
1696};
1697
1699 void operator()(Dart_LoadedElf* elf) {
1700 if (elf) {
1701 ::Dart_UnloadELF(elf);
1702 }
1703 }
1704};
1705
1706using UniqueLoadedElf = std::unique_ptr<Dart_LoadedElf, LoadedElfDeleter>;
1707
1710 const uint8_t* vm_snapshot_data = nullptr;
1711 const uint8_t* vm_snapshot_instrs = nullptr;
1712 const uint8_t* vm_isolate_data = nullptr;
1713 const uint8_t* vm_isolate_instrs = nullptr;
1714};
1715
1717 const FlutterEngineAOTDataSource* source,
1718 FlutterEngineAOTData* data_out) {
1721 "AOT data can only be created in AOT mode.");
1722 } else if (!source) {
1723 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Null source specified.");
1724 } else if (!data_out) {
1725 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Null data_out specified.");
1726 }
1727
1728 switch (source->type) {
1730 if (!source->elf_path || !fml::IsFile(source->elf_path)) {
1732 "Invalid ELF path specified.");
1733 }
1734
1735 auto aot_data = std::make_unique<_FlutterEngineAOTData>();
1736 const char* error = nullptr;
1737
1738#if OS_FUCHSIA
1739 // TODO(gw280): https://github.com/flutter/flutter/issues/50285
1740 // Dart doesn't implement Dart_LoadELF on Fuchsia
1741 Dart_LoadedElf* loaded_elf = nullptr;
1742#else
1743 Dart_LoadedElf* loaded_elf =
1744 Dart_LoadELF(source->elf_path, // file path
1745 0, // file offset
1746 &error, // error (out)
1747 &aot_data->vm_isolate_data, // vm isolate data (out)
1748 &aot_data->vm_isolate_instrs // vm isolate instr (out)
1749 );
1750 if (loaded_elf != nullptr) {
1751 aot_data->vm_snapshot_data = aot_data->vm_isolate_data;
1752 aot_data->vm_snapshot_instrs = aot_data->vm_isolate_instrs;
1753 }
1754#endif
1755
1756 if (loaded_elf == nullptr) {
1758 }
1759
1760 aot_data->loaded_elf.reset(loaded_elf);
1761
1762 *data_out = aot_data.release();
1763 return kSuccess;
1764 }
1765 }
1766
1767 return LOG_EMBEDDER_ERROR(
1769 "Invalid FlutterEngineAOTDataSourceType type specified.");
1770}
1771
1773 if (!data) {
1774 // Deleting a null object should be a no-op.
1775 return kSuccess;
1776 }
1777
1778 // Created in a unique pointer in `FlutterEngineCreateAOTData`.
1779 delete data;
1780 return kSuccess;
1781}
1782
1783// Constructs appropriate mapping callbacks if JIT snapshot locations have been
1784// explictly specified.
1786 flutter::Settings& settings) {
1787 auto make_mapping_callback = [](const char* path, bool executable) {
1788 return [path, executable]() {
1789 if (executable) {
1791 } else {
1793 }
1794 };
1795 };
1796
1797 // Users are allowed to specify only certain snapshots if they so desire.
1798 if (SAFE_ACCESS(args, vm_snapshot_data, nullptr) != nullptr) {
1799 settings.vm_snapshot_data = make_mapping_callback(
1800 reinterpret_cast<const char*>(args->vm_snapshot_data), false);
1801 }
1802
1803 if (SAFE_ACCESS(args, vm_snapshot_instructions, nullptr) != nullptr) {
1804 settings.vm_snapshot_instr = make_mapping_callback(
1805 reinterpret_cast<const char*>(args->vm_snapshot_instructions), true);
1806 }
1807
1808 if (SAFE_ACCESS(args, isolate_snapshot_data, nullptr) != nullptr) {
1809 settings.isolate_snapshot_data = make_mapping_callback(
1810 reinterpret_cast<const char*>(args->isolate_snapshot_data), false);
1811 }
1812
1813 if (SAFE_ACCESS(args, isolate_snapshot_instructions, nullptr) != nullptr) {
1814 settings.isolate_snapshot_instr = make_mapping_callback(
1815 reinterpret_cast<const char*>(args->isolate_snapshot_instructions),
1816 true);
1817 }
1818
1819#if !OS_FUCHSIA && (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG)
1820 settings.dart_library_sources_kernel = []() {
1821 return std::make_unique<fml::NonOwnedMapping>(kPlatformStrongDill,
1823 };
1824#endif // !OS_FUCHSIA && (FLUTTER_RUNTIME_MODE ==
1825 // FLUTTER_RUNTIME_MODE_DEBUG)
1826}
1827
1829 const FlutterProjectArgs* args,
1830 flutter::Settings& settings) { // NOLINT(google-runtime-references)
1831 // There are no ownership concerns here as all mappings are owned by the
1832 // embedder and not the engine.
1833 auto make_mapping_callback = [](const uint8_t* mapping, size_t size) {
1834 return [mapping, size]() {
1835 return std::make_unique<fml::NonOwnedMapping>(mapping, size);
1836 };
1837 };
1838
1839 if (SAFE_ACCESS(args, aot_data, nullptr) != nullptr) {
1840 settings.vm_snapshot_data =
1841 make_mapping_callback(args->aot_data->vm_snapshot_data, 0);
1842
1843 settings.vm_snapshot_instr =
1844 make_mapping_callback(args->aot_data->vm_snapshot_instrs, 0);
1845
1846 settings.isolate_snapshot_data =
1847 make_mapping_callback(args->aot_data->vm_isolate_data, 0);
1848
1849 settings.isolate_snapshot_instr =
1850 make_mapping_callback(args->aot_data->vm_isolate_instrs, 0);
1851 }
1852
1853 if (SAFE_ACCESS(args, vm_snapshot_data, nullptr) != nullptr) {
1854 settings.vm_snapshot_data = make_mapping_callback(
1855 args->vm_snapshot_data, SAFE_ACCESS(args, vm_snapshot_data_size, 0));
1856 }
1857
1858 if (SAFE_ACCESS(args, vm_snapshot_instructions, nullptr) != nullptr) {
1859 settings.vm_snapshot_instr = make_mapping_callback(
1860 args->vm_snapshot_instructions,
1861 SAFE_ACCESS(args, vm_snapshot_instructions_size, 0));
1862 }
1863
1864 if (SAFE_ACCESS(args, isolate_snapshot_data, nullptr) != nullptr) {
1865 settings.isolate_snapshot_data =
1866 make_mapping_callback(args->isolate_snapshot_data,
1867 SAFE_ACCESS(args, isolate_snapshot_data_size, 0));
1868 }
1869
1870 if (SAFE_ACCESS(args, isolate_snapshot_instructions, nullptr) != nullptr) {
1871 settings.isolate_snapshot_instr = make_mapping_callback(
1872 args->isolate_snapshot_instructions,
1873 SAFE_ACCESS(args, isolate_snapshot_instructions_size, 0));
1874 }
1875}
1876
1877// Create a callback to notify the embedder of semantic updates
1878// using the legacy embedder callbacks 'update_semantics_node_callback' and
1879// 'update_semantics_custom_action_callback'.
1882 FlutterUpdateSemanticsNodeCallback update_semantics_node_callback,
1884 update_semantics_custom_action_callback,
1885 void* user_data) {
1886 return [update_semantics_node_callback,
1887 update_semantics_custom_action_callback, user_data](
1888 int64_t view_id, const flutter::SemanticsNodeUpdates& nodes,
1890 flutter::EmbedderSemanticsUpdate update{nodes, actions};
1891 FlutterSemanticsUpdate* update_ptr = update.get();
1892
1893 // First, queue all node and custom action updates.
1894 if (update_semantics_node_callback != nullptr) {
1895 for (size_t i = 0; i < update_ptr->nodes_count; i++) {
1896 update_semantics_node_callback(&update_ptr->nodes[i], user_data);
1897 }
1898 }
1899
1900 if (update_semantics_custom_action_callback != nullptr) {
1901 for (size_t i = 0; i < update_ptr->custom_actions_count; i++) {
1902 update_semantics_custom_action_callback(&update_ptr->custom_actions[i],
1903 user_data);
1904 }
1905 }
1906
1907 // Second, mark node and action batches completed now that all
1908 // updates are queued.
1909 if (update_semantics_node_callback != nullptr) {
1910 const FlutterSemanticsNode batch_end_sentinel = {
1911 sizeof(FlutterSemanticsNode),
1913 };
1914 update_semantics_node_callback(&batch_end_sentinel, user_data);
1915 }
1916
1917 if (update_semantics_custom_action_callback != nullptr) {
1918 const FlutterSemanticsCustomAction batch_end_sentinel = {
1921 };
1922 update_semantics_custom_action_callback(&batch_end_sentinel, user_data);
1923 }
1924 };
1925}
1926
1927// Create a callback to notify the embedder of semantic updates
1928// using the deprecated embedder callback 'update_semantics_callback'.
1931 FlutterUpdateSemanticsCallback update_semantics_callback,
1932 void* user_data) {
1933 return [update_semantics_callback, user_data](
1934 int64_t view_id, const flutter::SemanticsNodeUpdates& nodes,
1936 flutter::EmbedderSemanticsUpdate update{nodes, actions};
1937
1938 update_semantics_callback(update.get(), user_data);
1939 };
1940}
1941
1942// Create a callback to notify the embedder of semantic updates
1943// using the new embedder callback 'update_semantics_callback2'.
1946 FlutterUpdateSemanticsCallback2 update_semantics_callback,
1947 void* user_data) {
1948 return [update_semantics_callback, user_data](
1949 int64_t view_id, const flutter::SemanticsNodeUpdates& nodes,
1951 flutter::EmbedderSemanticsUpdate2 update{view_id, nodes, actions};
1952
1953 update_semantics_callback(update.get(), user_data);
1954 };
1955}
1956
1957// Creates a callback that receives semantic updates from the engine
1958// and notifies the embedder's callback(s). Returns null if the embedder
1959// did not register any callbacks.
1962 void* user_data) {
1963 // There are three variants for the embedder API's semantic update callbacks.
1964 // Create a callback that maps to the embedder's desired semantic update API.
1965 //
1966 // Handle the case where the embedder registered the callback
1967 // 'updated_semantics_callback2'
1968 if (SAFE_ACCESS(args, update_semantics_callback2, nullptr) != nullptr) {
1970 args->update_semantics_callback2, user_data);
1971 }
1972
1973 // Handle the case where the embedder registered the deprecated callback
1974 // 'update_semantics_callback'.
1975 if (SAFE_ACCESS(args, update_semantics_callback, nullptr) != nullptr) {
1977 args->update_semantics_callback, user_data);
1978 }
1979
1980 // Handle the case where the embedder registered the deprecated callbacks
1981 // 'update_semantics_node_callback' and
1982 // 'update_semantics_custom_action_callback'.
1983 FlutterUpdateSemanticsNodeCallback update_semantics_node_callback = nullptr;
1984 if (SAFE_ACCESS(args, update_semantics_node_callback, nullptr) != nullptr) {
1985 update_semantics_node_callback = args->update_semantics_node_callback;
1986 }
1987
1989 update_semantics_custom_action_callback = nullptr;
1990 if (SAFE_ACCESS(args, update_semantics_custom_action_callback, nullptr) !=
1991 nullptr) {
1992 update_semantics_custom_action_callback =
1993 args->update_semantics_custom_action_callback;
1994 }
1995
1996 if (update_semantics_node_callback != nullptr ||
1997 update_semantics_custom_action_callback != nullptr) {
1999 update_semantics_node_callback, update_semantics_custom_action_callback,
2000 user_data);
2001 }
2002
2003 // Handle the case where the embedder registered no callbacks.
2004 return nullptr;
2005}
2006
2008 const FlutterRendererConfig* config,
2009 const FlutterProjectArgs* args,
2010 void* user_data,
2012 engine_out) {
2013 auto result =
2014 FlutterEngineInitialize(version, config, args, user_data, engine_out);
2015
2016 if (result != kSuccess) {
2017 return result;
2018 }
2019
2020 return FlutterEngineRunInitialized(*engine_out);
2021}
2022
2024 const FlutterRendererConfig* config,
2025 const FlutterProjectArgs* args,
2026 void* user_data,
2028 engine_out) {
2029 // Step 0: Figure out arguments for shell creation.
2030 if (version != FLUTTER_ENGINE_VERSION) {
2031 return LOG_EMBEDDER_ERROR(
2033 "Flutter embedder version mismatch. There has been a breaking change. "
2034 "Please consult the changelog and update the embedder.");
2035 }
2036
2037 if (engine_out == nullptr) {
2039 "The engine out parameter was missing.");
2040 }
2041
2042 if (args == nullptr) {
2044 "The Flutter project arguments were missing.");
2045 }
2046
2047 if (SAFE_ACCESS(args, assets_path, nullptr) == nullptr) {
2048 return LOG_EMBEDDER_ERROR(
2050 "The assets path in the Flutter project arguments was missing.");
2051 }
2052
2053 if (SAFE_ACCESS(args, main_path__unused__, nullptr) != nullptr) {
2054 FML_LOG(WARNING)
2055 << "FlutterProjectArgs.main_path is deprecated and should be set null.";
2056 }
2057
2058 if (SAFE_ACCESS(args, packages_path__unused__, nullptr) != nullptr) {
2059 FML_LOG(WARNING) << "FlutterProjectArgs.packages_path is deprecated and "
2060 "should be set null.";
2061 }
2062
2063 if (!IsRendererValid(config)) {
2065 "The renderer configuration was invalid.");
2066 }
2067
2068 std::string icu_data_path;
2069 if (SAFE_ACCESS(args, icu_data_path, nullptr) != nullptr) {
2070 icu_data_path = SAFE_ACCESS(args, icu_data_path, nullptr);
2071 }
2072
2073#if !SLIMPELLER
2074 if (SAFE_ACCESS(args, persistent_cache_path, nullptr) != nullptr) {
2075 std::string persistent_cache_path =
2076 SAFE_ACCESS(args, persistent_cache_path, nullptr);
2078 }
2079
2080 if (SAFE_ACCESS(args, is_persistent_cache_read_only, false)) {
2082 }
2083#endif // !SLIMPELLER
2084
2085 fml::CommandLine command_line;
2086 if (SAFE_ACCESS(args, command_line_argc, 0) != 0 &&
2087 SAFE_ACCESS(args, command_line_argv, nullptr) != nullptr) {
2088 command_line = fml::CommandLineFromArgcArgv(
2089 SAFE_ACCESS(args, command_line_argc, 0),
2090 SAFE_ACCESS(args, command_line_argv, nullptr));
2091 }
2092
2093 flutter::Settings settings = flutter::SettingsFromCommandLine(command_line);
2094
2095 if (SAFE_ACCESS(args, aot_data, nullptr)) {
2096 if (SAFE_ACCESS(args, vm_snapshot_data, nullptr) ||
2097 SAFE_ACCESS(args, vm_snapshot_instructions, nullptr) ||
2098 SAFE_ACCESS(args, isolate_snapshot_data, nullptr) ||
2099 SAFE_ACCESS(args, isolate_snapshot_instructions, nullptr)) {
2100 return LOG_EMBEDDER_ERROR(
2102 "Multiple AOT sources specified. Embedders should provide either "
2103 "*_snapshot_* buffers or aot_data, not both.");
2104 }
2105 }
2106
2109 } else {
2111 }
2112
2113 settings.icu_data_path = icu_data_path;
2114 settings.assets_path = args->assets_path;
2115 settings.leak_vm = !SAFE_ACCESS(args, shutdown_dart_vm_when_done, false);
2116 settings.old_gen_heap_size = SAFE_ACCESS(args, dart_old_gen_heap_size, -1);
2117 settings.enable_wide_gamut = SAFE_ACCESS(args, enable_wide_gamut, false);
2118
2120 // Verify the assets path contains Dart 2 kernel assets.
2121 const std::string kApplicationKernelSnapshotFileName = "kernel_blob.bin";
2122 std::string application_kernel_path = fml::paths::JoinPaths(
2124 if (!fml::IsFile(application_kernel_path)) {
2125 return LOG_EMBEDDER_ERROR(
2127 "Not running in AOT mode but could not resolve the kernel binary.");
2128 }
2130 }
2131
2132 if (SAFE_ACCESS(args, root_isolate_create_callback, nullptr) != nullptr) {
2134 SAFE_ACCESS(args, root_isolate_create_callback, nullptr);
2136 [callback, user_data](const auto& isolate) { callback(user_data); };
2137 }
2138
2139 // Wire up callback for engine and print logging.
2140 if (SAFE_ACCESS(args, log_message_callback, nullptr) != nullptr) {
2142 SAFE_ACCESS(args, log_message_callback, nullptr);
2144 const std::string& tag,
2145 const std::string& message) {
2146 callback(tag.c_str(), message.c_str(), user_data);
2147 };
2148 } else {
2149 settings.log_message_callback = [](const std::string& tag,
2150 const std::string& message) {
2151 // Fall back to logging to stdout if unspecified.
2152 if (tag.empty()) {
2153 std::cout << tag << ": ";
2154 }
2155 std::cout << message << std::endl;
2156 };
2157 }
2158
2159 if (SAFE_ACCESS(args, log_tag, nullptr) != nullptr) {
2160 settings.log_tag = SAFE_ACCESS(args, log_tag, nullptr);
2161 }
2162
2163 bool has_update_semantics_2_callback =
2164 SAFE_ACCESS(args, update_semantics_callback2, nullptr) != nullptr;
2165 bool has_update_semantics_callback =
2166 SAFE_ACCESS(args, update_semantics_callback, nullptr) != nullptr;
2167 bool has_legacy_update_semantics_callback =
2168 SAFE_ACCESS(args, update_semantics_node_callback, nullptr) != nullptr ||
2169 SAFE_ACCESS(args, update_semantics_custom_action_callback, nullptr) !=
2170 nullptr;
2171
2172 int semantic_callback_count = (has_update_semantics_2_callback ? 1 : 0) +
2173 (has_update_semantics_callback ? 1 : 0) +
2174 (has_legacy_update_semantics_callback ? 1 : 0);
2175
2176 if (semantic_callback_count > 1) {
2177 return LOG_EMBEDDER_ERROR(
2179 "Multiple semantics update callbacks provided. "
2180 "Embedders should provide either `update_semantics_callback2`, "
2181 "`update_semantics_callback`, or both "
2182 "`update_semantics_node_callback` and "
2183 "`update_semantics_custom_action_callback`.");
2184 }
2185
2187 update_semantics_callback =
2189
2191 platform_message_response_callback = nullptr;
2192 if (SAFE_ACCESS(args, platform_message_callback, nullptr) != nullptr) {
2193 platform_message_response_callback =
2194 [ptr = args->platform_message_callback,
2195 user_data](std::unique_ptr<flutter::PlatformMessage> message) {
2196 auto handle = new FlutterPlatformMessageResponseHandle();
2197 const FlutterPlatformMessage incoming_message = {
2198 sizeof(FlutterPlatformMessage), // struct_size
2199 message->channel().c_str(), // channel
2200 message->data().GetMapping(), // message
2201 message->data().GetSize(), // message_size
2202 handle, // response_handle
2203 };
2204 handle->message = std::move(message);
2205 return ptr(&incoming_message, user_data);
2206 };
2207 }
2208
2209 flutter::VsyncWaiterEmbedder::VsyncCallback vsync_callback = nullptr;
2210 if (SAFE_ACCESS(args, vsync_callback, nullptr) != nullptr) {
2211 vsync_callback = [ptr = args->vsync_callback, user_data](intptr_t baton) {
2212 return ptr(user_data, baton);
2213 };
2214 }
2215
2217 compute_platform_resolved_locale_callback = nullptr;
2218 if (SAFE_ACCESS(args, compute_platform_resolved_locale_callback, nullptr) !=
2219 nullptr) {
2220 compute_platform_resolved_locale_callback =
2221 [ptr = args->compute_platform_resolved_locale_callback](
2222 const std::vector<std::string>& supported_locales_data) {
2223 const size_t number_of_strings_per_locale = 3;
2224 size_t locale_count =
2225 supported_locales_data.size() / number_of_strings_per_locale;
2226 std::vector<FlutterLocale> supported_locales;
2227 std::vector<const FlutterLocale*> supported_locales_ptr;
2228 for (size_t i = 0; i < locale_count; ++i) {
2229 supported_locales.push_back(
2230 {.struct_size = sizeof(FlutterLocale),
2231 .language_code =
2232 supported_locales_data[i * number_of_strings_per_locale +
2233 0]
2234 .c_str(),
2235 .country_code =
2236 supported_locales_data[i * number_of_strings_per_locale +
2237 1]
2238 .c_str(),
2239 .script_code =
2240 supported_locales_data[i * number_of_strings_per_locale +
2241 2]
2242 .c_str(),
2243 .variant_code = nullptr});
2244 supported_locales_ptr.push_back(&supported_locales[i]);
2245 }
2246
2247 const FlutterLocale* result =
2248 ptr(supported_locales_ptr.data(), locale_count);
2249
2250 std::unique_ptr<std::vector<std::string>> out =
2251 std::make_unique<std::vector<std::string>>();
2252 if (result) {
2253 std::string language_code(SAFE_ACCESS(result, language_code, ""));
2254 if (language_code != "") {
2255 out->push_back(language_code);
2256 out->emplace_back(SAFE_ACCESS(result, country_code, ""));
2257 out->emplace_back(SAFE_ACCESS(result, script_code, ""));
2258 }
2259 }
2260 return out;
2261 };
2262 }
2263
2265 on_pre_engine_restart_callback = nullptr;
2266 if (SAFE_ACCESS(args, on_pre_engine_restart_callback, nullptr) != nullptr) {
2267 on_pre_engine_restart_callback = [ptr =
2268 args->on_pre_engine_restart_callback,
2269 user_data]() { return ptr(user_data); };
2270 }
2271
2273 nullptr;
2274 if (SAFE_ACCESS(args, channel_update_callback, nullptr) != nullptr) {
2275 channel_update_callback = [ptr = args->channel_update_callback, user_data](
2276 const std::string& name, bool listening) {
2277 FlutterChannelUpdate update{sizeof(FlutterChannelUpdate), name.c_str(),
2278 listening};
2279 ptr(&update, user_data);
2280 };
2281 }
2282
2284 view_focus_change_request_callback = nullptr;
2285 if (SAFE_ACCESS(args, view_focus_change_request_callback, nullptr) !=
2286 nullptr) {
2287 view_focus_change_request_callback =
2288 [ptr = args->view_focus_change_request_callback,
2290 FlutterViewFocusChangeRequest embedder_request{
2292 .view_id = request.view_id(),
2293 .state = static_cast<FlutterViewFocusState>(request.state()),
2294 .direction =
2295 static_cast<FlutterViewFocusDirection>(request.direction()),
2296 };
2297 ptr(&embedder_request, user_data);
2298 };
2299 }
2300
2301 auto external_view_embedder_result = InferExternalViewEmbedderFromArgs(
2302 SAFE_ACCESS(args, compositor, nullptr), settings.enable_impeller);
2303 if (!external_view_embedder_result.ok()) {
2304 FML_LOG(ERROR) << external_view_embedder_result.status().message();
2306 "Compositor arguments were invalid.");
2307 }
2308
2310 {
2311 update_semantics_callback, //
2312 platform_message_response_callback, //
2313 vsync_callback, //
2314 compute_platform_resolved_locale_callback, //
2315 on_pre_engine_restart_callback, //
2316 channel_update_callback, //
2317 view_focus_change_request_callback, //
2318 };
2319
2320 impeller::Flags impeller_flags;
2321 impeller_flags.use_sdfs = settings.impeller_use_sdfs;
2322
2323 auto on_create_platform_view = InferPlatformViewCreationCallback(
2324 config, user_data, platform_dispatch_table,
2325 std::move(external_view_embedder_result.value()),
2326 settings.enable_impeller, impeller_flags);
2327
2328 if (!on_create_platform_view) {
2329 return LOG_EMBEDDER_ERROR(
2331 "Could not infer platform view creation callback.");
2332 }
2333
2335 [](flutter::Shell& shell) {
2336 return std::make_unique<flutter::Rasterizer>(shell);
2337 };
2338
2339 using ExternalTextureResolver = flutter::EmbedderExternalTextureResolver;
2340 std::unique_ptr<ExternalTextureResolver> external_texture_resolver;
2341 external_texture_resolver = std::make_unique<ExternalTextureResolver>();
2342
2343#ifdef SHELL_ENABLE_GL
2345 external_texture_callback;
2346 if (config->type == kOpenGL) {
2347 const FlutterOpenGLRendererConfig* open_gl_config = &config->open_gl;
2348 if (SAFE_ACCESS(open_gl_config, gl_external_texture_frame_callback,
2349 nullptr) != nullptr) {
2350 external_texture_callback =
2351 [ptr = open_gl_config->gl_external_texture_frame_callback, user_data](
2352 int64_t texture_identifier, size_t width,
2353 size_t height) -> std::unique_ptr<FlutterOpenGLTexture> {
2354 std::unique_ptr<FlutterOpenGLTexture> texture =
2355 std::make_unique<FlutterOpenGLTexture>();
2356 if (!ptr(user_data, texture_identifier, width, height, texture.get())) {
2357 return nullptr;
2358 }
2359 return texture;
2360 };
2361 external_texture_resolver =
2362 std::make_unique<ExternalTextureResolver>(external_texture_callback);
2363 }
2364 }
2365#endif
2366#ifdef SHELL_ENABLE_METAL
2368 external_texture_metal_callback;
2369 if (config->type == kMetal) {
2370 const FlutterMetalRendererConfig* metal_config = &config->metal;
2371 if (SAFE_ACCESS(metal_config, external_texture_frame_callback, nullptr)) {
2372 external_texture_metal_callback =
2373 [ptr = metal_config->external_texture_frame_callback, user_data](
2374 int64_t texture_identifier, size_t width,
2375 size_t height) -> std::unique_ptr<FlutterMetalExternalTexture> {
2376 std::unique_ptr<FlutterMetalExternalTexture> texture =
2377 std::make_unique<FlutterMetalExternalTexture>();
2378 texture->struct_size = sizeof(FlutterMetalExternalTexture);
2379 if (!ptr(user_data, texture_identifier, width, height, texture.get())) {
2380 return nullptr;
2381 }
2382 return texture;
2383 };
2384 external_texture_resolver = std::make_unique<ExternalTextureResolver>(
2385 external_texture_metal_callback);
2386 }
2387 }
2388#endif
2389 auto custom_task_runners = SAFE_ACCESS(args, custom_task_runners, nullptr);
2390 auto thread_config_callback = [&custom_task_runners](
2391 const fml::Thread::ThreadConfig& config) {
2393 if (!custom_task_runners || !custom_task_runners->thread_priority_setter) {
2394 return;
2395 }
2397 switch (config.priority) {
2400 break;
2403 break;
2406 break;
2409 break;
2410 }
2411 custom_task_runners->thread_priority_setter(priority);
2412 };
2413 auto thread_host =
2415 custom_task_runners, thread_config_callback);
2416
2417 if (!thread_host || !thread_host->IsValid()) {
2419 "Could not set up or infer thread configuration "
2420 "to run the Flutter engine on.");
2421 }
2422
2423 auto task_runners = thread_host->GetTaskRunners();
2424
2425 if (!task_runners.IsValid()) {
2427 "Task runner configuration was invalid.");
2428 }
2429
2430 // Embedder supplied UI task runner runner does not have a message loop.
2431 bool has_ui_thread_message_loop =
2432 task_runners.GetUITaskRunner()->GetTaskQueueId().is_valid();
2433 // Message loop observers are used to flush the microtask queue.
2434 // If there is no message loop the queue is flushed from
2435 // EmbedderEngine::RunTask.
2436 settings.task_observer_add = [has_ui_thread_message_loop](
2437 intptr_t key, const fml::closure& callback) {
2438 if (has_ui_thread_message_loop) {
2440 }
2442 };
2443 settings.task_observer_remove = [has_ui_thread_message_loop](
2444 fml::TaskQueueId queue_id, intptr_t key) {
2445 if (has_ui_thread_message_loop) {
2447 }
2448 };
2449
2450 auto run_configuration =
2452
2453 if (SAFE_ACCESS(args, custom_dart_entrypoint, nullptr) != nullptr) {
2454 auto dart_entrypoint = std::string{args->custom_dart_entrypoint};
2455 if (!dart_entrypoint.empty()) {
2456 run_configuration.SetEntrypoint(std::move(dart_entrypoint));
2457 }
2458 }
2459
2460 if (SAFE_ACCESS(args, dart_entrypoint_argc, 0) > 0) {
2461 if (SAFE_ACCESS(args, dart_entrypoint_argv, nullptr) == nullptr) {
2463 "Could not determine Dart entrypoint arguments "
2464 "as dart_entrypoint_argc "
2465 "was set, but dart_entrypoint_argv was null.");
2466 }
2467 std::vector<std::string> arguments(args->dart_entrypoint_argc);
2468 for (int i = 0; i < args->dart_entrypoint_argc; ++i) {
2469 arguments[i] = std::string{args->dart_entrypoint_argv[i]};
2470 }
2471 run_configuration.SetEntrypointArgs(std::move(arguments));
2472 }
2473
2474 if (SAFE_ACCESS(args, engine_id, 0) != 0) {
2475 run_configuration.SetEngineId(args->engine_id);
2476 }
2477
2478 if (!run_configuration.IsValid()) {
2479 return LOG_EMBEDDER_ERROR(
2481 "Could not infer the Flutter project to run from given arguments.");
2482 }
2483
2484 // Create the engine but don't launch the shell or run the root isolate.
2485 auto embedder_engine = std::make_unique<flutter::EmbedderEngine>(
2486 std::move(thread_host), //
2487 std::move(task_runners), //
2488 std::move(settings), //
2489 std::move(run_configuration), //
2490 on_create_platform_view, //
2491 on_create_rasterizer, //
2492 std::move(external_texture_resolver) //
2493 );
2494
2495 // Release the ownership of the embedder engine to the caller.
2496 *engine_out = reinterpret_cast<FLUTTER_API_SYMBOL(FlutterEngine)>(
2497 embedder_engine.release());
2498 return kSuccess;
2499}
2500
2503 if (!engine) {
2504 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2505 }
2506
2507 auto embedder_engine = reinterpret_cast<flutter::EmbedderEngine*>(engine);
2508
2509 // The engine must not already be running. Initialize may only be called
2510 // once on an engine instance.
2511 if (embedder_engine->IsValid()) {
2512 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2513 }
2514
2515 // Step 1: Launch the shell.
2516 if (!embedder_engine->LaunchShell()) {
2518 "Could not launch the engine using supplied "
2519 "initialization arguments.");
2520 }
2521
2522 // Step 2: Tell the platform view to initialize itself.
2523 if (!embedder_engine->NotifyCreated()) {
2525 "Could not create platform view components.");
2526 }
2527
2528 // Step 3: Launch the root isolate.
2529 if (!embedder_engine->RunRootIsolate()) {
2530 return LOG_EMBEDDER_ERROR(
2532 "Could not run the root isolate of the Flutter application using the "
2533 "project arguments specified.");
2534 }
2535
2536 return kSuccess;
2537}
2538
2541 engine,
2542 const FlutterAddViewInfo* info) {
2543 if (!engine) {
2544 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2545 }
2546 if (!info || !info->view_metrics || !info->add_view_callback) {
2548 "Add view info handle was invalid.");
2549 }
2550
2553 return LOG_EMBEDDER_ERROR(
2555 "Add view info was invalid. The implicit view cannot be added.");
2556 }
2558 view_id) {
2561 "Add view info was invalid. The info and "
2562 "window metric view IDs must match.");
2563 }
2564 }
2565
2566 // TODO(loicsharma): Return an error if the engine was initialized with
2567 // callbacks that are incompatible with multiple views.
2568 // https://github.com/flutter/flutter/issues/144806
2569
2570 std::variant<flutter::ViewportMetrics, std::string> metrics_or_error =
2572
2573 if (const std::string* error = std::get_if<std::string>(&metrics_or_error)) {
2574 return LOG_EMBEDDER_ERROR(kInvalidArguments, error->c_str());
2575 }
2576
2577 auto metrics = std::get<flutter::ViewportMetrics>(metrics_or_error);
2578
2579 // The engine must be running to add a view.
2580 auto embedder_engine = reinterpret_cast<flutter::EmbedderEngine*>(engine);
2581 if (!embedder_engine->IsValid()) {
2582 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2583 }
2584
2586 [c_callback = info->add_view_callback,
2587 user_data = info->user_data](bool added) {
2588 FlutterAddViewResult result = {};
2589 result.struct_size = sizeof(FlutterAddViewResult);
2590 result.added = added;
2591 result.user_data = user_data;
2592 c_callback(&result);
2593 };
2594
2595 embedder_engine->GetShell().GetPlatformView()->AddView(view_id, metrics,
2596 callback);
2597 return kSuccess;
2598}
2599
2602 engine,
2603 const FlutterRemoveViewInfo* info) {
2604 if (!engine) {
2605 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2606 }
2607 if (!info || !info->remove_view_callback) {
2609 "Remove view info handle was invalid.");
2610 }
2611
2612 if (info->view_id == kFlutterImplicitViewId) {
2613 return LOG_EMBEDDER_ERROR(
2615 "Remove view info was invalid. The implicit view cannot be removed.");
2616 }
2617
2618 // TODO(loicsharma): Return an error if the engine was initialized with
2619 // callbacks that are incompatible with multiple views.
2620 // https://github.com/flutter/flutter/issues/144806
2621
2622 // The engine must be running to remove a view.
2623 auto embedder_engine = reinterpret_cast<flutter::EmbedderEngine*>(engine);
2624 if (!embedder_engine->IsValid()) {
2625 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2626 }
2627
2629 [c_callback = info->remove_view_callback,
2630 user_data = info->user_data](bool removed) {
2631 FlutterRemoveViewResult result = {};
2632 result.struct_size = sizeof(FlutterRemoveViewResult);
2633 result.removed = removed;
2634 result.user_data = user_data;
2635 c_callback(&result);
2636 };
2637
2638 embedder_engine->GetShell().GetPlatformView()->RemoveView(info->view_id,
2639 callback);
2640 return kSuccess;
2641}
2642
2645 const FlutterViewFocusEvent* event) {
2646 if (!engine) {
2647 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2648 }
2649 if (!event) {
2651 "View focus event must not be null.");
2652 }
2653 // The engine must be running to focus a view.
2654 auto embedder_engine = reinterpret_cast<flutter::EmbedderEngine*>(engine);
2655 if (!embedder_engine->IsValid()) {
2656 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2657 }
2658
2659 if (!STRUCT_HAS_MEMBER(event, direction)) {
2661 "The event struct has invalid size.");
2662 }
2663
2664 flutter::ViewFocusEvent flutter_event(
2665 event->view_id, //
2666 static_cast<flutter::ViewFocusState>(event->state),
2667 static_cast<flutter::ViewFocusDirection>(event->direction));
2668
2669 embedder_engine->GetShell().GetPlatformView()->SendViewFocusEvent(
2670 flutter_event);
2671
2672 return kSuccess;
2673}
2674
2677 engine) {
2678 if (engine == nullptr) {
2679 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2680 }
2681
2682 auto embedder_engine = reinterpret_cast<flutter::EmbedderEngine*>(engine);
2683 embedder_engine->NotifyDestroyed();
2684 embedder_engine->CollectShell();
2685 embedder_engine->CollectThreadHost();
2686 return kSuccess;
2687}
2688
2690 engine) {
2691 auto result = FlutterEngineDeinitialize(engine);
2692 if (result != kSuccess) {
2693 return result;
2694 }
2695 auto embedder_engine = reinterpret_cast<flutter::EmbedderEngine*>(engine);
2696 delete embedder_engine;
2697 return kSuccess;
2698}
2699
2702 const FlutterWindowMetricsEvent* flutter_metrics) {
2703 if (engine == nullptr || flutter_metrics == nullptr) {
2704 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2705 }
2707 SAFE_ACCESS(flutter_metrics, view_id, kFlutterImplicitViewId);
2708
2709 std::variant<flutter::ViewportMetrics, std::string> metrics_or_error =
2710 MakeViewportMetricsFromWindowMetrics(flutter_metrics);
2711 if (const std::string* error = std::get_if<std::string>(&metrics_or_error)) {
2712 return LOG_EMBEDDER_ERROR(kInvalidArguments, error->c_str());
2713 }
2714
2715 auto metrics = std::get<flutter::ViewportMetrics>(metrics_or_error);
2716
2717 return reinterpret_cast<flutter::EmbedderEngine*>(engine)->SetViewportMetrics(
2718 view_id, metrics)
2719 ? kSuccess
2721 "Viewport metrics were invalid.");
2722}
2723
2724// Returns the flutter::PointerData::Change for the given FlutterPointerPhase.
2751
2752// Returns the flutter::PointerData::DeviceKind for the given
2753// FlutterPointerDeviceKind.
2770
2771// Returns the flutter::PointerData::SignalKind for the given
2772// FlutterPointerSignaKind.
2787
2788// Returns the buttons to synthesize for a PointerData from a
2789// FlutterPointerEvent with no type or buttons set.
2792 switch (change) {
2795 // These kinds of change must have a non-zero `buttons`, otherwise
2796 // gesture recognizers will ignore these events.
2806 return 0;
2807 }
2808 return 0;
2809}
2810
2813 const FlutterPointerEvent* pointers,
2814 size_t events_count) {
2815 if (engine == nullptr) {
2816 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2817 }
2818
2819 if (pointers == nullptr || events_count == 0) {
2820 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid pointer events.");
2821 }
2822
2823 auto packet = std::make_unique<flutter::PointerDataPacket>(events_count);
2824
2825 const FlutterPointerEvent* current = pointers;
2826
2827 for (size_t i = 0; i < events_count; ++i) {
2828 flutter::PointerData pointer_data;
2829 pointer_data.Clear();
2830 // this is currely in use only on android embedding.
2831 pointer_data.embedder_id = 0;
2832 pointer_data.time_stamp = SAFE_ACCESS(current, timestamp, 0);
2833 pointer_data.change = ToPointerDataChange(
2834 SAFE_ACCESS(current, phase, FlutterPointerPhase::kCancel));
2835 pointer_data.physical_x = SAFE_ACCESS(current, x, 0.0);
2836 pointer_data.physical_y = SAFE_ACCESS(current, y, 0.0);
2837 // Delta will be generated in pointer_data_packet_converter.cc.
2838 pointer_data.physical_delta_x = 0.0;
2839 pointer_data.physical_delta_y = 0.0;
2840 pointer_data.device = SAFE_ACCESS(current, device, 0);
2841 // Pointer identifier will be generated in
2842 // pointer_data_packet_converter.cc.
2843 pointer_data.pointer_identifier = 0;
2844 pointer_data.signal_kind = ToPointerDataSignalKind(
2845 SAFE_ACCESS(current, signal_kind, kFlutterPointerSignalKindNone));
2846 pointer_data.scroll_delta_x = SAFE_ACCESS(current, scroll_delta_x, 0.0);
2847 pointer_data.scroll_delta_y = SAFE_ACCESS(current, scroll_delta_y, 0.0);
2848 FlutterPointerDeviceKind device_kind =
2849 SAFE_ACCESS(current, device_kind, kFlutterPointerDeviceKindMouse);
2850 // For backwards compatibility with embedders written before the device
2851 // kind and buttons were exposed, if the device kind is not set treat it
2852 // as a mouse, with a synthesized primary button state based on the phase.
2853 if (device_kind == 0) {
2855 pointer_data.buttons =
2857
2858 } else {
2859 pointer_data.kind = ToPointerDataKind(device_kind);
2860 if (pointer_data.kind == flutter::PointerData::DeviceKind::kTouch) {
2861 // For touch events, set the button internally rather than requiring
2862 // it at the API level, since it's a confusing construction to expose.
2863 if (pointer_data.change == flutter::PointerData::Change::kDown ||
2866 }
2867 } else {
2868 // Buttons use the same mask values, so pass them through directly.
2869 pointer_data.buttons = SAFE_ACCESS(current, buttons, 0);
2870 }
2871 }
2872 pointer_data.pan_x = SAFE_ACCESS(current, pan_x, 0.0);
2873 pointer_data.pan_y = SAFE_ACCESS(current, pan_y, 0.0);
2874 // Delta will be generated in pointer_data_packet_converter.cc.
2875 pointer_data.pan_delta_x = 0.0;
2876 pointer_data.pan_delta_y = 0.0;
2877 pointer_data.scale = SAFE_ACCESS(current, scale, 0.0);
2878 pointer_data.rotation = SAFE_ACCESS(current, rotation, 0.0);
2879 pointer_data.pressure = SAFE_ACCESS(current, pressure, 0.0);
2880 pointer_data.pressure_min = SAFE_ACCESS(current, pressure_min, 0.0);
2881 pointer_data.pressure_max = SAFE_ACCESS(current, pressure_max, 0.0);
2882 pointer_data.view_id =
2884 packet->SetPointerData(i, pointer_data);
2885 current = reinterpret_cast<const FlutterPointerEvent*>(
2886 reinterpret_cast<const uint8_t*>(current) + current->struct_size);
2887 }
2888
2889 return reinterpret_cast<flutter::EmbedderEngine*>(engine)
2890 ->DispatchPointerDataPacket(std::move(packet))
2891 ? kSuccess
2893 "Could not dispatch pointer events to the "
2894 "running Flutter application.");
2895}
2896
2898 FlutterKeyEventType event_kind) {
2899 switch (event_kind) {
2906 }
2908}
2909
2926
2927// Send a platform message to the framework.
2928//
2929// The `data_callback` will be invoked with `user_data`, and must not be empty.
2932 const char* channel,
2933 const uint8_t* data,
2934 size_t size,
2935 FlutterDataCallback data_callback,
2936 void* user_data) {
2937 FlutterEngineResult result;
2938
2939 FlutterPlatformMessageResponseHandle* response_handle;
2941 engine, data_callback, user_data, &response_handle);
2942 if (result != kSuccess) {
2943 return result;
2944 }
2945
2947 sizeof(FlutterPlatformMessage), // struct_size
2948 channel, // channel
2949 data, // message
2950 size, // message_size
2951 response_handle, // response_handle
2952 };
2953
2955 // Whether `SendPlatformMessage` succeeds or not, the response handle must be
2956 // released.
2957 FlutterEngineResult release_result =
2959 if (result != kSuccess) {
2960 return result;
2961 }
2962
2963 return release_result;
2964}
2965
2967 engine,
2968 const FlutterKeyEvent* event,
2970 void* user_data) {
2971 if (engine == nullptr) {
2972 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
2973 }
2974
2975 if (event == nullptr) {
2976 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid key event.");
2977 }
2978
2979 const char* character = SAFE_ACCESS(event, character, nullptr);
2980
2981 flutter::KeyData key_data;
2982 key_data.Clear();
2983 key_data.timestamp = static_cast<uint64_t>(SAFE_ACCESS(event, timestamp, 0));
2984 key_data.type = MapKeyEventType(
2986 key_data.physical = SAFE_ACCESS(event, physical, 0);
2987 key_data.logical = SAFE_ACCESS(event, logical, 0);
2988 key_data.synthesized = SAFE_ACCESS(event, synthesized, false);
2990 event, device_type,
2992
2993 auto packet = std::make_unique<flutter::KeyDataPacket>(key_data, character);
2994
2995 struct MessageData {
2997 void* user_data;
2998 };
2999
3000 MessageData* message_data =
3001 new MessageData{.callback = callback, .user_data = user_data};
3002
3003 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
3005 engine, kFlutterKeyDataChannel, packet->data().data(),
3006 packet->data().size(),
3007 [](const uint8_t* data, size_t size, void* user_data) {
3008 auto message_data = std::unique_ptr<MessageData>(
3009 reinterpret_cast<MessageData*>(user_data));
3010 if (message_data->callback == nullptr) {
3011 return;
3012 }
3013 bool handled = false;
3014 if (size == 1) {
3015 handled = *data != 0;
3016 }
3017 message_data->callback(handled, message_data->user_data);
3018 },
3019 message_data);
3020}
3021
3024 const FlutterPlatformMessage* flutter_message) {
3025 if (engine == nullptr) {
3026 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3027 }
3028
3029 if (flutter_message == nullptr) {
3030 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid message argument.");
3031 }
3032
3033 if (SAFE_ACCESS(flutter_message, channel, nullptr) == nullptr) {
3034 return LOG_EMBEDDER_ERROR(
3035 kInvalidArguments, "Message argument did not specify a valid channel.");
3036 }
3037
3038 size_t message_size = SAFE_ACCESS(flutter_message, message_size, 0);
3039 const uint8_t* message_data = SAFE_ACCESS(flutter_message, message, nullptr);
3040
3041 if (message_size != 0 && message_data == nullptr) {
3042 return LOG_EMBEDDER_ERROR(
3044 "Message size was non-zero but the message data was nullptr.");
3045 }
3046
3047 const FlutterPlatformMessageResponseHandle* response_handle =
3048 SAFE_ACCESS(flutter_message, response_handle, nullptr);
3049
3051 if (response_handle && response_handle->message) {
3052 response = response_handle->message->response();
3053 }
3054
3055 std::unique_ptr<flutter::PlatformMessage> message;
3056 if (message_size == 0) {
3057 message = std::make_unique<flutter::PlatformMessage>(
3058 flutter_message->channel, response);
3059 } else {
3060 message = std::make_unique<flutter::PlatformMessage>(
3061 flutter_message->channel,
3062 fml::MallocMapping::Copy(message_data, message_size), response);
3063 }
3064
3065 return reinterpret_cast<flutter::EmbedderEngine*>(engine)
3066 ->SendPlatformMessage(std::move(message))
3067 ? kSuccess
3069 "Could not send a message to the running "
3070 "Flutter application.");
3071}
3072
3075 FlutterDataCallback data_callback,
3076 void* user_data,
3077 FlutterPlatformMessageResponseHandle** response_out) {
3078 if (engine == nullptr) {
3079 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
3080 }
3081
3082 if (data_callback == nullptr || response_out == nullptr) {
3083 return LOG_EMBEDDER_ERROR(
3084 kInvalidArguments, "Data callback or the response handle was invalid.");
3085 }
3086
3088 [user_data, data_callback](const uint8_t* data, size_t size) {
3089 data_callback(data, size, user_data);
3090 };
3091
3092 auto platform_task_runner = reinterpret_cast<flutter::EmbedderEngine*>(engine)
3093 ->GetTaskRunners()
3094 .GetPlatformTaskRunner();
3095
3096 auto handle = new FlutterPlatformMessageResponseHandle();
3097
3098 handle->message = std::make_unique<flutter::PlatformMessage>(
3099 "", // The channel is empty and unused as the response handle is going
3100 // to referenced directly in the |FlutterEngineSendPlatformMessage|
3101 // with the container message discarded.
3102 fml::MakeRefCounted<flutter::EmbedderPlatformMessageResponse>(
3103 std::move(platform_task_runner), response_callback));
3104 *response_out = handle;
3105 return kSuccess;
3106}
3107
3111 if (engine == nullptr) {
3112 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3113 }
3114
3115 if (response == nullptr) {
3116 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid response handle.");
3117 }
3118 delete response;
3119 return kSuccess;
3120}
3121
3122// Note: This can execute on any thread.
3126 const uint8_t* data,
3127 size_t data_length) {
3128 if (data_length != 0 && data == nullptr) {
3129 return LOG_EMBEDDER_ERROR(
3131 "Data size was non zero but the pointer to the data was null.");
3132 }
3133
3134 auto response = handle->message->response();
3135
3136 if (response) {
3137 if (data_length == 0) {
3138 response->CompleteEmpty();
3139 } else {
3140 response->Complete(std::make_unique<fml::DataMapping>(
3141 std::vector<uint8_t>({data, data + data_length})));
3142 }
3143 }
3144
3145 delete handle;
3146
3147 return kSuccess;
3148}
3149
3154
3157 int64_t texture_identifier) {
3158 if (engine == nullptr) {
3159 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
3160 }
3161
3162 if (texture_identifier == 0) {
3164 "Texture identifier was invalid.");
3165 }
3166 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->RegisterTexture(
3167 texture_identifier)) {
3169 "Could not register the specified texture.");
3170 }
3171 return kSuccess;
3172}
3173
3176 int64_t texture_identifier) {
3177 if (engine == nullptr) {
3178 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
3179 }
3180
3181 if (texture_identifier == 0) {
3183 "Texture identifier was invalid.");
3184 }
3185
3186 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->UnregisterTexture(
3187 texture_identifier)) {
3189 "Could not un-register the specified texture.");
3190 }
3191
3192 return kSuccess;
3193}
3194
3197 int64_t texture_identifier) {
3198 if (engine == nullptr) {
3199 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3200 }
3201 if (texture_identifier == 0) {
3202 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid texture identifier.");
3203 }
3204 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)
3205 ->MarkTextureFrameAvailable(texture_identifier)) {
3206 return LOG_EMBEDDER_ERROR(
3208 "Could not mark the texture frame as being available.");
3209 }
3210 return kSuccess;
3211}
3212
3215 bool enabled) {
3216 if (engine == nullptr) {
3217 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3218 }
3219 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->SetSemanticsEnabled(
3220 enabled)) {
3222 "Could not update semantics state.");
3223 }
3224 return kSuccess;
3225}
3226
3230 if (engine == nullptr) {
3231 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3232 }
3233 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)
3234 ->SetAccessibilityFeatures(flags)) {
3236 "Could not update accessibility features.");
3237 }
3238 return kSuccess;
3239}
3240
3243 uint64_t node_id,
3245 const uint8_t* data,
3246 size_t data_length) {
3250 .node_id = node_id,
3251 .action = action,
3252 .data = data,
3253 .data_length = data_length};
3255}
3256
3259 const FlutterSendSemanticsActionInfo* info) {
3260 if (engine == nullptr) {
3261 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3262 }
3263 auto engine_action = static_cast<flutter::SemanticsAction>(info->action);
3264 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)
3266 info->view_id, info->node_id, engine_action,
3267 fml::MallocMapping::Copy(info->data, info->data_length))) {
3269 "Could not dispatch semantics action.");
3270 }
3271 return kSuccess;
3272}
3273
3275 engine,
3276 intptr_t baton,
3277 uint64_t frame_start_time_nanos,
3278 uint64_t frame_target_time_nanos) {
3279 if (engine == nullptr) {
3280 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3281 }
3282
3283 TRACE_EVENT0("flutter", "FlutterEngineOnVsync");
3284
3285 auto start_time = fml::TimePoint::FromEpochDelta(
3286 fml::TimeDelta::FromNanoseconds(frame_start_time_nanos));
3287
3288 auto target_time = fml::TimePoint::FromEpochDelta(
3289 fml::TimeDelta::FromNanoseconds(frame_target_time_nanos));
3290
3291 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->OnVsyncEvent(
3292 baton, start_time, target_time)) {
3293 return LOG_EMBEDDER_ERROR(
3295 "Could not notify the running engine instance of a Vsync event.");
3296 }
3297
3298 return kSuccess;
3299}
3300
3303 if (engine == nullptr) {
3304 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3305 }
3306
3307 TRACE_EVENT0("flutter", "FlutterEngineReloadSystemFonts");
3308
3309 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)
3310 ->ReloadSystemFonts()) {
3312 "Could not reload system fonts.");
3313 }
3314
3315 return kSuccess;
3316}
3317
3319 fml::tracing::TraceEvent0("flutter", name, /*flow_id_count=*/0,
3320 /*flow_ids=*/nullptr);
3321}
3322
3326
3328 fml::tracing::TraceEventInstant0("flutter", name, /*flow_id_count=*/0,
3329 /*flow_ids=*/nullptr);
3330}
3331
3335 void* baton) {
3336 if (engine == nullptr) {
3337 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3338 }
3339
3340 if (callback == nullptr) {
3342 "Render thread callback was null.");
3343 }
3344
3345 auto task = [callback, baton]() { callback(baton); };
3346
3347 return reinterpret_cast<flutter::EmbedderEngine*>(engine)
3348 ->PostRenderThreadTask(task)
3349 ? kSuccess
3351 "Could not post the render thread task.");
3352}
3353
3357
3359 engine,
3360 const FlutterTask* task) {
3361 if (engine == nullptr) {
3362 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3363 }
3364
3366 reinterpret_cast<intptr_t>(task->runner))) {
3367 // This task came too late, the embedder has already been destroyed.
3368 // This is not an error, just ignore the task.
3369 return kSuccess;
3370 }
3371
3372 return reinterpret_cast<flutter::EmbedderEngine*>(engine)->RunTask(task)
3373 ? kSuccess
3375 "Could not run the specified task.");
3376}
3377
3379 engine,
3380 const rapidjson::Document& document,
3381 const std::string& channel_name) {
3382 if (channel_name.empty()) {
3383 return false;
3384 }
3385
3386 rapidjson::StringBuffer buffer;
3387 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
3388
3389 if (!document.Accept(writer)) {
3390 return false;
3391 }
3392
3393 const char* message = buffer.GetString();
3394
3395 if (message == nullptr || buffer.GetSize() == 0) {
3396 return false;
3397 }
3398
3399 auto platform_message = std::make_unique<flutter::PlatformMessage>(
3400 channel_name.c_str(), // channel
3402 buffer.GetSize()), // message
3403 nullptr // response
3404 );
3405
3406 return reinterpret_cast<flutter::EmbedderEngine*>(engine)
3407 ->SendPlatformMessage(std::move(platform_message));
3408}
3409
3411 engine,
3412 const FlutterLocale** locales,
3413 size_t locales_count) {
3414 if (engine == nullptr) {
3415 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3416 }
3417
3418 if (locales_count == 0) {
3419 return kSuccess;
3420 }
3421
3422 if (locales == nullptr) {
3423 return LOG_EMBEDDER_ERROR(kInvalidArguments, "No locales were specified.");
3424 }
3425
3426 rapidjson::Document document;
3427 auto& allocator = document.GetAllocator();
3428
3429 document.SetObject();
3430 document.AddMember("method", "setLocale", allocator);
3431
3432 rapidjson::Value args(rapidjson::kArrayType);
3433 args.Reserve(locales_count * 4, allocator);
3434 for (size_t i = 0; i < locales_count; ++i) {
3435 const FlutterLocale* locale = locales[i];
3436 const char* language_code_str = SAFE_ACCESS(locale, language_code, nullptr);
3437 if (language_code_str == nullptr || ::strlen(language_code_str) == 0) {
3438 return LOG_EMBEDDER_ERROR(
3440 "Language code is required but not present in FlutterLocale.");
3441 }
3442
3443 const char* country_code_str = SAFE_ACCESS(locale, country_code, "");
3444 const char* script_code_str = SAFE_ACCESS(locale, script_code, "");
3445 const char* variant_code_str = SAFE_ACCESS(locale, variant_code, "");
3446
3447 rapidjson::Value language_code, country_code, script_code, variant_code;
3448
3449 language_code.SetString(language_code_str, allocator);
3450 country_code.SetString(country_code_str ? country_code_str : "", allocator);
3451 script_code.SetString(script_code_str ? script_code_str : "", allocator);
3452 variant_code.SetString(variant_code_str ? variant_code_str : "", allocator);
3453
3454 // Required.
3455 args.PushBack(language_code, allocator);
3456 args.PushBack(country_code, allocator);
3457 args.PushBack(script_code, allocator);
3458 args.PushBack(variant_code, allocator);
3459 }
3460 document.AddMember("args", args, allocator);
3461
3462 return DispatchJSONPlatformMessage(engine, document, "flutter/localization")
3463 ? kSuccess
3465 "Could not send message to update locale of "
3466 "a running Flutter application.");
3467}
3468
3472
3476 const FlutterEngineDartObject* object) {
3477 if (engine == nullptr) {
3478 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3479 }
3480
3481 if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->IsValid()) {
3482 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine not running.");
3483 }
3484
3485 if (port == ILLEGAL_PORT) {
3487 "Attempted to post to an illegal port.");
3488 }
3489
3490 if (object == nullptr) {
3492 "Invalid Dart object to post.");
3493 }
3494
3495 Dart_CObject dart_object = {};
3496 fml::ScopedCleanupClosure typed_data_finalizer;
3497
3498 switch (object->type) {
3500 dart_object.type = Dart_CObject_kNull;
3501 break;
3503 dart_object.type = Dart_CObject_kBool;
3504 dart_object.value.as_bool = object->bool_value;
3505 break;
3507 dart_object.type = Dart_CObject_kInt32;
3508 dart_object.value.as_int32 = object->int32_value;
3509 break;
3511 dart_object.type = Dart_CObject_kInt64;
3512 dart_object.value.as_int64 = object->int64_value;
3513 break;
3515 dart_object.type = Dart_CObject_kDouble;
3516 dart_object.value.as_double = object->double_value;
3517 break;
3519 if (object->string_value == nullptr) {
3521 "kFlutterEngineDartObjectTypeString must be "
3522 "a null terminated string but was null.");
3523 }
3524 dart_object.type = Dart_CObject_kString;
3525 dart_object.value.as_string = const_cast<char*>(object->string_value);
3526 break;
3528 auto* buffer = SAFE_ACCESS(object->buffer_value, buffer, nullptr);
3529 if (buffer == nullptr) {
3531 "kFlutterEngineDartObjectTypeBuffer must "
3532 "specify a buffer but found nullptr.");
3533 }
3534 auto buffer_size = SAFE_ACCESS(object->buffer_value, buffer_size, 0);
3535 auto callback =
3536 SAFE_ACCESS(object->buffer_value, buffer_collect_callback, nullptr);
3537 auto user_data = SAFE_ACCESS(object->buffer_value, user_data, nullptr);
3538
3539 // The user has provided a callback, let them manage the lifecycle of
3540 // the underlying data. If not, copy it out from the provided buffer.
3541
3542 if (callback == nullptr) {
3543 dart_object.type = Dart_CObject_kTypedData;
3544 dart_object.value.as_typed_data.type = Dart_TypedData_kUint8;
3545 dart_object.value.as_typed_data.length = buffer_size;
3546 dart_object.value.as_typed_data.values = buffer;
3547 } else {
3548 struct ExternalTypedDataPeer {
3549 void* user_data = nullptr;
3550 VoidCallback trampoline = nullptr;
3551 };
3552 auto peer = new ExternalTypedDataPeer();
3553 peer->user_data = user_data;
3554 peer->trampoline = callback;
3555 // This finalizer is set so that in case of failure of the
3556 // Dart_PostCObject below, we collect the peer. The embedder is still
3557 // responsible for collecting the buffer in case of non-kSuccess
3558 // returns from this method. This finalizer must be released in case
3559 // of kSuccess returns from this method.
3560 typed_data_finalizer.SetClosure([peer]() {
3561 // This is the tiny object we use as the peer to the Dart call so
3562 // that we can attach the a trampoline to the embedder supplied
3563 // callback. In case of error, we need to collect this object lest
3564 // we introduce a tiny leak.
3565 delete peer;
3566 });
3567 dart_object.type = Dart_CObject_kExternalTypedData;
3568 dart_object.value.as_external_typed_data.type = Dart_TypedData_kUint8;
3569 dart_object.value.as_external_typed_data.length = buffer_size;
3570 dart_object.value.as_external_typed_data.data = buffer;
3571 dart_object.value.as_external_typed_data.peer = peer;
3572 dart_object.value.as_external_typed_data.callback =
3573 +[](void* unused_isolate_callback_data, void* peer) {
3574 auto typed_peer = reinterpret_cast<ExternalTypedDataPeer*>(peer);
3575 typed_peer->trampoline(typed_peer->user_data);
3576 delete typed_peer;
3577 };
3578 }
3579 } break;
3580 default:
3581 return LOG_EMBEDDER_ERROR(
3583 "Invalid FlutterEngineDartObjectType type specified.");
3584 }
3585
3586 if (!Dart_PostCObject(port, &dart_object)) {
3588 "Could not post the object to the Dart VM.");
3589 }
3590
3591 // On a successful call, the VM takes ownership of and is responsible for
3592 // invoking the finalizer.
3593 typed_data_finalizer.Release();
3594 return kSuccess;
3595}
3596
3598 FLUTTER_API_SYMBOL(FlutterEngine) raw_engine) {
3599 auto engine = reinterpret_cast<flutter::EmbedderEngine*>(raw_engine);
3600 if (engine == nullptr || !engine->IsValid()) {
3601 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine was invalid.");
3602 }
3603
3604 engine->GetShell().NotifyLowMemoryWarning();
3605
3606 rapidjson::Document document;
3607 auto& allocator = document.GetAllocator();
3608
3609 document.SetObject();
3610 document.AddMember("type", "memoryPressure", allocator);
3611
3612 return DispatchJSONPlatformMessage(raw_engine, document, "flutter/system")
3613 ? kSuccess
3616 "Could not dispatch the low memory notification message.");
3617}
3618
3622 void* user_data) {
3623 if (engine == nullptr) {
3624 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3625 }
3626
3627 if (callback == nullptr) {
3629 "Invalid native thread callback.");
3630 }
3631
3632 return reinterpret_cast<flutter::EmbedderEngine*>(engine)
3633 ->PostTaskOnEngineManagedNativeThreads(
3636 })
3637 ? kSuccess
3639 "Internal error while attempting to post "
3640 "tasks to all threads.");
3641}
3642
3643namespace {
3644static bool ValidDisplayConfiguration(const FlutterEngineDisplay* displays,
3645 size_t display_count) {
3646 std::set<FlutterEngineDisplayId> display_ids;
3647 for (size_t i = 0; i < display_count; i++) {
3648 if (displays[i].single_display && display_count != 1) {
3649 return false;
3650 }
3651 display_ids.insert(displays[i].display_id);
3652 }
3653
3654 return display_ids.size() == display_count;
3655}
3656} // namespace
3657
3660 const FlutterEngineDisplaysUpdateType update_type,
3661 const FlutterEngineDisplay* embedder_displays,
3662 size_t display_count) {
3663 if (raw_engine == nullptr) {
3664 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3665 }
3666
3667 if (!ValidDisplayConfiguration(embedder_displays, display_count)) {
3668 return LOG_EMBEDDER_ERROR(
3670 "Invalid FlutterEngineDisplay configuration specified.");
3671 }
3672
3673 auto engine = reinterpret_cast<flutter::EmbedderEngine*>(raw_engine);
3674
3675 switch (update_type) {
3677 std::vector<std::unique_ptr<flutter::Display>> displays;
3678 const auto* display = embedder_displays;
3679 for (size_t i = 0; i < display_count; i++) {
3680 displays.push_back(std::make_unique<flutter::Display>(
3681 SAFE_ACCESS(display, display_id, i), //
3682 SAFE_ACCESS(display, refresh_rate, 0), //
3683 SAFE_ACCESS(display, width, 0), //
3684 SAFE_ACCESS(display, height, 0), //
3685 SAFE_ACCESS(display, device_pixel_ratio, 1)));
3686 display = reinterpret_cast<const FlutterEngineDisplay*>(
3687 reinterpret_cast<const uint8_t*>(display) + display->struct_size);
3688 }
3689 engine->GetShell().OnDisplayUpdates(std::move(displays));
3690 return kSuccess;
3691 }
3692 default:
3693 return LOG_EMBEDDER_ERROR(
3695 "Invalid FlutterEngineDisplaysUpdateType type specified.");
3696 }
3697}
3698
3700 engine) {
3701 if (engine == nullptr) {
3702 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3703 }
3704
3705 return reinterpret_cast<flutter::EmbedderEngine*>(engine)->ScheduleFrame()
3706 ? kSuccess
3708 "Could not schedule frame.");
3709}
3710
3714 void* user_data) {
3715 if (engine == nullptr) {
3716 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
3717 }
3718
3719 if (callback == nullptr) {
3721 "Next frame callback was null.");
3722 }
3723
3724 flutter::EmbedderEngine* embedder_engine =
3725 reinterpret_cast<flutter::EmbedderEngine*>(engine);
3726
3727 fml::WeakPtr<flutter::PlatformView> weak_platform_view =
3728 embedder_engine->GetShell().GetPlatformView();
3729
3730 if (!weak_platform_view) {
3732 "Platform view unavailable.");
3733 }
3734
3735 weak_platform_view->SetNextFrameCallback(
3737
3738 return kSuccess;
3739}
3740
3742 FlutterEngineProcTable* table) {
3743 if (!table) {
3744 return LOG_EMBEDDER_ERROR(kInvalidArguments, "Null table specified.");
3745 }
3746#define SET_PROC(member, function) \
3747 if (STRUCT_HAS_MEMBER(table, member)) { \
3748 table->member = &function; \
3749 }
3750
3751 SET_PROC(CreateAOTData, FlutterEngineCreateAOTData);
3752 SET_PROC(CollectAOTData, FlutterEngineCollectAOTData);
3755 SET_PROC(Initialize, FlutterEngineInitialize);
3756 SET_PROC(Deinitialize, FlutterEngineDeinitialize);
3757 SET_PROC(RunInitialized, FlutterEngineRunInitialized);
3758 SET_PROC(SendWindowMetricsEvent, FlutterEngineSendWindowMetricsEvent);
3759 SET_PROC(SendPointerEvent, FlutterEngineSendPointerEvent);
3760 SET_PROC(SendKeyEvent, FlutterEngineSendKeyEvent);
3761 SET_PROC(SendPlatformMessage, FlutterEngineSendPlatformMessage);
3762 SET_PROC(PlatformMessageCreateResponseHandle,
3764 SET_PROC(PlatformMessageReleaseResponseHandle,
3766 SET_PROC(SendPlatformMessageResponse,
3768 SET_PROC(RegisterExternalTexture, FlutterEngineRegisterExternalTexture);
3769 SET_PROC(UnregisterExternalTexture, FlutterEngineUnregisterExternalTexture);
3770 SET_PROC(MarkExternalTextureFrameAvailable,
3772 SET_PROC(UpdateSemanticsEnabled, FlutterEngineUpdateSemanticsEnabled);
3773 SET_PROC(UpdateAccessibilityFeatures,
3775 SET_PROC(DispatchSemanticsAction, FlutterEngineDispatchSemanticsAction);
3776 SET_PROC(SendSemanticsAction, FlutterEngineSendSemanticsAction);
3778 SET_PROC(ReloadSystemFonts, FlutterEngineReloadSystemFonts);
3779 SET_PROC(TraceEventDurationBegin, FlutterEngineTraceEventDurationBegin);
3780 SET_PROC(TraceEventDurationEnd, FlutterEngineTraceEventDurationEnd);
3781 SET_PROC(TraceEventInstant, FlutterEngineTraceEventInstant);
3782 SET_PROC(PostRenderThreadTask, FlutterEnginePostRenderThreadTask);
3785 SET_PROC(UpdateLocales, FlutterEngineUpdateLocales);
3786 SET_PROC(RunsAOTCompiledDartCode, FlutterEngineRunsAOTCompiledDartCode);
3787 SET_PROC(PostDartObject, FlutterEnginePostDartObject);
3788 SET_PROC(NotifyLowMemoryWarning, FlutterEngineNotifyLowMemoryWarning);
3789 SET_PROC(PostCallbackOnAllNativeThreads,
3791 SET_PROC(NotifyDisplayUpdate, FlutterEngineNotifyDisplayUpdate);
3792 SET_PROC(ScheduleFrame, FlutterEngineScheduleFrame);
3793 SET_PROC(SetNextFrameCallback, FlutterEngineSetNextFrameCallback);
3795 SET_PROC(RemoveView, FlutterEngineRemoveView);
3796 SET_PROC(SendViewFocusEvent, FlutterEngineSendViewFocusEvent);
3797#undef SET_PROC
3798
3799 return kSuccess;
3800}
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:923
const TaskRunners & GetTaskRunners() const override
If callers wish to interact directly with any shell subcomponents, they must (on the platform thread)...
Definition shell.cc:927
std::shared_ptr< fml::BasicTaskRunner > GetShutdownSafeIOTaskRunner()
The IO thread can be used for background tasks, including tasks that perform graphics operations usin...
Definition shell.cc:956
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:946
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:55
fml::closure Release()
Definition closure.h:61
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:3327
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:2930
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:3195
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:3358
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:3274
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:2007
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:3155
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:3410
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:2643
FlutterEngineResult FlutterEngineGetProcAddresses(FlutterEngineProcTable *table)
Gets the table of engine function pointers.
Definition embedder.cc:3741
static bool DispatchJSONPlatformMessage(FLUTTER_API_SYMBOL(FlutterEngine) engine, const rapidjson::Document &document, const std::string &channel_name)
Definition embedder.cc:3378
FlutterEngineResult FlutterEngineScheduleFrame(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Schedule a new frame to redraw the content.
Definition embedder.cc:3699
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:3318
FlutterEngineResult FlutterEngineSendWindowMetricsEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterWindowMetricsEvent *flutter_metrics)
Definition embedder.cc:2700
flutter::PointerData::SignalKind ToPointerDataSignalKind(FlutterPointerSignalKind kind)
Definition embedder.cc:2773
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:3354
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:3711
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:3150
#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:820
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:3332
static flutter::KeyEventDeviceType MapKeyEventDeviceType(FlutterKeyEventDeviceType event_kind)
Definition embedder.cc:2910
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:1149
std::unique_ptr< Dart_LoadedElf, LoadedElfDeleter > UniqueLoadedElf
Definition embedder.cc:1706
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:521
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:3241
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:3473
flutter::PointerData::DeviceKind ToPointerDataKind(FlutterPointerDeviceKind device_kind)
Definition embedder.cc:2754
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:2676
static sk_sp< SkSurface > MakeSkSurfaceFromBackingStore(GrDirectContext *context, const FlutterBackingStoreConfig &config, const FlutterOpenGLTexture *texture)
Definition embedder.cc:856
flutter::PointerData::Change ToPointerDataChange(FlutterPointerPhase phase)
Definition embedder.cc:2725
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:3619
FLUTTER_EXPORT FlutterEngineResult FlutterEngineAddView(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterAddViewInfo *info)
Adds a view.
Definition embedder.cc:2540
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:1366
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:2023
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:1390
flutter::PlatformViewEmbedder::UpdateSemanticsCallback CreateEmbedderSemanticsUpdateCallbackV3(FlutterUpdateSemanticsCallback2 update_semantics_callback, void *user_data)
Definition embedder.cc:1945
FlutterEngineResult FlutterEngineUpdateAccessibilityFeatures(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterAccessibilityFeature flags)
Sets additional accessibility features.
Definition embedder.cc:3227
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:2689
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:3073
FlutterEngineResult FlutterEngineCollectAOTData(FlutterEngineAOTData data)
Collects the AOT data.
Definition embedder.cc:1772
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:3658
FlutterEngineResult FlutterEngineSendPlatformMessage(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessage *flutter_message)
Definition embedder.cc:3022
bool FlutterEngineRunsAOTCompiledDartCode(void)
Returns if the Flutter engine instance will run AOT compiled Dart code. This call has no threading re...
Definition embedder.cc:3469
FlutterEngineResult FlutterEngineReloadSystemFonts(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Reloads the system fonts in engine.
Definition embedder.cc:3301
static flutter::KeyEventType MapKeyEventType(FlutterKeyEventType event_kind)
Definition embedder.cc:2897
flutter::PlatformViewEmbedder::UpdateSemanticsCallback CreateEmbedderSemanticsUpdateCallback(const FlutterProjectArgs *args, void *user_data)
Definition embedder.cc:1961
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:783
static fml::StatusOr< std::unique_ptr< flutter::EmbedderExternalViewEmbedder > > InferExternalViewEmbedderFromArgs(const FlutterCompositor *compositor, bool enable_impeller)
Definition embedder.cc:1549
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:1881
FlutterEngineResult FlutterEngineSendPointerEvent(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPointerEvent *pointers, size_t events_count)
Definition embedder.cc:2811
FlutterEngineResult FlutterEngineRunInitialized(FLUTTER_API_SYMBOL(FlutterEngine) engine)
Runs an initialized engine instance. An engine can be initialized via FlutterEngineInitialize....
Definition embedder.cc:2501
static bool IsSoftwareRendererConfigValid(const FlutterRendererConfig *config)
Definition embedder.cc:178
void PopulateJITSnapshotMappingCallbacks(const FlutterProjectArgs *args, flutter::Settings &settings)
Definition embedder.cc:1785
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:619
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:3257
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:3597
FlutterEngineResult FlutterEngineUnregisterExternalTexture(FLUTTER_API_SYMBOL(FlutterEngine) engine, int64_t texture_identifier)
Unregister a previous texture registration.
Definition embedder.cc:3174
FlutterEngineResult FlutterEngineUpdateSemanticsEnabled(FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled)
Enable or disable accessibility semantics.
Definition embedder.cc:3213
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:2966
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:3323
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:3123
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:2601
int64_t PointerDataButtonsForLegacyEvent(flutter::PointerData::Change change)
Definition embedder.cc:2790
void PopulateAOTSnapshotMappingCallbacks(const FlutterProjectArgs *args, flutter::Settings &settings)
Definition embedder.cc:1828
FlutterEngineResult FlutterPlatformMessageReleaseResponseHandle(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterPlatformMessageResponseHandle *response)
Collects the handle created using FlutterPlatformMessageCreateResponseHandle.
Definition embedder.cc:3108
flutter::PlatformViewEmbedder::UpdateSemanticsCallback CreateEmbedderSemanticsUpdateCallbackV2(FlutterUpdateSemanticsCallback update_semantics_callback, void *user_data)
Definition embedder.cc:1930
static std::variant< flutter::ViewportMetrics, std::string > MakeViewportMetricsFromWindowMetrics(const FlutterWindowMetricsEvent *flutter_metrics)
Definition embedder.cc:1626
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:1716
#define FLUTTER_API_SYMBOL(symbol)
Definition embedder.h:67
FlutterKeyEventDeviceType
Definition embedder.h:1407
@ kFlutterKeyEventDeviceTypeKeyboard
Definition embedder.h:1408
@ kFlutterKeyEventDeviceTypeDirectionalPad
Definition embedder.h:1409
@ kFlutterKeyEventDeviceTypeHdmi
Definition embedder.h:1412
@ kFlutterKeyEventDeviceTypeJoystick
Definition embedder.h:1411
@ kFlutterKeyEventDeviceTypeGamepad
Definition embedder.h:1410
void(* FlutterUpdateSemanticsCustomActionCallback)(const FlutterSemanticsCustomAction *, void *)
Definition embedder.h:1871
void(* FlutterUpdateSemanticsCallback)(const FlutterSemanticsUpdate *, void *)
Definition embedder.h:1875
FlutterViewFocusState
Represents the focus state of a given [FlutterView].
Definition embedder.h:1219
@ kFlutterEngineAOTDataSourceTypeElfPath
Definition embedder.h:2483
FlutterViewFocusDirection
Definition embedder.h:1200
struct _FlutterPlatformMessageResponseHandle FlutterPlatformMessageResponseHandle
Definition embedder.h:1486
@ 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:1508
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:2478
@ kFlutterEngineDartObjectTypeString
Definition embedder.h:2391
@ kFlutterEngineDartObjectTypeBool
Definition embedder.h:2387
@ kFlutterEngineDartObjectTypeDouble
Definition embedder.h:2390
@ kFlutterEngineDartObjectTypeInt32
Definition embedder.h:2388
@ kFlutterEngineDartObjectTypeBuffer
Definition embedder.h:2394
@ kFlutterEngineDartObjectTypeInt64
Definition embedder.h:2389
@ kFlutterEngineDartObjectTypeNull
Definition embedder.h:2386
void(* FlutterLogMessageCallback)(const char *, const char *, void *)
Definition embedder.h:2503
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:2459
FlutterPointerSignalKind
The type of a pointer signal.
Definition embedder.h:1345
@ kFlutterPointerSignalKindScale
Definition embedder.h:1349
@ kFlutterPointerSignalKindScrollInertiaCancel
Definition embedder.h:1348
@ kFlutterPointerSignalKindScroll
Definition embedder.h:1347
@ kFlutterPointerSignalKindNone
Definition embedder.h:1346
void(* FlutterUpdateSemanticsNodeCallback)(const FlutterSemanticsNode *, void *)
Definition embedder.h:1867
void(* VoidCallback)(void *)
Definition embedder.h:416
FlutterEngineDisplaysUpdateType
Definition embedder.h:2373
@ kFlutterEngineDisplaysUpdateTypeStartup
Definition embedder.h:2379
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:1482
int64_t FlutterViewId
Definition embedder.h:393
FlutterKeyEventType
Definition embedder.h:1401
@ kFlutterKeyEventTypeDown
Definition embedder.h:1403
@ kFlutterKeyEventTypeUp
Definition embedder.h:1402
@ kFlutterKeyEventTypeRepeat
Definition embedder.h:1404
void(* FlutterUpdateSemanticsCallback2)(const FlutterSemanticsUpdate2 *, void *)
Definition embedder.h:1879
int64_t FlutterEngineDartPort
Definition embedder.h:2383
@ kFlutterOpenGLTargetTypeFramebuffer
Definition embedder.h:424
@ kFlutterOpenGLTargetTypeSurface
Definition embedder.h:427
@ kFlutterOpenGLTargetTypeTexture
Definition embedder.h:421
@ kFlutterBackingStoreTypeSoftware2
Definition embedder.h:2115
@ kFlutterBackingStoreTypeMetal
Specifies a Metal backing store. This is backed by a Metal texture.
Definition embedder.h:2110
@ kFlutterBackingStoreTypeVulkan
Specifies a Vulkan backing store. This is backed by a Vulkan VkImage.
Definition embedder.h:2112
@ kFlutterBackingStoreTypeSoftware
Specified an software allocation for Flutter to render into using the CPU.
Definition embedder.h:2108
@ kFlutterBackingStoreTypeOpenGL
Definition embedder.h:2106
#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
@ kFlutterPointerDeviceKindInvertedStylus
Definition embedder.h:1314
@ 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
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
const FlutterLayer size_t layers_count
const FlutterLayer ** layers
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
std::shared_ptr< ContextGLES > context
impeller::ShaderType type
uint32_t color_type
int32_t height
int32_t width
UniqueLoadedElf loaded_elf
Definition embedder.cc:1709
const uint8_t * vm_isolate_instrs
Definition embedder.cc:1713
const uint8_t * vm_snapshot_instrs
Definition embedder.cc:1711
const uint8_t * vm_snapshot_data
Definition embedder.cc:1710
const uint8_t * vm_isolate_data
Definition embedder.cc:1712
std::unique_ptr< flutter::PlatformMessage > message
Definition embedder.cc:1695
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:2148
FlutterVulkanBackingStore vulkan
Definition embedder.h:2140
FlutterMetalBackingStore metal
Definition embedder.h:2138
FlutterBackingStoreType type
Specifies the type of backing store.
Definition embedder.h:2126
FlutterOpenGLBackingStore open_gl
The description of the OpenGL backing store.
Definition embedder.h:2132
FlutterSoftwareBackingStore software
The description of the software backing store.
Definition embedder.h:2134
FlutterSoftwareBackingStore2 software2
The description of the software backing store.
Definition embedder.h:2136
size_t struct_size
The size of this struct. Must be sizeof(FlutterBackingStore).
Definition embedder.h:2120
An update to whether a message channel has a listener set or not.
Definition embedder.h:1884
FlutterBackingStoreCreateCallback create_backing_store_callback
Definition embedder.h:2268
FlutterBackingStoreCollectCallback collect_backing_store_callback
Definition embedder.h:2273
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:2489
const char * elf_path
Absolute path to an ELF library file.
Definition embedder.h:2492
FlutterEngineDartObjectType type
Definition embedder.h:2442
const char * string_value
Definition embedder.h:2451
const FlutterEngineDartBuffer * buffer_value
Definition embedder.h:2452
Function-pointer-based versions of the APIs above.
Definition embedder.h:3763
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:2202
FlutterMetalTexture texture
Definition embedder.h:2029
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:1978
FlutterOpenGLTexture texture
A texture for Flutter to render into.
Definition embedder.h:1972
FlutterOpenGLTargetType type
Definition embedder.h:1969
FlutterOpenGLFramebuffer framebuffer
Definition embedder.h:1975
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:1492
size_t struct_size
The size of this struct. Must be sizeof(FlutterPointerEvent).
Definition embedder.h:1354
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:1843
size_t nodes_count
The number of semantics node updates.
Definition embedder.h:1841
size_t custom_actions_count
The number of semantics custom action updates.
Definition embedder.h:1845
FlutterSemanticsCustomAction * custom_actions
Array of semantics custom actions. Has length custom_actions_count.
Definition embedder.h:1847
FlutterViewId view_id
The ID of the view that includes the node.
Definition embedder.h:2833
FlutterSemanticsAction action
The semantics action.
Definition embedder.h:2839
size_t data_length
The data length.
Definition embedder.h:2845
uint64_t node_id
The semantics node identifier.
Definition embedder.h:2836
const uint8_t * data
Data associated with the action.
Definition embedder.h:2842
double height
Definition embedder.h:636
double width
Definition embedder.h:635
VoidCallback destruction_callback
Definition embedder.h:2015
size_t row_bytes
The number of bytes in a single row of the allocation.
Definition embedder.h:2006
FlutterSoftwarePixelFormat pixel_format
Definition embedder.h:2019
VoidCallback destruction_callback
Definition embedder.h:1996
size_t row_bytes
The number of bytes in a single row of the allocation.
Definition embedder.h:1987
SoftwareSurfacePresentCallback surface_present_callback
Definition embedder.h:1034
FlutterTaskRunner runner
Definition embedder.h:1904
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:1699
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
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:910
LoadAction load_action
Definition formats.h:911
std::shared_ptr< Texture > texture
Definition formats.h:909
StoreAction store_action
Definition formats.h:912
static constexpr Color DarkSlateGray()
Definition color.h:423
bool use_sdfs
Use SDFs for rendering.
Definition flags.h:11
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()