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,
444 const std::shared_ptr<fml::ConcurrentTaskRunner>
458 static std::pair<DartVMRef, fml::RefPtr<const DartSnapshot>>
462 using ServiceProtocolHandler =
464 rapidjson::Document*)>;
470 std::mutex misbehaving_message_channels_mutex_;
471 std::set<std::string> misbehaving_message_channels_;
474 std::shared_ptr<ResourceCacheLimitCalculator>
475 resource_cache_limit_calculator_;
476 size_t resource_cache_limit_;
479 mutable std::mutex time_recorder_mutex_;
480 std::optional<fml::TimePoint> latest_frame_target_time_;
481 std::unique_ptr<PlatformView> platform_view_;
482 std::unique_ptr<Engine> engine_;
483 std::unique_ptr<Rasterizer> rasterizer_;
484 std::shared_ptr<ShellIOManager> io_manager_;
485 std::shared_ptr<fml::SyncSwitch> is_gpu_disabled_sync_switch_;
486 std::shared_ptr<PlatformMessageHandler> platform_message_handler_;
487 std::atomic<bool> route_messages_through_platform_thread_ =
false;
496 std::promise<fml::WeakPtr<ShellIOManager>> weak_io_manager_promise_;
497 std::shared_ptr<fml::BasicTaskRunner> shutdown_safe_io_task_runner_;
499 std::unordered_map<std::string_view,
500 std::pair<fml::RefPtr<fml::TaskRunner>,
501 ServiceProtocolHandler>
504 service_protocol_handlers_;
505 bool is_set_up_ =
false;
506 bool is_added_to_service_protocol_ =
false;
507 uint64_t next_pointer_flow_id_ = 0;
509 bool first_frame_rasterized_ =
false;
510 std::atomic<bool> waiting_for_first_frame_ =
true;
511 std::mutex waiting_for_first_frame_mutex_;
512 std::condition_variable waiting_for_first_frame_condition_;
516 std::atomic<bool> needs_report_timings_{
false};
520 bool frame_timings_report_scheduled_ =
false;
525 std::vector<int64_t> unreported_timings_;
529 std::unique_ptr<DisplayManager> display_manager_;
533 std::mutex resize_mutex_;
537 std::unordered_map<int64_t, BoxConstraints> expected_frame_constraints_;
540 double device_pixel_ratio_ = 0.0;
543 std::optional<fml::Milliseconds> cached_display_refresh_rate_;
546 size_t UnreportedFramesCount()
const;
551 const std::shared_ptr<ResourceCacheLimitCalculator>&
552 resource_cache_limit_calculator,
554 bool is_gpu_disabled);
556 static std::unique_ptr<Shell> CreateShellOnPlatformThread(
559 std::shared_ptr<ShellIOManager> parent_io_manager,
560 const std::shared_ptr<ResourceCacheLimitCalculator>&
561 resource_cache_limit_calculator,
569 bool is_gpu_disabled);
571 static std::unique_ptr<Shell> CreateWithSnapshot(
575 const std::shared_ptr<ShellIOManager>& parent_io_manager,
576 const std::shared_ptr<ResourceCacheLimitCalculator>&
577 resource_cache_limit_calculator,
581 const CreateCallback<PlatformView>& on_create_platform_view,
582 const CreateCallback<Rasterizer>& on_create_rasterizer,
584 bool is_gpu_disabled);
587 std::unique_ptr<Engine>
engine,
588 std::unique_ptr<Rasterizer> rasterizer,
589 const std::shared_ptr<ShellIOManager>& io_manager);
591 void ReportTimings();
594 void OnPlatformViewCreated(std::unique_ptr<Surface> surface)
override;
597 void OnPlatformViewDestroyed()
override;
600 void OnPlatformViewScheduleFrame()
override;
603 void OnPlatformViewAddView(int64_t
view_id,
608 void OnPlatformViewRemoveView(int64_t
view_id,
612 void OnPlatformViewSendViewFocusEvent(
const ViewFocusEvent& event)
override;
615 void OnPlatformViewSetViewportMetrics(
620 void OnPlatformViewDispatchPlatformMessage(
621 std::unique_ptr<PlatformMessage>
message)
override;
624 void OnPlatformViewDispatchPointerDataPacket(
625 std::unique_ptr<PointerDataPacket> packet)
override;
632 void OnPlatformViewDispatchSemanticsAction(int64_t
view_id,
638 void OnPlatformViewSetSemanticsEnabled(
bool enabled)
override;
641 void OnPlatformViewSetAccessibilityFeatures(int32_t flags)
override;
644 void OnPlatformViewRegisterTexture(
645 std::shared_ptr<flutter::Texture>
texture)
override;
648 void OnPlatformViewUnregisterTexture(int64_t
texture_id)
override;
651 void OnPlatformViewMarkTextureFrameAvailable(int64_t
texture_id)
override;
654 void OnPlatformViewSetNextFrameCallback(
const fml::closure& closure)
override;
657 const Settings& OnPlatformViewGetSettings()
const override;
660 std::shared_ptr<fml::BasicTaskRunner>
661 OnPlatformViewGetShutdownSafeIOTaskRunner()
const override;
664 void LoadDartDeferredLibrary(
665 intptr_t loading_unit_id,
666 std::unique_ptr<const fml::Mapping> snapshot_data,
667 std::unique_ptr<const fml::Mapping> snapshot_instructions)
override;
669 void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
670 const std::string error_message,
671 bool transient)
override;
674 void UpdateAssetResolverByType(
675 std::unique_ptr<AssetResolver> updated_asset_resolver,
680 uint64_t frame_number)
override;
686 void OnAnimatorUpdateLatestFrameTargetTime(
690 void OnAnimatorDraw(std::shared_ptr<FramePipeline>
pipeline)
override;
693 void OnAnimatorDrawLastLayerTrees(
694 std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder)
override;
697 void OnEngineUpdateSemantics(
703 void OnEngineSetApplicationLocale(std::string locale)
override;
706 void OnEngineSetSemanticsTreeEnabled(
bool enabled)
override;
709 void OnEngineHandlePlatformMessage(
710 std::unique_ptr<PlatformMessage>
message)
override;
712 void HandleEngineSkiaMessage(std::unique_ptr<PlatformMessage>
message);
715 void OnPreEngineRestart()
override;
718 void OnRootIsolateCreated()
override;
721 void UpdateIsolateDescription(
const std::string isolate_name,
722 int64_t isolate_port)
override;
725 void SetNeedsReportTimings(
bool value)
override;
728 std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocale(
729 const std::vector<std::string>& supported_locale_data)
override;
732 void RequestDartDeferredLibrary(intptr_t loading_unit_id)
override;
738 void OnEngineChannelUpdate(std::string
name,
bool listening)
override;
741 double GetScaledFontSize(
double unscaled_font_size,
742 int configuration_id)
const override;
748 void OnFrameRasterized(
const FrameTiming&)
override;
757 bool ShouldDiscardLayerTree(int64_t
view_id,
762 std::string_view method)
const override;
765 bool HandleServiceProtocolMessage(
766 std::string_view method,
768 rapidjson::Document* response)
override;
775 bool OnServiceProtocolScreenshot(
777 rapidjson::Document* response);
780 bool OnServiceProtocolScreenshotSKP(
782 rapidjson::Document* response);
785 bool OnServiceProtocolRunInView(
787 rapidjson::Document* response);
790 bool OnServiceProtocolFlushUIThreadTasks(
792 rapidjson::Document* response);
795 bool OnServiceProtocolSetAssetBundlePath(
797 rapidjson::Document* response);
800 bool OnServiceProtocolGetDisplayRefreshRate(
802 rapidjson::Document* response);
808 bool OnServiceProtocolGetSkSLs(
810 rapidjson::Document* response);
813 bool OnServiceProtocolEstimateRasterCacheMemory(
815 rapidjson::Document* response);
821 bool OnServiceProtocolReloadAssetFonts(
823 rapidjson::Document* response);
826 bool OnServiceProtocolGetPipelineUsage(
828 rapidjson::Document* response);
831 void SendFontChangeNotification();
834 size_t GetResourceCacheLimit()
override {
return resource_cache_limit_; };
838 std::unique_ptr<DirectoryAssetBundle> RestoreOriginalAssetResolver();
840 BoxConstraints ExpectedFrameConstraints(int64_t
view_id);
844 std::unique_ptr<fml::TaskRunnerAffineWeakPtrFactory<Shell>> weak_factory_gpu_;