Flutter Engine
 
Loading...
Searching...
No Matches
embedder_test_context.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
6
7#include <utility>
8
10#include "flutter/fml/paths.h"
14#include "third_party/dart/runtime/bin/elf_loader.h"
15#include "third_party/skia/include/core/SkImage.h"
16
17namespace flutter {
18namespace testing {
19
21 : assets_path_(std::move(assets_path)),
22 aot_symbols_(
24 native_resolver_(std::make_shared<TestDartNativeResolver>()) {
28 [weak_resolver =
29 std::weak_ptr<TestDartNativeResolver>{native_resolver_}]() {
30 if (auto resolver = weak_resolver.lock()) {
31 resolver->SetNativeResolverForIsolate();
32 }
33 });
34}
35
37
40 return;
41 }
43 std::make_unique<fml::NonOwnedMapping>(aot_symbols_.vm_snapshot_data, 0u);
44 vm_snapshot_instructions_ = std::make_unique<fml::NonOwnedMapping>(
47 std::make_unique<fml::NonOwnedMapping>(aot_symbols_.vm_isolate_data, 0u);
48 isolate_snapshot_instructions_ = std::make_unique<fml::NonOwnedMapping>(
50}
51
54 return;
55 }
56 FlutterEngineAOTDataSource data_in = {};
57 FlutterEngineAOTData data_out = nullptr;
58
59 const auto elf_path = fml::paths::JoinPaths(
61
63 data_in.elf_path = elf_path.c_str();
64
65 ASSERT_EQ(FlutterEngineCreateAOTData(&data_in, &data_out), kSuccess);
66
67 aot_data_.reset(data_out);
68}
69
70const std::string& EmbedderTestContext::GetAssetsPath() const {
71 return assets_path_;
72}
73
77
81
85
90
94
98
102
104 const fml::closure& closure) {
105 if (closure) {
106 isolate_create_callbacks_.push_back(closure);
107 }
108}
109
116
118 for (const auto& closure : isolate_create_callbacks_) {
119 closure();
120 }
121}
122
124 Dart_NativeFunction function) {
125 native_resolver_->AddNativeCallback({name}, function);
126}
127
129 SemanticsUpdateCallback2 update_semantics_callback) {
130 update_semantics_callback2_ = std::move(update_semantics_callback);
131}
132
134 SemanticsUpdateCallback update_semantics_callback) {
135 update_semantics_callback_ = std::move(update_semantics_callback);
136}
137
139 SemanticsNodeCallback update_semantics_node_callback) {
140 update_semantics_node_callback_ = std::move(update_semantics_node_callback);
141}
142
144 SemanticsActionCallback update_semantics_custom_action_callback) {
146 std::move(update_semantics_custom_action_callback);
147}
148
153
158
163
170
175
178 if (update_semantics_callback2_ == nullptr) {
179 return nullptr;
180 }
181
182 return [](const FlutterSemanticsUpdate2* update, void* user_data) {
183 auto context = reinterpret_cast<EmbedderTestContext*>(user_data);
184 if (context->update_semantics_callback2_) {
185 context->update_semantics_callback2_(update);
186 }
187 };
188}
189
192 if (update_semantics_callback_ == nullptr) {
193 return nullptr;
194 }
195
196 return [](const FlutterSemanticsUpdate* update, void* user_data) {
197 auto context = reinterpret_cast<EmbedderTestContext*>(user_data);
198 if (context->update_semantics_callback_) {
199 context->update_semantics_callback_(update);
200 }
201 };
202}
203
206 if (update_semantics_node_callback_ == nullptr) {
207 return nullptr;
208 }
209
210 return [](const FlutterSemanticsNode* semantics_node, void* user_data) {
211 auto context = reinterpret_cast<EmbedderTestContext*>(user_data);
212 if (context->update_semantics_node_callback_) {
213 context->update_semantics_node_callback_(semantics_node);
214 }
215 };
216}
217
221 return nullptr;
222 }
223
224 return [](const FlutterSemanticsCustomAction* action, void* user_data) {
225 auto context = reinterpret_cast<EmbedderTestContext*>(user_data);
226 if (context->update_semantics_custom_action_callback_) {
228 }
229 };
230}
231
233 return [](const char* tag, const char* message, void* user_data) {
234 auto context = reinterpret_cast<EmbedderTestContext*>(user_data);
235 if (context->log_message_callback_) {
236 context->log_message_callback_(tag, message);
237 }
238 };
239}
240
243 return [](const FlutterLocale** supported_locales,
244 size_t length) -> const FlutterLocale* {
245 return supported_locales[0];
246 };
247}
248
251 if (channel_update_callback_ == nullptr) {
252 return nullptr;
253 }
254
255 return [](const FlutterChannelUpdate* update, void* user_data) {
256 auto context = reinterpret_cast<EmbedderTestContext*>(user_data);
257 if (context->channel_update_callback_) {
258 context->channel_update_callback_(update);
259 }
260 };
261}
262
265 return [](const FlutterViewFocusChangeRequest* request, void* user_data) {
266 auto context = reinterpret_cast<EmbedderTestContext*>(user_data);
267 if (context->view_focus_change_request_callback_) {
268 context->view_focus_change_request_callback_(request);
269 }
270 };
271}
272
276
279 << "Accessed the compositor on a context where one was not set up. Use "
280 "the config builder to set up a context with a custom compositor.";
281 return *compositor_;
282}
283
285 const NextSceneCallback& next_scene_callback) {
286 if (compositor_) {
287 compositor_->SetNextSceneCallback(next_scene_callback);
288 return;
289 }
290 next_scene_callback_ = next_scene_callback;
291}
292
293std::future<sk_sp<SkImage>> EmbedderTestContext::GetNextSceneImage() {
294 std::promise<sk_sp<SkImage>> promise;
295 auto future = promise.get_future();
297 [promise = std::move(promise)](const auto& image) mutable {
298 promise.set_value(image);
299 }));
300 return future;
301}
302
303/// @note Procedure doesn't copy all closures.
305 const std::function<sk_sp<SkImage>(void)>& image_callback) {
307 return;
308 }
310 next_scene_callback_ = nullptr;
311 callback(image_callback());
312}
313
315 std::function<void(intptr_t)> callback) {
316 vsync_callback_ = std::move(callback);
317}
318
320 vsync_callback_(baton);
321}
322
323} // namespace testing
324} // namespace flutter
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:176
void SetNextSceneCallback(const NextSceneCallback &next_scene_callback)
void SetSemanticsCustomActionCallback(SemanticsActionCallback semantics_custom_action)
const fml::Mapping * GetIsolateSnapshotData() const
std::vector< fml::closure > isolate_create_callbacks_
const fml::Mapping * GetVMSnapshotInstructions() const
void AddNativeCallback(const char *name, Dart_NativeFunction function)
std::function< void(const FlutterPlatformMessage *)> platform_message_callback_
FlutterUpdateSemanticsNodeCallback GetUpdateSemanticsNodeCallbackHook()
std::unique_ptr< fml::Mapping > isolate_snapshot_instructions_
std::function< void(intptr_t)> vsync_callback_
void SetSemanticsUpdateCallback(SemanticsUpdateCallback update_semantics)
std::shared_ptr< TestDartNativeResolver > native_resolver_
std::unique_ptr< fml::Mapping > vm_snapshot_data_
void SetViewFocusChangeRequestCallback(const ViewFocusChangeRequestCallback &callback)
void SetVsyncCallback(std::function< void(intptr_t)> callback)
const fml::Mapping * GetIsolateSnapshotInstructions() const
static FlutterLogMessageCallback GetLogMessageCallbackHook()
void SetSemanticsNodeCallback(SemanticsNodeCallback update_semantics_node)
std::unique_ptr< fml::Mapping > vm_snapshot_instructions_
void SetPlatformMessageCallback(const std::function< void(const FlutterPlatformMessage *)> &callback)
static FlutterComputePlatformResolvedLocaleCallback GetComputePlatformResolvedLocaleCallbackHook()
void SetChannelUpdateCallback(const ChannelUpdateCallback &callback)
FlutterViewFocusChangeRequestCallback GetViewFocusChangeRequestCallbackHook()
void AddIsolateCreateCallback(const fml::closure &closure)
void SetNextSceneCallback(const NextSceneCallback &next_scene_callback)
void SetLogMessageCallback(const LogMessageCallback &log_message_callback)
std::unique_ptr< EmbedderTestCompositor > compositor_
EmbedderTestContext(std::string assets_path="")
void SetSemanticsUpdateCallback2(SemanticsUpdateCallback2 update_semantics)
std::unique_ptr< fml::Mapping > isolate_snapshot_data_
std::function< void(sk_sp< SkImage > image)> NextSceneCallback
FlutterUpdateSemanticsCustomActionCallback GetUpdateSemanticsCustomActionCallbackHook()
std::future< sk_sp< SkImage > > GetNextSceneImage()
SemanticsUpdateCallback2 update_semantics_callback2_
FlutterUpdateSemanticsCallback2 GetUpdateSemanticsCallback2Hook()
ViewFocusChangeRequestCallback view_focus_change_request_callback_
FlutterUpdateSemanticsCallback GetUpdateSemanticsCallbackHook()
SemanticsActionCallback update_semantics_custom_action_callback_
void PlatformMessageCallback(const FlutterPlatformMessage *message)
FlutterChannelUpdateCallback GetChannelUpdateCallbackHook()
const fml::Mapping * GetVMSnapshotData() const
void FireRootSurfacePresentCallbackIfPresent(const std::function< sk_sp< SkImage >(void)> &image_callback)
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:1682
void(* FlutterUpdateSemanticsCustomActionCallback)(const FlutterSemanticsCustomAction *, void *)
Definition embedder.h:1816
void(* FlutterUpdateSemanticsCallback)(const FlutterSemanticsUpdate *, void *)
Definition embedder.h:1820
@ kFlutterEngineAOTDataSourceTypeElfPath
Definition embedder.h:2428
void(* FlutterLogMessageCallback)(const char *, const char *, void *)
Definition embedder.h:2448
void(* FlutterUpdateSemanticsNodeCallback)(const FlutterSemanticsNode *, void *)
Definition embedder.h:1812
void(* VoidCallback)(void *)
Definition embedder.h:409
const FlutterLocale *(* FlutterComputePlatformResolvedLocaleCallback)(const FlutterLocale **, size_t)
Definition embedder.h:2285
void(* FlutterUpdateSemanticsCallback2)(const FlutterSemanticsUpdate2 *, void *)
Definition embedder.h:1824
void(* FlutterChannelUpdateCallback)(const FlutterChannelUpdate *, void *)
Definition embedder.h:1838
void(* FlutterViewFocusChangeRequestCallback)(const FlutterViewFocusChangeRequest *, void *)
Definition embedder.h:1842
FlutterTransformation FlutterTransformationMake(const flutter::DlMatrix &matrix)
FlutterVulkanImage * image
G_BEGIN_DECLS GBytes * message
FlutterDesktopBinaryReply callback
#define FML_CHECK(condition)
Definition logging.h:104
Dart_NativeFunction function
Definition fuchsia.cc:50
size_t length
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
std::function< void(const FlutterSemanticsCustomAction *)> SemanticsActionCallback
std::function< void(const FlutterSemanticsNode *)> SemanticsNodeCallback
ELFAOTSymbols LoadELFSymbolFromFixturesIfNeccessary(std::string elf_filename)
Attempts to resolve AOT symbols from the portable ELF loader. This location is automatically resolved...
Definition elf_loader.cc:16
std::function< void(const FlutterViewFocusChangeRequest *)> ViewFocusChangeRequestCallback
constexpr const char * kDefaultAOTAppELFFileName
Definition elf_loader.h:16
std::function< void(const FlutterSemanticsUpdate2 *)> SemanticsUpdateCallback2
std::function< void(const char *tag, const char *message)> LogMessageCallback
std::function< void(const FlutterChannelUpdate *)> ChannelUpdateCallback
std::function< void(const FlutterSemanticsUpdate *)> SemanticsUpdateCallback
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27
std::string JoinPaths(std::initializer_list< std::string > components)
Definition paths.cc:14
internal::CopyableLambda< T > MakeCopyable(T lambda)
std::function< void()> closure
Definition closure.h:14
Definition ref_ptr.h:261
An update to whether a message channel has a listener set or not.
Definition embedder.h:1829
FlutterEngineAOTDataSourceType type
Definition embedder.h:2434
const char * elf_path
Absolute path to an ELF library file.
Definition embedder.h:2437
A batch of updates to semantics nodes and custom actions.
Definition embedder.h:1796
const uint8_t * vm_snapshot_data
Definition elf_loader.h:34
const uint8_t * vm_snapshot_instrs
Definition elf_loader.h:35
const uint8_t * vm_isolate_instrs
Definition elf_loader.h:37
const uint8_t * vm_isolate_data
Definition elf_loader.h:36
A 4x4 matrix using column-major storage.
Definition matrix.h:37