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 some failed cases; Add new test case for collect RasterCacheable …
…layer
  • Loading branch information
JsouLiang committed Jun 23, 2022
commit 0f60777025e2a0454a1933651caff0e8acd7a3e7
4 changes: 4 additions & 0 deletions flow/layers/color_filter_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/flow/compositor_context.h"
#include "flutter/flow/layers/color_filter_layer.h"

#include "flutter/display_list/display_list_color_filter.h"
#include "flutter/flow/layers/opacity_layer.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/flow/testing/layer_test.h"
#include "flutter/flow/testing/mock_layer.h"
#include "flutter/fml/macros.h"
Expand Down Expand Up @@ -253,6 +255,7 @@ TEST_F(ColorFilterLayerTest, CacheChild) {
RasterCacheLayerStrategy::kLayerChildren));

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

EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)1);
EXPECT_FALSE(raster_cache()->Draw(mock_layer.get(), other_canvas));
Expand Down Expand Up @@ -303,6 +306,7 @@ TEST_F(ColorFilterLayerTest, CacheChildren) {
RasterCacheLayerStrategy::kLayerChildren));

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

EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)1);
EXPECT_FALSE(raster_cache()->Draw(mock_layer1.get(), other_canvas));
Expand Down
27 changes: 27 additions & 0 deletions flow/layers/container_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "flutter/flow/testing/mock_layer.h"
#include "flutter/fml/macros.h"
#include "flutter/testing/mock_canvas.h"
#include "gtest/gtest.h"

namespace flutter {
namespace testing {
Expand Down Expand Up @@ -246,6 +247,32 @@ TEST_F(ContainerLayerTest, OpacityInheritance) {
container2->Preroll(context, SkMatrix::I());
EXPECT_FALSE(context->subtree_can_inherit_opacity);
}
TEST_F(ContainerLayerTest, CollectionCacheableLayer) {
SkPath child_path;
child_path.addRect(5.0f, 6.0f, 20.5f, 21.5f);
SkPaint child_paint(SkColors::kGreen);
SkMatrix initial_transform = SkMatrix::Translate(-0.5f, -0.5f);

auto mock_layer1 = std::make_shared<MockLayer>(SkPath(), child_paint);
auto mock_cacheable_container_layer1 =
std::make_shared<MockCacheableContainerLayer>();
auto mock_container_layer = std::make_shared<ContainerLayer>();
auto mock_cacheable_layer =
std::make_shared<MockCacheableLayer>(child_path, child_paint);
mock_cacheable_container_layer1->Add(mock_cacheable_layer);

// ContainerLayer
// |- MockLayer
// |- MockCacheableContainerLayer
// |- MockCacheableLayer
auto layer = std::make_shared<ContainerLayer>();
layer->Add(mock_cacheable_container_layer1);
layer->Add(mock_layer1);

layer->Preroll(preroll_context(), initial_transform);
ASSERT_EQ(preroll_context()->raster_cached_entries.size(),
static_cast<const unsigned long>(2));
}

using ContainerLayerDiffTest = DiffContextTest;

Expand Down
3 changes: 3 additions & 0 deletions flow/layers/image_filter_layer_unittests.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_tree.h"
#include "flutter/flow/layers/transform_layer.h"
#include "flutter/flow/testing/diff_context_test.h"
#include "flutter/flow/testing/layer_test.h"
Expand Down Expand Up @@ -306,6 +307,7 @@ TEST_F(ImageFilterLayerTest, CacheChild) {
RasterCacheLayerStrategy::kLayerChildren));

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

EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)1);
EXPECT_FALSE(raster_cache()->Draw(mock_layer.get(), other_canvas));
Expand Down Expand Up @@ -357,6 +359,7 @@ TEST_F(ImageFilterLayerTest, CacheChildren) {
RasterCacheLayerStrategy::kLayerChildren));

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

EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)1);
EXPECT_FALSE(raster_cache()->Draw(mock_layer1.get(), other_canvas));
Expand Down
45 changes: 21 additions & 24 deletions flow/layers/layer_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "flutter/flow/layer_snapshot_store.h"
#include "flutter/flow/layers/cacheable_layer.h"
#include "flutter/flow/layers/layer.h"
#include "flutter/flow/raster_cache.h"
#include "flutter/fml/time/time_point.h"
#include "flutter/fml/trace_event.h"
#include "include/core/SkMatrix.h"
Expand Down Expand Up @@ -66,38 +65,36 @@ bool LayerTree::Preroll(CompositorContext::ScopedFrame& frame,

root_layer_->Preroll(&context, frame.root_surface_transformation());

RasterCache(frame, &context);
TryToRasterCache(&context);

return context.surface_needs_readback;
}

void LayerTree::RasterCache(CompositorContext::ScopedFrame& frame,
PrerollContext* context,
bool ignore_raster_cache) {
auto* color_space = GetColorSpace(frame.canvas());
auto* raster_cache =
ignore_raster_cache ? nullptr : &frame.context().raster_cache();
void LayerTree::TryToRasterCache(PrerollContext* context,
bool ignore_raster_cache) {
auto mutator_stack = MutatorsStack();
for (unsigned i = 0; i < context->raster_cached_entries.size(); i++) {
auto& entry = context->raster_cached_entries[i];
if (entry->need_caching) {
PrerollContext context = {
raster_cache,
frame.gr_context(),
frame.view_embedder(),
mutator_stack,
color_space,
entry->cull_rect,
false,
frame.context().raster_time(),
frame.context().ui_time(),
frame.context().texture_registry(),
checkerboard_offscreen_layers_,
device_pixel_ratio_,
entry->has_platform_view,
entry->has_texture_layer,
PrerollContext preroll_context = {
// clang-format off
.raster_cache = context->raster_cache,
.gr_context = context->gr_context,
.view_embedder = context->view_embedder,
.mutators_stack = mutator_stack,
.dst_color_space = context->dst_color_space,
.cull_rect = entry->cull_rect,
.surface_needs_readback = false,
.raster_time = context->raster_time,
.ui_time = context->ui_time,
.texture_registry = context->texture_registry,
.checkerboard_offscreen_layers = context->checkerboard_offscreen_layers,
.frame_device_pixel_ratio = context->frame_device_pixel_ratio,
.has_platform_view = entry->has_platform_view,
.has_texture_layer = entry->has_texture_layer,
// clang-format on
};
entry->TryToPrepareRasterCache(&context);
entry->TryToPrepareRasterCache(&preroll_context);
Copy link
Contributor

Choose a reason for hiding this comment

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

This can fail for a number of reasons and yet you always skip the children. This method should return a true/false success status and the children should only be skipped if it fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

Even if it succeeds, the children may want to touch their entries, but I think we need some basic logic change in the raster cache to do this. They probably shouldn't keep their cached images for too long after they are superseded by a parent's cache, but they may want to mark their "Entry" in the raster cache so that their eligibility for caching remains valid - that way if the parent stops caching they can step in and cache themselves without having to count up from 0 accesses.

i += entry->num_child_entries;
}
}
Expand Down
6 changes: 2 additions & 4 deletions flow/layers/layer_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "flutter/flow/compositor_context.h"
#include "flutter/flow/layers/layer.h"
#include "flutter/flow/raster_cache.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/time/time_delta.h"
#include "third_party/skia/include/core/SkPicture.h"
Expand All @@ -33,9 +32,8 @@ class LayerTree {
bool ignore_raster_cache = false,
SkRect cull_rect = kGiantRect);

void RasterCache(CompositorContext::ScopedFrame& frame,
PrerollContext* context,
bool ignore_raster_cache = false);
static void TryToRasterCache(PrerollContext* context,
bool ignore_raster_cache = false);

void Paint(CompositorContext::ScopedFrame& frame,
bool ignore_raster_cache = false) const;
Expand Down
5 changes: 3 additions & 2 deletions flow/layers/layer_tree_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stddef.h>
#include "flutter/flow/layers/layer_tree.h"

#include "flutter/flow/compositor_context.h"
Expand All @@ -14,7 +15,6 @@

namespace flutter {
namespace testing {

class LayerTreeTest : public CanvasTest {
public:
LayerTreeTest()
Expand Down Expand Up @@ -198,7 +198,7 @@ TEST_F(LayerTreeTest, PrerollContextInitialization) {
// PrerollContext that this test must be revisited and updated.
// If any fields get removed or replaced, then the expect_defaults closure
// will fail to compile, again bringing attention to updating this test.
EXPECT_EQ(sizeof(PrerollContext), size_t(104));
EXPECT_EQ(sizeof(PrerollContext), size_t(128));

MutatorsStack mock_mutators;
FixedRefreshRateStopwatch mock_raster_time;
Expand All @@ -225,6 +225,7 @@ TEST_F(LayerTreeTest, PrerollContextInitialization) {
EXPECT_EQ(context.has_texture_layer, false);

EXPECT_EQ(context.subtree_can_inherit_opacity, false);
EXPECT_EQ(context.raster_cached_entries.size(), static_cast<size_t>(0));
};

// These 4 initializers are required because they are handled by reference
Expand Down
3 changes: 3 additions & 0 deletions flow/layers/opacity_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "flutter/flow/layers/clip_rect_layer.h"
#include "flutter/flow/layers/image_filter_layer.h"
#include "flutter/flow/layers/transform_layer.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/flow/testing/diff_context_test.h"
#include "flutter/flow/testing/layer_test.h"
#include "flutter/flow/testing/mock_layer.h"
Expand Down Expand Up @@ -106,6 +107,7 @@ TEST_F(OpacityLayerTest, CacheChild) {
RasterCacheLayerStrategy::kLayerChildren));

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

EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)1);
EXPECT_FALSE(raster_cache()->Draw(mock_layer.get(), other_canvas));
Expand Down Expand Up @@ -156,6 +158,7 @@ TEST_F(OpacityLayerTest, CacheChildren) {
RasterCacheLayerStrategy::kLayerChildren));

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

EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)1);
EXPECT_FALSE(raster_cache()->Draw(mock_layer1.get(), other_canvas));
Expand Down
31 changes: 19 additions & 12 deletions flow/layers/shader_mask_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

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

namespace flutter {

Expand All @@ -12,7 +13,9 @@ ShaderMaskLayer::ShaderMaskLayer(sk_sp<SkShader> shader,
: shader_(shader),
mask_rect_(mask_rect),
blend_mode_(blend_mode),
render_count_(1) {}
render_count_(1) {
set_layer_can_inherit_opacity(true);
}

void ShaderMaskLayer::Diff(DiffContext* context, const Layer* old_layer) {
DiffContext::AutoSubtreeRestore subtree(context);
Expand All @@ -25,6 +28,11 @@ void ShaderMaskLayer::Diff(DiffContext* context, const Layer* old_layer) {
}
}

#ifndef SUPPORT_FRACTIONAL_TRANSLATION
context->SetTransform(
RasterCache::GetIntegralTransCTM(context->GetTransform()));
#endif

DiffChildren(context, prev);

context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
Expand All @@ -33,34 +41,33 @@ void ShaderMaskLayer::Diff(DiffContext* context, const Layer* old_layer) {
void ShaderMaskLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
Layer::AutoPrerollSaveLayerState save =
Layer::AutoPrerollSaveLayerState::Create(context);
ContainerLayer::Preroll(context, matrix);

// We always paint with a saveLayer (or a cached rendering),
// so we can always apply opacity in any of those cases.
context->subtree_can_inherit_opacity = true;
Cacheable::AutoCache::Create(this, context, matrix);

SkMatrix child_matrix(matrix);
ContainerLayer::Preroll(context, matrix);
}

Cacheable::CacheType ShaderMaskLayer::NeedCaching(PrerollContext* context,
const SkMatrix& ctm) {
if (render_count_ >= kMinimumRendersBeforeCachingFilterLayer) {
TryToPrepareRasterCache(context, this, child_matrix,
RasterCacheLayerStrategy::kLayer);
return Cacheable::CacheType::kCurrent;
} else {
render_count_++;
return Cacheable::CacheType::kNone;
}
}

void ShaderMaskLayer::Paint(PaintContext& context) const {
TRACE_EVENT0("flutter", "ShaderMaskLayer::Paint");
FML_DCHECK(needs_painting(context));

AutoCachePaint cache_paint(context);

if (context.raster_cache &&
context.raster_cache->Draw(this, *context.leaf_nodes_canvas,
RasterCacheLayerStrategy::kLayer,
cache_paint.paint())) {
RasterCacheLayerStrategy::kLayer)) {
return;
}

AutoCachePaint cache_paint(context);
Layer::AutoSaveLayer save = Layer::AutoSaveLayer::Create(
context, paint_bounds(), cache_paint.paint());
PaintChildren(context);
Expand Down
8 changes: 7 additions & 1 deletion flow/layers/shader_mask_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#ifndef FLUTTER_FLOW_LAYERS_SHADER_MASK_LAYER_H_
#define FLUTTER_FLOW_LAYERS_SHADER_MASK_LAYER_H_

#include "flutter/flow/layers/cacheable_layer.h"
#include "flutter/flow/layers/container_layer.h"
#include "third_party/skia/include/core/SkShader.h"

namespace flutter {

class ShaderMaskLayer : public ContainerLayer {
class ShaderMaskLayer : public ContainerLayer, public Cacheable {
public:
ShaderMaskLayer(sk_sp<SkShader> shader,
const SkRect& mask_rect,
Expand All @@ -22,6 +23,11 @@ class ShaderMaskLayer : public ContainerLayer {

void Paint(PaintContext& context) const override;

Layer* asLayer() override { return this; };

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

private:
sk_sp<SkShader> shader_;
SkRect mask_rect_;
Expand Down
5 changes: 5 additions & 0 deletions flow/layers/shader_mask_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "flutter/flow/layers/shader_mask_layer.h"

#include "flutter/flow/layers/opacity_layer.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/flow/testing/layer_test.h"
#include "flutter/flow/testing/mock_layer.h"
#include "flutter/fml/macros.h"
Expand Down Expand Up @@ -305,16 +306,20 @@ TEST_F(ShaderMaskLayerTest, LayerCached) {
RasterCacheLayerStrategy::kLayer));

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

EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)0);
EXPECT_FALSE(raster_cache()->Draw(layer.get(), cache_canvas,
RasterCacheLayerStrategy::kLayer));

layer->Preroll(preroll_context(), initial_transform);
LayerTree::TryToRasterCache(preroll_context());
EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)0);
EXPECT_FALSE(raster_cache()->Draw(layer.get(), cache_canvas,
RasterCacheLayerStrategy::kLayer));

layer->Preroll(preroll_context(), initial_transform);
LayerTree::TryToRasterCache(preroll_context());
EXPECT_EQ(raster_cache()->GetLayerCachedEntriesCount(), (size_t)1);
EXPECT_TRUE(raster_cache()->Draw(layer.get(), cache_canvas,
RasterCacheLayerStrategy::kLayer));
Expand Down
8 changes: 7 additions & 1 deletion flow/raster_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,13 @@ bool RasterCache::ShouldBeCached(PrerollContext* context,
DisplayList* display_list,
bool is_complex,
bool will_change,
const SkMatrix& transformation_matrix) {
const SkMatrix& matrix) {
auto transformation_matrix = matrix;

if (!transformation_matrix.invert(nullptr)) {
// The matrix was singular. No point in going further.
return false;
}
if (!GenerateNewCacheInThisFrame()) {
return false;
}
Expand Down
Loading