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
Fix comments
  • Loading branch information
JsouLiang committed Jun 23, 2022
commit cdc123d9b7ad266c9fe3ed1cabf4c58d0f0afd63
6 changes: 3 additions & 3 deletions flow/layers/cacheable_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ AutoCache::AutoCache(RasterCacheItem* raster_cache_item,
: raster_cache_item_(raster_cache_item),
context_(context),
matrix_(matrix) {
if (checked()) {
if (cacheEnable()) {
raster_cache_item->PrerollSetup(context, matrix);
current_index_ = context_->raster_cached_entries->size();
}
}

bool AutoCache::checked() {
bool AutoCache::cacheEnable() {
return raster_cache_item_ && context_ && context_->raster_cache;
}

AutoCache::~AutoCache() {
if (checked()) {
if (cacheEnable()) {
raster_cache_item_->PrerollFinalize(context_, matrix_);
}
}
Expand Down
2 changes: 1 addition & 1 deletion flow/layers/cacheable_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AutoCache {
~AutoCache();

private:
inline bool checked();
inline bool cacheEnable();
int current_index_;
RasterCacheItem* raster_cache_item_ = nullptr;
PrerollContext* context_ = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion flow/layers/clip_rrect_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ TEST_F(ClipRRectLayerTest, LayerCached) {
cache_canvas, &paint));
}

TEST_F(ClipRRectLayerTest, LayerShouldNotCached) {
TEST_F(ClipRRectLayerTest, NoSaveLayerShouldNotCache) {
auto path1 = SkPath().addRect({10, 10, 30, 30});
SkPaint paint = SkPaint();
auto mock1 = MockLayer::MakeOpacityCompatible(path1);
Expand Down
38 changes: 19 additions & 19 deletions flow/layers/color_filter_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,26 +244,26 @@ TEST_F(ColorFilterLayerTest, CacheChild) {
other_canvas.setMatrix(other_transform);

use_mock_raster_cache();
const auto* cachebale_color_filter_item = layer->raster_cache_item();
const auto* cacheable_color_filter_item = layer->raster_cache_item();

EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)0);
EXPECT_EQ(cachebale_color_filter_item->cache_state(),
EXPECT_EQ(cacheable_color_filter_item->cache_state(),
RasterCacheItem::CacheState::kNone);
EXPECT_FALSE(cachebale_color_filter_item->GetId().has_value());
EXPECT_FALSE(cacheable_color_filter_item->GetId().has_value());

layer->Preroll(preroll_context(), initial_transform);
LayerTree::TryToRasterCache(cacheable_items(), &paint_context());

EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)1);
EXPECT_EQ(cachebale_color_filter_item->cache_state(),
EXPECT_EQ(cacheable_color_filter_item->cache_state(),
RasterCacheItem::CacheState::kChildren);
EXPECT_EQ(
cachebale_color_filter_item->GetId().value(),
cacheable_color_filter_item->GetId().value(),
RasterCacheKeyID(RasterCacheKeyID::LayerChildrenIds(layer.get()).value(),
RasterCacheKeyType::kLayerChildren));
EXPECT_FALSE(raster_cache()->Draw(
cachebale_color_filter_item->GetId().value(), other_canvas, &paint));
EXPECT_TRUE(raster_cache()->Draw(cachebale_color_filter_item->GetId().value(),
cacheable_color_filter_item->GetId().value(), other_canvas, &paint));
EXPECT_TRUE(raster_cache()->Draw(cacheable_color_filter_item->GetId().value(),
cache_canvas, &paint));
}

Expand All @@ -290,26 +290,26 @@ TEST_F(ColorFilterLayerTest, CacheChildren) {
use_mock_raster_cache();

EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)0);
const auto* cachebale_color_filter_item = layer->raster_cache_item();
const auto* cacheable_color_filter_item = layer->raster_cache_item();
EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)0);

EXPECT_EQ(cachebale_color_filter_item->cache_state(),
EXPECT_EQ(cacheable_color_filter_item->cache_state(),
RasterCacheItem::CacheState::kNone);
EXPECT_FALSE(cachebale_color_filter_item->GetId().has_value());
EXPECT_FALSE(cacheable_color_filter_item->GetId().has_value());

layer->Preroll(preroll_context(), initial_transform);
LayerTree::TryToRasterCache(cacheable_items(), &paint_context());

EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)1);
EXPECT_EQ(cachebale_color_filter_item->cache_state(),
EXPECT_EQ(cacheable_color_filter_item->cache_state(),
RasterCacheItem::CacheState::kChildren);
EXPECT_EQ(
cachebale_color_filter_item->GetId().value(),
cacheable_color_filter_item->GetId().value(),
RasterCacheKeyID(RasterCacheKeyID::LayerChildrenIds(layer.get()).value(),
RasterCacheKeyType::kLayerChildren));
EXPECT_FALSE(raster_cache()->Draw(
cachebale_color_filter_item->GetId().value(), other_canvas, &paint));
EXPECT_TRUE(raster_cache()->Draw(cachebale_color_filter_item->GetId().value(),
cacheable_color_filter_item->GetId().value(), other_canvas, &paint));
EXPECT_TRUE(raster_cache()->Draw(cacheable_color_filter_item->GetId().value(),
cache_canvas, &paint));
}

Expand All @@ -334,7 +334,7 @@ TEST_F(ColorFilterLayerTest, CacheColorFilterLayerSelf) {
other_canvas.setMatrix(other_transform);

use_mock_raster_cache();
const auto* cachebale_color_filter_item = layer->raster_cache_item();
const auto* cacheable_color_filter_item = layer->raster_cache_item();

// frame 1.
layer->Preroll(preroll_context(), initial_transform);
Expand All @@ -352,14 +352,14 @@ TEST_F(ColorFilterLayerTest, CacheColorFilterLayerSelf) {
EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)2);

// ImageFilterLayer default cache itself.
EXPECT_EQ(cachebale_color_filter_item->cache_state(),
EXPECT_EQ(cacheable_color_filter_item->cache_state(),
RasterCacheItem::CacheState::kCurrent);
EXPECT_EQ(cachebale_color_filter_item->GetId(),
EXPECT_EQ(cacheable_color_filter_item->GetId(),
RasterCacheKeyID(layer->unique_id(), RasterCacheKeyType::kLayer));
EXPECT_TRUE(raster_cache()->Draw(cachebale_color_filter_item->GetId().value(),
EXPECT_TRUE(raster_cache()->Draw(cacheable_color_filter_item->GetId().value(),
cache_canvas, &paint));
EXPECT_FALSE(raster_cache()->Draw(
cachebale_color_filter_item->GetId().value(), other_canvas, &paint));
cacheable_color_filter_item->GetId().value(), other_canvas, &paint));
}

TEST_F(ColorFilterLayerTest, OpacityInheritance) {
Expand Down
16 changes: 14 additions & 2 deletions flow/layers/container_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ TEST_F(ContainerLayerTest, RasterCacheTest) {
auto cacheable_layer21 =
std::make_shared<MockCacheableLayer>(child_path1, paint, 2);

// clang-format off
// layer
// |
// ________________________________ ________________________________
// | | |
// cacheable_container_layer1 mock_layer2 cacheable_container_layer2
// | |
// cacheable_container_layer11 cacheable_layer21
// |
// cacheable_layer111
// clang-format on

auto mock_layer1 = std::make_shared<MockLayer>(child_path1, child_paint1);
auto mock_layer2 = std::make_shared<MockLayer>(SkPath(), child_paint2);
auto mock_layer3 = std::make_shared<MockLayer>(child_path2, paint);
Expand All @@ -238,7 +250,7 @@ TEST_F(ContainerLayerTest, RasterCacheTest) {
SkCanvas cache_canvas;
cache_canvas.setMatrix(SkMatrix::I());

// frame1
// Initial Preroll for check the layer paint bounds
layer->Preroll(preroll_context(), SkMatrix::I());

EXPECT_EQ(mock_layer1->paint_bounds(),
Expand All @@ -254,7 +266,7 @@ TEST_F(ContainerLayerTest, RasterCacheTest) {
EXPECT_EQ(preroll_context()->raster_cached_entries->size(),
static_cast<unsigned long>(0));
{
// frame2
// frame1
use_mock_raster_cache();
preroll_context()->raster_cache->PrepareNewFrame();
layer->Preroll(preroll_context(), SkMatrix::I());
Expand Down
47 changes: 18 additions & 29 deletions flow/layers/display_list_raster_cache_item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,17 @@ void DisplayListRasterCacheItem::PrerollFinalize(PrerollContext* context,
}
auto* raster_cache = context->raster_cache;
SkRect bounds = display_list_->bounds().makeOffset(offset_.x(), offset_.y());
// We've marked the cache entry that we would like to cache so it stays
// alive, but if the following conditions apply then we need to set our
// state back to !cacheable_ so that we don't populate the entry later.
if (!SkRect::Intersects(context->cull_rect, bounds)) {
cache_state_ = CacheState::kNone;
return;
}
// Frame threshold has not yet been reached.
// If the display_list bounds and the cull_rect don't intersect then we will
// return prematurely. Another we will check the access count, if the access
// count is less than access_threshold we shouldn't cache the display_list.
if (raster_cache->MarkSeen(key_id_, transformation_matrix_) <
raster_cache->access_threshold()) {
raster_cache->access_threshold() ||
!SkRect::Intersects(context->cull_rect, bounds)) {
cache_state_ = CacheState::kNone;
} else {
context->subtree_can_inherit_opacity = true;
cache_state_ = CacheState::kCurrent;
return;
}
context->subtree_can_inherit_opacity = true;
cache_state_ = CacheState::kCurrent;
return;
}

Expand Down Expand Up @@ -151,31 +147,24 @@ bool DisplayListRasterCacheItem::TryToPrepareRasterCache(
// display_list or picture_list to calculate the memory they used, we
// shouldn't cache the current node if the memory is more significant than the
// limit.
if (!context.raster_cache || parent_cached ||
if (cache_state_ == kNone || !context.raster_cache || parent_cached ||
!context.raster_cache->GenerateNewCacheInThisFrame()) {
return false;
}
auto* raster_cache = context.raster_cache;
if (cache_state_ != kNone &&
raster_cache->MarkSeen(key_id_, transformation_matrix_) >=
context.raster_cache->access_threshold()) {
auto transformation_matrix = transformation_matrix_;
SkRect bounds =
display_list_->bounds().makeOffset(offset_.x(), offset_.y());
RasterCache::Context r_context = {
// clang-format off
SkRect bounds = display_list_->bounds().makeOffset(offset_.x(), offset_.y());
RasterCache::Context r_context = {
// clang-format off
.gr_context = context.gr_context,
.dst_color_space = context.dst_color_space,
.matrix = transformation_matrix,
.matrix = transformation_matrix_,
.logical_rect = bounds,
.flow_type = flow_type,
.checkerboard = context.checkerboard_offscreen_layers,
// clang-format on
};
return context.raster_cache->UpdateCacheEntry(
GetId().value(), r_context,
[=](SkCanvas* canvas) { display_list_->RenderTo(canvas); });
}
// clang-format on
};
return context.raster_cache->UpdateCacheEntry(
GetId().value(), r_context,
[=](SkCanvas* canvas) { display_list_->RenderTo(canvas); });
return false;
}
} // namespace flutter
1 change: 0 additions & 1 deletion flow/layers/image_filter_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ void ImageFilterLayer::Preroll(PrerollContext* context,

set_paint_bounds(child_bounds);

transformed_filter_ = nullptr;
transformed_filter_ = filter_->makeWithLocalMatrix(matrix);
if (transformed_filter_) {
layer_raster_cache_item_->MarkCacheChildren();
Copy link
Contributor

Choose a reason for hiding this comment

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

If it is false then you need to turn this flag off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Everytime when we entry the LayerRasterItem::PrerollSetup we will set the cache_state_ = kNone

void LayerRasterCacheItem::PrerollSetup(PrerollContext* context,
                                        const SkMatrix& matrix) {
  cache_state_ = CacheState::kNone;
 ...
}

I think if the transformed_filter_ is null, the cache_state is still kNone, we don't cache the layer's children. Even thought we set the flag is kChildren in last frame.

Copy link
Contributor

Choose a reason for hiding this comment

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

I disagree. transformed_filter_ being null has nothing to do with the cache item being in any state. It will be null if Skia can't handle the operation and for no other reason.

if the transform is the reason that Skia can't handle the operation then the status of whether transformed_filter_ is null could change any time the matrix changes and yet this code will only ever set "can_cache_children_" to true and never return it to false.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we can create a transformed filter then we can cache the children, otherwise we cannot. The ability to create the transformed filter can vary frame to frame independently of other factors about whether or not we can cache the layer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I know the transformed_filter_ if is null and the layer render_count is less than 3, we will cache nothing, if the transformed_filter_ isn't null and the layer render_count is less than 3, we will cache it children so if here will set the cache state is CahceChildren;
In layer_raster_cache_item first we will check the render_count if greate than 3, if so we well cache the layer

void LayerRasterCacheItem::PrerollFinalize(PrerollContext* context,
                                           const SkMatrix& matrix) {
  ....
  if (num_cache_attempts_ >= layer_cached_threshold_) {
    // the layer can be cached
    cache_state_ = CacheState::kCurrent;
    context->raster_cache->MarkSeen(key_id_, matrix_);
  } else {
    num_cache_attempts_++;
   ....
}

if the transformed_filter is not null and render_count less than 3, we cache children

void LayerRasterCacheItem::PrerollFinalize(PrerollContext* context,
                                           const SkMatrix& matrix) {
  if (num_cache_attempts_ >= layer_cached_threshold_) {
    // the layer can be cached
 ...
  } else {
    num_cache_attempts_++;
    // access current layer
    if (can_cache_children_) {
...
    }
  }
}

if the layer is not match any branch, we will cache none.

So for ImageFilterLayer if any logic which is I miss?

Copy link
Contributor

Choose a reason for hiding this comment

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

The creation of the transformed_filter can succeed or fail independently each time Preroll is called. The success on one frame has nothing to do with the success on a subsequent frame. It needs to be checked every frame and the value of "can_cache_children" must match the success for the current frame. On some frames it will be true, on others it will be false and can go back and forth between true and false as many times as it exists in the layer tree.

LayerCacheItem can only set the value to false in the initializer and then it can only be set to true after that by using "MarkCacheChildren". There is no way to set the value to false once it is set to true, but if a subsequent frame fails to create the transformed filter, then we need a way to reflect that by setting can_cache_children to false. How do we do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aha, Sorry, It's my mistake

Expand Down
34 changes: 17 additions & 17 deletions flow/layers/image_filter_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,26 +297,26 @@ TEST_F(ImageFilterLayerTest, CacheChild) {
SkPaint paint = SkPaint();

use_mock_raster_cache();
const auto* cachebale_image_filter_item = layer->raster_cache_item();
const auto* cacheable_image_filter_item = layer->raster_cache_item();

EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)0);
// ImageFilterLayer default cache itself.
EXPECT_EQ(cachebale_image_filter_item->cache_state(),
EXPECT_EQ(cacheable_image_filter_item->cache_state(),
RasterCacheItem::CacheState::kNone);
EXPECT_FALSE(cachebale_image_filter_item->Draw(paint_context(), &paint));
EXPECT_FALSE(cacheable_image_filter_item->Draw(paint_context(), &paint));

layer->Preroll(preroll_context(), initial_transform);
LayerTree::TryToRasterCache(cacheable_items(), &paint_context());

EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)1);
// The layer_cache_item's strategy is Children, mean we will must cache
// his children
EXPECT_EQ(cachebale_image_filter_item->cache_state(),
EXPECT_EQ(cacheable_image_filter_item->cache_state(),
RasterCacheItem::CacheState::kChildren);
EXPECT_TRUE(raster_cache()->Draw(cachebale_image_filter_item->GetId().value(),
EXPECT_TRUE(raster_cache()->Draw(cacheable_image_filter_item->GetId().value(),
cache_canvas, &paint));
EXPECT_FALSE(raster_cache()->Draw(
cachebale_image_filter_item->GetId().value(), other_canvas, &paint));
cacheable_image_filter_item->GetId().value(), other_canvas, &paint));
}

TEST_F(ImageFilterLayerTest, CacheChildren) {
Expand All @@ -342,13 +342,13 @@ TEST_F(ImageFilterLayerTest, CacheChildren) {

use_mock_raster_cache();

const auto* cachebale_image_filter_item = layer->raster_cache_item();
const auto* cacheable_image_filter_item = layer->raster_cache_item();
EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)0);

// ImageFilterLayer default cache itself.
EXPECT_EQ(cachebale_image_filter_item->cache_state(),
EXPECT_EQ(cacheable_image_filter_item->cache_state(),
RasterCacheItem::CacheState::kNone);
EXPECT_FALSE(cachebale_image_filter_item->Draw(paint_context(), &paint));
EXPECT_FALSE(cacheable_image_filter_item->Draw(paint_context(), &paint));

layer->Preroll(preroll_context(), initial_transform);
LayerTree::TryToRasterCache(cacheable_items(), &paint_context());
Expand All @@ -357,12 +357,12 @@ TEST_F(ImageFilterLayerTest, CacheChildren) {

// The layer_cache_item's strategy is Children, mean we will must cache his
// children
EXPECT_EQ(cachebale_image_filter_item->cache_state(),
EXPECT_EQ(cacheable_image_filter_item->cache_state(),
RasterCacheItem::CacheState::kChildren);
EXPECT_TRUE(raster_cache()->Draw(cachebale_image_filter_item->GetId().value(),
EXPECT_TRUE(raster_cache()->Draw(cacheable_image_filter_item->GetId().value(),
cache_canvas, &paint));
EXPECT_FALSE(raster_cache()->Draw(
cachebale_image_filter_item->GetId().value(), other_canvas, &paint));
cacheable_image_filter_item->GetId().value(), other_canvas, &paint));
}

TEST_F(ImageFilterLayerTest, CacheImageFilterLayerSelf) {
Expand All @@ -384,7 +384,7 @@ TEST_F(ImageFilterLayerTest, CacheImageFilterLayerSelf) {
SkPaint paint = SkPaint();

use_mock_raster_cache();
const auto* cachebale_image_filter_item = layer->raster_cache_item();
const auto* cacheable_image_filter_item = layer->raster_cache_item();
// frame 1.
layer->Preroll(preroll_context(), initial_transform);
layer->Paint(paint_context());
Expand All @@ -401,14 +401,14 @@ TEST_F(ImageFilterLayerTest, CacheImageFilterLayerSelf) {
EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)2);

// ImageFilterLayer default cache itself.
EXPECT_EQ(cachebale_image_filter_item->cache_state(),
EXPECT_EQ(cacheable_image_filter_item->cache_state(),
RasterCacheItem::CacheState::kCurrent);
EXPECT_EQ(cachebale_image_filter_item->GetId(),
EXPECT_EQ(cacheable_image_filter_item->GetId(),
RasterCacheKeyID(layer->unique_id(), RasterCacheKeyType::kLayer));
EXPECT_TRUE(raster_cache()->Draw(cachebale_image_filter_item->GetId().value(),
EXPECT_TRUE(raster_cache()->Draw(cacheable_image_filter_item->GetId().value(),
cache_canvas, &paint));
EXPECT_FALSE(raster_cache()->Draw(
cachebale_image_filter_item->GetId().value(), other_canvas, &paint));
cacheable_image_filter_item->GetId().value(), other_canvas, &paint));
}

TEST_F(ImageFilterLayerTest, OpacityInheritance) {
Expand Down
8 changes: 4 additions & 4 deletions flow/layers/layer_raster_cache_item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ LayerRasterCacheItem::LayerRasterCacheItem(Layer* layer,
bool can_cache_children)
: RasterCacheItem(
RasterCacheKeyID(layer->unique_id(), RasterCacheKeyType::kLayer),
// The layer raster_cache_item's cache state default value is none.
CacheState::kNone),
layer_(layer),
layer_cached_threshold_(layer_cached_threshold),
can_cache_children_(can_cache_children) {}

void LayerRasterCacheItem::PrerollSetup(PrerollContext* context,
const SkMatrix& matrix) {
cache_state_ = CacheState::kNone;
if (context->raster_cache && context->raster_cached_entries) {
context->raster_cached_entries->push_back(this);
child_items_ = context->raster_cached_entries->size();
Expand All @@ -38,7 +40,6 @@ std::unique_ptr<LayerRasterCacheItem> LayerRasterCacheItem::Make(

void LayerRasterCacheItem::PrerollFinalize(PrerollContext* context,
const SkMatrix& matrix) {
cache_state_ = CacheState::kNone;
if (!context->raster_cache || !context->raster_cached_entries) {
return;
}
Expand Down Expand Up @@ -109,9 +110,8 @@ bool LayerRasterCacheItem::Rasterize(const PaintContext& paint_context,

switch (cache_state_) {
case CacheState::kCurrent:
if (layer_->needs_painting(context)) {
layer_->Paint(context);
}
FML_DCHECK(layer_->needs_painting(context));
layer_->Paint(context);
break;
case CacheState::kChildren:
FML_DCHECK(layer_->as_container_layer());
Expand Down
3 changes: 2 additions & 1 deletion flow/layers/layer_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ void LayerTree::TryToRasterCache(
if (item->need_caching()) {
// try to cache current layer
// If parent failed to cache, just proceed to the next entry
if (item->TryToPrepareRasterCache(*paint_context)) {
// cache current entry, this entry's parent must not cache
if (item->TryToPrepareRasterCache(*paint_context, false)) {
// if parent cached, then foreach child layer to touch them.
for (unsigned j = 0; j < item->child_items(); j++) {
auto* child_item = raster_cached_items[i + j + 1];
Expand Down
Loading