engine.h 4.7 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/glue/drain_data_pipe_job.h"
10
#include "flutter/lib/ui/window/platform_message.h"
11
#include "flutter/runtime/runtime_controller.h"
12
#include "flutter/runtime/runtime_delegate.h"
13
#include "flutter/services/engine/sky_engine.mojom.h"
14
#include "flutter/shell/common/rasterizer.h"
15 16
#include "lib/ftl/macros.h"
#include "lib/ftl/memory/weak_ptr.h"
17
#include "mojo/public/cpp/application/service_provider_impl.h"
18
#include "mojo/public/cpp/bindings/binding.h"
19
#include "mojo/public/cpp/bindings/binding_set.h"
20
#include "mojo/public/cpp/system/data_pipe.h"
21
#include "mojo/public/cpp/system/handle.h"
22
#include "mojo/public/interfaces/application/service_provider.mojom.h"
23
#include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h"
A
Adam Barth 已提交
24
#include "third_party/skia/include/core/SkPicture.h"
25 26

namespace shell {
27
class PlatformView;
A
Adam Barth 已提交
28
class Animator;
29
using PointerDataPacket = blink::PointerDataPacket;
30

31
class Engine : public sky::SkyEngine, public blink::RuntimeDelegate {
32
 public:
33
  explicit Engine(PlatformView* platform_view);
A
Adam Barth 已提交
34

35 36
  ~Engine() override;

37
  ftl::WeakPtr<Engine> GetWeakPtr();
38

39
  static void Init();
40

A
Adam Barth 已提交
41
  void BeginFrame(ftl::TimePoint frame_time);
42

43 44
  void RunFromSource(const std::string& main,
                     const std::string& packages,
45
                     const std::string& bundle);
46 47

  Dart_Port GetUIIsolateMainPort();
48

49 50
  std::string GetUIIsolateName();

51 52 53
  void ConnectToEngine(mojo::InterfaceRequest<SkyEngine> request);
  void OnOutputSurfaceCreated(const ftl::Closure& gpu_continuation);
  void OnOutputSurfaceDestroyed(const ftl::Closure& gpu_continuation);
54
  void DispatchPointerDataPacket(const PointerDataPacket& packet);
55 56
  void DispatchSemanticsAction(int id, blink::SemanticsAction action);
  void SetSemanticsEnabled(bool enabled);
57

58
 private:
59
  // SkyEngine implementation:
60 61
  void SetServices(sky::ServicesDataPtr services) override;
  void OnViewportMetricsChanged(sky::ViewportMetricsPtr metrics) override;
62
  void OnLocaleChanged(const mojo::String& language_code,
63
                       const mojo::String& country_code) override;
64 65

  void RunFromFile(const mojo::String& main,
66
                   const mojo::String& packages,
67
                   const mojo::String& bundle) override;
68
  void RunFromPrecompiledSnapshot(const mojo::String& bundle_path) override;
69 70 71 72
  void RunFromBundle(const mojo::String& script_uri,
                     const mojo::String& bundle_path) override;
  void RunFromBundleAndSnapshot(const mojo::String& script_uri,
                                const mojo::String& bundle_path,
73
                                const mojo::String& snapshot_path) override;
A
Adam Barth 已提交
74 75
  void PushRoute(const mojo::String& route) override;
  void PopRoute() override;
76
  void OnAppLifecycleStateChanged(sky::AppLifecycleState state) override;
77

78
  // RuntimeDelegate methods:
79
  void ScheduleFrame() override;
A
Adam Barth 已提交
80
  void Render(std::unique_ptr<flow::LayerTree> layer_tree) override;
81
  void UpdateSemantics(std::vector<blink::SemanticsNode> update) override;
82 83 84 85 86
  void DidCreateMainIsolate(Dart_Isolate isolate) override;
  void DidCreateSecondaryIsolate(Dart_Isolate isolate) override;

  void BindToServiceProvider(
      mojo::InterfaceRequest<mojo::ServiceProvider> request);
A
Adam Barth 已提交
87

88
  void RunFromSnapshotStream(const std::string& script_uri,
89
                             mojo::ScopedDataPipeConsumerHandle snapshot);
90

91 92 93
  void StopAnimator();
  void StartAnimatorIfPossible();

94
  void ConfigureAssetBundle(const std::string& path);
95
  void ConfigureRuntime(const std::string& script_uri);
96

97
  ftl::WeakPtr<PlatformView> platform_view_;
98
  std::unique_ptr<Animator> animator_;
99

100
  sky::ServicesDataPtr services_;
101
  mojo::ServiceProviderImpl service_provider_impl_;
A
Adam Barth 已提交
102
  mojo::ServiceProviderPtr incoming_services_;
103 104
  mojo::BindingSet<mojo::ServiceProvider> service_provider_bindings_;

105
  mojo::asset_bundle::AssetBundlePtr root_bundle_;
106
  std::unique_ptr<blink::RuntimeController> runtime_;
107

108 109
  std::unique_ptr<glue::DrainDataPipeJob> snapshot_drainer_;

A
Adam Barth 已提交
110
  std::string initial_route_;
111
  sky::ViewportMetricsPtr viewport_metrics_;
112 113
  std::string language_code_;
  std::string country_code_;
A
Adam Barth 已提交
114
  bool semantics_enabled_ = false;
115
  mojo::Binding<SkyEngine> binding_;
116
  ftl::RefPtr<blink::ZipAssetStore> asset_store_;
117

118 119 120 121
  // TODO(eseidel): This should move into an AnimatorStateMachine.
  bool activity_running_;
  bool have_surface_;

122
  ftl::WeakPtrFactory<Engine> weak_factory_;
123

124
  FTL_DISALLOW_COPY_AND_ASSIGN(Engine);
125 126 127 128
};

}  // namespace shell

129
#endif  // SHELL_COMMON_ENGINE_H_