5#ifndef FLUTTER_SHELL_COMMON_RASTERIZER_H_
6#define FLUTTER_SHELL_COMMON_RASTERIZER_H_
11#include <unordered_map>
28#if IMPELLER_SUPPORTS_RENDERING
38#include "third_party/skia/include/core/SkData.h"
39#include "third_party/skia/include/core/SkImage.h"
40#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
42#if !IMPELLER_SUPPORTS_RENDERING
46class ImpellerContextFuture;
90 FrameItem(std::vector<std::unique_ptr<LayerTreeTask>> tasks,
209 std::shared_ptr<impeller::ImpellerContextFuture> impeller_context);
226 void Setup(std::unique_ptr<Surface> surface);
306 std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder);
440 const std::string& p_format,
497 const std::shared_ptr<ExternalViewEmbedder>& view_embedder);
508 std::unique_ptr<SnapshotSurfaceProducer> producer);
517 return compositor_context_.get();
607 enum class DoDrawStatus {
621 struct DoDrawResult {
625 DoDrawStatus status = DoDrawStatus::kDone;
633 std::unique_ptr<FrameItem> resubmitted_item;
637 std::unique_ptr<LayerTreeTask> last_successful_task;
638 std::optional<DrawSurfaceStatus> last_draw_status;
642 std::unique_ptr<GpuImageResult> MakeSkiaGpuImage(
643 sk_sp<DisplayList> display_list,
644 const SkImageInfo& image_info)
override;
647 void MakeRasterSnapshot(
648 sk_sp<DisplayList> display_list,
650 std::function<
void(sk_sp<DlImage>)>
callback)
override;
653 sk_sp<DlImage> MakeRasterSnapshotSync(sk_sp<DisplayList> display_list,
654 DlISize picture_size)
override;
657 sk_sp<SkImage> ConvertToRasterImage(sk_sp<SkImage>
image)
override;
660 void CacheRuntimeStage(
661 const std::shared_ptr<impeller::RuntimeStage>& runtime_stage)
override;
664 bool MakeRenderContextCurrent()
override;
673 const std::unique_ptr<Surface>& GetSurface()
const override {
678 bool IsAiksContextInitialized()
const override {
679#if IMPELLER_SUPPORTS_RENDERING
680 return surface_ && surface_->GetAiksContext();
687 std::shared_ptr<impeller::AiksContext> GetAiksContext()
const override {
688#if IMPELLER_SUPPORTS_RENDERING
690 return surface_->GetAiksContext();
692 if (
auto context = impeller_context_->GetContext()) {
693 return std::make_shared<impeller::AiksContext>(
701 const std::unique_ptr<SnapshotSurfaceProducer>& GetSnapshotSurfaceProducer()
703 return snapshot_surface_producer_;
707 std::shared_ptr<const fml::SyncSwitch> GetIsGpuDisabledSyncSwitch()
721 std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder,
722 std::vector<std::unique_ptr<LayerTreeTask>> tasks);
725 DoDrawResult DrawToSurfaces(
726 FrameTimingsRecorder& frame_timings_recorder,
727 std::vector<std::unique_ptr<LayerTreeTask>> tasks);
739 std::unique_ptr<FrameItem> DrawToSurfacesUnsafe(
740 FrameTimingsRecorder& frame_timings_recorder,
741 std::vector<std::unique_ptr<LayerTreeTask>> tasks);
751 float device_pixel_ratio,
752 std::optional<fml::TimePoint> presentation_time);
754 ViewRecord& EnsureViewRecord(int64_t
view_id);
756 void FireNextFrameCallbackIfPresent();
758 static bool ShouldResubmitFrame(
const DoDrawResult& result);
759 static DrawStatus ToDrawStatus(DoDrawStatus status);
761 bool is_torn_down_ =
false;
764 std::shared_ptr<impeller::ImpellerContextFuture> impeller_context_;
765 std::unique_ptr<Surface> surface_;
766 std::unique_ptr<SnapshotSurfaceProducer> snapshot_surface_producer_;
767 std::unique_ptr<flutter::CompositorContext> compositor_context_;
768 std::unordered_map<int64_t, ViewRecord> view_records_;
770 bool user_override_resource_cache_bytes_ =
false;
771 std::optional<size_t> max_cache_bytes_;
773 std::shared_ptr<ExternalViewEmbedder> external_view_embedder_;
774 std::unique_ptr<SnapshotController> snapshot_controller_;
Used to forward events from the rasterizer to interested subsystems. Currently, the shell sets itself...
virtual const TaskRunners & GetTaskRunners() const =0
Task runners used by the shell.
virtual void OnFrameRasterized(const FrameTiming &frame_timing)=0
Notifies the delegate that a frame has been rendered. The rasterizer collects profiling information f...
virtual const Settings & GetSettings() const =0
virtual std::shared_ptr< const fml::SyncSwitch > GetIsGpuDisabledSyncSwitch() const =0
virtual const fml::RefPtr< fml::RasterThreadMerger > GetParentRasterThreadMerger() const =0
The raster thread merger from parent shell's rasterizer.
virtual bool ShouldDiscardLayerTree(int64_t view_id, const flutter::LayerTree &tree)=0
virtual fml::Milliseconds GetFrameBudget()=0
virtual fml::TimePoint GetLatestFrameTargetTime() const =0
void SetNextFrameCallback(const fml::closure &callback)
Sets a callback that will be executed when the next layer tree in rendered to the on-screen surface....
fml::RefPtr< fml::RasterThreadMerger > GetRasterThreadMerger()
Returns the raster thread merger used by this rasterizer. This may be nullptr.
bool IsTornDown()
Returns whether TearDown has been called.
void SetSnapshotSurfaceProducer(std::unique_ptr< SnapshotSurfaceProducer > producer)
Set the snapshot surface producer. This is done on shell initialization. This is non-null on platform...
flutter::LayerTree * GetLastLayerTree(int64_t view_id)
Returns the last successfully drawn layer tree for the given view, or nullptr if there isn't any....
ScreenshotType
The type of the screenshot to obtain of the previously rendered layer tree.
void DisableThreadMergerIfNeeded()
Disables the thread merger if the external view embedder supports dynamic thread merging.
~Rasterizer()
Destroys the rasterizer. This must happen on the raster task runner. All GPU resources are collected ...
DrawStatus Draw(const std::shared_ptr< FramePipeline > &pipeline)
Takes the next item from the layer tree pipeline and executes the raster thread frame workload for th...
fml::TaskRunnerAffineWeakPtr< Rasterizer > GetWeakPtr() const
Gets a weak pointer to the rasterizer. The rasterizer may only be accessed on the raster task runner.
void SetResourceCacheMaxBytes(size_t max_bytes, bool from_user)
Skia has no notion of time. To work around the performance implications of this, it may cache GPU res...
void DrawLastLayerTrees(std::unique_ptr< FrameTimingsRecorder > frame_timings_recorder)
Draws the last layer trees with their last configuration. This may seem entirely redundant at first g...
MakeGpuImageBehavior
How to handle calls to MakeSkiaGpuImage.
@ kGpu
MakeSkiaGpuImage returns a GPU resident image, if possible.
void TeardownExternalViewEmbedder()
Releases any resource used by the external view embedder. For example, overlay surfaces or Android vi...
void EnableThreadMergerIfNeeded()
Enables the thread merger if the external view embedder supports dynamic thread merging.
fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > GetSnapshotDelegate() const
std::shared_ptr< flutter::TextureRegistry > GetTextureRegistry() override
Gets the registry of external textures currently in use by the rasterizer. These textures may be upda...
void SetImpellerContext(std::shared_ptr< impeller::ImpellerContextFuture > impeller_context)
std::optional< size_t > GetResourceCacheMaxBytes() const
The current value of Skia's resource cache size, if a surface is present.
void Teardown()
Releases the previously set up on-screen render surface and collects associated resources....
GrDirectContext * GetGrContext() override
void CollectView(int64_t view_id)
Deallocate the resources for displaying a view.
void Setup(std::unique_ptr< Surface > surface)
Rasterizers may be created well before an on-screen surface is available for rendering....
std::optional< DrawSurfaceStatus > GetLastDrawStatus(int64_t view_id)
Returns the last status of drawing the specific view.
void NotifyLowMemoryWarning() const
Notifies the rasterizer that there is a low memory situation and it must purge as many unnecessary re...
void SetExternalViewEmbedder(const std::shared_ptr< ExternalViewEmbedder > &view_embedder)
Set the External View Embedder. This is done on shell initialization. This is non-null on platforms t...
Screenshot ScreenshotLastLayerTree(ScreenshotType type, bool base64_encode)
Screenshots the last layer tree to one of the supported screenshot types and optionally Base 64 encod...
flutter::CompositorContext * compositor_context()
Returns a pointer to the compositor context used by this rasterizer. This pointer will never be nullp...
The refresh rate interface for Stopwatch.
Describes the fixed function and programmable aspects of rendering and compute operations performed b...
static std::shared_ptr< TypographerContext > Make()
FlutterVulkanImage * image
G_BEGIN_DECLS FlutterViewId view_id
FlutterDesktopBinaryReply callback
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
impeller::ISize32 DlISize
std::chrono::duration< double, std::milli > Milliseconds
std::function< void()> closure
std::unique_ptr< FrameTimingsRecorder > frame_timings_recorder
FrameItem(std::vector< std::unique_ptr< LayerTreeTask > > tasks, std::unique_ptr< FrameTimingsRecorder > frame_timings_recorder)
std::vector< std::unique_ptr< LayerTreeTask > > layer_tree_tasks
A POD type used to return the screenshot data along with the size of the frame.
ScreenshotFormat pixel_format
Screenshot(const Screenshot &other)
The copy constructor for a screenshot.
Screenshot()
Creates an empty screenshot.
~Screenshot()
Destroys the screenshot object and releases underlying data.