Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5c59e73

Browse files
committed
Collection Need RasterCache DisplayListLayer In Preroll
1 parent 3ea7e25 commit 5c59e73

File tree

5 files changed

+62
-17
lines changed

5 files changed

+62
-17
lines changed

flow/layers/display_list_layer.cc

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "flutter/flow/layers/display_list_layer.h"
66

77
#include "flutter/display_list/display_list_builder.h"
8+
#include "flutter/flow/layers/layer.h"
89

910
namespace flutter {
1011

@@ -91,24 +92,45 @@ bool DisplayListLayer::Compare(DiffContext::Statistics& statistics,
9192
void DisplayListLayer::Preroll(PrerollContext* context,
9293
const SkMatrix& matrix) {
9394
TRACE_EVENT0("flutter", "DisplayListLayer::Preroll");
95+
context->raster_cached_entries.emplace_back(RasterCacheEntry(this));
9496

97+
auto& cache_entry = context->raster_cached_entries.back();
98+
// display layer is a leaf node
99+
cache_entry.num_child_entries = 0;
100+
cache_entry.need_caching = IsNeedCached(context, matrix);
101+
}
102+
103+
bool DisplayListLayer::IsNeedCached(PrerollContext* context,
104+
const SkMatrix& ctm) {
95105
DisplayList* disp_list = display_list();
96106

97107
SkRect bounds = disp_list->bounds().makeOffset(offset_.x(), offset_.y());
98108

99109
if (auto* cache = context->raster_cache) {
100110
TRACE_EVENT0("flutter", "DisplayListLayer::RasterCache (Preroll)");
101111
if (context->cull_rect.intersects(bounds)) {
102-
if (cache->Prepare(context, disp_list, is_complex_, will_change_, matrix,
103-
offset_)) {
104-
context->subtree_can_inherit_opacity = true;
105-
}
106-
} else {
107-
// Don't evict raster cache entry during partial repaint
108-
cache->Touch(disp_list, matrix);
112+
return cache->ShouldBeCached(context, disp_list, is_complex_,
113+
will_change_, ctm);
114+
}
115+
}
116+
return false;
117+
}
118+
119+
void DisplayListLayer::TryToPrepareRasterCache(PrerollContext* context,
120+
const SkMatrix& ctm) {
121+
DisplayList* disp_list = display_list();
122+
123+
SkRect bounds = disp_list->bounds().makeOffset(offset_.x(), offset_.y());
124+
auto* cache = context->raster_cache;
125+
if (context->cull_rect.intersects(bounds)) {
126+
if (cache->Prepare(context, disp_list, is_complex_, will_change_, ctm,
127+
offset_)) {
128+
context->subtree_can_inherit_opacity = true;
109129
}
130+
} else {
131+
// Don't evict raster cache entry during partial repaint
132+
cache->Touch(disp_list, ctm);
110133
}
111-
set_paint_bounds(bounds);
112134
}
113135

114136
void DisplayListLayer::Paint(PaintContext& context) const {

flow/layers/display_list_layer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
#include "flutter/display_list/display_list.h"
99
#include "flutter/flow/layers/layer.h"
10+
#include "flutter/flow/raster_cache.h"
1011
#include "flutter/flow/skia_gpu_object.h"
12+
#include "include/core/SkMatrix.h"
1113

1214
namespace flutter {
1315

@@ -32,6 +34,11 @@ class DisplayListLayer : public Layer {
3234
return this;
3335
}
3436

37+
bool IsNeedCached(PrerollContext* context, const SkMatrix& ctm) override;
38+
39+
void TryToPrepareRasterCache(PrerollContext* context,
40+
const SkMatrix& ctm) override;
41+
3542
void Preroll(PrerollContext* frame, const SkMatrix& matrix) override;
3643

3744
void Paint(PaintContext& context) const override;

flow/layers/layer.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,6 @@ class Layer {
364364
uint64_t original_layer_id_;
365365
bool subtree_has_platform_view_;
366366
bool layer_can_inherit_opacity_;
367-
std::unordered_set<uint64_t> ancestors_ = {};
368-
369-
unsigned level_ = 0;
370367

371368
static uint64_t NextUniqueID();
372369

flow/raster_cache.cc

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,12 @@ bool RasterCache::Prepare(PrerollContext* context,
265265
return true;
266266
}
267267

268-
bool RasterCache::Prepare(PrerollContext* context,
269-
DisplayList* display_list,
270-
bool is_complex,
271-
bool will_change,
272-
const SkMatrix& untranslated_matrix,
273-
const SkPoint& offset) {
268+
bool RasterCache::ShouldBeCached(PrerollContext* context,
269+
DisplayList* display_list,
270+
bool is_complex,
271+
bool will_change,
272+
const SkMatrix& untranslated_matrix,
273+
const SkPoint& offset) {
274274
if (!GenerateNewCacheInThisFrame()) {
275275
return false;
276276
}
@@ -293,6 +293,17 @@ bool RasterCache::Prepare(PrerollContext* context,
293293
// The matrix was singular. No point in going further.
294294
return false;
295295
}
296+
return true;
297+
}
298+
299+
bool RasterCache::Prepare(PrerollContext* context,
300+
DisplayList* display_list,
301+
bool is_complex,
302+
bool will_change,
303+
const SkMatrix& untranslated_matrix,
304+
const SkPoint& offset) {
305+
SkMatrix transformation_matrix = untranslated_matrix;
306+
transformation_matrix.preTranslate(offset.x(), offset.y());
296307

297308
RasterCacheKey cache_key(display_list->unique_id(),
298309
RasterCacheKeyType::kDisplayList,

flow/raster_cache.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ class RasterCache {
187187
bool will_change,
188188
const SkMatrix& untranslated_matrix,
189189
const SkPoint& offset = SkPoint());
190+
191+
bool ShouldBeCached(PrerollContext* context,
192+
DisplayList* display_list,
193+
bool is_complex,
194+
bool will_change,
195+
const SkMatrix& untranslated_matrix,
196+
const SkPoint& offset = SkPoint());
197+
190198
bool Prepare(PrerollContext* context,
191199
DisplayList* display_list,
192200
bool is_complex,

0 commit comments

Comments
 (0)