OLD | NEW |
| (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 "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" | |
10 | |
11 namespace cc { | |
12 namespace { | |
13 | |
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); | |
24 } | |
25 | |
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); | |
36 } | |
37 | |
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()); \ | |
43 \ | |
44 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \ | |
45 op2.set_type(FilterOperation::filter_type); \ | |
46 \ | |
47 EXPECT_NE(a, op2.amount()); \ | |
48 \ | |
49 op2.set_amount(a); \ | |
50 \ | |
51 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \ | |
52 EXPECT_EQ(a, op2.amount()); \ | |
53 } | |
54 | |
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()); \ | |
63 \ | |
64 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \ | |
65 op2.set_type(FilterOperation::filter_type); \ | |
66 \ | |
67 EXPECT_NE(a, op2.drop_shadow_offset()); \ | |
68 EXPECT_NE(b, op2.amount()); \ | |
69 EXPECT_NE(c, op2.drop_shadow_color()); \ | |
70 \ | |
71 op2.set_drop_shadow_offset(a); \ | |
72 op2.set_amount(b); \ | |
73 op2.set_drop_shadow_color(c); \ | |
74 \ | |
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()); \ | |
79 } | |
80 | |
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]); \ | |
87 \ | |
88 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \ | |
89 op2.set_type(FilterOperation::filter_type); \ | |
90 \ | |
91 for (size_t i = 0; i < 20; ++i) \ | |
92 EXPECT_NE(a[i], op2.matrix()[i]); \ | |
93 \ | |
94 op2.set_matrix(a); \ | |
95 \ | |
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]); \ | |
99 } | |
100 | |
101 #define SAVE_RESTORE_AMOUNT_INSET(filter_name, filter_type, a, b) \ | |
102 { \ | |
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()); \ | |
107 \ | |
108 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \ | |
109 op2.set_type(FilterOperation::filter_type); \ | |
110 \ | |
111 EXPECT_NE(a, op2.amount()); \ | |
112 EXPECT_NE(b, op2.zoom_inset()); \ | |
113 \ | |
114 op2.set_amount(a); \ | |
115 op2.set_zoom_inset(b); \ | |
116 \ | |
117 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \ | |
118 EXPECT_EQ(a, op2.amount()); \ | |
119 EXPECT_EQ(b, op2.zoom_inset()); \ | |
120 } | |
121 | |
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); | |
135 | |
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); | |
139 | |
140 SAVE_RESTORE_AMOUNT_INSET(Zoom, ZOOM, 0.5f, 32); | |
141 } | |
142 | |
143 TEST(FilterOperationsTest, BlendGrayscaleFilters) { | |
144 FilterOperation from = FilterOperation::CreateGrayscaleFilter(0.25f); | |
145 FilterOperation to = FilterOperation::CreateGrayscaleFilter(0.75f); | |
146 | |
147 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75); | |
148 FilterOperation expected = FilterOperation::CreateGrayscaleFilter(0.f); | |
149 EXPECT_EQ(expected, blended); | |
150 | |
151 blended = FilterOperation::Blend(&from, &to, 0.75); | |
152 expected = FilterOperation::CreateGrayscaleFilter(0.625f); | |
153 EXPECT_EQ(expected, blended); | |
154 | |
155 blended = FilterOperation::Blend(&from, &to, 1.8); | |
156 expected = FilterOperation::CreateGrayscaleFilter(1.f); | |
157 EXPECT_EQ(expected, blended); | |
158 } | |
159 | |
160 TEST(FilterOperationsTest, BlendGrayscaleWithNull) { | |
161 FilterOperation filter = FilterOperation::CreateGrayscaleFilter(1.f); | |
162 | |
163 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25); | |
164 FilterOperation expected = FilterOperation::CreateGrayscaleFilter(0.75f); | |
165 EXPECT_EQ(expected, blended); | |
166 | |
167 blended = FilterOperation::Blend(NULL, &filter, 0.25); | |
168 expected = FilterOperation::CreateGrayscaleFilter(0.25f); | |
169 EXPECT_EQ(expected, blended); | |
170 } | |
171 | |
172 TEST(FilterOperationsTest, BlendSepiaFilters) { | |
173 FilterOperation from = FilterOperation::CreateSepiaFilter(0.25f); | |
174 FilterOperation to = FilterOperation::CreateSepiaFilter(0.75f); | |
175 | |
176 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75); | |
177 FilterOperation expected = FilterOperation::CreateSepiaFilter(0.f); | |
178 EXPECT_EQ(expected, blended); | |
179 | |
180 blended = FilterOperation::Blend(&from, &to, 0.75); | |
181 expected = FilterOperation::CreateSepiaFilter(0.625f); | |
182 EXPECT_EQ(expected, blended); | |
183 | |
184 blended = FilterOperation::Blend(&from, &to, 1.8); | |
185 expected = FilterOperation::CreateSepiaFilter(1.f); | |
186 EXPECT_EQ(expected, blended); | |
187 } | |
188 | |
189 TEST(FilterOperationsTest, BlendSepiaWithNull) { | |
190 FilterOperation filter = FilterOperation::CreateSepiaFilter(1.f); | |
191 | |
192 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25); | |
193 FilterOperation expected = FilterOperation::CreateSepiaFilter(0.75f); | |
194 EXPECT_EQ(expected, blended); | |
195 | |
196 blended = FilterOperation::Blend(NULL, &filter, 0.25); | |
197 expected = FilterOperation::CreateSepiaFilter(0.25f); | |
198 EXPECT_EQ(expected, blended); | |
199 } | |
200 | |
201 TEST(FilterOperationsTest, BlendSaturateFilters) { | |
202 FilterOperation from = FilterOperation::CreateSaturateFilter(0.25f); | |
203 FilterOperation to = FilterOperation::CreateSaturateFilter(0.75f); | |
204 | |
205 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75); | |
206 FilterOperation expected = FilterOperation::CreateSaturateFilter(0.f); | |
207 EXPECT_EQ(expected, blended); | |
208 | |
209 blended = FilterOperation::Blend(&from, &to, 0.75); | |
210 expected = FilterOperation::CreateSaturateFilter(0.625f); | |
211 EXPECT_EQ(expected, blended); | |
212 | |
213 blended = FilterOperation::Blend(&from, &to, 2.0); | |
214 expected = FilterOperation::CreateSaturateFilter(1.25f); | |
215 EXPECT_EQ(expected, blended); | |
216 } | |
217 | |
218 TEST(FilterOperationsTest, BlendSaturateWithNull) { | |
219 FilterOperation filter = FilterOperation::CreateSaturateFilter(0.f); | |
220 | |
221 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25); | |
222 FilterOperation expected = FilterOperation::CreateSaturateFilter(0.25f); | |
223 EXPECT_EQ(expected, blended); | |
224 | |
225 blended = FilterOperation::Blend(NULL, &filter, 0.25); | |
226 expected = FilterOperation::CreateSaturateFilter(0.75f); | |
227 EXPECT_EQ(expected, blended); | |
228 } | |
229 | |
230 TEST(FilterOperationsTest, BlendHueRotateFilters) { | |
231 FilterOperation from = FilterOperation::CreateHueRotateFilter(3.f); | |
232 FilterOperation to = FilterOperation::CreateHueRotateFilter(7.f); | |
233 | |
234 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75); | |
235 FilterOperation expected = FilterOperation::CreateHueRotateFilter(0.f); | |
236 EXPECT_EQ(expected, blended); | |
237 | |
238 blended = FilterOperation::Blend(&from, &to, 0.75); | |
239 expected = FilterOperation::CreateHueRotateFilter(6.f); | |
240 EXPECT_EQ(expected, blended); | |
241 | |
242 blended = FilterOperation::Blend(&from, &to, 1.5); | |
243 expected = FilterOperation::CreateHueRotateFilter(9.f); | |
244 EXPECT_EQ(expected, blended); | |
245 } | |
246 | |
247 TEST(FilterOperationsTest, BlendHueRotateWithNull) { | |
248 FilterOperation filter = FilterOperation::CreateHueRotateFilter(1.f); | |
249 | |
250 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25); | |
251 FilterOperation expected = FilterOperation::CreateHueRotateFilter(0.75f); | |
252 EXPECT_EQ(expected, blended); | |
253 | |
254 blended = FilterOperation::Blend(NULL, &filter, 0.25); | |
255 expected = FilterOperation::CreateHueRotateFilter(0.25f); | |
256 EXPECT_EQ(expected, blended); | |
257 } | |
258 | |
259 TEST(FilterOperationsTest, BlendInvertFilters) { | |
260 FilterOperation from = FilterOperation::CreateInvertFilter(0.25f); | |
261 FilterOperation to = FilterOperation::CreateInvertFilter(0.75f); | |
262 | |
263 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75); | |
264 FilterOperation expected = FilterOperation::CreateInvertFilter(0.f); | |
265 EXPECT_EQ(expected, blended); | |
266 | |
267 blended = FilterOperation::Blend(&from, &to, 0.75); | |
268 expected = FilterOperation::CreateInvertFilter(0.625f); | |
269 EXPECT_EQ(expected, blended); | |
270 | |
271 blended = FilterOperation::Blend(&from, &to, 1.8); | |
272 expected = FilterOperation::CreateInvertFilter(1.f); | |
273 EXPECT_EQ(expected, blended); | |
274 } | |
275 | |
276 TEST(FilterOperationsTest, BlendInvertWithNull) { | |
277 FilterOperation filter = FilterOperation::CreateInvertFilter(1.f); | |
278 | |
279 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25); | |
280 FilterOperation expected = FilterOperation::CreateInvertFilter(0.75f); | |
281 EXPECT_EQ(expected, blended); | |
282 | |
283 blended = FilterOperation::Blend(NULL, &filter, 0.25); | |
284 expected = FilterOperation::CreateInvertFilter(0.25f); | |
285 EXPECT_EQ(expected, blended); | |
286 } | |
287 | |
288 TEST(FilterOperationsTest, BlendBrightnessFilters) { | |
289 FilterOperation from = FilterOperation::CreateBrightnessFilter(3.f); | |
290 FilterOperation to = FilterOperation::CreateBrightnessFilter(7.f); | |
291 | |
292 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.9); | |
293 FilterOperation expected = FilterOperation::CreateBrightnessFilter(0.f); | |
294 EXPECT_EQ(expected, blended); | |
295 | |
296 blended = FilterOperation::Blend(&from, &to, 0.75); | |
297 expected = FilterOperation::CreateBrightnessFilter(6.f); | |
298 EXPECT_EQ(expected, blended); | |
299 | |
300 blended = FilterOperation::Blend(&from, &to, 1.5); | |
301 expected = FilterOperation::CreateBrightnessFilter(9.f); | |
302 EXPECT_EQ(expected, blended); | |
303 } | |
304 | |
305 TEST(FilterOperationsTest, BlendBrightnessWithNull) { | |
306 FilterOperation filter = FilterOperation::CreateBrightnessFilter(0.f); | |
307 | |
308 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25); | |
309 FilterOperation expected = FilterOperation::CreateBrightnessFilter(0.25f); | |
310 EXPECT_EQ(expected, blended); | |
311 | |
312 blended = FilterOperation::Blend(NULL, &filter, 0.25); | |
313 expected = FilterOperation::CreateBrightnessFilter(0.75f); | |
314 EXPECT_EQ(expected, blended); | |
315 } | |
316 | |
317 TEST(FilterOperationsTest, BlendContrastFilters) { | |
318 FilterOperation from = FilterOperation::CreateContrastFilter(3.f); | |
319 FilterOperation to = FilterOperation::CreateContrastFilter(7.f); | |
320 | |
321 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.9); | |
322 FilterOperation expected = FilterOperation::CreateContrastFilter(0.f); | |
323 EXPECT_EQ(expected, blended); | |
324 | |
325 blended = FilterOperation::Blend(&from, &to, 0.75); | |
326 expected = FilterOperation::CreateContrastFilter(6.f); | |
327 EXPECT_EQ(expected, blended); | |
328 | |
329 blended = FilterOperation::Blend(&from, &to, 1.5); | |
330 expected = FilterOperation::CreateContrastFilter(9.f); | |
331 EXPECT_EQ(expected, blended); | |
332 } | |
333 | |
334 TEST(FilterOperationsTest, BlendContrastWithNull) { | |
335 FilterOperation filter = FilterOperation::CreateContrastFilter(0.f); | |
336 | |
337 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25); | |
338 FilterOperation expected = FilterOperation::CreateContrastFilter(0.25f); | |
339 EXPECT_EQ(expected, blended); | |
340 | |
341 blended = FilterOperation::Blend(NULL, &filter, 0.25); | |
342 expected = FilterOperation::CreateContrastFilter(0.75f); | |
343 EXPECT_EQ(expected, blended); | |
344 } | |
345 | |
346 TEST(FilterOperationsTest, BlendOpacityFilters) { | |
347 FilterOperation from = FilterOperation::CreateOpacityFilter(0.25f); | |
348 FilterOperation to = FilterOperation::CreateOpacityFilter(0.75f); | |
349 | |
350 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75); | |
351 FilterOperation expected = FilterOperation::CreateOpacityFilter(0.f); | |
352 EXPECT_EQ(expected, blended); | |
353 | |
354 blended = FilterOperation::Blend(&from, &to, 0.75); | |
355 expected = FilterOperation::CreateOpacityFilter(0.625f); | |
356 EXPECT_EQ(expected, blended); | |
357 | |
358 blended = FilterOperation::Blend(&from, &to, 1.8); | |
359 expected = FilterOperation::CreateOpacityFilter(1.f); | |
360 EXPECT_EQ(expected, blended); | |
361 } | |
362 | |
363 TEST(FilterOperationsTest, BlendOpacityWithNull) { | |
364 FilterOperation filter = FilterOperation::CreateOpacityFilter(0.f); | |
365 | |
366 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25); | |
367 FilterOperation expected = FilterOperation::CreateOpacityFilter(0.25f); | |
368 EXPECT_EQ(expected, blended); | |
369 | |
370 blended = FilterOperation::Blend(NULL, &filter, 0.25); | |
371 expected = FilterOperation::CreateOpacityFilter(0.75f); | |
372 EXPECT_EQ(expected, blended); | |
373 } | |
374 | |
375 TEST(FilterOperationsTest, BlendBlurFilters) { | |
376 FilterOperation from = FilterOperation::CreateBlurFilter(3.f); | |
377 FilterOperation to = FilterOperation::CreateBlurFilter(7.f); | |
378 | |
379 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.9); | |
380 FilterOperation expected = FilterOperation::CreateBlurFilter(0.f); | |
381 EXPECT_EQ(expected, blended); | |
382 | |
383 blended = FilterOperation::Blend(&from, &to, 0.75); | |
384 expected = FilterOperation::CreateBlurFilter(6.f); | |
385 EXPECT_EQ(expected, blended); | |
386 | |
387 blended = FilterOperation::Blend(&from, &to, 1.5); | |
388 expected = FilterOperation::CreateBlurFilter(9.f); | |
389 EXPECT_EQ(expected, blended); | |
390 } | |
391 | |
392 TEST(FilterOperationsTest, BlendBlurWithNull) { | |
393 FilterOperation filter = FilterOperation::CreateBlurFilter(1.f); | |
394 | |
395 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25); | |
396 FilterOperation expected = FilterOperation::CreateBlurFilter(0.75f); | |
397 EXPECT_EQ(expected, blended); | |
398 | |
399 blended = FilterOperation::Blend(NULL, &filter, 0.25); | |
400 expected = FilterOperation::CreateBlurFilter(0.25f); | |
401 EXPECT_EQ(expected, blended); | |
402 } | |
403 | |
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)); | |
409 | |
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); | |
414 | |
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); | |
419 | |
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); | |
424 | |
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); | |
429 } | |
430 | |
431 TEST(FilterOperationsTest, BlendDropShadowWithNull) { | |
432 FilterOperation filter = FilterOperation::CreateDropShadowFilter( | |
433 gfx::Point(4, 4), 4.f, SkColorSetARGB(255, 40, 0, 0)); | |
434 | |
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); | |
439 | |
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); | |
444 } | |
445 | |
446 TEST(FilterOperationsTest, BlendZoomFilters) { | |
447 FilterOperation from = FilterOperation::CreateZoomFilter(2.f, 3); | |
448 FilterOperation to = FilterOperation::CreateZoomFilter(6.f, 0); | |
449 | |
450 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75); | |
451 FilterOperation expected = FilterOperation::CreateZoomFilter(1.f, 5); | |
452 EXPECT_EQ(expected, blended); | |
453 | |
454 blended = FilterOperation::Blend(&from, &to, 0.75); | |
455 expected = FilterOperation::CreateZoomFilter(5.f, 1); | |
456 EXPECT_EQ(expected, blended); | |
457 | |
458 blended = FilterOperation::Blend(&from, &to, 1.5); | |
459 expected = FilterOperation::CreateZoomFilter(8.f, 0); | |
460 EXPECT_EQ(expected, blended); | |
461 } | |
462 | |
463 TEST(FilterOperationsTest, BlendZoomWithNull) { | |
464 FilterOperation filter = FilterOperation::CreateZoomFilter(2.f, 1); | |
465 | |
466 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25); | |
467 FilterOperation expected = FilterOperation::CreateZoomFilter(1.75f, 1); | |
468 EXPECT_EQ(expected, blended); | |
469 | |
470 blended = FilterOperation::Blend(NULL, &filter, 0.25); | |
471 expected = FilterOperation::CreateZoomFilter(1.25f, 0); | |
472 EXPECT_EQ(expected, blended); | |
473 } | |
474 | |
475 TEST(FilterOperationsTest, BlendSaturatingBrightnessFilters) { | |
476 FilterOperation from = FilterOperation::CreateSaturatingBrightnessFilter(3.f); | |
477 FilterOperation to = FilterOperation::CreateSaturatingBrightnessFilter(7.f); | |
478 | |
479 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75); | |
480 FilterOperation expected = | |
481 FilterOperation::CreateSaturatingBrightnessFilter(0.f); | |
482 EXPECT_EQ(expected, blended); | |
483 | |
484 blended = FilterOperation::Blend(&from, &to, 0.75); | |
485 expected = FilterOperation::CreateSaturatingBrightnessFilter(6.f); | |
486 EXPECT_EQ(expected, blended); | |
487 | |
488 blended = FilterOperation::Blend(&from, &to, 1.5); | |
489 expected = FilterOperation::CreateSaturatingBrightnessFilter(9.f); | |
490 EXPECT_EQ(expected, blended); | |
491 } | |
492 | |
493 TEST(FilterOperationsTest, BlendSaturatingBrightnessWithNull) { | |
494 FilterOperation filter = | |
495 FilterOperation::CreateSaturatingBrightnessFilter(1.f); | |
496 | |
497 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25); | |
498 FilterOperation expected = | |
499 FilterOperation::CreateSaturatingBrightnessFilter(0.75f); | |
500 EXPECT_EQ(expected, blended); | |
501 | |
502 blended = FilterOperation::Blend(NULL, &filter, 0.25); | |
503 expected = FilterOperation::CreateSaturatingBrightnessFilter(0.25f); | |
504 EXPECT_EQ(expected, blended); | |
505 } | |
506 | |
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); | |
514 | |
515 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75); | |
516 EXPECT_EQ(from, blended); | |
517 | |
518 blended = FilterOperation::Blend(&from, &to, 0.5); | |
519 EXPECT_EQ(from, blended); | |
520 | |
521 blended = FilterOperation::Blend(&from, &to, 0.6); | |
522 EXPECT_EQ(to, blended); | |
523 | |
524 blended = FilterOperation::Blend(&from, &to, 1.5); | |
525 EXPECT_EQ(to, blended); | |
526 } | |
527 | |
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>()); | |
534 | |
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); | |
539 | |
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); | |
544 } | |
545 | |
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; | |
551 | |
552 from.Append(FilterOperation::CreateBlurFilter(0.f)); | |
553 to.Append(FilterOperation::CreateBlurFilter(2.f)); | |
554 | |
555 from.Append(FilterOperation::CreateSaturateFilter(4.f)); | |
556 to.Append(FilterOperation::CreateSaturateFilter(0.f)); | |
557 | |
558 from.Append(FilterOperation::CreateZoomFilter(2.0f, 1)); | |
559 to.Append(FilterOperation::CreateZoomFilter(10.f, 9)); | |
560 | |
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); | |
567 | |
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); | |
574 | |
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); | |
581 } | |
582 | |
583 TEST(FilterOperationsTest, BlendEmptyAndNonEmptySequences) { | |
584 FilterOperations empty; | |
585 FilterOperations filters; | |
586 | |
587 filters.Append(FilterOperation::CreateGrayscaleFilter(0.75f)); | |
588 filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); | |
589 filters.Append(FilterOperation::CreateHueRotateFilter(10.0f)); | |
590 | |
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); | |
597 | |
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); | |
604 | |
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); | |
611 | |
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); | |
618 | |
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); | |
625 | |
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); | |
632 } | |
633 | |
634 TEST(FilterOperationsTest, BlendEmptySequences) { | |
635 FilterOperations empty; | |
636 | |
637 FilterOperations blended = empty.Blend(empty, -0.75); | |
638 EXPECT_EQ(blended, empty); | |
639 | |
640 blended = empty.Blend(empty, 0.75); | |
641 EXPECT_EQ(blended, empty); | |
642 | |
643 blended = empty.Blend(empty, 1.5); | |
644 EXPECT_EQ(blended, empty); | |
645 } | |
646 | |
647 // Tests blending non-empty sequences that have non-matching operations. | |
648 TEST(FilterOperationsTest, BlendNonMatchingSequences) { | |
649 FilterOperations from; | |
650 FilterOperations to; | |
651 | |
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)); | |
656 | |
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); | |
663 } | |
664 | |
665 // Tests blending non-empty sequences of different sizes. | |
666 TEST(FilterOperationsTest, BlendRaggedSequences) { | |
667 FilterOperations from; | |
668 FilterOperations to; | |
669 | |
670 from.Append(FilterOperation::CreateSaturateFilter(3.f)); | |
671 from.Append(FilterOperation::CreateBlurFilter(2.f)); | |
672 to.Append(FilterOperation::CreateSaturateFilter(4.f)); | |
673 | |
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); | |
679 | |
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); | |
685 | |
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); | |
691 | |
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); | |
700 } | |
701 | |
702 } // namespace | |
703 } // namespace cc | |
OLD | NEW |