• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 struct ShellArgs;
22 
23 // The object that is returned to the embedder as an opaque pointer to the
24 // instance of the Flutter engine.
25 class EmbedderEngine {
26  public:
27   using IdleCallback = std::function<void(int64_t)>;
28 
29   EmbedderEngine(std::unique_ptr<EmbedderThreadHost> thread_host,
30                  TaskRunners task_runners,
31                  Settings settings,
32                  RunConfiguration run_configuration,
33                  Shell::CreateCallback<PlatformView> on_create_platform_view,
34                  Shell::CreateCallback<Rasterizer> on_create_rasterizer,
35                  EmbedderExternalTextureGL::ExternalTextureCallback
36                      external_texture_callback);
37 
38   ~EmbedderEngine();
39 
40   bool LaunchShell();
41 
42   bool CollectShell();
43 
44   const TaskRunners& GetTaskRunners() const;
45 
46   bool NotifyCreated();
47 
48   bool NotifyDestroyed();
49 
50   bool RunRootIsolate();
51 
52   bool IsValid() const;
53 
54   bool SetIdleNotificationCallback(const IdleCallback& idle_notification_callback);
55 
56   bool SetViewportMetrics(flutter::ViewportMetrics metrics);
57 
58   bool DispatchPointerDataPacket(
59       std::unique_ptr<flutter::PointerDataPacket> packet);
60 
61   bool SendPlatformMessage(fml::RefPtr<flutter::PlatformMessage> message);
62 
63   bool RegisterTexture(int64_t texture);
64 
65   bool UnregisterTexture(int64_t texture);
66 
67   bool MarkTextureFrameAvailable(int64_t texture);
68 
69   bool OnVsyncEvent(intptr_t baton,
70                     fml::TimePoint frame_start_time,
71                     fml::TimePoint frame_target_time);
72 
73   bool PostRenderThreadTask(fml::closure task);
74 
75   bool RunTask(const FlutterTask* task);
76 
77  private:
78   const std::unique_ptr<EmbedderThreadHost> thread_host_;
79   TaskRunners task_runners_;
80   RunConfiguration run_configuration_;
81   std::unique_ptr<ShellArgs> shell_args_;
82   std::unique_ptr<Shell> shell_;
83   const EmbedderExternalTextureGL::ExternalTextureCallback
84       external_texture_callback_;
85 
86   FML_DISALLOW_COPY_AND_ASSIGN(EmbedderEngine);
87 };
88 
89 }  // namespace flutter
90 
91 #endif  // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_ENGINE_H_
92