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/quads/render_pass.h" | 5 #include "cc/quads/render_pass.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
11 #include "cc/output/copy_output_request.h" | 11 #include "cc/output/copy_output_request.h" |
12 #include "cc/quads/render_pass_draw_quad.h" | 12 #include "cc/quads/render_pass_draw_quad.h" |
13 #include "cc/quads/solid_color_draw_quad.h" | 13 #include "cc/quads/solid_color_draw_quad.h" |
14 #include "cc/test/geometry_test_utils.h" | 14 #include "cc/test/geometry_test_utils.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 16 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
17 #include "ui/gfx/transform.h" | 17 #include "ui/gfx/transform.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 namespace { | 20 namespace { |
21 | 21 |
22 struct RenderPassSize { | 22 struct RenderPassSize { |
23 // If you add a new field to this class, make sure to add it to the | 23 // If you add a new field to this class, make sure to add it to the |
24 // Copy() tests. | 24 // Copy() tests. |
25 int id; | 25 int id; |
| 26 gfx::Rect output_rect; |
| 27 gfx::Rect damage_rect; |
| 28 gfx::Transform transform_to_root_target; |
| 29 FilterOperations filters; |
| 30 FilterOperations background_filters; |
| 31 bool has_transparent_background; |
| 32 std::vector<std::unique_ptr<CopyOutputRequest>> copy_callbacks; |
26 QuadList quad_list; | 33 QuadList quad_list; |
27 SharedQuadStateList shared_quad_state_list; | 34 SharedQuadStateList shared_quad_state_list; |
28 gfx::Transform transform_to_root_target; | |
29 gfx::Rect output_rect; | |
30 gfx::Rect damage_rect; | |
31 bool has_transparent_background; | |
32 std::vector<std::unique_ptr<CopyOutputRequest>> copy_callbacks; | |
33 }; | 35 }; |
34 | 36 |
35 static void CompareRenderPassLists(const RenderPassList& expected_list, | 37 static void CompareRenderPassLists(const RenderPassList& expected_list, |
36 const RenderPassList& actual_list) { | 38 const RenderPassList& actual_list) { |
37 EXPECT_EQ(expected_list.size(), actual_list.size()); | 39 EXPECT_EQ(expected_list.size(), actual_list.size()); |
38 for (size_t i = 0; i < actual_list.size(); ++i) { | 40 for (size_t i = 0; i < actual_list.size(); ++i) { |
39 RenderPass* expected = expected_list[i].get(); | 41 RenderPass* expected = expected_list[i].get(); |
40 RenderPass* actual = actual_list[i].get(); | 42 RenderPass* actual = actual_list[i].get(); |
41 | 43 |
42 EXPECT_EQ(expected->id, actual->id); | 44 EXPECT_EQ(expected->id, actual->id); |
43 EXPECT_EQ(expected->output_rect, actual->output_rect); | 45 EXPECT_EQ(expected->output_rect, actual->output_rect); |
44 EXPECT_EQ(expected->transform_to_root_target, | 46 EXPECT_EQ(expected->transform_to_root_target, |
45 actual->transform_to_root_target); | 47 actual->transform_to_root_target); |
46 EXPECT_EQ(expected->damage_rect, actual->damage_rect); | 48 EXPECT_EQ(expected->damage_rect, actual->damage_rect); |
| 49 EXPECT_EQ(expected->filters, actual->filters); |
| 50 EXPECT_EQ(expected->background_filters, expected->background_filters); |
47 EXPECT_EQ(expected->has_transparent_background, | 51 EXPECT_EQ(expected->has_transparent_background, |
48 actual->has_transparent_background); | 52 actual->has_transparent_background); |
49 | 53 |
50 EXPECT_EQ(expected->shared_quad_state_list.size(), | 54 EXPECT_EQ(expected->shared_quad_state_list.size(), |
51 actual->shared_quad_state_list.size()); | 55 actual->shared_quad_state_list.size()); |
52 EXPECT_EQ(expected->quad_list.size(), actual->quad_list.size()); | 56 EXPECT_EQ(expected->quad_list.size(), actual->quad_list.size()); |
53 | 57 |
54 for (auto exp_iter = expected->quad_list.cbegin(), | 58 for (auto exp_iter = expected->quad_list.cbegin(), |
55 act_iter = actual->quad_list.cbegin(); | 59 act_iter = actual->quad_list.cbegin(); |
56 exp_iter != expected->quad_list.cend(); | 60 exp_iter != expected->quad_list.cend(); |
57 ++exp_iter, ++act_iter) { | 61 ++exp_iter, ++act_iter) { |
58 EXPECT_EQ(exp_iter->rect.ToString(), act_iter->rect.ToString()); | 62 EXPECT_EQ(exp_iter->rect.ToString(), act_iter->rect.ToString()); |
59 EXPECT_EQ(exp_iter->shared_quad_state->quad_layer_bounds.ToString(), | 63 EXPECT_EQ(exp_iter->shared_quad_state->quad_layer_bounds.ToString(), |
60 act_iter->shared_quad_state->quad_layer_bounds.ToString()); | 64 act_iter->shared_quad_state->quad_layer_bounds.ToString()); |
61 } | 65 } |
62 } | 66 } |
63 } | 67 } |
64 | 68 |
65 TEST(RenderPassTest, CopyShouldBeIdenticalExceptIdAndQuads) { | 69 TEST(RenderPassTest, CopyShouldBeIdenticalExceptIdAndQuads) { |
66 int id = 3; | 70 int id = 3; |
67 gfx::Rect output_rect(45, 22, 120, 13); | 71 gfx::Rect output_rect(45, 22, 120, 13); |
68 gfx::Transform transform_to_root = | 72 gfx::Transform transform_to_root = |
69 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); | 73 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); |
70 gfx::Rect damage_rect(56, 123, 19, 43); | 74 gfx::Rect damage_rect(56, 123, 19, 43); |
| 75 FilterOperations filters; |
| 76 filters.Append(FilterOperation::CreateOpacityFilter(0.5)); |
| 77 FilterOperations background_filters; |
| 78 background_filters.Append(FilterOperation::CreateInvertFilter(1.0)); |
71 bool has_transparent_background = true; | 79 bool has_transparent_background = true; |
72 | 80 |
73 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 81 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
74 pass->SetAll(id, | 82 pass->SetAll(id, output_rect, damage_rect, transform_to_root, filters, |
75 output_rect, | 83 background_filters, has_transparent_background); |
76 damage_rect, | |
77 transform_to_root, | |
78 has_transparent_background); | |
79 pass->copy_requests.push_back(CopyOutputRequest::CreateEmptyRequest()); | 84 pass->copy_requests.push_back(CopyOutputRequest::CreateEmptyRequest()); |
80 | 85 |
81 // Stick a quad in the pass, this should not get copied. | 86 // Stick a quad in the pass, this should not get copied. |
82 SharedQuadState* shared_state = pass->CreateAndAppendSharedQuadState(); | 87 SharedQuadState* shared_state = pass->CreateAndAppendSharedQuadState(); |
83 shared_state->SetAll(gfx::Transform(), gfx::Size(), gfx::Rect(), gfx::Rect(), | 88 shared_state->SetAll(gfx::Transform(), gfx::Size(), gfx::Rect(), gfx::Rect(), |
84 false, 1, SkBlendMode::kSrcOver, 0); | 89 false, 1, SkBlendMode::kSrcOver, 0); |
85 | 90 |
86 SolidColorDrawQuad* color_quad = | 91 SolidColorDrawQuad* color_quad = |
87 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | 92 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
88 color_quad->SetNew(pass->shared_quad_state_list.back(), gfx::Rect(), | 93 color_quad->SetNew(pass->shared_quad_state_list.back(), gfx::Rect(), |
89 gfx::Rect(), SkColor(), false); | 94 gfx::Rect(), SkColor(), false); |
90 | 95 |
91 int new_id = 63; | 96 int new_id = 63; |
92 | 97 |
93 std::unique_ptr<RenderPass> copy = pass->Copy(new_id); | 98 std::unique_ptr<RenderPass> copy = pass->Copy(new_id); |
94 EXPECT_EQ(new_id, copy->id); | 99 EXPECT_EQ(new_id, copy->id); |
95 EXPECT_EQ(pass->output_rect, copy->output_rect); | 100 EXPECT_EQ(pass->output_rect, copy->output_rect); |
96 EXPECT_EQ(pass->transform_to_root_target, copy->transform_to_root_target); | 101 EXPECT_EQ(pass->transform_to_root_target, copy->transform_to_root_target); |
97 EXPECT_EQ(pass->damage_rect, copy->damage_rect); | 102 EXPECT_EQ(pass->damage_rect, copy->damage_rect); |
| 103 EXPECT_EQ(pass->filters, copy->filters); |
| 104 EXPECT_EQ(pass->background_filters, copy->background_filters); |
98 EXPECT_EQ(pass->has_transparent_background, copy->has_transparent_background); | 105 EXPECT_EQ(pass->has_transparent_background, copy->has_transparent_background); |
99 EXPECT_EQ(0u, copy->quad_list.size()); | 106 EXPECT_EQ(0u, copy->quad_list.size()); |
100 | 107 |
101 // The copy request should not be copied/duplicated. | 108 // The copy request should not be copied/duplicated. |
102 EXPECT_EQ(1u, pass->copy_requests.size()); | 109 EXPECT_EQ(1u, pass->copy_requests.size()); |
103 EXPECT_EQ(0u, copy->copy_requests.size()); | 110 EXPECT_EQ(0u, copy->copy_requests.size()); |
104 | 111 |
105 EXPECT_EQ(sizeof(RenderPassSize), sizeof(RenderPass)); | 112 EXPECT_EQ(sizeof(RenderPassSize), sizeof(RenderPass)); |
106 } | 113 } |
107 | 114 |
108 TEST(RenderPassTest, CopyAllShouldBeIdentical) { | 115 TEST(RenderPassTest, CopyAllShouldBeIdentical) { |
109 RenderPassList pass_list; | 116 RenderPassList pass_list; |
110 | 117 |
111 int id = 3; | 118 int id = 3; |
112 gfx::Rect output_rect(45, 22, 120, 13); | 119 gfx::Rect output_rect(45, 22, 120, 13); |
113 gfx::Transform transform_to_root = | 120 gfx::Transform transform_to_root = |
114 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); | 121 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); |
115 gfx::Rect damage_rect(56, 123, 19, 43); | 122 gfx::Rect damage_rect(56, 123, 19, 43); |
| 123 FilterOperations filters; |
| 124 filters.Append(FilterOperation::CreateOpacityFilter(0.5)); |
| 125 FilterOperations background_filters; |
| 126 background_filters.Append(FilterOperation::CreateInvertFilter(1.0)); |
116 bool has_transparent_background = true; | 127 bool has_transparent_background = true; |
117 | 128 |
118 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 129 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
119 pass->SetAll(id, | 130 pass->SetAll(id, output_rect, damage_rect, transform_to_root, filters, |
120 output_rect, | 131 background_filters, has_transparent_background); |
121 damage_rect, | |
122 transform_to_root, | |
123 has_transparent_background); | |
124 | 132 |
125 // Two quads using one shared state. | 133 // Two quads using one shared state. |
126 SharedQuadState* shared_state1 = pass->CreateAndAppendSharedQuadState(); | 134 SharedQuadState* shared_state1 = pass->CreateAndAppendSharedQuadState(); |
127 shared_state1->SetAll(gfx::Transform(), gfx::Size(1, 1), gfx::Rect(), | 135 shared_state1->SetAll(gfx::Transform(), gfx::Size(1, 1), gfx::Rect(), |
128 gfx::Rect(), false, 1, SkBlendMode::kSrcOver, 0); | 136 gfx::Rect(), false, 1, SkBlendMode::kSrcOver, 0); |
129 | 137 |
130 SolidColorDrawQuad* color_quad1 = | 138 SolidColorDrawQuad* color_quad1 = |
131 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | 139 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
132 color_quad1->SetNew(pass->shared_quad_state_list.back(), | 140 color_quad1->SetNew(pass->shared_quad_state_list.back(), |
133 gfx::Rect(1, 1, 1, 1), gfx::Rect(1, 1, 1, 1), SkColor(), | 141 gfx::Rect(1, 1, 1, 1), gfx::Rect(1, 1, 1, 1), SkColor(), |
(...skipping 21 matching lines...) Expand all Loading... |
155 color_quad4->SetNew(pass->shared_quad_state_list.back(), | 163 color_quad4->SetNew(pass->shared_quad_state_list.back(), |
156 gfx::Rect(4, 4, 4, 4), gfx::Rect(4, 4, 4, 4), SkColor(), | 164 gfx::Rect(4, 4, 4, 4), gfx::Rect(4, 4, 4, 4), SkColor(), |
157 false); | 165 false); |
158 | 166 |
159 // A second render pass with a quad. | 167 // A second render pass with a quad. |
160 int contrib_id = 4; | 168 int contrib_id = 4; |
161 gfx::Rect contrib_output_rect(10, 15, 12, 17); | 169 gfx::Rect contrib_output_rect(10, 15, 12, 17); |
162 gfx::Transform contrib_transform_to_root = | 170 gfx::Transform contrib_transform_to_root = |
163 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); | 171 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); |
164 gfx::Rect contrib_damage_rect(11, 16, 10, 15); | 172 gfx::Rect contrib_damage_rect(11, 16, 10, 15); |
| 173 FilterOperations contrib_filters; |
| 174 contrib_filters.Append(FilterOperation::CreateSepiaFilter(0.5)); |
| 175 FilterOperations contrib_background_filters; |
| 176 contrib_background_filters.Append(FilterOperation::CreateSaturateFilter(1)); |
165 bool contrib_has_transparent_background = true; | 177 bool contrib_has_transparent_background = true; |
166 | 178 |
167 std::unique_ptr<RenderPass> contrib = RenderPass::Create(); | 179 std::unique_ptr<RenderPass> contrib = RenderPass::Create(); |
168 contrib->SetAll(contrib_id, | 180 contrib->SetAll(contrib_id, contrib_output_rect, contrib_damage_rect, |
169 contrib_output_rect, | 181 contrib_transform_to_root, contrib_filters, |
170 contrib_damage_rect, | 182 contrib_background_filters, |
171 contrib_transform_to_root, | |
172 contrib_has_transparent_background); | 183 contrib_has_transparent_background); |
173 | 184 |
174 SharedQuadState* contrib_shared_state = | 185 SharedQuadState* contrib_shared_state = |
175 contrib->CreateAndAppendSharedQuadState(); | 186 contrib->CreateAndAppendSharedQuadState(); |
176 contrib_shared_state->SetAll(gfx::Transform(), gfx::Size(2, 2), gfx::Rect(), | 187 contrib_shared_state->SetAll(gfx::Transform(), gfx::Size(2, 2), gfx::Rect(), |
177 gfx::Rect(), false, 1, SkBlendMode::kSrcOver, 0); | 188 gfx::Rect(), false, 1, SkBlendMode::kSrcOver, 0); |
178 | 189 |
179 SolidColorDrawQuad* contrib_quad = | 190 SolidColorDrawQuad* contrib_quad = |
180 contrib->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | 191 contrib->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
181 contrib_quad->SetNew(contrib->shared_quad_state_list.back(), | 192 contrib_quad->SetNew(contrib->shared_quad_state_list.back(), |
182 gfx::Rect(3, 3, 3, 3), gfx::Rect(3, 3, 3, 3), SkColor(), | 193 gfx::Rect(3, 3, 3, 3), gfx::Rect(3, 3, 3, 3), SkColor(), |
183 false); | 194 false); |
184 | 195 |
185 // And a RenderPassDrawQuad for the contributing pass. | 196 // And a RenderPassDrawQuad for the contributing pass. |
186 std::unique_ptr<RenderPassDrawQuad> pass_quad = | 197 std::unique_ptr<RenderPassDrawQuad> pass_quad = |
187 base::WrapUnique(new RenderPassDrawQuad); | 198 base::WrapUnique(new RenderPassDrawQuad); |
188 pass_quad->SetNew(pass->shared_quad_state_list.back(), contrib_output_rect, | 199 pass_quad->SetNew(pass->shared_quad_state_list.back(), contrib_output_rect, |
189 contrib_output_rect, contrib_id, 0, gfx::Vector2dF(), | 200 contrib_output_rect, contrib_id, 0, gfx::Vector2dF(), |
190 gfx::Size(), FilterOperations(), gfx::Vector2dF(), | 201 gfx::Size(), gfx::Vector2dF(), gfx::PointF()); |
191 gfx::PointF(), FilterOperations()); | |
192 | 202 |
193 pass_list.push_back(std::move(pass)); | 203 pass_list.push_back(std::move(pass)); |
194 pass_list.push_back(std::move(contrib)); | 204 pass_list.push_back(std::move(contrib)); |
195 | 205 |
196 // Make a copy with CopyAll(). | 206 // Make a copy with CopyAll(). |
197 RenderPassList copy_list; | 207 RenderPassList copy_list; |
198 RenderPass::CopyAll(pass_list, ©_list); | 208 RenderPass::CopyAll(pass_list, ©_list); |
199 | 209 |
200 CompareRenderPassLists(pass_list, copy_list); | 210 CompareRenderPassLists(pass_list, copy_list); |
201 } | 211 } |
202 | 212 |
203 TEST(RenderPassTest, CopyAllWithCulledQuads) { | 213 TEST(RenderPassTest, CopyAllWithCulledQuads) { |
204 RenderPassList pass_list; | 214 RenderPassList pass_list; |
205 | 215 |
206 int id = 3; | 216 int id = 3; |
207 gfx::Rect output_rect(45, 22, 120, 13); | 217 gfx::Rect output_rect(45, 22, 120, 13); |
208 gfx::Transform transform_to_root = | 218 gfx::Transform transform_to_root = |
209 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); | 219 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); |
210 gfx::Rect damage_rect(56, 123, 19, 43); | 220 gfx::Rect damage_rect(56, 123, 19, 43); |
| 221 FilterOperations filters; |
| 222 filters.Append(FilterOperation::CreateOpacityFilter(0.5)); |
| 223 FilterOperations background_filters; |
| 224 background_filters.Append(FilterOperation::CreateInvertFilter(1.0)); |
211 bool has_transparent_background = true; | 225 bool has_transparent_background = true; |
212 | 226 |
213 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 227 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
214 pass->SetAll(id, | 228 pass->SetAll(id, output_rect, damage_rect, transform_to_root, filters, |
215 output_rect, | 229 background_filters, has_transparent_background); |
216 damage_rect, | |
217 transform_to_root, | |
218 has_transparent_background); | |
219 | 230 |
220 // A shared state with a quad. | 231 // A shared state with a quad. |
221 SharedQuadState* shared_state1 = pass->CreateAndAppendSharedQuadState(); | 232 SharedQuadState* shared_state1 = pass->CreateAndAppendSharedQuadState(); |
222 shared_state1->SetAll(gfx::Transform(), gfx::Size(1, 1), gfx::Rect(), | 233 shared_state1->SetAll(gfx::Transform(), gfx::Size(1, 1), gfx::Rect(), |
223 gfx::Rect(), false, 1, SkBlendMode::kSrcOver, 0); | 234 gfx::Rect(), false, 1, SkBlendMode::kSrcOver, 0); |
224 | 235 |
225 SolidColorDrawQuad* color_quad1 = | 236 SolidColorDrawQuad* color_quad1 = |
226 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | 237 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
227 color_quad1->SetNew(pass->shared_quad_state_list.back(), | 238 color_quad1->SetNew(pass->shared_quad_state_list.back(), |
228 gfx::Rect(1, 1, 1, 1), gfx::Rect(1, 1, 1, 1), SkColor(), | 239 gfx::Rect(1, 1, 1, 1), gfx::Rect(1, 1, 1, 1), SkColor(), |
(...skipping 24 matching lines...) Expand all Loading... |
253 | 264 |
254 // Make a copy with CopyAll(). | 265 // Make a copy with CopyAll(). |
255 RenderPassList copy_list; | 266 RenderPassList copy_list; |
256 RenderPass::CopyAll(pass_list, ©_list); | 267 RenderPass::CopyAll(pass_list, ©_list); |
257 | 268 |
258 CompareRenderPassLists(pass_list, copy_list); | 269 CompareRenderPassLists(pass_list, copy_list); |
259 } | 270 } |
260 | 271 |
261 } // namespace | 272 } // namespace |
262 } // namespace cc | 273 } // namespace cc |
OLD | NEW |