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.
5 #include "cc/output/filter_operations.h"
6 #include "skia/ext/refptr.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
9 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h"
10 #include "ui/gfx/geometry/point.h"
15 TEST(FilterOperationsTest
, GetOutsetsBlur
) {
17 ops
.Append(FilterOperation::CreateBlurFilter(20));
18 int top
, right
, bottom
, left
;
19 top
= right
= bottom
= left
= 0;
20 ops
.GetOutsets(&top
, &right
, &bottom
, &left
);
23 EXPECT_EQ(57, bottom
);
27 TEST(FilterOperationsTest
, GetOutsetsDropShadowReferenceFilter
) {
28 // TODO(hendrikw): We need to make outsets for reference filters be in line
29 // with non-reference filters. See crbug.com/523534
30 skia::RefPtr
<SkImageFilter
> filter
=
31 skia::AdoptRef(SkDropShadowImageFilter::Create(
32 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4),
33 SkIntToScalar(9), SK_ColorBLACK
,
34 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode
));
36 ops
.Append(FilterOperation::CreateReferenceFilter(filter
));
38 int top
, right
, bottom
, left
;
39 top
= right
= bottom
= left
= 0;
40 ops
.GetOutsets(&top
, &right
, &bottom
, &left
);
43 EXPECT_EQ(19, bottom
);
47 TEST(FilterOperationsTest
, GetOutsetsDropShadow
) {
49 ops
.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0));
50 int top
, right
, bottom
, left
;
51 top
= right
= bottom
= left
= 0;
52 ops
.GetOutsets(&top
, &right
, &bottom
, &left
);
55 EXPECT_EQ(65, bottom
);
59 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \
61 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \
62 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
63 EXPECT_EQ(a, op.amount()); \
65 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
66 op2.set_type(FilterOperation::filter_type); \
68 EXPECT_NE(a, op2.amount()); \
72 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
73 EXPECT_EQ(a, op2.amount()); \
76 #define SAVE_RESTORE_OFFSET_AMOUNT_COLOR(filter_name, filter_type, a, b, c) \
78 FilterOperation op = \
79 FilterOperation::Create##filter_name##Filter(a, b, c); \
80 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
81 EXPECT_EQ(a, op.drop_shadow_offset()); \
82 EXPECT_EQ(b, op.amount()); \
83 EXPECT_EQ(c, op.drop_shadow_color()); \
85 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
86 op2.set_type(FilterOperation::filter_type); \
88 EXPECT_NE(a, op2.drop_shadow_offset()); \
89 EXPECT_NE(b, op2.amount()); \
90 EXPECT_NE(c, op2.drop_shadow_color()); \
92 op2.set_drop_shadow_offset(a); \
94 op2.set_drop_shadow_color(c); \
96 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
97 EXPECT_EQ(a, op2.drop_shadow_offset()); \
98 EXPECT_EQ(b, op2.amount()); \
99 EXPECT_EQ(c, op2.drop_shadow_color()); \
102 #define SAVE_RESTORE_MATRIX(filter_name, filter_type, a) \
104 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \
105 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
106 for (size_t i = 0; i < 20; ++i) \
107 EXPECT_EQ(a[i], op.matrix()[i]); \
109 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
110 op2.set_type(FilterOperation::filter_type); \
112 for (size_t i = 0; i < 20; ++i) \
113 EXPECT_NE(a[i], op2.matrix()[i]); \
117 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
118 for (size_t i = 0; i < 20; ++i) \
119 EXPECT_EQ(a[i], op.matrix()[i]); \
122 #define SAVE_RESTORE_AMOUNT_INSET(filter_name, filter_type, a, b) \
124 FilterOperation op = FilterOperation::Create##filter_name##Filter(a, b); \
125 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
126 EXPECT_EQ(a, op.amount()); \
127 EXPECT_EQ(b, op.zoom_inset()); \
129 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
130 op2.set_type(FilterOperation::filter_type); \
132 EXPECT_NE(a, op2.amount()); \
133 EXPECT_NE(b, op2.zoom_inset()); \
136 op2.set_zoom_inset(b); \
138 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
139 EXPECT_EQ(a, op2.amount()); \
140 EXPECT_EQ(b, op2.zoom_inset()); \
143 TEST(FilterOperationsTest
, SaveAndRestore
) {
144 SAVE_RESTORE_AMOUNT(Grayscale
, GRAYSCALE
, 0.6f
);
145 SAVE_RESTORE_AMOUNT(Sepia
, SEPIA
, 0.6f
);
146 SAVE_RESTORE_AMOUNT(Saturate
, SATURATE
, 0.6f
);
147 SAVE_RESTORE_AMOUNT(HueRotate
, HUE_ROTATE
, 0.6f
);
148 SAVE_RESTORE_AMOUNT(Invert
, INVERT
, 0.6f
);
149 SAVE_RESTORE_AMOUNT(Brightness
, BRIGHTNESS
, 0.6f
);
150 SAVE_RESTORE_AMOUNT(Contrast
, CONTRAST
, 0.6f
);
151 SAVE_RESTORE_AMOUNT(Opacity
, OPACITY
, 0.6f
);
152 SAVE_RESTORE_AMOUNT(Blur
, BLUR
, 0.6f
);
153 SAVE_RESTORE_AMOUNT(SaturatingBrightness
, SATURATING_BRIGHTNESS
, 0.6f
);
154 SAVE_RESTORE_OFFSET_AMOUNT_COLOR(
155 DropShadow
, DROP_SHADOW
, gfx::Point(3, 4), 0.4f
, 0xffffff00);
157 SkScalar matrix
[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
159 SAVE_RESTORE_MATRIX(ColorMatrix
, COLOR_MATRIX
, matrix
);
161 SAVE_RESTORE_AMOUNT_INSET(Zoom
, ZOOM
, 0.5f
, 32);
164 TEST(FilterOperationsTest
, BlendGrayscaleFilters
) {
165 FilterOperation from
= FilterOperation::CreateGrayscaleFilter(0.25f
);
166 FilterOperation to
= FilterOperation::CreateGrayscaleFilter(0.75f
);
168 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
169 FilterOperation expected
= FilterOperation::CreateGrayscaleFilter(0.f
);
170 EXPECT_EQ(expected
, blended
);
172 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
173 expected
= FilterOperation::CreateGrayscaleFilter(0.625f
);
174 EXPECT_EQ(expected
, blended
);
176 blended
= FilterOperation::Blend(&from
, &to
, 1.8);
177 expected
= FilterOperation::CreateGrayscaleFilter(1.f
);
178 EXPECT_EQ(expected
, blended
);
181 TEST(FilterOperationsTest
, BlendGrayscaleWithNull
) {
182 FilterOperation filter
= FilterOperation::CreateGrayscaleFilter(1.f
);
184 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
185 FilterOperation expected
= FilterOperation::CreateGrayscaleFilter(0.75f
);
186 EXPECT_EQ(expected
, blended
);
188 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
189 expected
= FilterOperation::CreateGrayscaleFilter(0.25f
);
190 EXPECT_EQ(expected
, blended
);
193 TEST(FilterOperationsTest
, BlendSepiaFilters
) {
194 FilterOperation from
= FilterOperation::CreateSepiaFilter(0.25f
);
195 FilterOperation to
= FilterOperation::CreateSepiaFilter(0.75f
);
197 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
198 FilterOperation expected
= FilterOperation::CreateSepiaFilter(0.f
);
199 EXPECT_EQ(expected
, blended
);
201 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
202 expected
= FilterOperation::CreateSepiaFilter(0.625f
);
203 EXPECT_EQ(expected
, blended
);
205 blended
= FilterOperation::Blend(&from
, &to
, 1.8);
206 expected
= FilterOperation::CreateSepiaFilter(1.f
);
207 EXPECT_EQ(expected
, blended
);
210 TEST(FilterOperationsTest
, BlendSepiaWithNull
) {
211 FilterOperation filter
= FilterOperation::CreateSepiaFilter(1.f
);
213 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
214 FilterOperation expected
= FilterOperation::CreateSepiaFilter(0.75f
);
215 EXPECT_EQ(expected
, blended
);
217 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
218 expected
= FilterOperation::CreateSepiaFilter(0.25f
);
219 EXPECT_EQ(expected
, blended
);
222 TEST(FilterOperationsTest
, BlendSaturateFilters
) {
223 FilterOperation from
= FilterOperation::CreateSaturateFilter(0.25f
);
224 FilterOperation to
= FilterOperation::CreateSaturateFilter(0.75f
);
226 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
227 FilterOperation expected
= FilterOperation::CreateSaturateFilter(0.f
);
228 EXPECT_EQ(expected
, blended
);
230 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
231 expected
= FilterOperation::CreateSaturateFilter(0.625f
);
232 EXPECT_EQ(expected
, blended
);
234 blended
= FilterOperation::Blend(&from
, &to
, 2.0);
235 expected
= FilterOperation::CreateSaturateFilter(1.25f
);
236 EXPECT_EQ(expected
, blended
);
239 TEST(FilterOperationsTest
, BlendSaturateWithNull
) {
240 FilterOperation filter
= FilterOperation::CreateSaturateFilter(0.f
);
242 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
243 FilterOperation expected
= FilterOperation::CreateSaturateFilter(0.25f
);
244 EXPECT_EQ(expected
, blended
);
246 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
247 expected
= FilterOperation::CreateSaturateFilter(0.75f
);
248 EXPECT_EQ(expected
, blended
);
251 TEST(FilterOperationsTest
, BlendHueRotateFilters
) {
252 FilterOperation from
= FilterOperation::CreateHueRotateFilter(3.f
);
253 FilterOperation to
= FilterOperation::CreateHueRotateFilter(7.f
);
255 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
256 FilterOperation expected
= FilterOperation::CreateHueRotateFilter(0.f
);
257 EXPECT_EQ(expected
, blended
);
259 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
260 expected
= FilterOperation::CreateHueRotateFilter(6.f
);
261 EXPECT_EQ(expected
, blended
);
263 blended
= FilterOperation::Blend(&from
, &to
, 1.5);
264 expected
= FilterOperation::CreateHueRotateFilter(9.f
);
265 EXPECT_EQ(expected
, blended
);
268 TEST(FilterOperationsTest
, BlendHueRotateWithNull
) {
269 FilterOperation filter
= FilterOperation::CreateHueRotateFilter(1.f
);
271 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
272 FilterOperation expected
= FilterOperation::CreateHueRotateFilter(0.75f
);
273 EXPECT_EQ(expected
, blended
);
275 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
276 expected
= FilterOperation::CreateHueRotateFilter(0.25f
);
277 EXPECT_EQ(expected
, blended
);
280 TEST(FilterOperationsTest
, BlendInvertFilters
) {
281 FilterOperation from
= FilterOperation::CreateInvertFilter(0.25f
);
282 FilterOperation to
= FilterOperation::CreateInvertFilter(0.75f
);
284 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
285 FilterOperation expected
= FilterOperation::CreateInvertFilter(0.f
);
286 EXPECT_EQ(expected
, blended
);
288 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
289 expected
= FilterOperation::CreateInvertFilter(0.625f
);
290 EXPECT_EQ(expected
, blended
);
292 blended
= FilterOperation::Blend(&from
, &to
, 1.8);
293 expected
= FilterOperation::CreateInvertFilter(1.f
);
294 EXPECT_EQ(expected
, blended
);
297 TEST(FilterOperationsTest
, BlendInvertWithNull
) {
298 FilterOperation filter
= FilterOperation::CreateInvertFilter(1.f
);
300 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
301 FilterOperation expected
= FilterOperation::CreateInvertFilter(0.75f
);
302 EXPECT_EQ(expected
, blended
);
304 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
305 expected
= FilterOperation::CreateInvertFilter(0.25f
);
306 EXPECT_EQ(expected
, blended
);
309 TEST(FilterOperationsTest
, BlendBrightnessFilters
) {
310 FilterOperation from
= FilterOperation::CreateBrightnessFilter(3.f
);
311 FilterOperation to
= FilterOperation::CreateBrightnessFilter(7.f
);
313 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.9);
314 FilterOperation expected
= FilterOperation::CreateBrightnessFilter(0.f
);
315 EXPECT_EQ(expected
, blended
);
317 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
318 expected
= FilterOperation::CreateBrightnessFilter(6.f
);
319 EXPECT_EQ(expected
, blended
);
321 blended
= FilterOperation::Blend(&from
, &to
, 1.5);
322 expected
= FilterOperation::CreateBrightnessFilter(9.f
);
323 EXPECT_EQ(expected
, blended
);
326 TEST(FilterOperationsTest
, BlendBrightnessWithNull
) {
327 FilterOperation filter
= FilterOperation::CreateBrightnessFilter(0.f
);
329 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
330 FilterOperation expected
= FilterOperation::CreateBrightnessFilter(0.25f
);
331 EXPECT_EQ(expected
, blended
);
333 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
334 expected
= FilterOperation::CreateBrightnessFilter(0.75f
);
335 EXPECT_EQ(expected
, blended
);
338 TEST(FilterOperationsTest
, BlendContrastFilters
) {
339 FilterOperation from
= FilterOperation::CreateContrastFilter(3.f
);
340 FilterOperation to
= FilterOperation::CreateContrastFilter(7.f
);
342 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.9);
343 FilterOperation expected
= FilterOperation::CreateContrastFilter(0.f
);
344 EXPECT_EQ(expected
, blended
);
346 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
347 expected
= FilterOperation::CreateContrastFilter(6.f
);
348 EXPECT_EQ(expected
, blended
);
350 blended
= FilterOperation::Blend(&from
, &to
, 1.5);
351 expected
= FilterOperation::CreateContrastFilter(9.f
);
352 EXPECT_EQ(expected
, blended
);
355 TEST(FilterOperationsTest
, BlendContrastWithNull
) {
356 FilterOperation filter
= FilterOperation::CreateContrastFilter(0.f
);
358 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
359 FilterOperation expected
= FilterOperation::CreateContrastFilter(0.25f
);
360 EXPECT_EQ(expected
, blended
);
362 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
363 expected
= FilterOperation::CreateContrastFilter(0.75f
);
364 EXPECT_EQ(expected
, blended
);
367 TEST(FilterOperationsTest
, BlendOpacityFilters
) {
368 FilterOperation from
= FilterOperation::CreateOpacityFilter(0.25f
);
369 FilterOperation to
= FilterOperation::CreateOpacityFilter(0.75f
);
371 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
372 FilterOperation expected
= FilterOperation::CreateOpacityFilter(0.f
);
373 EXPECT_EQ(expected
, blended
);
375 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
376 expected
= FilterOperation::CreateOpacityFilter(0.625f
);
377 EXPECT_EQ(expected
, blended
);
379 blended
= FilterOperation::Blend(&from
, &to
, 1.8);
380 expected
= FilterOperation::CreateOpacityFilter(1.f
);
381 EXPECT_EQ(expected
, blended
);
384 TEST(FilterOperationsTest
, BlendOpacityWithNull
) {
385 FilterOperation filter
= FilterOperation::CreateOpacityFilter(0.f
);
387 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
388 FilterOperation expected
= FilterOperation::CreateOpacityFilter(0.25f
);
389 EXPECT_EQ(expected
, blended
);
391 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
392 expected
= FilterOperation::CreateOpacityFilter(0.75f
);
393 EXPECT_EQ(expected
, blended
);
396 TEST(FilterOperationsTest
, BlendBlurFilters
) {
397 FilterOperation from
= FilterOperation::CreateBlurFilter(3.f
);
398 FilterOperation to
= FilterOperation::CreateBlurFilter(7.f
);
400 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.9);
401 FilterOperation expected
= FilterOperation::CreateBlurFilter(0.f
);
402 EXPECT_EQ(expected
, blended
);
404 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
405 expected
= FilterOperation::CreateBlurFilter(6.f
);
406 EXPECT_EQ(expected
, blended
);
408 blended
= FilterOperation::Blend(&from
, &to
, 1.5);
409 expected
= FilterOperation::CreateBlurFilter(9.f
);
410 EXPECT_EQ(expected
, blended
);
413 TEST(FilterOperationsTest
, BlendBlurWithNull
) {
414 FilterOperation filter
= FilterOperation::CreateBlurFilter(1.f
);
416 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
417 FilterOperation expected
= FilterOperation::CreateBlurFilter(0.75f
);
418 EXPECT_EQ(expected
, blended
);
420 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
421 expected
= FilterOperation::CreateBlurFilter(0.25f
);
422 EXPECT_EQ(expected
, blended
);
425 TEST(FilterOperationsTest
, BlendDropShadowFilters
) {
426 FilterOperation from
= FilterOperation::CreateDropShadowFilter(
427 gfx::Point(0, 0), 2.f
, SkColorSetARGB(15, 34, 68, 136));
428 FilterOperation to
= FilterOperation::CreateDropShadowFilter(
429 gfx::Point(3, 5), 6.f
, SkColorSetARGB(51, 30, 60, 120));
431 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
432 FilterOperation expected
= FilterOperation::CreateDropShadowFilter(
433 gfx::Point(-2, -4), 0.f
, SkColorSetARGB(0, 0, 0, 0));
434 EXPECT_EQ(expected
, blended
);
436 blended
= FilterOperation::Blend(&from
, &to
, 0.25);
437 expected
= FilterOperation::CreateDropShadowFilter(
438 gfx::Point(1, 1), 3.f
, SkColorSetARGB(24, 32, 64, 128));
439 EXPECT_EQ(expected
, blended
);
441 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
442 expected
= FilterOperation::CreateDropShadowFilter(
443 gfx::Point(2, 4), 5.f
, SkColorSetARGB(42, 30, 61, 121));
444 EXPECT_EQ(expected
, blended
);
446 blended
= FilterOperation::Blend(&from
, &to
, 1.5);
447 expected
= FilterOperation::CreateDropShadowFilter(
448 gfx::Point(5, 8), 8.f
, SkColorSetARGB(69, 30, 59, 118));
449 EXPECT_EQ(expected
, blended
);
452 TEST(FilterOperationsTest
, BlendDropShadowWithNull
) {
453 FilterOperation filter
= FilterOperation::CreateDropShadowFilter(
454 gfx::Point(4, 4), 4.f
, SkColorSetARGB(255, 40, 0, 0));
456 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
457 FilterOperation expected
= FilterOperation::CreateDropShadowFilter(
458 gfx::Point(3, 3), 3.f
, SkColorSetARGB(191, 40, 0, 0));
459 EXPECT_EQ(expected
, blended
);
461 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
462 expected
= FilterOperation::CreateDropShadowFilter(
463 gfx::Point(1, 1), 1.f
, SkColorSetARGB(64, 40, 0, 0));
464 EXPECT_EQ(expected
, blended
);
467 TEST(FilterOperationsTest
, BlendZoomFilters
) {
468 FilterOperation from
= FilterOperation::CreateZoomFilter(2.f
, 3);
469 FilterOperation to
= FilterOperation::CreateZoomFilter(6.f
, 0);
471 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
472 FilterOperation expected
= FilterOperation::CreateZoomFilter(1.f
, 5);
473 EXPECT_EQ(expected
, blended
);
475 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
476 expected
= FilterOperation::CreateZoomFilter(5.f
, 1);
477 EXPECT_EQ(expected
, blended
);
479 blended
= FilterOperation::Blend(&from
, &to
, 1.5);
480 expected
= FilterOperation::CreateZoomFilter(8.f
, 0);
481 EXPECT_EQ(expected
, blended
);
484 TEST(FilterOperationsTest
, BlendZoomWithNull
) {
485 FilterOperation filter
= FilterOperation::CreateZoomFilter(2.f
, 1);
487 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
488 FilterOperation expected
= FilterOperation::CreateZoomFilter(1.75f
, 1);
489 EXPECT_EQ(expected
, blended
);
491 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
492 expected
= FilterOperation::CreateZoomFilter(1.25f
, 0);
493 EXPECT_EQ(expected
, blended
);
496 TEST(FilterOperationsTest
, BlendSaturatingBrightnessFilters
) {
497 FilterOperation from
= FilterOperation::CreateSaturatingBrightnessFilter(3.f
);
498 FilterOperation to
= FilterOperation::CreateSaturatingBrightnessFilter(7.f
);
500 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
501 FilterOperation expected
=
502 FilterOperation::CreateSaturatingBrightnessFilter(0.f
);
503 EXPECT_EQ(expected
, blended
);
505 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
506 expected
= FilterOperation::CreateSaturatingBrightnessFilter(6.f
);
507 EXPECT_EQ(expected
, blended
);
509 blended
= FilterOperation::Blend(&from
, &to
, 1.5);
510 expected
= FilterOperation::CreateSaturatingBrightnessFilter(9.f
);
511 EXPECT_EQ(expected
, blended
);
514 TEST(FilterOperationsTest
, BlendSaturatingBrightnessWithNull
) {
515 FilterOperation filter
=
516 FilterOperation::CreateSaturatingBrightnessFilter(1.f
);
518 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
519 FilterOperation expected
=
520 FilterOperation::CreateSaturatingBrightnessFilter(0.75f
);
521 EXPECT_EQ(expected
, blended
);
523 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
524 expected
= FilterOperation::CreateSaturatingBrightnessFilter(0.25f
);
525 EXPECT_EQ(expected
, blended
);
528 TEST(FilterOperationsTest
, BlendReferenceFilters
) {
529 skia::RefPtr
<SkImageFilter
> from_filter
=
530 skia::AdoptRef(SkBlurImageFilter::Create(1.f
, 1.f
));
531 skia::RefPtr
<SkImageFilter
> to_filter
=
532 skia::AdoptRef(SkBlurImageFilter::Create(2.f
, 2.f
));
533 FilterOperation from
= FilterOperation::CreateReferenceFilter(from_filter
);
534 FilterOperation to
= FilterOperation::CreateReferenceFilter(to_filter
);
536 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
537 EXPECT_EQ(from
, blended
);
539 blended
= FilterOperation::Blend(&from
, &to
, 0.5);
540 EXPECT_EQ(from
, blended
);
542 blended
= FilterOperation::Blend(&from
, &to
, 0.6);
543 EXPECT_EQ(to
, blended
);
545 blended
= FilterOperation::Blend(&from
, &to
, 1.5);
546 EXPECT_EQ(to
, blended
);
549 TEST(FilterOperationsTest
, BlendReferenceWithNull
) {
550 skia::RefPtr
<SkImageFilter
> image_filter
=
551 skia::AdoptRef(SkBlurImageFilter::Create(1.f
, 1.f
));
552 FilterOperation filter
= FilterOperation::CreateReferenceFilter(image_filter
);
553 FilterOperation null_filter
=
554 FilterOperation::CreateReferenceFilter(skia::RefPtr
<SkImageFilter
>());
556 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
557 EXPECT_EQ(filter
, blended
);
558 blended
= FilterOperation::Blend(&filter
, NULL
, 0.75);
559 EXPECT_EQ(null_filter
, blended
);
561 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
562 EXPECT_EQ(null_filter
, blended
);
563 blended
= FilterOperation::Blend(NULL
, &filter
, 0.75);
564 EXPECT_EQ(filter
, blended
);
567 // Tests blending non-empty sequences that have the same length and matching
569 TEST(FilterOperationsTest
, BlendMatchingSequences
) {
570 FilterOperations from
;
573 from
.Append(FilterOperation::CreateBlurFilter(0.f
));
574 to
.Append(FilterOperation::CreateBlurFilter(2.f
));
576 from
.Append(FilterOperation::CreateSaturateFilter(4.f
));
577 to
.Append(FilterOperation::CreateSaturateFilter(0.f
));
579 from
.Append(FilterOperation::CreateZoomFilter(2.0f
, 1));
580 to
.Append(FilterOperation::CreateZoomFilter(10.f
, 9));
582 FilterOperations blended
= to
.Blend(from
, -0.75);
583 FilterOperations expected
;
584 expected
.Append(FilterOperation::CreateBlurFilter(0.f
));
585 expected
.Append(FilterOperation::CreateSaturateFilter(7.f
));
586 expected
.Append(FilterOperation::CreateZoomFilter(1.f
, 0));
587 EXPECT_EQ(blended
, expected
);
589 blended
= to
.Blend(from
, 0.75);
591 expected
.Append(FilterOperation::CreateBlurFilter(1.5f
));
592 expected
.Append(FilterOperation::CreateSaturateFilter(1.f
));
593 expected
.Append(FilterOperation::CreateZoomFilter(8.f
, 7));
594 EXPECT_EQ(blended
, expected
);
596 blended
= to
.Blend(from
, 1.5);
598 expected
.Append(FilterOperation::CreateBlurFilter(3.f
));
599 expected
.Append(FilterOperation::CreateSaturateFilter(0.f
));
600 expected
.Append(FilterOperation::CreateZoomFilter(14.f
, 13));
601 EXPECT_EQ(blended
, expected
);
604 TEST(FilterOperationsTest
, BlendEmptyAndNonEmptySequences
) {
605 FilterOperations empty
;
606 FilterOperations filters
;
608 filters
.Append(FilterOperation::CreateGrayscaleFilter(0.75f
));
609 filters
.Append(FilterOperation::CreateBrightnessFilter(2.f
));
610 filters
.Append(FilterOperation::CreateHueRotateFilter(10.0f
));
612 FilterOperations blended
= empty
.Blend(filters
, -0.75);
613 FilterOperations expected
;
614 expected
.Append(FilterOperation::CreateGrayscaleFilter(1.f
));
615 expected
.Append(FilterOperation::CreateBrightnessFilter(2.75f
));
616 expected
.Append(FilterOperation::CreateHueRotateFilter(17.5f
));
617 EXPECT_EQ(blended
, expected
);
619 blended
= empty
.Blend(filters
, 0.75);
621 expected
.Append(FilterOperation::CreateGrayscaleFilter(0.1875f
));
622 expected
.Append(FilterOperation::CreateBrightnessFilter(1.25f
));
623 expected
.Append(FilterOperation::CreateHueRotateFilter(2.5f
));
624 EXPECT_EQ(blended
, expected
);
626 blended
= empty
.Blend(filters
, 1.5);
628 expected
.Append(FilterOperation::CreateGrayscaleFilter(0.f
));
629 expected
.Append(FilterOperation::CreateBrightnessFilter(0.5f
));
630 expected
.Append(FilterOperation::CreateHueRotateFilter(-5.f
));
631 EXPECT_EQ(blended
, expected
);
633 blended
= filters
.Blend(empty
, -0.75);
635 expected
.Append(FilterOperation::CreateGrayscaleFilter(0.f
));
636 expected
.Append(FilterOperation::CreateBrightnessFilter(0.25f
));
637 expected
.Append(FilterOperation::CreateHueRotateFilter(-7.5f
));
638 EXPECT_EQ(blended
, expected
);
640 blended
= filters
.Blend(empty
, 0.75);
642 expected
.Append(FilterOperation::CreateGrayscaleFilter(0.5625f
));
643 expected
.Append(FilterOperation::CreateBrightnessFilter(1.75f
));
644 expected
.Append(FilterOperation::CreateHueRotateFilter(7.5f
));
645 EXPECT_EQ(blended
, expected
);
647 blended
= filters
.Blend(empty
, 1.5);
649 expected
.Append(FilterOperation::CreateGrayscaleFilter(1.f
));
650 expected
.Append(FilterOperation::CreateBrightnessFilter(2.5f
));
651 expected
.Append(FilterOperation::CreateHueRotateFilter(15.f
));
652 EXPECT_EQ(blended
, expected
);
655 TEST(FilterOperationsTest
, BlendEmptySequences
) {
656 FilterOperations empty
;
658 FilterOperations blended
= empty
.Blend(empty
, -0.75);
659 EXPECT_EQ(blended
, empty
);
661 blended
= empty
.Blend(empty
, 0.75);
662 EXPECT_EQ(blended
, empty
);
664 blended
= empty
.Blend(empty
, 1.5);
665 EXPECT_EQ(blended
, empty
);
668 // Tests blending non-empty sequences that have non-matching operations.
669 TEST(FilterOperationsTest
, BlendNonMatchingSequences
) {
670 FilterOperations from
;
673 from
.Append(FilterOperation::CreateSaturateFilter(3.f
));
674 from
.Append(FilterOperation::CreateBlurFilter(2.f
));
675 to
.Append(FilterOperation::CreateSaturateFilter(4.f
));
676 to
.Append(FilterOperation::CreateHueRotateFilter(0.5f
));
678 FilterOperations blended
= to
.Blend(from
, -0.75);
679 EXPECT_EQ(to
, blended
);
680 blended
= to
.Blend(from
, 0.75);
681 EXPECT_EQ(to
, blended
);
682 blended
= to
.Blend(from
, 1.5);
683 EXPECT_EQ(to
, blended
);
686 // Tests blending non-empty sequences of different sizes.
687 TEST(FilterOperationsTest
, BlendRaggedSequences
) {
688 FilterOperations from
;
691 from
.Append(FilterOperation::CreateSaturateFilter(3.f
));
692 from
.Append(FilterOperation::CreateBlurFilter(2.f
));
693 to
.Append(FilterOperation::CreateSaturateFilter(4.f
));
695 FilterOperations blended
= to
.Blend(from
, -0.75);
696 FilterOperations expected
;
697 expected
.Append(FilterOperation::CreateSaturateFilter(2.25f
));
698 expected
.Append(FilterOperation::CreateBlurFilter(3.5f
));
699 EXPECT_EQ(expected
, blended
);
701 blended
= to
.Blend(from
, 0.75);
703 expected
.Append(FilterOperation::CreateSaturateFilter(3.75f
));
704 expected
.Append(FilterOperation::CreateBlurFilter(0.5f
));
705 EXPECT_EQ(expected
, blended
);
707 blended
= to
.Blend(from
, 1.5);
709 expected
.Append(FilterOperation::CreateSaturateFilter(4.5f
));
710 expected
.Append(FilterOperation::CreateBlurFilter(0.f
));
711 EXPECT_EQ(expected
, blended
);
713 from
.Append(FilterOperation::CreateOpacityFilter(1.f
));
714 to
.Append(FilterOperation::CreateOpacityFilter(1.f
));
715 blended
= to
.Blend(from
, -0.75);
716 EXPECT_EQ(to
, blended
);
717 blended
= to
.Blend(from
, 0.75);
718 EXPECT_EQ(to
, blended
);
719 blended
= to
.Blend(from
, 1.5);
720 EXPECT_EQ(to
, blended
);