| 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 "skia/ext/refptr.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 8 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
| 9 #include "ui/gfx/point.h" | 9 #include "ui/gfx/point.h" |
| 10 | 10 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 SAVE_RESTORE_OFFSET_AMOUNT_COLOR( | 133 SAVE_RESTORE_OFFSET_AMOUNT_COLOR( |
| 134 DropShadow, DROP_SHADOW, gfx::Point(3, 4), 0.4f, 0xffffff00); | 134 DropShadow, DROP_SHADOW, gfx::Point(3, 4), 0.4f, 0xffffff00); |
| 135 | 135 |
| 136 SkScalar matrix[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, | 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}; | 137 17, 18, 19, 20}; |
| 138 SAVE_RESTORE_MATRIX(ColorMatrix, COLOR_MATRIX, matrix); | 138 SAVE_RESTORE_MATRIX(ColorMatrix, COLOR_MATRIX, matrix); |
| 139 | 139 |
| 140 SAVE_RESTORE_AMOUNT_INSET(Zoom, ZOOM, 0.5f, 32); | 140 SAVE_RESTORE_AMOUNT_INSET(Zoom, ZOOM, 0.5f, 32); |
| 141 } | 141 } |
| 142 | 142 |
| 143 TEST(FilterOperationsTest, SaveAndRestoreAlphaThreshold) { |
| 144 SkRegion region(SkIRect::MakeLTRB(20, 10, 300, 200)); |
| 145 float dsf = 2.f; |
| 146 float inner = 0.6f; |
| 147 float outer = 0.3f; |
| 148 |
| 149 FilterOperation op = |
| 150 FilterOperation::CreateAlphaThresholdFilter(region, dsf, inner, outer); |
| 151 EXPECT_EQ(FilterOperation::ALPHA_THRESHOLD, op.type()); |
| 152 EXPECT_EQ(region, op.region()); |
| 153 EXPECT_EQ(dsf, op.device_scale_factor()); |
| 154 EXPECT_EQ(inner, op.amount()); |
| 155 EXPECT_EQ(outer, op.outer_threshold()); |
| 156 |
| 157 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); |
| 158 op2.set_type(FilterOperation::ALPHA_THRESHOLD); |
| 159 |
| 160 EXPECT_NE(region, op2.region()); |
| 161 EXPECT_NE(dsf, op2.device_scale_factor()); |
| 162 EXPECT_NE(inner, op2.amount()); |
| 163 EXPECT_NE(outer, op2.outer_threshold()); |
| 164 |
| 165 op2.set_region(region); |
| 166 op2.set_device_scale_factor(dsf); |
| 167 op2.set_amount(inner); |
| 168 op2.set_outer_threshold(outer); |
| 169 |
| 170 EXPECT_EQ(FilterOperation::ALPHA_THRESHOLD, op2.type()); |
| 171 EXPECT_EQ(region, op2.region()); |
| 172 EXPECT_EQ(dsf, op2.device_scale_factor()); |
| 173 EXPECT_EQ(inner, op2.amount()); |
| 174 EXPECT_EQ(outer, op2.outer_threshold()); |
| 175 } |
| 176 |
| 143 TEST(FilterOperationsTest, BlendGrayscaleFilters) { | 177 TEST(FilterOperationsTest, BlendGrayscaleFilters) { |
| 144 FilterOperation from = FilterOperation::CreateGrayscaleFilter(0.25f); | 178 FilterOperation from = FilterOperation::CreateGrayscaleFilter(0.25f); |
| 145 FilterOperation to = FilterOperation::CreateGrayscaleFilter(0.75f); | 179 FilterOperation to = FilterOperation::CreateGrayscaleFilter(0.75f); |
| 146 | 180 |
| 147 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75); | 181 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75); |
| 148 FilterOperation expected = FilterOperation::CreateGrayscaleFilter(0.f); | 182 FilterOperation expected = FilterOperation::CreateGrayscaleFilter(0.f); |
| 149 EXPECT_EQ(expected, blended); | 183 EXPECT_EQ(expected, blended); |
| 150 | 184 |
| 151 blended = FilterOperation::Blend(&from, &to, 0.75); | 185 blended = FilterOperation::Blend(&from, &to, 0.75); |
| 152 expected = FilterOperation::CreateGrayscaleFilter(0.625f); | 186 expected = FilterOperation::CreateGrayscaleFilter(0.625f); |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 EXPECT_EQ(filter, blended); | 570 EXPECT_EQ(filter, blended); |
| 537 blended = FilterOperation::Blend(&filter, NULL, 0.75); | 571 blended = FilterOperation::Blend(&filter, NULL, 0.75); |
| 538 EXPECT_EQ(null_filter, blended); | 572 EXPECT_EQ(null_filter, blended); |
| 539 | 573 |
| 540 blended = FilterOperation::Blend(NULL, &filter, 0.25); | 574 blended = FilterOperation::Blend(NULL, &filter, 0.25); |
| 541 EXPECT_EQ(null_filter, blended); | 575 EXPECT_EQ(null_filter, blended); |
| 542 blended = FilterOperation::Blend(NULL, &filter, 0.75); | 576 blended = FilterOperation::Blend(NULL, &filter, 0.75); |
| 543 EXPECT_EQ(filter, blended); | 577 EXPECT_EQ(filter, blended); |
| 544 } | 578 } |
| 545 | 579 |
| 580 TEST(FilterOperationsTest, BlendAlphaThresholdFilters) { |
| 581 SkRegion start_region(SkIRect::MakeLTRB(15, 5, 200, 100)); |
| 582 SkRegion end_region(SkIRect::MakeLTRB(20, 10, 300, 200)); |
| 583 float start_dsf = 1.f; |
| 584 float end_dsf = 2.f; |
| 585 |
| 586 FilterOperation from = FilterOperation::CreateAlphaThresholdFilter( |
| 587 start_region, start_dsf, 0.25f, 0.25f); |
| 588 FilterOperation to = FilterOperation::CreateAlphaThresholdFilter( |
| 589 end_region, end_dsf, 0.75f, 0.75f); |
| 590 |
| 591 FilterOperation blended = FilterOperation::Blend(&from, &to, -0.75); |
| 592 FilterOperation expected = FilterOperation::CreateAlphaThresholdFilter( |
| 593 start_region, start_dsf, 0.f, 0.f); |
| 594 EXPECT_EQ(expected, blended); |
| 595 |
| 596 blended = FilterOperation::Blend(&from, &to, 0.25); |
| 597 expected = FilterOperation::CreateAlphaThresholdFilter( |
| 598 start_region, start_dsf, 0.375f, 0.375f); |
| 599 EXPECT_EQ(expected, blended); |
| 600 |
| 601 blended = FilterOperation::Blend(&from, &to, 0.75); |
| 602 expected = FilterOperation::CreateAlphaThresholdFilter( |
| 603 end_region, end_dsf, 0.625f, 0.625f); |
| 604 EXPECT_EQ(expected, blended); |
| 605 |
| 606 blended = FilterOperation::Blend(&from, &to, 1.8); |
| 607 expected = FilterOperation::CreateAlphaThresholdFilter( |
| 608 end_region, end_dsf, 1.f, 1.f); |
| 609 EXPECT_EQ(expected, blended); |
| 610 } |
| 611 |
| 546 // Tests blending non-empty sequences that have the same length and matching | 612 // Tests blending non-empty sequences that have the same length and matching |
| 547 // operations. | 613 // operations. |
| 548 TEST(FilterOperationsTest, BlendMatchingSequences) { | 614 TEST(FilterOperationsTest, BlendMatchingSequences) { |
| 549 FilterOperations from; | 615 FilterOperations from; |
| 550 FilterOperations to; | 616 FilterOperations to; |
| 551 | 617 |
| 552 from.Append(FilterOperation::CreateBlurFilter(0.f)); | 618 from.Append(FilterOperation::CreateBlurFilter(0.f)); |
| 553 to.Append(FilterOperation::CreateBlurFilter(2.f)); | 619 to.Append(FilterOperation::CreateBlurFilter(2.f)); |
| 554 | 620 |
| 555 from.Append(FilterOperation::CreateSaturateFilter(4.f)); | 621 from.Append(FilterOperation::CreateSaturateFilter(4.f)); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 blended = to.Blend(from, -0.75); | 760 blended = to.Blend(from, -0.75); |
| 695 EXPECT_EQ(to, blended); | 761 EXPECT_EQ(to, blended); |
| 696 blended = to.Blend(from, 0.75); | 762 blended = to.Blend(from, 0.75); |
| 697 EXPECT_EQ(to, blended); | 763 EXPECT_EQ(to, blended); |
| 698 blended = to.Blend(from, 1.5); | 764 blended = to.Blend(from, 1.5); |
| 699 EXPECT_EQ(to, blended); | 765 EXPECT_EQ(to, blended); |
| 700 } | 766 } |
| 701 | 767 |
| 702 } // namespace | 768 } // namespace |
| 703 } // namespace cc | 769 } // namespace cc |
| OLD | NEW |