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_EMBEDDER_ENGINE_H_ 6 #define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_ENGINE_H_ 7 8 #include <memory> 9 #include <unordered_map> 10 11 #include "flutter/fml/macros.h" 12 #include "flutter/shell/common/shell.h" 13 #include "flutter/shell/common/thread_host.h" 14 #include "flutter/shell/platform/embedder/embedder.h" 15 #include "flutter/shell/platform/embedder/embedder_engine.h" 16 #include "flutter/shell/platform/embedder/embedder_external_texture_gl.h" 17 #include "flutter/shell/platform/embedder/embedder_thread_host.h" 18 19 namespace flutter { 20 21 // The object that is returned to the embedder as an opaque pointer to the 22 // instance of the Flutter engine. 23 class EmbedderEngine { 24 public: 25 using IdleCallback = std::function<void(int64_t)>; 26 27 EmbedderEngine(std::unique_ptr<EmbedderThreadHost> thread_host, 28 flutter::TaskRunners task_runners, 29 flutter::Settings settings, 30 Shell::CreateCallback<PlatformView> on_create_platform_view, 31 Shell::CreateCallback<Rasterizer> on_create_rasterizer, 32 EmbedderExternalTextureGL::ExternalTextureCallback 33 external_texture_callback); 34 35 ~EmbedderEngine(); 36 37 const TaskRunners& GetTaskRunners() const; 38 39 bool NotifyCreated(); 40 41 bool NotifyDestroyed(); 42 43 bool Run(RunConfiguration run_configuration); 44 45 bool IsValid() const; 46 47 bool SetIdleNotificationCallback(const IdleCallback& idle_notification_callback); 48 49 bool SetViewportMetrics(flutter::ViewportMetrics metrics); 50 51 bool DispatchPointerDataPacket( 52 std::unique_ptr<flutter::PointerDataPacket> packet); 53 54 bool SendPlatformMessage(fml::RefPtr<flutter::PlatformMessage> message); 55 56 bool RegisterTexture(int64_t texture); 57 58 bool UnregisterTexture(int64_t texture); 59 60 bool MarkTextureFrameAvailable(int64_t texture); 61 62 bool OnVsyncEvent(intptr_t baton, 63 fml::TimePoint frame_start_time, 64 fml::TimePoint frame_target_time); 65 66 bool PostRenderThreadTask(fml::closure task); 67 68 bool RunTask(const FlutterTask* task); 69 70 private: 71 const std::unique_ptr<EmbedderThreadHost> thread_host_; 72 TaskRunners task_runners_; 73 std::unique_ptr<Shell> shell_; 74 const EmbedderExternalTextureGL::ExternalTextureCallback 75 external_texture_callback_; 76 bool is_valid_ = false; 77 78 FML_DISALLOW_COPY_AND_ASSIGN(EmbedderEngine); 79 }; 80 81 } // namespace flutter 82 83 #endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_ENGINE_H_ 84