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;
612 void OnPlatformViewDispatchSemanticsAction(int64_t
view_id,
618 void OnPlatformViewSetSemanticsEnabled(
bool enabled)
override;
621 void OnPlatformViewSetAccessibilityFeatures(int32_t flags)
override;
624 void OnPlatformViewRegisterTexture(
625 std::shared_ptr<flutter::Texture>
texture)
override;
628 void OnPlatformViewUnregisterTexture(int64_t
texture_id)
override;
631 void OnPlatformViewMarkTextureFrameAvailable(int64_t
texture_id)
override;
634 void OnPlatformViewSetNextFrameCallback(
const fml::closure& closure)
override;
637 const Settings& OnPlatformViewGetSettings()
const override;
640 void LoadDartDeferredLibrary(
641 intptr_t loading_unit_id,
642 std::unique_ptr<const fml::Mapping> snapshot_data,
643 std::unique_ptr<const fml::Mapping> snapshot_instructions)
override;
645 void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
646 const std::string error_message,
647 bool transient)
override;
650 void UpdateAssetResolverByType(
651 std::unique_ptr<AssetResolver> updated_asset_resolver,
656 uint64_t frame_number)
override;
662 void OnAnimatorUpdateLatestFrameTargetTime(
666 void OnAnimatorDraw(std::shared_ptr<FramePipeline> pipeline)
override;
669 void OnAnimatorDrawLastLayerTrees(
670 std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder)
override;
673 void OnEngineUpdateSemantics(
679 void OnEngineSetApplicationLocale(std::string locale)
override;
682 void OnEngineSetSemanticsTreeEnabled(
bool enabled)
override;
685 void OnEngineHandlePlatformMessage(
686 std::unique_ptr<PlatformMessage>
message)
override;
688 void HandleEngineSkiaMessage(std::unique_ptr<PlatformMessage>
message);
691 void OnPreEngineRestart()
override;
694 void OnRootIsolateCreated()
override;
697 void UpdateIsolateDescription(
const std::string isolate_name,
698 int64_t isolate_port)
override;
701 void SetNeedsReportTimings(
bool value)
override;
704 std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocale(
705 const std::vector<std::string>& supported_locale_data)
override;
708 void RequestDartDeferredLibrary(intptr_t loading_unit_id)
override;
714 void OnEngineChannelUpdate(std::string
name,
bool listening)
override;
717 double GetScaledFontSize(
double unscaled_font_size,
718 int configuration_id)
const override;
724 void OnFrameRasterized(
const FrameTiming&)
override;
733 bool ShouldDiscardLayerTree(int64_t
view_id,
738 std::string_view method)
const override;
741 bool HandleServiceProtocolMessage(
742 std::string_view method,
744 rapidjson::Document* response)
override;
751 bool OnServiceProtocolScreenshot(
753 rapidjson::Document* response);
756 bool OnServiceProtocolScreenshotSKP(
758 rapidjson::Document* response);
761 bool OnServiceProtocolRunInView(
763 rapidjson::Document* response);
766 bool OnServiceProtocolFlushUIThreadTasks(
768 rapidjson::Document* response);
771 bool OnServiceProtocolSetAssetBundlePath(
773 rapidjson::Document* response);
776 bool OnServiceProtocolGetDisplayRefreshRate(
778 rapidjson::Document* response);
784 bool OnServiceProtocolGetSkSLs(
786 rapidjson::Document* response);
789 bool OnServiceProtocolEstimateRasterCacheMemory(
791 rapidjson::Document* response);
797 bool OnServiceProtocolReloadAssetFonts(
799 rapidjson::Document* response);
802 void SendFontChangeNotification();
805 size_t GetResourceCacheLimit()
override {
return resource_cache_limit_; };
809 std::unique_ptr<DirectoryAssetBundle> RestoreOriginalAssetResolver();
811 BoxConstraints ExpectedFrameConstraints(int64_t
view_id);
815 std::unique_ptr<fml::TaskRunnerAffineWeakPtrFactory<Shell>> weak_factory_gpu_;