| 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 "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 9 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
| 10 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" | 10 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 EXPECT_EQ(60, left); | 27 EXPECT_EQ(60, left); |
| 28 } | 28 } |
| 29 | 29 |
| 30 TEST(FilterOperationsTest, MapRectBlur) { | 30 TEST(FilterOperationsTest, MapRectBlur) { |
| 31 FilterOperations ops; | 31 FilterOperations ops; |
| 32 ops.Append(FilterOperation::CreateBlurFilter(20)); | 32 ops.Append(FilterOperation::CreateBlurFilter(20)); |
| 33 EXPECT_EQ(gfx::Rect(-60, -60, 130, 130), | 33 EXPECT_EQ(gfx::Rect(-60, -60, 130, 130), |
| 34 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); | 34 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 35 } | 35 } |
| 36 | 36 |
| 37 TEST(FilterOperationsTest, MapRectReverseBlur) { |
| 38 FilterOperations ops; |
| 39 ops.Append(FilterOperation::CreateBlurFilter(20)); |
| 40 EXPECT_EQ(gfx::Rect(-60, -60, 130, 130), |
| 41 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 42 } |
| 43 |
| 37 TEST(FilterOperationsTest, GetOutsetsDropShadowReferenceFilter) { | 44 TEST(FilterOperationsTest, GetOutsetsDropShadowReferenceFilter) { |
| 38 // TODO(hendrikw): We need to make outsets for reference filters be in line | 45 // TODO(hendrikw): We need to make outsets for reference filters be in line |
| 39 // with non-reference filters. See crbug.com/523534 | 46 // with non-reference filters. See crbug.com/523534 |
| 40 FilterOperations ops; | 47 FilterOperations ops; |
| 41 ops.Append( | 48 ops.Append( |
| 42 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make( | 49 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make( |
| 43 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), | 50 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), |
| 44 SkIntToScalar(9), SK_ColorBLACK, | 51 SkIntToScalar(9), SK_ColorBLACK, |
| 45 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, | 52 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, |
| 46 nullptr))); | 53 nullptr))); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 59 ops.Append( | 66 ops.Append( |
| 60 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make( | 67 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make( |
| 61 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), | 68 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), |
| 62 SkIntToScalar(9), SK_ColorBLACK, | 69 SkIntToScalar(9), SK_ColorBLACK, |
| 63 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, | 70 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, |
| 64 nullptr))); | 71 nullptr))); |
| 65 EXPECT_EQ(gfx::Rect(-9, -19, 34, 64), | 72 EXPECT_EQ(gfx::Rect(-9, -19, 34, 64), |
| 66 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); | 73 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 67 } | 74 } |
| 68 | 75 |
| 76 TEST(FilterOperationsTest, MapRectReverseDropShadowReferenceFilter) { |
| 77 FilterOperations ops; |
| 78 ops.Append( |
| 79 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make( |
| 80 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), |
| 81 SkIntToScalar(9), SK_ColorBLACK, |
| 82 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, |
| 83 nullptr))); |
| 84 EXPECT_EQ(gfx::Rect(-15, -35, 34, 64), |
| 85 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 86 } |
| 87 |
| 69 TEST(FilterOperationsTest, MapRectOffsetReferenceFilter) { | 88 TEST(FilterOperationsTest, MapRectOffsetReferenceFilter) { |
| 70 sk_sp<SkImageFilter> filter = SkOffsetImageFilter::Make(30, 40, nullptr); | 89 sk_sp<SkImageFilter> filter = SkOffsetImageFilter::Make(30, 40, nullptr); |
| 71 FilterOperations ops; | 90 FilterOperations ops; |
| 72 ops.Append(FilterOperation::CreateReferenceFilter(std::move(filter))); | 91 ops.Append(FilterOperation::CreateReferenceFilter(std::move(filter))); |
| 73 EXPECT_EQ(gfx::Rect(30, 40, 10, 10), | 92 EXPECT_EQ(gfx::Rect(30, 40, 10, 10), |
| 74 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); | 93 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 75 } | 94 } |
| 76 | 95 |
| 96 TEST(FilterOperationsTest, MapRectReverseOffsetReferenceFilter) { |
| 97 sk_sp<SkImageFilter> filter = SkOffsetImageFilter::Make(30, 40, nullptr); |
| 98 FilterOperations ops; |
| 99 ops.Append(FilterOperation::CreateReferenceFilter(std::move(filter))); |
| 100 EXPECT_EQ(gfx::Rect(-30, -40, 10, 10), |
| 101 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 102 } |
| 103 |
| 104 TEST(FilterOperationsTest, MapRectCombineNonCommutative) { |
| 105 // Offsets by 100px in each axis, then scales the resulting image by 2. |
| 106 FilterOperations ops; |
| 107 ops.Append(FilterOperation::CreateReferenceFilter( |
| 108 SkOffsetImageFilter::Make(100, 100, nullptr))); |
| 109 SkMatrix scaleMatrix; |
| 110 scaleMatrix.setScale(2, 2); |
| 111 ops.Append( |
| 112 FilterOperation::CreateReferenceFilter(SkImageFilter::MakeMatrixFilter( |
| 113 scaleMatrix, kNone_SkFilterQuality, nullptr))); |
| 114 |
| 115 EXPECT_EQ(gfx::Rect(200, 200, 20, 20), |
| 116 ops.MapRect(gfx::Rect(10, 10), SkMatrix::I())); |
| 117 } |
| 118 |
| 119 TEST(FilterOperationsTest, MapRectReverseCombineNonCommutative) { |
| 120 // Offsets by 100px in each axis, then scales the resulting image by 2. |
| 121 FilterOperations ops; |
| 122 ops.Append(FilterOperation::CreateReferenceFilter( |
| 123 SkOffsetImageFilter::Make(100, 100, nullptr))); |
| 124 SkMatrix scaleMatrix; |
| 125 scaleMatrix.setScale(2, 2); |
| 126 ops.Append( |
| 127 FilterOperation::CreateReferenceFilter(SkImageFilter::MakeMatrixFilter( |
| 128 scaleMatrix, kNone_SkFilterQuality, nullptr))); |
| 129 |
| 130 EXPECT_EQ(gfx::Rect(10, 10), |
| 131 ops.MapRectReverse(gfx::Rect(200, 200, 20, 20), SkMatrix::I())); |
| 132 } |
| 133 |
| 77 TEST(FilterOperationsTest, GetOutsetsNullReferenceFilter) { | 134 TEST(FilterOperationsTest, GetOutsetsNullReferenceFilter) { |
| 78 FilterOperations ops; | 135 FilterOperations ops; |
| 79 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); | 136 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); |
| 80 | 137 |
| 81 int top, right, bottom, left; | 138 int top, right, bottom, left; |
| 82 top = right = bottom = left = 0; | 139 top = right = bottom = left = 0; |
| 83 ops.GetOutsets(&top, &right, &bottom, &left); | 140 ops.GetOutsets(&top, &right, &bottom, &left); |
| 84 EXPECT_EQ(0, top); | 141 EXPECT_EQ(0, top); |
| 85 EXPECT_EQ(0, right); | 142 EXPECT_EQ(0, right); |
| 86 EXPECT_EQ(0, bottom); | 143 EXPECT_EQ(0, bottom); |
| 87 EXPECT_EQ(0, left); | 144 EXPECT_EQ(0, left); |
| 88 } | 145 } |
| 89 | 146 |
| 90 TEST(FilterOperationsTest, MapRectNullReferenceFilter) { | 147 TEST(FilterOperationsTest, MapRectNullReferenceFilter) { |
| 91 FilterOperations ops; | 148 FilterOperations ops; |
| 92 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); | 149 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); |
| 93 EXPECT_EQ(gfx::Rect(0, 0, 10, 10), | 150 EXPECT_EQ(gfx::Rect(0, 0, 10, 10), |
| 94 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); | 151 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 95 } | 152 } |
| 96 | 153 |
| 154 TEST(FilterOperationsTest, MapRectReverseNullReferenceFilter) { |
| 155 FilterOperations ops; |
| 156 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); |
| 157 EXPECT_EQ(gfx::Rect(0, 0, 10, 10), |
| 158 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 159 } |
| 160 |
| 97 TEST(FilterOperationsTest, GetOutsetsDropShadow) { | 161 TEST(FilterOperationsTest, GetOutsetsDropShadow) { |
| 98 FilterOperations ops; | 162 FilterOperations ops; |
| 99 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); | 163 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); |
| 100 int top, right, bottom, left; | 164 int top, right, bottom, left; |
| 101 top = right = bottom = left = 0; | 165 top = right = bottom = left = 0; |
| 102 ops.GetOutsets(&top, &right, &bottom, &left); | 166 ops.GetOutsets(&top, &right, &bottom, &left); |
| 103 EXPECT_EQ(52, top); | 167 EXPECT_EQ(52, top); |
| 104 EXPECT_EQ(63, right); | 168 EXPECT_EQ(63, right); |
| 105 EXPECT_EQ(68, bottom); | 169 EXPECT_EQ(68, bottom); |
| 106 EXPECT_EQ(57, left); | 170 EXPECT_EQ(57, left); |
| 107 } | 171 } |
| 108 | 172 |
| 109 TEST(FilterOperationsTest, MapRectDropShadow) { | 173 TEST(FilterOperationsTest, MapRectDropShadow) { |
| 110 FilterOperations ops; | 174 FilterOperations ops; |
| 111 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); | 175 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); |
| 112 EXPECT_EQ(gfx::Rect(-57, -52, 130, 130), | 176 EXPECT_EQ(gfx::Rect(-57, -52, 130, 130), |
| 113 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); | 177 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 114 } | 178 } |
| 115 | 179 |
| 180 TEST(FilterOperationsTest, MapRectReverseDropShadow) { |
| 181 FilterOperations ops; |
| 182 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); |
| 183 EXPECT_EQ(gfx::Rect(-63, -68, 130, 130), |
| 184 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 185 } |
| 186 |
| 116 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \ | 187 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \ |
| 117 { \ | 188 { \ |
| 118 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \ | 189 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \ |
| 119 EXPECT_EQ(FilterOperation::filter_type, op.type()); \ | 190 EXPECT_EQ(FilterOperation::filter_type, op.type()); \ |
| 120 EXPECT_EQ(a, op.amount()); \ | 191 EXPECT_EQ(a, op.amount()); \ |
| 121 \ | 192 \ |
| 122 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \ | 193 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \ |
| 123 op2.set_type(FilterOperation::filter_type); \ | 194 op2.set_type(FilterOperation::filter_type); \ |
| 124 \ | 195 \ |
| 125 EXPECT_NE(a, op2.amount()); \ | 196 EXPECT_NE(a, op2.amount()); \ |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 blended = to.Blend(from, -0.75); | 842 blended = to.Blend(from, -0.75); |
| 772 EXPECT_EQ(to, blended); | 843 EXPECT_EQ(to, blended); |
| 773 blended = to.Blend(from, 0.75); | 844 blended = to.Blend(from, 0.75); |
| 774 EXPECT_EQ(to, blended); | 845 EXPECT_EQ(to, blended); |
| 775 blended = to.Blend(from, 1.5); | 846 blended = to.Blend(from, 1.5); |
| 776 EXPECT_EQ(to, blended); | 847 EXPECT_EQ(to, blended); |
| 777 } | 848 } |
| 778 | 849 |
| 779 } // namespace | 850 } // namespace |
| 780 } // namespace cc | 851 } // namespace cc |
| OLD | NEW |