runtime_controller.h 4.8 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 35
                    TaskRunners task_runners,
                    fml::WeakPtr<GrContext> resource_context,
36
                    fml::RefPtr<flow::SkiaUnrefQueue> unref_queue,
37 38
                    std::string advisory_script_uri,
                    std::string advisory_script_entrypoint);
39

40 41
  ~RuntimeController();

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

  bool SetViewportMetrics(const ViewportMetrics& metrics);
45

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

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

  bool SetSemanticsEnabled(bool enabled);

52
  bool SetAccessibilityFeatures(int32_t flags);
53

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

  bool NotifyIdle(int64_t deadline);
57

58 59
  bool IsRootIsolateRunning() const;

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

  bool DispatchPointerDataPacket(const PointerDataPacket& packet);

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

68
  Dart_Port GetMainPort();
69

70
  std::string GetIsolateName();
71

72
  bool HasLivePorts();
73

74
  tonic::DartErrorHandleType GetLastError();
75

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

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

80
 private:
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
  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;
  };

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

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

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

  Window* GetWindowIfAvailable();

  bool FlushRuntimeStateToIsolate();

  // |blink::WindowClient|
139
  std::string DefaultRouteName() override;
140 141

  // |blink::WindowClient|
142
  void ScheduleFrame() override;
143 144

  // |blink::WindowClient|
145
  void Render(Scene* scene) override;
146

147 148
  // |blink::WindowClient|
  void UpdateSemantics(SemanticsUpdate* update) override;
149

150
  // |blink::WindowClient|
151
  void HandlePlatformMessage(fml::RefPtr<PlatformMessage> message) override;
152

153 154 155
  // |blink::WindowClient|
  FontCollection& GetFontCollection() override;

156
  FML_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
157 158
};

A
Adam Barth 已提交
159
}  // namespace blink
160

161
#endif  // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_