• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_ENGINE_H_
6 #define FLUTTER_SHELL_PLATFORM_FUCHSIA_ENGINE_H_
7 
8 #include <fuchsia/io/cpp/fidl.h>
9 #include <fuchsia/ui/gfx/cpp/fidl.h>
10 #include <fuchsia/ui/views/cpp/fidl.h>
11 #include <lib/async-loop/cpp/loop.h>
12 #include <lib/sys/cpp/service_directory.h>
13 #include <lib/zx/event.h>
14 
15 #include "flutter/fml/macros.h"
16 #include "flutter/shell/common/shell.h"
17 #include "isolate_configurator.h"
18 #include "thread.h"
19 
20 namespace flutter_runner {
21 
22 // Represents an instance of running Flutter engine along with the threads
23 // that host the same.
24 class Engine final {
25  public:
26   class Delegate {
27    public:
28     virtual void OnEngineTerminate(const Engine* holder) = 0;
29   };
30 
31   Engine(Delegate& delegate,
32          std::string thread_label,
33          std::shared_ptr<sys::ServiceDirectory> svc,
34          flutter::Settings settings,
35          fml::RefPtr<const flutter::DartSnapshot> isolate_snapshot,
36          fml::RefPtr<const flutter::DartSnapshot> shared_snapshot,
37          fuchsia::ui::views::ViewToken view_token,
38          UniqueFDIONS fdio_ns,
39          fidl::InterfaceRequest<fuchsia::io::Directory> directory_request);
40   ~Engine();
41 
42   // Returns the Dart return code for the root isolate if one is present. This
43   // call is thread safe and synchronous. This call must be made infrequently.
44   std::pair<bool, uint32_t> GetEngineReturnCode() const;
45 
46 #if !defined(DART_PRODUCT)
47   void WriteProfileToTrace() const;
48 #endif  // !defined(DART_PRODUCT)
49 
50  private:
51   Delegate& delegate_;
52   const std::string thread_label_;
53   flutter::Settings settings_;
54   std::array<std::unique_ptr<Thread>, 3> threads_;
55   std::unique_ptr<IsolateConfigurator> isolate_configurator_;
56   std::unique_ptr<flutter::Shell> shell_;
57   zx::event vsync_event_;
58   fml::WeakPtrFactory<Engine> weak_factory_;
59 
60   void OnMainIsolateStart();
61 
62   void OnMainIsolateShutdown();
63 
64   void Terminate();
65 
66   void OnSessionMetricsDidChange(const fuchsia::ui::gfx::Metrics& metrics);
67   void OnSessionSizeChangeHint(float width_change_factor,
68                                float height_change_factor);
69 
70   FML_DISALLOW_COPY_AND_ASSIGN(Engine);
71 };
72 
73 }  // namespace flutter_runner
74 
75 #endif  // FLUTTER_SHELL_PLATFORM_FUCHSIA_ENGINE_H_
76