Flutter Engine
flutter::testing::EmbedderConfigBuilder Class Reference

#include <embedder_config_builder.h>

Public Types

enum  InitializationPreference {
  InitializationPreference::kSnapshotsInitialize,
  InitializationPreference::kAOTDataInitialize,
  InitializationPreference::kMultiAOTInitialize,
  InitializationPreference::kNoInitialize
}
 

Public Member Functions

 EmbedderConfigBuilder (EmbedderTestContext &context, InitializationPreference preference=InitializationPreference::kSnapshotsInitialize)
 
 ~EmbedderConfigBuilder ()
 
FlutterProjectArgsGetProjectArgs ()
 
void SetSoftwareRendererConfig (SkISize surface_size=SkISize::Make(1, 1))
 
void SetOpenGLRendererConfig (SkISize surface_size)
 
void SetOpenGLFBOCallBack ()
 
void SetOpenGLPresentCallBack ()
 
void SetAssetsPath ()
 
void SetSnapshots ()
 
void SetAOTDataElf ()
 
void SetIsolateCreateCallbackHook ()
 
void SetSemanticsCallbackHooks ()
 
void SetLocalizationCallbackHooks ()
 
void SetDartEntrypoint (std::string entrypoint)
 
void AddCommandLineArgument (std::string arg)
 
void AddDartEntrypointArgument (std::string arg)
 
void SetPlatformTaskRunner (const FlutterTaskRunnerDescription *runner)
 
void SetRenderTaskRunner (const FlutterTaskRunnerDescription *runner)
 
void SetPlatformMessageCallback (const std::function< void(const FlutterPlatformMessage *)> &callback)
 
void SetCompositor ()
 
FlutterCompositorGetCompositor ()
 
void SetRenderTargetType (EmbedderTestBackingStoreProducer::RenderTargetType type)
 
UniqueEngine LaunchEngine () const
 
UniqueEngine InitializeEngine () const
 

Detailed Description

Definition at line 30 of file embedder_config_builder.h.

Member Enumeration Documentation

◆ InitializationPreference

Enumerator
kSnapshotsInitialize 
kAOTDataInitialize 
kMultiAOTInitialize 
kNoInitialize 

Definition at line 32 of file embedder_config_builder.h.

32  {
33  kSnapshotsInitialize,
34  kAOTDataInitialize,
35  kMultiAOTInitialize,
36  kNoInitialize,
37  };

Constructor & Destructor Documentation

◆ EmbedderConfigBuilder()

flutter::testing::EmbedderConfigBuilder::EmbedderConfigBuilder ( EmbedderTestContext context,
InitializationPreference  preference = InitializationPreference::kSnapshotsInitialize 
)

Definition at line 19 of file embedder_config_builder.cc.

References AddCommandLineArgument(), FML_LOG, height, kAOTDataInitialize, kMultiAOTInitialize, kNoInitialize, kSnapshotsInitialize, name, FlutterProjectArgs::platform_message_callback, SetAOTDataElf(), SetAssetsPath(), SetIsolateCreateCallbackHook(), SetLocalizationCallbackHooks(), SetSemanticsCallbackHooks(), SetSnapshots(), FlutterProjectArgs::shutdown_dart_vm_when_done, FlutterSoftwareRendererConfig::struct_size, FlutterCustomTaskRunners::struct_size, FlutterProjectArgs::struct_size, FlutterSoftwareRendererConfig::surface_present_callback, and ~EmbedderConfigBuilder().

22  : context_(context) {
23  project_args_.struct_size = sizeof(project_args_);
24  project_args_.shutdown_dart_vm_when_done = true;
25  project_args_.platform_message_callback =
26  [](const FlutterPlatformMessage* message, void* context) {
27  reinterpret_cast<EmbedderTestContext*>(context)
28  ->PlatformMessageCallback(message);
29  };
30 
31  custom_task_runners_.struct_size = sizeof(FlutterCustomTaskRunners);
32 
33 #ifdef SHELL_ENABLE_GL
34  opengl_renderer_config_.struct_size = sizeof(FlutterOpenGLRendererConfig);
35  opengl_renderer_config_.make_current = [](void* context) -> bool {
36  return reinterpret_cast<EmbedderTestContextGL*>(context)->GLMakeCurrent();
37  };
38  opengl_renderer_config_.clear_current = [](void* context) -> bool {
39  return reinterpret_cast<EmbedderTestContextGL*>(context)->GLClearCurrent();
40  };
41  opengl_renderer_config_.present_with_info =
42  [](void* context, const FlutterPresentInfo* present_info) -> bool {
43  return reinterpret_cast<EmbedderTestContextGL*>(context)->GLPresent(
44  present_info->fbo_id);
45  };
46  opengl_renderer_config_.fbo_with_frame_info_callback =
47  [](void* context, const FlutterFrameInfo* frame_info) -> uint32_t {
48  return reinterpret_cast<EmbedderTestContextGL*>(context)->GLGetFramebuffer(
49  *frame_info);
50  };
51  opengl_renderer_config_.make_resource_current = [](void* context) -> bool {
52  return reinterpret_cast<EmbedderTestContextGL*>(context)
53  ->GLMakeResourceCurrent();
54  };
55  opengl_renderer_config_.gl_proc_resolver = [](void* context,
56  const char* name) -> void* {
57  return reinterpret_cast<EmbedderTestContextGL*>(context)->GLGetProcAddress(
58  name);
59  };
60  opengl_renderer_config_.fbo_reset_after_present = true;
61  opengl_renderer_config_.surface_transformation =
62  [](void* context) -> FlutterTransformation {
63  return reinterpret_cast<EmbedderTestContext*>(context)
64  ->GetRootSurfaceTransformation();
65  };
66 #endif
67 
68  software_renderer_config_.struct_size = sizeof(FlutterSoftwareRendererConfig);
69  software_renderer_config_.surface_present_callback =
70  [](void* context, const void* allocation, size_t row_bytes,
71  size_t height) {
72  auto image_info =
73  SkImageInfo::MakeN32Premul(SkISize::Make(row_bytes / 4, height));
74  SkBitmap bitmap;
75  if (!bitmap.installPixels(image_info, const_cast<void*>(allocation),
76  row_bytes)) {
77  FML_LOG(ERROR) << "Could not copy pixels for the software "
78  "composition from the engine.";
79  return false;
80  }
81  bitmap.setImmutable();
82  return reinterpret_cast<EmbedderTestContextSoftware*>(context)->Present(
83  SkImage::MakeFromBitmap(bitmap));
84  };
85 
86  // The first argument is treated as the executable name. Don't make tests have
87  // to do this manually.
88  AddCommandLineArgument("embedder_unittest");
89 
90  if (preference != InitializationPreference::kNoInitialize) {
91  SetAssetsPath();
95  AddCommandLineArgument("--disable-observatory");
96 
99  SetSnapshots();
100  }
103  SetAOTDataElf();
104  }
105  }
106 }
#define FML_LOG(severity)
Definition: logging.h:65
FlutterPlatformMessageCallback platform_message_callback
Definition: embedder.h:1222
bool shutdown_dart_vm_when_done
Definition: embedder.h:1332
int32_t height
size_t struct_size
The size of this struct. Must be sizeof(FlutterProjectArgs).
Definition: embedder.h:1171
const char * name
Definition: fuchsia.cc:50
size_t struct_size
The size of this struct. Must be sizeof(FlutterCustomTaskRunners).
Definition: embedder.h:747
size_t struct_size
The size of this struct. Must be sizeof(FlutterSoftwareRendererConfig).
Definition: embedder.h:439
SoftwareSurfacePresentCallback surface_present_callback
Definition: embedder.h:444

◆ ~EmbedderConfigBuilder()

flutter::testing::EmbedderConfigBuilder::~EmbedderConfigBuilder ( )
default

Referenced by EmbedderConfigBuilder().

Member Function Documentation

◆ AddCommandLineArgument()

void flutter::testing::EmbedderConfigBuilder::AddCommandLineArgument ( std::string  arg)

Definition at line 212 of file embedder_config_builder.cc.

Referenced by EmbedderConfigBuilder().

212  {
213  if (arg.size() == 0) {
214  return;
215  }
216 
217  command_line_arguments_.emplace_back(std::move(arg));
218 }

◆ AddDartEntrypointArgument()

void flutter::testing::EmbedderConfigBuilder::AddDartEntrypointArgument ( std::string  arg)

Definition at line 220 of file embedder_config_builder.cc.

Referenced by flutter::testing::TEST_F().

220  {
221  if (arg.size() == 0) {
222  return;
223  }
224 
225  dart_entrypoint_arguments_.emplace_back(std::move(arg));
226 }

◆ GetCompositor()

FlutterCompositor & flutter::testing::EmbedderConfigBuilder::GetCompositor ( )

Definition at line 285 of file embedder_config_builder.cc.

Referenced by flutter::testing::TEST_F().

285  {
286  return compositor_;
287 }

◆ GetProjectArgs()

FlutterProjectArgs & flutter::testing::EmbedderConfigBuilder::GetProjectArgs ( )

Definition at line 110 of file embedder_config_builder.cc.

Referenced by flutter::testing::TEST_F().

110  {
111  return project_args_;
112 }

◆ InitializeEngine()

◆ LaunchEngine()

UniqueEngine flutter::testing::EmbedderConfigBuilder::LaunchEngine ( ) const

Definition at line 299 of file embedder_config_builder.cc.

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

299  {
300  return SetupEngine(true);
301 }

◆ SetAOTDataElf()

void flutter::testing::EmbedderConfigBuilder::SetAOTDataElf ( )

Definition at line 182 of file embedder_config_builder.cc.

References FlutterProjectArgs::aot_data, and flutter::testing::EmbedderTestContext::GetAOTData().

Referenced by EmbedderConfigBuilder().

182  {
183  project_args_.aot_data = context_.GetAOTData();
184 }
FlutterEngineAOTData GetAOTData() const
FlutterEngineAOTData aot_data
Definition: embedder.h:1363

◆ SetAssetsPath()

void flutter::testing::EmbedderConfigBuilder::SetAssetsPath ( )

Definition at line 156 of file embedder_config_builder.cc.

References FlutterProjectArgs::assets_path, and flutter::testing::EmbedderTestContext::GetAssetsPath().

Referenced by EmbedderConfigBuilder().

156  {
157  project_args_.assets_path = context_.GetAssetsPath().c_str();
158 }
const char * assets_path
Definition: embedder.h:1175
const std::string & GetAssetsPath() const

◆ SetCompositor()

void flutter::testing::EmbedderConfigBuilder::SetCompositor ( )

Definition at line 252 of file embedder_config_builder.cc.

References FlutterCompositor::collect_backing_store_callback, FlutterProjectArgs::compositor, FlutterCompositor::create_backing_store_callback, flutter::testing::EmbedderTestContext::GetCompositor(), FlutterCompositor::present_layers_callback, flutter::testing::EmbedderTestContext::SetupCompositor(), FlutterCompositor::struct_size, user_data, and FlutterCompositor::user_data.

Referenced by flutter::testing::TEST_F().

252  {
253  context_.SetupCompositor();
254  auto& compositor = context_.GetCompositor();
255  compositor_.struct_size = sizeof(compositor_);
256  compositor_.user_data = &compositor;
257  compositor_.create_backing_store_callback =
258  [](const FlutterBackingStoreConfig* config, //
259  FlutterBackingStore* backing_store_out, //
260  void* user_data //
261  ) {
262  return reinterpret_cast<EmbedderTestCompositor*>(user_data)
263  ->CreateBackingStore(config, backing_store_out);
264  };
265  compositor_.collect_backing_store_callback =
266  [](const FlutterBackingStore* backing_store, //
267  void* user_data //
268  ) {
269  return reinterpret_cast<EmbedderTestCompositor*>(user_data)
270  ->CollectBackingStore(backing_store);
271  };
272  compositor_.present_layers_callback = [](const FlutterLayer** layers, //
273  size_t layers_count, //
274  void* user_data //
275  ) {
276  return reinterpret_cast<EmbedderTestCompositor*>(user_data)->Present(
277  layers, //
278  layers_count //
279 
280  );
281  };
282  project_args_.compositor = &compositor_;
283 }
const FlutterCompositor * compositor
Definition: embedder.h:1348
void * user_data
Definition: embedder.h:925
G_BEGIN_DECLS FlValue gpointer user_data
FlutterBackingStoreCollectCallback collect_backing_store_callback
Definition: embedder.h:936
FlutterLayersPresentCallback present_layers_callback
Definition: embedder.h:939
size_t struct_size
This size of this struct. Must be sizeof(FlutterCompositor).
Definition: embedder.h:920
FlutterBackingStoreCreateCallback create_backing_store_callback
Definition: embedder.h:933

◆ SetDartEntrypoint()

void flutter::testing::EmbedderConfigBuilder::SetDartEntrypoint ( std::string  entrypoint)

Definition at line 203 of file embedder_config_builder.cc.

References FlutterProjectArgs::custom_dart_entrypoint.

Referenced by flutter::testing::TEST_F().

203  {
204  if (entrypoint.size() == 0) {
205  return;
206  }
207 
208  dart_entrypoint_ = std::move(entrypoint);
209  project_args_.custom_dart_entrypoint = dart_entrypoint_.c_str();
210 }
const char * custom_dart_entrypoint
Definition: embedder.h:1308

◆ SetIsolateCreateCallbackHook()

void flutter::testing::EmbedderConfigBuilder::SetIsolateCreateCallbackHook ( )

◆ SetLocalizationCallbackHooks()

void flutter::testing::EmbedderConfigBuilder::SetLocalizationCallbackHooks ( )

◆ SetOpenGLFBOCallBack()

void flutter::testing::EmbedderConfigBuilder::SetOpenGLFBOCallBack ( )

Definition at line 120 of file embedder_config_builder.cc.

References FlutterOpenGLRendererConfig::fbo_callback, FML_CHECK, FlutterUIntSize::height, kOpenGL, FlutterRendererConfig::open_gl, FlutterFrameInfo::size, FlutterFrameInfo::struct_size, FlutterRendererConfig::type, and FlutterUIntSize::width.

Referenced by flutter::testing::TEST_F().

120  {
121 #ifdef SHELL_ENABLE_GL
122  // SetOpenGLRendererConfig must be called before this.
123  FML_CHECK(renderer_config_.type == FlutterRendererType::kOpenGL);
124  renderer_config_.open_gl.fbo_callback = [](void* context) -> uint32_t {
125  FlutterFrameInfo frame_info = {};
126  // fbo_callback doesn't use the frame size information, only
127  // fbo_callback_with_frame_info does.
128  frame_info.struct_size = sizeof(FlutterFrameInfo);
129  frame_info.size.width = 0;
130  frame_info.size.height = 0;
131  return reinterpret_cast<EmbedderTestContextGL*>(context)->GLGetFramebuffer(
132  frame_info);
133  };
134 #endif
135 }
uint32_t width
Definition: embedder.h:319
uint32_t height
Definition: embedder.h:320
FlutterUIntSize size
The size of the surface that will be backed by the fbo.
Definition: embedder.h:354
size_t struct_size
The size of this struct. Must be sizeof(FlutterFrameInfo).
Definition: embedder.h:352
FlutterRendererType type
Definition: embedder.h:448
FlutterOpenGLRendererConfig open_gl
Definition: embedder.h:450
#define FML_CHECK(condition)
Definition: logging.h:68
UIntCallback fbo_callback
Definition: embedder.h:391

◆ SetOpenGLPresentCallBack()

void flutter::testing::EmbedderConfigBuilder::SetOpenGLPresentCallBack ( )

Definition at line 137 of file embedder_config_builder.cc.

References FML_CHECK, kOpenGL, FlutterRendererConfig::open_gl, FlutterOpenGLRendererConfig::present, and FlutterRendererConfig::type.

Referenced by flutter::testing::TEST_F().

137  {
138 #ifdef SHELL_ENABLE_GL
139  // SetOpenGLRendererConfig must be called before this.
140  FML_CHECK(renderer_config_.type == FlutterRendererType::kOpenGL);
141  renderer_config_.open_gl.present = [](void* context) -> bool {
142  // passing a placeholder fbo_id.
143  return reinterpret_cast<EmbedderTestContextGL*>(context)->GLPresent(0);
144  };
145 #endif
146 }
FlutterRendererType type
Definition: embedder.h:448
FlutterOpenGLRendererConfig open_gl
Definition: embedder.h:450
#define FML_CHECK(condition)
Definition: logging.h:68

◆ SetOpenGLRendererConfig()

void flutter::testing::EmbedderConfigBuilder::SetOpenGLRendererConfig ( SkISize  surface_size)

Definition at line 148 of file embedder_config_builder.cc.

References kOpenGL, FlutterRendererConfig::open_gl, flutter::testing::EmbedderTestContext::SetupSurface(), and FlutterRendererConfig::type.

Referenced by flutter::testing::TEST_F().

148  {
149 #ifdef SHELL_ENABLE_GL
150  renderer_config_.type = FlutterRendererType::kOpenGL;
151  renderer_config_.open_gl = opengl_renderer_config_;
152  context_.SetupSurface(surface_size);
153 #endif
154 }
virtual void SetupSurface(SkISize surface_size)=0
FlutterRendererType type
Definition: embedder.h:448
FlutterOpenGLRendererConfig open_gl
Definition: embedder.h:450

◆ SetPlatformMessageCallback()

void flutter::testing::EmbedderConfigBuilder::SetPlatformMessageCallback ( const std::function< void(const FlutterPlatformMessage *)> &  callback)

Definition at line 247 of file embedder_config_builder.cc.

References flutter::testing::EmbedderTestContext::SetPlatformMessageCallback().

Referenced by flutter::testing::TEST_F().

248  {
249  context_.SetPlatformMessageCallback(callback);
250 }
void SetPlatformMessageCallback(const std::function< void(const FlutterPlatformMessage *)> &callback)

◆ SetPlatformTaskRunner()

void flutter::testing::EmbedderConfigBuilder::SetPlatformTaskRunner ( const FlutterTaskRunnerDescription runner)

Definition at line 228 of file embedder_config_builder.cc.

References FlutterProjectArgs::custom_task_runners, and FlutterCustomTaskRunners::platform_task_runner.

Referenced by flutter::testing::TEST_F().

229  {
230  if (runner == nullptr) {
231  return;
232  }
233  custom_task_runners_.platform_task_runner = runner;
234  project_args_.custom_task_runners = &custom_task_runners_;
235 }
const FlutterCustomTaskRunners * custom_task_runners
Definition: embedder.h:1313
const FlutterTaskRunnerDescription * platform_task_runner
Definition: embedder.h:752

◆ SetRenderTargetType()

void flutter::testing::EmbedderConfigBuilder::SetRenderTargetType ( EmbedderTestBackingStoreProducer::RenderTargetType  type)

Definition at line 289 of file embedder_config_builder.cc.

References flutter::testing::EmbedderTestContext::GetCompositor(), and flutter::testing::EmbedderTestCompositor::SetBackingStoreProducer().

Referenced by flutter::testing::TEST_F().

290  {
291  auto& compositor = context_.GetCompositor();
292  // TODO(wrightgeorge): figure out a better way of plumbing through the
293  // GrDirectContext
294  compositor.SetBackingStoreProducer(
295  std::make_unique<EmbedderTestBackingStoreProducer>(
296  compositor.GetGrContext(), type));
297 }
void SetBackingStoreProducer(std::unique_ptr< EmbedderTestBackingStoreProducer > backingstore_producer)

◆ SetRenderTaskRunner()

void flutter::testing::EmbedderConfigBuilder::SetRenderTaskRunner ( const FlutterTaskRunnerDescription runner)

Definition at line 237 of file embedder_config_builder.cc.

References FlutterProjectArgs::custom_task_runners, and FlutterCustomTaskRunners::render_task_runner.

Referenced by flutter::testing::TEST_F().

238  {
239  if (runner == nullptr) {
240  return;
241  }
242 
243  custom_task_runners_.render_task_runner = runner;
244  project_args_.custom_task_runners = &custom_task_runners_;
245 }
const FlutterTaskRunnerDescription * render_task_runner
Definition: embedder.h:757
const FlutterCustomTaskRunners * custom_task_runners
Definition: embedder.h:1313

◆ SetSemanticsCallbackHooks()

void flutter::testing::EmbedderConfigBuilder::SetSemanticsCallbackHooks ( )

◆ SetSnapshots()

void flutter::testing::EmbedderConfigBuilder::SetSnapshots ( )

Definition at line 160 of file embedder_config_builder.cc.

References flutter::testing::EmbedderTestContext::GetIsolateSnapshotData(), flutter::testing::EmbedderTestContext::GetIsolateSnapshotInstructions(), flutter::testing::EmbedderTestContext::GetVMSnapshotData(), flutter::testing::EmbedderTestContext::GetVMSnapshotInstructions(), FlutterProjectArgs::isolate_snapshot_data, FlutterProjectArgs::isolate_snapshot_data_size, FlutterProjectArgs::isolate_snapshot_instructions, FlutterProjectArgs::isolate_snapshot_instructions_size, FlutterProjectArgs::vm_snapshot_data, FlutterProjectArgs::vm_snapshot_data_size, FlutterProjectArgs::vm_snapshot_instructions, and FlutterProjectArgs::vm_snapshot_instructions_size.

Referenced by EmbedderConfigBuilder().

160  {
161  if (auto mapping = context_.GetVMSnapshotData()) {
162  project_args_.vm_snapshot_data = mapping->GetMapping();
163  project_args_.vm_snapshot_data_size = mapping->GetSize();
164  }
165 
166  if (auto mapping = context_.GetVMSnapshotInstructions()) {
167  project_args_.vm_snapshot_instructions = mapping->GetMapping();
168  project_args_.vm_snapshot_instructions_size = mapping->GetSize();
169  }
170 
171  if (auto mapping = context_.GetIsolateSnapshotData()) {
172  project_args_.isolate_snapshot_data = mapping->GetMapping();
173  project_args_.isolate_snapshot_data_size = mapping->GetSize();
174  }
175 
176  if (auto mapping = context_.GetIsolateSnapshotInstructions()) {
177  project_args_.isolate_snapshot_instructions = mapping->GetMapping();
178  project_args_.isolate_snapshot_instructions_size = mapping->GetSize();
179  }
180 }
const uint8_t * isolate_snapshot_data
Definition: embedder.h:1243
size_t vm_snapshot_instructions_size
Definition: embedder.h:1238
const fml::Mapping * GetVMSnapshotInstructions() const
const fml::Mapping * GetVMSnapshotData() const
const uint8_t * vm_snapshot_data
Definition: embedder.h:1227
const uint8_t * vm_snapshot_instructions
Definition: embedder.h:1235
size_t isolate_snapshot_instructions_size
Definition: embedder.h:1254
size_t isolate_snapshot_data_size
Definition: embedder.h:1246
const fml::Mapping * GetIsolateSnapshotInstructions() const
const uint8_t * isolate_snapshot_instructions
Definition: embedder.h:1251
size_t vm_snapshot_data_size
Definition: embedder.h:1230
const fml::Mapping * GetIsolateSnapshotData() const

◆ SetSoftwareRendererConfig()

void flutter::testing::EmbedderConfigBuilder::SetSoftwareRendererConfig ( SkISize  surface_size = SkISize::Make(1, 1))

Definition at line 114 of file embedder_config_builder.cc.

References flutter::kSoftware, flutter::testing::EmbedderTestContext::SetupSurface(), FlutterRendererConfig::software, and FlutterRendererConfig::type.

Referenced by flutter::testing::TEST_F().

114  {
115  renderer_config_.type = FlutterRendererType::kSoftware;
116  renderer_config_.software = software_renderer_config_;
117  context_.SetupSurface(surface_size);
118 }
FlutterSoftwareRendererConfig software
Definition: embedder.h:451
virtual void SetupSurface(SkISize surface_size)=0
FlutterRendererType type
Definition: embedder.h:448

The documentation for this class was generated from the following files: