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/output/software_renderer.h" | 5 #include "cc/output/software_renderer.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "cc/output/compositor_frame_metadata.h" | 8 #include "cc/output/compositor_frame_metadata.h" |
9 #include "cc/output/copy_output_request.h" | 9 #include "cc/output/copy_output_request.h" |
10 #include "cc/output/copy_output_result.h" | 10 #include "cc/output/copy_output_result.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 } | 52 } |
53 | 53 |
54 SoftwareRenderer* renderer() const { return renderer_.get(); } | 54 SoftwareRenderer* renderer() const { return renderer_.get(); } |
55 | 55 |
56 // RendererClient implementation. | 56 // RendererClient implementation. |
57 void SetFullRootLayerDamage() override {} | 57 void SetFullRootLayerDamage() override {} |
58 | 58 |
59 scoped_ptr<SkBitmap> DrawAndCopyOutput(RenderPassList* list, | 59 scoped_ptr<SkBitmap> DrawAndCopyOutput(RenderPassList* list, |
60 float device_scale_factor, | 60 float device_scale_factor, |
61 gfx::Rect device_viewport_rect) { | 61 gfx::Rect device_viewport_rect) { |
62 CHECK(!list->empty()); | |
63 return DrawAndCopyOutput(list, | |
64 list->size() - 1, | |
65 device_scale_factor, | |
66 device_viewport_rect).Pass(); | |
danakj
2015/02/05 17:42:21
you dont need Pass() on a return statement
danakj
2015/02/05 18:15:28
return makes this an xvalue which allows the move
| |
67 } | |
68 | |
69 scoped_ptr<SkBitmap> DrawAndCopyOutput(RenderPassList* list, | |
70 size_t index, | |
71 float device_scale_factor, | |
72 gfx::Rect device_viewport_rect) { | |
62 scoped_ptr<SkBitmap> bitmap_result; | 73 scoped_ptr<SkBitmap> bitmap_result; |
63 base::RunLoop loop; | 74 base::RunLoop loop; |
64 | 75 |
65 list->back()->copy_requests.push_back( | 76 list->at(index)->copy_requests.push_back( |
66 CopyOutputRequest::CreateBitmapRequest( | 77 CopyOutputRequest::CreateBitmapRequest( |
67 base::Bind(&SoftwareRendererTest::SaveBitmapResult, | 78 base::Bind(&SoftwareRendererTest::SaveBitmapResult, |
68 base::Unretained(&bitmap_result), | 79 base::Unretained(&bitmap_result), |
69 loop.QuitClosure()))); | 80 loop.QuitClosure()))); |
70 | 81 |
71 renderer()->DrawFrame(list, | 82 renderer()->DrawFrame(list, |
72 device_scale_factor, | 83 device_scale_factor, |
73 device_viewport_rect, | 84 device_viewport_rect, |
74 device_viewport_rect, | 85 device_viewport_rect, |
75 false); | 86 false); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 shared_quad_state, outer_rect, outer_rect, SK_ColorYELLOW, false); | 139 shared_quad_state, outer_rect, outer_rect, SK_ColorYELLOW, false); |
129 | 140 |
130 RenderPassList list; | 141 RenderPassList list; |
131 list.push_back(root_render_pass.Pass()); | 142 list.push_back(root_render_pass.Pass()); |
132 | 143 |
133 float device_scale_factor = 1.f; | 144 float device_scale_factor = 1.f; |
134 gfx::Rect device_viewport_rect(outer_size); | 145 gfx::Rect device_viewport_rect(outer_size); |
135 scoped_ptr<SkBitmap> output = | 146 scoped_ptr<SkBitmap> output = |
136 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); | 147 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); |
137 EXPECT_EQ(outer_rect.width(), output->info().fWidth); | 148 EXPECT_EQ(outer_rect.width(), output->info().fWidth); |
138 EXPECT_EQ(outer_rect.width(), output->info().fHeight); | 149 EXPECT_EQ(outer_rect.height(), output->info().fHeight); |
139 | 150 |
140 EXPECT_EQ(SK_ColorYELLOW, output->getColor(0, 0)); | 151 EXPECT_EQ(SK_ColorYELLOW, output->getColor(0, 0)); |
141 EXPECT_EQ(SK_ColorYELLOW, | 152 EXPECT_EQ(SK_ColorYELLOW, |
142 output->getColor(outer_size.width() - 1, outer_size.height() - 1)); | 153 output->getColor(outer_size.width() - 1, outer_size.height() - 1)); |
143 EXPECT_EQ(SK_ColorYELLOW, output->getColor(1, 1)); | 154 EXPECT_EQ(SK_ColorYELLOW, output->getColor(1, 1)); |
144 EXPECT_EQ(SK_ColorCYAN, output->getColor(1, 2)); | 155 EXPECT_EQ(SK_ColorCYAN, output->getColor(1, 2)); |
145 EXPECT_EQ(SK_ColorCYAN, | 156 EXPECT_EQ(SK_ColorCYAN, |
146 output->getColor(inner_size.width() - 1, inner_size.height() - 1)); | 157 output->getColor(inner_size.width() - 1, inner_size.height() - 1)); |
147 } | 158 } |
148 | 159 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 false); | 237 false); |
227 | 238 |
228 RenderPassList list; | 239 RenderPassList list; |
229 list.push_back(root_render_pass.Pass()); | 240 list.push_back(root_render_pass.Pass()); |
230 | 241 |
231 float device_scale_factor = 1.f; | 242 float device_scale_factor = 1.f; |
232 gfx::Rect device_viewport_rect(outer_size); | 243 gfx::Rect device_viewport_rect(outer_size); |
233 scoped_ptr<SkBitmap> output = | 244 scoped_ptr<SkBitmap> output = |
234 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); | 245 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); |
235 EXPECT_EQ(outer_rect.width(), output->info().fWidth); | 246 EXPECT_EQ(outer_rect.width(), output->info().fWidth); |
236 EXPECT_EQ(outer_rect.width(), output->info().fHeight); | 247 EXPECT_EQ(outer_rect.height(), output->info().fHeight); |
237 | 248 |
238 EXPECT_EQ(SK_ColorYELLOW, output->getColor(0, 0)); | 249 EXPECT_EQ(SK_ColorYELLOW, output->getColor(0, 0)); |
239 EXPECT_EQ(SK_ColorYELLOW, | 250 EXPECT_EQ(SK_ColorYELLOW, |
240 output->getColor(outer_size.width() - 1, outer_size.height() - 1)); | 251 output->getColor(outer_size.width() - 1, outer_size.height() - 1)); |
241 EXPECT_EQ(SK_ColorCYAN, output->getColor(1, 1)); | 252 EXPECT_EQ(SK_ColorCYAN, output->getColor(1, 1)); |
242 EXPECT_EQ(SK_ColorCYAN, | 253 EXPECT_EQ(SK_ColorCYAN, |
243 output->getColor(inner_size.width() - 1, inner_size.height() - 1)); | 254 output->getColor(inner_size.width() - 1, inner_size.height() - 1)); |
244 } | 255 } |
245 | 256 |
246 TEST_F(SoftwareRendererTest, TileQuadVisibleRect) { | 257 TEST_F(SoftwareRendererTest, TileQuadVisibleRect) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 quad->visible_rect = visible_rect; | 312 quad->visible_rect = visible_rect; |
302 | 313 |
303 RenderPassList list; | 314 RenderPassList list; |
304 list.push_back(root_render_pass.Pass()); | 315 list.push_back(root_render_pass.Pass()); |
305 | 316 |
306 float device_scale_factor = 1.f; | 317 float device_scale_factor = 1.f; |
307 gfx::Rect device_viewport_rect(tile_size); | 318 gfx::Rect device_viewport_rect(tile_size); |
308 scoped_ptr<SkBitmap> output = | 319 scoped_ptr<SkBitmap> output = |
309 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); | 320 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); |
310 EXPECT_EQ(tile_rect.width(), output->info().fWidth); | 321 EXPECT_EQ(tile_rect.width(), output->info().fWidth); |
311 EXPECT_EQ(tile_rect.width(), output->info().fHeight); | 322 EXPECT_EQ(tile_rect.height(), output->info().fHeight); |
312 | 323 |
313 // Check portion of tile not in visible rect isn't drawn. | 324 // Check portion of tile not in visible rect isn't drawn. |
314 const unsigned int kTransparent = SK_ColorTRANSPARENT; | 325 const unsigned int kTransparent = SK_ColorTRANSPARENT; |
315 EXPECT_EQ(kTransparent, output->getColor(0, 0)); | 326 EXPECT_EQ(kTransparent, output->getColor(0, 0)); |
316 EXPECT_EQ(kTransparent, | 327 EXPECT_EQ(kTransparent, |
317 output->getColor(tile_rect.width() - 1, tile_rect.height() - 1)); | 328 output->getColor(tile_rect.width() - 1, tile_rect.height() - 1)); |
318 EXPECT_EQ(kTransparent, | 329 EXPECT_EQ(kTransparent, |
319 output->getColor(visible_rect.x() - 1, visible_rect.y() - 1)); | 330 output->getColor(visible_rect.x() - 1, visible_rect.y() - 1)); |
320 EXPECT_EQ(kTransparent, | 331 EXPECT_EQ(kTransparent, |
321 output->getColor(visible_rect.right(), visible_rect.bottom())); | 332 output->getColor(visible_rect.right(), visible_rect.bottom())); |
(...skipping 21 matching lines...) Expand all Loading... | |
343 RenderPassId root_clear_pass_id(1, 0); | 354 RenderPassId root_clear_pass_id(1, 0); |
344 TestRenderPass* root_clear_pass = AddRenderPass( | 355 TestRenderPass* root_clear_pass = AddRenderPass( |
345 &list, root_clear_pass_id, device_viewport_rect, gfx::Transform()); | 356 &list, root_clear_pass_id, device_viewport_rect, gfx::Transform()); |
346 AddQuad(root_clear_pass, device_viewport_rect, SK_ColorGREEN); | 357 AddQuad(root_clear_pass, device_viewport_rect, SK_ColorGREEN); |
347 | 358 |
348 renderer()->DecideRenderPassAllocationsForFrame(list); | 359 renderer()->DecideRenderPassAllocationsForFrame(list); |
349 | 360 |
350 scoped_ptr<SkBitmap> output = | 361 scoped_ptr<SkBitmap> output = |
351 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); | 362 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); |
352 EXPECT_EQ(device_viewport_rect.width(), output->info().fWidth); | 363 EXPECT_EQ(device_viewport_rect.width(), output->info().fWidth); |
353 EXPECT_EQ(device_viewport_rect.width(), output->info().fHeight); | 364 EXPECT_EQ(device_viewport_rect.height(), output->info().fHeight); |
354 | 365 |
355 EXPECT_EQ(SK_ColorGREEN, output->getColor(0, 0)); | 366 EXPECT_EQ(SK_ColorGREEN, output->getColor(0, 0)); |
356 EXPECT_EQ(SK_ColorGREEN, | 367 EXPECT_EQ(SK_ColorGREEN, |
357 output->getColor(device_viewport_rect.width() - 1, | 368 output->getColor(device_viewport_rect.width() - 1, |
358 device_viewport_rect.height() - 1)); | 369 device_viewport_rect.height() - 1)); |
359 | 370 |
360 list.clear(); | 371 list.clear(); |
361 | 372 |
362 // Draw a smaller magenta rect without filling the viewport in a separate | 373 // Draw a smaller magenta rect without filling the viewport in a separate |
363 // frame. | 374 // frame. |
364 gfx::Rect smaller_rect(20, 20, 60, 60); | 375 gfx::Rect smaller_rect(20, 20, 60, 60); |
365 | 376 |
366 RenderPassId root_smaller_pass_id(2, 0); | 377 RenderPassId root_smaller_pass_id(2, 0); |
367 TestRenderPass* root_smaller_pass = AddRenderPass( | 378 TestRenderPass* root_smaller_pass = AddRenderPass( |
368 &list, root_smaller_pass_id, device_viewport_rect, gfx::Transform()); | 379 &list, root_smaller_pass_id, device_viewport_rect, gfx::Transform()); |
369 AddQuad(root_smaller_pass, smaller_rect, SK_ColorMAGENTA); | 380 AddQuad(root_smaller_pass, smaller_rect, SK_ColorMAGENTA); |
370 | 381 |
371 renderer()->DecideRenderPassAllocationsForFrame(list); | 382 renderer()->DecideRenderPassAllocationsForFrame(list); |
372 | 383 |
373 output = DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); | 384 output = DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); |
374 EXPECT_EQ(device_viewport_rect.width(), output->info().fWidth); | 385 EXPECT_EQ(device_viewport_rect.width(), output->info().fWidth); |
375 EXPECT_EQ(device_viewport_rect.width(), output->info().fHeight); | 386 EXPECT_EQ(device_viewport_rect.height(), output->info().fHeight); |
376 | 387 |
377 // If we didn't clear, the borders should still be green. | 388 // If we didn't clear, the borders should still be green. |
378 EXPECT_EQ(SK_ColorGREEN, output->getColor(0, 0)); | 389 EXPECT_EQ(SK_ColorGREEN, output->getColor(0, 0)); |
379 EXPECT_EQ(SK_ColorGREEN, | 390 EXPECT_EQ(SK_ColorGREEN, |
380 output->getColor(device_viewport_rect.width() - 1, | 391 output->getColor(device_viewport_rect.width() - 1, |
381 device_viewport_rect.height() - 1)); | 392 device_viewport_rect.height() - 1)); |
382 | 393 |
383 EXPECT_EQ(SK_ColorMAGENTA, | 394 EXPECT_EQ(SK_ColorMAGENTA, |
384 output->getColor(smaller_rect.x(), smaller_rect.y())); | 395 output->getColor(smaller_rect.x(), smaller_rect.y())); |
385 EXPECT_EQ( | 396 EXPECT_EQ( |
(...skipping 24 matching lines...) Expand all Loading... | |
410 | 421 |
411 // Interior pass quad has smaller visible rect. | 422 // Interior pass quad has smaller visible rect. |
412 gfx::Rect interior_visible_rect(30, 30, 40, 40); | 423 gfx::Rect interior_visible_rect(30, 30, 40, 40); |
413 root_clear_pass->quad_list.front()->visible_rect = interior_visible_rect; | 424 root_clear_pass->quad_list.front()->visible_rect = interior_visible_rect; |
414 | 425 |
415 renderer()->DecideRenderPassAllocationsForFrame(list); | 426 renderer()->DecideRenderPassAllocationsForFrame(list); |
416 | 427 |
417 scoped_ptr<SkBitmap> output = | 428 scoped_ptr<SkBitmap> output = |
418 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); | 429 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); |
419 EXPECT_EQ(device_viewport_rect.width(), output->info().fWidth); | 430 EXPECT_EQ(device_viewport_rect.width(), output->info().fWidth); |
420 EXPECT_EQ(device_viewport_rect.width(), output->info().fHeight); | 431 EXPECT_EQ(device_viewport_rect.height(), output->info().fHeight); |
421 | 432 |
422 EXPECT_EQ(SK_ColorGREEN, output->getColor(0, 0)); | 433 EXPECT_EQ(SK_ColorGREEN, output->getColor(0, 0)); |
423 EXPECT_EQ(SK_ColorGREEN, | 434 EXPECT_EQ(SK_ColorGREEN, |
424 output->getColor(device_viewport_rect.width() - 1, | 435 output->getColor(device_viewport_rect.width() - 1, |
425 device_viewport_rect.height() - 1)); | 436 device_viewport_rect.height() - 1)); |
426 | 437 |
427 // Part outside visible rect should remain green. | 438 // Part outside visible rect should remain green. |
428 EXPECT_EQ(SK_ColorGREEN, | 439 EXPECT_EQ(SK_ColorGREEN, |
429 output->getColor(smaller_rect.x(), smaller_rect.y())); | 440 output->getColor(smaller_rect.x(), smaller_rect.y())); |
430 EXPECT_EQ( | 441 EXPECT_EQ( |
431 SK_ColorGREEN, | 442 SK_ColorGREEN, |
432 output->getColor(smaller_rect.right() - 1, smaller_rect.bottom() - 1)); | 443 output->getColor(smaller_rect.right() - 1, smaller_rect.bottom() - 1)); |
433 | 444 |
434 EXPECT_EQ( | 445 EXPECT_EQ( |
435 SK_ColorMAGENTA, | 446 SK_ColorMAGENTA, |
436 output->getColor(interior_visible_rect.x(), interior_visible_rect.y())); | 447 output->getColor(interior_visible_rect.x(), interior_visible_rect.y())); |
437 EXPECT_EQ(SK_ColorMAGENTA, | 448 EXPECT_EQ(SK_ColorMAGENTA, |
438 output->getColor(interior_visible_rect.right() - 1, | 449 output->getColor(interior_visible_rect.right() - 1, |
439 interior_visible_rect.bottom() - 1)); | 450 interior_visible_rect.bottom() - 1)); |
440 } | 451 } |
441 | 452 |
453 TEST_F(SoftwareRendererTest, DoubleLockTextureCrash) { | |
454 float device_scale_factor = 1.f; | |
455 gfx::Rect device_viewport_rect(0, 0, 100, 100); | |
456 InitializeRenderer(make_scoped_ptr(new SoftwareOutputDevice)); | |
457 | |
458 RenderPassList list; | |
459 | |
460 gfx::Rect first_rect(0, 0, 50, 50); | |
461 RenderPassId first_pass_id(3, 2); | |
462 TestRenderPass* first_pass = | |
463 AddRenderPass(&list, first_pass_id, first_rect, gfx::Transform()); | |
464 AddQuad(first_pass, first_rect, SK_ColorRED); | |
465 | |
466 gfx::Rect second_rect(50, 50, 50, 50); | |
467 RenderPassId second_pass_id(2, 1); | |
468 TestRenderPass* second_pass = | |
469 AddRenderPass(&list, second_pass_id, second_rect, gfx::Transform()); | |
470 AddQuad(second_pass, second_rect, SK_ColorBLUE); | |
471 | |
472 RenderPassId root_clear_pass_id(1, 0); | |
473 TestRenderPass* root_clear_pass = AddRenderPass( | |
474 &list, root_clear_pass_id, device_viewport_rect, gfx::Transform()); | |
475 AddRenderPassQuad(root_clear_pass, first_pass); | |
476 AddRenderPassQuad(root_clear_pass, second_pass); | |
477 AddQuad(root_clear_pass, device_viewport_rect, SK_ColorGREEN); | |
478 | |
479 renderer()->DecideRenderPassAllocationsForFrame(list); | |
480 | |
481 scoped_ptr<SkBitmap> output = | |
482 DrawAndCopyOutput(&list, 1, device_scale_factor, device_viewport_rect); | |
483 | |
484 EXPECT_EQ(second_rect.width(), output->info().fWidth); | |
485 EXPECT_EQ(second_rect.height(), output->info().fHeight); | |
486 | |
487 EXPECT_EQ(SK_ColorBLUE, output->getColor(0, 0)); | |
488 EXPECT_EQ(SK_ColorBLUE, | |
489 output->getColor(second_rect.width() - 1, | |
490 second_rect.height() - 1)); | |
491 EXPECT_EQ(SK_ColorBLUE, | |
492 output->getColor(second_rect.width() / 2, | |
493 second_rect.height() / 2)); | |
494 } | |
495 | |
442 } // namespace | 496 } // namespace |
443 } // namespace cc | 497 } // namespace cc |
OLD | NEW |