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 <map> 9 #include <memory> 10 #include <string> 11 #include <vector> 12 13 #include "flutter/fml/closure.h" 14 #include "flutter/fml/macros.h" 15 #include "flutter/fml/mapping.h" 16 #include "flutter/shell/platform/embedder/embedder.h" 17 #include "flutter/shell/platform/embedder/tests/embedder_test_compositor.h" 18 #include "flutter/testing/test_dart_native_resolver.h" 19 #include "flutter/testing/test_gl_surface.h" 20 #include "third_party/skia/include/core/SkImage.h" 21 22 namespace flutter { 23 namespace testing { 24 25 using SemanticsNodeCallback = std::function<void(const FlutterSemanticsNode*)>; 26 using SemanticsActionCallback = 27 std::function<void(const FlutterSemanticsCustomAction*)>; 28 29 class EmbedderTestContext { 30 public: 31 EmbedderTestContext(std::string assets_path = ""); 32 33 ~EmbedderTestContext(); 34 35 const std::string& GetAssetsPath() const; 36 37 const fml::Mapping* GetVMSnapshotData() const; 38 39 const fml::Mapping* GetVMSnapshotInstructions() const; 40 41 const fml::Mapping* GetIsolateSnapshotData() const; 42 43 const fml::Mapping* GetIsolateSnapshotInstructions() const; 44 45 void AddIsolateCreateCallback(fml::closure closure); 46 47 void AddNativeCallback(const char* name, Dart_NativeFunction function); 48 49 void SetSemanticsNodeCallback(SemanticsNodeCallback update_semantics_node); 50 51 void SetSemanticsCustomActionCallback( 52 SemanticsActionCallback semantics_custom_action); 53 54 void SetPlatformMessageCallback( 55 std::function<void(const FlutterPlatformMessage*)> callback); 56 57 void SetupCompositor(); 58 59 EmbedderTestCompositor& GetCompositor(); 60 61 using NextSceneCallback = std::function<void(sk_sp<SkImage> image)>; 62 void SetNextSceneCallback(NextSceneCallback next_scene_callback); 63 64 private: 65 // This allows the builder to access the hooks. 66 friend class EmbedderConfigBuilder; 67 68 std::string assets_path_; 69 std::unique_ptr<fml::Mapping> vm_snapshot_data_; 70 std::unique_ptr<fml::Mapping> vm_snapshot_instructions_; 71 std::unique_ptr<fml::Mapping> isolate_snapshot_data_; 72 std::unique_ptr<fml::Mapping> isolate_snapshot_instructions_; 73 std::vector<fml::closure> isolate_create_callbacks_; 74 std::shared_ptr<TestDartNativeResolver> native_resolver_; 75 SemanticsNodeCallback update_semantics_node_callback_; 76 SemanticsActionCallback update_semantics_custom_action_callback_; 77 std::function<void(const FlutterPlatformMessage*)> platform_message_callback_; 78 std::unique_ptr<TestGLSurface> gl_surface_; 79 std::unique_ptr<EmbedderTestCompositor> compositor_; 80 NextSceneCallback next_scene_callback_; 81 82 static VoidCallback GetIsolateCreateCallbackHook(); 83 84 static FlutterUpdateSemanticsNodeCallback 85 GetUpdateSemanticsNodeCallbackHook(); 86 87 static FlutterUpdateSemanticsCustomActionCallback 88 GetUpdateSemanticsCustomActionCallbackHook(); 89 90 void FireIsolateCreateCallbacks(); 91 92 void SetNativeResolver(); 93 94 void SetupOpenGLSurface(); 95 96 bool GLMakeCurrent(); 97 98 bool GLClearCurrent(); 99 100 bool GLPresent(); 101 102 uint32_t GLGetFramebuffer(); 103 104 bool GLMakeResourceCurrent(); 105 106 void* GLGetProcAddress(const char* name); 107 108 void PlatformMessageCallback(const FlutterPlatformMessage* message); 109 110 FML_DISALLOW_COPY_AND_ASSIGN(EmbedderTestContext); 111 }; 112 113 } // namespace testing 114 } // namespace flutter 115 116 #endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_CONTEXT_H_ 117