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 MakeSkiaSnapshot(sk_sp<DisplayList> display_list,
649 std::function<
void(sk_sp<SkImage>)>
callback,
653 sk_sp<SkImage> MakeSkiaSnapshotSync(
654 sk_sp<DisplayList> display_list,
659 void MakeImpellerSnapshot(
660 sk_sp<DisplayList> display_list,
662 std::function<
void(std::shared_ptr<impeller::Texture>)>
callback,
666 std::shared_ptr<impeller::Texture> MakeImpellerSnapshotSync(
667 sk_sp<DisplayList> display_list,
672 sk_sp<SkImage> ConvertToRasterImage(sk_sp<SkImage>
image)
override;
675 sk_sp<SkImage> MakeSkiaTextureImage(
676 sk_sp<SkImage>
image,
680 std::shared_ptr<impeller::Texture> MakeImpellerTextureImage(
681 sk_sp<SkImage>
image,
685 void CacheRuntimeStage(
686 const std::shared_ptr<impeller::RuntimeStage>& runtime_stage)
override;
689 bool MakeRenderContextCurrent()
override;
698 const std::unique_ptr<Surface>& GetSurface()
const override {
703 bool IsAiksContextInitialized()
const override {
704#if IMPELLER_SUPPORTS_RENDERING
705 return surface_ && surface_->GetAiksContext();
712 std::shared_ptr<impeller::AiksContext> GetAiksContext()
const override {
713#if IMPELLER_SUPPORTS_RENDERING
715 return surface_->GetAiksContext();
717 if (
auto context = impeller_context_->GetContext()) {
718 return std::make_shared<impeller::AiksContext>(
726 const std::unique_ptr<SnapshotSurfaceProducer>& GetSnapshotSurfaceProducer()
728 return snapshot_surface_producer_;
732 std::shared_ptr<const fml::SyncSwitch> GetIsGpuDisabledSyncSwitch()
746 std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder,
747 std::vector<std::unique_ptr<LayerTreeTask>> tasks);
750 DoDrawResult DrawToSurfaces(
751 FrameTimingsRecorder& frame_timings_recorder,
752 std::vector<std::unique_ptr<LayerTreeTask>> tasks);
764 std::unique_ptr<FrameItem> DrawToSurfacesUnsafe(
765 FrameTimingsRecorder& frame_timings_recorder,
766 std::vector<std::unique_ptr<LayerTreeTask>> tasks);
776 float device_pixel_ratio,
777 std::optional<fml::TimePoint> presentation_time);
779 ViewRecord& EnsureViewRecord(int64_t
view_id);
781 void FireNextFrameCallbackIfPresent();
783 static bool ShouldResubmitFrame(
const DoDrawResult& result);
784 static DrawStatus ToDrawStatus(DoDrawStatus status);
786 bool is_torn_down_ =
false;
789 std::shared_ptr<impeller::ImpellerContextFuture> impeller_context_;
790 std::unique_ptr<Surface> surface_;
791 std::unique_ptr<SnapshotSurfaceProducer> snapshot_surface_producer_;
792 std::unique_ptr<flutter::CompositorContext> compositor_context_;
793 std::unordered_map<int64_t, ViewRecord> view_records_;
795 bool user_override_resource_cache_bytes_ =
false;
796 std::optional<size_t> max_cache_bytes_;
798 std::shared_ptr<ExternalViewEmbedder> external_view_embedder_;
799 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
impeller::ShaderType type
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.