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
Rebase master
  • Loading branch information
JsouLiang committed Jun 23, 2022
commit 3e1ed6ce44ad4af12ddad53335aa26a0a0650ad1
7 changes: 4 additions & 3 deletions flow/layers/clip_shape_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ClipShapeLayer : public CacheableContainerLayer {
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
if (UsesSaveLayer()) {
context->SetTransform(
RasterCache::GetIntegralTransCTM(context->GetTransform()));
RasterCacheUtil::GetIntegralTransCTM(context->GetTransform()));
}
#endif
if (context->PushCullRect(clip_shape_bounds())) {
Expand Down Expand Up @@ -94,8 +94,9 @@ class ClipShapeLayer : public CacheableContainerLayer {
}

#ifndef SUPPORT_FRACTIONAL_TRANSLATION
context.internal_nodes_canvas->setMatrix(RasterCache::GetIntegralTransCTM(
context.leaf_nodes_canvas->getTotalMatrix()));
context.internal_nodes_canvas->setMatrix(
RasterCacheUtil::GetIntegralTransCTM(
context.leaf_nodes_canvas->getTotalMatrix()));
#endif

AutoCachePaint cache_paint(context);
Expand Down
9 changes: 8 additions & 1 deletion flow/layers/color_filter_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "flutter/flow/layers/color_filter_layer.h"
#include "flutter/flow/raster_cache_item.h"
#include "flutter/flow/raster_cache_util.h"

namespace flutter {

Expand All @@ -25,7 +26,7 @@ void ColorFilterLayer::Diff(DiffContext* context, const Layer* old_layer) {

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

DiffChildren(context, prev);
Expand All @@ -50,6 +51,12 @@ void ColorFilterLayer::Paint(PaintContext& context) const {
FML_DCHECK(needs_painting(context));

AutoCachePaint cache_paint(context);

#ifndef SUPPORT_FRACTIONAL_TRANSLATION
context.internal_nodes_canvas->setMatrix(RasterCacheUtil::GetIntegralTransCTM(
context.leaf_nodes_canvas->getTotalMatrix()));
#endif

if (context.raster_cache) {
if (layer_raster_cache_item_->IsCacheChildren()) {
cache_paint.setColorFilter(filter_);
Expand Down
2 changes: 1 addition & 1 deletion flow/layers/display_list_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void DisplayListLayer::Paint(PaintContext& context) const {
fml::TimePoint::Now() - start_time;

const SkRect device_bounds =
RasterCache::GetDeviceBounds(paint_bounds(), ctm);
RasterCacheUtil::GetDeviceBounds(paint_bounds(), ctm);
sk_sp<SkData> raster_data = offscreen_surface->GetRasterData(true);
LayerSnapshotData snapshot_data(unique_id(), offscreen_render_time,
raster_data, device_bounds);
Expand Down
8 changes: 7 additions & 1 deletion 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/raster_cache_util.h"

namespace flutter {

Expand All @@ -25,7 +26,7 @@ void ImageFilterLayer::Diff(DiffContext* context, const Layer* old_layer) {

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

if (filter_) {
Expand Down Expand Up @@ -85,6 +86,11 @@ void ImageFilterLayer::Paint(PaintContext& context) const {

AutoCachePaint cache_paint(context);

#ifndef SUPPORT_FRACTIONAL_TRANSLATION
context.internal_nodes_canvas->setMatrix(RasterCacheUtil::GetIntegralTransCTM(
context.leaf_nodes_canvas->getTotalMatrix()));
#endif

if (layer_raster_cache_item_->IsCacheChildren()) {
cache_paint.setImageFilter(transformed_filter_);
}
Expand Down
10 changes: 7 additions & 3 deletions flow/layers/layer_raster_cache_item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ void LayerRasterCacheItem::PrerollSetup(PrerollContext* context,
if (context->raster_cache && context->raster_cached_entries) {
context->raster_cached_entries->push_back(this);
child_items_ = context->raster_cached_entries->size();
matrix_ = matrix;
auto child_matrix = matrix;
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
child_matrix = RasterCacheUtil::GetIntegralTransCTM(matrix);
#endif
matrix_ = child_matrix;
}
}

Expand Down Expand Up @@ -52,7 +56,7 @@ void LayerRasterCacheItem::PrerollFinalize(PrerollContext* context,
if (num_cache_attempts_ >= layer_cached_threshold_) {
// the layer can be cached
cache_state_ = CacheState::kCurrent;
context->raster_cache->MarkSeen(key_id_, matrix);
context->raster_cache->MarkSeen(key_id_, matrix_);
} else {
num_cache_attempts_++;
// access current layer
Expand All @@ -66,7 +70,7 @@ void LayerRasterCacheItem::PrerollFinalize(PrerollContext* context,
RasterCacheKeyType::kLayerChildren);
}
cache_state_ = CacheState::kChildren;
context->raster_cache->MarkSeen(layer_children_id_.value(), matrix);
context->raster_cache->MarkSeen(layer_children_id_.value(), matrix_);
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion 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_cache_util.h"

namespace flutter {

Expand All @@ -28,7 +29,7 @@ void ShaderMaskLayer::Diff(DiffContext* context, const Layer* old_layer) {

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

DiffChildren(context, prev);
Expand All @@ -54,6 +55,11 @@ void ShaderMaskLayer::Paint(PaintContext& context) const {

AutoCachePaint cache_paint(context);

#ifndef SUPPORT_FRACTIONAL_TRANSLATION
context.internal_nodes_canvas->setMatrix(RasterCacheUtil::GetIntegralTransCTM(
context.leaf_nodes_canvas->getTotalMatrix()));
#endif

if (context.raster_cache) {
if (layer_raster_cache_item_->Draw(context, cache_paint.paint())) {
return;
Expand Down
11 changes: 6 additions & 5 deletions flow/raster_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void RasterCacheResult::draw(SkCanvas& canvas, const SkPaint* paint) const {
SkAutoCanvasRestore auto_restore(&canvas, true);

SkRect bounds =
RasterCache::GetDeviceBounds(logical_rect_, canvas.getTotalMatrix());
RasterCacheUtil::GetDeviceBounds(logical_rect_, canvas.getTotalMatrix());
FML_DCHECK(std::abs(bounds.width() - image_->dimensions().width()) <= 1 &&
std::abs(bounds.height() - image_->dimensions().height()) <= 1);
canvas.resetMatrix();
Expand All @@ -55,13 +55,14 @@ std::unique_ptr<RasterCacheResult> RasterCache::Rasterize(
const std::function<void(SkCanvas*)>& draw_function) {
TRACE_EVENT0("flutter", "RasterCachePopulate");

SkRect dest_rect = RasterCache::GetDeviceBounds(logical_rect, ctm);
SkRect dest_rect =
RasterCacheUtil::GetDeviceBounds(context.logical_rect, context.matrix);
// we always round out here so that the texture is integer sized.
int width = SkScalarCeilToInt(dest_rect.width());
int height = SkScalarCeilToInt(dest_rect.height());

const SkImageInfo image_info =
SkImageInfo::MakeN32Premul(width, height, sk_ref_sp(dst_color_space));
const SkImageInfo image_info = SkImageInfo::MakeN32Premul(
width, height, sk_ref_sp(context.dst_color_space));

sk_sp<SkSurface> surface =
context.gr_context ? SkSurface::MakeRenderTarget(
Expand All @@ -75,7 +76,7 @@ std::unique_ptr<RasterCacheResult> RasterCache::Rasterize(
SkCanvas* canvas = surface->getCanvas();
canvas->clear(SK_ColorTRANSPARENT);
canvas->translate(-dest_rect.left(), -dest_rect.top());
canvas->concat(ctm);
canvas->concat(context.matrix);
draw_function(canvas);

if (context.checkerboard) {
Expand Down
30 changes: 0 additions & 30 deletions flow/raster_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,36 +114,6 @@ class RasterCache {

virtual ~RasterCache() = default;

static SkRect GetDeviceBounds(const SkRect& rect, const SkMatrix& ctm) {
SkRect device_rect;
ctm.mapRect(&device_rect, rect);
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
device_rect.roundOut(&device_rect);
#endif
return device_rect;
}

/**
* @brief Snap the translation components of the matrix to integers.
*
* The snapping will only happen if the matrix only has scale and translation
* transformations.
*
* @param ctm the current transformation matrix.
* @return SkMatrix the snapped transformation matrix.
*/
static SkMatrix GetIntegralTransCTM(const SkMatrix& ctm) {
// Avoid integral snapping if the matrix has complex transformation to avoid
// the artifact observed in https://github.com/flutter/flutter/issues/41654.
if (!ctm.isScaleTranslate()) {
return ctm;
}
SkMatrix result = ctm;
result[SkMatrix::kMTransX] = SkScalarRoundToScalar(ctm.getTranslateX());
result[SkMatrix::kMTransY] = SkScalarRoundToScalar(ctm.getTranslateY());
return result;
}

// Draws this item if it should be rendered from the cache and returns
// true iff it was successfully drawn. Typically this should only fail
// if the item was disabled due to conditions discovered during |Preroll|
Expand Down
2 changes: 1 addition & 1 deletion flow/raster_cache_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ TEST(RasterCache, DeviceRectRoundOutForSkPicture) {
TEST(RasterCache, ComputeDeviceRectBasedOnFractionalTranslation) {
SkRect logical_rect = SkRect::MakeLTRB(0, 0, 300.2, 300.3);
SkMatrix ctm = SkMatrix::MakeAll(2.0, 0, 0, 0, 2.0, 0, 0, 0, 1);
auto result = RasterCache::GetDeviceBounds(logical_rect, ctm);
auto result = RasterCacheUtil::GetDeviceBounds(logical_rect, ctm);
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
ASSERT_EQ(result, SkRect::MakeLTRB(0.0, 0.0, 601.0, 601.0));
#else
Expand Down
10 changes: 5 additions & 5 deletions flow/raster_cache_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ struct RasterCacheUtil {

return true;
}

/**
* @brief Snap the translation components of the matrix to integers.
*
Expand All @@ -70,12 +69,13 @@ struct RasterCacheUtil {
return result;
}

static SkIRect GetDeviceBounds(const SkRect& rect, const SkMatrix& ctm) {
static SkRect GetDeviceBounds(const SkRect& rect, const SkMatrix& ctm) {
SkRect device_rect;
ctm.mapRect(&device_rect, rect);
SkIRect bounds;
device_rect.roundOut(&bounds);
return bounds;
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
device_rect.roundOut(&device_rect);
#endif
return device_rect;
}
};

Expand Down
4 changes: 2 additions & 2 deletions flow/testing/mock_raster_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void MockRasterCache::AddMockLayer(int width, int height) {
UpdateCacheEntry(
RasterCacheKeyID(layer.unique_id(), RasterCacheKeyType::kLayer),
r_context, [&](SkCanvas* canvas) {
SkIRect cache_rect = RasterCacheUtil::GetDeviceBounds(
SkRect cache_rect = RasterCacheUtil::GetDeviceBounds(
r_context.logical_rect, r_context.matrix);
return std::make_unique<MockRasterCacheResult>(cache_rect);
});
Expand Down Expand Up @@ -79,7 +79,7 @@ void MockRasterCache::AddMockPicture(int width, int height) {
UpdateCacheEntry(
RasterCacheKeyID(picture->uniqueID(), RasterCacheKeyType::kPicture),
r_context, [&](SkCanvas* canvas) {
SkIRect cache_rect = RasterCacheUtil::GetDeviceBounds(
SkRect cache_rect = RasterCacheUtil::GetDeviceBounds(
r_context.logical_rect, r_context.matrix);
return std::make_unique<MockRasterCacheResult>(cache_rect);
});
Expand Down