runtime_controller.h 5.9 KB
Newer Older
M
Michael Goderbauer 已提交
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_
#define FLUTTER_RUNTIME_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/ui_dart_state.h"
17
#include "flutter/lib/ui/window/pointer_data_packet.h"
18
#include "flutter/lib/ui/window/window.h"
19
#include "flutter/runtime/dart_vm.h"
20 21
#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
22

23
namespace flutter {
24
class Scene;
25
class RuntimeDelegate;
26
class View;
27
class Window;
28

29
class RuntimeController final : public WindowClient {
30
 public:
31 32 33 34 35
  RuntimeController(
      RuntimeDelegate& client,
      DartVM* vm,
      fml::RefPtr<const DartSnapshot> isolate_snapshot,
      TaskRunners task_runners,
36
      fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
37
      fml::WeakPtr<IOManager> io_manager,
38 39
      fml::RefPtr<SkiaUnrefQueue> unref_queue,
      fml::WeakPtr<ImageDecoder> image_decoder,
40 41 42 43 44 45
      std::string advisory_script_uri,
      std::string advisory_script_entrypoint,
      std::function<void(int64_t)> idle_notification_callback,
      fml::closure isolate_create_callback,
      fml::closure isolate_shutdown_callback,
      std::shared_ptr<const fml::Mapping> persistent_isolate_data);
46

47
  ~RuntimeController() override;
48

49 50 51
  std::unique_ptr<RuntimeController> Clone() const;

  bool SetViewportMetrics(const ViewportMetrics& metrics);
52

53
  bool SetLocales(const std::vector<std::string>& locale_data);
54

55 56
  bool SetUserSettingsData(const std::string& data);

57 58
  bool SetLifecycleState(const std::string& data);

59 60
  bool SetSemanticsEnabled(bool enabled);

61
  bool SetAccessibilityFeatures(int32_t flags);
62

63
  bool BeginFrame(fml::TimePoint frame_time);
64

65 66
  bool ReportTimings(std::vector<int64_t> timings);

67
  bool NotifyIdle(int64_t deadline);
68

69 70
  bool IsRootIsolateRunning() const;

71
  bool DispatchPlatformMessage(fml::RefPtr<PlatformMessage> message);
72 73 74 75

  bool DispatchPointerDataPacket(const PointerDataPacket& packet);

  bool DispatchSemanticsAction(int32_t id,
76 77
                               SemanticsAction action,
                               std::vector<uint8_t> args);
78

79
  Dart_Port GetMainPort();
80

81
  std::string GetIsolateName();
82

83
  bool HasLivePorts();
84

85
  tonic::DartErrorHandleType GetLastError();
86

87
  std::weak_ptr<DartIsolate> GetRootIsolate();
88

89
  std::pair<bool, uint32_t> GetRootIsolateReturnCode();
90

91
 private:
92 93 94 95
  struct Locale {
    Locale(std::string language_code_,
           std::string country_code_,
           std::string script_code_,
96 97 98
           std::string variant_code_);

    ~Locale();
99 100 101 102 103 104 105

    std::string language_code;
    std::string country_code;
    std::string script_code;
    std::string variant_code;
  };

106 107 108
  // Stores data about the window to be used at startup
  // as well as on hot restarts. Data kept here will persist
  // after hot restart.
109
  struct WindowData {
110 111 112 113 114 115
    WindowData();

    WindowData(const WindowData& other);

    ~WindowData();

116 117 118
    ViewportMetrics viewport_metrics;
    std::string language_code;
    std::string country_code;
119 120
    std::string script_code;
    std::string variant_code;
121
    std::vector<std::string> locale_data;
122
    std::string user_settings_data = "{}";
C
chunhtai 已提交
123
    std::string lifecycle_state = "AppLifecycleState.detached";
124
    bool semantics_enabled = false;
125
    bool assistive_technology_enabled = false;
126
    int32_t accessibility_feature_flags_ = 0;
127 128 129
  };

  RuntimeDelegate& client_;
B
Ben Konyi 已提交
130
  DartVM* const vm_;
131
  fml::RefPtr<const DartSnapshot> isolate_snapshot_;
132
  TaskRunners task_runners_;
133
  fml::WeakPtr<SnapshotDelegate> snapshot_delegate_;
134
  fml::WeakPtr<IOManager> io_manager_;
135
  fml::RefPtr<SkiaUnrefQueue> unref_queue_;
136
  fml::WeakPtr<ImageDecoder> image_decoder_;
137 138
  std::string advisory_script_uri_;
  std::string advisory_script_entrypoint_;
139
  std::function<void(int64_t)> idle_notification_callback_;
140
  WindowData window_data_;
141
  std::weak_ptr<DartIsolate> root_isolate_;
142
  std::pair<bool, uint32_t> root_isolate_return_code_ = {false, 0};
143 144
  const fml::closure isolate_create_callback_;
  const fml::closure isolate_shutdown_callback_;
145 146 147 148 149 150 151
  std::shared_ptr<const fml::Mapping> persistent_isolate_data_;

  RuntimeController(
      RuntimeDelegate& client,
      DartVM* vm,
      fml::RefPtr<const DartSnapshot> isolate_snapshot,
      TaskRunners task_runners,
152
      fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
153
      fml::WeakPtr<IOManager> io_manager,
154
      fml::RefPtr<SkiaUnrefQueue> unref_queue,
155 156 157 158 159 160 161 162
      fml::WeakPtr<ImageDecoder> image_decoder,
      std::string advisory_script_uri,
      std::string advisory_script_entrypoint,
      std::function<void(int64_t)> idle_notification_callback,
      WindowData data,
      fml::closure isolate_create_callback,
      fml::closure isolate_shutdown_callback,
      std::shared_ptr<const fml::Mapping> persistent_isolate_data);
163 164 165 166 167

  Window* GetWindowIfAvailable();

  bool FlushRuntimeStateToIsolate();

168
  // |WindowClient|
169
  std::string DefaultRouteName() override;
170

171
  // |WindowClient|
172
  void ScheduleFrame() override;
173

174
  // |WindowClient|
175
  void Render(Scene* scene) override;
176

177
  // |WindowClient|
178
  void UpdateSemantics(SemanticsUpdate* update) override;
179

180
  // |WindowClient|
181
  void HandlePlatformMessage(fml::RefPtr<PlatformMessage> message) override;
182

183
  // |WindowClient|
184
  FontCollection& GetFontCollection() override;
185

186
  // |WindowClient|
187 188
  void UpdateIsolateDescription(const std::string isolate_name,
                                int64_t isolate_port) override;
189

190 191 192
  // |WindowClient|
  void SetNeedsReportTimings(bool value) override;

193 194 195
  // |WindowClient|
  std::shared_ptr<const fml::Mapping> GetPersistentIsolateData() override;

196
  FML_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
197 198
};

199
}  // namespace flutter
200

201
#endif  // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_