OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "cc/render_surface_filters.h" | 5 #include "cc/render_surface_filters.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperation.
h" | 8 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperation.
h" |
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations
.h" | 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations
.h" |
10 | 10 |
11 using namespace WebKit; | 11 using namespace WebKit; |
12 | 12 |
13 namespace cc { | 13 namespace cc { |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Checks whether op can be combined with a following color matrix. | 16 // Checks whether op can be combined with a following color matrix. |
17 bool isCombined(const WebFilterOperation& op) | 17 bool isCombined(const WebFilterOperation& op) |
18 { | 18 { |
19 WebFilterOperations filters; | 19 WebFilterOperations filters; |
20 filters.append(op); | 20 filters.append(op); |
21 filters.append(WebFilterOperation::createBrightnessFilter(0)); // brightness
(0) is identity. | 21 filters.append(WebFilterOperation::createBrightnessFilter(0)); // brightness
(0) is identity. |
22 WebFilterOperations optimized = RenderSurfaceFilters::optimize(filters); | 22 WebFilterOperations optimized = RenderSurfaceFilters::Optimize(filters); |
23 return optimized.size() == 1; | 23 return optimized.size() == 1; |
24 } | 24 } |
25 | 25 |
26 TEST(RenderSurfaceFiltersTest, testColorMatrixFiltersCombined) | 26 TEST(RenderSurfaceFiltersTest, testColorMatrixFiltersCombined) |
27 { | 27 { |
28 // Several filters should always combine for any amount between 0 and 1: | 28 // Several filters should always combine for any amount between 0 and 1: |
29 // grayscale, saturate, invert, contrast, opacity. | 29 // grayscale, saturate, invert, contrast, opacity. |
30 EXPECT_TRUE(isCombined(WebFilterOperation::createGrayscaleFilter(0))); | 30 EXPECT_TRUE(isCombined(WebFilterOperation::createGrayscaleFilter(0))); |
31 // Note that we use 0.3f to avoid "argument is truncated from 'double' to | 31 // Note that we use 0.3f to avoid "argument is truncated from 'double' to |
32 // 'float'" warnings on Windows. 0.5 is exactly representable as a float, so | 32 // 'float'" warnings on Windows. 0.5 is exactly representable as a float, so |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 }; | 107 }; |
108 EXPECT_TRUE(isCombined(WebFilterOperation::createColorMatrixFilter(matrix4))
); | 108 EXPECT_TRUE(isCombined(WebFilterOperation::createColorMatrixFilter(matrix4))
); |
109 } | 109 } |
110 | 110 |
111 TEST(RenderSurfaceFiltersTest, testOptimize) | 111 TEST(RenderSurfaceFiltersTest, testOptimize) |
112 { | 112 { |
113 WebFilterOperation combines(WebFilterOperation::createBrightnessFilter(1)); | 113 WebFilterOperation combines(WebFilterOperation::createBrightnessFilter(1)); |
114 WebFilterOperation doesntCombine(WebFilterOperation::createBrightnessFilter(
1.5)); | 114 WebFilterOperation doesntCombine(WebFilterOperation::createBrightnessFilter(
1.5)); |
115 | 115 |
116 WebFilterOperations filters; | 116 WebFilterOperations filters; |
117 WebFilterOperations optimized = RenderSurfaceFilters::optimize(filters); | 117 WebFilterOperations optimized = RenderSurfaceFilters::Optimize(filters); |
118 EXPECT_EQ(0u, optimized.size()); | 118 EXPECT_EQ(0u, optimized.size()); |
119 | 119 |
120 filters.append(combines); | 120 filters.append(combines); |
121 optimized = RenderSurfaceFilters::optimize(filters); | 121 optimized = RenderSurfaceFilters::Optimize(filters); |
122 EXPECT_EQ(1u, optimized.size()); | 122 EXPECT_EQ(1u, optimized.size()); |
123 | 123 |
124 filters.append(combines); | 124 filters.append(combines); |
125 optimized = RenderSurfaceFilters::optimize(filters); | 125 optimized = RenderSurfaceFilters::Optimize(filters); |
126 EXPECT_EQ(1u, optimized.size()); | 126 EXPECT_EQ(1u, optimized.size()); |
127 | 127 |
128 filters.append(doesntCombine); | 128 filters.append(doesntCombine); |
129 optimized = RenderSurfaceFilters::optimize(filters); | 129 optimized = RenderSurfaceFilters::Optimize(filters); |
130 EXPECT_EQ(1u, optimized.size()); | 130 EXPECT_EQ(1u, optimized.size()); |
131 | 131 |
132 filters.append(combines); | 132 filters.append(combines); |
133 optimized = RenderSurfaceFilters::optimize(filters); | 133 optimized = RenderSurfaceFilters::Optimize(filters); |
134 EXPECT_EQ(2u, optimized.size()); | 134 EXPECT_EQ(2u, optimized.size()); |
135 | 135 |
136 filters.append(doesntCombine); | 136 filters.append(doesntCombine); |
137 optimized = RenderSurfaceFilters::optimize(filters); | 137 optimized = RenderSurfaceFilters::Optimize(filters); |
138 EXPECT_EQ(2u, optimized.size()); | 138 EXPECT_EQ(2u, optimized.size()); |
139 | 139 |
140 filters.append(doesntCombine); | 140 filters.append(doesntCombine); |
141 optimized = RenderSurfaceFilters::optimize(filters); | 141 optimized = RenderSurfaceFilters::Optimize(filters); |
142 EXPECT_EQ(3u, optimized.size()); | 142 EXPECT_EQ(3u, optimized.size()); |
143 } | 143 } |
144 | 144 |
145 } // namespace | 145 } // namespace |
146 } // namespace cc | 146 } // namespace cc |
OLD | NEW |