runtime_controller.h 5.3 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
  RuntimeController(RuntimeDelegate& client,
B
Ben Konyi 已提交
32
                    DartVM* vm,
33 34
                    fml::RefPtr<const DartSnapshot> isolate_snapshot,
                    fml::RefPtr<const DartSnapshot> shared_snapshot,
35
                    TaskRunners task_runners,
36
                    fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
37
                    fml::WeakPtr<IOManager> io_manager,
38
                    std::string advisory_script_uri,
39
                    std::string advisory_script_entrypoint,
40
                    std::function<void(int64_t)> idle_notification_callback);
41

42
  ~RuntimeController() override;
43

44 45 46
  std::unique_ptr<RuntimeController> Clone() const;

  bool SetViewportMetrics(const ViewportMetrics& metrics);
47

48
  bool SetLocales(const std::vector<std::string>& locale_data);
49

50 51
  bool SetUserSettingsData(const std::string& data);

52 53
  bool SetLifecycleState(const std::string& data);

54 55
  bool SetSemanticsEnabled(bool enabled);

56
  bool SetAccessibilityFeatures(int32_t flags);
57

58
  bool BeginFrame(fml::TimePoint frame_time);
59 60

  bool NotifyIdle(int64_t deadline);
61

62 63
  bool IsRootIsolateRunning() const;

64
  bool DispatchPlatformMessage(fml::RefPtr<PlatformMessage> message);
65 66 67 68

  bool DispatchPointerDataPacket(const PointerDataPacket& packet);

  bool DispatchSemanticsAction(int32_t id,
69 70
                               SemanticsAction action,
                               std::vector<uint8_t> args);
71

72
  Dart_Port GetMainPort();
73

74
  std::string GetIsolateName();
75

76
  bool HasLivePorts();
77

78
  tonic::DartErrorHandleType GetLastError();
79

80
  std::weak_ptr<DartIsolate> GetRootIsolate();
81

82
  std::pair<bool, uint32_t> GetRootIsolateReturnCode();
83

84
 private:
85 86 87 88
  struct Locale {
    Locale(std::string language_code_,
           std::string country_code_,
           std::string script_code_,
89 90 91
           std::string variant_code_);

    ~Locale();
92 93 94 95 96 97 98

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

99 100 101
  // Stores data about the window to be used at startup
  // as well as on hot restarts. Data kept here will persist
  // after hot restart.
102
  struct WindowData {
103 104 105 106 107 108
    WindowData();

    WindowData(const WindowData& other);

    ~WindowData();

109 110 111
    ViewportMetrics viewport_metrics;
    std::string language_code;
    std::string country_code;
112 113
    std::string script_code;
    std::string variant_code;
114
    std::vector<std::string> locale_data;
115
    std::string user_settings_data = "{}";
116
    std::string lifecycle_state;
117
    bool semantics_enabled = false;
118
    bool assistive_technology_enabled = false;
119
    int32_t accessibility_feature_flags_ = 0;
120 121 122
  };

  RuntimeDelegate& client_;
B
Ben Konyi 已提交
123
  DartVM* const vm_;
124 125
  fml::RefPtr<const DartSnapshot> isolate_snapshot_;
  fml::RefPtr<const DartSnapshot> shared_snapshot_;
126
  TaskRunners task_runners_;
127
  fml::WeakPtr<SnapshotDelegate> snapshot_delegate_;
128
  fml::WeakPtr<IOManager> io_manager_;
129 130
  std::string advisory_script_uri_;
  std::string advisory_script_entrypoint_;
131
  std::function<void(int64_t)> idle_notification_callback_;
132
  WindowData window_data_;
133
  std::weak_ptr<DartIsolate> root_isolate_;
134 135 136
  std::pair<bool, uint32_t> root_isolate_return_code_ = {false, 0};

  RuntimeController(RuntimeDelegate& client,
B
Ben Konyi 已提交
137
                    DartVM* vm,
138 139
                    fml::RefPtr<const DartSnapshot> isolate_snapshot,
                    fml::RefPtr<const DartSnapshot> shared_snapshot,
140
                    TaskRunners task_runners,
141
                    fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
142
                    fml::WeakPtr<IOManager> io_manager,
143 144
                    std::string advisory_script_uri,
                    std::string advisory_script_entrypoint,
145
                    std::function<void(int64_t)> idle_notification_callback,
146 147 148 149 150 151
                    WindowData data);

  Window* GetWindowIfAvailable();

  bool FlushRuntimeStateToIsolate();

152
  // |WindowClient|
153
  std::string DefaultRouteName() override;
154

155
  // |WindowClient|
156
  void ScheduleFrame() override;
157

158
  // |WindowClient|
159
  void Render(Scene* scene) override;
160

161
  // |WindowClient|
162
  void UpdateSemantics(SemanticsUpdate* update) override;
163

164
  // |WindowClient|
165
  void HandlePlatformMessage(fml::RefPtr<PlatformMessage> message) override;
166

167
  // |WindowClient|
168
  FontCollection& GetFontCollection() override;
169

170
  // |WindowClient|
171 172
  void UpdateIsolateDescription(const std::string isolate_name,
                                int64_t isolate_port) override;
173

174
  FML_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
175 176
};

177
}  // namespace flutter
178

179
#endif  // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_