Flutter Engine
flutter::testing::EmbedderTestContext Class Referenceabstract

#include <embedder_test_context.h>

Inheritance diagram for flutter::testing::EmbedderTestContext:
flutter::testing::EmbedderTestContextGL flutter::testing::EmbedderTestContextSoftware

Public Member Functions

 EmbedderTestContext (std::string assets_path="")
 
virtual ~EmbedderTestContext ()
 
const std::string & GetAssetsPath () const
 
const fml::MappingGetVMSnapshotData () const
 
const fml::MappingGetVMSnapshotInstructions () const
 
const fml::MappingGetIsolateSnapshotData () const
 
const fml::MappingGetIsolateSnapshotInstructions () const
 
FlutterEngineAOTData GetAOTData () const
 
void SetRootSurfaceTransformation (SkMatrix matrix)
 
void AddIsolateCreateCallback (fml::closure closure)
 
void AddNativeCallback (const char *name, Dart_NativeFunction function)
 
void SetSemanticsNodeCallback (const SemanticsNodeCallback &update_semantics_node)
 
void SetSemanticsCustomActionCallback (const SemanticsActionCallback &semantics_custom_action)
 
void SetPlatformMessageCallback (const std::function< void(const FlutterPlatformMessage *)> &callback)
 
std::future< sk_sp< SkImage > > GetNextSceneImage ()
 
EmbedderTestCompositorGetCompositor ()
 
virtual size_t GetSurfacePresentCount () const =0
 

Protected Types

using NextSceneCallback = std::function< void(sk_sp< SkImage > image)>
 

Protected Member Functions

void SetupAOTMappingsIfNecessary ()
 
void SetupAOTDataIfNecessary ()
 
virtual void SetupCompositor ()=0
 
void FireIsolateCreateCallbacks ()
 
void SetNativeResolver ()
 
FlutterTransformation GetRootSurfaceTransformation ()
 
void PlatformMessageCallback (const FlutterPlatformMessage *message)
 
void FireRootSurfacePresentCallbackIfPresent (const std::function< sk_sp< SkImage >(void)> &image_callback)
 
void SetNextSceneCallback (const NextSceneCallback &next_scene_callback)
 
virtual void SetupSurface (SkISize surface_size)=0
 
 FML_DISALLOW_COPY_AND_ASSIGN (EmbedderTestContext)
 

Static Protected Member Functions

static VoidCallback GetIsolateCreateCallbackHook ()
 
static FlutterUpdateSemanticsNodeCallback GetUpdateSemanticsNodeCallbackHook ()
 
static FlutterUpdateSemanticsCustomActionCallback GetUpdateSemanticsCustomActionCallbackHook ()
 
static FlutterComputePlatformResolvedLocaleCallback GetComputePlatformResolvedLocaleCallbackHook ()
 

Protected Attributes

std::string assets_path_
 
ELFAOTSymbols aot_symbols_
 
std::unique_ptr< fml::Mappingvm_snapshot_data_
 
std::unique_ptr< fml::Mappingvm_snapshot_instructions_
 
std::unique_ptr< fml::Mappingisolate_snapshot_data_
 
std::unique_ptr< fml::Mappingisolate_snapshot_instructions_
 
UniqueAOTData aot_data_
 
std::vector< fml::closureisolate_create_callbacks_
 
std::shared_ptr< TestDartNativeResolvernative_resolver_
 
SemanticsNodeCallback update_semantics_node_callback_
 
SemanticsActionCallback update_semantics_custom_action_callback_
 
std::function< void(const FlutterPlatformMessage *)> platform_message_callback_
 
std::unique_ptr< EmbedderTestCompositorcompositor_
 
NextSceneCallback next_scene_callback_
 
SkMatrix root_surface_transformation_
 

Friends

class EmbedderConfigBuilder
 

Detailed Description

Definition at line 41 of file embedder_test_context.h.

Member Typedef Documentation

◆ NextSceneCallback

using flutter::testing::EmbedderTestContext::NextSceneCallback = std::function<void(sk_sp<SkImage> image)>
protected

Definition at line 85 of file embedder_test_context.h.

Constructor & Destructor Documentation

◆ EmbedderTestContext()

flutter::testing::EmbedderTestContext::EmbedderTestContext ( std::string  assets_path = "")

Definition at line 18 of file embedder_test_context.cc.

References isolate_create_callbacks_, native_resolver_, SetupAOTDataIfNecessary(), SetupAOTMappingsIfNecessary(), and ~EmbedderTestContext().

19  : assets_path_(std::move(assets_path)),
21  native_resolver_(std::make_shared<TestDartNativeResolver>()) {
24  isolate_create_callbacks_.push_back(
25  [weak_resolver =
26  std::weak_ptr<TestDartNativeResolver>{native_resolver_}]() {
27  if (auto resolver = weak_resolver.lock()) {
28  resolver->SetNativeResolverForIsolate();
29  }
30  });
31 }
std::vector< fml::closure > isolate_create_callbacks_
std::shared_ptr< TestDartNativeResolver > native_resolver_
ELFAOTSymbols LoadELFSymbolFromFixturesIfNeccessary()
Attempts to resolve AOT symbols from the portable ELF loader. This location is automatically resolved...
Definition: elf_loader.cc:15

◆ ~EmbedderTestContext()

flutter::testing::EmbedderTestContext::~EmbedderTestContext ( )
virtualdefault

Referenced by EmbedderTestContext().

Member Function Documentation

◆ AddIsolateCreateCallback()

void flutter::testing::EmbedderTestContext::AddIsolateCreateCallback ( fml::closure  closure)

Definition at line 96 of file embedder_test_context.cc.

References isolate_create_callbacks_.

96  {
97  if (closure) {
99  }
100 }
std::vector< fml::closure > isolate_create_callbacks_
std::function< void()> closure
Definition: closure.h:14

◆ AddNativeCallback()

void flutter::testing::EmbedderTestContext::AddNativeCallback ( const char *  name,
Dart_NativeFunction  function 
)

Definition at line 115 of file embedder_test_context.cc.

References native_resolver_.

116  {
117  native_resolver_->AddNativeCallback({name}, function);
118 }
std::shared_ptr< TestDartNativeResolver > native_resolver_
const char * name
Definition: fuchsia.cc:50

◆ FireIsolateCreateCallbacks()

void flutter::testing::EmbedderTestContext::FireIsolateCreateCallbacks ( )
protected

Definition at line 109 of file embedder_test_context.cc.

References isolate_create_callbacks_.

Referenced by GetIsolateCreateCallbackHook().

109  {
110  for (auto closure : isolate_create_callbacks_) {
111  closure();
112  }
113 }
std::vector< fml::closure > isolate_create_callbacks_
std::function< void()> closure
Definition: closure.h:14

◆ FireRootSurfacePresentCallbackIfPresent()

void flutter::testing::EmbedderTestContext::FireRootSurfacePresentCallbackIfPresent ( const std::function< sk_sp< SkImage >(void)> &  image_callback)
protected
Note
Procedure doesn't copy all closures.

Definition at line 202 of file embedder_test_context.cc.

References next_scene_callback_.

Referenced by flutter::testing::EmbedderTestContextSoftware::Present(), and flutter::testing::EmbedderTestContextGL::~EmbedderTestContextGL().

203  {
204  if (!next_scene_callback_) {
205  return;
206  }
207  auto callback = next_scene_callback_;
208  next_scene_callback_ = nullptr;
209  callback(image_callback());
210 }

◆ FML_DISALLOW_COPY_AND_ASSIGN()

flutter::testing::EmbedderTestContext::FML_DISALLOW_COPY_AND_ASSIGN ( EmbedderTestContext  )
protected

◆ GetAOTData()

FlutterEngineAOTData flutter::testing::EmbedderTestContext::GetAOTData ( ) const

Definition at line 88 of file embedder_test_context.cc.

References aot_data_.

Referenced by flutter::testing::EmbedderConfigBuilder::SetAOTDataElf().

88  {
89  return aot_data_.get();
90 }

◆ GetAssetsPath()

const std::string & flutter::testing::EmbedderTestContext::GetAssetsPath ( ) const

Definition at line 67 of file embedder_test_context.cc.

References assets_path_.

Referenced by flutter::testing::EmbedderConfigBuilder::SetAssetsPath().

67  {
68  return assets_path_;
69 }

◆ GetCompositor()

EmbedderTestCompositor & flutter::testing::EmbedderTestContext::GetCompositor ( )

Definition at line 175 of file embedder_test_context.cc.

References compositor_, and FML_CHECK.

Referenced by flutter::testing::EmbedderConfigBuilder::SetCompositor(), and flutter::testing::EmbedderConfigBuilder::SetRenderTargetType().

175  {
177  << "Accessed the compositor on a context where one was not setup. Use "
178  "the config builder to setup a context with a custom compositor.";
179  return *compositor_;
180 }
std::unique_ptr< EmbedderTestCompositor > compositor_
#define FML_CHECK(condition)
Definition: logging.h:68

◆ GetComputePlatformResolvedLocaleCallbackHook()

FlutterComputePlatformResolvedLocaleCallback flutter::testing::EmbedderTestContext::GetComputePlatformResolvedLocaleCallbackHook ( )
staticprotected

Definition at line 164 of file embedder_test_context.cc.

References length.

Referenced by flutter::testing::EmbedderConfigBuilder::SetLocalizationCallbackHooks().

164  {
165  return [](const FlutterLocale** supported_locales,
166  size_t length) -> const FlutterLocale* {
167  return supported_locales[0];
168  };
169 }
size_t length

◆ GetIsolateCreateCallbackHook()

VoidCallback flutter::testing::EmbedderTestContext::GetIsolateCreateCallbackHook ( )
staticprotected

Definition at line 102 of file embedder_test_context.cc.

References FireIsolateCreateCallbacks(), and user_data.

Referenced by flutter::testing::EmbedderConfigBuilder::SetIsolateCreateCallbackHook().

102  {
103  return [](void* user_data) {
104  reinterpret_cast<EmbedderTestContext*>(user_data)
106  };
107 }
EmbedderTestContext(std::string assets_path="")
G_BEGIN_DECLS FlValue gpointer user_data

◆ GetIsolateSnapshotData()

const fml::Mapping * flutter::testing::EmbedderTestContext::GetIsolateSnapshotData ( ) const

Definition at line 79 of file embedder_test_context.cc.

References isolate_snapshot_data_.

Referenced by flutter::testing::EmbedderConfigBuilder::SetSnapshots().

79  {
80  return isolate_snapshot_data_.get();
81 }
std::unique_ptr< fml::Mapping > isolate_snapshot_data_

◆ GetIsolateSnapshotInstructions()

const fml::Mapping * flutter::testing::EmbedderTestContext::GetIsolateSnapshotInstructions ( ) const

Definition at line 83 of file embedder_test_context.cc.

References isolate_snapshot_instructions_.

Referenced by flutter::testing::EmbedderConfigBuilder::SetSnapshots().

84  {
85  return isolate_snapshot_instructions_.get();
86 }
std::unique_ptr< fml::Mapping > isolate_snapshot_instructions_

◆ GetNextSceneImage()

std::future< sk_sp< SkImage > > flutter::testing::EmbedderTestContext::GetNextSceneImage ( )

Definition at line 191 of file embedder_test_context.cc.

References fml::MakeCopyable(), and SetNextSceneCallback().

191  {
192  std::promise<sk_sp<SkImage>> promise;
193  auto future = promise.get_future();
195  fml::MakeCopyable([promise = std::move(promise)](auto image) mutable {
196  promise.set_value(image);
197  }));
198  return future;
199 }
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition: make_copyable.h:57
void SetNextSceneCallback(const NextSceneCallback &next_scene_callback)

◆ GetRootSurfaceTransformation()

FlutterTransformation flutter::testing::EmbedderTestContext::GetRootSurfaceTransformation ( )
protected

Definition at line 171 of file embedder_test_context.cc.

References FlutterTransformationMake(), and root_surface_transformation_.

171  {
173 }
FlutterTransformation FlutterTransformationMake(const SkMatrix &matrix)

◆ GetSurfacePresentCount()

virtual size_t flutter::testing::EmbedderTestContext::GetSurfacePresentCount ( ) const
pure virtual

◆ GetUpdateSemanticsCustomActionCallbackHook()

FlutterUpdateSemanticsCustomActionCallback flutter::testing::EmbedderTestContext::GetUpdateSemanticsCustomActionCallbackHook ( )
staticprotected

Definition at line 154 of file embedder_test_context.cc.

References action, and user_data.

Referenced by flutter::testing::EmbedderConfigBuilder::SetSemanticsCallbackHooks().

154  {
155  return [](const FlutterSemanticsCustomAction* action, void* user_data) {
156  auto context = reinterpret_cast<EmbedderTestContext*>(user_data);
157  if (auto callback = context->update_semantics_custom_action_callback_) {
158  callback(action);
159  }
160  };
161 }
EmbedderTestContext(std::string assets_path="")
G_BEGIN_DECLS FlValue gpointer user_data
SemanticsAction action

◆ GetUpdateSemanticsNodeCallbackHook()

FlutterUpdateSemanticsNodeCallback flutter::testing::EmbedderTestContext::GetUpdateSemanticsNodeCallbackHook ( )
staticprotected

Definition at line 144 of file embedder_test_context.cc.

References user_data.

Referenced by flutter::testing::EmbedderConfigBuilder::SetSemanticsCallbackHooks().

144  {
145  return [](const FlutterSemanticsNode* semantics_node, void* user_data) {
146  auto context = reinterpret_cast<EmbedderTestContext*>(user_data);
147  if (auto callback = context->update_semantics_node_callback_) {
148  callback(semantics_node);
149  }
150  };
151 }
EmbedderTestContext(std::string assets_path="")
G_BEGIN_DECLS FlValue gpointer user_data

◆ GetVMSnapshotData()

const fml::Mapping * flutter::testing::EmbedderTestContext::GetVMSnapshotData ( ) const

Definition at line 71 of file embedder_test_context.cc.

References vm_snapshot_data_.

Referenced by flutter::testing::EmbedderConfigBuilder::SetSnapshots().

71  {
72  return vm_snapshot_data_.get();
73 }
std::unique_ptr< fml::Mapping > vm_snapshot_data_

◆ GetVMSnapshotInstructions()

const fml::Mapping * flutter::testing::EmbedderTestContext::GetVMSnapshotInstructions ( ) const

Definition at line 75 of file embedder_test_context.cc.

References vm_snapshot_instructions_.

Referenced by flutter::testing::EmbedderConfigBuilder::SetSnapshots().

75  {
76  return vm_snapshot_instructions_.get();
77 }
std::unique_ptr< fml::Mapping > vm_snapshot_instructions_

◆ PlatformMessageCallback()

void flutter::testing::EmbedderTestContext::PlatformMessageCallback ( const FlutterPlatformMessage message)
protected

Definition at line 136 of file embedder_test_context.cc.

References platform_message_callback_.

137  {
140  }
141 }
std::function< void(const FlutterPlatformMessage *)> platform_message_callback_

◆ SetNativeResolver()

void flutter::testing::EmbedderTestContext::SetNativeResolver ( )
protected

◆ SetNextSceneCallback()

void flutter::testing::EmbedderTestContext::SetNextSceneCallback ( const NextSceneCallback next_scene_callback)
protected

Definition at line 182 of file embedder_test_context.cc.

References compositor_, and next_scene_callback_.

Referenced by GetNextSceneImage().

183  {
184  if (compositor_) {
185  compositor_->SetNextSceneCallback(next_scene_callback);
186  return;
187  }
188  next_scene_callback_ = next_scene_callback;
189 }
std::unique_ptr< EmbedderTestCompositor > compositor_

◆ SetPlatformMessageCallback()

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

Definition at line 131 of file embedder_test_context.cc.

References platform_message_callback_.

Referenced by flutter::testing::EmbedderConfigBuilder::SetPlatformMessageCallback().

132  {
133  platform_message_callback_ = callback;
134 }
std::function< void(const FlutterPlatformMessage *)> platform_message_callback_

◆ SetRootSurfaceTransformation()

void flutter::testing::EmbedderTestContext::SetRootSurfaceTransformation ( SkMatrix  matrix)

Definition at line 92 of file embedder_test_context.cc.

References root_surface_transformation_.

◆ SetSemanticsCustomActionCallback()

void flutter::testing::EmbedderTestContext::SetSemanticsCustomActionCallback ( const SemanticsActionCallback semantics_custom_action)

Definition at line 125 of file embedder_test_context.cc.

References update_semantics_custom_action_callback_.

126  {
128  update_semantics_custom_action_callback;
129 }
SemanticsActionCallback update_semantics_custom_action_callback_

◆ SetSemanticsNodeCallback()

void flutter::testing::EmbedderTestContext::SetSemanticsNodeCallback ( const SemanticsNodeCallback update_semantics_node)

Definition at line 120 of file embedder_test_context.cc.

References update_semantics_node_callback_.

121  {
122  update_semantics_node_callback_ = update_semantics_node_callback;
123 }
SemanticsNodeCallback update_semantics_node_callback_

◆ SetupAOTDataIfNecessary()

void flutter::testing::EmbedderTestContext::SetupAOTDataIfNecessary ( )
protected

Definition at line 49 of file embedder_test_context.cc.

References aot_data_, FlutterEngineAOTDataSource::elf_path, FlutterEngineCreateAOTData(), flutter::testing::GetFixturesPath(), flutter::DartVM::IsRunningPrecompiledCode(), fml::paths::JoinPaths(), flutter::testing::kAOTAppELFFileName, kFlutterEngineAOTDataSourceTypeElfPath, kSuccess, and FlutterEngineAOTDataSource::type.

Referenced by EmbedderTestContext().

49  {
51  return;
52  }
53  FlutterEngineAOTDataSource data_in = {};
54  FlutterEngineAOTData data_out = nullptr;
55 
56  const auto elf_path =
58 
60  data_in.elf_path = elf_path.c_str();
61 
62  ASSERT_EQ(FlutterEngineCreateAOTData(&data_in, &data_out), kSuccess);
63 
64  aot_data_.reset(data_out);
65 }
std::string JoinPaths(std::initializer_list< std::string > components)
Definition: paths.cc:14
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
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:199
FlutterEngineAOTDataSourceType type
Definition: embedder.h:1126
constexpr const char * kAOTAppELFFileName
Definition: elf_loader.h:17
const char * elf_path
Absolute path to an ELF library file.
Definition: embedder.h:1129
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:597

◆ SetupAOTMappingsIfNecessary()

void flutter::testing::EmbedderTestContext::SetupAOTMappingsIfNecessary ( )
protected

Definition at line 35 of file embedder_test_context.cc.

References aot_symbols_, isolate_snapshot_data_, isolate_snapshot_instructions_, flutter::DartVM::IsRunningPrecompiledCode(), flutter::testing::ELFAOTSymbols::vm_isolate_data, flutter::testing::ELFAOTSymbols::vm_isolate_instrs, flutter::testing::ELFAOTSymbols::vm_snapshot_data, vm_snapshot_data_, flutter::testing::ELFAOTSymbols::vm_snapshot_instrs, and vm_snapshot_instructions_.

Referenced by EmbedderTestContext().

35  {
37  return;
38  }
40  std::make_unique<fml::NonOwnedMapping>(aot_symbols_.vm_snapshot_data, 0u);
41  vm_snapshot_instructions_ = std::make_unique<fml::NonOwnedMapping>(
44  std::make_unique<fml::NonOwnedMapping>(aot_symbols_.vm_isolate_data, 0u);
45  isolate_snapshot_instructions_ = std::make_unique<fml::NonOwnedMapping>(
47 }
const uint8_t * vm_snapshot_instrs
Definition: elf_loader.h:28
std::unique_ptr< fml::Mapping > vm_snapshot_instructions_
const uint8_t * vm_isolate_data
Definition: elf_loader.h:29
std::unique_ptr< fml::Mapping > isolate_snapshot_instructions_
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:199
const uint8_t * vm_isolate_instrs
Definition: elf_loader.h:30
std::unique_ptr< fml::Mapping > vm_snapshot_data_
const uint8_t * vm_snapshot_data
Definition: elf_loader.h:27
std::unique_ptr< fml::Mapping > isolate_snapshot_data_

◆ SetupCompositor()

virtual void flutter::testing::EmbedderTestContext::SetupCompositor ( )
protectedpure virtual

◆ SetupSurface()

virtual void flutter::testing::EmbedderTestContext::SetupSurface ( SkISize  surface_size)
protectedpure virtual

Friends And Related Function Documentation

◆ EmbedderConfigBuilder

friend class EmbedderConfigBuilder
friend

Definition at line 83 of file embedder_test_context.h.

Member Data Documentation

◆ aot_data_

UniqueAOTData flutter::testing::EmbedderTestContext::aot_data_
protected

Definition at line 93 of file embedder_test_context.h.

Referenced by GetAOTData(), and SetupAOTDataIfNecessary().

◆ aot_symbols_

ELFAOTSymbols flutter::testing::EmbedderTestContext::aot_symbols_
protected

Definition at line 88 of file embedder_test_context.h.

Referenced by SetupAOTMappingsIfNecessary().

◆ assets_path_

std::string flutter::testing::EmbedderTestContext::assets_path_
protected

Definition at line 87 of file embedder_test_context.h.

Referenced by GetAssetsPath().

◆ compositor_

◆ isolate_create_callbacks_

std::vector<fml::closure> flutter::testing::EmbedderTestContext::isolate_create_callbacks_
protected

◆ isolate_snapshot_data_

std::unique_ptr<fml::Mapping> flutter::testing::EmbedderTestContext::isolate_snapshot_data_
protected

Definition at line 91 of file embedder_test_context.h.

Referenced by GetIsolateSnapshotData(), and SetupAOTMappingsIfNecessary().

◆ isolate_snapshot_instructions_

std::unique_ptr<fml::Mapping> flutter::testing::EmbedderTestContext::isolate_snapshot_instructions_
protected

◆ native_resolver_

std::shared_ptr<TestDartNativeResolver> flutter::testing::EmbedderTestContext::native_resolver_
protected

Definition at line 95 of file embedder_test_context.h.

Referenced by AddNativeCallback(), and EmbedderTestContext().

◆ next_scene_callback_

NextSceneCallback flutter::testing::EmbedderTestContext::next_scene_callback_
protected

◆ platform_message_callback_

std::function<void(const FlutterPlatformMessage*)> flutter::testing::EmbedderTestContext::platform_message_callback_
protected

Definition at line 98 of file embedder_test_context.h.

Referenced by PlatformMessageCallback(), and SetPlatformMessageCallback().

◆ root_surface_transformation_

SkMatrix flutter::testing::EmbedderTestContext::root_surface_transformation_
protected

◆ update_semantics_custom_action_callback_

SemanticsActionCallback flutter::testing::EmbedderTestContext::update_semantics_custom_action_callback_
protected

Definition at line 97 of file embedder_test_context.h.

Referenced by SetSemanticsCustomActionCallback().

◆ update_semantics_node_callback_

SemanticsNodeCallback flutter::testing::EmbedderTestContext::update_semantics_node_callback_
protected

Definition at line 96 of file embedder_test_context.h.

Referenced by SetSemanticsNodeCallback().

◆ vm_snapshot_data_

std::unique_ptr<fml::Mapping> flutter::testing::EmbedderTestContext::vm_snapshot_data_
protected

Definition at line 89 of file embedder_test_context.h.

Referenced by GetVMSnapshotData(), and SetupAOTMappingsIfNecessary().

◆ vm_snapshot_instructions_

std::unique_ptr<fml::Mapping> flutter::testing::EmbedderTestContext::vm_snapshot_instructions_
protected

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