engine.h 5.2 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
#include "flutter/assets/zip_asset_store.h"
#include "flutter/assets/asset_provider.h"
10
#include "flutter/lib/ui/window/platform_message.h"
11
#include "flutter/lib/ui/window/viewport_metrics.h"
12
#include "flutter/runtime/runtime_controller.h"
13
#include "flutter/runtime/runtime_delegate.h"
14
#include "flutter/shell/common/rasterizer.h"
15 16
#include "lib/fxl/macros.h"
#include "lib/fxl/memory/weak_ptr.h"
A
Adam Barth 已提交
17
#include "third_party/skia/include/core/SkPicture.h"
18

19 20 21 22 23
namespace blink {
class DirectoryAssetBundle;
class ZipAssetBundle;
}  // namespace blink

24
namespace shell {
25 26 27
class PlatformView;
class Animator;
using PointerDataPacket = blink::PointerDataPacket;
28

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

33 34
  ~Engine() override;

35
  fml::WeakPtr<Engine> GetWeakPtr();
36

37
  static void Init(const std::string& bundle_path);
38

39 40 41
  void RunBundle(const std::string& bundle_path,
                 const std::string& entrypoint = main_entrypoint_,
                 bool reuse_runtime_controller = false);
42

43 44 45 46 47
  // Uses the given provider to locate assets.
  void RunBundleWithAssets(fxl::RefPtr<blink::AssetProvider> asset_provider,
                           const std::string& bundle_path,
                           const std::string& entrypoint = main_entrypoint_,
                           bool reuse_runtime_controller = false);
48

49 50 51 52 53 54
  // Uses the given source code instead of looking inside the bundle for the
  // source code.
  void RunBundleAndSource(const std::string& bundle_path,
                          const std::string& main,
                          const std::string& packages,
                          bool reuse_runtime_controller = false);
55

56
  void BeginFrame(fxl::TimePoint frame_time);
57
  void NotifyIdle(int64_t deadline);
58

59 60 61 62
  void RunFromSource(const std::string& main,
                     const std::string& packages,
                     const std::string& bundle);
  void SetAssetBundlePath(const std::string& bundle_path);
63

64
  Dart_Port GetUIIsolateMainPort();
65
  std::string GetUIIsolateName();
66
  bool UIIsolateHasLivePorts();
67 68
  tonic::DartErrorHandleType GetUIIsolateLastError();
  tonic::DartErrorHandleType GetLoadScriptError();
69

70 71
  void OnOutputSurfaceCreated(const fxl::Closure& gpu_continuation);
  void OnOutputSurfaceDestroyed(const fxl::Closure& gpu_continuation);
72
  void SetViewportMetrics(const blink::ViewportMetrics& metrics);
73
  void DispatchPlatformMessage(fxl::RefPtr<blink::PlatformMessage> message);
74
  void DispatchPointerDataPacket(const PointerDataPacket& packet);
75 76 77
  void DispatchSemanticsAction(int id,
                               blink::SemanticsAction action,
                               std::vector<uint8_t> args);
78
  void SetSemanticsEnabled(bool enabled);
79
  void ScheduleFrame(bool regenerate_layer_tree = true) override;
80

81
  void set_rasterizer(fml::WeakPtr<Rasterizer> rasterizer);
82

83 84
 private:
  // RuntimeDelegate methods:
85
  std::string DefaultRouteName() override;
A
Adam Barth 已提交
86
  void Render(std::unique_ptr<flow::LayerTree> layer_tree) override;
Y
Yegor 已提交
87
  void UpdateSemantics(blink::SemanticsNodeUpdates update) override;
88
  void HandlePlatformMessage(
89
      fxl::RefPtr<blink::PlatformMessage> message) override;
90 91
  void DidCreateMainIsolate(Dart_Isolate isolate) override;
  void DidCreateSecondaryIsolate(Dart_Isolate isolate) override;
92

93
  void StopAnimator();
94
  void StartAnimatorIfPossible();
95

96 97 98
  void DoRunBundle(const std::string& script_uri,
                   const std::string& entrypoint,
                   bool reuse_runtime_controller);
99

100 101 102 103 104
  void ConfigureAssetBundle(const std::string& path);
  void ConfigureRuntime(const std::string& script_uri,
                        bool reuse_runtime_controller = false);

  bool HandleLifecyclePlatformMessage(blink::PlatformMessage* message);
105
  bool HandleNavigationPlatformMessage(
106
      fxl::RefPtr<blink::PlatformMessage> message);
107
  bool HandleLocalizationPlatformMessage(blink::PlatformMessage* message);
108
  void HandleSettingsPlatformMessage(blink::PlatformMessage* message);
109

110
  void HandleAssetPlatformMessage(fxl::RefPtr<blink::PlatformMessage> message);
111
  bool GetAssetAsBuffer(const std::string& name, std::vector<uint8_t>* data);
112

113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
  static const std::string main_entrypoint_;

  fxl::RefPtr<blink::AssetProvider> asset_provider_;
  std::weak_ptr<PlatformView> platform_view_;
  std::unique_ptr<Animator> animator_;
  std::unique_ptr<blink::RuntimeController> runtime_;
  tonic::DartErrorHandleType load_script_error_;
  std::string initial_route_;
  blink::ViewportMetrics viewport_metrics_;
  std::string language_code_;
  std::string country_code_;
  std::string user_settings_data_;
  bool semantics_enabled_ = false;
  // TODO(zarah): Remove usage of asset_store_ once app.flx is removed.
  fxl::RefPtr<blink::ZipAssetStore> asset_store_;
  fxl::RefPtr<blink::DirectoryAssetBundle> directory_asset_bundle_;
  // TODO(eseidel): This should move into an AnimatorStateMachine.
  bool activity_running_;
  bool have_surface_;
  fml::WeakPtrFactory<Engine> weak_factory_;
133

134
  FXL_DISALLOW_COPY_AND_ASSIGN(Engine);
135 136 137 138
};

}  // namespace shell

139
#endif  // SHELL_COMMON_ENGINE_H_