Flutter Engine
The Flutter Engine
engine.h
Go to the documentation of this file.
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_FLUTTER_ENGINE_H_
6#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_ENGINE_H_
7
8#include <optional>
9
10#include <fuchsia/intl/cpp/fidl.h>
11#include <fuchsia/io/cpp/fidl.h>
12#include <fuchsia/memorypressure/cpp/fidl.h>
13#include <fuchsia/ui/composition/cpp/fidl.h>
14#include <fuchsia/ui/views/cpp/fidl.h>
15#include <lib/async-loop/cpp/loop.h>
16#include <lib/sys/cpp/service_directory.h>
17
18#include "flutter/flow/embedded_views.h"
19#include "flutter/flow/surface.h"
20#include "flutter/fml/macros.h"
21#include "flutter/shell/common/shell.h"
22#include "flutter/shell/common/thread_host.h"
23#include "flutter/shell/platform/fuchsia/flutter/accessibility_bridge.h"
24
26#include "flatland_connection.h"
29#include "surface_producer.h"
30
31namespace flutter_runner {
32
33namespace testing {
34class EngineTest;
35}
36
37// Represents an instance of running Flutter engine along with the threads
38// that host the same.
39class Engine final : public fuchsia::memorypressure::Watcher {
40 public:
41 class Delegate {
42 public:
43 virtual void OnEngineTerminate(const Engine* holder) = 0;
44 };
45
47 const std::string& name_prefix,
48 const std::shared_ptr<sys::ServiceDirectory>& runner_services = nullptr);
49
50 Engine(Delegate& delegate,
51 std::string thread_label,
52 std::shared_ptr<sys::ServiceDirectory> svc,
53 std::shared_ptr<sys::ServiceDirectory> runner_services,
55 fuchsia::ui::views::ViewCreationToken view_creation_token,
56 std::pair<fuchsia::ui::views::ViewRefControl,
57 fuchsia::ui::views::ViewRef> view_ref_pair,
58 UniqueFDIONS fdio_ns,
59 fidl::InterfaceRequest<fuchsia::io::Directory> directory_request,
61 const std::vector<std::string>& dart_entrypoint_args);
62
63 ~Engine();
64
65 // Returns the Dart return code for the root isolate if one is present. This
66 // call is thread safe and synchronous. This call must be made infrequently.
67 std::optional<uint32_t> GetEngineReturnCode() const;
68
69#if !defined(DART_PRODUCT)
70 void WriteProfileToTrace() const;
71#endif // !defined(DART_PRODUCT)
72
73 private:
74 void Initialize(
75 std::pair<fuchsia::ui::views::ViewRefControl, fuchsia::ui::views::ViewRef>
76 view_ref_pair,
77 std::shared_ptr<sys::ServiceDirectory> svc,
78 std::shared_ptr<sys::ServiceDirectory> runner_services,
80 UniqueFDIONS fdio_ns,
81 fidl::InterfaceRequest<fuchsia::io::Directory> directory_request,
83 const std::vector<std::string>& dart_entrypoint_args);
84
85 static void WarmupSkps(
86 fml::BasicTaskRunner* concurrent_task_runner,
87 fml::BasicTaskRunner* raster_task_runner,
88 std::shared_ptr<SurfaceProducer> surface_producer,
90 std::shared_ptr<flutter::AssetManager> asset_manager,
91 std::optional<const std::vector<std::string>> skp_names,
92 std::optional<std::function<void(uint32_t)>> completion_callback,
93 bool synchronous = false);
94
95 void OnMainIsolateStart();
96
97 void OnMainIsolateShutdown();
98
99 void Terminate();
100
101 void DebugWireframeSettingsChanged(bool enabled);
102 void CreateView(int64_t view_id,
103 ViewCallback on_view_created,
104 ViewCreatedCallback on_view_bound,
105 bool hit_testable,
106 bool focusable);
107 void UpdateView(int64_t view_id,
108 SkRect occlusion_hint,
109 bool hit_testable,
110 bool focusable);
111 void DestroyView(int64_t view_id, ViewIdCallback on_view_unbound);
112
113 // |fuchsia::memorypressure::Watcher|
114 void OnLevelChanged(fuchsia::memorypressure::Level level,
115 fuchsia::memorypressure::Watcher::OnLevelChangedCallback
116 callback) override;
117
118 std::shared_ptr<flutter::ExternalViewEmbedder> GetExternalViewEmbedder();
119
120 std::unique_ptr<flutter::Surface> CreateSurface();
121
122 Delegate& delegate_;
123
124 const std::string thread_label_;
125 flutter::ThreadHost thread_host_;
126
127 fuchsia::ui::views::ViewCreationToken view_creation_token_;
128 std::shared_ptr<FlatlandConnection>
129 flatland_connection_; // Must come before surface_producer_
130 std::shared_ptr<SurfaceProducer> surface_producer_;
131 std::shared_ptr<ExternalViewEmbedder> view_embedder_;
132
133 std::unique_ptr<IsolateConfigurator> isolate_configurator_;
134 std::unique_ptr<flutter::Shell> shell_;
135 std::unique_ptr<AccessibilityBridge> accessibility_bridge_;
136
137 fuchsia::intl::PropertyProviderPtr intl_property_provider_;
138
139 fuchsia::memorypressure::ProviderPtr memory_pressure_provider_;
140 fidl::Binding<fuchsia::memorypressure::Watcher>
141 memory_pressure_watcher_binding_;
142 // We need to track the latest memory pressure level to determine
143 // the direction of change when a new level is provided.
144 fuchsia::memorypressure::Level latest_memory_pressure_level_;
145
146 bool intercept_all_input_ = false;
147
148 fml::WeakPtrFactory<Engine> weak_factory_;
150
152};
153
154} // namespace flutter_runner
155
156#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_ENGINE_H_
virtual void OnEngineTerminate(const Engine *holder)=0
static flutter::ThreadHost CreateThreadHost(const std::string &name_prefix, const std::shared_ptr< sys::ServiceDirectory > &runner_services=nullptr)
Definition: engine.cc:136
void WriteProfileToTrace() const
Definition: engine.cc:807
friend class testing::EngineTest
Definition: engine.h:149
Engine(Delegate &delegate, std::string thread_label, std::shared_ptr< sys::ServiceDirectory > svc, std::shared_ptr< sys::ServiceDirectory > runner_services, flutter::Settings settings, fuchsia::ui::views::ViewCreationToken view_creation_token, std::pair< fuchsia::ui::views::ViewRefControl, fuchsia::ui::views::ViewRef > view_ref_pair, UniqueFDIONS fdio_ns, fidl::InterfaceRequest< fuchsia::io::Directory > directory_request, FlutterRunnerProductConfiguration product_config, const std::vector< std::string > &dart_entrypoint_args)
Definition: engine.cc:202
std::optional< uint32_t > GetEngineReturnCode() const
Definition: engine.cc:709
An interface over the ability to schedule tasks on a TaskRunner.
Definition: task_runner.h:20
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:27
Dart_NativeFunction function
Definition: fuchsia.cc:51
std::function< void()> ViewCallback
std::function< void(fuchsia::ui::composition::ContentId)> ViewIdCallback
std::function< void(fuchsia::ui::composition::ContentId, fuchsia::ui::composition::ChildViewWatcherHandle child_view_watcher)> ViewCreatedCallback
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: SkSize.h:16
The collection of all the threads used by the engine.
Definition: thread_host.h:21