Chromium Code Reviews| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 scoped_ptr<SkBitmap> bitmap_result; | 62 scoped_ptr<SkBitmap> bitmap_result; |
| 63 base::RunLoop loop; | 63 base::RunLoop loop; |
| 64 | 64 |
| 65 CHECK(!list->empty()); | |
|
danakj
2015/02/06 23:11:42
I don't think we need this, back() will crash inst
| |
| 65 list->back()->copy_requests.push_back( | 66 list->back()->copy_requests.push_back( |
| 66 CopyOutputRequest::CreateBitmapRequest( | 67 CopyOutputRequest::CreateBitmapRequest( |
| 67 base::Bind(&SoftwareRendererTest::SaveBitmapResult, | 68 base::Bind(&SoftwareRendererTest::SaveBitmapResult, |
| 68 base::Unretained(&bitmap_result), | 69 base::Unretained(&bitmap_result), |
| 69 loop.QuitClosure()))); | 70 loop.QuitClosure()))); |
| 70 | 71 |
| 71 renderer()->DrawFrame(list, | 72 renderer()->DrawFrame(list, |
| 72 device_scale_factor, | 73 device_scale_factor, |
| 73 device_viewport_rect, | 74 device_viewport_rect, |
| 74 device_viewport_rect, | 75 device_viewport_rect, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 shared_quad_state, outer_rect, outer_rect, SK_ColorYELLOW, false); | 129 shared_quad_state, outer_rect, outer_rect, SK_ColorYELLOW, false); |
| 129 | 130 |
| 130 RenderPassList list; | 131 RenderPassList list; |
| 131 list.push_back(root_render_pass.Pass()); | 132 list.push_back(root_render_pass.Pass()); |
| 132 | 133 |
| 133 float device_scale_factor = 1.f; | 134 float device_scale_factor = 1.f; |
| 134 gfx::Rect device_viewport_rect(outer_size); | 135 gfx::Rect device_viewport_rect(outer_size); |
| 135 scoped_ptr<SkBitmap> output = | 136 scoped_ptr<SkBitmap> output = |
| 136 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); | 137 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); |
| 137 EXPECT_EQ(outer_rect.width(), output->info().fWidth); | 138 EXPECT_EQ(outer_rect.width(), output->info().fWidth); |
| 138 EXPECT_EQ(outer_rect.width(), output->info().fHeight); | 139 EXPECT_EQ(outer_rect.height(), output->info().fHeight); |
| 139 | 140 |
| 140 EXPECT_EQ(SK_ColorYELLOW, output->getColor(0, 0)); | 141 EXPECT_EQ(SK_ColorYELLOW, output->getColor(0, 0)); |
| 141 EXPECT_EQ(SK_ColorYELLOW, | 142 EXPECT_EQ(SK_ColorYELLOW, |
| 142 output->getColor(outer_size.width() - 1, outer_size.height() - 1)); | 143 output->getColor(outer_size.width() - 1, outer_size.height() - 1)); |
| 143 EXPECT_EQ(SK_ColorYELLOW, output->getColor(1, 1)); | 144 EXPECT_EQ(SK_ColorYELLOW, output->getColor(1, 1)); |
| 144 EXPECT_EQ(SK_ColorCYAN, output->getColor(1, 2)); | 145 EXPECT_EQ(SK_ColorCYAN, output->getColor(1, 2)); |
| 145 EXPECT_EQ(SK_ColorCYAN, | 146 EXPECT_EQ(SK_ColorCYAN, |
| 146 output->getColor(inner_size.width() - 1, inner_size.height() - 1)); | 147 output->getColor(inner_size.width() - 1, inner_size.height() - 1)); |
| 147 } | 148 } |
| 148 | 149 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 false); | 227 false); |
| 227 | 228 |
| 228 RenderPassList list; | 229 RenderPassList list; |
| 229 list.push_back(root_render_pass.Pass()); | 230 list.push_back(root_render_pass.Pass()); |
| 230 | 231 |
| 231 float device_scale_factor = 1.f; | 232 float device_scale_factor = 1.f; |
| 232 gfx::Rect device_viewport_rect(outer_size); | 233 gfx::Rect device_viewport_rect(outer_size); |
| 233 scoped_ptr<SkBitmap> output = | 234 scoped_ptr<SkBitmap> output = |
| 234 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); | 235 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); |
| 235 EXPECT_EQ(outer_rect.width(), output->info().fWidth); | 236 EXPECT_EQ(outer_rect.width(), output->info().fWidth); |
| 236 EXPECT_EQ(outer_rect.width(), output->info().fHeight); | 237 EXPECT_EQ(outer_rect.height(), output->info().fHeight); |
| 237 | 238 |
| 238 EXPECT_EQ(SK_ColorYELLOW, output->getColor(0, 0)); | 239 EXPECT_EQ(SK_ColorYELLOW, output->getColor(0, 0)); |
| 239 EXPECT_EQ(SK_ColorYELLOW, | 240 EXPECT_EQ(SK_ColorYELLOW, |
| 240 output->getColor(outer_size.width() - 1, outer_size.height() - 1)); | 241 output->getColor(outer_size.width() - 1, outer_size.height() - 1)); |
| 241 EXPECT_EQ(SK_ColorCYAN, output->getColor(1, 1)); | 242 EXPECT_EQ(SK_ColorCYAN, output->getColor(1, 1)); |
| 242 EXPECT_EQ(SK_ColorCYAN, | 243 EXPECT_EQ(SK_ColorCYAN, |
| 243 output->getColor(inner_size.width() - 1, inner_size.height() - 1)); | 244 output->getColor(inner_size.width() - 1, inner_size.height() - 1)); |
| 244 } | 245 } |
| 245 | 246 |
| 246 TEST_F(SoftwareRendererTest, TileQuadVisibleRect) { | 247 TEST_F(SoftwareRendererTest, TileQuadVisibleRect) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 quad->visible_rect = visible_rect; | 302 quad->visible_rect = visible_rect; |
| 302 | 303 |
| 303 RenderPassList list; | 304 RenderPassList list; |
| 304 list.push_back(root_render_pass.Pass()); | 305 list.push_back(root_render_pass.Pass()); |
| 305 | 306 |
| 306 float device_scale_factor = 1.f; | 307 float device_scale_factor = 1.f; |
| 307 gfx::Rect device_viewport_rect(tile_size); | 308 gfx::Rect device_viewport_rect(tile_size); |
| 308 scoped_ptr<SkBitmap> output = | 309 scoped_ptr<SkBitmap> output = |
| 309 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); | 310 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); |
| 310 EXPECT_EQ(tile_rect.width(), output->info().fWidth); | 311 EXPECT_EQ(tile_rect.width(), output->info().fWidth); |
| 311 EXPECT_EQ(tile_rect.width(), output->info().fHeight); | 312 EXPECT_EQ(tile_rect.height(), output->info().fHeight); |
| 312 | 313 |
| 313 // Check portion of tile not in visible rect isn't drawn. | 314 // Check portion of tile not in visible rect isn't drawn. |
| 314 const unsigned int kTransparent = SK_ColorTRANSPARENT; | 315 const unsigned int kTransparent = SK_ColorTRANSPARENT; |
| 315 EXPECT_EQ(kTransparent, output->getColor(0, 0)); | 316 EXPECT_EQ(kTransparent, output->getColor(0, 0)); |
| 316 EXPECT_EQ(kTransparent, | 317 EXPECT_EQ(kTransparent, |
| 317 output->getColor(tile_rect.width() - 1, tile_rect.height() - 1)); | 318 output->getColor(tile_rect.width() - 1, tile_rect.height() - 1)); |
| 318 EXPECT_EQ(kTransparent, | 319 EXPECT_EQ(kTransparent, |
| 319 output->getColor(visible_rect.x() - 1, visible_rect.y() - 1)); | 320 output->getColor(visible_rect.x() - 1, visible_rect.y() - 1)); |
| 320 EXPECT_EQ(kTransparent, | 321 EXPECT_EQ(kTransparent, |
| 321 output->getColor(visible_rect.right(), visible_rect.bottom())); | 322 output->getColor(visible_rect.right(), visible_rect.bottom())); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 343 RenderPassId root_clear_pass_id(1, 0); | 344 RenderPassId root_clear_pass_id(1, 0); |
| 344 TestRenderPass* root_clear_pass = AddRenderPass( | 345 TestRenderPass* root_clear_pass = AddRenderPass( |
| 345 &list, root_clear_pass_id, device_viewport_rect, gfx::Transform()); | 346 &list, root_clear_pass_id, device_viewport_rect, gfx::Transform()); |
| 346 AddQuad(root_clear_pass, device_viewport_rect, SK_ColorGREEN); | 347 AddQuad(root_clear_pass, device_viewport_rect, SK_ColorGREEN); |
| 347 | 348 |
| 348 renderer()->DecideRenderPassAllocationsForFrame(list); | 349 renderer()->DecideRenderPassAllocationsForFrame(list); |
| 349 | 350 |
| 350 scoped_ptr<SkBitmap> output = | 351 scoped_ptr<SkBitmap> output = |
| 351 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); | 352 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); |
| 352 EXPECT_EQ(device_viewport_rect.width(), output->info().fWidth); | 353 EXPECT_EQ(device_viewport_rect.width(), output->info().fWidth); |
| 353 EXPECT_EQ(device_viewport_rect.width(), output->info().fHeight); | 354 EXPECT_EQ(device_viewport_rect.height(), output->info().fHeight); |
| 354 | 355 |
| 355 EXPECT_EQ(SK_ColorGREEN, output->getColor(0, 0)); | 356 EXPECT_EQ(SK_ColorGREEN, output->getColor(0, 0)); |
| 356 EXPECT_EQ(SK_ColorGREEN, | 357 EXPECT_EQ(SK_ColorGREEN, |
| 357 output->getColor(device_viewport_rect.width() - 1, | 358 output->getColor(device_viewport_rect.width() - 1, |
| 358 device_viewport_rect.height() - 1)); | 359 device_viewport_rect.height() - 1)); |
| 359 | 360 |
| 360 list.clear(); | 361 list.clear(); |
| 361 | 362 |
| 362 // Draw a smaller magenta rect without filling the viewport in a separate | 363 // Draw a smaller magenta rect without filling the viewport in a separate |
| 363 // frame. | 364 // frame. |
| 364 gfx::Rect smaller_rect(20, 20, 60, 60); | 365 gfx::Rect smaller_rect(20, 20, 60, 60); |
| 365 | 366 |
| 366 RenderPassId root_smaller_pass_id(2, 0); | 367 RenderPassId root_smaller_pass_id(2, 0); |
| 367 TestRenderPass* root_smaller_pass = AddRenderPass( | 368 TestRenderPass* root_smaller_pass = AddRenderPass( |
| 368 &list, root_smaller_pass_id, device_viewport_rect, gfx::Transform()); | 369 &list, root_smaller_pass_id, device_viewport_rect, gfx::Transform()); |
| 369 AddQuad(root_smaller_pass, smaller_rect, SK_ColorMAGENTA); | 370 AddQuad(root_smaller_pass, smaller_rect, SK_ColorMAGENTA); |
| 370 | 371 |
| 371 renderer()->DecideRenderPassAllocationsForFrame(list); | 372 renderer()->DecideRenderPassAllocationsForFrame(list); |
| 372 | 373 |
| 373 output = DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); | 374 output = DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); |
| 374 EXPECT_EQ(device_viewport_rect.width(), output->info().fWidth); | 375 EXPECT_EQ(device_viewport_rect.width(), output->info().fWidth); |
| 375 EXPECT_EQ(device_viewport_rect.width(), output->info().fHeight); | 376 EXPECT_EQ(device_viewport_rect.height(), output->info().fHeight); |
| 376 | 377 |
| 377 // If we didn't clear, the borders should still be green. | 378 // If we didn't clear, the borders should still be green. |
| 378 EXPECT_EQ(SK_ColorGREEN, output->getColor(0, 0)); | 379 EXPECT_EQ(SK_ColorGREEN, output->getColor(0, 0)); |
| 379 EXPECT_EQ(SK_ColorGREEN, | 380 EXPECT_EQ(SK_ColorGREEN, |
| 380 output->getColor(device_viewport_rect.width() - 1, | 381 output->getColor(device_viewport_rect.width() - 1, |
| 381 device_viewport_rect.height() - 1)); | 382 device_viewport_rect.height() - 1)); |
| 382 | 383 |
| 383 EXPECT_EQ(SK_ColorMAGENTA, | 384 EXPECT_EQ(SK_ColorMAGENTA, |
| 384 output->getColor(smaller_rect.x(), smaller_rect.y())); | 385 output->getColor(smaller_rect.x(), smaller_rect.y())); |
| 385 EXPECT_EQ( | 386 EXPECT_EQ( |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 410 | 411 |
| 411 // Interior pass quad has smaller visible rect. | 412 // Interior pass quad has smaller visible rect. |
| 412 gfx::Rect interior_visible_rect(30, 30, 40, 40); | 413 gfx::Rect interior_visible_rect(30, 30, 40, 40); |
| 413 root_clear_pass->quad_list.front()->visible_rect = interior_visible_rect; | 414 root_clear_pass->quad_list.front()->visible_rect = interior_visible_rect; |
| 414 | 415 |
| 415 renderer()->DecideRenderPassAllocationsForFrame(list); | 416 renderer()->DecideRenderPassAllocationsForFrame(list); |
| 416 | 417 |
| 417 scoped_ptr<SkBitmap> output = | 418 scoped_ptr<SkBitmap> output = |
| 418 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); | 419 DrawAndCopyOutput(&list, device_scale_factor, device_viewport_rect); |
| 419 EXPECT_EQ(device_viewport_rect.width(), output->info().fWidth); | 420 EXPECT_EQ(device_viewport_rect.width(), output->info().fWidth); |
| 420 EXPECT_EQ(device_viewport_rect.width(), output->info().fHeight); | 421 EXPECT_EQ(device_viewport_rect.height(), output->info().fHeight); |
| 421 | 422 |
| 422 EXPECT_EQ(SK_ColorGREEN, output->getColor(0, 0)); | 423 EXPECT_EQ(SK_ColorGREEN, output->getColor(0, 0)); |
| 423 EXPECT_EQ(SK_ColorGREEN, | 424 EXPECT_EQ(SK_ColorGREEN, |
| 424 output->getColor(device_viewport_rect.width() - 1, | 425 output->getColor(device_viewport_rect.width() - 1, |
| 425 device_viewport_rect.height() - 1)); | 426 device_viewport_rect.height() - 1)); |
| 426 | 427 |
| 427 // Part outside visible rect should remain green. | 428 // Part outside visible rect should remain green. |
| 428 EXPECT_EQ(SK_ColorGREEN, | 429 EXPECT_EQ(SK_ColorGREEN, |
| 429 output->getColor(smaller_rect.x(), smaller_rect.y())); | 430 output->getColor(smaller_rect.x(), smaller_rect.y())); |
| 430 EXPECT_EQ( | 431 EXPECT_EQ( |
| 431 SK_ColorGREEN, | 432 SK_ColorGREEN, |
| 432 output->getColor(smaller_rect.right() - 1, smaller_rect.bottom() - 1)); | 433 output->getColor(smaller_rect.right() - 1, smaller_rect.bottom() - 1)); |
| 433 | 434 |
| 434 EXPECT_EQ( | 435 EXPECT_EQ( |
| 435 SK_ColorMAGENTA, | 436 SK_ColorMAGENTA, |
| 436 output->getColor(interior_visible_rect.x(), interior_visible_rect.y())); | 437 output->getColor(interior_visible_rect.x(), interior_visible_rect.y())); |
| 437 EXPECT_EQ(SK_ColorMAGENTA, | 438 EXPECT_EQ(SK_ColorMAGENTA, |
| 438 output->getColor(interior_visible_rect.right() - 1, | 439 output->getColor(interior_visible_rect.right() - 1, |
| 439 interior_visible_rect.bottom() - 1)); | 440 interior_visible_rect.bottom() - 1)); |
| 440 } | 441 } |
| 441 | 442 |
| 442 } // namespace | 443 } // namespace |
| 443 } // namespace cc | 444 } // namespace cc |
| OLD | NEW |