runtime_controller.h 5.1 KB
Newer Older
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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 42
  ~RuntimeController();

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 86 87 88 89 90 91 92 93 94 95 96 97
  struct Locale {
    Locale(std::string language_code_,
           std::string country_code_,
           std::string script_code_,
           std::string variant_code_)
        : language_code(language_code_),
          country_code(country_code_),
          script_code(script_code_),
          variant_code(variant_code_) {}

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

98 99 100 101
  struct WindowData {
    ViewportMetrics viewport_metrics;
    std::string language_code;
    std::string country_code;
102 103
    std::string script_code;
    std::string variant_code;
104
    std::vector<std::string> locale_data;
105 106
    std::string user_settings_data = "{}";
    bool semantics_enabled = false;
107
    bool assistive_technology_enabled = false;
108
    int32_t accessibility_feature_flags_ = 0;
109 110 111
  };

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

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

  Window* GetWindowIfAvailable();

  bool FlushRuntimeStateToIsolate();

  // |blink::WindowClient|
142
  std::string DefaultRouteName() override;
143 144

  // |blink::WindowClient|
145
  void ScheduleFrame() override;
146 147

  // |blink::WindowClient|
148
  void Render(Scene* scene) override;
149

150 151
  // |blink::WindowClient|
  void UpdateSemantics(SemanticsUpdate* update) override;
152

153
  // |blink::WindowClient|
154
  void HandlePlatformMessage(fml::RefPtr<PlatformMessage> message) override;
155

156 157 158
  // |blink::WindowClient|
  void SetIsolateDebugName(const std::string name) override;

159 160 161
  // |blink::WindowClient|
  FontCollection& GetFontCollection() override;

162
  FML_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
163 164
};

A
Adam Barth 已提交
165
}  // namespace blink
166

167
#endif  // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_