OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/output/filter_operations.h" | 5 #include "cc/output/filter_operations.h" |
6 #include "skia/ext/refptr.h" | |
6 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | |
7 #include "ui/gfx/point.h" | 9 #include "ui/gfx/point.h" |
8 | 10 |
9 namespace cc { | 11 namespace cc { |
10 namespace { | 12 namespace { |
11 | 13 |
12 TEST(FilterOperationsTest, GetOutsetsBlur) { | 14 TEST(FilterOperationsTest, GetOutsetsBlur) { |
13 FilterOperations ops; | 15 FilterOperations ops; |
14 ops.Append(FilterOperation::CreateBlurFilter(20)); | 16 ops.Append(FilterOperation::CreateBlurFilter(20)); |
15 int top, right, bottom, left; | 17 int top, right, bottom, left; |
16 top = right = bottom = left = 0; | 18 top = right = bottom = left = 0; |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25); | 492 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25); |
491 FilterOperation expected = | 493 FilterOperation expected = |
492 FilterOperation::CreateSaturatingBrightnessFilter(0.75f); | 494 FilterOperation::CreateSaturatingBrightnessFilter(0.75f); |
493 EXPECT_EQ(expected, blended); | 495 EXPECT_EQ(expected, blended); |
494 | 496 |
495 blended = FilterOperation::Blend(NULL, &filter, 0.25); | 497 blended = FilterOperation::Blend(NULL, &filter, 0.25); |
496 expected = FilterOperation::CreateSaturatingBrightnessFilter(0.25f); | 498 expected = FilterOperation::CreateSaturatingBrightnessFilter(0.25f); |
497 EXPECT_EQ(expected, blended); | 499 EXPECT_EQ(expected, blended); |
498 } | 500 } |
499 | 501 |
502 TEST(FilterOperationsTest, BlendReferenceFilters) { | |
503 skia::RefPtr<SkImageFilter> from_filter = skia::AdoptRef( | |
504 new SkBlurImageFilter(1.f, 1.f)); | |
505 skia::RefPtr<SkImageFilter> to_filter = skia::AdoptRef( | |
506 new SkBlurImageFilter(2.f, 2.f)); | |
507 FilterOperation from = FilterOperation::CreateReferenceFilter(from_filter); | |
508 FilterOperation to = FilterOperation::CreateReferenceFilter(to_filter); | |
509 | |
510 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75); | |
511 EXPECT_EQ(from, blended); | |
512 | |
513 blended = FilterOperation::Blend(&from, &to, 0.5); | |
514 EXPECT_EQ(from, blended); | |
515 | |
516 blended = FilterOperation::Blend(&from, &to, 0.6); | |
517 EXPECT_EQ(to, blended); | |
518 | |
519 blended = FilterOperation::Blend(&from, &to, 1.5); | |
520 EXPECT_EQ(to, blended); | |
521 } | |
522 | |
523 TEST(FilterOperationsTest, BlendReferenceWithNull) { | |
524 skia::RefPtr<SkImageFilter> image_filter = skia::AdoptRef( | |
525 new SkBlurImageFilter(1.f, 1.f)); | |
526 FilterOperation filter = FilterOperation::CreateReferenceFilter(image_filter); | |
danakj
2013/09/09 22:04:50
nit: s/filter/from/
ajuma
2013/09/10 21:17:58
This is used as the 'from' filter in the first two
| |
527 | |
528 FilterOperation blended = FilterOperation::Blend(&filter, NULL, 0.25); | |
529 EXPECT_EQ(filter, blended); | |
530 blended = FilterOperation::Blend(&filter, NULL, 0.75); | |
531 EXPECT_EQ(FilterOperation::CreateEmptyFilter(), blended); | |
532 | |
533 blended = FilterOperation::Blend(NULL, &filter, 0.25); | |
534 EXPECT_EQ(FilterOperation::CreateEmptyFilter(), blended); | |
535 blended = FilterOperation::Blend(NULL, &filter, 0.75); | |
536 EXPECT_EQ(filter, blended); | |
537 } | |
538 | |
500 // Tests blending non-empty sequences that have the same length and matching | 539 // Tests blending non-empty sequences that have the same length and matching |
501 // operations. | 540 // operations. |
502 TEST(FilterOperationsTest, BlendMatchingSequences) { | 541 TEST(FilterOperationsTest, BlendMatchingSequences) { |
503 FilterOperations from; | 542 FilterOperations from; |
504 FilterOperations to; | 543 FilterOperations to; |
505 | 544 |
506 from.Append(FilterOperation::CreateBlurFilter(0.f)); | 545 from.Append(FilterOperation::CreateBlurFilter(0.f)); |
507 to.Append(FilterOperation::CreateBlurFilter(2.f)); | 546 to.Append(FilterOperation::CreateBlurFilter(2.f)); |
508 | 547 |
509 from.Append(FilterOperation::CreateSaturateFilter(4.f)); | 548 from.Append(FilterOperation::CreateSaturateFilter(4.f)); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 blended = to.Blend(from, -0.75); | 658 blended = to.Blend(from, -0.75); |
620 EXPECT_EQ(to, blended); | 659 EXPECT_EQ(to, blended); |
621 blended = to.Blend(from, 0.75); | 660 blended = to.Blend(from, 0.75); |
622 EXPECT_EQ(to, blended); | 661 EXPECT_EQ(to, blended); |
623 blended = to.Blend(from, 1.5); | 662 blended = to.Blend(from, 1.5); |
624 EXPECT_EQ(to, blended); | 663 EXPECT_EQ(to, blended); |
625 } | 664 } |
626 | 665 |
627 } // namespace | 666 } // namespace |
628 } // namespace cc | 667 } // namespace cc |
OLD | NEW |