Chromium Code Reviews| 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 "ui/gfx/geometry/point.h" | 12 #include "ui/gfx/geometry/point.h" |
| 13 #include "ui/gfx/geometry/rect.h" | |
| 13 | 14 |
| 14 namespace cc { | 15 namespace cc { |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 TEST(FilterOperationsTest, GetOutsetsBlur) { | 18 TEST(FilterOperationsTest, GetOutsetsBlur) { |
| 18 FilterOperations ops; | 19 FilterOperations ops; |
| 19 ops.Append(FilterOperation::CreateBlurFilter(20)); | 20 ops.Append(FilterOperation::CreateBlurFilter(20)); |
| 20 int top, right, bottom, left; | 21 int top, right, bottom, left; |
| 21 top = right = bottom = left = 0; | 22 top = right = bottom = left = 0; |
| 22 ops.GetOutsets(&top, &right, &bottom, &left); | 23 ops.GetOutsets(&top, &right, &bottom, &left); |
| 23 EXPECT_EQ(57, top); | 24 EXPECT_EQ(57, top); |
| 24 EXPECT_EQ(57, right); | 25 EXPECT_EQ(57, right); |
| 25 EXPECT_EQ(57, bottom); | 26 EXPECT_EQ(57, bottom); |
| 26 EXPECT_EQ(57, left); | 27 EXPECT_EQ(57, left); |
| 27 } | 28 } |
| 28 | 29 |
| 30 TEST(FilterOperationsTest, MapRectBlur) { | |
| 31 FilterOperations ops; | |
| 32 ops.Append(FilterOperation::CreateBlurFilter(20)); | |
| 33 EXPECT_EQ(gfx::Rect(-57, -57, 124, 124), | |
| 34 ops.MapRect(gfx::Rect(0, 0, 10, 10))); | |
| 35 } | |
| 36 | |
| 29 TEST(FilterOperationsTest, GetOutsetsDropShadowReferenceFilter) { | 37 TEST(FilterOperationsTest, GetOutsetsDropShadowReferenceFilter) { |
| 30 // 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 |
| 31 // with non-reference filters. See crbug.com/523534 | 39 // with non-reference filters. See crbug.com/523534 |
| 32 skia::RefPtr<SkImageFilter> filter = | 40 skia::RefPtr<SkImageFilter> filter = |
| 33 skia::AdoptRef(SkDropShadowImageFilter::Create( | 41 skia::AdoptRef(SkDropShadowImageFilter::Create( |
| 34 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), | 42 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), |
| 35 SkIntToScalar(9), SK_ColorBLACK, | 43 SkIntToScalar(9), SK_ColorBLACK, |
| 36 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode)); | 44 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode)); |
| 37 FilterOperations ops; | 45 FilterOperations ops; |
| 38 ops.Append(FilterOperation::CreateReferenceFilter(filter)); | 46 ops.Append(FilterOperation::CreateReferenceFilter(filter)); |
| 39 | 47 |
| 40 int top, right, bottom, left; | 48 int top, right, bottom, left; |
| 41 top = right = bottom = left = 0; | 49 top = right = bottom = left = 0; |
| 42 ops.GetOutsets(&top, &right, &bottom, &left); | 50 ops.GetOutsets(&top, &right, &bottom, &left); |
| 43 EXPECT_EQ(35, top); | 51 EXPECT_EQ(35, top); |
| 44 EXPECT_EQ(9, right); | 52 EXPECT_EQ(9, right); |
| 45 EXPECT_EQ(19, bottom); | 53 EXPECT_EQ(19, bottom); |
| 46 EXPECT_EQ(15, left); | 54 EXPECT_EQ(15, left); |
| 47 } | 55 } |
| 48 | 56 |
| 57 TEST(FilterOperationsTest, MapRectDropShadowReferenceFilter) { | |
| 58 // TODO(hendrikw): We need to make outsets for reference filters be in line | |
|
Stephen White
2016/04/11 18:05:00
Is this comment still valid? If not, remove it.
jbroman
2016/04/11 20:21:52
I'm not entirely clear on what it means, so I figu
Stephen White
2016/04/11 20:56:04
The referenced bug is basically what you're doing
jbroman
2016/04/12 19:32:36
Done.
| |
| 59 // with non-reference filters. See crbug.com/523534 | |
| 60 skia::RefPtr<SkImageFilter> filter = | |
| 61 skia::AdoptRef(SkDropShadowImageFilter::Create( | |
| 62 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), | |
| 63 SkIntToScalar(9), SK_ColorBLACK, | |
| 64 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode)); | |
| 65 FilterOperations ops; | |
| 66 ops.Append(FilterOperation::CreateReferenceFilter(filter)); | |
| 67 EXPECT_EQ(gfx::Rect(-15, -35, 34, 64), ops.MapRect(gfx::Rect(0, 0, 10, 10))); | |
|
Stephen White
2016/04/11 18:05:00
This does look like a reverse mapping. Maybe the c
jbroman
2016/04/11 20:21:52
These expectations were taken from GetOutsets (wit
Stephen White
2016/04/11 20:56:04
Yeah, I think there is/was a bug in GetOutsets().
jbroman
2016/04/12 19:32:37
Acknowledged.
| |
| 68 } | |
| 69 | |
| 49 TEST(FilterOperationsTest, GetOutsetsNullReferenceFilter) { | 70 TEST(FilterOperationsTest, GetOutsetsNullReferenceFilter) { |
| 50 FilterOperations ops; | 71 FilterOperations ops; |
| 51 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); | 72 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); |
| 52 | 73 |
| 53 int top, right, bottom, left; | 74 int top, right, bottom, left; |
| 54 top = right = bottom = left = 0; | 75 top = right = bottom = left = 0; |
| 55 ops.GetOutsets(&top, &right, &bottom, &left); | 76 ops.GetOutsets(&top, &right, &bottom, &left); |
| 56 EXPECT_EQ(0, top); | 77 EXPECT_EQ(0, top); |
| 57 EXPECT_EQ(0, right); | 78 EXPECT_EQ(0, right); |
| 58 EXPECT_EQ(0, bottom); | 79 EXPECT_EQ(0, bottom); |
| 59 EXPECT_EQ(0, left); | 80 EXPECT_EQ(0, left); |
| 60 } | 81 } |
| 61 | 82 |
| 83 TEST(FilterOperationsTest, MapRectNullReferenceFilter) { | |
| 84 FilterOperations ops; | |
| 85 ops.Append(FilterOperation::CreateReferenceFilter(nullptr)); | |
| 86 EXPECT_EQ(gfx::Rect(0, 0, 10, 10), ops.MapRect(gfx::Rect(0, 0, 10, 10))); | |
|
Stephen White
2016/04/11 18:05:00
Could you add a test for a non-null Reference filt
jbroman
2016/04/11 20:21:52
Is the drop shadow reference filter (above) insuff
Stephen White
2016/04/11 20:56:04
The advantage of SkOffsetImageFilter is that it do
jbroman
2016/04/12 19:32:36
Done.
| |
| 87 } | |
| 88 | |
| 62 TEST(FilterOperationsTest, GetOutsetsDropShadow) { | 89 TEST(FilterOperationsTest, GetOutsetsDropShadow) { |
| 63 FilterOperations ops; | 90 FilterOperations ops; |
| 64 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); | 91 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); |
| 65 int top, right, bottom, left; | 92 int top, right, bottom, left; |
| 66 top = right = bottom = left = 0; | 93 top = right = bottom = left = 0; |
| 67 ops.GetOutsets(&top, &right, &bottom, &left); | 94 ops.GetOutsets(&top, &right, &bottom, &left); |
| 68 EXPECT_EQ(49, top); | 95 EXPECT_EQ(49, top); |
| 69 EXPECT_EQ(60, right); | 96 EXPECT_EQ(60, right); |
| 70 EXPECT_EQ(65, bottom); | 97 EXPECT_EQ(65, bottom); |
| 71 EXPECT_EQ(54, left); | 98 EXPECT_EQ(54, left); |
| 72 } | 99 } |
| 73 | 100 |
| 101 TEST(FilterOperationsTest, MapRectDropShadow) { | |
| 102 FilterOperations ops; | |
| 103 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0)); | |
| 104 EXPECT_EQ(gfx::Rect(-54, -49, 124, 124), | |
| 105 ops.MapRect(gfx::Rect(0, 0, 10, 10))); | |
| 106 } | |
| 107 | |
| 74 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \ | 108 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \ |
| 75 { \ | 109 { \ |
| 76 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \ | 110 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \ |
| 77 EXPECT_EQ(FilterOperation::filter_type, op.type()); \ | 111 EXPECT_EQ(FilterOperation::filter_type, op.type()); \ |
| 78 EXPECT_EQ(a, op.amount()); \ | 112 EXPECT_EQ(a, op.amount()); \ |
| 79 \ | 113 \ |
| 80 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \ | 114 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \ |
| 81 op2.set_type(FilterOperation::filter_type); \ | 115 op2.set_type(FilterOperation::filter_type); \ |
| 82 \ | 116 \ |
| 83 EXPECT_NE(a, op2.amount()); \ | 117 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); | 764 blended = to.Blend(from, -0.75); |
| 731 EXPECT_EQ(to, blended); | 765 EXPECT_EQ(to, blended); |
| 732 blended = to.Blend(from, 0.75); | 766 blended = to.Blend(from, 0.75); |
| 733 EXPECT_EQ(to, blended); | 767 EXPECT_EQ(to, blended); |
| 734 blended = to.Blend(from, 1.5); | 768 blended = to.Blend(from, 1.5); |
| 735 EXPECT_EQ(to, blended); | 769 EXPECT_EQ(to, blended); |
| 736 } | 770 } |
| 737 | 771 |
| 738 } // namespace | 772 } // namespace |
| 739 } // namespace cc | 773 } // namespace cc |
| OLD | NEW |