runtime_controller.h 5.0 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
  struct WindowData {
97 98 99 100 101 102
    WindowData();

    WindowData(const WindowData& other);

    ~WindowData();

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

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

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

  Window* GetWindowIfAvailable();

  bool FlushRuntimeStateToIsolate();

  // |blink::WindowClient|
146
  std::string DefaultRouteName() override;
147 148

  // |blink::WindowClient|
149
  void ScheduleFrame() override;
150 151

  // |blink::WindowClient|
152
  void Render(Scene* scene) override;
153

154 155
  // |blink::WindowClient|
  void UpdateSemantics(SemanticsUpdate* update) override;
156

157
  // |blink::WindowClient|
158
  void HandlePlatformMessage(fml::RefPtr<PlatformMessage> message) override;
159

160 161 162
  // |blink::WindowClient|
  void SetIsolateDebugName(const std::string name) override;

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

166
  FML_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
167 168
};

A
Adam Barth 已提交
169
}  // namespace blink
170

171
#endif  // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_