Flutter Engine
flutter::Rasterizer Class Referencefinal

#include <rasterizer.h>

Inheritance diagram for flutter::Rasterizer:
flutter::SnapshotDelegate

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  ScreenshotType {
  ScreenshotType::SkiaPicture,
  ScreenshotType::UncompressedImage,
  ScreenshotType::CompressedImage
}
 The type of the screenshot to obtain of the previously rendered layer tree. More...
 
using LayerTreeDiscardCallback = std::function< bool(flutter::LayerTree &)>
 

Public Member Functions

 Rasterizer (Delegate &delegate)
 Creates a new instance of a rasterizer. Rasterizers may only be created on the GPU 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 GPU task runner. All GPU resources are collected before this call returns. Any context setup by the embedder to hold these resources can be immediately collected as well. More...
 
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 setup) is user error. More...
 
void Teardown ()
 Releases the previously setup 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. 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< RasterizerGetWeakPtr () const
 Gets a weak pointer to the rasterizer. The rasterizer may only be accessed on the GPU task runner. More...
 
fml::TaskRunnerAffineWeakPtr< SnapshotDelegateGetSnapshotDelegate () const
 
flutter::LayerTreeGetLastLayerTree ()
 Sometimes, it may be necessary to render the same frame again without having to wait for the framework to build a whole new layer tree describing the same contents. One such case is when external textures (video or camera streams for example) are updated in an otherwise static layer tree. To support this use case, the rasterizer holds onto the last rendered layer tree. More...
 
void DrawLastLayerTree ()
 Draws a last layer tree to the render surface. 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...
 
flutter::TextureRegistryGetTextureRegistry ()
 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...
 
void Draw (fml::RefPtr< Pipeline< flutter::LayerTree >> pipeline, LayerTreeDiscardCallback discardCallback=NoDiscard)
 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...
 
flutter::CompositorContextcompositor_context ()
 Returns a pointer to the compositor context used by this rasterizer. This pointer will never 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...
 

Detailed Description

The rasterizer is a component owned by the shell that resides on the GPU task runner. Each shell owns exactly one instance of a rasterizer. The rasterizer may only be created, used and collected on the GPU 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 41 of file rasterizer.h.

Member Typedef Documentation

◆ LayerTreeDiscardCallback

Member Enumeration Documentation

◆ ScreenshotType

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 SkPicture that can be used to introspect the series of commands used to draw that picture.

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. This format is 32 bits per pixel, 8 bits per component and denoted by the kN32_SkColorType Skia color type.

CompressedImage 

A format used to denote compressed image data. The PNG compressed container is used.

Definition at line 249 of file rasterizer.h.

249  {
250  //--------------------------------------------------------------------------
251  /// A format used to denote a Skia picture. A Skia picture is a serialized
252  /// representation of an `SkPicture` that can be used to introspect the
253  /// series of commands used to draw that picture.
254  ///
255  /// Skia pictures are typically stored as files with the .skp extension on
256  /// disk. These files may be viewed in an interactive debugger available at
257  /// https://debugger.skia.org/
258  ///
259  SkiaPicture,
260 
261  //--------------------------------------------------------------------------
262  /// A format used to denote uncompressed image data. This format
263  /// is 32 bits per pixel, 8 bits per component and
264  /// denoted by the `kN32_SkColorType ` Skia color type.
265  ///
266  UncompressedImage,
267 
268  //--------------------------------------------------------------------------
269  /// A format used to denote compressed image data. The PNG compressed
270  /// container is used.
271  ///
272  CompressedImage,
273  };

Constructor & Destructor Documentation

◆ Rasterizer()

flutter::Rasterizer::Rasterizer ( Delegate delegate)

Creates a new instance of a rasterizer. Rasterizers may only be created on the GPU task runner. Rasterizers are currently only created by the shell (which also sets itself up as the rasterizer delegate).

Parameters
[in]delegateThe rasterizer delegate.

Definition at line 39 of file rasterizer.cc.

References compositor_context(), FML_DCHECK, and ~Rasterizer().

40  : delegate_(delegate),
41  compositor_context_(std::make_unique<flutter::CompositorContext>(
42  delegate.GetFrameBudget())),
43  user_override_resource_cache_bytes_(false),
44  weak_factory_(this) {
45  FML_DCHECK(compositor_context_);
46 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ ~Rasterizer()

flutter::Rasterizer::~Rasterizer ( )
default

Destroys the rasterizer. This must happen on the GPU task runner. All GPU resources are collected before this call returns. Any context setup by the embedder to hold these resources can be immediately collected as well.

Referenced by Rasterizer().

Member Function Documentation

◆ compositor_context()

flutter::CompositorContext* flutter::Rasterizer::compositor_context ( )
inline

Returns a pointer to the compositor context used by this rasterizer. This pointer will never be nullptr.

Returns
The compositor context used by this rasterizer.

Definition at line 358 of file rasterizer.h.

References delegate_, DisableThreadMergerIfNeeded(), EnableThreadMergerIfNeeded(), FML_DISALLOW_COPY_AND_ASSIGN, function, GetResourceCacheMaxBytes(), SetResourceCacheMaxBytes(), and fml::size().

Referenced by Rasterizer().

358  {
359  return compositor_context_.get();
360  }

◆ DisableThreadMergerIfNeeded()

void flutter::Rasterizer::DisableThreadMergerIfNeeded ( )

Disables the thread merger if the external view embedder supports dynamic thread merging.

Attention
This method is thread-safe. When the thread merger is disabled, the raster task queue will continue to run in the same thread until |EnableThreadMergerIfNeeded| is called.
See also
ExternalViewEmbedder

Definition at line 118 of file rasterizer.cc.

References fml::RasterThreadMerger::Disable().

Referenced by compositor_context().

118  {
119  if (raster_thread_merger_) {
120  raster_thread_merger_->Disable();
121  }
122 }

◆ Draw()

void flutter::Rasterizer::Draw ( fml::RefPtr< Pipeline< flutter::LayerTree >>  pipeline,
LayerTreeDiscardCallback  discardCallback = NoDiscard 
)

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.

See also
Rasterizer::DoDraw
Parameters
[in]pipelineThe layer tree pipeline to take the next layer tree to render from.
[in]discardCallbackif specified and returns true, the layer tree is discarded instead of being rendered

Definition at line 154 of file rasterizer.cc.

References flutter::LayerTree::build_time(), fml::RasterThreadMerger::DecrementLease(), flutter::LayerTree::device_pixel_ratio(), flutter::PersistentCache::DumpSkp(), FML_DCHECK, flutter::LayerTree::frame_size(), fml::TimeDelta::FromMillisecondsF(), function, flutter::PersistentCache::GetCacheForProcess(), flutter::Rasterizer::Delegate::GetFrameBudget(), flutter::Rasterizer::Delegate::GetIsGpuDisabledSyncSwitch(), flutter::Rasterizer::Delegate::GetLatestFrameTargetTime(), flutter::TaskRunners::GetRasterTaskRunner(), flutter::Rasterizer::Delegate::GetTaskRunners(), flutter::PersistentCache::IsDumpingSkp(), fml::RasterThreadMerger::IsOnRasterizingThread(), flutter::FrameTiming::kBuildFinish, flutter::FrameTiming::kBuildStart, flutter::kDiscarded, flutter::kEnqueuePipeline, flutter::kFailed, flutter::FrameTiming::kRasterFinish, flutter::FrameTiming::kRasterStart, flutter::kResubmit, flutter::kSkipAndRetry, flutter::kSuccess, fml::kUnmergedNow, flutter::FrameTiming::kVsyncStart, flutter::MoreAvailable, fml::TimePoint::Now(), flutter::Rasterizer::Delegate::OnFrameRasterized(), fml::TaskRunner::PostTask(), flutter::PersistentCache::ResetStoredNewShaders(), fml::TaskRunner::RunsTasksOnCurrentThread(), ScreenshotLastLayerTree(), flutter::FrameTiming::Set(), fml::size(), SkiaPicture, flutter::PersistentCache::StoredNewShaders(), TRACE_EVENT0, and fml::tracing::TraceEventAsyncComplete().

155  {
156  TRACE_EVENT0("flutter", "GPURasterizer::Draw");
157  if (raster_thread_merger_ &&
158  !raster_thread_merger_->IsOnRasterizingThread()) {
159  // we yield and let this frame be serviced on the right thread.
160  return;
161  }
162  FML_DCHECK(delegate_.GetTaskRunners()
165 
166  RasterStatus raster_status = RasterStatus::kFailed;
168  [&](std::unique_ptr<LayerTree> layer_tree) {
169  if (discardCallback(*layer_tree.get())) {
170  raster_status = RasterStatus::kDiscarded;
171  } else {
172  raster_status = DoDraw(std::move(layer_tree));
173  }
174  };
175 
176  PipelineConsumeResult consume_result = pipeline->Consume(consumer);
177  // if the raster status is to resubmit the frame, we push the frame to the
178  // front of the queue and also change the consume status to more available.
179 
180  auto should_resubmit_frame = raster_status == RasterStatus::kResubmit ||
181  raster_status == RasterStatus::kSkipAndRetry;
182  if (should_resubmit_frame) {
183  auto front_continuation = pipeline->ProduceIfEmpty();
184  bool result =
185  front_continuation.Complete(std::move(resubmitted_layer_tree_));
186  if (result) {
187  consume_result = PipelineConsumeResult::MoreAvailable;
188  }
189  } else if (raster_status == RasterStatus::kEnqueuePipeline) {
190  consume_result = PipelineConsumeResult::MoreAvailable;
191  }
192 
193  // Merging the thread as we know the next `Draw` should be run on the platform
194  // thread.
195  if (surface_ != nullptr && surface_->GetExternalViewEmbedder() != nullptr) {
196  surface_->GetExternalViewEmbedder()->EndFrame(should_resubmit_frame,
197  raster_thread_merger_);
198  }
199 
200  // Consume as many pipeline items as possible. But yield the event loop
201  // between successive tries.
202  switch (consume_result) {
205  [weak_this = weak_factory_.GetWeakPtr(), pipeline]() {
206  if (weak_this) {
207  weak_this->Draw(pipeline);
208  }
209  });
210  break;
211  }
212  default:
213  break;
214  }
215 }
PipelineConsumeResult
Definition: pipeline.h:19
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
#define FML_DCHECK(condition)
Definition: logging.h:86
virtual void PostTask(const fml::closure &task)
Definition: task_runner.cc:24
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
Definition: task_runners.cc:42
virtual const TaskRunners & GetTaskRunners() const =0
Task runners used by the shell.
std::function< void(ResourcePtr)> Consumer
Definition: pipeline.h:136
virtual bool RunsTasksOnCurrentThread()
Definition: task_runner.cc:43

◆ DrawLastLayerTree()

void flutter::Rasterizer::DrawLastLayerTree ( )

Draws a last layer tree to the render surface. 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.

Definition at line 147 of file rasterizer.cc.

147  {
148  if (!last_layer_tree_ || !surface_) {
149  return;
150  }
151  DrawToSurface(*last_layer_tree_);
152 }

◆ EnableThreadMergerIfNeeded()

void flutter::Rasterizer::EnableThreadMergerIfNeeded ( )

Enables the thread merger if the external view embedder supports dynamic thread merging.

Attention
This method is thread-safe. When the thread merger is enabled, the raster task queue can run in the platform thread at any time.
See also
ExternalViewEmbedder

Definition at line 112 of file rasterizer.cc.

References fml::RasterThreadMerger::Enable().

Referenced by compositor_context().

112  {
113  if (raster_thread_merger_) {
114  raster_thread_merger_->Enable();
115  }
116 }

◆ GetLastLayerTree()

flutter::LayerTree * flutter::Rasterizer::GetLastLayerTree ( )

Sometimes, it may be necessary to render the same frame again without having to wait for the framework to build a whole new layer tree describing the same contents. One such case is when external textures (video or camera streams for example) are updated in an otherwise static layer tree. To support this use case, the rasterizer holds onto the last rendered layer tree.

Returns
A pointer to the last layer or nullptr if this rasterizer has never rendered a frame.

Definition at line 143 of file rasterizer.cc.

Referenced by ScreenshotLastLayerTree().

143  {
144  return last_layer_tree_.get();
145 }

◆ GetResourceCacheMaxBytes()

std::optional< size_t > flutter::Rasterizer::GetResourceCacheMaxBytes ( ) const

The current value of Skia's resource cache size, if a surface is present.

Attention
This cache does not describe the entirety of GPU resources that may be cached. The RasterCache also holds very large GPU resources.
See also
RasterCache
Returns
The size of Skia's resource cache, if available.

Definition at line 687 of file rasterizer.cc.

Referenced by compositor_context().

687  {
688  if (!surface_) {
689  return std::nullopt;
690  }
691  GrDirectContext* context = surface_->GetContext();
692  if (context) {
693  size_t max_bytes;
694  context->getResourceCacheLimits(nullptr, &max_bytes);
695  return max_bytes;
696  }
697  return std::nullopt;
698 }

◆ GetSnapshotDelegate()

fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > flutter::Rasterizer::GetSnapshotDelegate ( ) const

Definition at line 67 of file rasterizer.cc.

68  {
69  return weak_factory_.GetWeakPtr();
70 }

◆ GetTextureRegistry()

flutter::TextureRegistry * flutter::Rasterizer::GetTextureRegistry ( )

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.

Returns
A pointer to the external texture registry.

Definition at line 139 of file rasterizer.cc.

139  {
140  return &compositor_context_->texture_registry();
141 }

◆ GetWeakPtr()

fml::TaskRunnerAffineWeakPtr< Rasterizer > flutter::Rasterizer::GetWeakPtr ( ) const

Gets a weak pointer to the rasterizer. The rasterizer may only be accessed on the GPU task runner.

Returns
The weak pointer to the rasterizer.

Definition at line 63 of file rasterizer.cc.

63  {
64  return weak_factory_.GetWeakPtr();
65 }

◆ NotifyLowMemoryWarning()

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 124 of file rasterizer.cc.

References FML_DLOG.

124  {
125  if (!surface_) {
126  FML_DLOG(INFO)
127  << "Rasterizer::NotifyLowMemoryWarning called with no surface.";
128  return;
129  }
130  auto context = surface_->GetContext();
131  if (!context) {
132  FML_DLOG(INFO)
133  << "Rasterizer::NotifyLowMemoryWarning called with no GrContext.";
134  return;
135  }
136  context->performDeferredCleanup(std::chrono::milliseconds(0));
137 }
#define FML_DLOG(severity)
Definition: logging.h:85

◆ ScreenshotLastLayerTree()

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).

Parameters
[in]typeThe type of the screenshot to gather.
[in]base64_encodeWhether Base 64 encoding must be applied to the data after a screenshot has been captured.
Returns
A non-empty screenshot if one could be captured. A screenshot capture may fail if there were no layer trees previously rendered by this rasterizer, or, due to an unspecified internal error. Internal error will be logged to the console.

Definition at line 608 of file rasterizer.cc.

References CompressedImage, FML_LOG, flutter::LayerTree::frame_size(), GetLastLayerTree(), flutter::ScreenshotLayerTreeAsPicture(), SkiaPicture, and UncompressedImage.

Referenced by Draw().

610  {
611  auto* layer_tree = GetLastLayerTree();
612  if (layer_tree == nullptr) {
613  FML_LOG(ERROR) << "Last layer tree was null when screenshotting.";
614  return {};
615  }
616 
617  sk_sp<SkData> data = nullptr;
618 
619  GrDirectContext* surface_context =
620  surface_ ? surface_->GetContext() : nullptr;
621 
622  switch (type) {
624  data = ScreenshotLayerTreeAsPicture(layer_tree, *compositor_context_);
625  break;
627  data = ScreenshotLayerTreeAsImage(layer_tree, *compositor_context_,
628  surface_context, false);
629  break;
631  data = ScreenshotLayerTreeAsImage(layer_tree, *compositor_context_,
632  surface_context, true);
633  break;
634  }
635 
636  if (data == nullptr) {
637  FML_LOG(ERROR) << "Screenshot data was null.";
638  return {};
639  }
640 
641  if (base64_encode) {
642  size_t b64_size = SkBase64::Encode(data->data(), data->size(), nullptr);
643  auto b64_data = SkData::MakeUninitialized(b64_size);
644  SkBase64::Encode(data->data(), data->size(), b64_data->writable_data());
645  return Rasterizer::Screenshot{b64_data, layer_tree->frame_size()};
646  }
647 
648  return Rasterizer::Screenshot{data, layer_tree->frame_size()};
649 }
#define FML_LOG(severity)
Definition: logging.h:65
static sk_sp< SkData > ScreenshotLayerTreeAsPicture(flutter::LayerTree *tree, flutter::CompositorContext &compositor_context)
Definition: rasterizer.cc:493
flutter::LayerTree * GetLastLayerTree()
Sometimes, it may be necessary to render the same frame again without having to wait for the framewor...
Definition: rasterizer.cc:143

◆ SetNextFrameCallback()

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).

Parameters
[in]callbackThe callback to execute when the next layer tree is rendered on-screen.

Definition at line 651 of file rasterizer.cc.

651  {
652  next_frame_callback_ = callback;
653 }

◆ SetResourceCacheMaxBytes()

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.

Attention
This cache setting will be invalidated when the surface is torn down via Rasterizer::Teardown. This call must be made again with new limits after surface re-acquisition.
This cache does not describe the entirety of GPU resources that may be cached. The RasterCache also holds very large GPU resources.
See also
RasterCache
Parameters
[in]max_bytesThe maximum byte size of resource that may be cached for GPU rendering.
[in]from_userWhether 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 665 of file rasterizer.cc.

Referenced by compositor_context(), and Setup().

665  {
666  user_override_resource_cache_bytes_ |= from_user;
667 
668  if (!from_user && user_override_resource_cache_bytes_) {
669  // We should not update the setting here if a user has explicitly set a
670  // value for this over the flutter/skia channel.
671  return;
672  }
673 
674  max_cache_bytes_ = max_bytes;
675  if (!surface_) {
676  return;
677  }
678 
679  GrDirectContext* context = surface_->GetContext();
680  if (context) {
681  int max_resources;
682  context->getResourceCacheLimits(&max_resources, nullptr);
683  context->setResourceCacheLimits(max_resources, max_bytes);
684  }
685 }

◆ Setup()

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 setup) is user error.

See also
Rasterizer::Teardown
Parameters
[in]surfaceThe on-screen render surface.

Definition at line 72 of file rasterizer.cc.

References flutter::TaskRunners::GetPlatformTaskRunner(), flutter::TaskRunners::GetRasterTaskRunner(), fml::TaskRunner::GetTaskQueueId(), flutter::Rasterizer::Delegate::GetTaskRunners(), fml::RasterThreadMerger::SetMergeUnmergeCallback(), and SetResourceCacheMaxBytes().

72  {
73  surface_ = std::move(surface);
74  if (max_cache_bytes_.has_value()) {
75  SetResourceCacheMaxBytes(max_cache_bytes_.value(),
76  user_override_resource_cache_bytes_);
77  }
78  compositor_context_->OnGrContextCreated();
79  if (surface_->GetExternalViewEmbedder() &&
80  surface_->GetExternalViewEmbedder()->SupportsDynamicThreadMerging() &&
81  !raster_thread_merger_) {
82  const auto platform_id =
84  const auto gpu_id =
86  raster_thread_merger_ =
87  fml::MakeRefCounted<fml::RasterThreadMerger>(platform_id, gpu_id);
88  }
89  if (raster_thread_merger_) {
90  raster_thread_merger_->SetMergeUnmergeCallback([=]() {
91  // Clear the GL context after the thread configuration has changed.
92  if (surface_) {
93  surface_->ClearRenderContext();
94  }
95  });
96  }
97 }
virtual TaskQueueId GetTaskQueueId()
Definition: task_runner.cc:38
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
Definition: task_runners.cc:30
fml::RefPtr< fml::TaskRunner > GetRasterTaskRunner() const
Definition: task_runners.cc:42
virtual const TaskRunners & GetTaskRunners() const =0
Task runners used by the shell.
void SetMergeUnmergeCallback(const fml::closure &callback)
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...
Definition: rasterizer.cc:665

◆ Teardown()

void flutter::Rasterizer::Teardown ( )

Releases the previously setup 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.

Definition at line 99 of file rasterizer.cc.

References FML_DCHECK, fml::RefPtr< T >::get(), fml::RasterThreadMerger::IsEnabled(), fml::RasterThreadMerger::IsMerged(), fml::RasterThreadMerger::SetMergeUnmergeCallback(), and fml::RasterThreadMerger::UnMergeNow().

99  {
100  compositor_context_->OnGrContextDestroyed();
101  surface_.reset();
102  last_layer_tree_.reset();
103 
104  if (raster_thread_merger_.get() != nullptr &&
105  raster_thread_merger_.get()->IsMerged()) {
106  FML_DCHECK(raster_thread_merger_->IsEnabled());
107  raster_thread_merger_->UnMergeNow();
108  raster_thread_merger_->SetMergeUnmergeCallback(nullptr);
109  }
110 }
#define FML_DCHECK(condition)
Definition: logging.h:86
void SetMergeUnmergeCallback(const fml::closure &callback)
T * get() const
Definition: ref_ptr.h:112

The documentation for this class was generated from the following files: