runtime_controller.h 3.5 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 27
  RuntimeController(RuntimeDelegate& client,
                    const DartVM* vm,
28
                    fxl::RefPtr<DartSnapshot> isolate_snapshot,
29 30 31 32
                    TaskRunners task_runners,
                    fml::WeakPtr<GrContext> resource_context,
                    fxl::RefPtr<flow::SkiaUnrefQueue> unref_queue);

33 34
  ~RuntimeController();

35 36 37
  std::unique_ptr<RuntimeController> Clone() const;

  bool SetViewportMetrics(const ViewportMetrics& metrics);
38

39
  bool SetLocale(const std::string& language_code,
A
Adam Barth 已提交
40
                 const std::string& country_code);
41

42 43 44 45 46 47 48
  bool SetUserSettingsData(const std::string& data);

  bool SetSemanticsEnabled(bool enabled);

  bool BeginFrame(fxl::TimePoint frame_time);

  bool NotifyIdle(int64_t deadline);
49

50 51
  bool IsRootIsolateRunning() const;

52 53 54 55 56
  bool DispatchPlatformMessage(fxl::RefPtr<PlatformMessage> message);

  bool DispatchPointerDataPacket(const PointerDataPacket& packet);

  bool DispatchSemanticsAction(int32_t id,
57 58
                               SemanticsAction action,
                               std::vector<uint8_t> args);
59

60
  Dart_Port GetMainPort();
61

62
  std::string GetIsolateName();
63

64
  bool HasLivePorts();
65

66
  tonic::DartErrorHandleType GetLastError();
67

68
  fml::WeakPtr<DartIsolate> GetRootIsolate();
69

70
  std::pair<bool, uint32_t> GetRootIsolateReturnCode();
71

72 73 74 75 76 77 78 79 80 81 82
 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_;
  const DartVM* vm_;
83
  fxl::RefPtr<DartSnapshot> isolate_snapshot_;
84 85 86 87 88 89 90 91 92
  TaskRunners task_runners_;
  fml::WeakPtr<GrContext> resource_context_;
  fxl::RefPtr<flow::SkiaUnrefQueue> unref_queue_;
  WindowData window_data_;
  fml::WeakPtr<DartIsolate> root_isolate_;
  std::pair<bool, uint32_t> root_isolate_return_code_ = {false, 0};

  RuntimeController(RuntimeDelegate& client,
                    const DartVM* vm,
93
                    fxl::RefPtr<DartSnapshot> isolate_snapshot,
94 95 96 97 98 99 100 101 102 103
                    TaskRunners task_runners,
                    fml::WeakPtr<GrContext> resource_context,
                    fxl::RefPtr<flow::SkiaUnrefQueue> unref_queue,
                    WindowData data);

  Window* GetWindowIfAvailable();

  bool FlushRuntimeStateToIsolate();

  // |blink::WindowClient|
104
  std::string DefaultRouteName() override;
105 106

  // |blink::WindowClient|
107
  void ScheduleFrame() override;
108 109

  // |blink::WindowClient|
110
  void Render(Scene* scene) override;
111

112 113
  // |blink::WindowClient|
  void UpdateSemantics(SemanticsUpdate* update) override;
114

115 116
  // |blink::WindowClient|
  void HandlePlatformMessage(fxl::RefPtr<PlatformMessage> message) override;
117

118
  FXL_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
119 120
};

A
Adam Barth 已提交
121
}  // namespace blink
122

123
#endif  // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_