runtime_controller.h 5.2 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/text/font_collection.h"
15
#include "flutter/lib/ui/ui_dart_state.h"
16
#include "flutter/lib/ui/window/pointer_data_packet.h"
17
#include "flutter/lib/ui/window/window.h"
18
#include "flutter/runtime/dart_vm.h"
19 20
#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
21 22

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

28
class RuntimeController final : public WindowClient {
29
 public:
30
  RuntimeController(RuntimeDelegate& client,
B
Ben Konyi 已提交
31
                    DartVM* vm,
32 33
                    fml::RefPtr<DartSnapshot> isolate_snapshot,
                    fml::RefPtr<DartSnapshot> shared_snapshot,
34
                    TaskRunners task_runners,
35
                    fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
36
                    fml::WeakPtr<GrContext> resource_context,
37
                    fml::RefPtr<flow::SkiaUnrefQueue> unref_queue,
38 39
                    std::string advisory_script_uri,
                    std::string advisory_script_entrypoint);
40

41
  ~RuntimeController() override;
42

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

  bool SetViewportMetrics(const ViewportMetrics& metrics);
46

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

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

  bool SetSemanticsEnabled(bool enabled);

53
  bool SetAccessibilityFeatures(int32_t flags);
54

55
  bool BeginFrame(fml::TimePoint frame_time);
56 57

  bool NotifyIdle(int64_t deadline);
58

59 60
  bool IsRootIsolateRunning() const;

61
  bool DispatchPlatformMessage(fml::RefPtr<PlatformMessage> message);
62 63 64 65

  bool DispatchPointerDataPacket(const PointerDataPacket& packet);

  bool DispatchSemanticsAction(int32_t id,
66 67
                               SemanticsAction action,
                               std::vector<uint8_t> args);
68

69
  Dart_Port GetMainPort();
70

71
  std::string GetIsolateName();
72

73
  bool HasLivePorts();
74

75
  tonic::DartErrorHandleType GetLastError();
76

77
  std::weak_ptr<DartIsolate> GetRootIsolate();
78

79
  std::pair<bool, uint32_t> GetRootIsolateReturnCode();
80

81
 private:
82 83 84 85
  struct Locale {
    Locale(std::string language_code_,
           std::string country_code_,
           std::string script_code_,
86 87 88
           std::string variant_code_);

    ~Locale();
89 90 91 92 93 94 95

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

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

    WindowData(const WindowData& other);

    ~WindowData();

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

  RuntimeDelegate& client_;
B
Ben Konyi 已提交
119
  DartVM* const vm_;
120 121
  fml::RefPtr<DartSnapshot> isolate_snapshot_;
  fml::RefPtr<DartSnapshot> shared_snapshot_;
122
  TaskRunners task_runners_;
123
  fml::WeakPtr<SnapshotDelegate> snapshot_delegate_;
124
  fml::WeakPtr<GrContext> resource_context_;
125
  fml::RefPtr<flow::SkiaUnrefQueue> unref_queue_;
126 127
  std::string advisory_script_uri_;
  std::string advisory_script_entrypoint_;
128
  WindowData window_data_;
129
  std::weak_ptr<DartIsolate> root_isolate_;
130 131 132
  std::pair<bool, uint32_t> root_isolate_return_code_ = {false, 0};

  RuntimeController(RuntimeDelegate& client,
B
Ben Konyi 已提交
133
                    DartVM* vm,
134 135
                    fml::RefPtr<DartSnapshot> isolate_snapshot,
                    fml::RefPtr<DartSnapshot> shared_snapshot,
136
                    TaskRunners task_runners,
137
                    fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
138
                    fml::WeakPtr<GrContext> resource_context,
139
                    fml::RefPtr<flow::SkiaUnrefQueue> unref_queue,
140 141
                    std::string advisory_script_uri,
                    std::string advisory_script_entrypoint,
142 143 144 145 146 147 148
                    WindowData data);

  Window* GetWindowIfAvailable();

  bool FlushRuntimeStateToIsolate();

  // |blink::WindowClient|
149
  std::string DefaultRouteName() override;
150 151

  // |blink::WindowClient|
152
  void ScheduleFrame() override;
153 154

  // |blink::WindowClient|
155
  void Render(Scene* scene) override;
156

157 158
  // |blink::WindowClient|
  void UpdateSemantics(SemanticsUpdate* update) override;
159

160
  // |blink::WindowClient|
161
  void HandlePlatformMessage(fml::RefPtr<PlatformMessage> message) override;
162

163
  // |blink::WindowClient|
164
  FontCollection& GetFontCollection() override;
165

166
  // |blink::WindowClient|
167 168
  void UpdateIsolateDescription(const std::string isolate_name,
                                int64_t isolate_port) override;
169

170
  FML_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
171 172
};

A
Adam Barth 已提交
173
}  // namespace blink
174

175
#endif  // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_