Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: cc/output/filter_operations_unittest.cc

Issue 2114303002: cc: Add unit tests for non-identity matrix for FilterOperation::MapRect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: SkMatrix::MakeScale Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/output/filter_operation.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include "cc/output/filter_operations.h" 7 #include "cc/output/filter_operations.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/skia/include/effects/SkBlurImageFilter.h" 9 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
10 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" 10 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h"
(...skipping 14 matching lines...) Expand all
25 EXPECT_EQ(60, right); 25 EXPECT_EQ(60, right);
26 EXPECT_EQ(60, bottom); 26 EXPECT_EQ(60, bottom);
27 EXPECT_EQ(60, left); 27 EXPECT_EQ(60, left);
28 } 28 }
29 29
30 TEST(FilterOperationsTest, MapRectBlur) { 30 TEST(FilterOperationsTest, MapRectBlur) {
31 FilterOperations ops; 31 FilterOperations ops;
32 ops.Append(FilterOperation::CreateBlurFilter(20)); 32 ops.Append(FilterOperation::CreateBlurFilter(20));
33 EXPECT_EQ(gfx::Rect(-60, -60, 130, 130), 33 EXPECT_EQ(gfx::Rect(-60, -60, 130, 130),
34 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); 34 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
35 EXPECT_EQ(gfx::Rect(-120, -120, 260, 260),
36 ops.MapRect(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
37 EXPECT_EQ(gfx::Rect(-60, -70, 130, 130),
38 ops.MapRect(gfx::Rect(0, -10, 10, 10), SkMatrix::MakeScale(1, -1)));
35 } 39 }
36 40
37 TEST(FilterOperationsTest, MapRectReverseBlur) { 41 TEST(FilterOperationsTest, MapRectReverseBlur) {
38 FilterOperations ops; 42 FilterOperations ops;
39 ops.Append(FilterOperation::CreateBlurFilter(20)); 43 ops.Append(FilterOperation::CreateBlurFilter(20));
40 EXPECT_EQ(gfx::Rect(-60, -60, 130, 130), 44 EXPECT_EQ(gfx::Rect(-60, -60, 130, 130),
41 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); 45 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
46 EXPECT_EQ(
47 gfx::Rect(-120, -120, 260, 260),
48 ops.MapRectReverse(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
49 EXPECT_EQ(gfx::Rect(-60, -70, 130, 130),
50 ops.MapRectReverse(gfx::Rect(0, -10, 10, 10),
51 SkMatrix::MakeScale(1, -1)));
42 } 52 }
43 53
44 TEST(FilterOperationsTest, GetOutsetsDropShadowReferenceFilter) { 54 TEST(FilterOperationsTest, GetOutsetsDropShadowReferenceFilter) {
45 // TODO(hendrikw): We need to make outsets for reference filters be in line 55 // TODO(hendrikw): We need to make outsets for reference filters be in line
46 // with non-reference filters. See crbug.com/523534 56 // with non-reference filters. See crbug.com/523534
47 FilterOperations ops; 57 FilterOperations ops;
48 ops.Append( 58 ops.Append(
49 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make( 59 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make(
50 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), 60 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4),
51 SkIntToScalar(9), SK_ColorBLACK, 61 SkIntToScalar(9), SK_ColorBLACK,
(...skipping 12 matching lines...) Expand all
64 TEST(FilterOperationsTest, MapRectDropShadowReferenceFilter) { 74 TEST(FilterOperationsTest, MapRectDropShadowReferenceFilter) {
65 FilterOperations ops; 75 FilterOperations ops;
66 ops.Append( 76 ops.Append(
67 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make( 77 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make(
68 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), 78 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4),
69 SkIntToScalar(9), SK_ColorBLACK, 79 SkIntToScalar(9), SK_ColorBLACK,
70 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, 80 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
71 nullptr))); 81 nullptr)));
72 EXPECT_EQ(gfx::Rect(-9, -19, 34, 64), 82 EXPECT_EQ(gfx::Rect(-9, -19, 34, 64),
73 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); 83 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
84 EXPECT_EQ(gfx::Rect(-18, -38, 68, 128),
85 ops.MapRect(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
86 EXPECT_EQ(gfx::Rect(-9, -45, 34, 64),
87 ops.MapRect(gfx::Rect(0, -10, 10, 10), SkMatrix::MakeScale(1, -1)));
74 } 88 }
75 89
76 TEST(FilterOperationsTest, MapRectReverseDropShadowReferenceFilter) { 90 TEST(FilterOperationsTest, MapRectReverseDropShadowReferenceFilter) {
77 FilterOperations ops; 91 FilterOperations ops;
78 ops.Append( 92 ops.Append(
79 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make( 93 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make(
80 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), 94 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4),
81 SkIntToScalar(9), SK_ColorBLACK, 95 SkIntToScalar(9), SK_ColorBLACK,
82 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, 96 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
83 nullptr))); 97 nullptr)));
84 EXPECT_EQ(gfx::Rect(-15, -35, 34, 64), 98 EXPECT_EQ(gfx::Rect(-15, -35, 34, 64),
85 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); 99 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
100 EXPECT_EQ(
101 gfx::Rect(-30, -70, 68, 128),
102 ops.MapRectReverse(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
103 EXPECT_EQ(gfx::Rect(-15, -29, 34, 64),
104 ops.MapRectReverse(gfx::Rect(0, -10, 10, 10),
105 SkMatrix::MakeScale(1, -1)));
86 } 106 }
87 107
88 TEST(FilterOperationsTest, MapRectOffsetReferenceFilter) { 108 TEST(FilterOperationsTest, MapRectOffsetReferenceFilter) {
89 sk_sp<SkImageFilter> filter = SkOffsetImageFilter::Make(30, 40, nullptr); 109 sk_sp<SkImageFilter> filter = SkOffsetImageFilter::Make(30, 40, nullptr);
90 FilterOperations ops; 110 FilterOperations ops;
91 ops.Append(FilterOperation::CreateReferenceFilter(std::move(filter))); 111 ops.Append(FilterOperation::CreateReferenceFilter(std::move(filter)));
92 EXPECT_EQ(gfx::Rect(30, 40, 10, 10), 112 EXPECT_EQ(gfx::Rect(30, 40, 10, 10),
93 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); 113 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
114 EXPECT_EQ(gfx::Rect(60, 80, 20, 20),
115 ops.MapRect(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
116 EXPECT_EQ(gfx::Rect(30, -50, 10, 10),
117 ops.MapRect(gfx::Rect(0, -10, 10, 10), SkMatrix::MakeScale(1, -1)));
94 } 118 }
95 119
96 TEST(FilterOperationsTest, MapRectReverseOffsetReferenceFilter) { 120 TEST(FilterOperationsTest, MapRectReverseOffsetReferenceFilter) {
97 sk_sp<SkImageFilter> filter = SkOffsetImageFilter::Make(30, 40, nullptr); 121 sk_sp<SkImageFilter> filter = SkOffsetImageFilter::Make(30, 40, nullptr);
98 FilterOperations ops; 122 FilterOperations ops;
99 ops.Append(FilterOperation::CreateReferenceFilter(std::move(filter))); 123 ops.Append(FilterOperation::CreateReferenceFilter(std::move(filter)));
100 EXPECT_EQ(gfx::Rect(-30, -40, 10, 10), 124 EXPECT_EQ(gfx::Rect(-30, -40, 10, 10),
101 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); 125 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
126 EXPECT_EQ(
127 gfx::Rect(-60, -80, 20, 20),
128 ops.MapRectReverse(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
129 EXPECT_EQ(gfx::Rect(-30, 30, 10, 10),
130 ops.MapRectReverse(gfx::Rect(0, -10, 10, 10),
131 SkMatrix::MakeScale(1, -1)));
102 } 132 }
103 133
104 TEST(FilterOperationsTest, MapRectCombineNonCommutative) { 134 TEST(FilterOperationsTest, MapRectCombineNonCommutative) {
105 // Offsets by 100px in each axis, then scales the resulting image by 2. 135 // Offsets by 100px in each axis, then scales the resulting image by 2.
106 FilterOperations ops; 136 FilterOperations ops;
107 ops.Append(FilterOperation::CreateReferenceFilter( 137 ops.Append(FilterOperation::CreateReferenceFilter(
108 SkOffsetImageFilter::Make(100, 100, nullptr))); 138 SkOffsetImageFilter::Make(100, 100, nullptr)));
109 SkMatrix scaleMatrix; 139 SkMatrix scaleMatrix;
110 scaleMatrix.setScale(2, 2); 140 scaleMatrix.setScale(2, 2);
111 ops.Append( 141 ops.Append(
112 FilterOperation::CreateReferenceFilter(SkImageFilter::MakeMatrixFilter( 142 FilterOperation::CreateReferenceFilter(SkImageFilter::MakeMatrixFilter(
113 scaleMatrix, kNone_SkFilterQuality, nullptr))); 143 scaleMatrix, kNone_SkFilterQuality, nullptr)));
114 144
115 EXPECT_EQ(gfx::Rect(200, 200, 20, 20), 145 EXPECT_EQ(gfx::Rect(200, 200, 20, 20),
116 ops.MapRect(gfx::Rect(10, 10), SkMatrix::I())); 146 ops.MapRect(gfx::Rect(10, 10), SkMatrix::I()));
147 EXPECT_EQ(gfx::Rect(400, 400, 40, 40),
148 ops.MapRect(gfx::Rect(20, 20), SkMatrix::MakeScale(2, 2)));
149 EXPECT_EQ(gfx::Rect(200, -220, 20, 20),
150 ops.MapRect(gfx::Rect(0, -10, 10, 10), SkMatrix::MakeScale(1, -1)));
117 } 151 }
118 152
119 TEST(FilterOperationsTest, MapRectReverseCombineNonCommutative) { 153 TEST(FilterOperationsTest, MapRectReverseCombineNonCommutative) {
120 // Offsets by 100px in each axis, then scales the resulting image by 2. 154 // Offsets by 100px in each axis, then scales the resulting image by 2.
121 FilterOperations ops; 155 FilterOperations ops;
122 ops.Append(FilterOperation::CreateReferenceFilter( 156 ops.Append(FilterOperation::CreateReferenceFilter(
123 SkOffsetImageFilter::Make(100, 100, nullptr))); 157 SkOffsetImageFilter::Make(100, 100, nullptr)));
124 SkMatrix scaleMatrix; 158 SkMatrix scaleMatrix;
125 scaleMatrix.setScale(2, 2); 159 scaleMatrix.setScale(2, 2);
126 ops.Append( 160 ops.Append(
127 FilterOperation::CreateReferenceFilter(SkImageFilter::MakeMatrixFilter( 161 FilterOperation::CreateReferenceFilter(SkImageFilter::MakeMatrixFilter(
128 scaleMatrix, kNone_SkFilterQuality, nullptr))); 162 scaleMatrix, kNone_SkFilterQuality, nullptr)));
129 163
130 EXPECT_EQ(gfx::Rect(10, 10), 164 EXPECT_EQ(gfx::Rect(10, 10),
131 ops.MapRectReverse(gfx::Rect(200, 200, 20, 20), SkMatrix::I())); 165 ops.MapRectReverse(gfx::Rect(200, 200, 20, 20), SkMatrix::I()));
166 EXPECT_EQ(gfx::Rect(20, 20), ops.MapRectReverse(gfx::Rect(400, 400, 40, 40),
167 SkMatrix::MakeScale(2, 2)));
168 EXPECT_EQ(gfx::Rect(0, -10, 10, 10),
169 ops.MapRectReverse(gfx::Rect(200, -220, 20, 20),
170 SkMatrix::MakeScale(1, -1)));
132 } 171 }
133 172
134 TEST(FilterOperationsTest, GetOutsetsNullReferenceFilter) { 173 TEST(FilterOperationsTest, GetOutsetsNullReferenceFilter) {
135 FilterOperations ops; 174 FilterOperations ops;
136 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); 175 ops.Append(FilterOperation::CreateReferenceFilter(nullptr));
137 176
138 int top, right, bottom, left; 177 int top, right, bottom, left;
139 top = right = bottom = left = 0; 178 top = right = bottom = left = 0;
140 ops.GetOutsets(&top, &right, &bottom, &left); 179 ops.GetOutsets(&top, &right, &bottom, &left);
141 EXPECT_EQ(0, top); 180 EXPECT_EQ(0, top);
142 EXPECT_EQ(0, right); 181 EXPECT_EQ(0, right);
143 EXPECT_EQ(0, bottom); 182 EXPECT_EQ(0, bottom);
144 EXPECT_EQ(0, left); 183 EXPECT_EQ(0, left);
145 } 184 }
146 185
147 TEST(FilterOperationsTest, MapRectNullReferenceFilter) { 186 TEST(FilterOperationsTest, MapRectNullReferenceFilter) {
148 FilterOperations ops; 187 FilterOperations ops;
149 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); 188 ops.Append(FilterOperation::CreateReferenceFilter(nullptr));
150 EXPECT_EQ(gfx::Rect(0, 0, 10, 10), 189 EXPECT_EQ(gfx::Rect(0, 0, 10, 10),
151 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); 190 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
191 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
192 ops.MapRect(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
193 EXPECT_EQ(gfx::Rect(0, -10, 10, 10),
194 ops.MapRect(gfx::Rect(0, -10, 10, 10), SkMatrix::MakeScale(1, -1)));
152 } 195 }
153 196
154 TEST(FilterOperationsTest, MapRectReverseNullReferenceFilter) { 197 TEST(FilterOperationsTest, MapRectReverseNullReferenceFilter) {
155 FilterOperations ops; 198 FilterOperations ops;
156 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); 199 ops.Append(FilterOperation::CreateReferenceFilter(nullptr));
157 EXPECT_EQ(gfx::Rect(0, 0, 10, 10), 200 EXPECT_EQ(gfx::Rect(0, 0, 10, 10),
158 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); 201 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
202 EXPECT_EQ(
203 gfx::Rect(0, 0, 20, 20),
204 ops.MapRectReverse(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
205 EXPECT_EQ(gfx::Rect(0, -10, 10, 10),
206 ops.MapRectReverse(gfx::Rect(0, -10, 10, 10),
207 SkMatrix::MakeScale(1, -1)));
159 } 208 }
160 209
161 TEST(FilterOperationsTest, GetOutsetsDropShadow) { 210 TEST(FilterOperationsTest, GetOutsetsDropShadow) {
162 FilterOperations ops; 211 FilterOperations ops;
163 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); 212 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0));
164 int top, right, bottom, left; 213 int top, right, bottom, left;
165 top = right = bottom = left = 0; 214 top = right = bottom = left = 0;
166 ops.GetOutsets(&top, &right, &bottom, &left); 215 ops.GetOutsets(&top, &right, &bottom, &left);
167 EXPECT_EQ(52, top); 216 EXPECT_EQ(52, top);
168 EXPECT_EQ(63, right); 217 EXPECT_EQ(63, right);
169 EXPECT_EQ(68, bottom); 218 EXPECT_EQ(68, bottom);
170 EXPECT_EQ(57, left); 219 EXPECT_EQ(57, left);
171 } 220 }
172 221
173 TEST(FilterOperationsTest, MapRectDropShadow) { 222 TEST(FilterOperationsTest, MapRectDropShadow) {
174 FilterOperations ops; 223 FilterOperations ops;
175 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); 224 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0));
176 EXPECT_EQ(gfx::Rect(-57, -52, 130, 130), 225 EXPECT_EQ(gfx::Rect(-57, -52, 130, 130),
177 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); 226 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
227 EXPECT_EQ(gfx::Rect(-114, -104, 260, 260),
228 ops.MapRect(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
229 EXPECT_EQ(gfx::Rect(-57, -78, 130, 130),
230 ops.MapRect(gfx::Rect(0, -10, 10, 10), SkMatrix::MakeScale(1, -1)));
178 } 231 }
179 232
180 TEST(FilterOperationsTest, MapRectReverseDropShadow) { 233 TEST(FilterOperationsTest, MapRectReverseDropShadow) {
181 FilterOperations ops; 234 FilterOperations ops;
182 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); 235 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0));
183 EXPECT_EQ(gfx::Rect(-63, -68, 130, 130), 236 EXPECT_EQ(gfx::Rect(-63, -68, 130, 130),
184 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); 237 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
238 EXPECT_EQ(
239 gfx::Rect(-126, -136, 260, 260),
240 ops.MapRectReverse(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
241 EXPECT_EQ(gfx::Rect(-63, -62, 130, 130),
242 ops.MapRectReverse(gfx::Rect(0, -10, 10, 10),
243 SkMatrix::MakeScale(1, -1)));
185 } 244 }
186 245
187 TEST(FilterOperationsTest, GetOutsetsDropShadowDoesNotContract) { 246 TEST(FilterOperationsTest, GetOutsetsDropShadowDoesNotContract) {
188 // Even with a drop-shadow, the original content is still drawn. Thus the 247 // Even with a drop-shadow, the original content is still drawn. Thus the
189 // content bounds are never contracted due to a drop-shadow. 248 // content bounds are never contracted due to a drop-shadow.
190 FilterOperations ops; 249 FilterOperations ops;
191 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 0, 0)); 250 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 0, 0));
192 int top, right, bottom, left; 251 int top, right, bottom, left;
193 top = right = bottom = left = 0; 252 top = right = bottom = left = 0;
194 ops.GetOutsets(&top, &right, &bottom, &left); 253 ops.GetOutsets(&top, &right, &bottom, &left);
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 blended = to.Blend(from, -0.75); 933 blended = to.Blend(from, -0.75);
875 EXPECT_EQ(to, blended); 934 EXPECT_EQ(to, blended);
876 blended = to.Blend(from, 0.75); 935 blended = to.Blend(from, 0.75);
877 EXPECT_EQ(to, blended); 936 EXPECT_EQ(to, blended);
878 blended = to.Blend(from, 1.5); 937 blended = to.Blend(from, 1.5);
879 EXPECT_EQ(to, blended); 938 EXPECT_EQ(to, blended);
880 } 939 }
881 940
882 } // namespace 941 } // namespace
883 } // namespace cc 942 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/filter_operation.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698