runtime_controller.h 4.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

10
#include "flutter/common/task_runners.h"
11
#include "flutter/flow/layers/layer_tree.h"
12
#include "flutter/lib/ui/text/font_collection.h"
13
#include "flutter/lib/ui/ui_dart_state.h"
14
#include "flutter/lib/ui/window/pointer_data_packet.h"
15
#include "flutter/lib/ui/window/window.h"
16
#include "flutter/runtime/dart_vm.h"
17
#include "lib/fxl/macros.h"
18 19

namespace blink {
20
class Scene;
21
class RuntimeDelegate;
22
class View;
23
class Window;
24

25
class RuntimeController final : public WindowClient {
26
 public:
27
  RuntimeController(RuntimeDelegate& client,
B
Ben Konyi 已提交
28
                    DartVM* vm,
29
                    fxl::RefPtr<DartSnapshot> isolate_snapshot,
30
                    fxl::RefPtr<DartSnapshot> shared_snapshot,
31 32
                    TaskRunners task_runners,
                    fml::WeakPtr<GrContext> resource_context,
33 34 35
                    fxl::RefPtr<flow::SkiaUnrefQueue> unref_queue,
                    std::string advisory_script_uri,
                    std::string advisory_script_entrypoint);
36

37 38
  ~RuntimeController();

39 40 41
  std::unique_ptr<RuntimeController> Clone() const;

  bool SetViewportMetrics(const ViewportMetrics& metrics);
42

43
  bool SetLocale(const std::string& language_code,
A
Adam Barth 已提交
44
                 const std::string& country_code);
45

46 47 48 49
  bool SetUserSettingsData(const std::string& data);

  bool SetSemanticsEnabled(bool enabled);

50 51
  bool SetAssistiveTechnologyEnabled(bool enabled);

52 53 54
  bool BeginFrame(fxl::TimePoint frame_time);

  bool NotifyIdle(int64_t deadline);
55

56 57
  bool IsRootIsolateRunning() const;

58 59 60 61 62
  bool DispatchPlatformMessage(fxl::RefPtr<PlatformMessage> message);

  bool DispatchPointerDataPacket(const PointerDataPacket& packet);

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

66
  Dart_Port GetMainPort();
67

68
  std::string GetIsolateName();
69

70
  bool HasLivePorts();
71

72
  tonic::DartErrorHandleType GetLastError();
73

74
  fml::WeakPtr<DartIsolate> GetRootIsolate();
75

76
  std::pair<bool, uint32_t> GetRootIsolateReturnCode();
77

78 79 80 81 82 83 84
 private:
  struct WindowData {
    ViewportMetrics viewport_metrics;
    std::string language_code;
    std::string country_code;
    std::string user_settings_data = "{}";
    bool semantics_enabled = false;
85
    bool assistive_technology_enabled = false;
86 87 88
  };

  RuntimeDelegate& client_;
B
Ben Konyi 已提交
89
  DartVM* const vm_;
90
  fxl::RefPtr<DartSnapshot> isolate_snapshot_;
91
  fxl::RefPtr<DartSnapshot> shared_snapshot_;
92 93 94
  TaskRunners task_runners_;
  fml::WeakPtr<GrContext> resource_context_;
  fxl::RefPtr<flow::SkiaUnrefQueue> unref_queue_;
95 96
  std::string advisory_script_uri_;
  std::string advisory_script_entrypoint_;
97 98 99 100 101
  WindowData window_data_;
  fml::WeakPtr<DartIsolate> root_isolate_;
  std::pair<bool, uint32_t> root_isolate_return_code_ = {false, 0};

  RuntimeController(RuntimeDelegate& client,
B
Ben Konyi 已提交
102
                    DartVM* vm,
103
                    fxl::RefPtr<DartSnapshot> isolate_snapshot,
104
                    fxl::RefPtr<DartSnapshot> shared_snapshot,
105 106 107
                    TaskRunners task_runners,
                    fml::WeakPtr<GrContext> resource_context,
                    fxl::RefPtr<flow::SkiaUnrefQueue> unref_queue,
108 109
                    std::string advisory_script_uri,
                    std::string advisory_script_entrypoint,
110 111 112 113 114 115 116
                    WindowData data);

  Window* GetWindowIfAvailable();

  bool FlushRuntimeStateToIsolate();

  // |blink::WindowClient|
117
  std::string DefaultRouteName() override;
118 119

  // |blink::WindowClient|
120
  void ScheduleFrame() override;
121 122

  // |blink::WindowClient|
123
  void Render(Scene* scene) override;
124

125 126
  // |blink::WindowClient|
  void UpdateSemantics(SemanticsUpdate* update) override;
127

128 129
  // |blink::WindowClient|
  void HandlePlatformMessage(fxl::RefPtr<PlatformMessage> message) override;
130

131 132 133
  // |blink::WindowClient|
  FontCollection& GetFontCollection() override;

134
  FXL_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
135 136
};

A
Adam Barth 已提交
137
}  // namespace blink
138

139
#endif  // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_