122 typedef std::function<std::unique_ptr<Engine>(
130 std::unique_ptr<Animator> animator,
134 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch,
135 const std::shared_future<impeller::RuntimeStageBackend>&
136 runtime_stage_backend)>
170 static std::unique_ptr<Shell>
Create(
176 bool is_gpu_disabled =
false);
204 std::unique_ptr<Shell>
Spawn(
206 const std::string& initial_route,
431 const std::shared_ptr<fml::ConcurrentTaskRunner>
445 static std::pair<DartVMRef, fml::RefPtr<const DartSnapshot>>
449 using ServiceProtocolHandler =
451 rapidjson::Document*)>;
457 std::mutex misbehaving_message_channels_mutex_;
458 std::set<std::string> misbehaving_message_channels_;
461 std::shared_ptr<ResourceCacheLimitCalculator>
462 resource_cache_limit_calculator_;
463 size_t resource_cache_limit_;
466 mutable std::mutex time_recorder_mutex_;
467 std::optional<fml::TimePoint> latest_frame_target_time_;
468 std::unique_ptr<PlatformView> platform_view_;
469 std::unique_ptr<Engine> engine_;
470 std::unique_ptr<Rasterizer> rasterizer_;
471 std::shared_ptr<ShellIOManager> io_manager_;
472 std::shared_ptr<fml::SyncSwitch> is_gpu_disabled_sync_switch_;
473 std::shared_ptr<PlatformMessageHandler> platform_message_handler_;
474 std::atomic<bool> route_messages_through_platform_thread_ =
false;
483 std::unordered_map<std::string_view,
484 std::pair<fml::RefPtr<fml::TaskRunner>,
485 ServiceProtocolHandler>
488 service_protocol_handlers_;
489 bool is_set_up_ =
false;
490 bool is_added_to_service_protocol_ =
false;
491 uint64_t next_pointer_flow_id_ = 0;
493 bool first_frame_rasterized_ =
false;
494 std::atomic<bool> waiting_for_first_frame_ =
true;
495 std::mutex waiting_for_first_frame_mutex_;
496 std::condition_variable waiting_for_first_frame_condition_;
500 std::atomic<bool> needs_report_timings_{
false};
504 bool frame_timings_report_scheduled_ =
false;
509 std::vector<int64_t> unreported_timings_;
513 std::unique_ptr<DisplayManager> display_manager_;
517 std::mutex resize_mutex_;
521 std::unordered_map<int64_t, BoxConstraints> expected_frame_constraints_;
524 double device_pixel_ratio_ = 0.0;
527 std::optional<fml::Milliseconds> cached_display_refresh_rate_;
530 size_t UnreportedFramesCount()
const;
535 const std::shared_ptr<ResourceCacheLimitCalculator>&
536 resource_cache_limit_calculator,
538 bool is_gpu_disabled);
540 static std::unique_ptr<Shell> CreateShellOnPlatformThread(
543 std::shared_ptr<ShellIOManager> parent_io_manager,
544 const std::shared_ptr<ResourceCacheLimitCalculator>&
545 resource_cache_limit_calculator,
553 bool is_gpu_disabled);
555 static std::unique_ptr<Shell> CreateWithSnapshot(
559 const std::shared_ptr<ShellIOManager>& parent_io_manager,
560 const std::shared_ptr<ResourceCacheLimitCalculator>&
561 resource_cache_limit_calculator,
565 const CreateCallback<PlatformView>& on_create_platform_view,
566 const CreateCallback<Rasterizer>& on_create_rasterizer,
568 bool is_gpu_disabled);
571 std::unique_ptr<Engine>
engine,
572 std::unique_ptr<Rasterizer> rasterizer,
573 const std::shared_ptr<ShellIOManager>& io_manager);
575 void ReportTimings();
578 void OnPlatformViewCreated(std::unique_ptr<Surface> surface)
override;
581 void OnPlatformViewDestroyed()
override;
584 void OnPlatformViewScheduleFrame()
override;
587 void OnPlatformViewAddView(int64_t
view_id,
592 void OnPlatformViewRemoveView(int64_t
view_id,
596 void OnPlatformViewSendViewFocusEvent(
const ViewFocusEvent& event)
override;
599 void OnPlatformViewSetViewportMetrics(
604 void OnPlatformViewDispatchPlatformMessage(
605 std::unique_ptr<PlatformMessage>
message)
override;
608 void OnPlatformViewDispatchPointerDataPacket(
609 std::unique_ptr<PointerDataPacket> packet)
override;
616 void OnPlatformViewDispatchSemanticsAction(int64_t
view_id,
622 void OnPlatformViewSetSemanticsEnabled(
bool enabled)
override;
625 void OnPlatformViewSetAccessibilityFeatures(int32_t flags)
override;
628 void OnPlatformViewRegisterTexture(
629 std::shared_ptr<flutter::Texture>
texture)
override;
632 void OnPlatformViewUnregisterTexture(int64_t
texture_id)
override;
635 void OnPlatformViewMarkTextureFrameAvailable(int64_t
texture_id)
override;
638 void OnPlatformViewSetNextFrameCallback(
const fml::closure& closure)
override;
641 const Settings& OnPlatformViewGetSettings()
const override;
644 void LoadDartDeferredLibrary(
645 intptr_t loading_unit_id,
646 std::unique_ptr<const fml::Mapping> snapshot_data,
647 std::unique_ptr<const fml::Mapping> snapshot_instructions)
override;
649 void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
650 const std::string error_message,
651 bool transient)
override;
654 void UpdateAssetResolverByType(
655 std::unique_ptr<AssetResolver> updated_asset_resolver,
660 uint64_t frame_number)
override;
666 void OnAnimatorUpdateLatestFrameTargetTime(
670 void OnAnimatorDraw(std::shared_ptr<FramePipeline> pipeline)
override;
673 void OnAnimatorDrawLastLayerTrees(
674 std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder)
override;
677 void OnEngineUpdateSemantics(
683 void OnEngineSetApplicationLocale(std::string locale)
override;
686 void OnEngineSetSemanticsTreeEnabled(
bool enabled)
override;
689 void OnEngineHandlePlatformMessage(
690 std::unique_ptr<PlatformMessage>
message)
override;
692 void HandleEngineSkiaMessage(std::unique_ptr<PlatformMessage>
message);
695 void OnPreEngineRestart()
override;
698 void OnRootIsolateCreated()
override;
701 void UpdateIsolateDescription(
const std::string isolate_name,
702 int64_t isolate_port)
override;
705 void SetNeedsReportTimings(
bool value)
override;
708 std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocale(
709 const std::vector<std::string>& supported_locale_data)
override;
712 void RequestDartDeferredLibrary(intptr_t loading_unit_id)
override;
718 void OnEngineChannelUpdate(std::string
name,
bool listening)
override;
721 double GetScaledFontSize(
double unscaled_font_size,
722 int configuration_id)
const override;
728 void OnFrameRasterized(
const FrameTiming&)
override;
737 bool ShouldDiscardLayerTree(int64_t
view_id,
742 std::string_view method)
const override;
745 bool HandleServiceProtocolMessage(
746 std::string_view method,
748 rapidjson::Document* response)
override;
755 bool OnServiceProtocolScreenshot(
757 rapidjson::Document* response);
760 bool OnServiceProtocolScreenshotSKP(
762 rapidjson::Document* response);
765 bool OnServiceProtocolRunInView(
767 rapidjson::Document* response);
770 bool OnServiceProtocolFlushUIThreadTasks(
772 rapidjson::Document* response);
775 bool OnServiceProtocolSetAssetBundlePath(
777 rapidjson::Document* response);
780 bool OnServiceProtocolGetDisplayRefreshRate(
782 rapidjson::Document* response);
788 bool OnServiceProtocolGetSkSLs(
790 rapidjson::Document* response);
793 bool OnServiceProtocolEstimateRasterCacheMemory(
795 rapidjson::Document* response);
801 bool OnServiceProtocolReloadAssetFonts(
803 rapidjson::Document* response);
806 bool OnServiceProtocolGetPipelineUsage(
808 rapidjson::Document* response);
811 void SendFontChangeNotification();
814 size_t GetResourceCacheLimit()
override {
return resource_cache_limit_; };
818 std::unique_ptr<DirectoryAssetBundle> RestoreOriginalAssetResolver();
820 BoxConstraints ExpectedFrameConstraints(int64_t
view_id);
824 std::unique_ptr<fml::TaskRunnerAffineWeakPtrFactory<Shell>> weak_factory_gpu_;