5#include "flutter/shell/platform/embedder/tests/embedder_config_builder.h"
7#include "flutter/common/constants.h"
8#include "flutter/runtime/dart_vm.h"
9#include "flutter/shell/platform/embedder/embedder.h"
15#include "flutter/shell/platform/embedder/tests/embedder_test_compositor_gl.h"
16#include "flutter/shell/platform/embedder/tests/embedder_test_context_gl.h"
19#ifdef SHELL_ENABLE_VULKAN
20#include "flutter/shell/platform/embedder/tests/embedder_test_context_vulkan.h"
21#include "flutter/vulkan/vulkan_device.h"
25#ifdef SHELL_ENABLE_METAL
26#include "flutter/shell/platform/embedder/tests/embedder_test_context_metal.h"
41 ->PlatformMessageCallback(
message);
48 opengl_renderer_config_.make_current = [](
void* context) ->
bool {
51 opengl_renderer_config_.clear_current = [](
void* context) ->
bool {
54 opengl_renderer_config_.present_with_info =
59 opengl_renderer_config_.fbo_with_frame_info_callback =
64 opengl_renderer_config_.populate_existing_damage =
nullptr;
65 opengl_renderer_config_.make_resource_current = [](
void* context) ->
bool {
67 ->GLMakeResourceCurrent();
69 opengl_renderer_config_.gl_proc_resolver = [](
void* context,
70 const char*
name) ->
void* {
74 opengl_renderer_config_.fbo_reset_after_present =
true;
75 opengl_renderer_config_.surface_transformation =
78 ->GetRootSurfaceTransformation();
82#ifdef SHELL_ENABLE_METAL
83 InitializeMetalRendererConfig();
86#ifdef SHELL_ENABLE_VULKAN
87 InitializeVulkanRendererConfig();
92 [](
void* context,
const void* allocation,
size_t row_bytes,
97 if (!
bitmap.installPixels(image_info,
const_cast<void*
>(allocation),
99 FML_LOG(
ERROR) <<
"Could not copy pixels for the software "
100 "composition from the engine.";
135 return project_args_;
140 renderer_config_.
software = software_renderer_config_;
145#ifdef SHELL_ENABLE_GL
162#ifdef SHELL_ENABLE_GL
194#ifdef SHELL_ENABLE_GL
196 renderer_config_.
open_gl = opengl_renderer_config_;
202#ifdef SHELL_ENABLE_METAL
204 renderer_config_.
metal = metal_renderer_config_;
211 std::optional<FlutterVulkanInstanceProcAddressCallback>
212 instance_proc_address_callback) {
213#ifdef SHELL_ENABLE_VULKAN
216 if (instance_proc_address_callback.has_value()) {
218 instance_proc_address_callback.value();
220 renderer_config_.
vulkan = vulkan_renderer_config;
282 log_tag_ = std::move(tag);
283 project_args_.
log_tag = log_tag_.c_str();
292 if (executable_name.empty()) {
295 command_line_arguments_[0] = std::move(executable_name);
299 if (entrypoint.empty()) {
303 dart_entrypoint_ = std::move(entrypoint);
312 command_line_arguments_.emplace_back(std::move(arg));
320 dart_entrypoint_arguments_.emplace_back(std::move(arg));
325 if (runner ==
nullptr) {
340 return renderer_config_;
345 if (runner ==
nullptr) {
359 bool use_present_layers_callback) {
362 compositor_.struct_size =
sizeof(compositor_);
363 compositor_.user_data = &compositor;
364 compositor_.create_backing_store_callback =
370 ->CreateBackingStore(config, backing_store_out);
372 compositor_.collect_backing_store_callback =
377 ->CollectBackingStore(backing_store);
379 if (use_present_layers_callback) {
380 compositor_.present_layers_callback = [](
const FlutterLayer** layers,
398 compositor_.avoid_backing_store_cache = avoid_backing_store_cache;
413 std::make_unique<EmbedderTestBackingStoreProducer>(
414 compositor.GetGrContext(),
type, software_pixfmt));
418 return SetupEngine(
true);
422 return SetupEngine(
false);
429 std::vector<const char*>
args;
430 args.reserve(command_line_arguments_.size());
432 for (
const auto& arg : command_line_arguments_) {
433 args.push_back(arg.c_str());
446 std::vector<const char*> dart_args;
447 dart_args.reserve(dart_entrypoint_arguments_.size());
449 for (
const auto& arg : dart_entrypoint_arguments_) {
450 dart_args.push_back(arg.c_str());
453 if (!dart_args.empty()) {
465 &project_args, &context_, &
engine)
467 &project_args, &context_, &
engine);
476#ifdef SHELL_ENABLE_METAL
478void EmbedderConfigBuilder::InitializeMetalRendererConfig() {
483 metal_renderer_config_.struct_size =
sizeof(metal_renderer_config_);
484 EmbedderTestContextMetal& metal_context =
485 reinterpret_cast<EmbedderTestContextMetal&
>(context_);
487 metal_renderer_config_.device =
488 metal_context.GetTestMetalContext()->GetMetalDevice();
489 metal_renderer_config_.present_command_queue =
490 metal_context.GetTestMetalContext()->GetMetalCommandQueue();
491 metal_renderer_config_.get_next_drawable_callback =
493 return reinterpret_cast<EmbedderTestContextMetal*
>(
user_data)
494 ->GetNextDrawable(frame_info);
496 metal_renderer_config_.present_drawable_callback =
498 EmbedderTestContextMetal* metal_context =
499 reinterpret_cast<EmbedderTestContextMetal*
>(
user_data);
500 return metal_context->Present(
texture->texture_id);
502 metal_renderer_config_.external_texture_frame_callback =
505 EmbedderTestContextMetal* metal_context =
506 reinterpret_cast<EmbedderTestContextMetal*
>(
user_data);
514#ifdef SHELL_ENABLE_VULKAN
516void EmbedderConfigBuilder::InitializeVulkanRendererConfig() {
522 vulkan_renderer_config_.version =
523 static_cast<EmbedderTestContextVulkan&
>(context_)
524 .vulkan_context_->application_->GetAPIVersion();
525 vulkan_renderer_config_.instance =
526 static_cast<EmbedderTestContextVulkan&
>(context_)
527 .vulkan_context_->application_->GetInstance();
528 vulkan_renderer_config_.physical_device =
529 static_cast<EmbedderTestContextVulkan&
>(context_)
530 .vulkan_context_->device_->GetPhysicalDeviceHandle();
531 vulkan_renderer_config_.device =
532 static_cast<EmbedderTestContextVulkan&
>(context_)
533 .vulkan_context_->device_->GetHandle();
534 vulkan_renderer_config_.queue_family_index =
535 static_cast<EmbedderTestContextVulkan&
>(context_)
536 .vulkan_context_->device_->GetGraphicsQueueIndex();
537 vulkan_renderer_config_.queue =
538 static_cast<EmbedderTestContextVulkan&
>(context_)
539 .vulkan_context_->device_->GetQueueHandle();
540 vulkan_renderer_config_.get_instance_proc_address_callback =
542 vulkan_renderer_config_.get_next_image_callback =
546 reinterpret_cast<EmbedderTestContextVulkan*
>(context)->GetNextImage(
547 {
static_cast<int>(frame_info->size.width),
548 static_cast<int>(frame_info->size.height)});
555 vulkan_renderer_config_.present_image_callback =
557 return reinterpret_cast<EmbedderTestContextVulkan*
>(context)->PresentImage(
558 reinterpret_cast<VkImage
>(
image->image));
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
void SetSoftwareRendererConfig(SkISize surface_size=SkISize::Make(1, 1))
void SetPlatformTaskRunner(const FlutterTaskRunnerDescription *runner)
void SetupVsyncCallback()
void SetLogTag(std::string tag)
void SetIsolateCreateCallbackHook()
void SetRendererConfig(EmbedderTestContextType type, SkISize surface_size)
void SetExecutableName(std::string executable_name)
void SetRenderTargetType(EmbedderTestBackingStoreProducer::RenderTargetType type, FlutterSoftwarePixelFormat software_pixfmt=kFlutterSoftwarePixelFormatNative32)
void SetOpenGLFBOCallBack()
void SetDartEntrypoint(std::string entrypoint)
void AddCommandLineArgument(std::string arg)
void SetLogMessageCallbackHook()
void SetChannelUpdateCallbackHook()
FlutterProjectArgs & GetProjectArgs()
void SetRenderTaskRunner(const FlutterTaskRunnerDescription *runner)
FlutterRendererConfig & GetRendererConfig()
void SetOpenGLPresentCallBack()
void AddDartEntrypointArgument(std::string arg)
void SetVulkanRendererConfig(SkISize surface_size, std::optional< FlutterVulkanInstanceProcAddressCallback > instance_proc_address_callback={})
void SetOpenGLRendererConfig(SkISize surface_size)
EmbedderConfigBuilder(EmbedderTestContext &context, InitializationPreference preference=InitializationPreference::kSnapshotsInitialize)
FlutterCompositor & GetCompositor()
void SetMetalRendererConfig(SkISize surface_size)
UniqueEngine LaunchEngine() const
void SetCompositor(bool avoid_backing_store_cache=false, bool use_present_layers_callback=false)
void SetSemanticsCallbackHooks()
UniqueEngine InitializeEngine() const
void SetLocalizationCallbackHooks()
void SetPlatformMessageCallback(const std::function< void(const FlutterPlatformMessage *)> &callback)
void SetBackingStoreProducer(std::unique_ptr< EmbedderTestBackingStoreProducer > backingstore_producer)
bool Present(FlutterViewId view_id, const FlutterLayer **layers, size_t layers_count)
static void * InstanceProcAddr(void *user_data, FlutterVulkanInstanceHandle instance, const char *name)
void RunVsyncCallback(intptr_t baton)
const fml::Mapping * GetIsolateSnapshotData() const
virtual EmbedderTestContextType GetContextType() const =0
const fml::Mapping * GetVMSnapshotInstructions() const
EmbedderTestCompositor & GetCompositor()
FlutterUpdateSemanticsNodeCallback GetUpdateSemanticsNodeCallbackHook()
const fml::Mapping * GetIsolateSnapshotInstructions() const
static FlutterLogMessageCallback GetLogMessageCallbackHook()
const std::string & GetAssetsPath() const
static VoidCallback GetIsolateCreateCallbackHook()
void SetPlatformMessageCallback(const std::function< void(const FlutterPlatformMessage *)> &callback)
static FlutterComputePlatformResolvedLocaleCallback GetComputePlatformResolvedLocaleCallbackHook()
FlutterEngineAOTData GetAOTData() const
virtual void SetupCompositor()=0
FlutterUpdateSemanticsCustomActionCallback GetUpdateSemanticsCustomActionCallbackHook()
FlutterUpdateSemanticsCallback2 GetUpdateSemanticsCallback2Hook()
FlutterUpdateSemanticsCallback GetUpdateSemanticsCallbackHook()
FlutterChannelUpdateCallback GetChannelUpdateCallbackHook()
const fml::Mapping * GetVMSnapshotData() const
virtual void SetupSurface(SkISize surface_size)=0
FlutterEngineResult FlutterEngineRun(size_t version, const FlutterRendererConfig *config, const FlutterProjectArgs *args, void *user_data, FLUTTER_API_SYMBOL(FlutterEngine) *engine_out)
Initialize and run a Flutter engine instance and return a handle to it. This is a convenience method ...
FlutterEngineResult 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...
FlutterSoftwarePixelFormat
#define FLUTTER_ENGINE_VERSION
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_LOG(severity)
#define FML_CHECK(condition)
Dart_NativeFunction function
SK_API sk_sp< SkImage > RasterFromBitmap(const SkBitmap &bitmap)
sk_sp< const SkImage > image
fml::UniqueObject< FlutterEngine, UniqueEngineTraits > UniqueEngine
constexpr int64_t kFlutterImplicitViewId
DEF_SWITCHES_START aot vmservice shared library name
const FlutterTaskRunnerDescription * render_task_runner
const FlutterTaskRunnerDescription * platform_task_runner
size_t struct_size
The size of this struct. Must be sizeof(FlutterCustomTaskRunners).
size_t struct_size
The size of this struct. Must be sizeof(FlutterFrameInfo).
FlutterUIntSize size
The size of the surface that will be backed by the fbo.
UIntCallback fbo_callback
uint32_t fbo_id
Id of the fbo backing the surface that was presented.
FlutterPlatformMessageCallback platform_message_callback
FlutterComputePlatformResolvedLocaleCallback compute_platform_resolved_locale_callback
FlutterLogMessageCallback log_message_callback
VsyncCallback vsync_callback
const uint8_t * isolate_snapshot_data
FlutterEngineAOTData aot_data
FlutterUpdateSemanticsCallback update_semantics_callback
const uint8_t * vm_snapshot_data
size_t isolate_snapshot_instructions_size
const char *const * dart_entrypoint_argv
size_t struct_size
The size of this struct. Must be sizeof(FlutterProjectArgs).
FlutterUpdateSemanticsCallback2 update_semantics_callback2
const uint8_t * vm_snapshot_instructions
size_t isolate_snapshot_data_size
const char *const * command_line_argv
FlutterChannelUpdateCallback channel_update_callback
size_t vm_snapshot_instructions_size
bool shutdown_dart_vm_when_done
const char * custom_dart_entrypoint
FlutterUpdateSemanticsCustomActionCallback update_semantics_custom_action_callback
FlutterUpdateSemanticsNodeCallback update_semantics_node_callback
const FlutterCustomTaskRunners * custom_task_runners
size_t vm_snapshot_data_size
int command_line_argc
The command line argument count used to initialize the project.
VoidCallback root_isolate_create_callback
const uint8_t * isolate_snapshot_instructions
const FlutterCompositor * compositor
FlutterVulkanRendererConfig vulkan
FlutterMetalRendererConfig metal
FlutterSoftwareRendererConfig software
FlutterOpenGLRendererConfig open_gl
size_t struct_size
The size of this struct. Must be sizeof(FlutterSoftwareRendererConfig).
SoftwareSurfacePresentCallback surface_present_callback
FlutterVulkanInstanceProcAddressCallback get_instance_proc_address_callback
static constexpr SkISize Make(int32_t w, int32_t h)
static SkImageInfo MakeN32Premul(int width, int height)
@ VK_FORMAT_R8G8B8A8_UNORM