[NaCl SDK] Fix mysterious gtest failure in Html5FsTest::OpenForCreate
[chromium-blink-merge.git] / cc / output / filter_operations_unittest.cc
blobd6ae6ab500afc6626b275cea98e9792aaae994a6
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 "ui/gfx/geometry/point.h"
11 namespace cc {
12 namespace {
14 TEST(FilterOperationsTest, GetOutsetsBlur) {
15 FilterOperations ops;
16 ops.Append(FilterOperation::CreateBlurFilter(20));
17 int top, right, bottom, left;
18 top = right = bottom = left = 0;
19 ops.GetOutsets(&top, &right, &bottom, &left);
20 EXPECT_EQ(57, top);
21 EXPECT_EQ(57, right);
22 EXPECT_EQ(57, bottom);
23 EXPECT_EQ(57, left);
26 TEST(FilterOperationsTest, GetOutsetsDropShadow) {
27 FilterOperations ops;
28 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0));
29 int top, right, bottom, left;
30 top = right = bottom = left = 0;
31 ops.GetOutsets(&top, &right, &bottom, &left);
32 EXPECT_EQ(49, top);
33 EXPECT_EQ(60, right);
34 EXPECT_EQ(65, bottom);
35 EXPECT_EQ(54, left);
38 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \
39 { \
40 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \
41 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
42 EXPECT_EQ(a, op.amount()); \
44 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
45 op2.set_type(FilterOperation::filter_type); \
47 EXPECT_NE(a, op2.amount()); \
49 op2.set_amount(a); \
51 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
52 EXPECT_EQ(a, op2.amount()); \
55 #define SAVE_RESTORE_OFFSET_AMOUNT_COLOR(filter_name, filter_type, a, b, c) \
56 { \
57 FilterOperation op = \
58 FilterOperation::Create##filter_name##Filter(a, b, c); \
59 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
60 EXPECT_EQ(a, op.drop_shadow_offset()); \
61 EXPECT_EQ(b, op.amount()); \
62 EXPECT_EQ(c, op.drop_shadow_color()); \
64 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
65 op2.set_type(FilterOperation::filter_type); \
67 EXPECT_NE(a, op2.drop_shadow_offset()); \
68 EXPECT_NE(b, op2.amount()); \
69 EXPECT_NE(c, op2.drop_shadow_color()); \
71 op2.set_drop_shadow_offset(a); \
72 op2.set_amount(b); \
73 op2.set_drop_shadow_color(c); \
75 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
76 EXPECT_EQ(a, op2.drop_shadow_offset()); \
77 EXPECT_EQ(b, op2.amount()); \
78 EXPECT_EQ(c, op2.drop_shadow_color()); \
81 #define SAVE_RESTORE_MATRIX(filter_name, filter_type, a) \
82 { \
83 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \
84 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
85 for (size_t i = 0; i < 20; ++i) \
86 EXPECT_EQ(a[i], op.matrix()[i]); \
88 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
89 op2.set_type(FilterOperation::filter_type); \
91 for (size_t i = 0; i < 20; ++i) \
92 EXPECT_NE(a[i], op2.matrix()[i]); \
94 op2.set_matrix(a); \
96 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
97 for (size_t i = 0; i < 20; ++i) \
98 EXPECT_EQ(a[i], op.matrix()[i]); \
101 #define SAVE_RESTORE_AMOUNT_INSET(filter_name, filter_type, a, b) \
103 FilterOperation op = FilterOperation::Create##filter_name##Filter(a, b); \
104 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
105 EXPECT_EQ(a, op.amount()); \
106 EXPECT_EQ(b, op.zoom_inset()); \
108 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
109 op2.set_type(FilterOperation::filter_type); \
111 EXPECT_NE(a, op2.amount()); \
112 EXPECT_NE(b, op2.zoom_inset()); \
114 op2.set_amount(a); \
115 op2.set_zoom_inset(b); \
117 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
118 EXPECT_EQ(a, op2.amount()); \
119 EXPECT_EQ(b, op2.zoom_inset()); \
122 TEST(FilterOperationsTest, SaveAndRestore) {
123 SAVE_RESTORE_AMOUNT(Grayscale, GRAYSCALE, 0.6f);
124 SAVE_RESTORE_AMOUNT(Sepia, SEPIA, 0.6f);
125 SAVE_RESTORE_AMOUNT(Saturate, SATURATE, 0.6f);
126 SAVE_RESTORE_AMOUNT(HueRotate, HUE_ROTATE, 0.6f);
127 SAVE_RESTORE_AMOUNT(Invert, INVERT, 0.6f);
128 SAVE_RESTORE_AMOUNT(Brightness, BRIGHTNESS, 0.6f);
129 SAVE_RESTORE_AMOUNT(Contrast, CONTRAST, 0.6f);
130 SAVE_RESTORE_AMOUNT(Opacity, OPACITY, 0.6f);
131 SAVE_RESTORE_AMOUNT(Blur, BLUR, 0.6f);
132 SAVE_RESTORE_AMOUNT(SaturatingBrightness, SATURATING_BRIGHTNESS, 0.6f);
133 SAVE_RESTORE_OFFSET_AMOUNT_COLOR(
134 DropShadow, DROP_SHADOW, gfx::Point(3, 4), 0.4f, 0xffffff00);
136 SkScalar matrix[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
137 17, 18, 19, 20};
138 SAVE_RESTORE_MATRIX(ColorMatrix, COLOR_MATRIX, matrix);
140 SAVE_RESTORE_AMOUNT_INSET(Zoom, ZOOM, 0.5f, 32);
143 TEST(FilterOperationsTest, BlendGrayscaleFilters) {
144 FilterOperation from = FilterOperation::CreateGrayscaleFilter(0.25f);
145 FilterOperation to = FilterOperation::CreateGrayscaleFilter(0.75f);
147 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
148 FilterOperation expected = FilterOperation::CreateGrayscaleFilter(0.f);
149 EXPECT_EQ(expected, blended);
151 blended = FilterOperation::Blend(&from, &to, 0.75);
152 expected = FilterOperation::CreateGrayscaleFilter(0.625f);
153 EXPECT_EQ(expected, blended);
155 blended = FilterOperation::Blend(&from, &to, 1.8);
156 expected = FilterOperation::CreateGrayscaleFilter(1.f);
157 EXPECT_EQ(expected, blended);
160 TEST(FilterOperationsTest, BlendGrayscaleWithNull) {
161 FilterOperation filter = FilterOperation::CreateGrayscaleFilter(1.f);
163 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
164 FilterOperation expected = FilterOperation::CreateGrayscaleFilter(0.75f);
165 EXPECT_EQ(expected, blended);
167 blended = FilterOperation::Blend(NULL, &filter, 0.25);
168 expected = FilterOperation::CreateGrayscaleFilter(0.25f);
169 EXPECT_EQ(expected, blended);
172 TEST(FilterOperationsTest, BlendSepiaFilters) {
173 FilterOperation from = FilterOperation::CreateSepiaFilter(0.25f);
174 FilterOperation to = FilterOperation::CreateSepiaFilter(0.75f);
176 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
177 FilterOperation expected = FilterOperation::CreateSepiaFilter(0.f);
178 EXPECT_EQ(expected, blended);
180 blended = FilterOperation::Blend(&from, &to, 0.75);
181 expected = FilterOperation::CreateSepiaFilter(0.625f);
182 EXPECT_EQ(expected, blended);
184 blended = FilterOperation::Blend(&from, &to, 1.8);
185 expected = FilterOperation::CreateSepiaFilter(1.f);
186 EXPECT_EQ(expected, blended);
189 TEST(FilterOperationsTest, BlendSepiaWithNull) {
190 FilterOperation filter = FilterOperation::CreateSepiaFilter(1.f);
192 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
193 FilterOperation expected = FilterOperation::CreateSepiaFilter(0.75f);
194 EXPECT_EQ(expected, blended);
196 blended = FilterOperation::Blend(NULL, &filter, 0.25);
197 expected = FilterOperation::CreateSepiaFilter(0.25f);
198 EXPECT_EQ(expected, blended);
201 TEST(FilterOperationsTest, BlendSaturateFilters) {
202 FilterOperation from = FilterOperation::CreateSaturateFilter(0.25f);
203 FilterOperation to = FilterOperation::CreateSaturateFilter(0.75f);
205 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
206 FilterOperation expected = FilterOperation::CreateSaturateFilter(0.f);
207 EXPECT_EQ(expected, blended);
209 blended = FilterOperation::Blend(&from, &to, 0.75);
210 expected = FilterOperation::CreateSaturateFilter(0.625f);
211 EXPECT_EQ(expected, blended);
213 blended = FilterOperation::Blend(&from, &to, 2.0);
214 expected = FilterOperation::CreateSaturateFilter(1.25f);
215 EXPECT_EQ(expected, blended);
218 TEST(FilterOperationsTest, BlendSaturateWithNull) {
219 FilterOperation filter = FilterOperation::CreateSaturateFilter(0.f);
221 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
222 FilterOperation expected = FilterOperation::CreateSaturateFilter(0.25f);
223 EXPECT_EQ(expected, blended);
225 blended = FilterOperation::Blend(NULL, &filter, 0.25);
226 expected = FilterOperation::CreateSaturateFilter(0.75f);
227 EXPECT_EQ(expected, blended);
230 TEST(FilterOperationsTest, BlendHueRotateFilters) {
231 FilterOperation from = FilterOperation::CreateHueRotateFilter(3.f);
232 FilterOperation to = FilterOperation::CreateHueRotateFilter(7.f);
234 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
235 FilterOperation expected = FilterOperation::CreateHueRotateFilter(0.f);
236 EXPECT_EQ(expected, blended);
238 blended = FilterOperation::Blend(&from, &to, 0.75);
239 expected = FilterOperation::CreateHueRotateFilter(6.f);
240 EXPECT_EQ(expected, blended);
242 blended = FilterOperation::Blend(&from, &to, 1.5);
243 expected = FilterOperation::CreateHueRotateFilter(9.f);
244 EXPECT_EQ(expected, blended);
247 TEST(FilterOperationsTest, BlendHueRotateWithNull) {
248 FilterOperation filter = FilterOperation::CreateHueRotateFilter(1.f);
250 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
251 FilterOperation expected = FilterOperation::CreateHueRotateFilter(0.75f);
252 EXPECT_EQ(expected, blended);
254 blended = FilterOperation::Blend(NULL, &filter, 0.25);
255 expected = FilterOperation::CreateHueRotateFilter(0.25f);
256 EXPECT_EQ(expected, blended);
259 TEST(FilterOperationsTest, BlendInvertFilters) {
260 FilterOperation from = FilterOperation::CreateInvertFilter(0.25f);
261 FilterOperation to = FilterOperation::CreateInvertFilter(0.75f);
263 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
264 FilterOperation expected = FilterOperation::CreateInvertFilter(0.f);
265 EXPECT_EQ(expected, blended);
267 blended = FilterOperation::Blend(&from, &to, 0.75);
268 expected = FilterOperation::CreateInvertFilter(0.625f);
269 EXPECT_EQ(expected, blended);
271 blended = FilterOperation::Blend(&from, &to, 1.8);
272 expected = FilterOperation::CreateInvertFilter(1.f);
273 EXPECT_EQ(expected, blended);
276 TEST(FilterOperationsTest, BlendInvertWithNull) {
277 FilterOperation filter = FilterOperation::CreateInvertFilter(1.f);
279 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
280 FilterOperation expected = FilterOperation::CreateInvertFilter(0.75f);
281 EXPECT_EQ(expected, blended);
283 blended = FilterOperation::Blend(NULL, &filter, 0.25);
284 expected = FilterOperation::CreateInvertFilter(0.25f);
285 EXPECT_EQ(expected, blended);
288 TEST(FilterOperationsTest, BlendBrightnessFilters) {
289 FilterOperation from = FilterOperation::CreateBrightnessFilter(3.f);
290 FilterOperation to = FilterOperation::CreateBrightnessFilter(7.f);
292 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.9);
293 FilterOperation expected = FilterOperation::CreateBrightnessFilter(0.f);
294 EXPECT_EQ(expected, blended);
296 blended = FilterOperation::Blend(&from, &to, 0.75);
297 expected = FilterOperation::CreateBrightnessFilter(6.f);
298 EXPECT_EQ(expected, blended);
300 blended = FilterOperation::Blend(&from, &to, 1.5);
301 expected = FilterOperation::CreateBrightnessFilter(9.f);
302 EXPECT_EQ(expected, blended);
305 TEST(FilterOperationsTest, BlendBrightnessWithNull) {
306 FilterOperation filter = FilterOperation::CreateBrightnessFilter(0.f);
308 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
309 FilterOperation expected = FilterOperation::CreateBrightnessFilter(0.25f);
310 EXPECT_EQ(expected, blended);
312 blended = FilterOperation::Blend(NULL, &filter, 0.25);
313 expected = FilterOperation::CreateBrightnessFilter(0.75f);
314 EXPECT_EQ(expected, blended);
317 TEST(FilterOperationsTest, BlendContrastFilters) {
318 FilterOperation from = FilterOperation::CreateContrastFilter(3.f);
319 FilterOperation to = FilterOperation::CreateContrastFilter(7.f);
321 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.9);
322 FilterOperation expected = FilterOperation::CreateContrastFilter(0.f);
323 EXPECT_EQ(expected, blended);
325 blended = FilterOperation::Blend(&from, &to, 0.75);
326 expected = FilterOperation::CreateContrastFilter(6.f);
327 EXPECT_EQ(expected, blended);
329 blended = FilterOperation::Blend(&from, &to, 1.5);
330 expected = FilterOperation::CreateContrastFilter(9.f);
331 EXPECT_EQ(expected, blended);
334 TEST(FilterOperationsTest, BlendContrastWithNull) {
335 FilterOperation filter = FilterOperation::CreateContrastFilter(0.f);
337 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
338 FilterOperation expected = FilterOperation::CreateContrastFilter(0.25f);
339 EXPECT_EQ(expected, blended);
341 blended = FilterOperation::Blend(NULL, &filter, 0.25);
342 expected = FilterOperation::CreateContrastFilter(0.75f);
343 EXPECT_EQ(expected, blended);
346 TEST(FilterOperationsTest, BlendOpacityFilters) {
347 FilterOperation from = FilterOperation::CreateOpacityFilter(0.25f);
348 FilterOperation to = FilterOperation::CreateOpacityFilter(0.75f);
350 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
351 FilterOperation expected = FilterOperation::CreateOpacityFilter(0.f);
352 EXPECT_EQ(expected, blended);
354 blended = FilterOperation::Blend(&from, &to, 0.75);
355 expected = FilterOperation::CreateOpacityFilter(0.625f);
356 EXPECT_EQ(expected, blended);
358 blended = FilterOperation::Blend(&from, &to, 1.8);
359 expected = FilterOperation::CreateOpacityFilter(1.f);
360 EXPECT_EQ(expected, blended);
363 TEST(FilterOperationsTest, BlendOpacityWithNull) {
364 FilterOperation filter = FilterOperation::CreateOpacityFilter(0.f);
366 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
367 FilterOperation expected = FilterOperation::CreateOpacityFilter(0.25f);
368 EXPECT_EQ(expected, blended);
370 blended = FilterOperation::Blend(NULL, &filter, 0.25);
371 expected = FilterOperation::CreateOpacityFilter(0.75f);
372 EXPECT_EQ(expected, blended);
375 TEST(FilterOperationsTest, BlendBlurFilters) {
376 FilterOperation from = FilterOperation::CreateBlurFilter(3.f);
377 FilterOperation to = FilterOperation::CreateBlurFilter(7.f);
379 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.9);
380 FilterOperation expected = FilterOperation::CreateBlurFilter(0.f);
381 EXPECT_EQ(expected, blended);
383 blended = FilterOperation::Blend(&from, &to, 0.75);
384 expected = FilterOperation::CreateBlurFilter(6.f);
385 EXPECT_EQ(expected, blended);
387 blended = FilterOperation::Blend(&from, &to, 1.5);
388 expected = FilterOperation::CreateBlurFilter(9.f);
389 EXPECT_EQ(expected, blended);
392 TEST(FilterOperationsTest, BlendBlurWithNull) {
393 FilterOperation filter = FilterOperation::CreateBlurFilter(1.f);
395 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
396 FilterOperation expected = FilterOperation::CreateBlurFilter(0.75f);
397 EXPECT_EQ(expected, blended);
399 blended = FilterOperation::Blend(NULL, &filter, 0.25);
400 expected = FilterOperation::CreateBlurFilter(0.25f);
401 EXPECT_EQ(expected, blended);
404 TEST(FilterOperationsTest, BlendDropShadowFilters) {
405 FilterOperation from = FilterOperation::CreateDropShadowFilter(
406 gfx::Point(0, 0), 2.f, SkColorSetARGB(15, 34, 68, 136));
407 FilterOperation to = FilterOperation::CreateDropShadowFilter(
408 gfx::Point(3, 5), 6.f, SkColorSetARGB(51, 30, 60, 120));
410 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
411 FilterOperation expected = FilterOperation::CreateDropShadowFilter(
412 gfx::Point(-2, -4), 0.f, SkColorSetARGB(0, 0, 0, 0));
413 EXPECT_EQ(expected, blended);
415 blended = FilterOperation::Blend(&from, &to, 0.25);
416 expected = FilterOperation::CreateDropShadowFilter(
417 gfx::Point(1, 1), 3.f, SkColorSetARGB(24, 32, 64, 128));
418 EXPECT_EQ(expected, blended);
420 blended = FilterOperation::Blend(&from, &to, 0.75);
421 expected = FilterOperation::CreateDropShadowFilter(
422 gfx::Point(2, 4), 5.f, SkColorSetARGB(42, 30, 61, 121));
423 EXPECT_EQ(expected, blended);
425 blended = FilterOperation::Blend(&from, &to, 1.5);
426 expected = FilterOperation::CreateDropShadowFilter(
427 gfx::Point(5, 8), 8.f, SkColorSetARGB(69, 30, 59, 118));
428 EXPECT_EQ(expected, blended);
431 TEST(FilterOperationsTest, BlendDropShadowWithNull) {
432 FilterOperation filter = FilterOperation::CreateDropShadowFilter(
433 gfx::Point(4, 4), 4.f, SkColorSetARGB(255, 40, 0, 0));
435 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
436 FilterOperation expected = FilterOperation::CreateDropShadowFilter(
437 gfx::Point(3, 3), 3.f, SkColorSetARGB(191, 40, 0, 0));
438 EXPECT_EQ(expected, blended);
440 blended = FilterOperation::Blend(NULL, &filter, 0.25);
441 expected = FilterOperation::CreateDropShadowFilter(
442 gfx::Point(1, 1), 1.f, SkColorSetARGB(64, 40, 0, 0));
443 EXPECT_EQ(expected, blended);
446 TEST(FilterOperationsTest, BlendZoomFilters) {
447 FilterOperation from = FilterOperation::CreateZoomFilter(2.f, 3);
448 FilterOperation to = FilterOperation::CreateZoomFilter(6.f, 0);
450 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
451 FilterOperation expected = FilterOperation::CreateZoomFilter(1.f, 5);
452 EXPECT_EQ(expected, blended);
454 blended = FilterOperation::Blend(&from, &to, 0.75);
455 expected = FilterOperation::CreateZoomFilter(5.f, 1);
456 EXPECT_EQ(expected, blended);
458 blended = FilterOperation::Blend(&from, &to, 1.5);
459 expected = FilterOperation::CreateZoomFilter(8.f, 0);
460 EXPECT_EQ(expected, blended);
463 TEST(FilterOperationsTest, BlendZoomWithNull) {
464 FilterOperation filter = FilterOperation::CreateZoomFilter(2.f, 1);
466 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
467 FilterOperation expected = FilterOperation::CreateZoomFilter(1.75f, 1);
468 EXPECT_EQ(expected, blended);
470 blended = FilterOperation::Blend(NULL, &filter, 0.25);
471 expected = FilterOperation::CreateZoomFilter(1.25f, 0);
472 EXPECT_EQ(expected, blended);
475 TEST(FilterOperationsTest, BlendSaturatingBrightnessFilters) {
476 FilterOperation from = FilterOperation::CreateSaturatingBrightnessFilter(3.f);
477 FilterOperation to = FilterOperation::CreateSaturatingBrightnessFilter(7.f);
479 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
480 FilterOperation expected =
481 FilterOperation::CreateSaturatingBrightnessFilter(0.f);
482 EXPECT_EQ(expected, blended);
484 blended = FilterOperation::Blend(&from, &to, 0.75);
485 expected = FilterOperation::CreateSaturatingBrightnessFilter(6.f);
486 EXPECT_EQ(expected, blended);
488 blended = FilterOperation::Blend(&from, &to, 1.5);
489 expected = FilterOperation::CreateSaturatingBrightnessFilter(9.f);
490 EXPECT_EQ(expected, blended);
493 TEST(FilterOperationsTest, BlendSaturatingBrightnessWithNull) {
494 FilterOperation filter =
495 FilterOperation::CreateSaturatingBrightnessFilter(1.f);
497 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
498 FilterOperation expected =
499 FilterOperation::CreateSaturatingBrightnessFilter(0.75f);
500 EXPECT_EQ(expected, blended);
502 blended = FilterOperation::Blend(NULL, &filter, 0.25);
503 expected = FilterOperation::CreateSaturatingBrightnessFilter(0.25f);
504 EXPECT_EQ(expected, blended);
507 TEST(FilterOperationsTest, BlendReferenceFilters) {
508 skia::RefPtr<SkImageFilter> from_filter =
509 skia::AdoptRef(SkBlurImageFilter::Create(1.f, 1.f));
510 skia::RefPtr<SkImageFilter> to_filter =
511 skia::AdoptRef(SkBlurImageFilter::Create(2.f, 2.f));
512 FilterOperation from = FilterOperation::CreateReferenceFilter(from_filter);
513 FilterOperation to = FilterOperation::CreateReferenceFilter(to_filter);
515 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75);
516 EXPECT_EQ(from, blended);
518 blended = FilterOperation::Blend(&from, &to, 0.5);
519 EXPECT_EQ(from, blended);
521 blended = FilterOperation::Blend(&from, &to, 0.6);
522 EXPECT_EQ(to, blended);
524 blended = FilterOperation::Blend(&from, &to, 1.5);
525 EXPECT_EQ(to, blended);
528 TEST(FilterOperationsTest, BlendReferenceWithNull) {
529 skia::RefPtr<SkImageFilter> image_filter =
530 skia::AdoptRef(SkBlurImageFilter::Create(1.f, 1.f));
531 FilterOperation filter = FilterOperation::CreateReferenceFilter(image_filter);
532 FilterOperation null_filter =
533 FilterOperation::CreateReferenceFilter(skia::RefPtr<SkImageFilter>());
535 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25);
536 EXPECT_EQ(filter, blended);
537 blended = FilterOperation::Blend(&filter, NULL, 0.75);
538 EXPECT_EQ(null_filter, blended);
540 blended = FilterOperation::Blend(NULL, &filter, 0.25);
541 EXPECT_EQ(null_filter, blended);
542 blended = FilterOperation::Blend(NULL, &filter, 0.75);
543 EXPECT_EQ(filter, blended);
546 // Tests blending non-empty sequences that have the same length and matching
547 // operations.
548 TEST(FilterOperationsTest, BlendMatchingSequences) {
549 FilterOperations from;
550 FilterOperations to;
552 from.Append(FilterOperation::CreateBlurFilter(0.f));
553 to.Append(FilterOperation::CreateBlurFilter(2.f));
555 from.Append(FilterOperation::CreateSaturateFilter(4.f));
556 to.Append(FilterOperation::CreateSaturateFilter(0.f));
558 from.Append(FilterOperation::CreateZoomFilter(2.0f, 1));
559 to.Append(FilterOperation::CreateZoomFilter(10.f, 9));
561 FilterOperations blended = to.Blend(from, -0.75);
562 FilterOperations expected;
563 expected.Append(FilterOperation::CreateBlurFilter(0.f));
564 expected.Append(FilterOperation::CreateSaturateFilter(7.f));
565 expected.Append(FilterOperation::CreateZoomFilter(1.f, 0));
566 EXPECT_EQ(blended, expected);
568 blended = to.Blend(from, 0.75);
569 expected.Clear();
570 expected.Append(FilterOperation::CreateBlurFilter(1.5f));
571 expected.Append(FilterOperation::CreateSaturateFilter(1.f));
572 expected.Append(FilterOperation::CreateZoomFilter(8.f, 7));
573 EXPECT_EQ(blended, expected);
575 blended = to.Blend(from, 1.5);
576 expected.Clear();
577 expected.Append(FilterOperation::CreateBlurFilter(3.f));
578 expected.Append(FilterOperation::CreateSaturateFilter(0.f));
579 expected.Append(FilterOperation::CreateZoomFilter(14.f, 13));
580 EXPECT_EQ(blended, expected);
583 TEST(FilterOperationsTest, BlendEmptyAndNonEmptySequences) {
584 FilterOperations empty;
585 FilterOperations filters;
587 filters.Append(FilterOperation::CreateGrayscaleFilter(0.75f));
588 filters.Append(FilterOperation::CreateBrightnessFilter(2.f));
589 filters.Append(FilterOperation::CreateHueRotateFilter(10.0f));
591 FilterOperations blended = empty.Blend(filters, -0.75);
592 FilterOperations expected;
593 expected.Append(FilterOperation::CreateGrayscaleFilter(1.f));
594 expected.Append(FilterOperation::CreateBrightnessFilter(2.75f));
595 expected.Append(FilterOperation::CreateHueRotateFilter(17.5f));
596 EXPECT_EQ(blended, expected);
598 blended = empty.Blend(filters, 0.75);
599 expected.Clear();
600 expected.Append(FilterOperation::CreateGrayscaleFilter(0.1875f));
601 expected.Append(FilterOperation::CreateBrightnessFilter(1.25f));
602 expected.Append(FilterOperation::CreateHueRotateFilter(2.5f));
603 EXPECT_EQ(blended, expected);
605 blended = empty.Blend(filters, 1.5);
606 expected.Clear();
607 expected.Append(FilterOperation::CreateGrayscaleFilter(0.f));
608 expected.Append(FilterOperation::CreateBrightnessFilter(0.5f));
609 expected.Append(FilterOperation::CreateHueRotateFilter(-5.f));
610 EXPECT_EQ(blended, expected);
612 blended = filters.Blend(empty, -0.75);
613 expected.Clear();
614 expected.Append(FilterOperation::CreateGrayscaleFilter(0.f));
615 expected.Append(FilterOperation::CreateBrightnessFilter(0.25f));
616 expected.Append(FilterOperation::CreateHueRotateFilter(-7.5f));
617 EXPECT_EQ(blended, expected);
619 blended = filters.Blend(empty, 0.75);
620 expected.Clear();
621 expected.Append(FilterOperation::CreateGrayscaleFilter(0.5625f));
622 expected.Append(FilterOperation::CreateBrightnessFilter(1.75f));
623 expected.Append(FilterOperation::CreateHueRotateFilter(7.5f));
624 EXPECT_EQ(blended, expected);
626 blended = filters.Blend(empty, 1.5);
627 expected.Clear();
628 expected.Append(FilterOperation::CreateGrayscaleFilter(1.f));
629 expected.Append(FilterOperation::CreateBrightnessFilter(2.5f));
630 expected.Append(FilterOperation::CreateHueRotateFilter(15.f));
631 EXPECT_EQ(blended, expected);
634 TEST(FilterOperationsTest, BlendEmptySequences) {
635 FilterOperations empty;
637 FilterOperations blended = empty.Blend(empty, -0.75);
638 EXPECT_EQ(blended, empty);
640 blended = empty.Blend(empty, 0.75);
641 EXPECT_EQ(blended, empty);
643 blended = empty.Blend(empty, 1.5);
644 EXPECT_EQ(blended, empty);
647 // Tests blending non-empty sequences that have non-matching operations.
648 TEST(FilterOperationsTest, BlendNonMatchingSequences) {
649 FilterOperations from;
650 FilterOperations to;
652 from.Append(FilterOperation::CreateSaturateFilter(3.f));
653 from.Append(FilterOperation::CreateBlurFilter(2.f));
654 to.Append(FilterOperation::CreateSaturateFilter(4.f));
655 to.Append(FilterOperation::CreateHueRotateFilter(0.5f));
657 FilterOperations blended = to.Blend(from, -0.75);
658 EXPECT_EQ(to, blended);
659 blended = to.Blend(from, 0.75);
660 EXPECT_EQ(to, blended);
661 blended = to.Blend(from, 1.5);
662 EXPECT_EQ(to, blended);
665 // Tests blending non-empty sequences of different sizes.
666 TEST(FilterOperationsTest, BlendRaggedSequences) {
667 FilterOperations from;
668 FilterOperations to;
670 from.Append(FilterOperation::CreateSaturateFilter(3.f));
671 from.Append(FilterOperation::CreateBlurFilter(2.f));
672 to.Append(FilterOperation::CreateSaturateFilter(4.f));
674 FilterOperations blended = to.Blend(from, -0.75);
675 FilterOperations expected;
676 expected.Append(FilterOperation::CreateSaturateFilter(2.25f));
677 expected.Append(FilterOperation::CreateBlurFilter(3.5f));
678 EXPECT_EQ(expected, blended);
680 blended = to.Blend(from, 0.75);
681 expected.Clear();
682 expected.Append(FilterOperation::CreateSaturateFilter(3.75f));
683 expected.Append(FilterOperation::CreateBlurFilter(0.5f));
684 EXPECT_EQ(expected, blended);
686 blended = to.Blend(from, 1.5);
687 expected.Clear();
688 expected.Append(FilterOperation::CreateSaturateFilter(4.5f));
689 expected.Append(FilterOperation::CreateBlurFilter(0.f));
690 EXPECT_EQ(expected, blended);
692 from.Append(FilterOperation::CreateOpacityFilter(1.f));
693 to.Append(FilterOperation::CreateOpacityFilter(1.f));
694 blended = to.Blend(from, -0.75);
695 EXPECT_EQ(to, blended);
696 blended = to.Blend(from, 0.75);
697 EXPECT_EQ(to, blended);
698 blended = to.Blend(from, 1.5);
699 EXPECT_EQ(to, blended);
702 } // namespace
703 } // namespace cc