Flutter Engine
The Flutter Engine
|
#include <rasterizer.h>
Classes | |
class | Delegate |
Used to forward events from the rasterizer to interested subsystems. Currently, the shell sets itself up as the rasterizer delegate to listen for frame rasterization events. It can then forward these events to the engine. More... | |
struct | Screenshot |
A POD type used to return the screenshot data along with the size of the frame. More... | |
Public Types | |
enum class | MakeGpuImageBehavior { kGpu , kBitmap } |
How to handle calls to MakeSkiaGpuImage. More... | |
enum class | ScreenshotType { SkiaPicture , UncompressedImage , CompressedImage , SurfaceData } |
The type of the screenshot to obtain of the previously rendered layer tree. More... | |
enum class | ScreenshotFormat { kUnknown , kR8G8B8A8UNormInt , kB8G8R8A8UNormInt , kR16G16B16A16Float } |
Public Member Functions | |
Rasterizer (Delegate &delegate, MakeGpuImageBehavior gpu_image_behavior=MakeGpuImageBehavior::kGpu) | |
Creates a new instance of a rasterizer. Rasterizers may only be created on the raster task runner. Rasterizers are currently only created by the shell (which also sets itself up as the rasterizer delegate). More... | |
~Rasterizer () | |
Destroys the rasterizer. This must happen on the raster task runner. All GPU resources are collected before this call returns. Any context set up by the embedder to hold these resources can be immediately collected as well. More... | |
void | SetImpellerContext (std::weak_ptr< impeller::Context > impeller_context) |
void | Setup (std::unique_ptr< Surface > surface) |
Rasterizers may be created well before an on-screen surface is available for rendering. Shells usually create a rasterizer in their constructors. Once an on-screen surface is available however, one may be provided to the rasterizer using this call. No rendering may occur before this call. The surface is held till the balancing call to Rasterizer::Teardown is made. Calling a setup before tearing down the previous surface (if this is not the first time the surface has been set up) is user error. More... | |
void | Teardown () |
Releases the previously set up on-screen render surface and collects associated resources. No more rendering may occur till the next call to Rasterizer::Setup with a new render surface. Calling a teardown without a setup is user error. Calling this method multiple times is safe. More... | |
void | TeardownExternalViewEmbedder () |
Releases any resource used by the external view embedder. For example, overlay surfaces or Android views. On Android, this method post a task to the platform thread, and waits until it completes. More... | |
void | NotifyLowMemoryWarning () const |
Notifies the rasterizer that there is a low memory situation and it must purge as many unnecessary resources as possible. Currently, the Skia context associated with onscreen rendering is told to free GPU resources. More... | |
fml::TaskRunnerAffineWeakPtr< Rasterizer > | GetWeakPtr () const |
Gets a weak pointer to the rasterizer. The rasterizer may only be accessed on the raster task runner. More... | |
fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > | GetSnapshotDelegate () const |
void | CollectView (int64_t view_id) |
Deallocate the resources for displaying a view. More... | |
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. This is useful during DrawLastLayerTrees and computing frame damage. More... | |
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 glance. After all, on surface loss and re-acquisition, the framework generates a new layer tree. Otherwise, why render the same contents to the screen again? This is used as an optimization in cases where there are external textures (video or camera streams for example) in referenced in the layer tree. These textures may be updated at a cadence different from that of the Flutter application. Flutter can re-render the layer tree with just the updated textures instead of waiting for the framework to do the work to generate the layer tree describing the same contents. More... | |
GrDirectContext * | GetGrContext () override |
std::shared_ptr< flutter::TextureRegistry > | GetTextureRegistry () override |
Gets the registry of external textures currently in use by the rasterizer. These textures may be updated at a cadence different from that of the Flutter application. When an external texture is referenced in the Flutter layer tree, that texture is composited within the Flutter layer tree. More... | |
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 that pipeline item to render a frame on the on-screen surface. More... | |
Screenshot | ScreenshotLastLayerTree (ScreenshotType type, bool base64_encode) |
Screenshots the last layer tree to one of the supported screenshot types and optionally Base 64 encodes that data for easier transmission and packaging (usually over the service protocol for instrumentation tools running on the host). More... | |
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. This is used by embedders to listen for one time operations like listening for when the first frame is rendered so that they may hide splash screens. More... | |
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 that support embedding externally composited views. More... | |
void | SetSnapshotSurfaceProducer (std::unique_ptr< SnapshotSurfaceProducer > producer) |
Set the snapshot surface producer. This is done on shell initialization. This is non-null on platforms that support taking GPU accelerated raster snapshots in the background. More... | |
flutter::CompositorContext * | compositor_context () |
Returns a pointer to the compositor context used by this rasterizer. This pointer will never be nullptr . More... | |
fml::RefPtr< fml::RasterThreadMerger > | GetRasterThreadMerger () |
Returns the raster thread merger used by this rasterizer. This may be nullptr . More... | |
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 resources to reference them from one frame to the next. Using this call, embedders may set the maximum bytes cached by Skia in its caches dedicated to on-screen rendering. More... | |
std::optional< size_t > | GetResourceCacheMaxBytes () const |
The current value of Skia's resource cache size, if a surface is present. More... | |
void | EnableThreadMergerIfNeeded () |
Enables the thread merger if the external view embedder supports dynamic thread merging. More... | |
void | DisableThreadMergerIfNeeded () |
Disables the thread merger if the external view embedder supports dynamic thread merging. More... | |
bool | IsTornDown () |
Returns whether TearDown has been called. More... | |
std::optional< DrawSurfaceStatus > | GetLastDrawStatus (int64_t view_id) |
Returns the last status of drawing the specific view. More... | |
virtual std::unique_ptr< GpuImageResult > | MakeSkiaGpuImage (sk_sp< DisplayList > display_list, const SkImageInfo &image_info)=0 |
Attempts to create a GrBackendTexture for the specified DisplayList. May result in a raster bitmap if no GPU context is available. More... | |
virtual std::shared_ptr< TextureRegistry > | GetTextureRegistry ()=0 |
Gets the registry of external textures currently in use by the rasterizer. These textures may be updated at a cadence different from that of the Flutter application. When an external texture is referenced in the Flutter layer tree, that texture is composited within the Flutter layer tree. More... | |
virtual GrDirectContext * | GetGrContext ()=0 |
virtual void | MakeRasterSnapshot (sk_sp< DisplayList > display_list, SkISize picture_size, std::function< void(sk_sp< DlImage >)> callback)=0 |
virtual sk_sp< DlImage > | MakeRasterSnapshotSync (sk_sp< DisplayList > display_list, SkISize picture_size)=0 |
virtual sk_sp< SkImage > | ConvertToRasterImage (sk_sp< SkImage > image)=0 |
virtual void | CacheRuntimeStage (const std::shared_ptr< impeller::RuntimeStage > &runtime_stage)=0 |
virtual fml::Milliseconds | GetFrameBudget () const =0 |
Public Member Functions inherited from flutter::SnapshotController::Delegate | |
virtual | ~Delegate ()=default |
virtual const std::unique_ptr< Surface > & | GetSurface () const =0 |
virtual std::shared_ptr< impeller::AiksContext > | GetAiksContext () const =0 |
virtual const std::unique_ptr< SnapshotSurfaceProducer > & | GetSnapshotSurfaceProducer () const =0 |
virtual std::shared_ptr< const fml::SyncSwitch > | GetIsGpuDisabledSyncSwitch () const =0 |
The rasterizer is a component owned by the shell that resides on the raster task runner. Each shell owns exactly one instance of a rasterizer. The rasterizer may only be created, used and collected on the raster task runner.
The rasterizer owns the instance of the currently active on-screen render surface. On this surface, it renders the contents of layer trees submitted to it by the Engine
(which lives on the UI task runner).
The primary components owned by the rasterizer are the compositor context and the on-screen render surface. The compositor context has all the GPU state necessary to render frames to the render surface.
Definition at line 114 of file rasterizer.h.
|
strong |
How to handle calls to MakeSkiaGpuImage.
Enumerator | |
---|---|
kGpu | MakeSkiaGpuImage returns a GPU resident image, if possible. |
kBitmap | MakeSkiaGpuImage returns a checkerboard bitmap. This is useful in test contexts where no GPU surface is available. |
Definition at line 178 of file rasterizer.h.
|
strong |
Enumerator | |
---|---|
kUnknown | |
kR8G8B8A8UNormInt | |
kB8G8R8A8UNormInt | |
kR16G16B16A16Float |
Definition at line 383 of file rasterizer.h.
|
strong |
The type of the screenshot to obtain of the previously rendered layer tree.
Enumerator | |
---|---|
SkiaPicture | A format used to denote a Skia picture. A Skia picture is a serialized representation of an Skia pictures are typically stored as files with the .skp extension on disk. These files may be viewed in an interactive debugger available at https://debugger.skia.org/ |
UncompressedImage | A format used to denote uncompressed image data. For Skia, this format is 32 bits per pixel, 8 bits per component and denoted by the |
CompressedImage | A format used to denote compressed image data. The PNG compressed container is used. |
SurfaceData | Reads the data directly from the Rasterizer's surface. The pixel format is determined from the surface. This is the only way to read wide gamut color data, but isn't supported everywhere. |
Definition at line 347 of file rasterizer.h.
|
explicit |
Creates a new instance of a rasterizer. Rasterizers may only be created on the raster task runner. Rasterizers are currently only created by the shell (which also sets itself up as the rasterizer delegate).
[in] | delegate | The rasterizer delegate. |
[in] | gpu_image_behavior | How to handle calls to MakeSkiaGpuImage. |
Definition at line 53 of file rasterizer.cc.
|
default |
Destroys the rasterizer. This must happen on the raster task runner. All GPU resources are collected before this call returns. Any context set up by the embedder to hold these resources can be immediately collected as well.
void flutter::Rasterizer::CollectView | ( | int64_t | view_id | ) |
Deallocate the resources for displaying a view.
This method must be called on the raster task runner when a view is removed from the engine. When the rasterizer is requested to draw an unrecognized view, it implicitly allocates necessary resources. These resources must be explicitly deallocated.
[in] | view_id | The ID of the view. |
Definition at line 191 of file rasterizer.cc.
|
inline |
Returns a pointer to the compositor context used by this rasterizer. This pointer will never be nullptr
.
Definition at line 515 of file rasterizer.h.
void flutter::Rasterizer::DisableThreadMergerIfNeeded | ( | ) |
Disables the thread merger if the external view embedder supports dynamic thread merging.
ExternalViewEmbedder
Definition at line 164 of file rasterizer.cc.
DrawStatus flutter::Rasterizer::Draw | ( | const std::shared_ptr< FramePipeline > & | pipeline | ) |
Takes the next item from the layer tree pipeline and executes the raster thread frame workload for that pipeline item to render a frame on the on-screen surface.
Why does the draw call take a layer tree pipeline and not the layer tree directly?
The pipeline is the way book-keeping of frame workloads distributed across the multiple threads is managed. The rasterizer deals with the pipelines directly (instead of layer trees which is what it actually renders) because the pipeline consumer's workload must be accounted for within the pipeline itself. If the rasterizer took the layer tree directly, it would have to be taken out of the pipeline. That would signal the end of the frame workload and the pipeline would be ready for new frames. But the last frame has not been rendered by the frame yet! On the other hand, the pipeline must own the layer tree it renders because it keeps a reference to the last layer tree around till a new frame is rendered. So a simple reference wont work either. The Rasterizer::DoDraw
method actually performs the GPU operations within the layer tree pipeline.
Rasterizer::DoDraw
[in] | pipeline | The layer tree pipeline to take the next layer tree to render from. |
Definition at line 245 of file rasterizer.cc.
void flutter::Rasterizer::DrawLastLayerTrees | ( | std::unique_ptr< FrameTimingsRecorder > | frame_timings_recorder | ) |
Draws the last layer trees with their last configuration. This may seem entirely redundant at first glance. After all, on surface loss and re-acquisition, the framework generates a new layer tree. Otherwise, why render the same contents to the screen again? This is used as an optimization in cases where there are external textures (video or camera streams for example) in referenced in the layer tree. These textures may be updated at a cadence different from that of the Flutter application. Flutter can re-render the layer tree with just the updated textures instead of waiting for the framework to do the work to generate the layer tree describing the same contents.
Calling this method clears all last layer trees (GetLastLayerTree).
Definition at line 218 of file rasterizer.cc.
void flutter::Rasterizer::EnableThreadMergerIfNeeded | ( | ) |
Enables the thread merger if the external view embedder supports dynamic thread merging.
ExternalViewEmbedder
Definition at line 158 of file rasterizer.cc.
|
overridevirtual |
Implements flutter::SnapshotDelegate.
Definition at line 202 of file rasterizer.cc.
std::optional< DrawSurfaceStatus > flutter::Rasterizer::GetLastDrawStatus | ( | int64_t | view_id | ) |
Returns the last status of drawing the specific view.
This method is used only in unit tests.
Definition at line 148 of file rasterizer.cc.
flutter::LayerTree * flutter::Rasterizer::GetLastLayerTree | ( | int64_t | view_id | ) |
Returns the last successfully drawn layer tree for the given view, or nullptr if there isn't any. This is useful during DrawLastLayerTrees
and computing frame damage.
nullptr
if this rasterizer has never rendered a frame to the given view. Definition at line 206 of file rasterizer.cc.
fml::RefPtr< fml::RasterThreadMerger > flutter::Rasterizer::GetRasterThreadMerger | ( | ) |
Returns the raster thread merger used by this rasterizer. This may be nullptr
.
Definition at line 1099 of file rasterizer.cc.
std::optional< size_t > flutter::Rasterizer::GetResourceCacheMaxBytes | ( | ) | const |
The current value of Skia's resource cache size, if a surface is present.
RasterCache
also holds very large GPU resources.RasterCache
Definition at line 1140 of file rasterizer.cc.
fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > flutter::Rasterizer::GetSnapshotDelegate | ( | ) | const |
Definition at line 70 of file rasterizer.cc.
|
overridevirtual |
Gets the registry of external textures currently in use by the rasterizer. These textures may be updated at a cadence different from that of the Flutter application. When an external texture is referenced in the Flutter layer tree, that texture is composited within the Flutter layer tree.
Implements flutter::SnapshotDelegate.
Definition at line 198 of file rasterizer.cc.
fml::TaskRunnerAffineWeakPtr< Rasterizer > flutter::Rasterizer::GetWeakPtr | ( | ) | const |
Gets a weak pointer to the rasterizer. The rasterizer may only be accessed on the raster task runner.
Definition at line 66 of file rasterizer.cc.
bool flutter::Rasterizer::IsTornDown | ( | ) |
Returns whether TearDown has been called.
This method is used only in unit tests.
Definition at line 144 of file rasterizer.cc.
void flutter::Rasterizer::NotifyLowMemoryWarning | ( | ) | const |
Notifies the rasterizer that there is a low memory situation and it must purge as many unnecessary resources as possible. Currently, the Skia context associated with onscreen rendering is told to free GPU resources.
Definition at line 170 of file rasterizer.cc.
Rasterizer::Screenshot flutter::Rasterizer::ScreenshotLastLayerTree | ( | Rasterizer::ScreenshotType | type, |
bool | base64_encode | ||
) |
Screenshots the last layer tree to one of the supported screenshot types and optionally Base 64 encodes that data for easier transmission and packaging (usually over the service protocol for instrumentation tools running on the host).
[in] | type | The type of the screenshot to gather. |
[in] | base64_encode | Whether Base 64 encoding must be applied to the data after a screenshot has been captured. |
Definition at line 1020 of file rasterizer.cc.
void flutter::Rasterizer::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 that support embedding externally composited views.
[in] | view_embedder | The external view embedder object. |
Definition at line 1089 of file rasterizer.cc.
void flutter::Rasterizer::SetImpellerContext | ( | std::weak_ptr< impeller::Context > | impeller_context | ) |
Definition at line 75 of file rasterizer.cc.
void flutter::Rasterizer::SetNextFrameCallback | ( | const fml::closure & | callback | ) |
Sets a callback that will be executed when the next layer tree in rendered to the on-screen surface. This is used by embedders to listen for one time operations like listening for when the first frame is rendered so that they may hide splash screens.
The callback is only executed once and dropped on the GPU thread when executed (lambda captures must be able to deal with the threading repercussions of this behavior).
[in] | callback | The callback to execute when the next layer tree is rendered on-screen. |
Definition at line 1085 of file rasterizer.cc.
void flutter::Rasterizer::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 resources to reference them from one frame to the next. Using this call, embedders may set the maximum bytes cached by Skia in its caches dedicated to on-screen rendering.
Rasterizer::Teardown
. This call must be made again with new limits after surface re-acquisition.RasterCache
also holds very large GPU resources.RasterCache
[in] | max_bytes | The maximum byte size of resource that may be cached for GPU rendering. |
[in] | from_user | Whether this request was from user code, e.g. via the flutter/skia message channel, in which case it should not be overridden by the platform. |
Definition at line 1113 of file rasterizer.cc.
void flutter::Rasterizer::SetSnapshotSurfaceProducer | ( | std::unique_ptr< SnapshotSurfaceProducer > | producer | ) |
Set the snapshot surface producer. This is done on shell initialization. This is non-null on platforms that support taking GPU accelerated raster snapshots in the background.
[in] | producer | A surface producer for raster snapshotting when the onscreen surface is not available. |
Definition at line 1094 of file rasterizer.cc.
void flutter::Rasterizer::Setup | ( | std::unique_ptr< Surface > | surface | ) |
Rasterizers may be created well before an on-screen surface is available for rendering. Shells usually create a rasterizer in their constructors. Once an on-screen surface is available however, one may be provided to the rasterizer using this call. No rendering may occur before this call. The surface is held till the balancing call to Rasterizer::Teardown
is made. Calling a setup before tearing down the previous surface (if this is not the first time the surface has been set up) is user error.
Rasterizer::Teardown
[in] | surface | The on-screen render surface. |
Definition at line 80 of file rasterizer.cc.
void flutter::Rasterizer::Teardown | ( | ) |
Releases the previously set up on-screen render surface and collects associated resources. No more rendering may occur till the next call to Rasterizer::Setup
with a new render surface. Calling a teardown without a setup is user error. Calling this method multiple times is safe.
Definition at line 119 of file rasterizer.cc.
void flutter::Rasterizer::TeardownExternalViewEmbedder | ( | ) |
Releases any resource used by the external view embedder. For example, overlay surfaces or Android views. On Android, this method post a task to the platform thread, and waits until it completes.
Definition at line 113 of file rasterizer.cc.