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

24
namespace flutter {
25
class Scene;
26
class RuntimeDelegate;
27
class View;
28
class Window;
29

30
class RuntimeController final : public WindowClient {
31
 public:
32 33 34 35 36
  RuntimeController(
      RuntimeDelegate& client,
      DartVM* vm,
      fml::RefPtr<const DartSnapshot> isolate_snapshot,
      TaskRunners task_runners,
37
      fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
38
      fml::WeakPtr<IOManager> io_manager,
39 40
      fml::RefPtr<SkiaUnrefQueue> unref_queue,
      fml::WeakPtr<ImageDecoder> image_decoder,
41 42
      std::string advisory_script_uri,
      std::string advisory_script_entrypoint,
43
      const std::function<void(int64_t)>& idle_notification_callback,
44
      const WindowData& data,
45 46
      const fml::closure& isolate_create_callback,
      const fml::closure& isolate_shutdown_callback,
47
      std::shared_ptr<const fml::Mapping> persistent_isolate_data);
48

49
  ~RuntimeController() override;
50

51 52 53
  std::unique_ptr<RuntimeController> Clone() const;

  bool SetViewportMetrics(const ViewportMetrics& metrics);
54

55
  bool SetLocales(const std::vector<std::string>& locale_data);
56

57 58
  bool SetUserSettingsData(const std::string& data);

59 60
  bool SetLifecycleState(const std::string& data);

61 62
  bool SetSemanticsEnabled(bool enabled);

63
  bool SetAccessibilityFeatures(int32_t flags);
64

65
  bool BeginFrame(fml::TimePoint frame_time);
66

67 68
  bool ReportTimings(std::vector<int64_t> timings);

69
  bool NotifyIdle(int64_t deadline);
70

71 72
  bool IsRootIsolateRunning() const;

73
  bool DispatchPlatformMessage(fml::RefPtr<PlatformMessage> message);
74 75 76 77

  bool DispatchPointerDataPacket(const PointerDataPacket& packet);

  bool DispatchSemanticsAction(int32_t id,
78 79
                               SemanticsAction action,
                               std::vector<uint8_t> args);
80

81
  Dart_Port GetMainPort();
82

83
  std::string GetIsolateName();
84

85
  bool HasLivePorts();
86

87
  tonic::DartErrorHandleType GetLastError();
88

89
  std::weak_ptr<DartIsolate> GetRootIsolate();
90

91
  std::pair<bool, uint32_t> GetRootIsolateReturnCode();
92

93
 private:
94 95 96 97
  struct Locale {
    Locale(std::string language_code_,
           std::string country_code_,
           std::string script_code_,
98 99 100
           std::string variant_code_);

    ~Locale();
101 102 103 104 105 106 107

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

108
  RuntimeDelegate& client_;
B
Ben Konyi 已提交
109
  DartVM* const vm_;
110
  fml::RefPtr<const DartSnapshot> isolate_snapshot_;
111
  TaskRunners task_runners_;
112
  fml::WeakPtr<SnapshotDelegate> snapshot_delegate_;
113
  fml::WeakPtr<IOManager> io_manager_;
114
  fml::RefPtr<SkiaUnrefQueue> unref_queue_;
115
  fml::WeakPtr<ImageDecoder> image_decoder_;
116 117
  std::string advisory_script_uri_;
  std::string advisory_script_entrypoint_;
118
  std::function<void(int64_t)> idle_notification_callback_;
119
  WindowData window_data_;
120
  std::weak_ptr<DartIsolate> root_isolate_;
121
  std::pair<bool, uint32_t> root_isolate_return_code_ = {false, 0};
122 123
  const fml::closure isolate_create_callback_;
  const fml::closure isolate_shutdown_callback_;
124 125
  std::shared_ptr<const fml::Mapping> persistent_isolate_data_;

126 127 128 129
  Window* GetWindowIfAvailable();

  bool FlushRuntimeStateToIsolate();

130
  // |WindowClient|
131
  std::string DefaultRouteName() override;
132

133
  // |WindowClient|
134
  void ScheduleFrame() override;
135

136
  // |WindowClient|
137
  void Render(Scene* scene) override;
138

139
  // |WindowClient|
140
  void UpdateSemantics(SemanticsUpdate* update) override;
141

142
  // |WindowClient|
143
  void HandlePlatformMessage(fml::RefPtr<PlatformMessage> message) override;
144

145
  // |WindowClient|
146
  FontCollection& GetFontCollection() override;
147

148
  // |WindowClient|
149 150
  void UpdateIsolateDescription(const std::string isolate_name,
                                int64_t isolate_port) override;
151

152 153 154
  // |WindowClient|
  void SetNeedsReportTimings(bool value) override;

155 156 157
  // |WindowClient|
  std::shared_ptr<const fml::Mapping> GetPersistentIsolateData() override;

158
  FML_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
159 160
};

161
}  // namespace flutter
162

163
#endif  // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_