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
Change the Cacheable interface capacity
  • Loading branch information
JsouLiang committed Jun 23, 2022
commit 45b28cf669627a19a73b50a9dbc7079920d9af48
31 changes: 9 additions & 22 deletions flow/layers/cacheable_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class Cacheable {
public:
Cacheable() = default;

enum class CacheType { kNone, kCurrent, kChildren, kTouch };

class AutoCache {
public:
static AutoCache Create(Cacheable* cacheable,
Expand All @@ -40,10 +38,7 @@ class Cacheable {
~AutoCache() {
cacheable_entry_->num_child_entries =
context_->raster_cached_entries.size() - current_index_;
// Get current layer's cache type
auto cache_type = layer_->NeedCaching(context_, matrix_);
// we should modify some parmas of the entry, like need_cache or matrix
layer_->ConfigCacheType(cacheable_entry_, cache_type);
layer_->TryToCache(context_, cacheable_entry_, matrix_);
cacheable_entry_->has_platform_view = context_->has_platform_view;
cacheable_entry_->has_texture_layer = context_->has_texture_layer;
}
Expand All @@ -67,22 +62,14 @@ class Cacheable {

virtual Layer* asLayer() = 0;

virtual CacheType NeedCaching(PrerollContext* context,
const SkMatrix& ctm) = 0;

// Usually, we have this case to do:
// 1. CacheType::kNone, which mean we don't need to cache this layer, so we
// set the entry's need_caching to false
// 2. CacheType::kChildren, which mean we need to cache the layer's children,
// so we mark children need cache
virtual void ConfigCacheType(RasterCacheableEntry* entry, CacheType type) {
if (type == Cacheable::CacheType::kNone) {
entry->need_caching = false;
} else if (type == Cacheable::CacheType::kChildren) {
// Replace Cacheable child
entry->MarkLayerChildrenNeedCached();
} else if (type == CacheType::kTouch) {
// touch the cache
virtual void TryToCache(PrerollContext* context,
RasterCacheableEntry* entry,
const SkMatrix& ctm) = 0;

void ShouldTouchCache(PrerollContext* context, RasterCacheableEntry* entry) {
// check if should touch the cache
if (context->has_platform_view || context->has_texture_layer ||
!SkRect::Intersects(context->cull_rect, asLayer()->paint_bounds())) {
entry->MarkTouchCache();
}
}
Expand Down
25 changes: 13 additions & 12 deletions flow/layers/color_filter_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,22 @@ void ColorFilterLayer::Preroll(PrerollContext* context,
ContainerLayer::Preroll(context, matrix);
}

Cacheable::CacheType ColorFilterLayer::NeedCaching(PrerollContext* context,
const SkMatrix& ctm) {
void ColorFilterLayer::TryToCache(PrerollContext* context,
RasterCacheableEntry* entry,
const SkMatrix& ctm) {
if (!context->raster_cache) {
return Cacheable::CacheType::kNone;
entry->MarkNotCache();
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The AutoCache shouldn't create any entries in the vector and return an AutoCache instance that does nothing (i.e. has no cacheable which will not do anything in the destructor, so TryToCache never gets called.)

if (!context->has_platform_view && !context->has_texture_layer &&
SkRect::Intersects(context->cull_rect, paint_bounds())) {
if (render_count_ >= kMinimumRendersBeforeCachingFilterLayer) {
return Cacheable::CacheType::kCurrent;
} else {
render_count_++;
return Cacheable::CacheType::kChildren;
}
// We should try to cache the layer or layer's children.
// First we should to check if we need to touch the cache.
ShouldTouchCache(context, entry);
if (render_count_ >= kMinimumRendersBeforeCachingFilterLayer) {
// entry default cache current layer
return;
}
return Cacheable::CacheType::kTouch;
render_count_++;
entry->MarkLayerChildrenNeedCached();
}

void ColorFilterLayer::Paint(PaintContext& context) const {
Expand Down
5 changes: 3 additions & 2 deletions flow/layers/color_filter_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ class ColorFilterLayer : public ContainerLayer, public Cacheable {

void Paint(PaintContext& context) const override;

Cacheable::CacheType NeedCaching(PrerollContext* context,
const SkMatrix& ctm) override;
void TryToCache(PrerollContext* context,
RasterCacheableEntry* entry,
const SkMatrix& ctm) override;

Layer* asLayer() override { return this; }

Expand Down
29 changes: 13 additions & 16 deletions flow/layers/display_list_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ void DisplayListLayer::Preroll(PrerollContext* context,
set_paint_bounds(bounds);
}

Cacheable::CacheType DisplayListLayer::NeedCaching(PrerollContext* context,
const SkMatrix& ctm) {
void DisplayListLayer::TryToCache(PrerollContext* context,
RasterCacheableEntry* entry,
const SkMatrix& ctm) {
if (auto* cache = context->raster_cache) {
TRACE_EVENT0("flutter", "DisplayListLayer::RasterCache (Preroll)");
// For display_list_layer if the context has raster_cache, we will try to
Expand All @@ -114,26 +115,22 @@ Cacheable::CacheType DisplayListLayer::NeedCaching(PrerollContext* context,
SkMatrix transformation_matrix = ctm;
transformation_matrix.preTranslate(offset_.x(), offset_.y());

context->raster_cached_entries.back()->matrix = transformation_matrix;
entry->matrix = transformation_matrix;
// if current Layer can be cached, we change the
// subtree_can_inherit_opacity to true
context->subtree_can_inherit_opacity = true;
// default cache current display_list
return;
}
return Cacheable::CacheType::kCurrent;
entry->MarkNotCache();
return;
}
return Cacheable::CacheType::kTouch;
}
return Cacheable::CacheType::kNone;
}

void DisplayListLayer::ConfigCacheType(RasterCacheableEntry* cacheable_entry,
CacheType cache_type) {
cacheable_entry->need_caching = true;
if (cache_type == Cacheable::CacheType::kTouch) {
cacheable_entry->MarkTouchCache();
} else if (cache_type == Cacheable::CacheType::kNone) {
cacheable_entry->need_caching = false;
// current bound is not intersect with cull_rect, touch the display_list
entry->MarkTouchCache();
return;
}
entry->MarkNotCache();
return;
}

void DisplayListLayer::Paint(PaintContext& context) const {
Expand Down
8 changes: 3 additions & 5 deletions flow/layers/display_list_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ class DisplayListLayer : public Layer, public Cacheable {
return this;
}

Cacheable::CacheType NeedCaching(PrerollContext* context,
const SkMatrix& ctm) override;
virtual void TryToCache(PrerollContext* context,
RasterCacheableEntry* entry,
const SkMatrix& ctm) override;

Layer* asLayer() override { return this; }

void ConfigCacheType(RasterCacheableEntry* cacheable_entry,
CacheType cache_type) override;

void Preroll(PrerollContext* frame, const SkMatrix& matrix) override;

void Paint(PaintContext& context) const override;
Expand Down
67 changes: 36 additions & 31 deletions flow/layers/image_filter_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "flutter/flow/layers/image_filter_layer.h"
#include "flutter/flow/layers/layer.h"
#include "flutter/flow/layers/shader_mask_layer.h"
#include "flutter/flow/raster_cacheable_entry.h"

namespace flutter {
Expand Down Expand Up @@ -74,41 +75,45 @@ void ImageFilterLayer::Preroll(PrerollContext* context,
set_paint_bounds(child_bounds);
}

Cacheable::CacheType ImageFilterLayer::NeedCaching(PrerollContext* context,
const SkMatrix& ctm) {
void ImageFilterLayer::TryToCache(PrerollContext* context,
RasterCacheableEntry* entry,
const SkMatrix& ctm) {
if (!filter_ || !context->raster_cache) {
return Cacheable::CacheType::kNone;
entry->MarkNotCache();
return;
}
if (!context->has_platform_view && !context->has_texture_layer &&
SkRect::Intersects(context->cull_rect, paint_bounds())) {
if (render_count_ >= kMinimumRendersBeforeCachingFilterLayer) {
return Cacheable::CacheType::kCurrent;
}
transformed_filter_ = nullptr;
// This ImageFilterLayer is not yet considered stable so we
// increment the count to measure how many times it has been
// seen from frame to frame.
render_count_++;

// Now we will try to pre-render the children into the cache.
// To apply the filter to pre-rendered children, we must first
// modify the filter to be aware of the transform under which
// the cached bitmap was produced. Some SkImageFilter
// instances can do this operation on some transforms and some
// (filters or transforms) cannot. We can only cache the children
// and apply the filter on the fly if this operation succeeds.
transformed_filter_ = filter_->makeWithLocalMatrix(ctm);
if (transformed_filter_) {
// With a modified SkImageFilter we can now try to cache the
// children to avoid their rendering costs if they remain
// stable between frames and also avoiding a rendering surface
// switch during the Paint phase even if they are not stable.
// This benefit is seen most during animations.
return Cacheable::CacheType::kChildren;
}
if (render_count_ >= kMinimumRendersBeforeCachingFilterLayer) {
// entry default cache current layer
ShouldTouchCache(context, entry);
return;
}
transformed_filter_ = nullptr;
// This ImageFilterLayer is not yet considered stable so we
// increment the count to measure how many times it has been
// seen from frame to frame.
render_count_++;

// Now we will try to pre-render the children into the cache.
// To apply the filter to pre-rendered children, we must first
// modify the filter to be aware of the transform under which
// the cached bitmap was produced. Some SkImageFilter
// instances can do this operation on some transforms and some
// (filters or transforms) cannot. We can only cache the children
// and apply the filter on the fly if this operation succeeds.
transformed_filter_ = filter_->makeWithLocalMatrix(ctm);
if (transformed_filter_) {
// With a modified SkImageFilter we can now try to cache the
// children to avoid their rendering costs if they remain
// stable between frames and also avoiding a rendering surface
// switch during the Paint phase even if they are not stable.
// This benefit is seen most during animations.
ShouldTouchCache(context, entry);
entry->MarkLayerChildrenNeedCached();
return;
}

return Cacheable::CacheType::kTouch;
entry->MarkNotCache();
return;
}

void ImageFilterLayer::Paint(PaintContext& context) const {
Expand Down
5 changes: 3 additions & 2 deletions flow/layers/image_filter_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ class ImageFilterLayer : public ContainerLayer, public Cacheable {

void Paint(PaintContext& context) const override;

Cacheable::CacheType NeedCaching(PrerollContext* context,
const SkMatrix& ctm) override;
void TryToCache(PrerollContext* context,
RasterCacheableEntry* entry,
const SkMatrix& ctm) override;

Layer* asLayer() override { return this; }

Expand Down
42 changes: 16 additions & 26 deletions flow/layers/opacity_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,37 +68,27 @@ void OpacityLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
context->cull_rect = context->cull_rect.makeOffset(offset_.fX, offset_.fY);
}

void OpacityLayer::ConfigCacheType(RasterCacheableEntry* cacheable_entry,
CacheType cache_type) {
if (cache_type == Cacheable::CacheType::kChildren) {
void OpacityLayer::TryToCache(PrerollContext* context,
RasterCacheableEntry* entry,
const SkMatrix& ctm) {
if (!context->raster_cache) {
entry->MarkNotCache();
return;
}
// try to cache the opacity layer's children
if (!children_can_accept_opacity()) {
// Check the layer if should to touch the cache
ShouldTouchCache(context, entry);

auto child_matrix = child_matrix_;
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
child_matrix = RasterCache::GetIntegralTransCTM(child_matrix_);
#endif
cacheable_entry->matrix = child_matrix;
cacheable_entry->MarkLayerChildrenNeedCached();
if (cache_type == Cacheable::CacheType::kTouch) {
cacheable_entry->MarkTouchCache();
}
} else if (cache_type == Cacheable::CacheType::kNone) {
cacheable_entry->need_caching = false;
}
}

Cacheable::CacheType OpacityLayer::NeedCaching(PrerollContext* context,
const SkMatrix& ctm) {
if (!context->raster_cache) {
return Cacheable::CacheType::kNone;
}
if (!context->has_platform_view && !context->has_texture_layer &&
SkRect::Intersects(context->cull_rect, paint_bounds())) {
if (!children_can_accept_opacity()) {
return Cacheable::CacheType::kChildren;
}
return Cacheable::CacheType::kNone;
entry->matrix = child_matrix;
entry->MarkLayerChildrenNeedCached();
return;
}

return Cacheable::CacheType::kTouch;
entry->MarkNotCache();
}

void OpacityLayer::Paint(PaintContext& context) const {
Expand Down
7 changes: 3 additions & 4 deletions flow/layers/opacity_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ class OpacityLayer : public ContainerLayer, public Cacheable {

void Paint(PaintContext& context) const override;

Cacheable::CacheType NeedCaching(PrerollContext* context,
const SkMatrix& ctm) override;

void ConfigCacheType(RasterCacheableEntry* entry, CacheType type) override;
void TryToCache(PrerollContext* context,
RasterCacheableEntry* entry,
const SkMatrix& ctm) override;

// Returns whether the children are capable of inheriting an opacity value
// and modifying their rendering accordingly. This value is only guaranteed
Expand Down
35 changes: 17 additions & 18 deletions flow/layers/picture_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,37 +120,36 @@ void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
set_paint_bounds(bounds);
}

Cacheable::CacheType PictureLayer::NeedCaching(PrerollContext* context,
const SkMatrix& ctm) {
void PictureLayer::TryToCache(PrerollContext* context,
RasterCacheableEntry* entry,
const SkMatrix& ctm) {
if (auto* cache = context->raster_cache) {
TRACE_EVENT0("flutter", "PictureLayer::RasterCache (Preroll)");
if (context->cull_rect.intersects(paint_bounds())) {
// For sk_picture_layer if the context has raster_cache, we will try to
// collection it when we raster cache it, we will to decision Prepare or
// Touch cache
if (context->cull_rect.intersect(paint_bounds())) {
if (cache->ShouldBeCached(context, picture(), is_complex_, will_change_,
ctm)) {
SkMatrix transformation_matrix = ctm;
transformation_matrix.preTranslate(offset_.x(), offset_.y());

context->raster_cached_entries.back()->matrix = transformation_matrix;

entry->matrix = transformation_matrix;
// if current Layer can be cached, we change the
// subtree_can_inherit_opacity to true
context->subtree_can_inherit_opacity = true;
return Cacheable::CacheType::kCurrent;
return;
}
entry->MarkNotCache();
return;
} else {
// current bound is not intersect with cull_rect, touch the sk_picture
entry->MarkTouchCache();
return;
}
return Cacheable::CacheType::kTouch;
}
return Cacheable::CacheType::kNone;
}

void PictureLayer::ConfigCacheType(RasterCacheableEntry* cacheable_entry,
CacheType cache_type) {
cacheable_entry->need_caching = true;
if (cache_type == Cacheable::CacheType::kTouch) {
cacheable_entry->MarkTouchCache();
} else if (cache_type == Cacheable::CacheType::kNone) {
cacheable_entry->need_caching = false;
}
entry->MarkNotCache();
return;
}

void PictureLayer::Paint(PaintContext& context) const {
Expand Down
Loading