Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ba9ddaa

Browse files
committed
Add tests
1 parent 53fc806 commit ba9ddaa

File tree

7 files changed

+50
-7
lines changed

7 files changed

+50
-7
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ FILE: ../../../flutter/flow/compositor_context.cc
102102
FILE: ../../../flutter/flow/compositor_context.h
103103
FILE: ../../../flutter/flow/diff_context.cc
104104
FILE: ../../../flutter/flow/diff_context.h
105+
FILE: ../../../flutter/flow/diff_context_unittests.cc
105106
FILE: ../../../flutter/flow/embedded_view_params_unittests.cc
106107
FILE: ../../../flutter/flow/embedded_views.cc
107108
FILE: ../../../flutter/flow/embedded_views.h

flow/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ if (enable_unittests) {
128128
testonly = true
129129

130130
sources = [
131+
"diff_context_unittests.cc",
131132
"embedded_view_params_unittests.cc",
132133
"flow_run_all_unittests.cc",
133134
"flow_test_utils.cc",

flow/diff_context.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ void DiffContext::AlignRect(SkIRect& rect,
8383
if (right % horizontal_alignment != 0) {
8484
right += horizontal_alignment - right % horizontal_alignment;
8585
}
86-
if (bottom % horizontal_alignment != 0) {
87-
bottom += horizontal_alignment - bottom % horizontal_alignment;
86+
if (bottom % vertical_alignment != 0) {
87+
bottom += vertical_alignment - bottom % vertical_alignment;
8888
}
8989
right = std::min(right, frame_size_.width());
9090
bottom = std::min(bottom, frame_size_.height());

flow/diff_context.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ class DiffContext {
137137
// clip_alignment controls the alignment of resulting frame and surface
138138
// damage.
139139
Damage ComputeDamage(const SkIRect& additional_damage,
140-
int horizontal_clip_alignment = 1,
141-
int vertical_clip_alignment = 1) const;
140+
int horizontal_clip_alignment = 0,
141+
int vertical_clip_alignment = 0) const;
142142

143143
double frame_device_pixel_ratio() const { return frame_device_pixel_ratio_; };
144144

flow/diff_context_unittests.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/flow/testing/diff_context_test.h"
6+
7+
namespace flutter {
8+
namespace testing {
9+
10+
TEST_F(DiffContextTest, ClipAlignment) {
11+
MockLayerTree t1;
12+
t1.root()->Add(
13+
CreatePictureLayer(CreatePicture(SkRect::MakeLTRB(30, 30, 50, 50), 1)));
14+
auto damage = DiffLayerTree(t1, MockLayerTree(), SkIRect::MakeEmpty(), 0, 0);
15+
EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(30, 30, 50, 50));
16+
EXPECT_EQ(damage.buffer_damage, SkIRect::MakeLTRB(30, 30, 50, 50));
17+
18+
damage = DiffLayerTree(t1, MockLayerTree(), SkIRect::MakeEmpty(), 1, 1);
19+
EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(30, 30, 50, 50));
20+
EXPECT_EQ(damage.buffer_damage, SkIRect::MakeLTRB(30, 30, 50, 50));
21+
22+
damage = DiffLayerTree(t1, MockLayerTree(), SkIRect::MakeEmpty(), 8, 1);
23+
EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(24, 30, 56, 50));
24+
EXPECT_EQ(damage.buffer_damage, SkIRect::MakeLTRB(24, 30, 56, 50));
25+
26+
damage = DiffLayerTree(t1, MockLayerTree(), SkIRect::MakeEmpty(), 1, 8);
27+
EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(30, 24, 50, 56));
28+
EXPECT_EQ(damage.buffer_damage, SkIRect::MakeLTRB(30, 24, 50, 56));
29+
30+
damage = DiffLayerTree(t1, MockLayerTree(), SkIRect::MakeEmpty(), 16, 16);
31+
EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(16, 16, 64, 64));
32+
EXPECT_EQ(damage.buffer_damage, SkIRect::MakeLTRB(16, 16, 64, 64));
33+
}
34+
35+
} // namespace testing
36+
} // namespace flutter

flow/testing/diff_context_test.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ DiffContextTest::DiffContextTest()
1515

1616
Damage DiffContextTest::DiffLayerTree(MockLayerTree& layer_tree,
1717
const MockLayerTree& old_layer_tree,
18-
const SkIRect& additional_damage) {
18+
const SkIRect& additional_damage,
19+
int horizontal_clip_alignment,
20+
int vertical_clip_alignment) {
1921
FML_CHECK(layer_tree.size() == old_layer_tree.size());
2022

2123
DiffContext dc(layer_tree.size(), 1, layer_tree.paint_region_map(),
2224
old_layer_tree.paint_region_map());
2325
dc.PushCullRect(
2426
SkRect::MakeIWH(layer_tree.size().width(), layer_tree.size().height()));
2527
layer_tree.root()->Diff(&dc, old_layer_tree.root());
26-
return dc.ComputeDamage(additional_damage);
28+
return dc.ComputeDamage(additional_damage, horizontal_clip_alignment,
29+
vertical_clip_alignment);
2730
}
2831

2932
sk_sp<SkPicture> DiffContextTest::CreatePicture(const SkRect& bounds,

flow/testing/diff_context_test.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class DiffContextTest : public ThreadTest {
3838

3939
Damage DiffLayerTree(MockLayerTree& layer_tree,
4040
const MockLayerTree& old_layer_tree,
41-
const SkIRect& additional_damage = SkIRect::MakeEmpty());
41+
const SkIRect& additional_damage = SkIRect::MakeEmpty(),
42+
int horizontal_clip_alignment = 0,
43+
int vertical_alignment = 0);
4244

4345
// Create picture consisting of filled rect with given color; Being able
4446
// to specify different color is useful to test deep comparison of pictures

0 commit comments

Comments
 (0)