Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
embedder_test_context.h
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#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_TEST_CONTEXT_H_
6#define FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_TEST_CONTEXT_H_
7
8#include <future>
9#include <map>
10#include <memory>
11#include <mutex>
12#include <string>
13#include <vector>
14
15#include "flutter/fml/closure.h"
16#include "flutter/fml/macros.h"
17#include "flutter/fml/mapping.h"
18#include "flutter/shell/platform/embedder/embedder.h"
19#include "flutter/shell/platform/embedder/tests/embedder_test_compositor.h"
20#include "flutter/testing/elf_loader.h"
21#include "flutter/testing/test_dart_native_resolver.h"
23
24namespace flutter {
25namespace testing {
26
28 std::function<void(const FlutterSemanticsUpdate2*)>;
30 std::function<void(const FlutterSemanticsUpdate*)>;
31using SemanticsNodeCallback = std::function<void(const FlutterSemanticsNode*)>;
33 std::function<void(const FlutterSemanticsCustomAction*)>;
35 std::function<void(const char* tag, const char* message)>;
36using ChannelUpdateCallback = std::function<void(const FlutterChannelUpdate*)>;
37
40 if (aot_data) {
42 }
43 }
44};
45
46using UniqueAOTData = std::unique_ptr<_FlutterEngineAOTData, AOTDataDeleter>;
47
54
56 public:
57 explicit EmbedderTestContext(std::string assets_path = "");
58
60
61 const std::string& GetAssetsPath() const;
62
63 const fml::Mapping* GetVMSnapshotData() const;
64
66
68
70
72
74
75 void AddIsolateCreateCallback(const fml::closure& closure);
76
78
80
82
83 void SetSemanticsNodeCallback(SemanticsNodeCallback update_semantics_node);
84
86 SemanticsActionCallback semantics_custom_action);
87
89 const std::function<void(const FlutterPlatformMessage*)>& callback);
90
91 void SetLogMessageCallback(const LogMessageCallback& log_message_callback);
92
94
95 std::future<sk_sp<SkImage>> GetNextSceneImage();
96
98
99 virtual size_t GetSurfacePresentCount() const = 0;
100
102
103 // Sets up the callback for vsync. This callback will be invoked
104 // for every vsync. This should be used in conjunction with SetupVsyncCallback
105 // on the EmbedderConfigBuilder. Any callback setup here must call
106 // `FlutterEngineOnVsync` from the platform task runner.
107 void SetVsyncCallback(std::function<void(intptr_t)> callback);
108
109 // Runs the vsync callback.
110 void RunVsyncCallback(intptr_t baton);
111
112 // TODO(gw280): encapsulate these properly for subclasses to use
113 protected:
114 // This allows the builder to access the hooks.
116
117 using NextSceneCallback = std::function<void(sk_sp<SkImage> image)>;
118
119#ifdef SHELL_ENABLE_VULKAN
120 // The TestVulkanContext destructor must be called _after_ the compositor is
121 // freed.
122 fml::RefPtr<TestVulkanContext> vulkan_context_ = nullptr;
123#endif
124
125 std::string assets_path_;
127 std::unique_ptr<fml::Mapping> vm_snapshot_data_;
128 std::unique_ptr<fml::Mapping> vm_snapshot_instructions_;
129 std::unique_ptr<fml::Mapping> isolate_snapshot_data_;
130 std::unique_ptr<fml::Mapping> isolate_snapshot_instructions_;
132 std::vector<fml::closure> isolate_create_callbacks_;
133 std::shared_ptr<TestDartNativeResolver> native_resolver_;
141 std::unique_ptr<EmbedderTestCompositor> compositor_;
144 std::function<void(intptr_t)> vsync_callback_ = nullptr;
145
147
149
151
153
156
158
161
163
165
167
168 virtual void SetupCompositor() = 0;
169
171
173
175
177
179 const std::function<sk_sp<SkImage>(void)>& image_callback);
180
181 void SetNextSceneCallback(const NextSceneCallback& next_scene_callback);
182
183 virtual void SetupSurface(SkISize surface_size) = 0;
184
186};
187
188} // namespace testing
189} // namespace flutter
190
191#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_TEST_CONTEXT_H_
void SetSemanticsCustomActionCallback(SemanticsActionCallback semantics_custom_action)
const fml::Mapping * GetIsolateSnapshotData() const
std::vector< fml::closure > isolate_create_callbacks_
virtual EmbedderTestContextType GetContextType() const =0
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
virtual size_t GetSurfacePresentCount() const =0
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_
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()
FML_DISALLOW_COPY_AND_ASSIGN(EmbedderTestContext)
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)
virtual void SetupSurface(SkISize surface_size)=0
void(* Dart_NativeFunction)(Dart_NativeArguments arguments)
Definition dart_api.h:3198
FlutterEngineResult FlutterEngineCollectAOTData(FlutterEngineAOTData data)
Collects the AOT data.
Definition embedder.cc:1476
void(* FlutterUpdateSemanticsCustomActionCallback)(const FlutterSemanticsCustomAction *, void *)
Definition embedder.h:1520
void(* FlutterUpdateSemanticsCallback)(const FlutterSemanticsUpdate *, void *)
Definition embedder.h:1524
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
sk_sp< SkImage > image
Definition examples.cpp:29
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Dart_NativeFunction function
Definition fuchsia.cc:51
Win32Message message
std::function< void(const FlutterSemanticsCustomAction *)> SemanticsActionCallback
std::function< void(const FlutterSemanticsNode *)> SemanticsNodeCallback
std::unique_ptr< _FlutterEngineAOTData, AOTDataDeleter > UniqueAOTData
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::function< void()> closure
Definition closure.h:14
An update to whether a message channel has a listener set or not.
Definition embedder.h:1533
A batch of updates to semantics nodes and custom actions.
Definition embedder.h:1502
void operator()(FlutterEngineAOTData aot_data)