Flutter Engine
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::ViewToken view_token, scenic::ViewRefPair view_ref_pair, UniqueFDIONS fdio_ns, fidl::InterfaceRequest< fuchsia::io::Directory > directory_request, FlutterRunnerProductConfiguration product_config)
 
 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, scenic::ViewRefPair view_ref_pair, UniqueFDIONS fdio_ns, fidl::InterfaceRequest< fuchsia::io::Directory > directory_request, FlutterRunnerProductConfiguration product_config)
 
 ~Engine ()
 
std::optional< uint32_t > GetEngineReturnCode () const
 
void WriteProfileToTrace () const
 

Static Public Member Functions

static flutter::ThreadHost CreateThreadHost (const std::string &name_prefix)
 

Friends

class testing::EngineTest
 

Detailed Description

Definition at line 44 of file engine.h.

Constructor & Destructor Documentation

◆ Engine() [1/2]

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::ViewToken  view_token,
scenic::ViewRefPair  view_ref_pair,
UniqueFDIONS  fdio_ns,
fidl::InterfaceRequest< fuchsia::io::Directory >  directory_request,
FlutterRunnerProductConfiguration  product_config 
)

Definition at line 64 of file engine.cc.

74  : delegate_(delegate),
75  thread_label_(std::move(thread_label)),
76  thread_host_(CreateThreadHost(thread_label_)),
77  view_token_(std::move(view_token)),
78  memory_pressure_watcher_binding_(this),
79  latest_memory_pressure_level_(fuchsia::memorypressure::Level::NORMAL),
80  intercept_all_input_(product_config.get_intercept_all_input()),
81  weak_factory_(this) {
82  Initialize(/*=use_flatland*/ false, std::move(view_ref_pair), std::move(svc),
83  std::move(runner_services), std::move(settings),
84  std::move(fdio_ns), std::move(directory_request),
85  std::move(product_config));
86 }
static flutter::ThreadHost CreateThreadHost(const std::string &name_prefix)
Definition: engine.cc:57
MockDelegate delegate_
ThreadHost thread_host_
void Initialize(fidl::InterfaceHandle< fuchsia::sys::Environment > environment, zx::channel directory_request, std::optional< zx::eventpair > view_ref)
Initializes Dart bindings for the Fuchsia application model.
Definition: fuchsia.cc:103

◆ Engine() [2/2]

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,
scenic::ViewRefPair  view_ref_pair,
UniqueFDIONS  fdio_ns,
fidl::InterfaceRequest< fuchsia::io::Directory >  directory_request,
FlutterRunnerProductConfiguration  product_config 
)

Definition at line 88 of file engine.cc.

References action, flutter::PersistentCache::asset_manager(), flutter::Shell::Create(), dart_utils::RootInspectNode::CreateRootChild(), flutter_runner::FlutterRunnerProductConfiguration::enable_shader_warmup(), flutter_runner::FlutterRunnerProductConfiguration::enable_shader_warmup_dart_hooks(), engine, flutter::Engine::Failure, FML_CHECK, FML_DCHECK, FML_LOG, FML_VLOG, flutter::Settings::font_initialization_data, flutter_runner::FlutterRunnerProductConfiguration::get_max_frames_in_flight(), flutter_runner::FlutterRunnerProductConfiguration::get_vsync_offset(), flutter::PersistentCache::GetCacheForProcess(), fml::MessageLoop::GetCurrent(), fml::MessageLoop::GetTaskRunner(), height, flutter::RunConfiguration::InferFromSettings(), flutter::ThreadHost::io_thread, fml::MakeCopyable(), platform_view, flutter::ThreadHost::raster_thread, flutter::Settings::root_isolate_create_callback, flutter::Settings::root_isolate_shutdown_callback, fml::AutoResetWaitableEvent::Signal(), TRACE_EVENT0, flutter::ThreadHost::ui_thread, fml::AutoResetWaitableEvent::Wait(), and width.

98  : delegate_(delegate),
99  thread_label_(std::move(thread_label)),
100  thread_host_(CreateThreadHost(thread_label_)),
101  view_creation_token_(std::move(view_creation_token)),
102  memory_pressure_watcher_binding_(this),
103  latest_memory_pressure_level_(fuchsia::memorypressure::Level::NORMAL),
104  intercept_all_input_(product_config.get_intercept_all_input()),
105  weak_factory_(this) {
106  Initialize(/*=use_flatland*/ true, std::move(view_ref_pair), std::move(svc),
107  std::move(runner_services), std::move(settings),
108  std::move(fdio_ns), std::move(directory_request),
109  std::move(product_config));
110 }
static flutter::ThreadHost CreateThreadHost(const std::string &name_prefix)
Definition: engine.cc:57
MockDelegate delegate_
ThreadHost thread_host_
void Initialize(fidl::InterfaceHandle< fuchsia::sys::Environment > environment, zx::channel directory_request, std::optional< zx::eventpair > view_ref)
Initializes Dart bindings for the Fuchsia application model.
Definition: fuchsia.cc:103

◆ ~Engine()

flutter_runner::Engine::~Engine ( )

Definition at line 638 of file engine.cc.

References fml::MakeCopyable(), flutter::ThreadHost::raster_thread, fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

638  {
639  shell_.reset();
640 
641  // Destroy rendering objects on the raster thread.
642  fml::AutoResetWaitableEvent view_embedder_latch;
643  thread_host_.raster_thread->GetTaskRunner()->PostTask(
644  fml::MakeCopyable([this, &view_embedder_latch]() mutable {
645  flatland_view_embedder_.reset();
646  external_view_embedder_.reset();
647  surface_producer_.reset();
648  flatland_connection_.reset();
649  session_connection_.reset();
650 
651  view_embedder_latch.Signal();
652  }));
653  view_embedder_latch.Wait();
654 }
ThreadHost thread_host_
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition: make_copyable.h:57

Member Function Documentation

◆ CreateThreadHost()

flutter::ThreadHost flutter_runner::Engine::CreateThreadHost ( const std::string &  name_prefix)
static

Definition at line 57 of file engine.cc.

References fml::Thread::SetCurrentThreadName().

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

57  {
58  fml::Thread::SetCurrentThreadName(name_prefix + ".platform");
59  return flutter::ThreadHost(name_prefix, flutter::ThreadHost::Type::RASTER |
60  flutter::ThreadHost::Type::UI |
61  flutter::ThreadHost::Type::IO);
62 }
The collection of all the threads used by the engine.
Definition: thread_host.h:16
static void SetCurrentThreadName(const std::string &name)
Definition: thread.cc:70

◆ GetEngineReturnCode()

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

Definition at line 656 of file engine.cc.

References engine, FML_CHECK, FML_DLOG, FML_LOG, flutter_runner::Engine::Delegate::OnEngineTerminate(), fml::TaskRunner::RunNowOrPostTask(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

Referenced by flutter_runner::ComponentV1::GetDebugLabel(), and flutter_runner::ComponentV2::GetDebugLabel().

656  {
657  if (!shell_) {
658  return std::nullopt;
659  }
660  std::optional<uint32_t> code;
663  shell_->GetTaskRunners().GetUITaskRunner(),
664  [&latch, &code, engine = shell_->GetEngine()]() {
665  if (engine) {
666  code = engine->GetUIIsolateReturnCode();
667  }
668  latch.Signal();
669  });
670  latch.Wait();
671  return code;
672 }
static void RunNowOrPostTask(fml::RefPtr< fml::TaskRunner > runner, const fml::closure &task)
Definition: task_runner.cc:55

◆ WriteProfileToTrace()

void flutter_runner::Engine::WriteProfileToTrace ( ) const

Definition at line 808 of file engine.cc.

References callback, flutter::DeserializeImageWithoutData(), flutter::DeserializeTypefaceWithoutData(), error, FML_LOG, function, flutter_runner::SurfaceProducerSurface::GetSkiaSurface(), flutter_runner::VulkanSurfaceProducer::gr_context(), height, fml::BasicTaskRunner::PostTask(), flutter_runner::VulkanSurfaceProducer::ProduceOffscreenSurface(), fml::size(), and width.

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

Friends And Related Function Documentation

◆ testing::EngineTest

friend class testing::EngineTest
friend

Definition at line 175 of file engine.h.


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