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 
33  if (aot_data) {
35  }
36  }
37 };
38 
39 using UniqueAOTData = std::unique_ptr<_FlutterEngineAOTData, AOTDataDeleter>;
40 
42  public:
43  EmbedderTestContext(std::string assets_path = "");
44 
45  virtual ~EmbedderTestContext();
46 
47  const std::string& GetAssetsPath() const;
48 
49  const fml::Mapping* GetVMSnapshotData() const;
50 
51  const fml::Mapping* GetVMSnapshotInstructions() const;
52 
53  const fml::Mapping* GetIsolateSnapshotData() const;
54 
55  const fml::Mapping* GetIsolateSnapshotInstructions() const;
56 
57  FlutterEngineAOTData GetAOTData() const;
58 
59  void SetRootSurfaceTransformation(SkMatrix matrix);
60 
61  void AddIsolateCreateCallback(fml::closure closure);
62 
63  void AddNativeCallback(const char* name, Dart_NativeFunction function);
64 
65  void SetSemanticsNodeCallback(
66  const SemanticsNodeCallback& update_semantics_node);
67 
68  void SetSemanticsCustomActionCallback(
69  const SemanticsActionCallback& semantics_custom_action);
70 
71  void SetPlatformMessageCallback(
72  const std::function<void(const FlutterPlatformMessage*)>& callback);
73 
74  std::future<sk_sp<SkImage>> GetNextSceneImage();
75 
76  EmbedderTestCompositor& GetCompositor();
77 
78  virtual size_t GetSurfacePresentCount() const = 0;
79 
80  // TODO(gw280): encapsulate these properly for subclasses to use
81  protected:
82  // This allows the builder to access the hooks.
83  friend class EmbedderConfigBuilder;
84 
85  using NextSceneCallback = std::function<void(sk_sp<SkImage> image)>;
86 
87  std::string assets_path_;
89  std::unique_ptr<fml::Mapping> vm_snapshot_data_;
90  std::unique_ptr<fml::Mapping> vm_snapshot_instructions_;
91  std::unique_ptr<fml::Mapping> isolate_snapshot_data_;
92  std::unique_ptr<fml::Mapping> isolate_snapshot_instructions_;
94  std::vector<fml::closure> isolate_create_callbacks_;
95  std::shared_ptr<TestDartNativeResolver> native_resolver_;
98  std::function<void(const FlutterPlatformMessage*)> platform_message_callback_;
99  std::unique_ptr<EmbedderTestCompositor> compositor_;
102 
103  static VoidCallback GetIsolateCreateCallbackHook();
104 
106  GetUpdateSemanticsNodeCallbackHook();
107 
109  GetUpdateSemanticsCustomActionCallbackHook();
110 
112  GetComputePlatformResolvedLocaleCallbackHook();
113 
114  void SetupAOTMappingsIfNecessary();
115 
116  void SetupAOTDataIfNecessary();
117 
118  virtual void SetupCompositor() = 0;
119 
120  void FireIsolateCreateCallbacks();
121 
122  void SetNativeResolver();
123 
124  FlutterTransformation GetRootSurfaceTransformation();
125 
126  void PlatformMessageCallback(const FlutterPlatformMessage* message);
127 
128  void FireRootSurfacePresentCallbackIfPresent(
129  const std::function<sk_sp<SkImage>(void)>& image_callback);
130 
131  void SetNextSceneCallback(const NextSceneCallback& next_scene_callback);
132 
133  virtual void SetupSurface(SkISize surface_size) = 0;
134 
136 };
137 
138 } // namespace testing
139 } // namespace flutter
140 
141 #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_
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:696
void(* FlutterUpdateSemanticsCustomActionCallback)(const FlutterSemanticsCustomAction *, void *)
Definition: embedder.h:700
std::unique_ptr< fml::Mapping > isolate_snapshot_instructions_
const FlutterLocale *(* FlutterComputePlatformResolvedLocaleCallback)(const FlutterLocale **, size_t)
Definition: embedder.h:966
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:651
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:243
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