5#define RAPIDJSON_HAS_STDSTRING 1
6#include "flutter/shell/common/shell.h"
13#include "flutter/assets/directory_asset_bundle.h"
14#include "flutter/common/constants.h"
15#include "flutter/common/graphics/persistent_cache.h"
16#include "flutter/fml/base32.h"
17#include "flutter/fml/file.h"
18#include "flutter/fml/icu_util.h"
19#include "flutter/fml/log_settings.h"
20#include "flutter/fml/logging.h"
21#include "flutter/fml/make_copyable.h"
22#include "flutter/fml/message_loop.h"
23#include "flutter/fml/paths.h"
24#include "flutter/fml/trace_event.h"
25#include "flutter/runtime/dart_vm.h"
26#include "flutter/shell/common/base64.h"
27#include "flutter/shell/common/engine.h"
28#include "flutter/shell/common/skia_event_tracer_impl.h"
29#include "flutter/shell/common/switches.h"
30#include "flutter/shell/common/vsync_waiter.h"
32#include "rapidjson/stringbuffer.h"
33#include "rapidjson/writer.h"
34#include "third_party/dart/runtime/include/dart_tools_api.h"
55std::unique_ptr<Engine> CreateEngine(
63 std::unique_ptr<Animator> animator,
67 const std::shared_ptr<VolatilePathTracker>& volatile_path_tracker,
68 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch,
70 return std::make_unique<Engine>(delegate,
81 volatile_path_tracker,
83 runtime_stage_backend);
86void RegisterCodecsWithSkia() {
106void PerformInitializationTasks(
Settings& settings) {
114 static std::once_flag gShellSettingsInitialization = {};
115 std::call_once(gShellSettingsInitialization, [&settings] {
119 if (settings.trace_skia) {
123 if (!settings.trace_allowlist.empty()) {
127 if (!settings.skia_deterministic_rendering_on_cpu) {
130 FML_DLOG(INFO) <<
"Skia deterministic rendering is enabled.";
132 RegisterCodecsWithSkia();
134 if (settings.icu_initialization_required) {
135 if (!settings.icu_data_path.empty()) {
137 }
else if (settings.icu_mapper) {
140 FML_DLOG(WARNING) <<
"Skipping ICU initialization in the shell.";
150std::pair<DartVMRef, fml::RefPtr<const DartSnapshot>>
161 if (!isolate_snapshot) {
162 isolate_snapshot = vm->GetVMData()->GetIsolateSnapshot();
164 return {std::move(vm), isolate_snapshot};
173 bool is_gpu_disabled) {
175 PerformInitializationTasks(settings);
180 auto resource_cache_limit_calculator =
181 std::make_shared<ResourceCacheLimitCalculator>(
182 settings.resource_cache_max_bytes_threshold);
184 return CreateWithSnapshot(platform_data,
188 resource_cache_limit_calculator,
191 std::move(isolate_snapshot),
192 on_create_platform_view,
193 on_create_rasterizer,
194 CreateEngine, is_gpu_disabled);
198 const std::shared_ptr<impeller::Context>& impeller_context) {
199 if (!impeller_context) {
202 switch (impeller_context->GetBackendType()) {
212std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
215 std::shared_ptr<ShellIOManager> parent_io_manager,
216 const std::shared_ptr<ResourceCacheLimitCalculator>&
217 resource_cache_limit_calculator,
218 const TaskRunners& task_runners,
219 const PlatformData& platform_data,
220 const Settings& settings,
222 const Shell::CreateCallback<PlatformView>& on_create_platform_view,
223 const Shell::CreateCallback<Rasterizer>& on_create_rasterizer,
225 bool is_gpu_disabled) {
226 if (!task_runners.IsValid()) {
227 FML_LOG(
ERROR) <<
"Task runners to run the shell were invalid.";
231 auto shell = std::unique_ptr<Shell>(
232 new Shell(std::move(vm), task_runners, std::move(parent_merger),
233 resource_cache_limit_calculator, settings,
234 std::make_shared<VolatilePathTracker>(
235 task_runners.GetUITaskRunner(),
236 !
settings.skia_deterministic_rendering_on_cpu),
246 std::promise<std::unique_ptr<Rasterizer>> rasterizer_promise;
247 auto rasterizer_future = rasterizer_promise.get_future();
248 std::promise<fml::TaskRunnerAffineWeakPtr<SnapshotDelegate>>
249 snapshot_delegate_promise;
250 auto snapshot_delegate_future = snapshot_delegate_promise.get_future();
252 task_runners.GetRasterTaskRunner(),
253 [&rasterizer_promise,
254 &snapshot_delegate_promise,
255 on_create_rasterizer,
259 TRACE_EVENT0(
"flutter",
"ShellSetupGPUSubsystem");
260 std::unique_ptr<Rasterizer> rasterizer(on_create_rasterizer(*shell));
261 rasterizer->SetImpellerContext(impeller_context);
262 snapshot_delegate_promise.set_value(rasterizer->GetSnapshotDelegate());
263 rasterizer_promise.set_value(std::move(rasterizer));
277 std::promise<std::shared_ptr<ShellIOManager>> io_manager_promise;
278 auto io_manager_future = io_manager_promise.get_future();
279 std::promise<fml::WeakPtr<ShellIOManager>> weak_io_manager_promise;
280 auto weak_io_manager_future = weak_io_manager_promise.get_future();
281 std::promise<fml::RefPtr<SkiaUnrefQueue>> unref_queue_promise;
282 auto unref_queue_future = unref_queue_promise.get_future();
283 auto io_task_runner =
shell->GetTaskRunners().GetIOTaskRunner();
290 [&io_manager_promise,
291 &weak_io_manager_promise,
293 &unref_queue_promise,
296 is_backgrounded_sync_switch =
shell->GetIsGpuDisabledSyncSwitch()
298 TRACE_EVENT0(
"flutter",
"ShellSetupIOSubsystem");
299 std::shared_ptr<ShellIOManager> io_manager;
300 if (parent_io_manager) {
301 io_manager = parent_io_manager;
303 io_manager = std::make_shared<ShellIOManager>(
304 platform_view_ptr->CreateResourceContext(),
305 is_backgrounded_sync_switch,
307 platform_view_ptr->GetImpellerContext()
310 weak_io_manager_promise.set_value(io_manager->GetWeakPtr());
311 unref_queue_promise.set_value(io_manager->GetSkiaUnrefQueue());
312 io_manager_promise.set_value(io_manager);
320 std::promise<std::unique_ptr<Engine>> engine_promise;
321 auto engine_future = engine_promise.get_future();
323 shell->GetTaskRunners().GetUITaskRunner(),
328 isolate_snapshot = std::move(isolate_snapshot),
329 vsync_waiter = std::move(vsync_waiter),
330 &weak_io_manager_future,
331 &snapshot_delegate_future,
336 TRACE_EVENT0(
"flutter",
"ShellSetupUISubsystem");
337 const auto& task_runners = shell->GetTaskRunners();
341 auto animator = std::make_unique<Animator>(*shell, task_runners,
342 std::move(vsync_waiter));
344 engine_promise.set_value(on_create_engine(
348 std::move(isolate_snapshot),
351 shell->GetSettings(),
353 weak_io_manager_future.get(),
354 unref_queue_future.get(),
355 snapshot_delegate_future.get(),
356 shell->volatile_path_tracker_,
357 shell->is_gpu_disabled_sync_switch_,
358 runtime_stage_backend
364 rasterizer_future.get(),
365 io_manager_future.get())
373std::unique_ptr<Shell> Shell::CreateWithSnapshot(
374 const PlatformData& platform_data,
375 const TaskRunners& task_runners,
377 const std::shared_ptr<ShellIOManager>& parent_io_manager,
378 const std::shared_ptr<ResourceCacheLimitCalculator>&
379 resource_cache_limit_calculator,
383 const Shell::CreateCallback<PlatformView>& on_create_platform_view,
384 const Shell::CreateCallback<Rasterizer>& on_create_rasterizer,
385 const Shell::EngineCreateCallback& on_create_engine,
386 bool is_gpu_disabled) {
388 PerformInitializationTasks(settings);
392 const bool callbacks_valid =
393 on_create_platform_view && on_create_rasterizer && on_create_engine;
394 if (!task_runners.IsValid() || !callbacks_valid) {
399 std::unique_ptr<Shell>
shell;
400 auto platform_task_runner = task_runners.GetPlatformTaskRunner();
402 platform_task_runner,
405 parent_thread_merger,
407 resource_cache_limit_calculator,
408 task_runners = task_runners,
409 platform_data = platform_data,
412 isolate_snapshot = std::move(isolate_snapshot),
413 on_create_platform_view = on_create_platform_view,
414 on_create_rasterizer = on_create_rasterizer,
415 on_create_engine = on_create_engine,
416 is_gpu_disabled]()
mutable {
417 shell = CreateShellOnPlatformThread(std::move(vm),
418 parent_thread_merger,
420 resource_cache_limit_calculator,
424 std::move(isolate_snapshot),
425 on_create_platform_view,
426 on_create_rasterizer,
427 on_create_engine, is_gpu_disabled);
434Shell::Shell(DartVMRef vm,
435 const TaskRunners& task_runners,
437 const std::shared_ptr<ResourceCacheLimitCalculator>&
438 resource_cache_limit_calculator,
439 const Settings& settings,
440 std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
441 bool is_gpu_disabled)
443 parent_raster_thread_merger_(
std::move(parent_merger)),
444 resource_cache_limit_calculator_(resource_cache_limit_calculator),
447 is_gpu_disabled_sync_switch_(new
fml::SyncSwitch(is_gpu_disabled)),
448 volatile_path_tracker_(
std::move(volatile_path_tracker)),
449 weak_factory_gpu_(nullptr),
450 weak_factory_(this) {
452 <<
"Software rendering is incompatible with Impeller.";
455 <<
"[Action Required] The application opted out of Impeller by either "
456 "using the --no-enable-impeller flag or FLTEnableImpeller=false "
457 "plist flag. This option is going to go away in an upcoming Flutter "
458 "release. Remove the explicit opt-out. If you need to opt-out, "
459 "report a bug describing the issue.";
461 FML_CHECK(vm_) <<
"Must have access to VM to create a shell.";
465 display_manager_ = std::make_unique<DisplayManager>();
466 resource_cache_limit_calculator->AddResourceCacheLimitItem(
467 weak_factory_.GetWeakPtr());
474 this->weak_factory_gpu_ =
475 std::make_unique<fml::TaskRunnerAffineWeakPtrFactory<Shell>>(this);
482 std::bind(&Shell::OnServiceProtocolScreenshot,
this,
483 std::placeholders::_1, std::placeholders::_2)};
486 std::bind(&Shell::OnServiceProtocolScreenshotSKP,
this,
487 std::placeholders::_1, std::placeholders::_2)};
490 std::bind(&Shell::OnServiceProtocolRunInView,
this, std::placeholders::_1,
491 std::placeholders::_2)};
492 service_protocol_handlers_
495 std::bind(&Shell::OnServiceProtocolFlushUIThreadTasks,
this,
496 std::placeholders::_1, std::placeholders::_2)};
497 service_protocol_handlers_
500 std::bind(&Shell::OnServiceProtocolSetAssetBundlePath,
this,
501 std::placeholders::_1, std::placeholders::_2)};
502 service_protocol_handlers_
505 std::bind(&Shell::OnServiceProtocolGetDisplayRefreshRate,
this,
506 std::placeholders::_1, std::placeholders::_2)};
509 std::bind(&Shell::OnServiceProtocolGetSkSLs,
this, std::placeholders::_1,
510 std::placeholders::_2)};
511 service_protocol_handlers_
514 std::bind(&Shell::OnServiceProtocolEstimateRasterCacheMemory,
this,
515 std::placeholders::_1, std::placeholders::_2)};
516 service_protocol_handlers_
519 std::bind(&Shell::OnServiceProtocolRenderFrameWithRasterStats,
this,
520 std::placeholders::_1, std::placeholders::_2)};
523 std::bind(&Shell::OnServiceProtocolReloadAssetFonts,
this,
524 std::placeholders::_1, std::placeholders::_2)};
528 PersistentCache::GetCacheForProcess()->RemoveWorkerTaskRunner(
531 vm_->GetServiceProtocol()->RemoveHandler(
this);
534 platform_latch, io_latch;
539 engine_->ShutdownPlatformIsolates();
540 platiso_latch.Signal();
542 platiso_latch.
Wait();
555 [
this, rasterizer = std::move(rasterizer_), &gpu_latch]()
mutable {
557 this->weak_factory_gpu_.reset();
566 &io_latch]()
mutable {
569 platform_view->ReleaseResourceContext();
582 &platform_latch]()
mutable {
583 platform_view.reset();
584 platform_latch.Signal();
586 platform_latch.Wait();
589std::unique_ptr<Shell> Shell::Spawn(
591 const std::string& initial_route,
596 bool is_gpu_disabled =
false;
597 GetIsGpuDisabledSyncSwitch()->Execute(
599 .SetIfFalse([&is_gpu_disabled] { is_gpu_disabled =
false; })
600 .SetIfTrue([&is_gpu_disabled] { is_gpu_disabled =
true; }));
601 std::unique_ptr<Shell>
result = CreateWithSnapshot(
603 io_manager_, resource_cache_limit_calculator_, GetSettings(), vm_,
604 vm_->GetVMData()->GetIsolateSnapshot(), on_create_platform_view,
605 on_create_rasterizer,
606 [
engine = this->engine_.get(), initial_route](
611 const Settings& settings, std::unique_ptr<Animator> animator,
615 const std::shared_ptr<VolatilePathTracker>& volatile_path_tracker,
616 const std::shared_ptr<fml::SyncSwitch>& is_gpu_disabled_sync_switch,
618 return engine->Spawn(
625 std::move(snapshot_delegate),
626 is_gpu_disabled_sync_switch);
629 result->RunEngine(std::move(run_configuration));
633void Shell::NotifyLowMemoryWarning()
const {
644 [rasterizer = rasterizer_->GetWeakPtr(), trace_id = trace_id]() {
646 rasterizer->NotifyLowMemoryWarning();
656 RunEngine(std::move(run_configuration),
nullptr);
659void Shell::RunEngine(
664 if (!result_callback) {
667 platform_runner->PostTask(
668 [result_callback, run_result]() { result_callback(run_result); });
676 [run_configuration = std::move(run_configuration),
677 weak_engine = weak_engine_,
result]()
mutable {
680 <<
"Could not launch engine with configuration - no engine.";
681 result(Engine::RunStatus::Failure);
684 auto run_result = weak_engine->Run(std::move(run_configuration));
686 FML_LOG(
ERROR) <<
"Could not launch engine with configuration.";
693std::optional<DartErrorCode> Shell::GetUIIsolateLastError()
const {
700 switch (weak_engine_->GetUIIsolateLastError()) {
702 return DartErrorCode::CompilationError;
704 return DartErrorCode::ApiError;
706 return DartErrorCode::UnknownError;
708 return DartErrorCode::NoError;
710 return DartErrorCode::UnknownError;
713bool Shell::EngineHasLivePorts()
const {
721 return weak_engine_->UIIsolateHasLivePorts();
724bool Shell::IsSetup()
const {
728bool Shell::Setup(std::unique_ptr<PlatformView>
platform_view,
729 std::unique_ptr<Engine>
engine,
730 std::unique_ptr<Rasterizer> rasterizer,
731 const std::shared_ptr<ShellIOManager>& io_manager) {
741 platform_message_handler_ = platform_view_->GetPlatformMessageHandler();
742 route_messages_through_platform_thread_.store(
true);
744 [
self = weak_factory_.GetWeakPtr()] {
746 self->route_messages_through_platform_thread_.store(false);
749 engine_ = std::move(
engine);
750 rasterizer_ = std::move(rasterizer);
754 auto view_embedder = platform_view_->CreateExternalViewEmbedder();
755 rasterizer_->SetExternalViewEmbedder(view_embedder);
756 rasterizer_->SetSnapshotSurfaceProducer(
757 platform_view_->CreateSnapshotSurfaceProducer());
761 weak_engine_ = engine_->GetWeakPtr();
762 weak_rasterizer_ = rasterizer_->GetWeakPtr();
763 weak_platform_view_ = platform_view_->GetWeakPtr();
766 engine_->AddView(kFlutterImplicitViewId, ViewportMetrics{}, [](
bool added) {
767 FML_DCHECK(added) <<
"Failed to add the implicit view";
771 if (!
settings_.prefetched_default_font_manager) {
775 engine->SetupDefaultFontManager();
782 PersistentCache::GetCacheForProcess()->AddWorkerTaskRunner(
785 PersistentCache::GetCacheForProcess()->SetIsDumpingSkp(
786 settings_.dump_skp_on_shader_compilation);
789 PersistentCache::GetCacheForProcess()->Purge();
805 return parent_raster_thread_merger_;
810 return weak_rasterizer_;
820 return weak_platform_view_;
833void Shell::OnPlatformViewCreated(std::unique_ptr<Surface>
surface) {
834 TRACE_EVENT0(
"flutter",
"Shell::OnPlatformViewCreated");
847 rasterizer_->DisableThreadMergerIfNeeded();
859 const bool should_post_raster_task =
860 !
task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread();
863 [&waiting_for_first_frame = waiting_for_first_frame_,
864 rasterizer = rasterizer_->GetWeakPtr(),
870 rasterizer->EnableThreadMergerIfNeeded();
871 rasterizer->Setup(std::move(surface));
874 waiting_for_first_frame.store(
true);
877 auto ui_task = [
engine = engine_->GetWeakPtr()] {
894 raster_task, should_post_raster_task, &latch] {
895 if (io_manager && !io_manager->GetResourceContext()) {
898 io_manager->NotifyResourceContextAvailable(resource_context);
906 if (should_post_raster_task) {
915 if (!should_post_raster_task) {
924void Shell::OnPlatformViewDestroyed() {
925 TRACE_EVENT0(
"flutter",
"Shell::OnPlatformViewDestroyed");
937 rasterizer_->DisableThreadMergerIfNeeded();
943 engine->NotifyDestroyed();
957 auto io_task = [io_manager =
io_manager_.get(), &latch]() {
960 io_manager->GetIsGpuDisabledSyncSwitch()->Execute(
962 [&] { io_manager->GetSkiaUnrefQueue()->Drain(); }));
968 auto raster_task = [rasterizer = rasterizer_->GetWeakPtr(),
975 rasterizer->EnableThreadMergerIfNeeded();
976 rasterizer->Teardown();
994 rasterizer_->TeardownExternalViewEmbedder();
998void Shell::OnPlatformViewScheduleFrame() {
999 TRACE_EVENT0(
"flutter",
"Shell::OnPlatformViewScheduleFrame");
1005 engine->ScheduleFrame();
1011void Shell::OnPlatformViewSetViewportMetrics(int64_t view_id,
1024 resource_cache_limit_ =
1026 size_t resource_cache_max_bytes =
1027 resource_cache_limit_calculator_->GetResourceCacheMaxBytes();
1029 [rasterizer = rasterizer_->GetWeakPtr(), resource_cache_max_bytes] {
1031 rasterizer->SetResourceCacheMaxBytes(resource_cache_max_bytes, false);
1036 [
engine = engine_->GetWeakPtr(), view_id, metrics]() {
1038 engine->SetViewportMetrics(view_id, metrics);
1043 std::scoped_lock<std::mutex> lock(resize_mutex_);
1044 expected_frame_sizes_[view_id] =
1045 SkISize::Make(metrics.physical_width, metrics.physical_height);
1046 device_pixel_ratio_ = metrics.device_pixel_ratio;
1051void Shell::OnPlatformViewDispatchPlatformMessage(
1052 std::unique_ptr<PlatformMessage>
message) {
1054#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
1055 if (!
task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread()) {
1056 std::scoped_lock lock(misbehaving_message_channels_mutex_);
1057 auto inserted = misbehaving_message_channels_.insert(
message->channel());
1058 if (inserted.second) {
1060 <<
"The '" <<
message->channel()
1061 <<
"' channel sent a message from native to Flutter on a "
1062 "non-platform thread. Platform channel messages must be sent on "
1063 "the platform thread. Failure to do so may result in data loss or "
1064 "crashes, and must be fixed in the plugin or application code "
1065 "creating that channel.\n"
1066 "See https://docs.flutter.dev/platform-integration/"
1067 "platform-channels#channels-and-platform-threading for more "
1078 engine->DispatchPlatformMessage(std::move(message));
1084void Shell::OnPlatformViewDispatchPointerDataPacket(
1085 std::unique_ptr<PointerDataPacket> packet) {
1087 "flutter",
"Shell::OnPlatformViewDispatchPointerDataPacket",
1088 1, &next_pointer_flow_id_);
1094 flow_id = next_pointer_flow_id_]()
mutable {
1096 engine->DispatchPointerDataPacket(std::move(packet), flow_id);
1099 next_pointer_flow_id_++;
1103void Shell::OnPlatformViewDispatchSemanticsAction(int32_t node_id,
1111 args = std::move(
args)]()
mutable {
1113 engine->DispatchSemanticsAction(node_id, action, std::move(args));
1119void Shell::OnPlatformViewSetSemanticsEnabled(
bool enabled) {
1124 [
engine = engine_->GetWeakPtr(), enabled] {
1126 engine->SetSemanticsEnabled(enabled);
1132void Shell::OnPlatformViewSetAccessibilityFeatures(int32_t
flags) {
1139 engine->SetAccessibilityFeatures(flags);
1145void Shell::OnPlatformViewRegisterTexture(
1146 std::shared_ptr<flutter::Texture>
texture) {
1151 [rasterizer = rasterizer_->GetWeakPtr(),
texture] {
1153 if (auto registry = rasterizer->GetTextureRegistry()) {
1154 registry->RegisterTexture(texture);
1166 [rasterizer = rasterizer_->GetWeakPtr(),
texture_id]() {
1168 if (auto registry = rasterizer->GetTextureRegistry()) {
1169 registry->UnregisterTexture(texture_id);
1176void Shell::OnPlatformViewMarkTextureFrameAvailable(int64_t
texture_id) {
1182 [rasterizer = rasterizer_->GetWeakPtr(),
texture_id]() {
1183 auto registry = rasterizer->GetTextureRegistry();
1195 texture->MarkNewFrameAvailable();
1201 engine->ScheduleFrame(
false);
1207void Shell::OnPlatformViewSetNextFrameCallback(
const fml::closure& closure) {
1212 [rasterizer = rasterizer_->GetWeakPtr(), closure = closure]() {
1214 rasterizer->SetNextFrameCallback(closure);
1220const Settings& Shell::OnPlatformViewGetSettings()
const {
1226 uint64_t frame_number) {
1232 std::scoped_lock time_recorder_lock(time_recorder_mutex_);
1233 latest_frame_target_time_.emplace(frame_target_time);
1236 engine_->BeginFrame(frame_target_time, frame_number);
1246 engine_->NotifyIdle(deadline);
1247 volatile_path_tracker_->OnFrame();
1251void Shell::OnAnimatorUpdateLatestFrameTargetTime(
1257 std::scoped_lock time_recorder_lock(time_recorder_mutex_);
1258 if (!latest_frame_target_time_) {
1259 latest_frame_target_time_ = frame_target_time;
1260 }
else if (latest_frame_target_time_ < frame_target_time) {
1261 latest_frame_target_time_ = frame_target_time;
1267void Shell::OnAnimatorDraw(std::shared_ptr<FramePipeline> pipeline) {
1271 [&waiting_for_first_frame = waiting_for_first_frame_,
1272 &waiting_for_first_frame_condition = waiting_for_first_frame_condition_,
1273 rasterizer = rasterizer_->GetWeakPtr(),
1274 weak_pipeline = std::weak_ptr<FramePipeline>(pipeline)]()
mutable {
1276 std::shared_ptr<FramePipeline> pipeline = weak_pipeline.lock();
1278 rasterizer->Draw(pipeline);
1281 if (waiting_for_first_frame.load()) {
1282 waiting_for_first_frame.store(false);
1283 waiting_for_first_frame_condition.notify_all();
1290void Shell::OnAnimatorDrawLastLayerTrees(
1291 std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder) {
1295 [rasterizer = rasterizer_->GetWeakPtr(),
1296 frame_timings_recorder = std::move(frame_timings_recorder)]()
mutable {
1298 rasterizer->DrawLastLayerTrees(std::move(frame_timings_recorder));
1312 [view = platform_view_->GetWeakPtr(),
update = std::move(
update),
1313 actions = std::move(actions)] {
1315 view->UpdateSemantics(update, actions);
1321void Shell::OnEngineHandlePlatformMessage(
1322 std::unique_ptr<PlatformMessage>
message) {
1327 HandleEngineSkiaMessage(std::move(
message));
1331 if (platform_message_handler_) {
1332 if (route_messages_through_platform_thread_ &&
1333 !platform_message_handler_
1334 ->DoesHandlePlatformMessageOnPlatformThread()) {
1352 [weak_platform_message_handler =
1353 std::weak_ptr<PlatformMessageHandler>(platform_message_handler_),
1355 ui_task_runner->PostTask(
1358 auto platform_message_handler =
1359 weak_platform_message_handler.lock();
1360 if (platform_message_handler) {
1361 platform_message_handler->HandlePlatformMessage(
1367 platform_message_handler_->HandlePlatformMessage(std::move(
message));
1374 view->HandlePlatformMessage(std::move(message));
1380void Shell::OnEngineChannelUpdate(std::string
name,
bool listening) {
1384 [view = platform_view_->GetWeakPtr(),
name = std::move(
name), listening] {
1386 view->SendChannelUpdate(name, listening);
1391void Shell::HandleEngineSkiaMessage(std::unique_ptr<PlatformMessage>
message) {
1392 const auto& data =
message->data();
1394 rapidjson::Document document;
1395 document.Parse(
reinterpret_cast<const char*
>(data.GetMapping()),
1397 if (document.HasParseError() || !document.IsObject()) {
1400 auto root = document.GetObject();
1401 auto method =
root.FindMember(
"method");
1402 if (method->value !=
"Skia.setResourceCacheMaxBytes") {
1405 auto args =
root.FindMember(
"args");
1406 if (
args ==
root.MemberEnd() || !
args->value.IsInt()) {
1411 [rasterizer = rasterizer_->GetWeakPtr(), max_bytes =
args->value.GetInt(),
1412 response =
message->response()] {
1414 rasterizer->SetResourceCacheMaxBytes(static_cast<size_t>(max_bytes),
1420 std::vector<uint8_t>
data = {
'[',
't',
'r',
'u',
'e',
']'};
1422 std::make_unique<fml::DataMapping>(std::move(data)));
1428void Shell::OnPreEngineRestart() {
1435 [view = platform_view_->GetWeakPtr(), &latch]() {
1437 view->OnPreEngineRestart();
1447void Shell::OnRootIsolateCreated() {
1448 if (is_added_to_service_protocol_) {
1451 auto description = GetServiceProtocolDescription();
1454 [
self = weak_factory_.GetWeakPtr(),
1455 description = std::move(description)]() {
1457 self->vm_->GetServiceProtocol()->AddHandler(self.get(), description);
1460 is_added_to_service_protocol_ =
true;
1464void Shell::UpdateIsolateDescription(
const std::string isolate_name,
1465 int64_t isolate_port) {
1466 Handler::Description description(isolate_port, isolate_name);
1467 vm_->GetServiceProtocol()->SetHandlerDescription(
this, description);
1470void Shell::SetNeedsReportTimings(
bool value) {
1471 needs_report_timings_ =
value;
1475std::unique_ptr<std::vector<std::string>> Shell::ComputePlatformResolvedLocale(
1476 const std::vector<std::string>& supported_locale_data) {
1477 return platform_view_->ComputePlatformResolvedLocales(supported_locale_data);
1480void Shell::LoadDartDeferredLibrary(
1481 intptr_t loading_unit_id,
1482 std::unique_ptr<const fml::Mapping> snapshot_data,
1483 std::unique_ptr<const fml::Mapping> snapshot_instructions) {
1485 [
engine = engine_->GetWeakPtr(), loading_unit_id,
1486 data = std::move(snapshot_data),
1487 instructions = std::move(snapshot_instructions)]()
mutable {
1489 engine->LoadDartDeferredLibrary(loading_unit_id, std::move(data),
1490 std::move(instructions));
1495void Shell::LoadDartDeferredLibraryError(intptr_t loading_unit_id,
1496 const std::string error_message,
1500 [
engine = weak_engine_, loading_unit_id, error_message, transient] {
1502 engine->LoadDartDeferredLibraryError(loading_unit_id, error_message,
1508void Shell::UpdateAssetResolverByType(
1509 std::unique_ptr<AssetResolver> updated_asset_resolver,
1515 asset_resolver = std::move(updated_asset_resolver)]()
mutable {
1517 engine->GetAssetManager()->UpdateResolverByType(
1518 std::move(asset_resolver), type);
1524void Shell::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
1526 [view = platform_view_->GetWeakPtr(), loading_unit_id] {
1528 view->RequestDartDeferredLibrary(loading_unit_id);
1534double Shell::GetScaledFontSize(
double unscaled_font_size,
1535 int configuration_id)
const {
1536 return platform_view_->GetScaledFontSize(unscaled_font_size,
1540void Shell::ReportTimings() {
1544 auto timings = std::move(unreported_timings_);
1545 unreported_timings_ = {};
1548 engine->ReportTimings(timings);
1553size_t Shell::UnreportedFramesCount()
const {
1556 FML_DCHECK(unreported_timings_.size() % (FrameTiming::kStatisticsCount) == 0);
1557 return unreported_timings_.size() / (FrameTiming::kStatisticsCount);
1566 if (
settings_.frame_rasterized_callback) {
1567 settings_.frame_rasterized_callback(timing);
1570 if (!needs_report_timings_) {
1574 size_t old_count = unreported_timings_.size();
1576 for (
auto phase : FrameTiming::kPhases) {
1577 unreported_timings_.push_back(
1586 old_count + FrameTiming::kStatisticsCount);
1600 if (!first_frame_rasterized_ || UnreportedFramesCount() >= 100) {
1601 first_frame_rasterized_ =
true;
1603 }
else if (!frame_timings_report_scheduled_) {
1605 constexpr int kBatchTimeInMilliseconds = 1000;
1607 constexpr int kBatchTimeInMilliseconds = 100;
1613 frame_timings_report_scheduled_ =
true;
1615 [
self = weak_factory_gpu_->GetWeakPtr()]() {
1619 self->frame_timings_report_scheduled_ =
false;
1620 if (
self->UnreportedFramesCount() > 0) {
1621 self->ReportTimings();
1629 double display_refresh_rate = display_manager_->GetMainDisplayRefreshRate();
1630 if (display_refresh_rate > 0) {
1638 std::scoped_lock time_recorder_lock(time_recorder_mutex_);
1639 FML_CHECK(latest_frame_target_time_.has_value())
1640 <<
"GetLatestFrameTargetTime called before OnAnimatorBeginFrame";
1643 return latest_frame_target_time_.value();
1647bool Shell::ShouldDiscardLayerTree(int64_t view_id,
1649 std::scoped_lock<std::mutex> lock(resize_mutex_);
1650 auto expected_frame_size = ExpectedFrameSize(view_id);
1651 return !expected_frame_size.isEmpty() &&
1657 std::string_view method)
const {
1659 auto found = service_protocol_handlers_.find(method);
1660 if (found != service_protocol_handlers_.end()) {
1661 return found->second.first;
1667bool Shell::HandleServiceProtocolMessage(
1668 std::string_view method,
1670 rapidjson::Document* response) {
1671 auto found = service_protocol_handlers_.find(method);
1672 if (found != service_protocol_handlers_.end()) {
1673 return found->second.second(
params, response);
1683 if (!weak_engine_) {
1688 weak_engine_->GetUIIsolateMainPort(),
1689 weak_engine_->GetUIIsolateName(),
1694 std::string error_details) {
1695 auto& allocator = response->GetAllocator();
1696 response->SetObject();
1697 const int64_t kInvalidParams = -32602;
1698 response->AddMember(
"code", kInvalidParams, allocator);
1699 response->AddMember(
"message",
"Invalid params", allocator);
1701 rapidjson::Value details(rapidjson::kObjectType);
1702 details.AddMember(
"details", std::move(error_details), allocator);
1703 response->AddMember(
"data", details, allocator);
1709 auto& allocator = response->GetAllocator();
1710 response->SetObject();
1711 const int64_t kJsonServerError = -32000;
1712 response->AddMember(
"code", kJsonServerError, allocator);
1713 response->AddMember(
"message", std::move(
message), allocator);
1717bool Shell::OnServiceProtocolScreenshot(
1718 const ServiceProtocol::Handler::ServiceProtocolMap&
params,
1719 rapidjson::Document* response) {
1721 auto screenshot = rasterizer_->ScreenshotLastLayerTree(
1722 Rasterizer::ScreenshotType::CompressedImage,
true);
1723 if (screenshot.data) {
1724 response->SetObject();
1725 auto& allocator = response->GetAllocator();
1726 response->AddMember(
"type",
"Screenshot", allocator);
1727 rapidjson::Value
image;
1728 image.SetString(
static_cast<const char*
>(screenshot.data->data()),
1729 screenshot.data->size(), allocator);
1730 response->AddMember(
"screenshot",
image, allocator);
1738bool Shell::OnServiceProtocolScreenshotSKP(
1739 const ServiceProtocol::Handler::ServiceProtocolMap&
params,
1740 rapidjson::Document* response) {
1744 response,
"Cannot capture SKP screenshot with Impeller enabled.");
1747 auto screenshot = rasterizer_->ScreenshotLastLayerTree(
1748 Rasterizer::ScreenshotType::SkiaPicture,
true);
1749 if (screenshot.data) {
1750 response->SetObject();
1751 auto& allocator = response->GetAllocator();
1752 response->AddMember(
"type",
"ScreenshotSkp", allocator);
1753 rapidjson::Value
skp;
1754 skp.SetString(
static_cast<const char*
>(screenshot.data->data()),
1755 screenshot.data->size(), allocator);
1756 response->AddMember(
"skp",
skp, allocator);
1764bool Shell::OnServiceProtocolRunInView(
1765 const ServiceProtocol::Handler::ServiceProtocolMap&
params,
1766 rapidjson::Document* response) {
1769 if (
params.count(
"mainScript") == 0) {
1771 "'mainScript' parameter is missing.");
1775 if (
params.count(
"assetDirectory") == 0) {
1777 "'assetDirectory' parameter is missing.");
1781 std::string main_script_path =
1783 std::string asset_directory_path =
1786 auto main_script_file_mapping =
1790 auto isolate_configuration = IsolateConfiguration::CreateForKernel(
1791 std::move(main_script_file_mapping));
1793 RunConfiguration configuration(std::move(isolate_configuration));
1795 configuration.SetEntrypointAndLibrary(engine_->GetLastEntrypoint(),
1796 engine_->GetLastEntrypointLibrary());
1797 configuration.SetEntrypointArgs(engine_->GetLastEntrypointArgs());
1799 configuration.AddAssetResolver(std::make_unique<DirectoryAssetBundle>(
1806 auto old_asset_manager = engine_->GetAssetManager();
1807 if (old_asset_manager !=
nullptr) {
1808 for (
auto& old_resolver : old_asset_manager->TakeResolvers()) {
1809 if (old_resolver->IsValidAfterAssetManagerChange()) {
1810 configuration.AddAssetResolver(std::move(old_resolver));
1815 auto& allocator = response->GetAllocator();
1816 response->SetObject();
1817 if (engine_->Restart(std::move(configuration))) {
1818 response->AddMember(
"type",
"Success", allocator);
1819 auto new_description = GetServiceProtocolDescription();
1820 rapidjson::Value view(rapidjson::kObjectType);
1821 new_description.Write(
this, view, allocator);
1822 response->AddMember(
"view", view, allocator);
1825 FML_DLOG(
ERROR) <<
"Could not run configuration in engine.";
1827 "Could not run configuration in engine.");
1836bool Shell::OnServiceProtocolFlushUIThreadTasks(
1837 const ServiceProtocol::Handler::ServiceProtocolMap&
params,
1838 rapidjson::Document* response) {
1846 response->SetObject();
1847 response->AddMember(
"type",
"Success", response->GetAllocator());
1851bool Shell::OnServiceProtocolGetDisplayRefreshRate(
1852 const ServiceProtocol::Handler::ServiceProtocolMap&
params,
1853 rapidjson::Document* response) {
1855 response->SetObject();
1856 response->AddMember(
"type",
"DisplayRefreshRate", response->GetAllocator());
1857 response->AddMember(
"fps", display_manager_->GetMainDisplayRefreshRate(),
1858 response->GetAllocator());
1862double Shell::GetMainDisplayRefreshRate() {
1863 return display_manager_->GetMainDisplayRefreshRate();
1873 [
engine = engine_->GetWeakPtr(), factory = std::move(factory),
1876 engine->GetImageGeneratorRegistry()->AddFactory(factory, priority);
1881bool Shell::OnServiceProtocolGetSkSLs(
1882 const ServiceProtocol::Handler::ServiceProtocolMap&
params,
1883 rapidjson::Document* response) {
1885 response->SetObject();
1886 response->AddMember(
"type",
"GetSkSLs", response->GetAllocator());
1888 rapidjson::Value shaders_json(rapidjson::kObjectType);
1889 PersistentCache* persistent_cache = PersistentCache::GetCacheForProcess();
1890 std::vector<PersistentCache::SkSLCache> sksls = persistent_cache->LoadSkSLs();
1891 for (
const auto& sksl : sksls) {
1892 size_t b64_size = Base64::EncodedSize(sksl.value->size());
1894 char* b64_char =
static_cast<char*
>(b64_data->writable_data());
1895 Base64::Encode(sksl.value->data(), sksl.value->size(), b64_char);
1896 b64_char[b64_size] = 0;
1897 rapidjson::Value shader_value(b64_char, response->GetAllocator());
1898 std::string_view key_view(
reinterpret_cast<const char*
>(sksl.key->data()),
1901 if (!encode_result.first) {
1904 rapidjson::Value shader_key(encode_result.second, response->GetAllocator());
1905 shaders_json.AddMember(shader_key, shader_value, response->GetAllocator());
1907 response->AddMember(
"SkSLs", shaders_json, response->GetAllocator());
1911bool Shell::OnServiceProtocolEstimateRasterCacheMemory(
1912 const ServiceProtocol::Handler::ServiceProtocolMap&
params,
1913 rapidjson::Document* response) {
1915 const auto& raster_cache = rasterizer_->compositor_context()->raster_cache();
1916 response->SetObject();
1917 response->AddMember(
"type",
"EstimateRasterCacheMemory",
1918 response->GetAllocator());
1919 response->AddMember<uint64_t>(
"layerBytes",
1920 raster_cache.EstimateLayerCacheByteSize(),
1921 response->GetAllocator());
1922 response->AddMember<uint64_t>(
"pictureBytes",
1923 raster_cache.EstimatePictureCacheByteSize(),
1924 response->GetAllocator());
1929bool Shell::OnServiceProtocolSetAssetBundlePath(
1930 const ServiceProtocol::Handler::ServiceProtocolMap&
params,
1931 rapidjson::Document* response) {
1934 if (
params.count(
"assetDirectory") == 0) {
1936 "'assetDirectory' parameter is missing.");
1940 auto& allocator = response->GetAllocator();
1941 response->SetObject();
1943 auto asset_manager = std::make_shared<AssetManager>();
1945 if (!asset_manager->PushFront(std::make_unique<DirectoryAssetBundle>(
1957 auto old_asset_manager = engine_->GetAssetManager();
1958 if (old_asset_manager !=
nullptr) {
1959 for (
auto& old_resolver : old_asset_manager->TakeResolvers()) {
1960 if (old_resolver->IsValidAfterAssetManagerChange()) {
1961 asset_manager->PushBack(std::move(old_resolver));
1966 if (engine_->UpdateAssetManager(asset_manager)) {
1967 response->AddMember(
"type",
"Success", allocator);
1968 auto new_description = GetServiceProtocolDescription();
1969 rapidjson::Value view(rapidjson::kObjectType);
1970 new_description.Write(
this, view, allocator);
1971 response->AddMember(
"view", view, allocator);
1984 double device_pixel_ratio,
1986 rapidjson::Document* response) {
1987 auto& allocator = response->GetAllocator();
1995 result.AddMember(
"top", bounds.top(), allocator);
1996 result.AddMember(
"left", bounds.left(), allocator);
1997 result.AddMember(
"width", bounds.width(), allocator);
1998 result.AddMember(
"height", bounds.height(), allocator);
2001 if (snapshot_bytes) {
2002 rapidjson::Value
image;
2004 const uint8_t*
data =
2005 reinterpret_cast<const uint8_t*
>(snapshot_bytes->data());
2006 for (
size_t i = 0; i < snapshot_bytes->size(); i++) {
2014bool Shell::OnServiceProtocolRenderFrameWithRasterStats(
2015 const ServiceProtocol::Handler::ServiceProtocolMap&
params,
2016 rapidjson::Document* response) {
2021 const char*
error =
"Raster status not supported on Impeller backend.";
2022 ServiceProtocolFailureError(response,
error);
2030 if (
auto last_layer_tree = rasterizer_->GetLastLayerTree(view_id)) {
2031 auto& allocator = response->GetAllocator();
2032 response->SetObject();
2033 response->AddMember(
"type",
"RenderFrameWithRasterStats", allocator);
2038 auto frame_timings_recorder = std::make_unique<FrameTimingsRecorder>();
2040 frame_timings_recorder->RecordVsync(now, now);
2041 frame_timings_recorder->RecordBuildStart(now);
2042 frame_timings_recorder->RecordBuildEnd(now);
2044 last_layer_tree->enable_leaf_layer_tracing(
true);
2045 rasterizer_->DrawLastLayerTrees(std::move(frame_timings_recorder));
2046 last_layer_tree->enable_leaf_layer_tracing(
false);
2048 rapidjson::Value snapshots;
2049 snapshots.SetArray();
2051 LayerSnapshotStore&
store =
2052 rasterizer_->compositor_context()->snapshot_store();
2053 for (
const LayerSnapshotData& data :
store) {
2059 response->AddMember(
"snapshots", snapshots, allocator);
2061 const auto& frame_size = ExpectedFrameSize(view_id);
2062 response->AddMember(
"frame_width", frame_size.width(), allocator);
2063 response->AddMember(
"frame_height", frame_size.height(), allocator);
2068 "Failed to render the last frame with raster stats."
2069 " Rasterizer does not hold a valid last layer tree."
2070 " This could happen if this method was invoked before a frame was "
2078void Shell::SendFontChangeNotification() {
2081 rapidjson::Document document;
2082 document.SetObject();
2083 auto& allocator = document.GetAllocator();
2084 rapidjson::Value message_value;
2085 message_value.SetString(kFontChange, allocator);
2086 document.AddMember(
kTypeKey, message_value, allocator);
2088 rapidjson::StringBuffer
buffer;
2089 rapidjson::Writer<rapidjson::StringBuffer> writer(
buffer);
2090 document.Accept(writer);
2092 std::unique_ptr<PlatformMessage> fontsChangeMessage =
2093 std::make_unique<flutter::PlatformMessage>(
2096 OnPlatformViewDispatchPlatformMessage(std::move(fontsChangeMessage));
2099bool Shell::OnServiceProtocolReloadAssetFonts(
2100 const ServiceProtocol::Handler::ServiceProtocolMap&
params,
2101 rapidjson::Document* response) {
2106 engine_->GetFontCollection().RegisterFonts(engine_->GetAssetManager());
2107 engine_->GetFontCollection().GetFontCollection()->ClearFontFamilyCache();
2108 SendFontChangeNotification();
2110 auto& allocator = response->GetAllocator();
2111 response->SetObject();
2112 response->AddMember(
"type",
"Success", allocator);
2117void Shell::OnPlatformViewAddView(int64_t view_id,
2124 <<
"Unexpected request to add the implicit view #"
2133 engine->AddView(view_id, viewport_metrics, callback);
2138void Shell::OnPlatformViewRemoveView(int64_t view_id,
2144 <<
"Unexpected request to remove the implicit view #"
2147 expected_frame_sizes_.erase(view_id);
2150 engine = engine_->GetWeakPtr(),
2151 rasterizer = rasterizer_->GetWeakPtr(),
2156 bool removed = engine->RemoveView(view_id);
2163 task_runners.GetRasterTaskRunner()->PostTask([rasterizer, view_id]() {
2165 rasterizer->CollectView(view_id);
2173 bool base64_encode) {
2175 switch (screenshot_type) {
2176 case Rasterizer::ScreenshotType::SkiaPicture:
2178 <<
"Impeller backend cannot produce ScreenshotType::SkiaPicture.";
2180 case Rasterizer::ScreenshotType::UncompressedImage:
2181 case Rasterizer::ScreenshotType::CompressedImage:
2182 case Rasterizer::ScreenshotType::SurfaceData:
2191 rasterizer = GetRasterizer(),
2197 screenshot = rasterizer->ScreenshotLastLayerTree(screenshot_type,
2208 if (
task_runners_.GetUITaskRunner()->RunsTasksOnCurrentThread() ||
2209 task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread()) {
2211 "WaitForFirstFrame called from thread that can't wait "
2212 "because it is responsible for generating the frame.");
2216 auto now = std::chrono::steady_clock::now();
2217 auto max_duration = std::chrono::steady_clock::time_point::max() - now;
2218 auto desired_duration = std::chrono::milliseconds(timeout.ToMilliseconds());
2220 now + (desired_duration > max_duration ? max_duration : desired_duration);
2222 std::unique_lock<std::mutex> lock(waiting_for_first_frame_mutex_);
2223 bool success = waiting_for_first_frame_condition_.wait_until(
2224 lock,
duration, [&waiting_for_first_frame = waiting_for_first_frame_] {
2225 return !waiting_for_first_frame.load();
2234bool Shell::ReloadSystemFonts() {
2241 engine_->SetupDefaultFontManager();
2242 engine_->GetFontCollection().GetFontCollection()->ClearFontFamilyCache();
2245 SendFontChangeNotification();
2249std::shared_ptr<const fml::SyncSwitch> Shell::GetIsGpuDisabledSyncSwitch()
2251 return is_gpu_disabled_sync_switch_;
2256 switch (availability) {
2257 case GpuAvailability::kAvailable:
2258 is_gpu_disabled_sync_switch_->SetSwitch(
false);
2260 case GpuAvailability::kFlushAndMakeUnavailable: {
2265 io_manager->GetSkiaUnrefQueue()->Drain();
2271 case GpuAvailability::kUnavailable:
2272 is_gpu_disabled_sync_switch_->SetSwitch(
true);
2279void Shell::OnDisplayUpdates(std::vector<std::unique_ptr<Display>> displays) {
2283 std::vector<DisplayData> display_data;
2284 display_data.reserve(displays.size());
2285 for (
const auto& display : displays) {
2286 display_data.push_back(display->GetDisplayData());
2289 [
engine = engine_->GetWeakPtr(),
2290 display_data = std::move(display_data)]() {
2292 engine->SetDisplays(display_data);
2296 display_manager_->HandleDisplayUpdates(std::move(displays));
2303const std::shared_ptr<PlatformMessageHandler>&
2304Shell::GetPlatformMessageHandler()
const {
2305 return platform_message_handler_;
2308const std::weak_ptr<VsyncWaiter> Shell::GetVsyncWaiter()
const {
2312 return engine_->GetVsyncWaiter();
2315const std::shared_ptr<fml::ConcurrentTaskRunner>
2316Shell::GetConcurrentWorkerTaskRunner()
const {
2321 return vm_->GetConcurrentWorkerTaskRunner();
2324SkISize Shell::ExpectedFrameSize(int64_t view_id) {
2325 auto found = expected_frame_sizes_.find(view_id);
2326 if (found == expected_frame_sizes_.end()) {
2329 return found->second;
static sk_sp< SkData > MakeUninitialized(size_t length)
AssetResolverType
Identifies the type of AssetResolver an instance is.
static fml::RefPtr< const DartSnapshot > VMSnapshotFromSettings(const Settings &settings)
From the fields present in the given settings object, infer the core snapshot.
static fml::RefPtr< const DartSnapshot > IsolateSnapshotFromSettings(const Settings &settings)
From the fields present in the given settings object, infer the isolate snapshot.
static DartVMRef Create(const Settings &settings, fml::RefPtr< const DartSnapshot > vm_snapshot=nullptr, fml::RefPtr< const DartSnapshot > isolate_snapshot=nullptr)
Describes a running instance of the Dart VM. There may only be one running instance of the Dart VM in...
While the engine operates entirely on the UI task runner, it needs the capabilities of the other comp...
RunStatus
Indicates the result of the call to Engine::Run.
uint64_t GetPictureCacheCount() const
uint64_t GetLayerCacheBytes() const
uint64_t GetFrameNumber() const
uint64_t GetPictureCacheBytes() const
uint64_t GetLayerCacheCount() const
fml::TimePoint Get(Phase phase) const
sk_sp< SkData > GetSnapshot() const
int64_t GetLayerUniqueId() const
fml::TimeDelta GetDuration() const
const SkISize & frame_size() const
static void SetCacheSkSL(bool value)
ScreenshotType
The type of the screenshot to obtain of the previously rendered layer tree.
Specifies all the configuration required by the runtime library to launch the root isolate....
std::map< std::string_view, std::string_view > ServiceProtocolMap
static const std::string_view kSetAssetBundlePathExtensionName
static const std::string_view kReloadAssetFonts
static const std::string_view kScreenshotSkpExtensionName
static const std::string_view kScreenshotExtensionName
static const std::string_view kGetDisplayRefreshRateExtensionName
static const std::string_view kRunInViewExtensionName
static const std::string_view kEstimateRasterCacheMemoryExtensionName
static const std::string_view kGetSkSLsExtensionName
static const std::string_view kRenderFrameWithRasterStatsExtensionName
static const std::string_view kFlushUIThreadTasksExtensionName
static std::unique_ptr< Shell > Create(const PlatformData &platform_data, const TaskRunners &task_runners, Settings settings, const CreateCallback< PlatformView > &on_create_platform_view, const CreateCallback< Rasterizer > &on_create_rasterizer, bool is_gpu_disabled=false)
Creates a shell instance using the provided settings. The callbacks to create the various shell subco...
static std::pair< DartVMRef, fml::RefPtr< const DartSnapshot > > InferVmInitDataFromSettings(Settings &settings)
std::function< std::unique_ptr< Engine >(Engine::Delegate &delegate, const PointerDataDispatcherMaker &dispatcher_maker, DartVM &vm, fml::RefPtr< const DartSnapshot > isolate_snapshot, TaskRunners task_runners, const PlatformData &platform_data, Settings settings, std::unique_ptr< Animator > animator, fml::WeakPtr< IOManager > io_manager, fml::RefPtr< SkiaUnrefQueue > unref_queue, fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate, std::shared_ptr< VolatilePathTracker > volatile_path_tracker, const std::shared_ptr< fml::SyncSwitch > &gpu_disabled_switch, impeller::RuntimeStageBackend runtime_stage_type)> EngineCreateCallback
std::function< std::unique_ptr< T >(Shell &)> CreateCallback
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
fml::RefPtr< fml::TaskRunner > GetUITaskRunner() const
fml::RefPtr< fml::TaskRunner > GetIOTaskRunner() const
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
A Mapping like NonOwnedMapping, but uses Free as its release proc.
static MallocMapping Copy(const T *begin, const T *end)
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
virtual bool RunsTasksOnCurrentThread()
constexpr int64_t ToMicroseconds() const
static constexpr TimeDelta FromMilliseconds(int64_t millis)
TimeDelta ToEpochDelta() const
DART_EXPORT void Dart_NotifyLowMemory(void)
const EmbeddedViewParams * params
TaskRunners task_runners_
fml::WeakPtr< IOManager > io_manager_
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
static const uint8_t buffer[]
const uint8_t uint32_t uint32_t GError ** error
#define FML_DLOG(severity)
#define FML_LOG(severity)
#define FML_CHECK(condition)
#define FML_DCHECK(condition)
static constexpr char kTypeKey[]
constexpr SkCodecs::Decoder Decoder()
constexpr SkCodecs::Decoder Decoder()
constexpr SkCodecs::Decoder Decoder()
constexpr SkCodecs::Decoder Decoder()
constexpr SkCodecs::Decoder Decoder()
constexpr SkCodecs::Decoder Decoder()
constexpr SkCodecs::Decoder Decoder()
static impeller::RuntimeStageBackend DetermineRuntimeStageBackend(const std::shared_ptr< impeller::Context > &impeller_context)
constexpr int64_t kFlutterImplicitViewId
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
static void ServiceProtocolFailureError(rapidjson::Document *response, std::string message)
std::function< std::shared_ptr< ImageGenerator >(sk_sp< SkData > buffer)> ImageGeneratorFactory
ImageGeneratorFactory is the top level primitive for specifying an image decoder in Flutter....
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
void InitSkiaEventTracer(bool enabled, const std::optional< std::vector< std::string > > &allowlist)
std::function< std::unique_ptr< PointerDataDispatcher >(PointerDataDispatcher::Delegate &)> PointerDataDispatcherMaker
Signature for constructing PointerDataDispatcher.
constexpr char kFontChange[]
static void ServiceProtocolParameterError(rapidjson::Document *response, std::string error_details)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
constexpr char kTypeKey[]
constexpr char kSystemChannel[]
constexpr char kSkiaChannel[]
static rapidjson::Value SerializeLayerSnapshot(double device_pixel_ratio, const LayerSnapshotData &snapshot, rapidjson::Document *response)
GpuAvailability
Values for |Shell::SetGpuAvailability|.
void InitializeICU(const std::string &icu_data_path)
void InitializeICUFromMapping(std::unique_ptr< Mapping > mapping)
std::string FromURI(const std::string &uri)
void TraceSetAllowlist(const std::vector< std::string > &allowlist)
std::chrono::duration< double, std::milli > Milliseconds
void SetLogSettings(const LogSettings &settings)
constexpr LogSeverity kLogError
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
internal::CopyableLambda< T > MakeCopyable(T lambda)
std::pair< bool, std::string > Base32Encode(std::string_view input)
constexpr Milliseconds kDefaultFrameBudget
constexpr LogSeverity kLogInfo
std::function< void()> closure
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
Milliseconds RefreshRateToFrameBudget(T refresh_rate)
void SetLogHandler(std::function< void(const char *)> handler)
static constexpr SkISize MakeEmpty()
static constexpr SkISize Make(int32_t w, int32_t h)
A POD type used to return the screenshot data along with the size of the frame.
double device_pixel_ratio
LogSeverity min_log_level
Represents the 2 code paths available when calling |SyncSwitchExecute|.
Handlers & SetIfFalse(const std::function< void()> &handler)
Sets the handler that will be executed if the |SyncSwitch| is false.
#define TRACE_FLOW_BEGIN(category, name, id)
#define TRACE_EVENT0(category_group, name)
#define TRACE_EVENT_ASYNC_END0(category_group, name, id)
#define TRACE_EVENT0_WITH_FLOW_IDS(category_group, name, flow_id_count, flow_ids)
#define TRACE_EVENT_ASYNC_BEGIN0(category_group, name, id)