| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "cc/output/filter_operations.h" | 7 #include "cc/output/filter_operations.h" |
| 8 #include "skia/ext/refptr.h" | 8 #include "skia/ext/refptr.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 10 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
| 11 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" | 11 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" |
| 12 #include "third_party/skia/include/effects/SkOffsetImageFilter.h" |
| 12 #include "ui/gfx/geometry/point.h" | 13 #include "ui/gfx/geometry/point.h" |
| 14 #include "ui/gfx/geometry/rect.h" |
| 13 | 15 |
| 14 namespace cc { | 16 namespace cc { |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 TEST(FilterOperationsTest, GetOutsetsBlur) { | 19 TEST(FilterOperationsTest, GetOutsetsBlur) { |
| 18 FilterOperations ops; | 20 FilterOperations ops; |
| 19 ops.Append(FilterOperation::CreateBlurFilter(20)); | 21 ops.Append(FilterOperation::CreateBlurFilter(20)); |
| 20 int top, right, bottom, left; | 22 int top, right, bottom, left; |
| 21 top = right = bottom = left = 0; | 23 top = right = bottom = left = 0; |
| 22 ops.GetOutsets(&top, &right, &bottom, &left); | 24 ops.GetOutsets(&top, &right, &bottom, &left); |
| 23 EXPECT_EQ(57, top); | 25 EXPECT_EQ(57, top); |
| 24 EXPECT_EQ(57, right); | 26 EXPECT_EQ(57, right); |
| 25 EXPECT_EQ(57, bottom); | 27 EXPECT_EQ(57, bottom); |
| 26 EXPECT_EQ(57, left); | 28 EXPECT_EQ(57, left); |
| 27 } | 29 } |
| 28 | 30 |
| 31 TEST(FilterOperationsTest, MapRectBlur) { |
| 32 FilterOperations ops; |
| 33 ops.Append(FilterOperation::CreateBlurFilter(20)); |
| 34 EXPECT_EQ(gfx::Rect(-57, -57, 124, 124), |
| 35 ops.MapRect(gfx::Rect(0, 0, 10, 10))); |
| 36 } |
| 37 |
| 29 TEST(FilterOperationsTest, GetOutsetsDropShadowReferenceFilter) { | 38 TEST(FilterOperationsTest, GetOutsetsDropShadowReferenceFilter) { |
| 30 // TODO(hendrikw): We need to make outsets for reference filters be in line | 39 // TODO(hendrikw): We need to make outsets for reference filters be in line |
| 31 // with non-reference filters. See crbug.com/523534 | 40 // with non-reference filters. See crbug.com/523534 |
| 32 skia::RefPtr<SkImageFilter> filter = | 41 skia::RefPtr<SkImageFilter> filter = |
| 33 skia::AdoptRef(SkDropShadowImageFilter::Create( | 42 skia::AdoptRef(SkDropShadowImageFilter::Create( |
| 34 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), | 43 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), |
| 35 SkIntToScalar(9), SK_ColorBLACK, | 44 SkIntToScalar(9), SK_ColorBLACK, |
| 36 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode)); | 45 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode)); |
| 37 FilterOperations ops; | 46 FilterOperations ops; |
| 38 ops.Append(FilterOperation::CreateReferenceFilter(filter)); | 47 ops.Append(FilterOperation::CreateReferenceFilter(filter)); |
| 39 | 48 |
| 40 int top, right, bottom, left; | 49 int top, right, bottom, left; |
| 41 top = right = bottom = left = 0; | 50 top = right = bottom = left = 0; |
| 42 ops.GetOutsets(&top, &right, &bottom, &left); | 51 ops.GetOutsets(&top, &right, &bottom, &left); |
| 43 EXPECT_EQ(35, top); | 52 EXPECT_EQ(35, top); |
| 44 EXPECT_EQ(9, right); | 53 EXPECT_EQ(9, right); |
| 45 EXPECT_EQ(19, bottom); | 54 EXPECT_EQ(19, bottom); |
| 46 EXPECT_EQ(15, left); | 55 EXPECT_EQ(15, left); |
| 47 } | 56 } |
| 48 | 57 |
| 58 TEST(FilterOperationsTest, MapRectDropShadowReferenceFilter) { |
| 59 skia::RefPtr<SkImageFilter> filter = |
| 60 skia::AdoptRef(SkDropShadowImageFilter::Create( |
| 61 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), |
| 62 SkIntToScalar(9), SK_ColorBLACK, |
| 63 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode)); |
| 64 FilterOperations ops; |
| 65 ops.Append(FilterOperation::CreateReferenceFilter(filter)); |
| 66 EXPECT_EQ(gfx::Rect(-9, -19, 34, 64), ops.MapRect(gfx::Rect(0, 0, 10, 10))); |
| 67 } |
| 68 |
| 69 TEST(FilterOperationsTest, MapRectOffsetReferenceFilter) { |
| 70 skia::RefPtr<SkImageFilter> filter = |
| 71 skia::AdoptRef(SkOffsetImageFilter::Make(30, 40, nullptr)); |
| 72 FilterOperations ops; |
| 73 ops.Append(FilterOperation::CreateReferenceFilter(std::move(filter))); |
| 74 EXPECT_EQ(gfx::Rect(30, 40, 10, 10), ops.MapRect(gfx::Rect(0, 0, 10, 10))); |
| 75 } |
| 76 |
| 49 TEST(FilterOperationsTest, GetOutsetsNullReferenceFilter) { | 77 TEST(FilterOperationsTest, GetOutsetsNullReferenceFilter) { |
| 50 FilterOperations ops; | 78 FilterOperations ops; |
| 51 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); | 79 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); |
| 52 | 80 |
| 53 int top, right, bottom, left; | 81 int top, right, bottom, left; |
| 54 top = right = bottom = left = 0; | 82 top = right = bottom = left = 0; |
| 55 ops.GetOutsets(&top, &right, &bottom, &left); | 83 ops.GetOutsets(&top, &right, &bottom, &left); |
| 56 EXPECT_EQ(0, top); | 84 EXPECT_EQ(0, top); |
| 57 EXPECT_EQ(0, right); | 85 EXPECT_EQ(0, right); |
| 58 EXPECT_EQ(0, bottom); | 86 EXPECT_EQ(0, bottom); |
| 59 EXPECT_EQ(0, left); | 87 EXPECT_EQ(0, left); |
| 60 } | 88 } |
| 61 | 89 |
| 90 TEST(FilterOperationsTest, MapRectNullReferenceFilter) { |
| 91 FilterOperations ops; |
| 92 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); |
| 93 EXPECT_EQ(gfx::Rect(0, 0, 10, 10), ops.MapRect(gfx::Rect(0, 0, 10, 10))); |
| 94 } |
| 95 |
| 62 TEST(FilterOperationsTest, GetOutsetsDropShadow) { | 96 TEST(FilterOperationsTest, GetOutsetsDropShadow) { |
| 63 FilterOperations ops; | 97 FilterOperations ops; |
| 64 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); | 98 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); |
| 65 int top, right, bottom, left; | 99 int top, right, bottom, left; |
| 66 top = right = bottom = left = 0; | 100 top = right = bottom = left = 0; |
| 67 ops.GetOutsets(&top, &right, &bottom, &left); | 101 ops.GetOutsets(&top, &right, &bottom, &left); |
| 68 EXPECT_EQ(49, top); | 102 EXPECT_EQ(49, top); |
| 69 EXPECT_EQ(60, right); | 103 EXPECT_EQ(60, right); |
| 70 EXPECT_EQ(65, bottom); | 104 EXPECT_EQ(65, bottom); |
| 71 EXPECT_EQ(54, left); | 105 EXPECT_EQ(54, left); |
| 72 } | 106 } |
| 73 | 107 |
| 108 TEST(FilterOperationsTest, MapRectDropShadow) { |
| 109 FilterOperations ops; |
| 110 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); |
| 111 EXPECT_EQ(gfx::Rect(-54, -49, 124, 124), |
| 112 ops.MapRect(gfx::Rect(0, 0, 10, 10))); |
| 113 } |
| 114 |
| 74 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \ | 115 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \ |
| 75 { \ | 116 { \ |
| 76 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \ | 117 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \ |
| 77 EXPECT_EQ(FilterOperation::filter_type, op.type()); \ | 118 EXPECT_EQ(FilterOperation::filter_type, op.type()); \ |
| 78 EXPECT_EQ(a, op.amount()); \ | 119 EXPECT_EQ(a, op.amount()); \ |
| 79 \ | 120 \ |
| 80 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \ | 121 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \ |
| 81 op2.set_type(FilterOperation::filter_type); \ | 122 op2.set_type(FilterOperation::filter_type); \ |
| 82 \ | 123 \ |
| 83 EXPECT_NE(a, op2.amount()); \ | 124 EXPECT_NE(a, op2.amount()); \ |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 blended = to.Blend(from, -0.75); | 771 blended = to.Blend(from, -0.75); |
| 731 EXPECT_EQ(to, blended); | 772 EXPECT_EQ(to, blended); |
| 732 blended = to.Blend(from, 0.75); | 773 blended = to.Blend(from, 0.75); |
| 733 EXPECT_EQ(to, blended); | 774 EXPECT_EQ(to, blended); |
| 734 blended = to.Blend(from, 1.5); | 775 blended = to.Blend(from, 1.5); |
| 735 EXPECT_EQ(to, blended); | 776 EXPECT_EQ(to, blended); |
| 736 } | 777 } |
| 737 | 778 |
| 738 } // namespace | 779 } // namespace |
| 739 } // namespace cc | 780 } // namespace cc |
| OLD | NEW |