OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/output/compositor_frame.h" | 5 #include "cc/output/compositor_frame.h" |
6 #include "cc/quads/render_pass.h" | 6 #include "cc/quads/render_pass.h" |
7 #include "cc/quads/solid_color_draw_quad.h" | 7 #include "cc/quads/solid_color_draw_quad.h" |
8 #include "cc/quads/surface_draw_quad.h" | 8 #include "cc/quads/surface_draw_quad.h" |
9 #include "cc/surfaces/surface.h" | 9 #include "cc/surfaces/surface.h" |
10 #include "cc/surfaces/surface_aggregator.h" | 10 #include "cc/surfaces/surface_aggregator.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); | 24 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); |
25 | 25 |
26 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { | 26 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { |
27 public: | 27 public: |
28 void ReturnResources(const ReturnedResourceArray& resources) override {} | 28 void ReturnResources(const ReturnedResourceArray& resources) override {} |
29 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {} | 29 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {} |
30 }; | 30 }; |
31 | 31 |
32 class SurfacesPixelTest : public RendererPixelTest<GLRenderer> { | 32 class SurfacesPixelTest : public RendererPixelTest<GLRenderer> { |
33 public: | 33 public: |
34 SurfacesPixelTest() | 34 SurfacesPixelTest() : factory_(kArbitraryFrameSinkId, &manager_, &client_) {} |
35 : allocator_(kArbitraryFrameSinkId), | |
36 factory_(kArbitraryFrameSinkId, &manager_, &client_) {} | |
37 | 35 |
38 protected: | 36 protected: |
39 SurfaceManager manager_; | 37 SurfaceManager manager_; |
40 SurfaceIdAllocator allocator_; | 38 SurfaceIdAllocator allocator_; |
41 EmptySurfaceFactoryClient client_; | 39 EmptySurfaceFactoryClient client_; |
42 SurfaceFactory factory_; | 40 SurfaceFactory factory_; |
43 }; | 41 }; |
44 | 42 |
45 SharedQuadState* CreateAndAppendTestSharedQuadState( | 43 SharedQuadState* CreateAndAppendTestSharedQuadState( |
46 RenderPass* render_pass, | 44 RenderPass* render_pass, |
(...skipping 30 matching lines...) Expand all Loading... |
77 SK_ColorGREEN, | 75 SK_ColorGREEN, |
78 force_anti_aliasing_off); | 76 force_anti_aliasing_off); |
79 | 77 |
80 std::unique_ptr<DelegatedFrameData> delegated_frame_data( | 78 std::unique_ptr<DelegatedFrameData> delegated_frame_data( |
81 new DelegatedFrameData); | 79 new DelegatedFrameData); |
82 delegated_frame_data->render_pass_list.push_back(std::move(pass)); | 80 delegated_frame_data->render_pass_list.push_back(std::move(pass)); |
83 | 81 |
84 CompositorFrame root_frame; | 82 CompositorFrame root_frame; |
85 root_frame.delegated_frame_data = std::move(delegated_frame_data); | 83 root_frame.delegated_frame_data = std::move(delegated_frame_data); |
86 | 84 |
87 SurfaceId root_surface_id = allocator_.GenerateId(); | 85 LocalFrameId root_local_frame_id = allocator_.GenerateId(); |
88 factory_.Create(root_surface_id); | 86 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id); |
89 factory_.SubmitCompositorFrame(root_surface_id, std::move(root_frame), | 87 factory_.Create(root_local_frame_id); |
| 88 factory_.SubmitCompositorFrame(root_local_frame_id, std::move(root_frame), |
90 SurfaceFactory::DrawCallback()); | 89 SurfaceFactory::DrawCallback()); |
91 | 90 |
92 SurfaceAggregator aggregator(&manager_, resource_provider_.get(), true); | 91 SurfaceAggregator aggregator(&manager_, resource_provider_.get(), true); |
93 CompositorFrame aggregated_frame = aggregator.Aggregate(root_surface_id); | 92 CompositorFrame aggregated_frame = aggregator.Aggregate(root_surface_id); |
94 factory_.Destroy(root_surface_id); | 93 factory_.Destroy(root_local_frame_id); |
95 | 94 |
96 bool discard_alpha = false; | 95 bool discard_alpha = false; |
97 ExactPixelComparator pixel_comparator(discard_alpha); | 96 ExactPixelComparator pixel_comparator(discard_alpha); |
98 RenderPassList* pass_list = | 97 RenderPassList* pass_list = |
99 &aggregated_frame.delegated_frame_data->render_pass_list; | 98 &aggregated_frame.delegated_frame_data->render_pass_list; |
100 EXPECT_TRUE(RunPixelTest(pass_list, | 99 EXPECT_TRUE(RunPixelTest(pass_list, |
101 base::FilePath(FILE_PATH_LITERAL("green.png")), | 100 base::FilePath(FILE_PATH_LITERAL("green.png")), |
102 pixel_comparator)); | 101 pixel_comparator)); |
103 } | 102 } |
104 | 103 |
105 // Draws a frame with simple surface embedding. | 104 // Draws a frame with simple surface embedding. |
106 TEST_F(SurfacesPixelTest, DrawSimpleAggregatedFrame) { | 105 TEST_F(SurfacesPixelTest, DrawSimpleAggregatedFrame) { |
107 gfx::Size child_size(200, 100); | 106 gfx::Size child_size(200, 100); |
108 SurfaceId child_surface_id = allocator_.GenerateId(); | 107 LocalFrameId child_local_frame_id = allocator_.GenerateId(); |
109 SurfaceId root_surface_id = allocator_.GenerateId(); | 108 SurfaceId child_surface_id(factory_.frame_sink_id(), child_local_frame_id); |
110 factory_.Create(child_surface_id); | 109 LocalFrameId root_local_frame_id = allocator_.GenerateId(); |
111 factory_.Create(root_surface_id); | 110 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id); |
| 111 |
| 112 factory_.Create(child_local_frame_id); |
| 113 factory_.Create(root_local_frame_id); |
112 { | 114 { |
113 gfx::Rect rect(device_viewport_size_); | 115 gfx::Rect rect(device_viewport_size_); |
114 RenderPassId id(1, 1); | 116 RenderPassId id(1, 1); |
115 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 117 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
116 pass->SetNew(id, rect, rect, gfx::Transform()); | 118 pass->SetNew(id, rect, rect, gfx::Transform()); |
117 | 119 |
118 CreateAndAppendTestSharedQuadState( | 120 CreateAndAppendTestSharedQuadState( |
119 pass.get(), gfx::Transform(), device_viewport_size_); | 121 pass.get(), gfx::Transform(), device_viewport_size_); |
120 | 122 |
121 SurfaceDrawQuad* surface_quad = | 123 SurfaceDrawQuad* surface_quad = |
(...skipping 12 matching lines...) Expand all Loading... |
134 SK_ColorYELLOW, | 136 SK_ColorYELLOW, |
135 force_anti_aliasing_off); | 137 force_anti_aliasing_off); |
136 | 138 |
137 std::unique_ptr<DelegatedFrameData> delegated_frame_data( | 139 std::unique_ptr<DelegatedFrameData> delegated_frame_data( |
138 new DelegatedFrameData); | 140 new DelegatedFrameData); |
139 delegated_frame_data->render_pass_list.push_back(std::move(pass)); | 141 delegated_frame_data->render_pass_list.push_back(std::move(pass)); |
140 | 142 |
141 CompositorFrame root_frame; | 143 CompositorFrame root_frame; |
142 root_frame.delegated_frame_data = std::move(delegated_frame_data); | 144 root_frame.delegated_frame_data = std::move(delegated_frame_data); |
143 | 145 |
144 factory_.SubmitCompositorFrame(root_surface_id, std::move(root_frame), | 146 factory_.SubmitCompositorFrame(root_local_frame_id, std::move(root_frame), |
145 SurfaceFactory::DrawCallback()); | 147 SurfaceFactory::DrawCallback()); |
146 } | 148 } |
147 | 149 |
148 { | 150 { |
149 gfx::Rect rect(child_size); | 151 gfx::Rect rect(child_size); |
150 RenderPassId id(1, 1); | 152 RenderPassId id(1, 1); |
151 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 153 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
152 pass->SetNew(id, rect, rect, gfx::Transform()); | 154 pass->SetNew(id, rect, rect, gfx::Transform()); |
153 | 155 |
154 CreateAndAppendTestSharedQuadState( | 156 CreateAndAppendTestSharedQuadState( |
155 pass.get(), gfx::Transform(), child_size); | 157 pass.get(), gfx::Transform(), child_size); |
156 | 158 |
157 SolidColorDrawQuad* color_quad = | 159 SolidColorDrawQuad* color_quad = |
158 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | 160 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
159 bool force_anti_aliasing_off = false; | 161 bool force_anti_aliasing_off = false; |
160 color_quad->SetNew(pass->shared_quad_state_list.back(), | 162 color_quad->SetNew(pass->shared_quad_state_list.back(), |
161 rect, | 163 rect, |
162 rect, | 164 rect, |
163 SK_ColorBLUE, | 165 SK_ColorBLUE, |
164 force_anti_aliasing_off); | 166 force_anti_aliasing_off); |
165 | 167 |
166 std::unique_ptr<DelegatedFrameData> delegated_frame_data( | 168 std::unique_ptr<DelegatedFrameData> delegated_frame_data( |
167 new DelegatedFrameData); | 169 new DelegatedFrameData); |
168 delegated_frame_data->render_pass_list.push_back(std::move(pass)); | 170 delegated_frame_data->render_pass_list.push_back(std::move(pass)); |
169 | 171 |
170 CompositorFrame child_frame; | 172 CompositorFrame child_frame; |
171 child_frame.delegated_frame_data = std::move(delegated_frame_data); | 173 child_frame.delegated_frame_data = std::move(delegated_frame_data); |
172 | 174 |
173 factory_.SubmitCompositorFrame(child_surface_id, std::move(child_frame), | 175 factory_.SubmitCompositorFrame(child_local_frame_id, std::move(child_frame), |
174 SurfaceFactory::DrawCallback()); | 176 SurfaceFactory::DrawCallback()); |
175 } | 177 } |
176 | 178 |
177 SurfaceAggregator aggregator(&manager_, resource_provider_.get(), true); | 179 SurfaceAggregator aggregator(&manager_, resource_provider_.get(), true); |
178 CompositorFrame aggregated_frame = aggregator.Aggregate(root_surface_id); | 180 CompositorFrame aggregated_frame = aggregator.Aggregate(root_surface_id); |
179 | 181 |
180 bool discard_alpha = false; | 182 bool discard_alpha = false; |
181 ExactPixelComparator pixel_comparator(discard_alpha); | 183 ExactPixelComparator pixel_comparator(discard_alpha); |
182 RenderPassList* pass_list = | 184 RenderPassList* pass_list = |
183 &aggregated_frame.delegated_frame_data->render_pass_list; | 185 &aggregated_frame.delegated_frame_data->render_pass_list; |
184 EXPECT_TRUE(RunPixelTest(pass_list, | 186 EXPECT_TRUE(RunPixelTest(pass_list, |
185 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")), | 187 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")), |
186 pixel_comparator)); | 188 pixel_comparator)); |
187 factory_.Destroy(root_surface_id); | 189 factory_.Destroy(root_local_frame_id); |
188 factory_.Destroy(child_surface_id); | 190 factory_.Destroy(child_local_frame_id); |
189 } | 191 } |
190 | 192 |
191 // Tests a surface quad that has a non-identity transform into its pass. | 193 // Tests a surface quad that has a non-identity transform into its pass. |
192 TEST_F(SurfacesPixelTest, DrawAggregatedFrameWithSurfaceTransforms) { | 194 TEST_F(SurfacesPixelTest, DrawAggregatedFrameWithSurfaceTransforms) { |
193 gfx::Size child_size(100, 200); | 195 gfx::Size child_size(100, 200); |
194 gfx::Size quad_size(100, 100); | 196 gfx::Size quad_size(100, 100); |
195 // Structure: | 197 // Structure: |
196 // root (200x200) -> left_child (100x200 @ 0x0, | 198 // root (200x200) -> left_child (100x200 @ 0x0, |
197 // right_child (100x200 @ 0x100) | 199 // right_child (100x200 @ 0x100) |
198 // left_child -> top_green_quad (100x100 @ 0x0), | 200 // left_child -> top_green_quad (100x100 @ 0x0), |
199 // bottom_blue_quad (100x100 @ 0x100) | 201 // bottom_blue_quad (100x100 @ 0x100) |
200 // right_child -> top_blue_quad (100x100 @ 0x0), | 202 // right_child -> top_blue_quad (100x100 @ 0x0), |
201 // bottom_green_quad (100x100 @ 0x100) | 203 // bottom_green_quad (100x100 @ 0x100) |
202 SurfaceId left_child_id = allocator_.GenerateId(); | 204 LocalFrameId left_child_local_id = allocator_.GenerateId(); |
203 SurfaceId right_child_id = allocator_.GenerateId(); | 205 SurfaceId left_child_id(factory_.frame_sink_id(), left_child_local_id); |
204 SurfaceId root_surface_id = allocator_.GenerateId(); | 206 LocalFrameId right_child_local_id = allocator_.GenerateId(); |
205 factory_.Create(left_child_id); | 207 SurfaceId right_child_id(factory_.frame_sink_id(), right_child_local_id); |
206 factory_.Create(right_child_id); | 208 LocalFrameId root_local_frame_id = allocator_.GenerateId(); |
207 factory_.Create(root_surface_id); | 209 SurfaceId root_surface_id(factory_.frame_sink_id(), root_local_frame_id); |
| 210 factory_.Create(left_child_local_id); |
| 211 factory_.Create(right_child_local_id); |
| 212 factory_.Create(root_local_frame_id); |
208 | 213 |
209 { | 214 { |
210 gfx::Rect rect(device_viewport_size_); | 215 gfx::Rect rect(device_viewport_size_); |
211 RenderPassId id(1, 1); | 216 RenderPassId id(1, 1); |
212 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 217 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
213 pass->SetNew(id, rect, rect, gfx::Transform()); | 218 pass->SetNew(id, rect, rect, gfx::Transform()); |
214 | 219 |
215 gfx::Transform surface_transform; | 220 gfx::Transform surface_transform; |
216 CreateAndAppendTestSharedQuadState( | 221 CreateAndAppendTestSharedQuadState( |
217 pass.get(), surface_transform, device_viewport_size_); | 222 pass.get(), surface_transform, device_viewport_size_); |
(...skipping 16 matching lines...) Expand all Loading... |
234 gfx::Rect(child_size), | 239 gfx::Rect(child_size), |
235 right_child_id); | 240 right_child_id); |
236 | 241 |
237 std::unique_ptr<DelegatedFrameData> delegated_frame_data( | 242 std::unique_ptr<DelegatedFrameData> delegated_frame_data( |
238 new DelegatedFrameData); | 243 new DelegatedFrameData); |
239 delegated_frame_data->render_pass_list.push_back(std::move(pass)); | 244 delegated_frame_data->render_pass_list.push_back(std::move(pass)); |
240 | 245 |
241 CompositorFrame root_frame; | 246 CompositorFrame root_frame; |
242 root_frame.delegated_frame_data = std::move(delegated_frame_data); | 247 root_frame.delegated_frame_data = std::move(delegated_frame_data); |
243 | 248 |
244 factory_.SubmitCompositorFrame(root_surface_id, std::move(root_frame), | 249 factory_.SubmitCompositorFrame(root_local_frame_id, std::move(root_frame), |
245 SurfaceFactory::DrawCallback()); | 250 SurfaceFactory::DrawCallback()); |
246 } | 251 } |
247 | 252 |
248 { | 253 { |
249 gfx::Rect rect(child_size); | 254 gfx::Rect rect(child_size); |
250 RenderPassId id(1, 1); | 255 RenderPassId id(1, 1); |
251 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 256 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
252 pass->SetNew(id, rect, rect, gfx::Transform()); | 257 pass->SetNew(id, rect, rect, gfx::Transform()); |
253 | 258 |
254 CreateAndAppendTestSharedQuadState( | 259 CreateAndAppendTestSharedQuadState( |
(...skipping 16 matching lines...) Expand all Loading... |
271 SK_ColorBLUE, | 276 SK_ColorBLUE, |
272 force_anti_aliasing_off); | 277 force_anti_aliasing_off); |
273 | 278 |
274 std::unique_ptr<DelegatedFrameData> delegated_frame_data( | 279 std::unique_ptr<DelegatedFrameData> delegated_frame_data( |
275 new DelegatedFrameData); | 280 new DelegatedFrameData); |
276 delegated_frame_data->render_pass_list.push_back(std::move(pass)); | 281 delegated_frame_data->render_pass_list.push_back(std::move(pass)); |
277 | 282 |
278 CompositorFrame child_frame; | 283 CompositorFrame child_frame; |
279 child_frame.delegated_frame_data = std::move(delegated_frame_data); | 284 child_frame.delegated_frame_data = std::move(delegated_frame_data); |
280 | 285 |
281 factory_.SubmitCompositorFrame(left_child_id, std::move(child_frame), | 286 factory_.SubmitCompositorFrame(left_child_local_id, std::move(child_frame), |
282 SurfaceFactory::DrawCallback()); | 287 SurfaceFactory::DrawCallback()); |
283 } | 288 } |
284 | 289 |
285 { | 290 { |
286 gfx::Rect rect(child_size); | 291 gfx::Rect rect(child_size); |
287 RenderPassId id(1, 1); | 292 RenderPassId id(1, 1); |
288 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 293 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
289 pass->SetNew(id, rect, rect, gfx::Transform()); | 294 pass->SetNew(id, rect, rect, gfx::Transform()); |
290 | 295 |
291 CreateAndAppendTestSharedQuadState( | 296 CreateAndAppendTestSharedQuadState( |
(...skipping 16 matching lines...) Expand all Loading... |
308 SK_ColorGREEN, | 313 SK_ColorGREEN, |
309 force_anti_aliasing_off); | 314 force_anti_aliasing_off); |
310 | 315 |
311 std::unique_ptr<DelegatedFrameData> delegated_frame_data( | 316 std::unique_ptr<DelegatedFrameData> delegated_frame_data( |
312 new DelegatedFrameData); | 317 new DelegatedFrameData); |
313 delegated_frame_data->render_pass_list.push_back(std::move(pass)); | 318 delegated_frame_data->render_pass_list.push_back(std::move(pass)); |
314 | 319 |
315 CompositorFrame child_frame; | 320 CompositorFrame child_frame; |
316 child_frame.delegated_frame_data = std::move(delegated_frame_data); | 321 child_frame.delegated_frame_data = std::move(delegated_frame_data); |
317 | 322 |
318 factory_.SubmitCompositorFrame(right_child_id, std::move(child_frame), | 323 factory_.SubmitCompositorFrame(right_child_local_id, std::move(child_frame), |
319 SurfaceFactory::DrawCallback()); | 324 SurfaceFactory::DrawCallback()); |
320 } | 325 } |
321 | 326 |
322 SurfaceAggregator aggregator(&manager_, resource_provider_.get(), true); | 327 SurfaceAggregator aggregator(&manager_, resource_provider_.get(), true); |
323 CompositorFrame aggregated_frame = aggregator.Aggregate(root_surface_id); | 328 CompositorFrame aggregated_frame = aggregator.Aggregate(root_surface_id); |
324 | 329 |
325 bool discard_alpha = false; | 330 bool discard_alpha = false; |
326 ExactPixelComparator pixel_comparator(discard_alpha); | 331 ExactPixelComparator pixel_comparator(discard_alpha); |
327 RenderPassList* pass_list = | 332 RenderPassList* pass_list = |
328 &aggregated_frame.delegated_frame_data->render_pass_list; | 333 &aggregated_frame.delegated_frame_data->render_pass_list; |
329 EXPECT_TRUE(RunPixelTest( | 334 EXPECT_TRUE(RunPixelTest( |
330 pass_list, | 335 pass_list, |
331 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")), | 336 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")), |
332 pixel_comparator)); | 337 pixel_comparator)); |
333 | 338 |
334 factory_.Destroy(root_surface_id); | 339 factory_.Destroy(root_local_frame_id); |
335 factory_.Destroy(left_child_id); | 340 factory_.Destroy(left_child_local_id); |
336 factory_.Destroy(right_child_id); | 341 factory_.Destroy(right_child_local_id); |
337 } | 342 } |
338 | 343 |
339 } // namespace | 344 } // namespace |
340 } // namespace cc | 345 } // namespace cc |
341 | 346 |
342 #endif // !defined(OS_ANDROID) | 347 #endif // !defined(OS_ANDROID) |
OLD | NEW |