• 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_RUNTIME_ACE_RUNTIME_CONTROLLER_H_
6 #define FLUTTER_RUNTIME_ACE_RUNTIME_CONTROLLER_H_
7 
8 #include <memory>
9 #include <vector>
10 
11 #include "flutter/common/task_runners.h"
12 #include "flutter/flow/layers/layer_tree.h"
13 #include "flutter/fml/macros.h"
14 #include "flutter/lib/ui/io_manager.h"
15 #include "flutter/lib/ui/text/font_collection.h"
16 #include "flutter/lib/ui/window/pointer_data_packet.h"
17 #include "flutter/lib/ui/window/window.h"
18 
19 namespace flutter {
20 class Scene;
21 class RuntimeDelegate;
22 class View;
23 class Window;
24 
25 class RuntimeController final : public WindowClient {
26  public:
27   using IdleCallback = std::function<void(int64_t)>;
28 
29   RuntimeController(RuntimeDelegate& client,
30                     TaskRunners task_runners,
31                     fml::WeakPtr<IOManager> io_manager,
32                     int32_t instance_id,
33                     std::function<void(int64_t)> idle_notification_callback);
34 
35   ~RuntimeController() override;
36 
37   std::unique_ptr<RuntimeController> Clone() const;
38 
39   void SetIdleNotificationCallback(const IdleCallback& idle_notification_callback);
40 
41   bool SetViewportMetrics(const ViewportMetrics& metrics);
42 
43   bool SetLocales(const std::vector<std::string>& locale_data);
44 
45   bool SetUserSettingsData(const std::string& data);
46 
47   bool SetLifecycleState(const std::string& data);
48 
49   bool SetSemanticsEnabled(bool enabled);
50 
51   bool SetAccessibilityFeatures(int32_t flags);
52 
53   bool BeginFrame(fml::TimePoint frame_time);
54 
55   bool ReportTimings(std::vector<int64_t> timings);
56 
57   bool NotifyIdle(int64_t deadline);
58 
59   bool IsRootIsolateRunning() const;
60 
61   bool DispatchPlatformMessage(fml::RefPtr<PlatformMessage> message);
62 
63   bool DispatchPointerDataPacket(const PointerDataPacket& packet);
64 
65  private:
66   struct Locale {
67     Locale(std::string language_code_,
68            std::string country_code_,
69            std::string script_code_,
70            std::string variant_code_);
71 
72     ~Locale();
73 
74     std::string language_code;
75     std::string country_code;
76     std::string script_code;
77     std::string variant_code;
78   };
79 
80   // Stores data about the window to be used at startup
81   // as well as on hot restarts. Data kept here will persist
82   // after hot restart.
83   struct WindowData {
84     WindowData();
85 
86     WindowData(const WindowData& other);
87 
88     ~WindowData();
89 
90     ViewportMetrics viewport_metrics;
91     std::string language_code;
92     std::string country_code;
93     std::string script_code;
94     std::string variant_code;
95     std::vector<std::string> locale_data;
96     std::string user_settings_data = "{}";
97     std::string lifecycle_state;
98     bool semantics_enabled = false;
99     bool assistive_technology_enabled = false;
100     int32_t accessibility_feature_flags_ = 0;
101   };
102 
103   RuntimeDelegate& client_;
104   TaskRunners task_runners_;
105   fml::WeakPtr<IOManager> io_manager_;
106   std::string advisory_script_uri_;
107   std::string advisory_script_entrypoint_;
108   int32_t instance_id_;
109   std::function<void(int64_t)> idle_notification_callback_;
110   WindowData window_data_;
111 
112   RuntimeController(RuntimeDelegate& client,
113                     TaskRunners task_runners,
114                     fml::WeakPtr<IOManager> io_manager,
115                     int32_t instance_id,
116                     std::function<void(int64_t)> idle_notification_callback,
117                     WindowData data);
118 
119   Window* GetWindowIfAvailable();
120 
121   bool FlushRuntimeStateToIsolate();
122 
123   // |WindowClient|
124   std::string DefaultRouteName() override;
125 
126   // |WindowClient|
127   void ScheduleFrame() override;
128 
129   // |WindowClient|
130   void Render(Scene* scene) override;
131 
132   // |WindowClient|
133   void HandlePlatformMessage(fml::RefPtr<PlatformMessage> message) override;
134 
135   // |WindowClient|
136   FontCollection& GetFontCollection() override;
137 
138   // |WindowClient|
139   void SetNeedsReportTimings(bool value) override;
140 
141   FML_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
142 };
143 
144 }  // namespace flutter
145 
146 #endif  // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_
147