Flutter Engine
 
Loading...
Searching...
No Matches
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)
 

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 203 of file engine.cc.

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

◆ ~Engine()

flutter_runner::Engine::~Engine ( )

Definition at line 698 of file engine.cc.

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

References fml::MakeCopyable(), fml::AutoResetWaitableEvent::Signal(), thread_host_, and fml::AutoResetWaitableEvent::Wait().

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 137 of file engine.cc.

139 {
141 fml::Thread::ThreadConfig(name_prefix + ".platform"));
142
143 // Default the config setter to setup the thread name only.
145
146 // Override the config setter if the media profile provider is available.
147 if (services) {
148 // Connect to the media profile provider to assign thread priorities using
149 // Fuchsia's scheduler role API. Failure to connect will print a warning and
150 // proceed with engine initialization, leaving threads created by the engine
151 // at default priority.
152 //
153 // The use of std::shared_ptr here is to work around the unfortunate
154 // requirement for flutter::ThreadConfigSetter (i.e. std::function<>) that
155 // the target callable be copy-constructible. This awkwardly conflicts with
156 // fuchsia::media::ProfileProviderSyncPtr being move-only. std::shared_ptr
157 // provides copyable object that references the move-only SyncPtr.
158 std::shared_ptr<fuchsia::media::ProfileProviderSyncPtr>
159 media_profile_provider =
160 std::make_shared<fuchsia::media::ProfileProviderSyncPtr>();
161
162 const zx_status_t connect_status =
163 services->Connect(media_profile_provider->NewRequest());
164 if (connect_status != ZX_OK) {
165 FML_LOG(WARNING)
166 << "Failed to connect to " << fuchsia::media::ProfileProvider::Name_
167 << ": " << zx_status_get_string(connect_status)
168 << " This is not a fatal error, but threads created by the engine "
169 "will run at default priority, regardless of the requested "
170 "priority.";
171 } else {
172 // Set the role for (this) platform thread. See comment above about the
173 // role naming scheme.
174 SetThreadRole(*media_profile_provider, name_prefix + ".type.platform");
175
176 // This lambda must be copyable or the assignment fails to compile,
177 // necessitating the use of std::shared_ptr for the profile provider.
178 config_setter = [name_prefix, media_profile_provider](
179 const fml::Thread::ThreadConfig& config) {
180 SetThreadConfig(name_prefix, *media_profile_provider, config);
181 };
182 }
183 }
184
185 flutter::ThreadHost::ThreadHostConfig thread_host_config{config_setter};
186
187 thread_host_config.SetRasterConfig(
191 thread_host_config.SetUIConfig(
193 flutter::ThreadHost::Type::kUi, name_prefix),
195 thread_host_config.SetIOConfig(
197 flutter::ThreadHost::Type::kIo, name_prefix),
199
200 return flutter::ThreadHost(thread_host_config);
201}
@ 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:101
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

References FML_LOG, fml::Thread::kDisplay, flutter::ThreadHost::kIo, fml::Thread::kNormal, fml::Thread::kRaster, flutter::ThreadHost::kRaster, flutter::ThreadHost::kUi, flutter::ThreadHost::ThreadHostConfig::MakeThreadName(), fml::Thread::SetCurrentThreadName(), and flutter::ThreadHost::ThreadHostConfig::SetRasterConfig().

Referenced by flutter_runner::testing::TEST().

◆ GetEngineReturnCode()

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

Definition at line 713 of file engine.cc.

713 {
714 if (!shell_) {
715 return std::nullopt;
716 }
717 std::optional<uint32_t> code;
720 shell_->GetTaskRunners().GetUITaskRunner(),
721 [&latch, &code, engine = shell_->GetEngine()]() {
722 if (engine) {
723 code = engine->GetUIIsolateReturnCode();
724 }
725 latch.Signal();
726 });
727 latch.Wait();
728 return code;
729}
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
FlutterEngine engine
Definition main.cc:84

References engine, fml::TaskRunner::RunNowOrPostTask(), and fml::AutoResetWaitableEvent::Signal().

◆ WriteProfileToTrace()

void flutter_runner::Engine::WriteProfileToTrace ( ) const

Definition at line 811 of file engine.cc.

811 {
812 Dart_Port main_port = shell_->GetEngine()->GetUIIsolateMainPort();
813 char* error = NULL;
814 bool success = Dart_WriteProfileToTimeline(main_port, &error);
815 if (!success) {
816 FML_LOG(ERROR) << "Failed to write Dart profile to trace: " << error;
817 free(error);
818 }
819}
const uint8_t uint32_t uint32_t GError ** error

References error, and FML_LOG.

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: