runtime_controller.h 5.4 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
                    std::string advisory_script_uri,
39 40
                    std::string advisory_script_entrypoint,
                    fml::closure 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 52 53
  bool SetUserSettingsData(const std::string& data);

  bool SetSemanticsEnabled(bool enabled);

54
  bool SetAccessibilityFeatures(int32_t flags);
55

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

  bool NotifyIdle(int64_t deadline);
59

60 61
  bool IsRootIsolateRunning() const;

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

  bool DispatchPointerDataPacket(const PointerDataPacket& packet);

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

70
  Dart_Port GetMainPort();
71

72
  std::string GetIsolateName();
73

74
  bool HasLivePorts();
75

76
  tonic::DartErrorHandleType GetLastError();
77

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

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

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

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

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

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

    WindowData(const WindowData& other);

    ~WindowData();

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

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

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

  Window* GetWindowIfAvailable();

  bool FlushRuntimeStateToIsolate();

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

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

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

160 161
  // |blink::WindowClient|
  void UpdateSemantics(SemanticsUpdate* update) override;
162

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

166
  // |blink::WindowClient|
167
  FontCollection& GetFontCollection() override;
168

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

173
  FML_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
174 175
};

A
Adam Barth 已提交
176
}  // namespace blink
177

178
#endif  // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_