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

8
#include "flutter/assets/zip_asset_store.h"
9
#include "flutter/lib/ui/window/platform_message.h"
10
#include "flutter/lib/ui/window/viewport_metrics.h"
11
#include "flutter/runtime/runtime_controller.h"
12
#include "flutter/runtime/runtime_delegate.h"
13
#include "flutter/shell/common/rasterizer.h"
14 15
#include "lib/ftl/macros.h"
#include "lib/ftl/memory/weak_ptr.h"
A
Adam Barth 已提交
16
#include "third_party/skia/include/core/SkPicture.h"
17

A
Adam Barth 已提交
18 19 20 21 22
namespace blink {
class DirectoryAssetBundle;
class ZipAssetBundle;
}  // namespace blink

23
namespace shell {
24
class PlatformView;
A
Adam Barth 已提交
25
class Animator;
26
using PointerDataPacket = blink::PointerDataPacket;
27

A
Adam Barth 已提交
28
class Engine : public blink::RuntimeDelegate {
29
 public:
30
  explicit Engine(PlatformView* platform_view);
A
Adam Barth 已提交
31

32 33
  ~Engine() override;

34
  ftl::WeakPtr<Engine> GetWeakPtr();
35

36
  static void Init();
37

38 39 40 41 42 43 44 45 46 47 48 49 50 51
  void RunBundle(const std::string& bundle_path);

  // Uses the given snapshot instead of looking inside the bundle for the
  // snapshot. If |snapshot_override| is empty, this function looks for the
  // snapshot in the bundle itself.
  void RunBundleAndSnapshot(const std::string& bundle_path,
                            const std::string& snapshot_override);

  // Uses the given source code instead of looking inside the bindle for the
  // source code.
  void RunBundleAndSource(const std::string& bundle_path,
                          const std::string& main,
                          const std::string& packages);

A
Adam Barth 已提交
52
  void BeginFrame(ftl::TimePoint frame_time);
53

54 55
  void RunFromSource(const std::string& main,
                     const std::string& packages,
56
                     const std::string& bundle);
57 58

  Dart_Port GetUIIsolateMainPort();
59

60 61
  std::string GetUIIsolateName();

62 63
  bool UIIsolateHasLivePorts();

64 65
  void OnOutputSurfaceCreated(const ftl::Closure& gpu_continuation);
  void OnOutputSurfaceDestroyed(const ftl::Closure& gpu_continuation);
66
  void SetViewportMetrics(const blink::ViewportMetrics& metrics);
A
Adam Barth 已提交
67
  void DispatchPlatformMessage(ftl::RefPtr<blink::PlatformMessage> message);
68
  void DispatchPointerDataPacket(const PointerDataPacket& packet);
69 70
  void DispatchSemanticsAction(int id, blink::SemanticsAction action);
  void SetSemanticsEnabled(bool enabled);
71

72
 private:
73
  // RuntimeDelegate methods:
74
  void ScheduleFrame() override;
A
Adam Barth 已提交
75
  void Render(std::unique_ptr<flow::LayerTree> layer_tree) override;
76
  void UpdateSemantics(std::vector<blink::SemanticsNode> update) override;
77 78
  void HandlePlatformMessage(
      ftl::RefPtr<blink::PlatformMessage> message) override;
79 80 81
  void DidCreateMainIsolate(Dart_Isolate isolate) override;
  void DidCreateSecondaryIsolate(Dart_Isolate isolate) override;

82 83 84
  void StopAnimator();
  void StartAnimatorIfPossible();

85
  void ConfigureAssetBundle(const std::string& path);
86
  void ConfigureRuntime(const std::string& script_uri);
87

88 89 90 91 92 93
  bool HandleLifecyclePlatformMessage(blink::PlatformMessage* message);
  bool HandleNavigationPlatformMessage(
      ftl::RefPtr<blink::PlatformMessage> message);
  bool HandleLocalizationPlatformMessage(
      ftl::RefPtr<blink::PlatformMessage> message);

A
Adam Barth 已提交
94
  void HandleAssetPlatformMessage(ftl::RefPtr<blink::PlatformMessage> message);
95
  bool GetAssetAsBuffer(const std::string& name, std::vector<uint8_t>* data);
A
Adam Barth 已提交
96

97
  ftl::WeakPtr<PlatformView> platform_view_;
98
  std::unique_ptr<Animator> animator_;
99
  std::unique_ptr<blink::RuntimeController> runtime_;
100
  ftl::RefPtr<blink::PlatformMessage> pending_push_route_message_;
101
  blink::ViewportMetrics viewport_metrics_;
102 103
  std::string language_code_;
  std::string country_code_;
A
Adam Barth 已提交
104
  bool semantics_enabled_ = false;
A
Adam Barth 已提交
105
  // TODO(abarth): Unify these two behind a common interface.
106
  ftl::RefPtr<blink::ZipAssetStore> asset_store_;
A
Adam Barth 已提交
107
  std::unique_ptr<blink::DirectoryAssetBundle> directory_asset_bundle_;
108 109 110
  // TODO(eseidel): This should move into an AnimatorStateMachine.
  bool activity_running_;
  bool have_surface_;
111
  ftl::WeakPtrFactory<Engine> weak_factory_;
112

113
  FTL_DISALLOW_COPY_AND_ASSIGN(Engine);
114 115 116 117
};

}  // namespace shell

118
#endif  // SHELL_COMMON_ENGINE_H_