runtime_controller.h 3.9 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/ui_dart_state.h"
13
#include "flutter/lib/ui/window/pointer_data_packet.h"
14
#include "flutter/lib/ui/window/window.h"
15
#include "flutter/runtime/dart_vm.h"
16
#include "lib/fxl/macros.h"
17 18

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

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

36 37
  ~RuntimeController();

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

  bool SetViewportMetrics(const ViewportMetrics& metrics);
41

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

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

  bool SetSemanticsEnabled(bool enabled);

  bool BeginFrame(fxl::TimePoint frame_time);

  bool NotifyIdle(int64_t deadline);
52

53 54
  bool IsRootIsolateRunning() const;

55 56 57 58 59
  bool DispatchPlatformMessage(fxl::RefPtr<PlatformMessage> message);

  bool DispatchPointerDataPacket(const PointerDataPacket& packet);

  bool DispatchSemanticsAction(int32_t id,
60 61
                               SemanticsAction action,
                               std::vector<uint8_t> args);
62

63
  Dart_Port GetMainPort();
64

65
  std::string GetIsolateName();
66

67
  bool HasLivePorts();
68

69
  tonic::DartErrorHandleType GetLastError();
70

71
  fml::WeakPtr<DartIsolate> GetRootIsolate();
72

73
  std::pair<bool, uint32_t> GetRootIsolateReturnCode();
74

75 76 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;
  };

  RuntimeDelegate& client_;
85
  const DartVM* vm_;
86
  fxl::RefPtr<DartSnapshot> isolate_snapshot_;
87
  fxl::RefPtr<DartSnapshot> shared_snapshot_;
88 89 90
  TaskRunners task_runners_;
  fml::WeakPtr<GrContext> resource_context_;
  fxl::RefPtr<flow::SkiaUnrefQueue> unref_queue_;
91 92
  std::string advisory_script_uri_;
  std::string advisory_script_entrypoint_;
93 94 95 96 97
  WindowData window_data_;
  fml::WeakPtr<DartIsolate> root_isolate_;
  std::pair<bool, uint32_t> root_isolate_return_code_ = {false, 0};

  RuntimeController(RuntimeDelegate& client,
98
                    const DartVM* vm,
99
                    fxl::RefPtr<DartSnapshot> isolate_snapshot,
100
                    fxl::RefPtr<DartSnapshot> shared_snapshot,
101 102 103
                    TaskRunners task_runners,
                    fml::WeakPtr<GrContext> resource_context,
                    fxl::RefPtr<flow::SkiaUnrefQueue> unref_queue,
104 105
                    std::string advisory_script_uri,
                    std::string advisory_script_entrypoint,
106 107 108 109 110 111 112
                    WindowData data);

  Window* GetWindowIfAvailable();

  bool FlushRuntimeStateToIsolate();

  // |blink::WindowClient|
113
  std::string DefaultRouteName() override;
114 115

  // |blink::WindowClient|
116
  void ScheduleFrame() override;
117 118

  // |blink::WindowClient|
119
  void Render(Scene* scene) override;
120

121 122
  // |blink::WindowClient|
  void UpdateSemantics(SemanticsUpdate* update) override;
123

124 125
  // |blink::WindowClient|
  void HandlePlatformMessage(fxl::RefPtr<PlatformMessage> message) override;
126

127
  FXL_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
128 129
};

A
Adam Barth 已提交
130
}  // namespace blink
131

132
#endif  // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_