Flutter Engine
The 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
5#include "flutter/shell/platform/embedder/tests/embedder_test_context.h"
6
7#include <utility>
8
9#include "flutter/fml/make_copyable.h"
10#include "flutter/fml/paths.h"
11#include "flutter/runtime/dart_vm.h"
12#include "flutter/shell/platform/embedder/tests/embedder_assertions.h"
13#include "flutter/testing/testing.h"
14#include "third_party/dart/runtime/bin/elf_loader.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
100 const fml::closure& closure) {
101 if (closure) {
102 isolate_create_callbacks_.push_back(closure);
103 }
104}
105
112
114 for (const auto& closure : isolate_create_callbacks_) {
115 closure();
116 }
117}
118
123
125 SemanticsUpdateCallback2 update_semantics_callback) {
126 update_semantics_callback2_ = std::move(update_semantics_callback);
127}
128
130 SemanticsUpdateCallback update_semantics_callback) {
131 update_semantics_callback_ = std::move(update_semantics_callback);
132}
133
135 SemanticsNodeCallback update_semantics_node_callback) {
136 update_semantics_node_callback_ = std::move(update_semantics_node_callback);
137}
138
140 SemanticsActionCallback update_semantics_custom_action_callback) {
142 std::move(update_semantics_custom_action_callback);
143}
144
149
154
161
166
169 if (update_semantics_callback2_ == nullptr) {
170 return nullptr;
171 }
172
173 return [](const FlutterSemanticsUpdate2* update, void* user_data) {
174 auto context = reinterpret_cast<EmbedderTestContext*>(user_data);
175 if (context->update_semantics_callback2_) {
177 }
178 };
179}
180
183 if (update_semantics_callback_ == nullptr) {
184 return nullptr;
185 }
186
187 return [](const FlutterSemanticsUpdate* update, void* user_data) {
188 auto context = reinterpret_cast<EmbedderTestContext*>(user_data);
189 if (context->update_semantics_callback_) {
191 }
192 };
193}
194
197 if (update_semantics_node_callback_ == nullptr) {
198 return nullptr;
199 }
200
201 return [](const FlutterSemanticsNode* semantics_node, void* user_data) {
202 auto context = reinterpret_cast<EmbedderTestContext*>(user_data);
203 if (context->update_semantics_node_callback_) {
204 context->update_semantics_node_callback_(semantics_node);
205 }
206 };
207}
208
212 return nullptr;
213 }
214
215 return [](const FlutterSemanticsCustomAction* action, void* user_data) {
216 auto context = reinterpret_cast<EmbedderTestContext*>(user_data);
217 if (context->update_semantics_custom_action_callback_) {
219 }
220 };
221}
222
224 return [](const char* tag, const char* message, void* user_data) {
225 auto context = reinterpret_cast<EmbedderTestContext*>(user_data);
226 if (context->log_message_callback_) {
227 context->log_message_callback_(tag, message);
228 }
229 };
230}
231
234 return [](const FlutterLocale** supported_locales,
235 size_t length) -> const FlutterLocale* {
236 return supported_locales[0];
237 };
238}
239
242 if (channel_update_callback_ == nullptr) {
243 return nullptr;
244 }
245
246 return [](const FlutterChannelUpdate* update, void* user_data) {
247 auto context = reinterpret_cast<EmbedderTestContext*>(user_data);
248 if (context->channel_update_callback_) {
250 }
251 };
252}
253
257
260 << "Accessed the compositor on a context where one was not set up. Use "
261 "the config builder to set up a context with a custom compositor.";
262 return *compositor_;
263}
264
266 const NextSceneCallback& next_scene_callback) {
267 if (compositor_) {
268 compositor_->SetNextSceneCallback(next_scene_callback);
269 return;
270 }
271 next_scene_callback_ = next_scene_callback;
272}
273
274std::future<sk_sp<SkImage>> EmbedderTestContext::GetNextSceneImage() {
275 std::promise<sk_sp<SkImage>> promise;
276 auto future = promise.get_future();
278 fml::MakeCopyable([promise = std::move(promise)](auto image) mutable {
279 promise.set_value(image);
280 }));
281 return future;
282}
283
284/// @note Procedure doesn't copy all closures.
286 const std::function<sk_sp<SkImage>(void)>& image_callback) {
288 return;
289 }
291 next_scene_callback_ = nullptr;
292 callback(image_callback());
293}
294
296 std::function<void(intptr_t)> callback) {
297 vsync_callback_ = std::move(callback);
298}
299
301 vsync_callback_(baton);
302}
303
304} // namespace testing
305} // 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:205
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 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)
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()
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)
void(* Dart_NativeFunction)(Dart_NativeArguments arguments)
Definition dart_api.h:3198
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:1422
void(* FlutterUpdateSemanticsCustomActionCallback)(const FlutterSemanticsCustomAction *, void *)
Definition embedder.h:1520
void(* FlutterUpdateSemanticsCallback)(const FlutterSemanticsUpdate *, void *)
Definition embedder.h:1524
@ kFlutterEngineAOTDataSourceTypeElfPath
Definition embedder.h:2108
void(* FlutterLogMessageCallback)(const char *, const char *, void *)
Definition embedder.h:2128
void(* FlutterUpdateSemanticsNodeCallback)(const FlutterSemanticsNode *, void *)
Definition embedder.h:1516
const FlutterLocale *(* FlutterComputePlatformResolvedLocaleCallback)(const FlutterLocale **, size_t)
Definition embedder.h:1965
void(* FlutterUpdateSemanticsCallback2)(const FlutterSemanticsUpdate2 *, void *)
Definition embedder.h:1528
void(* FlutterChannelUpdateCallback)(const FlutterChannelUpdate *, void *)
Definition embedder.h:1542
FlutterTransformation FlutterTransformationMake(const SkMatrix &matrix)
sk_sp< SkImage > image
Definition examples.cpp:29
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_CHECK(condition)
Definition logging.h:85
Dart_NativeFunction function
Definition fuchsia.cc:51
size_t length
Win32Message message
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:17
constexpr const char * kDefaultAOTAppELFFileName
Definition elf_loader.h:17
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 switches.h:32
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:256
An update to whether a message channel has a listener set or not.
Definition embedder.h:1533
FlutterEngineAOTDataSourceType type
Definition embedder.h:2114
const char * elf_path
Absolute path to an ELF library file.
Definition embedder.h:2117
A batch of updates to semantics nodes and custom actions.
Definition embedder.h:1502
const uint8_t * vm_snapshot_data
Definition elf_loader.h:35
const uint8_t * vm_snapshot_instrs
Definition elf_loader.h:36
const uint8_t * vm_isolate_instrs
Definition elf_loader.h:38
const uint8_t * vm_isolate_data
Definition elf_loader.h:37