| 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 12 matching lines...) Expand all Loading... |
| 23 ops.GetOutsets(&top, &right, &bottom, &left); | 23 ops.GetOutsets(&top, &right, &bottom, &left); |
| 24 EXPECT_EQ(57, top); | 24 EXPECT_EQ(57, top); |
| 25 EXPECT_EQ(57, right); | 25 EXPECT_EQ(57, right); |
| 26 EXPECT_EQ(57, bottom); | 26 EXPECT_EQ(57, bottom); |
| 27 EXPECT_EQ(57, left); | 27 EXPECT_EQ(57, 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(-57, -57, 124, 124), | 33 EXPECT_EQ(gfx::Rect(-60, -60, 130, 130), |
| 34 ops.MapRect(gfx::Rect(0, 0, 10, 10))); | 34 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 35 } | 35 } |
| 36 | 36 |
| 37 TEST(FilterOperationsTest, GetOutsetsDropShadowReferenceFilter) { | 37 TEST(FilterOperationsTest, GetOutsetsDropShadowReferenceFilter) { |
| 38 // TODO(hendrikw): We need to make outsets for reference filters be in line | 38 // TODO(hendrikw): We need to make outsets for reference filters be in line |
| 39 // with non-reference filters. See crbug.com/523534 | 39 // with non-reference filters. See crbug.com/523534 |
| 40 FilterOperations ops; | 40 FilterOperations ops; |
| 41 ops.Append( | 41 ops.Append( |
| 42 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make( | 42 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make( |
| 43 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), | 43 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), |
| 44 SkIntToScalar(9), SK_ColorBLACK, | 44 SkIntToScalar(9), SK_ColorBLACK, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 TEST(FilterOperationsTest, MapRectDropShadowReferenceFilter) { | 57 TEST(FilterOperationsTest, MapRectDropShadowReferenceFilter) { |
| 58 FilterOperations ops; | 58 FilterOperations ops; |
| 59 ops.Append( | 59 ops.Append( |
| 60 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make( | 60 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make( |
| 61 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), | 61 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), |
| 62 SkIntToScalar(9), SK_ColorBLACK, | 62 SkIntToScalar(9), SK_ColorBLACK, |
| 63 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, | 63 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, |
| 64 nullptr))); | 64 nullptr))); |
| 65 EXPECT_EQ(gfx::Rect(-9, -19, 34, 64), ops.MapRect(gfx::Rect(0, 0, 10, 10))); | 65 EXPECT_EQ(gfx::Rect(-9, -19, 34, 64), |
| 66 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 66 } | 67 } |
| 67 | 68 |
| 68 TEST(FilterOperationsTest, MapRectOffsetReferenceFilter) { | 69 TEST(FilterOperationsTest, MapRectOffsetReferenceFilter) { |
| 69 sk_sp<SkImageFilter> filter = SkOffsetImageFilter::Make(30, 40, nullptr); | 70 sk_sp<SkImageFilter> filter = SkOffsetImageFilter::Make(30, 40, nullptr); |
| 70 FilterOperations ops; | 71 FilterOperations ops; |
| 71 ops.Append(FilterOperation::CreateReferenceFilter(std::move(filter))); | 72 ops.Append(FilterOperation::CreateReferenceFilter(std::move(filter))); |
| 72 EXPECT_EQ(gfx::Rect(30, 40, 10, 10), ops.MapRect(gfx::Rect(0, 0, 10, 10))); | 73 EXPECT_EQ(gfx::Rect(30, 40, 10, 10), |
| 74 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 73 } | 75 } |
| 74 | 76 |
| 75 TEST(FilterOperationsTest, GetOutsetsNullReferenceFilter) { | 77 TEST(FilterOperationsTest, GetOutsetsNullReferenceFilter) { |
| 76 FilterOperations ops; | 78 FilterOperations ops; |
| 77 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); | 79 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); |
| 78 | 80 |
| 79 int top, right, bottom, left; | 81 int top, right, bottom, left; |
| 80 top = right = bottom = left = 0; | 82 top = right = bottom = left = 0; |
| 81 ops.GetOutsets(&top, &right, &bottom, &left); | 83 ops.GetOutsets(&top, &right, &bottom, &left); |
| 82 EXPECT_EQ(0, top); | 84 EXPECT_EQ(0, top); |
| 83 EXPECT_EQ(0, right); | 85 EXPECT_EQ(0, right); |
| 84 EXPECT_EQ(0, bottom); | 86 EXPECT_EQ(0, bottom); |
| 85 EXPECT_EQ(0, left); | 87 EXPECT_EQ(0, left); |
| 86 } | 88 } |
| 87 | 89 |
| 88 TEST(FilterOperationsTest, MapRectNullReferenceFilter) { | 90 TEST(FilterOperationsTest, MapRectNullReferenceFilter) { |
| 89 FilterOperations ops; | 91 FilterOperations ops; |
| 90 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); | 92 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); |
| 91 EXPECT_EQ(gfx::Rect(0, 0, 10, 10), ops.MapRect(gfx::Rect(0, 0, 10, 10))); | 93 EXPECT_EQ(gfx::Rect(0, 0, 10, 10), |
| 94 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 92 } | 95 } |
| 93 | 96 |
| 94 TEST(FilterOperationsTest, GetOutsetsDropShadow) { | 97 TEST(FilterOperationsTest, GetOutsetsDropShadow) { |
| 95 FilterOperations ops; | 98 FilterOperations ops; |
| 96 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); | 99 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); |
| 97 int top, right, bottom, left; | 100 int top, right, bottom, left; |
| 98 top = right = bottom = left = 0; | 101 top = right = bottom = left = 0; |
| 99 ops.GetOutsets(&top, &right, &bottom, &left); | 102 ops.GetOutsets(&top, &right, &bottom, &left); |
| 100 EXPECT_EQ(49, top); | 103 EXPECT_EQ(49, top); |
| 101 EXPECT_EQ(60, right); | 104 EXPECT_EQ(60, right); |
| 102 EXPECT_EQ(65, bottom); | 105 EXPECT_EQ(65, bottom); |
| 103 EXPECT_EQ(54, left); | 106 EXPECT_EQ(54, left); |
| 104 } | 107 } |
| 105 | 108 |
| 106 TEST(FilterOperationsTest, MapRectDropShadow) { | 109 TEST(FilterOperationsTest, MapRectDropShadow) { |
| 107 FilterOperations ops; | 110 FilterOperations ops; |
| 108 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); | 111 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); |
| 109 EXPECT_EQ(gfx::Rect(-54, -49, 124, 124), | 112 EXPECT_EQ(gfx::Rect(-57, -52, 130, 130), |
| 110 ops.MapRect(gfx::Rect(0, 0, 10, 10))); | 113 ops.MapRect(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); |
| 111 } | 114 } |
| 112 | 115 |
| 113 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \ | 116 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \ |
| 114 { \ | 117 { \ |
| 115 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \ | 118 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \ |
| 116 EXPECT_EQ(FilterOperation::filter_type, op.type()); \ | 119 EXPECT_EQ(FilterOperation::filter_type, op.type()); \ |
| 117 EXPECT_EQ(a, op.amount()); \ | 120 EXPECT_EQ(a, op.amount()); \ |
| 118 \ | 121 \ |
| 119 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \ | 122 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \ |
| 120 op2.set_type(FilterOperation::filter_type); \ | 123 op2.set_type(FilterOperation::filter_type); \ |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 blended = to.Blend(from, -0.75); | 771 blended = to.Blend(from, -0.75); |
| 769 EXPECT_EQ(to, blended); | 772 EXPECT_EQ(to, blended); |
| 770 blended = to.Blend(from, 0.75); | 773 blended = to.Blend(from, 0.75); |
| 771 EXPECT_EQ(to, blended); | 774 EXPECT_EQ(to, blended); |
| 772 blended = to.Blend(from, 1.5); | 775 blended = to.Blend(from, 1.5); |
| 773 EXPECT_EQ(to, blended); | 776 EXPECT_EQ(to, blended); |
| 774 } | 777 } |
| 775 | 778 |
| 776 } // namespace | 779 } // namespace |
| 777 } // namespace cc | 780 } // namespace cc |
| OLD | NEW |