runtime_controller.h 5.7 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 36 37 38 39 40 41 42 43 44
  RuntimeController(
      RuntimeDelegate& client,
      DartVM* vm,
      fml::RefPtr<const DartSnapshot> isolate_snapshot,
      fml::RefPtr<const DartSnapshot> shared_snapshot,
      TaskRunners task_runners,
      fml::WeakPtr<IOManager> io_manager,
      fml::WeakPtr<ImageDecoder> iamge_decoder,
      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);
45

46
  ~RuntimeController() override;
47

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

  bool SetViewportMetrics(const ViewportMetrics& metrics);
51

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

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

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

58 59
  bool SetSemanticsEnabled(bool enabled);

60
  bool SetAccessibilityFeatures(int32_t flags);
61

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

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

66
  bool NotifyIdle(int64_t deadline);
67

68 69
  bool IsRootIsolateRunning() const;

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

  bool DispatchPointerDataPacket(const PointerDataPacket& packet);

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

78
  Dart_Port GetMainPort();
79

80
  std::string GetIsolateName();
81

82
  bool HasLivePorts();
83

84
  tonic::DartErrorHandleType GetLastError();
85

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

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

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

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

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

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

    WindowData(const WindowData& other);

    ~WindowData();

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

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

  RuntimeController(
      RuntimeDelegate& client,
      DartVM* vm,
      fml::RefPtr<const DartSnapshot> isolate_snapshot,
      fml::RefPtr<const DartSnapshot> shared_snapshot,
      TaskRunners task_runners,
      fml::WeakPtr<IOManager> io_manager,
      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);
160 161 162 163 164

  Window* GetWindowIfAvailable();

  bool FlushRuntimeStateToIsolate();

165
  // |WindowClient|
166
  std::string DefaultRouteName() override;
167

168
  // |WindowClient|
169
  void ScheduleFrame() override;
170

171
  // |WindowClient|
172
  void Render(Scene* scene) override;
173

174
  // |WindowClient|
175
  void UpdateSemantics(SemanticsUpdate* update) override;
176

177
  // |WindowClient|
178
  void HandlePlatformMessage(fml::RefPtr<PlatformMessage> message) override;
179

180
  // |WindowClient|
181
  FontCollection& GetFontCollection() override;
182

183
  // |WindowClient|
184 185
  void UpdateIsolateDescription(const std::string isolate_name,
                                int64_t isolate_port) override;
186

187 188 189
  // |WindowClient|
  void SetNeedsReportTimings(bool value) override;

190 191 192
  // |WindowClient|
  std::shared_ptr<const fml::Mapping> GetPersistentIsolateData() override;

193
  FML_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
194 195
};

196
}  // namespace flutter
197

198
#endif  // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_