engine.h 4.6 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 SHELL_COMMON_ENGINE_H_
#define SHELL_COMMON_ENGINE_H_
7

8 9 10 11 12 13
#include <memory>
#include <string>

#include "flutter/assets/asset_manager.h"
#include "flutter/common/task_runners.h"
#include "flutter/lib/ui/semantics/semantics_node.h"
14
#include "flutter/lib/ui/window/platform_message.h"
15
#include "flutter/lib/ui/window/viewport_metrics.h"
16
#include "flutter/runtime/dart_vm.h"
17
#include "flutter/runtime/runtime_controller.h"
18
#include "flutter/runtime/runtime_delegate.h"
19
#include "flutter/shell/common/animator.h"
20
#include "flutter/shell/common/rasterizer.h"
21
#include "flutter/shell/common/run_configuration.h"
22 23
#include "lib/fxl/macros.h"
#include "lib/fxl/memory/weak_ptr.h"
A
Adam Barth 已提交
24
#include "third_party/skia/include/core/SkPicture.h"
25 26 27

namespace shell {

28
class Engine final : public blink::RuntimeDelegate {
29
 public:
30 31 32 33 34 35 36 37 38 39 40 41
  class Delegate {
   public:
    virtual void OnEngineUpdateSemantics(
        const Engine& engine,
        blink::SemanticsNodeUpdates update) = 0;

    virtual void OnEngineHandlePlatformMessage(
        const Engine& engine,
        fxl::RefPtr<blink::PlatformMessage> message) = 0;
  };

  Engine(Delegate& delegate,
42
         const blink::DartVM& vm,
43
         fxl::RefPtr<blink::DartSnapshot> isolate_snapshot,
44
         fxl::RefPtr<blink::DartSnapshot> shared_snapshot,
45 46 47 48 49
         blink::TaskRunners task_runners,
         blink::Settings settings,
         std::unique_ptr<Animator> animator,
         fml::WeakPtr<GrContext> resource_context,
         fxl::RefPtr<flow::SkiaUnrefQueue> unref_queue);
A
Adam Barth 已提交
50

51 52
  ~Engine() override;

53
  fml::WeakPtr<Engine> GetWeakPtr() const;
54

55 56
  FXL_WARN_UNUSED_RESULT
  bool Run(RunConfiguration configuration);
57

58 59 60 61 62 63
  // Used to "cold reload" a running application where the shell (along with the
  // platform view and its rasterizer bindings) remains the same but the root
  // isolate is torn down and restarted with the new configuration. Only used in
  // the development workflow.
  FXL_WARN_UNUSED_RESULT
  bool Restart(RunConfiguration configuration);
64

65
  bool UpdateAssetManager(fml::RefPtr<blink::AssetManager> asset_manager);
66

67
  void BeginFrame(fxl::TimePoint frame_time);
68

69
  void NotifyIdle(int64_t deadline);
70

71
  Dart_Port GetUIIsolateMainPort();
72

73
  std::string GetUIIsolateName();
74

75
  bool UIIsolateHasLivePorts();
76

77
  tonic::DartErrorHandleType GetUIIsolateLastError();
78

79
  tonic::DartErrorHandleType GetLoadScriptError();
80

81 82 83 84 85 86
  std::pair<bool, uint32_t> GetUIIsolateReturnCode();

  void OnOutputSurfaceCreated();

  void OnOutputSurfaceDestroyed();

87
  void SetViewportMetrics(const blink::ViewportMetrics& metrics);
88

89
  void DispatchPlatformMessage(fxl::RefPtr<blink::PlatformMessage> message);
90 91 92

  void DispatchPointerDataPacket(const blink::PointerDataPacket& packet);

93 94 95
  void DispatchSemanticsAction(int id,
                               blink::SemanticsAction action,
                               std::vector<uint8_t> args);
96

97
  void SetSemanticsEnabled(bool enabled);
98

99
  void ScheduleFrame(bool regenerate_layer_tree = true) override;
100

101
 private:
102 103 104 105 106 107 108
  Engine::Delegate& delegate_;
  const blink::Settings settings_;
  std::unique_ptr<Animator> animator_;
  std::unique_ptr<blink::RuntimeController> runtime_controller_;
  tonic::DartErrorHandleType load_script_error_;
  std::string initial_route_;
  blink::ViewportMetrics viewport_metrics_;
109
  fml::RefPtr<blink::AssetManager> asset_manager_;
110 111 112 113 114
  bool activity_running_;
  bool have_surface_;
  fml::WeakPtrFactory<Engine> weak_factory_;

  // |blink::RuntimeDelegate|
115
  std::string DefaultRouteName() override;
116 117

  // |blink::RuntimeDelegate|
A
Adam Barth 已提交
118
  void Render(std::unique_ptr<flow::LayerTree> layer_tree) override;
119 120

  // |blink::RuntimeDelegate|
Y
Yegor 已提交
121
  void UpdateSemantics(blink::SemanticsNodeUpdates update) override;
122 123

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

127
  void StopAnimator();
128

129
  void StartAnimatorIfPossible();
130 131

  bool HandleLifecyclePlatformMessage(blink::PlatformMessage* message);
132

133
  bool HandleNavigationPlatformMessage(
134
      fxl::RefPtr<blink::PlatformMessage> message);
135

136
  bool HandleLocalizationPlatformMessage(blink::PlatformMessage* message);
137

138
  void HandleSettingsPlatformMessage(blink::PlatformMessage* message);
139

140
  void HandleAssetPlatformMessage(fxl::RefPtr<blink::PlatformMessage> message);
141

142
  bool GetAssetAsBuffer(const std::string& name, std::vector<uint8_t>* data);
143

144
  bool PrepareAndLaunchIsolate(RunConfiguration configuration);
145

146
  FXL_DISALLOW_COPY_AND_ASSIGN(Engine);
147 148 149 150
};

}  // namespace shell

151
#endif  // SHELL_COMMON_ENGINE_H_