OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 #include "cc/layers/content_layer.h" |
6 #include "cc/output/copy_output_request.h" | 7 #include "cc/output/copy_output_request.h" |
7 #include "cc/output/copy_output_result.h" | 8 #include "cc/output/copy_output_result.h" |
8 #include "cc/test/layer_tree_pixel_test.h" | 9 #include "cc/test/layer_tree_pixel_test.h" |
9 #include "cc/test/paths.h" | 10 #include "cc/test/paths.h" |
| 11 #include "cc/test/solid_color_content_layer_client.h" |
| 12 #include "cc/trees/layer_tree_impl.h" |
10 | 13 |
11 #if !defined(OS_ANDROID) | 14 #if !defined(OS_ANDROID) |
12 | 15 |
13 namespace cc { | 16 namespace cc { |
14 namespace { | 17 namespace { |
15 | 18 |
16 class LayerTreeHostReadbackPixelTest : public LayerTreePixelTest { | 19 class LayerTreeHostReadbackPixelTest : public LayerTreePixelTest { |
17 protected: | 20 protected: |
18 virtual scoped_ptr<CopyOutputRequest> CreateCopyOutputRequest() OVERRIDE { | 21 virtual scoped_ptr<CopyOutputRequest> CreateCopyOutputRequest() OVERRIDE { |
19 scoped_ptr<CopyOutputRequest> request; | 22 scoped_ptr<CopyOutputRequest> request; |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 gfx::Rect(200, 200), SK_ColorWHITE); | 334 gfx::Rect(200, 200), SK_ColorWHITE); |
332 | 335 |
333 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 336 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
334 gfx::Rect(200, 200), SK_ColorGREEN); | 337 gfx::Rect(200, 200), SK_ColorGREEN); |
335 background->AddChild(green); | 338 background->AddChild(green); |
336 | 339 |
337 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( | 340 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
338 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE); | 341 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE); |
339 green->AddChild(blue); | 342 green->AddChild(blue); |
340 | 343 |
341 // Grab the middle of the viewport. | 344 // Grab the middle of the root layer. |
342 copy_subrect_ = gfx::Rect(50, 50, 100, 100); | 345 copy_subrect_ = gfx::Rect(50, 50, 100, 100); |
343 | 346 |
344 RunPixelTest(SOFTWARE_WITH_DEFAULT, | 347 RunPixelTest(SOFTWARE_WITH_DEFAULT, |
345 background, | 348 background, |
346 base::FilePath(FILE_PATH_LITERAL( | 349 base::FilePath(FILE_PATH_LITERAL( |
347 "green_small_with_blue_corner.png"))); | 350 "green_small_with_blue_corner.png"))); |
348 } | 351 } |
349 | 352 |
350 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSubrect_GL_Bitmap) { | 353 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSubrect_GL_Bitmap) { |
351 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 354 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
352 gfx::Rect(200, 200), SK_ColorWHITE); | 355 gfx::Rect(200, 200), SK_ColorWHITE); |
353 | 356 |
354 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 357 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
355 gfx::Rect(200, 200), SK_ColorGREEN); | 358 gfx::Rect(200, 200), SK_ColorGREEN); |
356 background->AddChild(green); | 359 background->AddChild(green); |
357 | 360 |
358 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( | 361 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
359 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE); | 362 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE); |
360 green->AddChild(blue); | 363 green->AddChild(blue); |
361 | 364 |
362 // Grab the middle of the viewport. | 365 // Grab the middle of the root layer. |
363 copy_subrect_ = gfx::Rect(50, 50, 100, 100); | 366 copy_subrect_ = gfx::Rect(50, 50, 100, 100); |
364 | 367 |
365 RunPixelTest(GL_WITH_BITMAP, | 368 RunPixelTest(GL_WITH_BITMAP, |
366 background, | 369 background, |
367 base::FilePath(FILE_PATH_LITERAL( | 370 base::FilePath(FILE_PATH_LITERAL( |
368 "green_small_with_blue_corner.png"))); | 371 "green_small_with_blue_corner.png"))); |
369 } | 372 } |
370 | 373 |
371 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSubrect_GL) { | 374 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackSubrect_GL) { |
372 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 375 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
373 gfx::Rect(200, 200), SK_ColorWHITE); | 376 gfx::Rect(200, 200), SK_ColorWHITE); |
374 | 377 |
375 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 378 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
376 gfx::Rect(200, 200), SK_ColorGREEN); | 379 gfx::Rect(200, 200), SK_ColorGREEN); |
377 background->AddChild(green); | 380 background->AddChild(green); |
378 | 381 |
379 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( | 382 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
380 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE); | 383 gfx::Rect(100, 100, 50, 50), SK_ColorBLUE); |
381 green->AddChild(blue); | 384 green->AddChild(blue); |
382 | 385 |
383 // Grab the middle of the viewport. | 386 // Grab the middle of the root layer. |
384 copy_subrect_ = gfx::Rect(50, 50, 100, 100); | 387 copy_subrect_ = gfx::Rect(50, 50, 100, 100); |
385 | 388 |
386 RunPixelTest(GL_WITH_DEFAULT, | 389 RunPixelTest(GL_WITH_DEFAULT, |
387 background, | 390 background, |
388 base::FilePath(FILE_PATH_LITERAL( | 391 base::FilePath(FILE_PATH_LITERAL( |
389 "green_small_with_blue_corner.png"))); | 392 "green_small_with_blue_corner.png"))); |
390 } | 393 } |
391 | 394 |
392 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect_Software) { | 395 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect_Software) { |
393 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 396 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
394 gfx::Rect(200, 200), SK_ColorWHITE); | 397 gfx::Rect(200, 200), SK_ColorWHITE); |
395 | 398 |
396 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 399 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
397 gfx::Rect(25, 25, 150, 150), SK_ColorGREEN); | 400 gfx::Rect(25, 25, 150, 150), SK_ColorGREEN); |
398 background->AddChild(green); | 401 background->AddChild(green); |
399 | 402 |
400 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( | 403 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
401 gfx::Rect(75, 75, 50, 50), SK_ColorBLUE); | 404 gfx::Rect(75, 75, 50, 50), SK_ColorBLUE); |
402 green->AddChild(blue); | 405 green->AddChild(blue); |
403 | 406 |
404 // Grab the middle of the viewport. | 407 // Grab the middle of the green layer. |
405 copy_subrect_ = gfx::Rect(25, 25, 100, 100); | 408 copy_subrect_ = gfx::Rect(25, 25, 100, 100); |
406 | 409 |
407 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT, | 410 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT, |
408 background, | 411 background, |
409 green.get(), | 412 green.get(), |
410 base::FilePath(FILE_PATH_LITERAL( | 413 base::FilePath(FILE_PATH_LITERAL( |
411 "green_small_with_blue_corner.png"))); | 414 "green_small_with_blue_corner.png"))); |
412 } | 415 } |
413 | 416 |
414 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect_GL_Bitmap) { | 417 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect_GL_Bitmap) { |
415 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 418 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
416 gfx::Rect(200, 200), SK_ColorWHITE); | 419 gfx::Rect(200, 200), SK_ColorWHITE); |
417 | 420 |
418 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 421 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
419 gfx::Rect(25, 25, 150, 150), SK_ColorGREEN); | 422 gfx::Rect(25, 25, 150, 150), SK_ColorGREEN); |
420 background->AddChild(green); | 423 background->AddChild(green); |
421 | 424 |
422 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( | 425 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
423 gfx::Rect(75, 75, 50, 50), SK_ColorBLUE); | 426 gfx::Rect(75, 75, 50, 50), SK_ColorBLUE); |
424 green->AddChild(blue); | 427 green->AddChild(blue); |
425 | 428 |
426 // Grab the middle of the viewport. | 429 // Grab the middle of the green layer. |
427 copy_subrect_ = gfx::Rect(25, 25, 100, 100); | 430 copy_subrect_ = gfx::Rect(25, 25, 100, 100); |
428 | 431 |
429 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP, | 432 RunPixelTestWithReadbackTarget(GL_WITH_BITMAP, |
430 background, | 433 background, |
431 green.get(), | 434 green.get(), |
432 base::FilePath(FILE_PATH_LITERAL( | 435 base::FilePath(FILE_PATH_LITERAL( |
433 "green_small_with_blue_corner.png"))); | 436 "green_small_with_blue_corner.png"))); |
434 } | 437 } |
435 | 438 |
436 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect_GL) { | 439 TEST_F(LayerTreeHostReadbackPixelTest, ReadbackNonRootLayerSubrect_GL) { |
437 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 440 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
438 gfx::Rect(200, 200), SK_ColorWHITE); | 441 gfx::Rect(200, 200), SK_ColorWHITE); |
439 | 442 |
440 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( | 443 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( |
441 gfx::Rect(25, 25, 150, 150), SK_ColorGREEN); | 444 gfx::Rect(25, 25, 150, 150), SK_ColorGREEN); |
442 background->AddChild(green); | 445 background->AddChild(green); |
443 | 446 |
444 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( | 447 scoped_refptr<SolidColorLayer> blue = CreateSolidColorLayer( |
445 gfx::Rect(75, 75, 50, 50), SK_ColorBLUE); | 448 gfx::Rect(75, 75, 50, 50), SK_ColorBLUE); |
446 green->AddChild(blue); | 449 green->AddChild(blue); |
447 | 450 |
448 // Grab the middle of the viewport. | 451 // Grab the middle of the green layer. |
449 copy_subrect_ = gfx::Rect(25, 25, 100, 100); | 452 copy_subrect_ = gfx::Rect(25, 25, 100, 100); |
450 | 453 |
451 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, | 454 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, |
452 background, | 455 background, |
453 green.get(), | 456 green.get(), |
454 base::FilePath(FILE_PATH_LITERAL( | 457 base::FilePath(FILE_PATH_LITERAL( |
455 "green_small_with_blue_corner.png"))); | 458 "green_small_with_blue_corner.png"))); |
456 } | 459 } |
457 | 460 |
| 461 class LayerTreeHostReadbackDeviceScalePixelTest |
| 462 : public LayerTreeHostReadbackPixelTest { |
| 463 protected: |
| 464 LayerTreeHostReadbackDeviceScalePixelTest() |
| 465 : device_scale_factor_(1.f), |
| 466 white_client_(SK_ColorWHITE), |
| 467 green_client_(SK_ColorGREEN), |
| 468 blue_client_(SK_ColorBLUE) {} |
| 469 |
| 470 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 471 // Cause the device scale factor to be inherited by contents scales. |
| 472 settings->layer_transforms_should_scale_layer_contents = true; |
| 473 } |
| 474 |
| 475 virtual void SetupTree() OVERRIDE { |
| 476 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_); |
| 477 LayerTreePixelTest::SetupTree(); |
| 478 } |
| 479 |
| 480 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 481 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); |
| 482 |
| 483 LayerImpl* background_impl = root_impl->children()[0]; |
| 484 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_x()); |
| 485 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_y()); |
| 486 |
| 487 LayerImpl* green_impl = background_impl->children()[0]; |
| 488 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_x()); |
| 489 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_y()); |
| 490 |
| 491 LayerImpl* blue_impl = green_impl->children()[0]; |
| 492 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_x()); |
| 493 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_y()); |
| 494 } |
| 495 |
| 496 float device_scale_factor_; |
| 497 SolidColorContentLayerClient white_client_; |
| 498 SolidColorContentLayerClient green_client_; |
| 499 SolidColorContentLayerClient blue_client_; |
| 500 }; |
| 501 |
| 502 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest, |
| 503 ReadbackSubrect_Software) { |
| 504 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 505 background->SetAnchorPoint(gfx::PointF()); |
| 506 background->SetBounds(gfx::Size(100, 100)); |
| 507 background->SetIsDrawable(true); |
| 508 |
| 509 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 510 green->SetAnchorPoint(gfx::PointF()); |
| 511 green->SetBounds(gfx::Size(100, 100)); |
| 512 green->SetIsDrawable(true); |
| 513 background->AddChild(green); |
| 514 |
| 515 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 516 blue->SetAnchorPoint(gfx::PointF()); |
| 517 blue->SetPosition(gfx::Point(50, 50)); |
| 518 blue->SetBounds(gfx::Size(25, 25)); |
| 519 blue->SetIsDrawable(true); |
| 520 green->AddChild(blue); |
| 521 |
| 522 // Grab the middle of the root layer. |
| 523 copy_subrect_ = gfx::Rect(25, 25, 50, 50); |
| 524 device_scale_factor_ = 2.f; |
| 525 |
| 526 RunPixelTest(SOFTWARE_WITH_DEFAULT, |
| 527 background, |
| 528 base::FilePath(FILE_PATH_LITERAL( |
| 529 "green_small_with_blue_corner.png"))); |
| 530 } |
| 531 |
| 532 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest, |
| 533 ReadbackSubrect_GL) { |
| 534 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 535 background->SetAnchorPoint(gfx::PointF()); |
| 536 background->SetBounds(gfx::Size(100, 100)); |
| 537 background->SetIsDrawable(true); |
| 538 |
| 539 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 540 green->SetAnchorPoint(gfx::PointF()); |
| 541 green->SetBounds(gfx::Size(100, 100)); |
| 542 green->SetIsDrawable(true); |
| 543 background->AddChild(green); |
| 544 |
| 545 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 546 blue->SetAnchorPoint(gfx::PointF()); |
| 547 blue->SetPosition(gfx::Point(50, 50)); |
| 548 blue->SetBounds(gfx::Size(25, 25)); |
| 549 blue->SetIsDrawable(true); |
| 550 green->AddChild(blue); |
| 551 |
| 552 // Grab the middle of the root layer. |
| 553 copy_subrect_ = gfx::Rect(25, 25, 50, 50); |
| 554 device_scale_factor_ = 2.f; |
| 555 |
| 556 RunPixelTest(GL_WITH_DEFAULT, |
| 557 background, |
| 558 base::FilePath(FILE_PATH_LITERAL( |
| 559 "green_small_with_blue_corner.png"))); |
| 560 } |
| 561 |
| 562 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest, |
| 563 ReadbackNonRootLayerSubrect_Software) { |
| 564 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 565 background->SetAnchorPoint(gfx::PointF()); |
| 566 background->SetBounds(gfx::Size(100, 100)); |
| 567 background->SetIsDrawable(true); |
| 568 |
| 569 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 570 green->SetAnchorPoint(gfx::PointF()); |
| 571 green->SetPosition(gfx::Point(10, 20)); |
| 572 green->SetBounds(gfx::Size(90, 80)); |
| 573 green->SetIsDrawable(true); |
| 574 background->AddChild(green); |
| 575 |
| 576 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 577 blue->SetAnchorPoint(gfx::PointF()); |
| 578 blue->SetPosition(gfx::Point(50, 50)); |
| 579 blue->SetBounds(gfx::Size(25, 25)); |
| 580 blue->SetIsDrawable(true); |
| 581 green->AddChild(blue); |
| 582 |
| 583 // Grab the green layer's content with blue in the bottom right. |
| 584 copy_subrect_ = gfx::Rect(25, 25, 50, 50); |
| 585 device_scale_factor_ = 2.f; |
| 586 |
| 587 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT, |
| 588 background, |
| 589 green.get(), |
| 590 base::FilePath(FILE_PATH_LITERAL( |
| 591 "green_small_with_blue_corner.png"))); |
| 592 } |
| 593 |
| 594 TEST_F(LayerTreeHostReadbackDeviceScalePixelTest, |
| 595 ReadbackNonRootLayerSubrect_GL) { |
| 596 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 597 background->SetAnchorPoint(gfx::PointF()); |
| 598 background->SetBounds(gfx::Size(100, 100)); |
| 599 background->SetIsDrawable(true); |
| 600 |
| 601 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 602 green->SetAnchorPoint(gfx::PointF()); |
| 603 green->SetPosition(gfx::Point(10, 20)); |
| 604 green->SetBounds(gfx::Size(90, 80)); |
| 605 green->SetIsDrawable(true); |
| 606 background->AddChild(green); |
| 607 |
| 608 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 609 blue->SetAnchorPoint(gfx::PointF()); |
| 610 blue->SetPosition(gfx::Point(50, 50)); |
| 611 blue->SetBounds(gfx::Size(25, 25)); |
| 612 blue->SetIsDrawable(true); |
| 613 green->AddChild(blue); |
| 614 |
| 615 // Grab the green layer's content with blue in the bottom right. |
| 616 copy_subrect_ = gfx::Rect(25, 25, 50, 50); |
| 617 device_scale_factor_ = 2.f; |
| 618 |
| 619 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, |
| 620 background, |
| 621 green.get(), |
| 622 base::FilePath(FILE_PATH_LITERAL( |
| 623 "green_small_with_blue_corner.png"))); |
| 624 } |
| 625 |
| 626 class LayerTreeHostReadbackViaCompositeAndReadbackPixelTest |
| 627 : public LayerTreePixelTest { |
| 628 protected: |
| 629 LayerTreeHostReadbackViaCompositeAndReadbackPixelTest() |
| 630 : device_scale_factor_(1.f), |
| 631 white_client_(SK_ColorWHITE), |
| 632 green_client_(SK_ColorGREEN), |
| 633 blue_client_(SK_ColorBLUE) {} |
| 634 |
| 635 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 636 // Cause the device scale factor to be inherited by contents scales. |
| 637 settings->layer_transforms_should_scale_layer_contents = true; |
| 638 } |
| 639 |
| 640 virtual void SetupTree() OVERRIDE { |
| 641 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_); |
| 642 LayerTreePixelTest::SetupTree(); |
| 643 } |
| 644 |
| 645 virtual void BeginTest() OVERRIDE { |
| 646 EXPECT_EQ(device_scale_factor_, layer_tree_host()->device_scale_factor()); |
| 647 if (TestEnded()) |
| 648 return; |
| 649 |
| 650 gfx::Rect device_viewport_copy_rect( |
| 651 layer_tree_host()->device_viewport_size()); |
| 652 if (!device_viewport_copy_subrect_.IsEmpty()) |
| 653 device_viewport_copy_rect.Intersect(device_viewport_copy_subrect_); |
| 654 |
| 655 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
| 656 bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 657 device_viewport_copy_rect.width(), |
| 658 device_viewport_copy_rect.height()); |
| 659 bitmap->allocPixels(); |
| 660 { |
| 661 scoped_ptr<SkAutoLockPixels> lock(new SkAutoLockPixels(*bitmap)); |
| 662 layer_tree_host()->CompositeAndReadback(bitmap->getPixels(), |
| 663 device_viewport_copy_rect); |
| 664 } |
| 665 |
| 666 result_bitmap_ = bitmap.Pass(); |
| 667 EndTest(); |
| 668 } |
| 669 |
| 670 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 671 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); |
| 672 |
| 673 LayerImpl* background_impl = root_impl->children()[0]; |
| 674 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_x()); |
| 675 EXPECT_EQ(device_scale_factor_, background_impl->contents_scale_y()); |
| 676 |
| 677 LayerImpl* green_impl = background_impl->children()[0]; |
| 678 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_x()); |
| 679 EXPECT_EQ(device_scale_factor_, green_impl->contents_scale_y()); |
| 680 |
| 681 LayerImpl* blue_impl = green_impl->children()[0]; |
| 682 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_x()); |
| 683 EXPECT_EQ(device_scale_factor_, blue_impl->contents_scale_y()); |
| 684 } |
| 685 |
| 686 gfx::Rect device_viewport_copy_subrect_; |
| 687 float device_scale_factor_; |
| 688 SolidColorContentLayerClient white_client_; |
| 689 SolidColorContentLayerClient green_client_; |
| 690 SolidColorContentLayerClient blue_client_; |
| 691 }; |
| 692 |
| 693 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest, |
| 694 CompositeAndReadback_Software_1) { |
| 695 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 696 background->SetAnchorPoint(gfx::PointF()); |
| 697 background->SetBounds(gfx::Size(200, 200)); |
| 698 background->SetIsDrawable(true); |
| 699 |
| 700 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 701 green->SetAnchorPoint(gfx::PointF()); |
| 702 green->SetBounds(gfx::Size(200, 200)); |
| 703 green->SetIsDrawable(true); |
| 704 background->AddChild(green); |
| 705 |
| 706 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 707 blue->SetAnchorPoint(gfx::PointF()); |
| 708 blue->SetPosition(gfx::Point(100, 100)); |
| 709 blue->SetBounds(gfx::Size(50, 50)); |
| 710 blue->SetIsDrawable(true); |
| 711 green->AddChild(blue); |
| 712 |
| 713 // Grab the middle of the device viewport. |
| 714 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100); |
| 715 device_scale_factor_ = 1.f; |
| 716 |
| 717 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT, |
| 718 background, |
| 719 green.get(), |
| 720 base::FilePath(FILE_PATH_LITERAL( |
| 721 "green_small_with_blue_corner.png"))); |
| 722 } |
| 723 |
| 724 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest, |
| 725 CompositeAndReadback_Software_2) { |
| 726 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 727 background->SetAnchorPoint(gfx::PointF()); |
| 728 background->SetBounds(gfx::Size(100, 100)); |
| 729 background->SetIsDrawable(true); |
| 730 |
| 731 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 732 green->SetAnchorPoint(gfx::PointF()); |
| 733 green->SetBounds(gfx::Size(100, 100)); |
| 734 green->SetIsDrawable(true); |
| 735 background->AddChild(green); |
| 736 |
| 737 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 738 blue->SetAnchorPoint(gfx::PointF()); |
| 739 blue->SetPosition(gfx::Point(50, 50)); |
| 740 blue->SetBounds(gfx::Size(25, 25)); |
| 741 blue->SetIsDrawable(true); |
| 742 green->AddChild(blue); |
| 743 |
| 744 // Grab the middle of the device viewport. |
| 745 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100); |
| 746 device_scale_factor_ = 2.f; |
| 747 |
| 748 RunPixelTestWithReadbackTarget(SOFTWARE_WITH_DEFAULT, |
| 749 background, |
| 750 green.get(), |
| 751 base::FilePath(FILE_PATH_LITERAL( |
| 752 "green_small_with_blue_corner.png"))); |
| 753 } |
| 754 |
| 755 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest, |
| 756 CompositeAndReadback_GL_1) { |
| 757 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 758 background->SetAnchorPoint(gfx::PointF()); |
| 759 background->SetBounds(gfx::Size(200, 200)); |
| 760 background->SetIsDrawable(true); |
| 761 |
| 762 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 763 green->SetAnchorPoint(gfx::PointF()); |
| 764 green->SetBounds(gfx::Size(200, 200)); |
| 765 green->SetIsDrawable(true); |
| 766 background->AddChild(green); |
| 767 |
| 768 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 769 blue->SetAnchorPoint(gfx::PointF()); |
| 770 blue->SetPosition(gfx::Point(100, 100)); |
| 771 blue->SetBounds(gfx::Size(50, 50)); |
| 772 blue->SetIsDrawable(true); |
| 773 green->AddChild(blue); |
| 774 |
| 775 // Grab the middle of the device viewport. |
| 776 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100); |
| 777 device_scale_factor_ = 1.f; |
| 778 |
| 779 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, |
| 780 background, |
| 781 green.get(), |
| 782 base::FilePath(FILE_PATH_LITERAL( |
| 783 "green_small_with_blue_corner.png"))); |
| 784 } |
| 785 |
| 786 TEST_F(LayerTreeHostReadbackViaCompositeAndReadbackPixelTest, |
| 787 CompositeAndReadback_GL_2) { |
| 788 scoped_refptr<ContentLayer> background = ContentLayer::Create(&white_client_); |
| 789 background->SetAnchorPoint(gfx::PointF()); |
| 790 background->SetBounds(gfx::Size(100, 100)); |
| 791 background->SetIsDrawable(true); |
| 792 |
| 793 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 794 green->SetAnchorPoint(gfx::PointF()); |
| 795 green->SetBounds(gfx::Size(100, 100)); |
| 796 green->SetIsDrawable(true); |
| 797 background->AddChild(green); |
| 798 |
| 799 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 800 blue->SetAnchorPoint(gfx::PointF()); |
| 801 blue->SetPosition(gfx::Point(50, 50)); |
| 802 blue->SetBounds(gfx::Size(25, 25)); |
| 803 blue->SetIsDrawable(true); |
| 804 green->AddChild(blue); |
| 805 |
| 806 // Grab the middle of the device viewport. |
| 807 device_viewport_copy_subrect_ = gfx::Rect(50, 50, 100, 100); |
| 808 device_scale_factor_ = 2.f; |
| 809 |
| 810 RunPixelTestWithReadbackTarget(GL_WITH_DEFAULT, |
| 811 background, |
| 812 green.get(), |
| 813 base::FilePath(FILE_PATH_LITERAL( |
| 814 "green_small_with_blue_corner.png"))); |
| 815 } |
| 816 |
458 } // namespace | 817 } // namespace |
459 } // namespace cc | 818 } // namespace cc |
460 | 819 |
461 #endif // OS_ANDROID | 820 #endif // OS_ANDROID |
OLD | NEW |