Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Friends | List of all members
flutter_runner::Engine Class Referencefinal

#include <engine.h>

Inheritance diagram for flutter_runner::Engine:

Classes

class  Delegate
 

Public Member Functions

 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)
 
 ~Engine ()
 
std::optional< uint32_t > GetEngineReturnCode () const
 
void WriteProfileToTrace () const
 

Static Public Member Functions

static flutter::ThreadHost CreateThreadHost (const std::string &name_prefix, const std::shared_ptr< sys::ServiceDirectory > &runner_services=nullptr)
 

Private Member Functions

void OnLevelChanged (fuchsia::memorypressure::Level level, fuchsia::memorypressure::Watcher::OnLevelChangedCallback callback) override
 

Friends

class testing::EngineTest
 

Detailed Description

Definition at line 39 of file engine.h.

Constructor & Destructor Documentation

◆ Engine()

flutter_runner::Engine::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 at line 202 of file engine.cc.

214 : delegate_(delegate),
215 thread_label_(std::move(thread_label)),
216 thread_host_(CreateThreadHost(thread_label_, runner_services)),
217 view_creation_token_(std::move(view_creation_token)),
218 memory_pressure_watcher_binding_(this),
219 latest_memory_pressure_level_(fuchsia::memorypressure::Level::NORMAL),
220 intercept_all_input_(product_config.get_intercept_all_input()),
221 weak_factory_(this) {
222 Initialize(std::move(view_ref_pair), std::move(svc),
223 std::move(runner_services), std::move(settings),
224 std::move(fdio_ns), std::move(directory_request),
225 std::move(product_config), dart_entrypoint_args);
226}
static flutter::ThreadHost CreateThreadHost(const std::string &name_prefix, const std::shared_ptr< sys::ServiceDirectory > &runner_services=nullptr)
Definition engine.cc:136

◆ ~Engine()

flutter_runner::Engine::~Engine ( )

Definition at line 694 of file engine.cc.

694 {
695 shell_.reset();
696
697 // Destroy rendering objects on the raster thread.
698 fml::AutoResetWaitableEvent view_embedder_latch;
699 thread_host_.raster_thread->GetTaskRunner()->PostTask(
700 fml::MakeCopyable([this, &view_embedder_latch]() mutable {
701 view_embedder_.reset();
702 flatland_connection_.reset();
703 surface_producer_.reset();
704 view_embedder_latch.Signal();
705 }));
706 view_embedder_latch.Wait();
707}
internal::CopyableLambda< T > MakeCopyable(T lambda)
std::unique_ptr< fml::Thread > raster_thread
Definition thread_host.h:85

Member Function Documentation

◆ CreateThreadHost()

flutter::ThreadHost flutter_runner::Engine::CreateThreadHost ( const std::string &  name_prefix,
const std::shared_ptr< sys::ServiceDirectory > &  runner_services = nullptr 
)
static

Definition at line 136 of file engine.cc.

138 {
140 fml::Thread::ThreadConfig(name_prefix + ".platform"));
141
142 // Default the config setter to setup the thread name only.
144
145 // Override the config setter if the media profile provider is available.
146 if (services) {
147 // Connect to the media profile provider to assign thread priorities using
148 // Fuchsia's scheduler role API. Failure to connect will print a warning and
149 // proceed with engine initialization, leaving threads created by the engine
150 // at default priority.
151 //
152 // The use of std::shared_ptr here is to work around the unfortunate
153 // requirement for flutter::ThreadConfigSetter (i.e. std::function<>) that
154 // the target callable be copy-constructible. This awkwardly conflicts with
155 // fuchsia::media::ProfileProviderSyncPtr being move-only. std::shared_ptr
156 // provides copyable object that references the move-only SyncPtr.
157 std::shared_ptr<fuchsia::media::ProfileProviderSyncPtr>
158 media_profile_provider =
159 std::make_shared<fuchsia::media::ProfileProviderSyncPtr>();
160
161 const zx_status_t connect_status =
162 services->Connect(media_profile_provider->NewRequest());
163 if (connect_status != ZX_OK) {
164 FML_LOG(WARNING)
165 << "Failed to connect to " << fuchsia::media::ProfileProvider::Name_
166 << ": " << zx_status_get_string(connect_status)
167 << " This is not a fatal error, but threads created by the engine "
168 "will run at default priority, regardless of the requested "
169 "priority.";
170 } else {
171 // Set the role for (this) platform thread. See comment above about the
172 // role naming scheme.
173 SetThreadRole(*media_profile_provider, name_prefix + ".type.platform");
174
175 // This lambda must be copyable or the assignment fails to compile,
176 // necessitating the use of std::shared_ptr for the profile provider.
177 config_setter = [name_prefix, media_profile_provider](
178 const fml::Thread::ThreadConfig& config) {
179 SetThreadConfig(name_prefix, *media_profile_provider, config);
180 };
181 }
182 }
183
184 flutter::ThreadHost::ThreadHostConfig thread_host_config{config_setter};
185
186 thread_host_config.SetRasterConfig(
190 thread_host_config.SetUIConfig(
192 flutter::ThreadHost::Type::kUi, name_prefix),
194 thread_host_config.SetIOConfig(
196 flutter::ThreadHost::Type::kIo, name_prefix),
198
199 return flutter::ThreadHost(thread_host_config);
200}
@ kNormal
Default priority level.
@ kRaster
Suitable for thread which raster data.
@ kDisplay
Suitable for threads which generate data for the display.
static void SetCurrentThreadName(const ThreadConfig &config)
Definition thread.cc:135
#define FML_LOG(severity)
Definition logging.h:82
fml::Thread::ThreadConfigSetter ThreadConfigSetter
Definition thread_host.h:18
static std::string MakeThreadName(Type type, const std::string &prefix)
Use the prefix and thread type to generator a thread name.
void SetRasterConfig(const ThreadConfig &)
Specified the IO Thread Config, meanwhile set the mask.
The collection of all the threads used by the engine.
Definition thread_host.h:21
The ThreadConfig is the thread info include thread name, thread priority.
Definition thread.h:35

◆ GetEngineReturnCode()

std::optional< uint32_t > flutter_runner::Engine::GetEngineReturnCode ( ) const

Definition at line 709 of file engine.cc.

709 {
710 if (!shell_) {
711 return std::nullopt;
712 }
713 std::optional<uint32_t> code;
716 shell_->GetTaskRunners().GetUITaskRunner(),
717 [&latch, &code, engine = shell_->GetEngine()]() {
718 if (engine) {
719 code = engine->GetUIIsolateReturnCode();
720 }
721 latch.Signal();
722 });
723 latch.Wait();
724 return code;
725}
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
FlutterEngine engine
Definition main.cc:68

◆ OnLevelChanged()

void flutter_runner::Engine::OnLevelChanged ( fuchsia::memorypressure::Level  level,
fuchsia::memorypressure::Watcher::OnLevelChangedCallback  callback 
)
overrideprivate

Definition at line 962 of file engine.cc.

964 {
965 // The callback must be invoked immediately to acknowledge the message.
966 // This is the "Throttle push using acknowledgements" pattern:
967 // https://fuchsia.dev/fuchsia-src/concepts/api/fidl#throttle_push_using_acknowledgements
968 callback();
969
970 FML_LOG(WARNING) << "memorypressure watcher: OnLevelChanged from "
971 << static_cast<int>(latest_memory_pressure_level_) << " to "
972 << static_cast<int>(level);
973
974 if (latest_memory_pressure_level_ == fuchsia::memorypressure::Level::NORMAL &&
975 (level == fuchsia::memorypressure::Level::WARNING ||
976 level == fuchsia::memorypressure::Level::CRITICAL)) {
977 FML_LOG(WARNING)
978 << "memorypressure watcher: notifying Flutter that memory is low";
979 shell_->NotifyLowMemoryWarning();
980 }
981 latest_memory_pressure_level_ = level;
982}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ WriteProfileToTrace()

void flutter_runner::Engine::WriteProfileToTrace ( ) const

Definition at line 807 of file engine.cc.

807 {
808 Dart_Port main_port = shell_->GetEngine()->GetUIIsolateMainPort();
809 char* error = NULL;
810 bool success = Dart_WriteProfileToTimeline(main_port, &error);
811 if (!success) {
812 FML_LOG(ERROR) << "Failed to write Dart profile to trace: " << error;
813 free(error);
814 }
815}
DART_EXPORT bool Dart_WriteProfileToTimeline(Dart_Port main_port, char **error)
int64_t Dart_Port
Definition dart_api.h:1524
const uint8_t uint32_t uint32_t GError ** error
#define ERROR(message)

Friends And Related Symbol Documentation

◆ testing::EngineTest

friend class testing::EngineTest
friend

Definition at line 149 of file engine.h.


The documentation for this class was generated from the following files: