Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9f44aad
Collection Need RasterCache Layer in Preroll
JsouLiang Mar 9, 2022
bb6a4cc
Collection Need RasterCache DisplayListLayer In Preroll
JsouLiang Mar 9, 2022
51ae333
Collection Need RasterCache DisplayListLayer In Preroll
JsouLiang Mar 31, 2022
bb86e3a
Differentiate RasterCacheableEntry Layer DisplayList SkPicture
JsouLiang Mar 31, 2022
98b4ad6
Collection Raster Cacheable OpacityLayer in Preroll
JsouLiang Apr 2, 2022
2a0fbc3
Add PictureLayer RasterCache
JsouLiang Apr 8, 2022
9a71e09
Use Cacheable Object to entry the layer
JsouLiang Apr 16, 2022
0f60777
Fix some failed cases; Add new test case for collect RasterCacheable …
JsouLiang Apr 16, 2022
d53733e
Fix RasterCacheDisabledWithPlatformViews test error
JsouLiang Apr 16, 2022
4600cd6
ImageFilterLayer NeedCache check filter is nullptr
JsouLiang Apr 16, 2022
7626d11
Fix the PrerollContext size is different in windows platform
JsouLiang Apr 17, 2022
d88aff2
Change the logic of raster cache entry
JsouLiang Apr 19, 2022
45b28cf
Change the Cacheable interface capacity
JsouLiang Apr 20, 2022
57a8d16
Update the LayerTree::TryToRasterCache logic; Change some comments
JsouLiang Apr 22, 2022
e4eb2a0
fix conflict
JsouLiang Apr 23, 2022
7e5af26
Add RasterCache test in Container_layer_unittest file
JsouLiang Apr 24, 2022
879ee10
If parent cached success, we will try to remove the children cache
JsouLiang Apr 26, 2022
2c038e9
Move Prepare, Touch, Draw from RasterCache to CacheableItem
JsouLiang Apr 30, 2022
829e9f4
fix shell unittest test failed
JsouLiang Apr 30, 2022
91cf4e9
Optimize structure
JsouLiang May 3, 2022
ba5694e
Change RasterCacheItem struct and fix some test cases
JsouLiang May 4, 2022
45448d4
Fix test cases
JsouLiang May 5, 2022
dc089ad
Remove the RasterCacheResult survival count
JsouLiang May 7, 2022
2f1eb2f
fix naming issues
JsouLiang May 10, 2022
473288b
Change the RasterCache of ClipLayer
JsouLiang May 17, 2022
a80a037
Fix some comments
JsouLiang May 20, 2022
fd82489
Change the licenses
JsouLiang May 20, 2022
d3883c6
fix some comments
JsouLiang Jun 13, 2022
3e1ed6c
Rebase master
JsouLiang Jun 14, 2022
a25e920
Remove redundant logic
JsouLiang Jun 15, 2022
fd3bc8e
resolve conflicting files
JsouLiang Jun 23, 2022
cdc123d
Fix comments
JsouLiang Jun 23, 2022
d8d373a
Update licenses
JsouLiang Jun 23, 2022
9e0e52b
fix the display_list_raster_item set cache entry logic
JsouLiang Jun 24, 2022
9b68847
ImageFilterLayer Reset cache_children; Fix some comments
JsouLiang Jun 27, 2022
7c7fc4c
LayerRCI use GetPaintBoundsFromLayer to paint cache
JsouLiang Jun 29, 2022
91f7278
Change lambda capture variable; fix nits
JsouLiang Jun 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
If parent cached success, we will try to remove the children cache
  • Loading branch information
JsouLiang committed Jun 23, 2022
commit 879ee10e6994ea2bd99e48d56915f305c3bcdd5e
32 changes: 32 additions & 0 deletions flow/layers/container_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ TEST_F(ContainerLayerTest, RasterCacheTest) {
{
// frame2
use_mock_raster_cache();
preroll_context()->raster_cache->PrepareNewFrame();
layer->Preroll(preroll_context(), SkMatrix::I());
// Cache the cacheable entries
LayerTree::TryToRasterCache(preroll_context());
Expand Down Expand Up @@ -286,13 +287,15 @@ TEST_F(ContainerLayerTest, RasterCacheTest) {
EXPECT_FALSE(raster_cache()->HasCache(cacheable_layer21->asLayer(),
SkMatrix::I(),
RasterCacheLayerStrategy::kLayer));
preroll_context()->raster_cache->CleanupAfterFrame();
}

{
// frame2
// new frame the layer tree will create new PrerollContext, so in here we
// clear the cached_entries
preroll_context()->raster_cached_entries.clear();
preroll_context()->raster_cache->PrepareNewFrame();
layer->Preroll(preroll_context(), SkMatrix::I());

// Cache the cacheable entries
Expand All @@ -319,12 +322,14 @@ TEST_F(ContainerLayerTest, RasterCacheTest) {
EXPECT_TRUE(raster_cache()->HasCache(cacheable_layer21->asLayer(),
SkMatrix::I(),
RasterCacheLayerStrategy::kLayer));
preroll_context()->raster_cache->CleanupAfterFrame();
}

{
// frame3
// new frame the layer tree will create new PrerollContext, so in here we
// clear the cached_entries
preroll_context()->raster_cache->PrepareNewFrame();
preroll_context()->raster_cached_entries.clear();
layer->Preroll(preroll_context(), SkMatrix::I());

Expand Down Expand Up @@ -352,6 +357,33 @@ TEST_F(ContainerLayerTest, RasterCacheTest) {
EXPECT_TRUE(raster_cache()->HasCache(cacheable_layer21->asLayer(),
SkMatrix::I(),
RasterCacheLayerStrategy::kLayer));
preroll_context()->raster_cache->CleanupAfterFrame();
}

{
preroll_context()->raster_cache->PrepareNewFrame();
// frame4
preroll_context()->raster_cached_entries.clear();
layer->Preroll(preroll_context(), SkMatrix::I());
preroll_context()->raster_cache->CleanupAfterFrame();

// frame5
preroll_context()->raster_cache->PrepareNewFrame();
preroll_context()->raster_cached_entries.clear();
layer->Preroll(preroll_context(), SkMatrix::I());
preroll_context()->raster_cache->CleanupAfterFrame();

// frame6
preroll_context()->raster_cache->PrepareNewFrame();
preroll_context()->raster_cached_entries.clear();
layer->Preroll(preroll_context(), SkMatrix::I());
preroll_context()->raster_cache->CleanupAfterFrame();

// Cause of the cacheable_layer21's parent cacheable_layer2 has cached and
// has after third frames, we will remove the cacheable_layer21
EXPECT_FALSE(raster_cache()->HasCache(cacheable_layer21->asLayer(),
SkMatrix::I(),
RasterCacheLayerStrategy::kLayer));
}
}

Expand Down
12 changes: 4 additions & 8 deletions flow/layers/display_list_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ void DisplayListLayer::Preroll(PrerollContext* context,

Cacheable::AutoCache cache =
Cacheable::AutoCache::Create(this, context, matrix, bounds);

if (disp_list->can_apply_group_opacity()) {
context->subtree_can_inherit_opacity = true;
}
set_paint_bounds(bounds);
}

Expand All @@ -110,14 +112,8 @@ void DisplayListLayer::TryToCache(PrerollContext* context,
will_change_, ctm)) {
SkMatrix transformation_matrix = ctm;
transformation_matrix.preTranslate(offset_.x(), offset_.y());

context->subtree_can_inherit_opacity = true;
entry->matrix = transformation_matrix;
// if current Layer can be cached, we change the
// subtree_can_inherit_opacity to true
if (display_list()->can_apply_group_opacity()) {
context->subtree_can_inherit_opacity = true;
}
// default cache current display_list
return;
}
entry->MarkNotCache();
Expand Down
25 changes: 18 additions & 7 deletions flow/raster_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,33 +408,44 @@ bool RasterCache::Prepare(PrerollContext* context,

void RasterCache::Touch(Layer* layer,
const SkMatrix& ctm,
RasterCacheLayerStrategy strategey) {
RasterCacheLayerStrategy strategey,
bool parent_had_cached) {
auto cache_key_optional =
TryToMakeRasterCacheKeyForLayer(layer, strategey, ctm);
if (!cache_key_optional) {
return;
}
Touch(cache_key_optional.value());
Touch(cache_key_optional.value(), parent_had_cached);
}

void RasterCache::Touch(SkPicture* picture,
const SkMatrix& transformation_matrix) {
const SkMatrix& transformation_matrix,
bool parent_had_cached) {
RasterCacheKey cache_key(picture->uniqueID(), RasterCacheKeyType::kPicture,
transformation_matrix);
Touch(cache_key);
Touch(cache_key, parent_had_cached);
}

void RasterCache::Touch(DisplayList* display_list,
const SkMatrix& transformation_matrix) {
const SkMatrix& transformation_matrix,
bool parent_had_cached) {
RasterCacheKey cache_key(display_list->unique_id(),
RasterCacheKeyType::kDisplayList,
transformation_matrix);
Touch(cache_key);
Touch(cache_key, parent_had_cached);
}

void RasterCache::Touch(const RasterCacheKey& cache_key) {
void RasterCache::Touch(const RasterCacheKey& cache_key,
bool parent_had_cached) {
auto it = cache_.find(cache_key);
if (it != cache_.end()) {
if (parent_had_cached) {
// current entry has beyond can live frame, try to remove it
if (--it->second.survive_frame_count <= 0) {
it->second.used_this_frame = false;
}
return;
}
it->second.used_this_frame = true;
it->second.access_count++;
}
Expand Down
16 changes: 12 additions & 4 deletions flow/raster_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,17 @@ class RasterCache {
// used for this frame in order to not get evicted. This is needed during
// partial repaint for layers that are outside of current clip and are culled
// away.
void Touch(SkPicture* picture, const SkMatrix& transformation_matrix);
void Touch(DisplayList* display_list, const SkMatrix& transformation_matrix);
void Touch(SkPicture* picture,
const SkMatrix& transformation_matrix,
bool parent_cached = false);
void Touch(DisplayList* display_list,
const SkMatrix& transformation_matrix,
bool parent_cached = false);
void Touch(
Layer* layer,
const SkMatrix& ctm,
RasterCacheLayerStrategy strategey = RasterCacheLayerStrategy::kLayer);
RasterCacheLayerStrategy strategey = RasterCacheLayerStrategy::kLayer,
bool parent_cached = false);

bool Prepare(
PrerollContext* context,
Expand Down Expand Up @@ -342,10 +347,13 @@ class RasterCache {
struct Entry {
bool used_this_frame = false;
size_t access_count = 0;
// if this entry's parent has cached, we will remove this entry after the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably shouldn't introduce this concept here.

The concept of a survival count has been proposed, but I think the last PR that tried to introduce it is stalled on lack of evidence of its value compared to other fixes.

See #31925

Let's leave survival for another PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that parents caching is not likely to be a short-lived state and waiting 3 frames to make sure they are going to keep caching is probably not going to save many child entries in the long term.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a concept to keep in mind, but I think it is early to introduce it with this refactoring which is more about consolidating the cache management into a post-Preroll, pre-Paint cycle.

// survive_frame_count.
unsigned survive_frame_count = 3;
std::unique_ptr<RasterCacheResult> image;
};

void Touch(const RasterCacheKey& cache_key);
void Touch(const RasterCacheKey& cache_key, bool parent_cached = false);

bool Draw(const RasterCacheKey& cache_key,
SkCanvas& canvas,
Expand Down
6 changes: 3 additions & 3 deletions flow/raster_cacheable_entry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void CacheableLayerWrapper::TouchRasterCache(PrerollContext* context,
auto strategy = cache_children_ ? RasterCacheLayerStrategy::kLayerChildren
: RasterCacheLayerStrategy::kLayer;
auto* cache = context->raster_cache;
cache->Touch(layer, matrix, strategy);
cache->Touch(layer, matrix, strategy, true);
}

bool CacheableDisplayListWrapper::TryToPrepareRasterCache(
Expand All @@ -55,7 +55,7 @@ bool CacheableDisplayListWrapper::TryToPrepareRasterCache(

void CacheableDisplayListWrapper::TouchRasterCache(PrerollContext* context,
const SkMatrix& matrix) {
context->raster_cache->Touch(display_list_, matrix);
context->raster_cache->Touch(display_list_, matrix, true);
}

bool CacheableSkPictureWrapper::TryToPrepareRasterCache(
Expand All @@ -67,7 +67,7 @@ bool CacheableSkPictureWrapper::TryToPrepareRasterCache(
return true;
}
// current bound is not intersect with cull_rect, touch the sk_picture
cache->Touch(sk_picture_, matrix);
cache->Touch(sk_picture_, matrix, true);
return false;
}

Expand Down