| 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 |
| 77 TEST(FilterOperationsTest, GetOutsetsNullReferenceFilter) { | 104 TEST(FilterOperationsTest, GetOutsetsNullReferenceFilter) { |
| 78 FilterOperations ops; | 105 FilterOperations ops; |
| 79 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); | 106 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); |
| 80 | 107 |
| 81 int top, right, bottom, left; | 108 int top, right, bottom, left; |
| 82 top = right = bottom = left = 0; | 109 top = right = bottom = left = 0; |
| 83 ops.GetOutsets(&top, &right, &bottom, &left); | 110 ops.GetOutsets(&top, &right, &bottom, &left); |
| 84 EXPECT_EQ(0, top); | 111 EXPECT_EQ(0, top); |
| 85 EXPECT_EQ(0, right); | 112 EXPECT_EQ(0, right); |
| 86 EXPECT_EQ(0, bottom); | 113 EXPECT_EQ(0, bottom); |
| 87 EXPECT_EQ(0, left); | 114 EXPECT_EQ(0, left); |
| 88 } | 115 } |
| 89 | 116 |
| 90 TEST(FilterOperationsTest, MapRectNullReferenceFilter) { | 117 TEST(FilterOperationsTest, MapRectNullReferenceFilter) { |
| 91 FilterOperations ops; | 118 FilterOperations ops; |
| 92 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); | 119 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); |
| 93 EXPECT_EQ(gfx::Rect(0, 0, 10, 10), | 120 EXPECT_EQ(gfx::Rect(0, 0, 10, 10), |
| 94 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); | 121 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 95 } | 122 } |
| 96 | 123 |
| 124 TEST(FilterOperationsTest, MapRectReverseNullReferenceFilter) { |
| 125 FilterOperations ops; |
| 126 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); |
| 127 EXPECT_EQ(gfx::Rect(0, 0, 10, 10), |
| 128 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 129 } |
| 130 |
| 97 TEST(FilterOperationsTest, GetOutsetsDropShadow) { | 131 TEST(FilterOperationsTest, GetOutsetsDropShadow) { |
| 98 FilterOperations ops; | 132 FilterOperations ops; |
| 99 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); | 133 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); |
| 100 int top, right, bottom, left; | 134 int top, right, bottom, left; |
| 101 top = right = bottom = left = 0; | 135 top = right = bottom = left = 0; |
| 102 ops.GetOutsets(&top, &right, &bottom, &left); | 136 ops.GetOutsets(&top, &right, &bottom, &left); |
| 103 EXPECT_EQ(52, top); | 137 EXPECT_EQ(52, top); |
| 104 EXPECT_EQ(63, right); | 138 EXPECT_EQ(63, right); |
| 105 EXPECT_EQ(68, bottom); | 139 EXPECT_EQ(68, bottom); |
| 106 EXPECT_EQ(57, left); | 140 EXPECT_EQ(57, left); |
| 107 } | 141 } |
| 108 | 142 |
| 109 TEST(FilterOperationsTest, MapRectDropShadow) { | 143 TEST(FilterOperationsTest, MapRectDropShadow) { |
| 110 FilterOperations ops; | 144 FilterOperations ops; |
| 111 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); | 145 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); |
| 112 EXPECT_EQ(gfx::Rect(-57, -52, 130, 130), | 146 EXPECT_EQ(gfx::Rect(-57, -52, 130, 130), |
| 113 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); | 147 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 114 } | 148 } |
| 115 | 149 |
| 150 TEST(FilterOperationsTest, MapRectReverseDropShadow) { |
| 151 FilterOperations ops; |
| 152 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); |
| 153 EXPECT_EQ(gfx::Rect(-63, -68, 130, 130), |
| 154 ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 155 } |
| 156 |
| 116 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \ | 157 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \ |
| 117 { \ | 158 { \ |
| 118 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \ | 159 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \ |
| 119 EXPECT_EQ(FilterOperation::filter_type, op.type()); \ | 160 EXPECT_EQ(FilterOperation::filter_type, op.type()); \ |
| 120 EXPECT_EQ(a, op.amount()); \ | 161 EXPECT_EQ(a, op.amount()); \ |
| 121 \ | 162 \ |
| 122 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \ | 163 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \ |
| 123 op2.set_type(FilterOperation::filter_type); \ | 164 op2.set_type(FilterOperation::filter_type); \ |
| 124 \ | 165 \ |
| 125 EXPECT_NE(a, op2.amount()); \ | 166 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); | 812 blended = to.Blend(from, -0.75); |
| 772 EXPECT_EQ(to, blended); | 813 EXPECT_EQ(to, blended); |
| 773 blended = to.Blend(from, 0.75); | 814 blended = to.Blend(from, 0.75); |
| 774 EXPECT_EQ(to, blended); | 815 EXPECT_EQ(to, blended); |
| 775 blended = to.Blend(from, 1.5); | 816 blended = to.Blend(from, 1.5); |
| 776 EXPECT_EQ(to, blended); | 817 EXPECT_EQ(to, blended); |
| 777 } | 818 } |
| 778 | 819 |
| 779 } // namespace | 820 } // namespace |
| 780 } // namespace cc | 821 } // namespace cc |
| OLD | NEW |