Flutter Engine
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_CONTEXT_H_
6 #define FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_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"
22 #include "third_party/skia/include/core/SkImage.h"
23 
24 namespace flutter {
25 namespace testing {
26 
27 using SemanticsNodeCallback = std::function<void(const FlutterSemanticsNode*)>;
29  std::function<void(const FlutterSemanticsCustomAction*)>;
30 using LogMessageCallback =
31  std::function<void(const char* tag, const char* message)>;
32 
35  if (aot_data) {
37  }
38  }
39 };
40 
41 using UniqueAOTData = std::unique_ptr<_FlutterEngineAOTData, AOTDataDeleter>;
42 
47 };
48 
50  public:
51  EmbedderTestContext(std::string assets_path = "");
52 
53  virtual ~EmbedderTestContext();
54 
55  const std::string& GetAssetsPath() const;
56 
57  const fml::Mapping* GetVMSnapshotData() const;
58 
59  const fml::Mapping* GetVMSnapshotInstructions() const;
60 
61  const fml::Mapping* GetIsolateSnapshotData() const;
62 
63  const fml::Mapping* GetIsolateSnapshotInstructions() const;
64 
65  FlutterEngineAOTData GetAOTData() const;
66 
67  void SetRootSurfaceTransformation(SkMatrix matrix);
68 
69  void AddIsolateCreateCallback(fml::closure closure);
70 
71  void AddNativeCallback(const char* name, Dart_NativeFunction function);
72 
73  void SetSemanticsNodeCallback(
74  const SemanticsNodeCallback& update_semantics_node);
75 
76  void SetSemanticsCustomActionCallback(
77  const SemanticsActionCallback& semantics_custom_action);
78 
79  void SetPlatformMessageCallback(
80  const std::function<void(const FlutterPlatformMessage*)>& callback);
81 
82  void SetLogMessageCallback(const LogMessageCallback& log_message_callback);
83 
84  std::future<sk_sp<SkImage>> GetNextSceneImage();
85 
86  EmbedderTestCompositor& GetCompositor();
87 
88  virtual size_t GetSurfacePresentCount() const = 0;
89 
90  virtual EmbedderTestContextType GetContextType() const = 0;
91 
92  // TODO(gw280): encapsulate these properly for subclasses to use
93  protected:
94  // This allows the builder to access the hooks.
95  friend class EmbedderConfigBuilder;
96 
97  using NextSceneCallback = std::function<void(sk_sp<SkImage> image)>;
98 
99  std::string assets_path_;
101  std::unique_ptr<fml::Mapping> vm_snapshot_data_;
102  std::unique_ptr<fml::Mapping> vm_snapshot_instructions_;
103  std::unique_ptr<fml::Mapping> isolate_snapshot_data_;
104  std::unique_ptr<fml::Mapping> isolate_snapshot_instructions_;
106  std::vector<fml::closure> isolate_create_callbacks_;
107  std::shared_ptr<TestDartNativeResolver> native_resolver_;
110  std::function<void(const FlutterPlatformMessage*)> platform_message_callback_;
112  std::unique_ptr<EmbedderTestCompositor> compositor_;
115 
116  static VoidCallback GetIsolateCreateCallbackHook();
117 
119  GetUpdateSemanticsNodeCallbackHook();
120 
122  GetUpdateSemanticsCustomActionCallbackHook();
123 
124  static FlutterLogMessageCallback GetLogMessageCallbackHook();
125 
127  GetComputePlatformResolvedLocaleCallbackHook();
128 
129  void SetupAOTMappingsIfNecessary();
130 
131  void SetupAOTDataIfNecessary();
132 
133  virtual void SetupCompositor() = 0;
134 
135  void FireIsolateCreateCallbacks();
136 
137  void SetNativeResolver();
138 
139  FlutterTransformation GetRootSurfaceTransformation();
140 
141  void PlatformMessageCallback(const FlutterPlatformMessage* message);
142 
143  void FireRootSurfacePresentCallbackIfPresent(
144  const std::function<sk_sp<SkImage>(void)>& image_callback);
145 
146  void SetNextSceneCallback(const NextSceneCallback& next_scene_callback);
147 
148  virtual void SetupSurface(SkISize surface_size) = 0;
149 
151 };
152 
153 } // namespace testing
154 } // namespace flutter
155 
156 #endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_CONTEXT_H_
std::unique_ptr< _FlutterEngineAOTData, AOTDataDeleter > UniqueAOTData
std::unique_ptr< fml::Mapping > vm_snapshot_instructions_
std::function< void(const FlutterPlatformMessage *)> platform_message_callback_
void(* FlutterLogMessageCallback)(const char *, const char *, void *)
Definition: embedder.h:1340
std::vector< fml::closure > isolate_create_callbacks_
Dart_NativeFunction function
Definition: fuchsia.cc:51
std::shared_ptr< TestDartNativeResolver > native_resolver_
void(* FlutterUpdateSemanticsNodeCallback)(const FlutterSemanticsNode *, void *)
Definition: embedder.h:887
void(* FlutterUpdateSemanticsCustomActionCallback)(const FlutterSemanticsCustomAction *, void *)
Definition: embedder.h:891
FlKeyEvent FlKeyResponderAsyncCallback callback
std::unique_ptr< fml::Mapping > isolate_snapshot_instructions_
const FlutterLocale *(* FlutterComputePlatformResolvedLocaleCallback)(const FlutterLocale **, size_t)
Definition: embedder.h:1182
std::function< void(const char *tag, const char *message)> LogMessageCallback
std::function< void(const FlutterSemanticsCustomAction *)> SemanticsActionCallback
std::function< void()> closure
Definition: closure.h:14
SemanticsNodeCallback update_semantics_node_callback_
FlutterEngineResult FlutterEngineCollectAOTData(FlutterEngineAOTData data)
Collects the AOT data.
Definition: embedder.cc:802
void operator()(FlutterEngineAOTData aot_data)
SemanticsActionCallback update_semantics_custom_action_callback_
std::unique_ptr< EmbedderTestCompositor > compositor_
std::unique_ptr< fml::Mapping > vm_snapshot_data_
const char * name
Definition: fuchsia.cc:50
void(* VoidCallback)(void *)
Definition: embedder.h:251
std::unique_ptr< fml::Mapping > isolate_snapshot_data_
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:27
std::function< void(sk_sp< SkImage > image)> NextSceneCallback
std::function< void(const FlutterSemanticsNode *)> SemanticsNodeCallback