5#include "flutter/flow/compositor_context.h"
9#include "flutter/flow/layers/layer_tree.h"
16 bool has_raster_cache,
17 bool impeller_enabled) {
22 : empty_paint_region_map,
23 has_raster_cache, impeller_enabled);
28 const Layer* prev_root_layer =
nullptr;
29 if (!prev_layer_tree_ ||
36 prev_root_layer = prev_layer_tree_->
root_layer();
42 context.
ComputeDamage(additional_damage_, horizontal_clip_alignment_,
43 vertical_clip_alignment_);
51 raster_time_(fixed_refresh_rate_updater_),
52 ui_time_(fixed_refresh_rate_updater_) {}
56 raster_time_(updater),
61void CompositorContext::BeginFrame(ScopedFrame&
frame,
62 bool enable_instrumentation) {
63 if (enable_instrumentation) {
68void CompositorContext::EndFrame(ScopedFrame&
frame,
69 bool enable_instrumentation) {
70 if (enable_instrumentation) {
79 const SkMatrix& root_surface_transformation,
80 bool instrumentation_enabled,
81 bool surface_supports_readback,
85 return std::make_unique<ScopedFrame>(
86 *
this, gr_context, canvas, view_embedder, root_surface_transformation,
87 instrumentation_enabled, surface_supports_readback, raster_thread_merger,
96 const SkMatrix& root_surface_transformation,
97 bool instrumentation_enabled,
98 bool surface_supports_readback,
102 gr_context_(gr_context),
104 aiks_context_(aiks_context),
105 view_embedder_(view_embedder),
106 root_surface_transformation_(root_surface_transformation),
107 instrumentation_enabled_(instrumentation_enabled),
108 surface_supports_readback_(surface_supports_readback),
109 raster_thread_merger_(
std::move(raster_thread_merger)) {
110 context_.BeginFrame(*
this, instrumentation_enabled_);
114 context_.EndFrame(*
this, instrumentation_enabled_);
119 bool ignore_raster_cache,
121 TRACE_EVENT0(
"flutter",
"CompositorContext::ScopedFrame::Raster");
123 std::optional<SkRect> clip_rect;
125 clip_rect = frame_damage->
ComputeClipRect(layer_tree, !ignore_raster_cache,
129 !ShouldPerformPartialRepaint(clip_rect, layer_tree.
frame_size())) {
130 clip_rect = std::nullopt;
131 frame_damage->
Reset();
135 bool root_needs_readback = layer_tree.
Preroll(
136 *
this, ignore_raster_cache, clip_rect ? *clip_rect :
kGiantRect);
137 bool needs_save_layer = root_needs_readback && !surface_supports_readback();
139 if (view_embedder_ && raster_thread_merger_) {
140 post_preroll_result =
141 view_embedder_->PostPrerollAction(raster_thread_merger_);
152 PaintLayerTreeImpeller(layer_tree, clip_rect, ignore_raster_cache);
154 PaintLayerTreeSkia(layer_tree, clip_rect, needs_save_layer,
155 ignore_raster_cache);
160void CompositorContext::ScopedFrame::PaintLayerTreeSkia(
162 std::optional<SkRect> clip_rect,
163 bool needs_save_layer,
164 bool ignore_raster_cache) {
169 canvas()->ClipRect(*clip_rect);
172 if (needs_save_layer) {
183 layer_tree.
Paint(*
this, ignore_raster_cache);
186void CompositorContext::ScopedFrame::PaintLayerTreeImpeller(
188 std::optional<SkRect> clip_rect,
189 bool ignore_raster_cache) {
190 if (canvas() && clip_rect) {
191 canvas()->Translate(-clip_rect->x(), -clip_rect->y());
194 layer_tree.
Paint(*
this, ignore_raster_cache);
210bool CompositorContext::ShouldPerformPartialRepaint(
211 std::optional<SkRect> damage_rect,
213 if (!damage_rect.has_value()) {
216 if (damage_rect->width() >= layer_tree_size.
width() &&
217 damage_rect->height() >= layer_tree_size.
height()) {
220 auto rx = damage_rect->width() / layer_tree_size.
width();
221 auto ry = damage_rect->height() / layer_tree_size.
height();
226 texture_registry_->OnGrContextCreated();
228 raster_cache_.Clear();
233 texture_registry_->OnGrContextDestroyed();
235 raster_cache_.Clear();
ScopedFrame(CompositorContext &context, GrDirectContext *gr_context, DlCanvas *canvas, ExternalViewEmbedder *view_embedder, const SkMatrix &root_surface_transformation, bool instrumentation_enabled, bool surface_supports_readback, fml::RefPtr< fml::RasterThreadMerger > raster_thread_merger, impeller::AiksContext *aiks_context)
virtual RasterStatus Raster(LayerTree &layer_tree, bool ignore_raster_cache, FrameDamage *frame_damage)
void OnGrContextCreated()
virtual std::unique_ptr< ScopedFrame > AcquireFrame(GrDirectContext *gr_context, DlCanvas *canvas, ExternalViewEmbedder *view_embedder, const SkMatrix &root_surface_transformation, bool instrumentation_enabled, bool surface_supports_readback, fml::RefPtr< fml::RasterThreadMerger > raster_thread_merger, impeller::AiksContext *aiks_context)
void OnGrContextDestroyed()
virtual ~CompositorContext()
void MarkSubtreeDirty(const PaintRegion &previous_paint_region=PaintRegion())
bool PushCullRect(const SkRect &clip)
Damage ComputeDamage(const SkIRect &additional_damage, int horizontal_clip_alignment=0, int vertical_clip_alignment=0) const
Developer-facing API for rendering anything within the engine.
std::optional< SkRect > ComputeClipRect(flutter::LayerTree &layer_tree, bool has_raster_cache, bool impeller_enabled)
Layer * root_layer() const
bool Preroll(CompositorContext::ScopedFrame &frame, bool ignore_raster_cache=false, SkRect cull_rect=kGiantRect)
const SkISize & frame_size() const
void Paint(CompositorContext::ScopedFrame &frame, bool ignore_raster_cache=false) const
const PaintRegionMap & paint_region_map() const
virtual void Diff(DiffContext *context, const Layer *old_layer)
The refresh rate interface for Stopwatch.
Optional< SkRect > bounds
std::map< uint64_t, PaintRegion > PaintRegionMap
constexpr float kImpellerRepaintRatio
The max ratio of pixel width or height to size that is dirty which results in a partial repaint.
static constexpr SkRect kGiantRect
constexpr int32_t width() const
constexpr int32_t height() const
static SkRect Make(const SkISize &size)
static SkRect MakeIWH(int w, int h)
static constexpr DlColor kTransparent()
#define TRACE_EVENT0(category_group, name)