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

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

Issue 2748263002: Move cc::DisplayItemList and related classes into cc/paint/ (Closed)
Patch Set: Merge branch 'master' into ccpaint Created 3 years, 9 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_operations.cc ('k') | cc/output/gl_renderer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <stddef.h>
6
7 #include "cc/output/filter_operations.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
10 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h"
11 #include "third_party/skia/include/effects/SkOffsetImageFilter.h"
12 #include "third_party/skia/include/effects/SkXfermodeImageFilter.h"
13 #include "ui/gfx/geometry/point.h"
14 #include "ui/gfx/geometry/rect.h"
15
16 namespace cc {
17 namespace {
18
19 TEST(FilterOperationsTest, GetOutsetsBlur) {
20 FilterOperations ops;
21 ops.Append(FilterOperation::CreateBlurFilter(20));
22 int top, right, bottom, left;
23 top = right = bottom = left = 0;
24 ops.GetOutsets(&top, &right, &bottom, &left);
25 EXPECT_EQ(60, top);
26 EXPECT_EQ(60, right);
27 EXPECT_EQ(60, bottom);
28 EXPECT_EQ(60, left);
29 }
30
31 TEST(FilterOperationsTest, MapRectBlur) {
32 FilterOperations ops;
33 ops.Append(FilterOperation::CreateBlurFilter(20));
34 EXPECT_EQ(gfx::Rect(-60, -60, 130, 130),
35 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
36 EXPECT_EQ(gfx::Rect(-120, -120, 260, 260),
37 ops.MapRect(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
38 EXPECT_EQ(gfx::Rect(-60, -70, 130, 130),
39 ops.MapRect(gfx::Rect(0, -10, 10, 10), SkMatrix::MakeScale(1, -1)));
40 }
41
42 TEST(FilterOperationsTest, MapRectBlurOverflow) {
43 // Passes if float-cast-overflow does not occur in ubsan builds.
44 // The blur spread exceeds INT_MAX.
45 FilterOperations ops;
46 ops.Append(FilterOperation::CreateBlurFilter(2e9f));
47 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I());
48 }
49
50 TEST(FilterOperationsTest, MapRectReverseBlur) {
51 FilterOperations ops;
52 ops.Append(FilterOperation::CreateBlurFilter(20));
53 EXPECT_EQ(gfx::Rect(-60, -60, 130, 130),
54 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
55 EXPECT_EQ(
56 gfx::Rect(-120, -120, 260, 260),
57 ops.MapRectReverse(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
58 EXPECT_EQ(gfx::Rect(-60, -70, 130, 130),
59 ops.MapRectReverse(gfx::Rect(0, -10, 10, 10),
60 SkMatrix::MakeScale(1, -1)));
61 }
62
63 TEST(FilterOperationsTest, GetOutsetsDropShadowReferenceFilter) {
64 // TODO(hendrikw): We need to make outsets for reference filters be in line
65 // with non-reference filters. See crbug.com/523534
66 FilterOperations ops;
67 ops.Append(
68 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make(
69 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4),
70 SkIntToScalar(9), SK_ColorBLACK,
71 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
72 nullptr)));
73
74 int top, right, bottom, left;
75 top = right = bottom = left = 0;
76 ops.GetOutsets(&top, &right, &bottom, &left);
77 EXPECT_EQ(35, top);
78 EXPECT_EQ(9, right);
79 EXPECT_EQ(19, bottom);
80 EXPECT_EQ(15, left);
81 }
82
83 TEST(FilterOperationsTest, MapRectDropShadowReferenceFilter) {
84 FilterOperations ops;
85 ops.Append(
86 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make(
87 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4),
88 SkIntToScalar(9), SK_ColorBLACK,
89 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
90 nullptr)));
91 EXPECT_EQ(gfx::Rect(-9, -19, 34, 64),
92 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
93 EXPECT_EQ(gfx::Rect(-18, -38, 68, 128),
94 ops.MapRect(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
95 EXPECT_EQ(gfx::Rect(-9, -45, 34, 64),
96 ops.MapRect(gfx::Rect(0, -10, 10, 10), SkMatrix::MakeScale(1, -1)));
97 }
98
99 TEST(FilterOperationsTest, MapRectReverseDropShadowReferenceFilter) {
100 FilterOperations ops;
101 ops.Append(
102 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make(
103 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4),
104 SkIntToScalar(9), SK_ColorBLACK,
105 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
106 nullptr)));
107 EXPECT_EQ(gfx::Rect(-15, -35, 34, 64),
108 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
109 EXPECT_EQ(
110 gfx::Rect(-30, -70, 68, 128),
111 ops.MapRectReverse(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
112 EXPECT_EQ(gfx::Rect(-15, -29, 34, 64),
113 ops.MapRectReverse(gfx::Rect(0, -10, 10, 10),
114 SkMatrix::MakeScale(1, -1)));
115 }
116
117 TEST(FilterOperationsTest, MapRectOffsetReferenceFilter) {
118 sk_sp<SkImageFilter> filter = SkOffsetImageFilter::Make(30, 40, nullptr);
119 FilterOperations ops;
120 ops.Append(FilterOperation::CreateReferenceFilter(std::move(filter)));
121 EXPECT_EQ(gfx::Rect(30, 40, 10, 10),
122 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
123 EXPECT_EQ(gfx::Rect(60, 80, 20, 20),
124 ops.MapRect(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
125 EXPECT_EQ(gfx::Rect(30, -50, 10, 10),
126 ops.MapRect(gfx::Rect(0, -10, 10, 10), SkMatrix::MakeScale(1, -1)));
127 }
128
129 TEST(FilterOperationsTest, MapRectReverseOffsetReferenceFilter) {
130 sk_sp<SkImageFilter> filter = SkOffsetImageFilter::Make(30, 40, nullptr);
131 FilterOperations ops;
132 ops.Append(FilterOperation::CreateReferenceFilter(std::move(filter)));
133 EXPECT_EQ(gfx::Rect(-30, -40, 10, 10),
134 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
135 EXPECT_EQ(
136 gfx::Rect(-60, -80, 20, 20),
137 ops.MapRectReverse(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
138 EXPECT_EQ(gfx::Rect(-30, 30, 10, 10),
139 ops.MapRectReverse(gfx::Rect(0, -10, 10, 10),
140 SkMatrix::MakeScale(1, -1)));
141 }
142
143 TEST(FilterOperationsTest, MapRectCombineNonCommutative) {
144 // Offsets by 100px in each axis, then scales the resulting image by 2.
145 FilterOperations ops;
146 ops.Append(FilterOperation::CreateReferenceFilter(
147 SkOffsetImageFilter::Make(100, 100, nullptr)));
148 SkMatrix scaleMatrix;
149 scaleMatrix.setScale(2, 2);
150 ops.Append(
151 FilterOperation::CreateReferenceFilter(SkImageFilter::MakeMatrixFilter(
152 scaleMatrix, kNone_SkFilterQuality, nullptr)));
153
154 EXPECT_EQ(gfx::Rect(200, 200, 20, 20),
155 ops.MapRect(gfx::Rect(10, 10), SkMatrix::I()));
156 EXPECT_EQ(gfx::Rect(400, 400, 40, 40),
157 ops.MapRect(gfx::Rect(20, 20), SkMatrix::MakeScale(2, 2)));
158 EXPECT_EQ(gfx::Rect(200, -220, 20, 20),
159 ops.MapRect(gfx::Rect(0, -10, 10, 10), SkMatrix::MakeScale(1, -1)));
160 }
161
162 TEST(FilterOperationsTest, MapRectReverseCombineNonCommutative) {
163 // Offsets by 100px in each axis, then scales the resulting image by 2.
164 FilterOperations ops;
165 ops.Append(FilterOperation::CreateReferenceFilter(
166 SkOffsetImageFilter::Make(100, 100, nullptr)));
167 SkMatrix scaleMatrix;
168 scaleMatrix.setScale(2, 2);
169 ops.Append(
170 FilterOperation::CreateReferenceFilter(SkImageFilter::MakeMatrixFilter(
171 scaleMatrix, kNone_SkFilterQuality, nullptr)));
172
173 EXPECT_EQ(gfx::Rect(10, 10),
174 ops.MapRectReverse(gfx::Rect(200, 200, 20, 20), SkMatrix::I()));
175 EXPECT_EQ(gfx::Rect(20, 20), ops.MapRectReverse(gfx::Rect(400, 400, 40, 40),
176 SkMatrix::MakeScale(2, 2)));
177 EXPECT_EQ(gfx::Rect(0, -10, 10, 10),
178 ops.MapRectReverse(gfx::Rect(200, -220, 20, 20),
179 SkMatrix::MakeScale(1, -1)));
180 }
181
182 TEST(FilterOperationsTest, GetOutsetsNullReferenceFilter) {
183 FilterOperations ops;
184 ops.Append(FilterOperation::CreateReferenceFilter(nullptr));
185
186 int top, right, bottom, left;
187 top = right = bottom = left = 0;
188 ops.GetOutsets(&top, &right, &bottom, &left);
189 EXPECT_EQ(0, top);
190 EXPECT_EQ(0, right);
191 EXPECT_EQ(0, bottom);
192 EXPECT_EQ(0, left);
193 }
194
195 TEST(FilterOperationsTest, MapRectNullReferenceFilter) {
196 FilterOperations ops;
197 ops.Append(FilterOperation::CreateReferenceFilter(nullptr));
198 EXPECT_EQ(gfx::Rect(0, 0, 10, 10),
199 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
200 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
201 ops.MapRect(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
202 EXPECT_EQ(gfx::Rect(0, -10, 10, 10),
203 ops.MapRect(gfx::Rect(0, -10, 10, 10), SkMatrix::MakeScale(1, -1)));
204 }
205
206 TEST(FilterOperationsTest, MapRectReverseNullReferenceFilter) {
207 FilterOperations ops;
208 ops.Append(FilterOperation::CreateReferenceFilter(nullptr));
209 EXPECT_EQ(gfx::Rect(0, 0, 10, 10),
210 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
211 EXPECT_EQ(
212 gfx::Rect(0, 0, 20, 20),
213 ops.MapRectReverse(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
214 EXPECT_EQ(gfx::Rect(0, -10, 10, 10),
215 ops.MapRectReverse(gfx::Rect(0, -10, 10, 10),
216 SkMatrix::MakeScale(1, -1)));
217 }
218
219 TEST(FilterOperationsTest, GetOutsetsDropShadow) {
220 FilterOperations ops;
221 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0));
222 int top, right, bottom, left;
223 top = right = bottom = left = 0;
224 ops.GetOutsets(&top, &right, &bottom, &left);
225 EXPECT_EQ(52, top);
226 EXPECT_EQ(63, right);
227 EXPECT_EQ(68, bottom);
228 EXPECT_EQ(57, left);
229 }
230
231 TEST(FilterOperationsTest, MapRectDropShadow) {
232 FilterOperations ops;
233 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0));
234 EXPECT_EQ(gfx::Rect(-57, -52, 130, 130),
235 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
236 EXPECT_EQ(gfx::Rect(-114, -104, 260, 260),
237 ops.MapRect(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
238 EXPECT_EQ(gfx::Rect(-57, -78, 130, 130),
239 ops.MapRect(gfx::Rect(0, -10, 10, 10), SkMatrix::MakeScale(1, -1)));
240 }
241
242 TEST(FilterOperationsTest, MapRectReverseDropShadow) {
243 FilterOperations ops;
244 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0));
245 EXPECT_EQ(gfx::Rect(-63, -68, 130, 130),
246 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
247 EXPECT_EQ(
248 gfx::Rect(-126, -136, 260, 260),
249 ops.MapRectReverse(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2)));
250 EXPECT_EQ(gfx::Rect(-63, -62, 130, 130),
251 ops.MapRectReverse(gfx::Rect(0, -10, 10, 10),
252 SkMatrix::MakeScale(1, -1)));
253 }
254
255 TEST(FilterOperationsTest, GetOutsetsDropShadowDoesNotContract) {
256 // Even with a drop-shadow, the original content is still drawn. Thus the
257 // content bounds are never contracted due to a drop-shadow.
258 FilterOperations ops;
259 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 0, 0));
260 int top, right, bottom, left;
261 top = right = bottom = left = 0;
262 ops.GetOutsets(&top, &right, &bottom, &left);
263 EXPECT_EQ(0, top);
264 EXPECT_EQ(3, right);
265 EXPECT_EQ(8, bottom);
266 EXPECT_EQ(0, left);
267 }
268
269 TEST(FilterOperationsTest, MapRectDropShadowDoesNotContract) {
270 // Even with a drop-shadow, the original content is still drawn. Thus the
271 // content bounds are never contracted due to a drop-shadow.
272 FilterOperations ops;
273 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 0, 0));
274 EXPECT_EQ(gfx::Rect(0, 0, 13, 18),
275 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
276 }
277
278 TEST(FilterOperationsTest, MapRectReverseDropShadowDoesNotContract) {
279 // Even with a drop-shadow, the original content is still drawn. Thus the
280 // content bounds are never contracted due to a drop-shadow.
281 FilterOperations ops;
282 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 0, 0));
283 EXPECT_EQ(gfx::Rect(-3, -8, 13, 18),
284 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I()));
285 }
286
287 TEST(FilterOperationsTest, MapRectTypeConversionDoesNotOverflow) {
288 // Must be bigger than half of the positive range so that the width/height
289 // overflow happens, but small enough that there aren't other issues before
290 // the overflow would happen.
291 SkScalar big_offset =
292 SkFloatToScalar(std::numeric_limits<int>::max()) * 2 / 3;
293
294 FilterOperations ops;
295 ops.Append(FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make(
296 SkBlendMode::kSrcOver,
297 SkOffsetImageFilter::Make(-big_offset, -big_offset, nullptr),
298 SkOffsetImageFilter::Make(big_offset, big_offset, nullptr), nullptr)));
299 gfx::Rect rect = ops.MapRect(gfx::Rect(-10, -10, 20, 20), SkMatrix::I());
300 EXPECT_GT(rect.width(), 0);
301 EXPECT_GT(rect.height(), 0);
302 }
303
304 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \
305 { \
306 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \
307 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
308 EXPECT_EQ(a, op.amount()); \
309 \
310 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
311 op2.set_type(FilterOperation::filter_type); \
312 \
313 EXPECT_NE(a, op2.amount()); \
314 \
315 op2.set_amount(a); \
316 \
317 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
318 EXPECT_EQ(a, op2.amount()); \
319 }
320
321 #define SAVE_RESTORE_OFFSET_AMOUNT_COLOR(filter_name, filter_type, a, b, c) \
322 { \
323 FilterOperation op = \
324 FilterOperation::Create##filter_name##Filter(a, b, c); \
325 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
326 EXPECT_EQ(a, op.drop_shadow_offset()); \
327 EXPECT_EQ(b, op.amount()); \
328 EXPECT_EQ(c, op.drop_shadow_color()); \
329 \
330 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
331 op2.set_type(FilterOperation::filter_type); \
332 \
333 EXPECT_NE(a, op2.drop_shadow_offset()); \
334 EXPECT_NE(b, op2.amount()); \
335 EXPECT_NE(c, op2.drop_shadow_color()); \
336 \
337 op2.set_drop_shadow_offset(a); \
338 op2.set_amount(b); \
339 op2.set_drop_shadow_color(c); \
340 \
341 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
342 EXPECT_EQ(a, op2.drop_shadow_offset()); \
343 EXPECT_EQ(b, op2.amount()); \
344 EXPECT_EQ(c, op2.drop_shadow_color()); \
345 }
346
347 #define SAVE_RESTORE_MATRIX(filter_name, filter_type, a) \
348 { \
349 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \
350 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
351 for (size_t i = 0; i < 20; ++i) \
352 EXPECT_EQ(a[i], op.matrix()[i]); \
353 \
354 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
355 op2.set_type(FilterOperation::filter_type); \
356 \
357 for (size_t i = 0; i < 20; ++i) \
358 EXPECT_NE(a[i], op2.matrix()[i]); \
359 \
360 op2.set_matrix(a); \
361 \
362 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
363 for (size_t i = 0; i < 20; ++i) \
364 EXPECT_EQ(a[i], op.matrix()[i]); \
365 }
366
367 #define SAVE_RESTORE_AMOUNT_INSET(filter_name, filter_type, a, b) \
368 { \
369 FilterOperation op = FilterOperation::Create##filter_name##Filter(a, b); \
370 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
371 EXPECT_EQ(a, op.amount()); \
372 EXPECT_EQ(b, op.zoom_inset()); \
373 \
374 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
375 op2.set_type(FilterOperation::filter_type); \
376 \
377 EXPECT_NE(a, op2.amount()); \
378 EXPECT_NE(b, op2.zoom_inset()); \
379 \
380 op2.set_amount(a); \
381 op2.set_zoom_inset(b); \
382 \
383 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
384 EXPECT_EQ(a, op2.amount()); \
385 EXPECT_EQ(b, op2.zoom_inset()); \
386 }
387
388 TEST(FilterOperationsTest, SaveAndRestore) {
389 SAVE_RESTORE_AMOUNT(Grayscale, GRAYSCALE, 0.6f);
390 SAVE_RESTORE_AMOUNT(Sepia, SEPIA, 0.6f);
391 SAVE_RESTORE_AMOUNT(Saturate, SATURATE, 0.6f);
392 SAVE_RESTORE_AMOUNT(HueRotate, HUE_ROTATE, 0.6f);
393 SAVE_RESTORE_AMOUNT(Invert, INVERT, 0.6f);
394 SAVE_RESTORE_AMOUNT(Brightness, BRIGHTNESS, 0.6f);
395 SAVE_RESTORE_AMOUNT(Contrast, CONTRAST, 0.6f);
396 SAVE_RESTORE_AMOUNT(Opacity, OPACITY, 0.6f);
397 SAVE_RESTORE_AMOUNT(Blur, BLUR, 0.6f);
398 SAVE_RESTORE_AMOUNT(SaturatingBrightness, SATURATING_BRIGHTNESS, 0.6f);
399 SAVE_RESTORE_OFFSET_AMOUNT_COLOR(
400 DropShadow, DROP_SHADOW, gfx::Point(3, 4), 0.4f, 0xffffff00);
401
402 SkScalar matrix[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
403 17, 18, 19, 20};
404 SAVE_RESTORE_MATRIX(ColorMatrix, COLOR_MATRIX, matrix);
405
406 SAVE_RESTORE_AMOUNT_INSET(Zoom, ZOOM, 0.5f, 32);
407 }
408
409 TEST(FilterOperationsTest, BlendGrayscaleFilters) {
410 FilterOperation from = FilterOperation::CreateGrayscaleFilter(0.25f);
411 FilterOperation to = FilterOperation::CreateGrayscaleFilter(0.75f);
412
413 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
414 FilterOperation expected = FilterOperation::CreateGrayscaleFilter(0.f);
415 EXPECT_EQ(expected, blended);
416
417 blended = FilterOperation::Blend(&from, &to, 0.75);
418 expected = FilterOperation::CreateGrayscaleFilter(0.625f);
419 EXPECT_EQ(expected, blended);
420
421 blended = FilterOperation::Blend(&from, &to, 1.8);
422 expected = FilterOperation::CreateGrayscaleFilter(1.f);
423 EXPECT_EQ(expected, blended);
424 }
425
426 TEST(FilterOperationsTest, BlendGrayscaleWithNull) {
427 FilterOperation filter = FilterOperation::CreateGrayscaleFilter(1.f);
428
429 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
430 FilterOperation expected = FilterOperation::CreateGrayscaleFilter(0.75f);
431 EXPECT_EQ(expected, blended);
432
433 blended = FilterOperation::Blend(NULL, &filter, 0.25);
434 expected = FilterOperation::CreateGrayscaleFilter(0.25f);
435 EXPECT_EQ(expected, blended);
436 }
437
438 TEST(FilterOperationsTest, BlendSepiaFilters) {
439 FilterOperation from = FilterOperation::CreateSepiaFilter(0.25f);
440 FilterOperation to = FilterOperation::CreateSepiaFilter(0.75f);
441
442 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
443 FilterOperation expected = FilterOperation::CreateSepiaFilter(0.f);
444 EXPECT_EQ(expected, blended);
445
446 blended = FilterOperation::Blend(&from, &to, 0.75);
447 expected = FilterOperation::CreateSepiaFilter(0.625f);
448 EXPECT_EQ(expected, blended);
449
450 blended = FilterOperation::Blend(&from, &to, 1.8);
451 expected = FilterOperation::CreateSepiaFilter(1.f);
452 EXPECT_EQ(expected, blended);
453 }
454
455 TEST(FilterOperationsTest, BlendSepiaWithNull) {
456 FilterOperation filter = FilterOperation::CreateSepiaFilter(1.f);
457
458 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
459 FilterOperation expected = FilterOperation::CreateSepiaFilter(0.75f);
460 EXPECT_EQ(expected, blended);
461
462 blended = FilterOperation::Blend(NULL, &filter, 0.25);
463 expected = FilterOperation::CreateSepiaFilter(0.25f);
464 EXPECT_EQ(expected, blended);
465 }
466
467 TEST(FilterOperationsTest, BlendSaturateFilters) {
468 FilterOperation from = FilterOperation::CreateSaturateFilter(0.25f);
469 FilterOperation to = FilterOperation::CreateSaturateFilter(0.75f);
470
471 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
472 FilterOperation expected = FilterOperation::CreateSaturateFilter(0.f);
473 EXPECT_EQ(expected, blended);
474
475 blended = FilterOperation::Blend(&from, &to, 0.75);
476 expected = FilterOperation::CreateSaturateFilter(0.625f);
477 EXPECT_EQ(expected, blended);
478
479 blended = FilterOperation::Blend(&from, &to, 2.0);
480 expected = FilterOperation::CreateSaturateFilter(1.25f);
481 EXPECT_EQ(expected, blended);
482 }
483
484 TEST(FilterOperationsTest, BlendSaturateWithNull) {
485 FilterOperation filter = FilterOperation::CreateSaturateFilter(0.f);
486
487 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
488 FilterOperation expected = FilterOperation::CreateSaturateFilter(0.25f);
489 EXPECT_EQ(expected, blended);
490
491 blended = FilterOperation::Blend(NULL, &filter, 0.25);
492 expected = FilterOperation::CreateSaturateFilter(0.75f);
493 EXPECT_EQ(expected, blended);
494 }
495
496 TEST(FilterOperationsTest, BlendHueRotateFilters) {
497 FilterOperation from = FilterOperation::CreateHueRotateFilter(3.f);
498 FilterOperation to = FilterOperation::CreateHueRotateFilter(7.f);
499
500 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
501 FilterOperation expected = FilterOperation::CreateHueRotateFilter(0.f);
502 EXPECT_EQ(expected, blended);
503
504 blended = FilterOperation::Blend(&from, &to, 0.75);
505 expected = FilterOperation::CreateHueRotateFilter(6.f);
506 EXPECT_EQ(expected, blended);
507
508 blended = FilterOperation::Blend(&from, &to, 1.5);
509 expected = FilterOperation::CreateHueRotateFilter(9.f);
510 EXPECT_EQ(expected, blended);
511 }
512
513 TEST(FilterOperationsTest, BlendHueRotateWithNull) {
514 FilterOperation filter = FilterOperation::CreateHueRotateFilter(1.f);
515
516 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
517 FilterOperation expected = FilterOperation::CreateHueRotateFilter(0.75f);
518 EXPECT_EQ(expected, blended);
519
520 blended = FilterOperation::Blend(NULL, &filter, 0.25);
521 expected = FilterOperation::CreateHueRotateFilter(0.25f);
522 EXPECT_EQ(expected, blended);
523 }
524
525 TEST(FilterOperationsTest, BlendInvertFilters) {
526 FilterOperation from = FilterOperation::CreateInvertFilter(0.25f);
527 FilterOperation to = FilterOperation::CreateInvertFilter(0.75f);
528
529 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
530 FilterOperation expected = FilterOperation::CreateInvertFilter(0.f);
531 EXPECT_EQ(expected, blended);
532
533 blended = FilterOperation::Blend(&from, &to, 0.75);
534 expected = FilterOperation::CreateInvertFilter(0.625f);
535 EXPECT_EQ(expected, blended);
536
537 blended = FilterOperation::Blend(&from, &to, 1.8);
538 expected = FilterOperation::CreateInvertFilter(1.f);
539 EXPECT_EQ(expected, blended);
540 }
541
542 TEST(FilterOperationsTest, BlendInvertWithNull) {
543 FilterOperation filter = FilterOperation::CreateInvertFilter(1.f);
544
545 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
546 FilterOperation expected = FilterOperation::CreateInvertFilter(0.75f);
547 EXPECT_EQ(expected, blended);
548
549 blended = FilterOperation::Blend(NULL, &filter, 0.25);
550 expected = FilterOperation::CreateInvertFilter(0.25f);
551 EXPECT_EQ(expected, blended);
552 }
553
554 TEST(FilterOperationsTest, BlendBrightnessFilters) {
555 FilterOperation from = FilterOperation::CreateBrightnessFilter(3.f);
556 FilterOperation to = FilterOperation::CreateBrightnessFilter(7.f);
557
558 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.9);
559 FilterOperation expected = FilterOperation::CreateBrightnessFilter(0.f);
560 EXPECT_EQ(expected, blended);
561
562 blended = FilterOperation::Blend(&from, &to, 0.75);
563 expected = FilterOperation::CreateBrightnessFilter(6.f);
564 EXPECT_EQ(expected, blended);
565
566 blended = FilterOperation::Blend(&from, &to, 1.5);
567 expected = FilterOperation::CreateBrightnessFilter(9.f);
568 EXPECT_EQ(expected, blended);
569 }
570
571 TEST(FilterOperationsTest, BlendBrightnessWithNull) {
572 FilterOperation filter = FilterOperation::CreateBrightnessFilter(0.f);
573
574 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
575 FilterOperation expected = FilterOperation::CreateBrightnessFilter(0.25f);
576 EXPECT_EQ(expected, blended);
577
578 blended = FilterOperation::Blend(NULL, &filter, 0.25);
579 expected = FilterOperation::CreateBrightnessFilter(0.75f);
580 EXPECT_EQ(expected, blended);
581 }
582
583 TEST(FilterOperationsTest, BlendContrastFilters) {
584 FilterOperation from = FilterOperation::CreateContrastFilter(3.f);
585 FilterOperation to = FilterOperation::CreateContrastFilter(7.f);
586
587 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.9);
588 FilterOperation expected = FilterOperation::CreateContrastFilter(0.f);
589 EXPECT_EQ(expected, blended);
590
591 blended = FilterOperation::Blend(&from, &to, 0.75);
592 expected = FilterOperation::CreateContrastFilter(6.f);
593 EXPECT_EQ(expected, blended);
594
595 blended = FilterOperation::Blend(&from, &to, 1.5);
596 expected = FilterOperation::CreateContrastFilter(9.f);
597 EXPECT_EQ(expected, blended);
598 }
599
600 TEST(FilterOperationsTest, BlendContrastWithNull) {
601 FilterOperation filter = FilterOperation::CreateContrastFilter(0.f);
602
603 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
604 FilterOperation expected = FilterOperation::CreateContrastFilter(0.25f);
605 EXPECT_EQ(expected, blended);
606
607 blended = FilterOperation::Blend(NULL, &filter, 0.25);
608 expected = FilterOperation::CreateContrastFilter(0.75f);
609 EXPECT_EQ(expected, blended);
610 }
611
612 TEST(FilterOperationsTest, BlendOpacityFilters) {
613 FilterOperation from = FilterOperation::CreateOpacityFilter(0.25f);
614 FilterOperation to = FilterOperation::CreateOpacityFilter(0.75f);
615
616 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
617 FilterOperation expected = FilterOperation::CreateOpacityFilter(0.f);
618 EXPECT_EQ(expected, blended);
619
620 blended = FilterOperation::Blend(&from, &to, 0.75);
621 expected = FilterOperation::CreateOpacityFilter(0.625f);
622 EXPECT_EQ(expected, blended);
623
624 blended = FilterOperation::Blend(&from, &to, 1.8);
625 expected = FilterOperation::CreateOpacityFilter(1.f);
626 EXPECT_EQ(expected, blended);
627 }
628
629 TEST(FilterOperationsTest, BlendOpacityWithNull) {
630 FilterOperation filter = FilterOperation::CreateOpacityFilter(0.f);
631
632 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
633 FilterOperation expected = FilterOperation::CreateOpacityFilter(0.25f);
634 EXPECT_EQ(expected, blended);
635
636 blended = FilterOperation::Blend(NULL, &filter, 0.25);
637 expected = FilterOperation::CreateOpacityFilter(0.75f);
638 EXPECT_EQ(expected, blended);
639 }
640
641 TEST(FilterOperationsTest, BlendBlurFilters) {
642 FilterOperation from = FilterOperation::CreateBlurFilter(3.f);
643 FilterOperation to = FilterOperation::CreateBlurFilter(7.f);
644
645 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.9);
646 FilterOperation expected = FilterOperation::CreateBlurFilter(0.f);
647 EXPECT_EQ(expected, blended);
648
649 blended = FilterOperation::Blend(&from, &to, 0.75);
650 expected = FilterOperation::CreateBlurFilter(6.f);
651 EXPECT_EQ(expected, blended);
652
653 blended = FilterOperation::Blend(&from, &to, 1.5);
654 expected = FilterOperation::CreateBlurFilter(9.f);
655 EXPECT_EQ(expected, blended);
656 }
657
658 TEST(FilterOperationsTest, BlendBlurWithNull) {
659 FilterOperation filter = FilterOperation::CreateBlurFilter(1.f);
660
661 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
662 FilterOperation expected = FilterOperation::CreateBlurFilter(0.75f);
663 EXPECT_EQ(expected, blended);
664
665 blended = FilterOperation::Blend(NULL, &filter, 0.25);
666 expected = FilterOperation::CreateBlurFilter(0.25f);
667 EXPECT_EQ(expected, blended);
668 }
669
670 TEST(FilterOperationsTest, BlendDropShadowFilters) {
671 FilterOperation from = FilterOperation::CreateDropShadowFilter(
672 gfx::Point(0, 0), 2.f, SkColorSetARGB(15, 34, 68, 136));
673 FilterOperation to = FilterOperation::CreateDropShadowFilter(
674 gfx::Point(3, 5), 6.f, SkColorSetARGB(51, 30, 60, 120));
675
676 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
677 FilterOperation expected = FilterOperation::CreateDropShadowFilter(
678 gfx::Point(-2, -4), 0.f, SkColorSetARGB(0, 0, 0, 0));
679 EXPECT_EQ(expected, blended);
680
681 blended = FilterOperation::Blend(&from, &to, 0.25);
682 expected = FilterOperation::CreateDropShadowFilter(
683 gfx::Point(1, 1), 3.f, SkColorSetARGB(24, 32, 64, 128));
684 EXPECT_EQ(expected, blended);
685
686 blended = FilterOperation::Blend(&from, &to, 0.75);
687 expected = FilterOperation::CreateDropShadowFilter(
688 gfx::Point(2, 4), 5.f, SkColorSetARGB(42, 30, 61, 121));
689 EXPECT_EQ(expected, blended);
690
691 blended = FilterOperation::Blend(&from, &to, 1.5);
692 expected = FilterOperation::CreateDropShadowFilter(
693 gfx::Point(5, 8), 8.f, SkColorSetARGB(69, 30, 59, 118));
694 EXPECT_EQ(expected, blended);
695 }
696
697 TEST(FilterOperationsTest, BlendDropShadowWithNull) {
698 FilterOperation filter = FilterOperation::CreateDropShadowFilter(
699 gfx::Point(4, 4), 4.f, SkColorSetARGB(255, 40, 0, 0));
700
701 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
702 FilterOperation expected = FilterOperation::CreateDropShadowFilter(
703 gfx::Point(3, 3), 3.f, SkColorSetARGB(191, 40, 0, 0));
704 EXPECT_EQ(expected, blended);
705
706 blended = FilterOperation::Blend(NULL, &filter, 0.25);
707 expected = FilterOperation::CreateDropShadowFilter(
708 gfx::Point(1, 1), 1.f, SkColorSetARGB(64, 40, 0, 0));
709 EXPECT_EQ(expected, blended);
710 }
711
712 TEST(FilterOperationsTest, BlendZoomFilters) {
713 FilterOperation from = FilterOperation::CreateZoomFilter(2.f, 3);
714 FilterOperation to = FilterOperation::CreateZoomFilter(6.f, 0);
715
716 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
717 FilterOperation expected = FilterOperation::CreateZoomFilter(1.f, 5);
718 EXPECT_EQ(expected, blended);
719
720 blended = FilterOperation::Blend(&from, &to, 0.75);
721 expected = FilterOperation::CreateZoomFilter(5.f, 1);
722 EXPECT_EQ(expected, blended);
723
724 blended = FilterOperation::Blend(&from, &to, 1.5);
725 expected = FilterOperation::CreateZoomFilter(8.f, 0);
726 EXPECT_EQ(expected, blended);
727 }
728
729 TEST(FilterOperationsTest, BlendZoomWithNull) {
730 FilterOperation filter = FilterOperation::CreateZoomFilter(2.f, 1);
731
732 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
733 FilterOperation expected = FilterOperation::CreateZoomFilter(1.75f, 1);
734 EXPECT_EQ(expected, blended);
735
736 blended = FilterOperation::Blend(NULL, &filter, 0.25);
737 expected = FilterOperation::CreateZoomFilter(1.25f, 0);
738 EXPECT_EQ(expected, blended);
739 }
740
741 TEST(FilterOperationsTest, BlendSaturatingBrightnessFilters) {
742 FilterOperation from = FilterOperation::CreateSaturatingBrightnessFilter(3.f);
743 FilterOperation to = FilterOperation::CreateSaturatingBrightnessFilter(7.f);
744
745 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
746 FilterOperation expected =
747 FilterOperation::CreateSaturatingBrightnessFilter(0.f);
748 EXPECT_EQ(expected, blended);
749
750 blended = FilterOperation::Blend(&from, &to, 0.75);
751 expected = FilterOperation::CreateSaturatingBrightnessFilter(6.f);
752 EXPECT_EQ(expected, blended);
753
754 blended = FilterOperation::Blend(&from, &to, 1.5);
755 expected = FilterOperation::CreateSaturatingBrightnessFilter(9.f);
756 EXPECT_EQ(expected, blended);
757 }
758
759 TEST(FilterOperationsTest, BlendSaturatingBrightnessWithNull) {
760 FilterOperation filter =
761 FilterOperation::CreateSaturatingBrightnessFilter(1.f);
762
763 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
764 FilterOperation expected =
765 FilterOperation::CreateSaturatingBrightnessFilter(0.75f);
766 EXPECT_EQ(expected, blended);
767
768 blended = FilterOperation::Blend(NULL, &filter, 0.25);
769 expected = FilterOperation::CreateSaturatingBrightnessFilter(0.25f);
770 EXPECT_EQ(expected, blended);
771 }
772
773 TEST(FilterOperationsTest, BlendReferenceFilters) {
774 sk_sp<SkImageFilter> from_filter(SkBlurImageFilter::Make(1.f, 1.f, nullptr));
775 sk_sp<SkImageFilter> to_filter(SkBlurImageFilter::Make(2.f, 2.f, nullptr));
776 FilterOperation from =
777 FilterOperation::CreateReferenceFilter(std::move(from_filter));
778 FilterOperation to =
779 FilterOperation::CreateReferenceFilter(std::move(to_filter));
780
781 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
782 EXPECT_EQ(from, blended);
783
784 blended = FilterOperation::Blend(&from, &to, 0.5);
785 EXPECT_EQ(from, blended);
786
787 blended = FilterOperation::Blend(&from, &to, 0.6);
788 EXPECT_EQ(to, blended);
789
790 blended = FilterOperation::Blend(&from, &to, 1.5);
791 EXPECT_EQ(to, blended);
792 }
793
794 TEST(FilterOperationsTest, BlendReferenceWithNull) {
795 sk_sp<SkImageFilter> image_filter(SkBlurImageFilter::Make(1.f, 1.f, nullptr));
796 FilterOperation filter =
797 FilterOperation::CreateReferenceFilter(std::move(image_filter));
798 FilterOperation null_filter = FilterOperation::CreateReferenceFilter(nullptr);
799
800 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
801 EXPECT_EQ(filter, blended);
802 blended = FilterOperation::Blend(&filter, NULL, 0.75);
803 EXPECT_EQ(null_filter, blended);
804
805 blended = FilterOperation::Blend(NULL, &filter, 0.25);
806 EXPECT_EQ(null_filter, blended);
807 blended = FilterOperation::Blend(NULL, &filter, 0.75);
808 EXPECT_EQ(filter, blended);
809 }
810
811 // Tests blending non-empty sequences that have the same length and matching
812 // operations.
813 TEST(FilterOperationsTest, BlendMatchingSequences) {
814 FilterOperations from;
815 FilterOperations to;
816
817 from.Append(FilterOperation::CreateBlurFilter(0.f));
818 to.Append(FilterOperation::CreateBlurFilter(2.f));
819
820 from.Append(FilterOperation::CreateSaturateFilter(4.f));
821 to.Append(FilterOperation::CreateSaturateFilter(0.f));
822
823 from.Append(FilterOperation::CreateZoomFilter(2.0f, 1));
824 to.Append(FilterOperation::CreateZoomFilter(10.f, 9));
825
826 FilterOperations blended = to.Blend(from, -0.75);
827 FilterOperations expected;
828 expected.Append(FilterOperation::CreateBlurFilter(0.f));
829 expected.Append(FilterOperation::CreateSaturateFilter(7.f));
830 expected.Append(FilterOperation::CreateZoomFilter(1.f, 0));
831 EXPECT_EQ(blended, expected);
832
833 blended = to.Blend(from, 0.75);
834 expected.Clear();
835 expected.Append(FilterOperation::CreateBlurFilter(1.5f));
836 expected.Append(FilterOperation::CreateSaturateFilter(1.f));
837 expected.Append(FilterOperation::CreateZoomFilter(8.f, 7));
838 EXPECT_EQ(blended, expected);
839
840 blended = to.Blend(from, 1.5);
841 expected.Clear();
842 expected.Append(FilterOperation::CreateBlurFilter(3.f));
843 expected.Append(FilterOperation::CreateSaturateFilter(0.f));
844 expected.Append(FilterOperation::CreateZoomFilter(14.f, 13));
845 EXPECT_EQ(blended, expected);
846 }
847
848 TEST(FilterOperationsTest, BlendEmptyAndNonEmptySequences) {
849 FilterOperations empty;
850 FilterOperations filters;
851
852 filters.Append(FilterOperation::CreateGrayscaleFilter(0.75f));
853 filters.Append(FilterOperation::CreateBrightnessFilter(2.f));
854 filters.Append(FilterOperation::CreateHueRotateFilter(10.0f));
855
856 FilterOperations blended = empty.Blend(filters, -0.75);
857 FilterOperations expected;
858 expected.Append(FilterOperation::CreateGrayscaleFilter(1.f));
859 expected.Append(FilterOperation::CreateBrightnessFilter(2.75f));
860 expected.Append(FilterOperation::CreateHueRotateFilter(17.5f));
861 EXPECT_EQ(blended, expected);
862
863 blended = empty.Blend(filters, 0.75);
864 expected.Clear();
865 expected.Append(FilterOperation::CreateGrayscaleFilter(0.1875f));
866 expected.Append(FilterOperation::CreateBrightnessFilter(1.25f));
867 expected.Append(FilterOperation::CreateHueRotateFilter(2.5f));
868 EXPECT_EQ(blended, expected);
869
870 blended = empty.Blend(filters, 1.5);
871 expected.Clear();
872 expected.Append(FilterOperation::CreateGrayscaleFilter(0.f));
873 expected.Append(FilterOperation::CreateBrightnessFilter(0.5f));
874 expected.Append(FilterOperation::CreateHueRotateFilter(-5.f));
875 EXPECT_EQ(blended, expected);
876
877 blended = filters.Blend(empty, -0.75);
878 expected.Clear();
879 expected.Append(FilterOperation::CreateGrayscaleFilter(0.f));
880 expected.Append(FilterOperation::CreateBrightnessFilter(0.25f));
881 expected.Append(FilterOperation::CreateHueRotateFilter(-7.5f));
882 EXPECT_EQ(blended, expected);
883
884 blended = filters.Blend(empty, 0.75);
885 expected.Clear();
886 expected.Append(FilterOperation::CreateGrayscaleFilter(0.5625f));
887 expected.Append(FilterOperation::CreateBrightnessFilter(1.75f));
888 expected.Append(FilterOperation::CreateHueRotateFilter(7.5f));
889 EXPECT_EQ(blended, expected);
890
891 blended = filters.Blend(empty, 1.5);
892 expected.Clear();
893 expected.Append(FilterOperation::CreateGrayscaleFilter(1.f));
894 expected.Append(FilterOperation::CreateBrightnessFilter(2.5f));
895 expected.Append(FilterOperation::CreateHueRotateFilter(15.f));
896 EXPECT_EQ(blended, expected);
897 }
898
899 TEST(FilterOperationsTest, BlendEmptySequences) {
900 FilterOperations empty;
901
902 FilterOperations blended = empty.Blend(empty, -0.75);
903 EXPECT_EQ(blended, empty);
904
905 blended = empty.Blend(empty, 0.75);
906 EXPECT_EQ(blended, empty);
907
908 blended = empty.Blend(empty, 1.5);
909 EXPECT_EQ(blended, empty);
910 }
911
912 // Tests blending non-empty sequences that have non-matching operations.
913 TEST(FilterOperationsTest, BlendNonMatchingSequences) {
914 FilterOperations from;
915 FilterOperations to;
916
917 from.Append(FilterOperation::CreateSaturateFilter(3.f));
918 from.Append(FilterOperation::CreateBlurFilter(2.f));
919 to.Append(FilterOperation::CreateSaturateFilter(4.f));
920 to.Append(FilterOperation::CreateHueRotateFilter(0.5f));
921
922 FilterOperations blended = to.Blend(from, -0.75);
923 EXPECT_EQ(to, blended);
924 blended = to.Blend(from, 0.75);
925 EXPECT_EQ(to, blended);
926 blended = to.Blend(from, 1.5);
927 EXPECT_EQ(to, blended);
928 }
929
930 // Tests blending non-empty sequences of different sizes.
931 TEST(FilterOperationsTest, BlendRaggedSequences) {
932 FilterOperations from;
933 FilterOperations to;
934
935 from.Append(FilterOperation::CreateSaturateFilter(3.f));
936 from.Append(FilterOperation::CreateBlurFilter(2.f));
937 to.Append(FilterOperation::CreateSaturateFilter(4.f));
938
939 FilterOperations blended = to.Blend(from, -0.75);
940 FilterOperations expected;
941 expected.Append(FilterOperation::CreateSaturateFilter(2.25f));
942 expected.Append(FilterOperation::CreateBlurFilter(3.5f));
943 EXPECT_EQ(expected, blended);
944
945 blended = to.Blend(from, 0.75);
946 expected.Clear();
947 expected.Append(FilterOperation::CreateSaturateFilter(3.75f));
948 expected.Append(FilterOperation::CreateBlurFilter(0.5f));
949 EXPECT_EQ(expected, blended);
950
951 blended = to.Blend(from, 1.5);
952 expected.Clear();
953 expected.Append(FilterOperation::CreateSaturateFilter(4.5f));
954 expected.Append(FilterOperation::CreateBlurFilter(0.f));
955 EXPECT_EQ(expected, blended);
956
957 from.Append(FilterOperation::CreateOpacityFilter(1.f));
958 to.Append(FilterOperation::CreateOpacityFilter(1.f));
959 blended = to.Blend(from, -0.75);
960 EXPECT_EQ(to, blended);
961 blended = to.Blend(from, 0.75);
962 EXPECT_EQ(to, blended);
963 blended = to.Blend(from, 1.5);
964 EXPECT_EQ(to, blended);
965 }
966
967 TEST(FilterOperationsTest, ToString) {
968 FilterOperations filters;
969 EXPECT_EQ(std::string("{\"FilterOperations\":[]}"), filters.ToString());
970
971 filters.Append(FilterOperation::CreateSaturateFilter(3.f));
972 filters.Append(FilterOperation::CreateBlurFilter(2.f));
973 EXPECT_EQ(std::string("{\"FilterOperations\":[{\"amount\":3.0,\"type\":2},"
974 "{\"amount\":2.0,\"type\":8}]}"),
975 filters.ToString());
976 }
977
978 } // namespace
979 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/filter_operations.cc ('k') | cc/output/gl_renderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698