Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont snap in pre-roll (#36173) #36181

Merged
merged 4 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
4 changes: 2 additions & 2 deletions flow/layers/color_filter_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ void ColorFilterLayer::Preroll(PrerollContext* context,
const SkMatrix& matrix) {
Layer::AutoPrerollSaveLayerState save =
Layer::AutoPrerollSaveLayerState::Create(context);
AutoCache cache = AutoCache(layer_raster_cache_item_.get(), context, matrix);

SkMatrix child_matrix = matrix;
if (context->raster_cache) {
child_matrix = RasterCacheUtil::GetIntegralTransCTM(child_matrix);
}
AutoCache cache =
AutoCache(layer_raster_cache_item_.get(), context, child_matrix);

ContainerLayer::Preroll(context, child_matrix);
// We always use a saveLayer (or a cached rendering), so we
Expand Down
10 changes: 6 additions & 4 deletions flow/layers/image_filter_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ void ImageFilterLayer::Preroll(PrerollContext* context,

Layer::AutoPrerollSaveLayerState save =
Layer::AutoPrerollSaveLayerState::Create(context);

AutoCache cache = AutoCache(layer_raster_cache_item_.get(), context, matrix);

SkRect child_bounds = SkRect::MakeEmpty();
SkMatrix child_matrix = matrix;
if (context->raster_cache) {
child_matrix = RasterCacheUtil::GetIntegralTransCTM(child_matrix);
}

AutoCache cache =
AutoCache(layer_raster_cache_item_.get(), context, child_matrix);

SkRect child_bounds = SkRect::MakeEmpty();

PrerollChildren(context, child_matrix, &child_bounds);
context->subtree_can_inherit_opacity = true;

Expand Down
5 changes: 4 additions & 1 deletion flow/layers/opacity_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ void OpacityLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {

SkMatrix child_matrix = matrix;
child_matrix.preTranslate(offset_.fX, offset_.fY);
if (context->raster_cache) {
child_matrix = RasterCacheUtil::GetIntegralTransCTM(child_matrix);
}

// Similar to what's done in TransformLayer::Preroll, we have to apply the
// reverse transformation to the cull rect to properly cull child layers.
Expand All @@ -52,7 +55,7 @@ void OpacityLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
context->mutators_stack.PushOpacity(alpha_);

AutoCache auto_cache =
AutoCache(layer_raster_cache_item_.get(), context, matrix);
AutoCache(layer_raster_cache_item_.get(), context, child_matrix);
Layer::AutoPrerollSaveLayerState save =
Layer::AutoPrerollSaveLayerState::Create(context);

Expand Down
39 changes: 39 additions & 0 deletions flow/layers/opacity_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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/raster_cache_util.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 @@ -662,5 +663,43 @@ TEST_F(OpacityLayerDiffTest, FractionalTranslationWithRasterCache) {
EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(11, 11, 61, 61));
}

TEST_F(OpacityLayerTest, FullyOpaqueWithFractionalValues) {
use_mock_raster_cache(); // Ensure non-fractional alignment.

const SkPath child_path = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f));
const SkPoint layer_offset = SkPoint::Make(0.5f, 1.5f);
const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 0.5f);
const SkMatrix layer_transform =
SkMatrix::Translate(layer_offset.fX, layer_offset.fY);
const SkPaint child_paint = SkPaint(SkColors::kGreen);
const SkRect expected_layer_bounds =
layer_transform.mapRect(child_path.getBounds());
auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
auto layer = std::make_shared<OpacityLayer>(SK_AlphaOPAQUE, layer_offset);
layer->Add(mock_layer);
layer->Preroll(preroll_context(), initial_transform);

const SkPaint opacity_paint = SkPaint(SkColors::kBlack); // A = 1.0f
SkRect opacity_bounds;
expected_layer_bounds.makeOffset(-layer_offset.fX, -layer_offset.fY)
.roundOut(&opacity_bounds);
auto expected_draw_calls = std::vector(
{MockCanvas::DrawCall{0, MockCanvas::SaveData{1}},
MockCanvas::DrawCall{
1, MockCanvas::ConcatMatrixData{SkM44(layer_transform)}},
MockCanvas::DrawCall{
1, MockCanvas::SetMatrixData{SkM44(
RasterCacheUtil::GetIntegralTransCTM(layer_transform))}},
MockCanvas::DrawCall{
1, MockCanvas::SaveLayerData{opacity_bounds, opacity_paint, nullptr,
2}},
MockCanvas::DrawCall{2,
MockCanvas::DrawPathData{child_path, child_paint}},
MockCanvas::DrawCall{2, MockCanvas::RestoreData{1}},
MockCanvas::DrawCall{1, MockCanvas::RestoreData{0}}});
layer->Paint(paint_context());
EXPECT_EQ(mock_canvas().draw_calls(), expected_draw_calls);
}

} // namespace testing
} // namespace flutter
9 changes: 7 additions & 2 deletions flow/layers/shader_mask_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ void ShaderMaskLayer::Diff(DiffContext* context, const Layer* old_layer) {
void ShaderMaskLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
Layer::AutoPrerollSaveLayerState save =
Layer::AutoPrerollSaveLayerState::Create(context);
SkMatrix child_matrix = matrix;
if (context->raster_cache) {
child_matrix = RasterCacheUtil::GetIntegralTransCTM(child_matrix);
}

AutoCache cache = AutoCache(layer_raster_cache_item_.get(), context, matrix);
AutoCache cache =
AutoCache(layer_raster_cache_item_.get(), context, child_matrix);

ContainerLayer::Preroll(context, matrix);
ContainerLayer::Preroll(context, child_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;
Expand Down
41 changes: 41 additions & 0 deletions flow/layers/shader_mask_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/flow/layers/opacity_layer.h"
#include "flutter/flow/raster_cache.h"
#include "flutter/flow/raster_cache_util.h"
#include "flutter/flow/testing/layer_test.h"
#include "flutter/flow/testing/mock_layer.h"
#include "flutter/fml/macros.h"
Expand Down Expand Up @@ -389,5 +390,45 @@ TEST_F(ShaderMaskLayerTest, OpacityInheritance) {
EXPECT_TRUE(DisplayListsEQ_Verbose(expected_builder.Build(), display_list()));
}

TEST_F(ShaderMaskLayerTest, SimpleFilterWithRasterCache) {
use_mock_raster_cache(); // Ensure non-fractional alignment.

const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f);
const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f);
const SkRect layer_bounds = SkRect::MakeLTRB(2.0f, 4.0f, 6.5f, 6.5f);
const SkPath child_path = SkPath().addRect(child_bounds);
const SkPaint child_paint = SkPaint(SkColors::kYellow);
auto layer_filter =
SkPerlinNoiseShader::MakeFractalNoise(1.0f, 1.0f, 1, 1.0f);
auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
auto layer = std::make_shared<ShaderMaskLayer>(layer_filter, layer_bounds,
SkBlendMode::kSrc);
layer->Add(mock_layer);
layer->Preroll(preroll_context(), initial_transform);

SkPaint filter_paint;
filter_paint.setBlendMode(SkBlendMode::kSrc);
filter_paint.setShader(layer_filter);
layer->Paint(paint_context());
EXPECT_EQ(
mock_canvas().draw_calls(),
std::vector({MockCanvas::DrawCall{0, MockCanvas::SetMatrixData{SkM44(
SkMatrix::Translate(0.0, 0.0))}},
MockCanvas::DrawCall{
0, MockCanvas::SaveLayerData{child_bounds, SkPaint(),
nullptr, 1}},
MockCanvas::DrawCall{
1, MockCanvas::DrawPathData{child_path, child_paint}},
MockCanvas::DrawCall{
1, MockCanvas::ConcatMatrixData{SkM44::Translate(
layer_bounds.fLeft, layer_bounds.fTop)}},
MockCanvas::DrawCall{
1, MockCanvas::DrawRectData{SkRect::MakeWH(
layer_bounds.width(),
layer_bounds.height()),
filter_paint}},
MockCanvas::DrawCall{1, MockCanvas::RestoreData{0}}}));
}

} // namespace testing
} // namespace flutter
17 changes: 13 additions & 4 deletions flow/testing/mock_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,27 @@ void MockCacheableContainerLayer::Preroll(PrerollContext* context,
const SkMatrix& matrix) {
Layer::AutoPrerollSaveLayerState save =
Layer::AutoPrerollSaveLayerState::Create(context);
auto cache = AutoCache(layer_raster_cache_item_.get(), context, matrix);
SkMatrix child_matrix = matrix;
if (context->raster_cache) {
child_matrix = RasterCacheUtil::GetIntegralTransCTM(child_matrix);
}

auto cache = AutoCache(layer_raster_cache_item_.get(), context, child_matrix);

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

void MockCacheableLayer::Preroll(PrerollContext* context,
const SkMatrix& matrix) {
Layer::AutoPrerollSaveLayerState save =
Layer::AutoPrerollSaveLayerState::Create(context);
auto cache = AutoCache(raster_cache_item_.get(), context, matrix);
SkMatrix child_matrix = matrix;
if (context->raster_cache) {
child_matrix = RasterCacheUtil::GetIntegralTransCTM(child_matrix);
}
auto cache = AutoCache(raster_cache_item_.get(), context, child_matrix);

MockLayer::Preroll(context, matrix);
MockLayer::Preroll(context, child_matrix);
}

} // namespace testing
Expand Down