Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/message_loop/message_loop_proxy.h" | 6 #include "base/message_loop/message_loop_proxy.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "content/browser/gpu/gpu_data_manager_impl.h" | 9 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 10 #include "content/browser/renderer_host/render_widget_host_impl.h" | 10 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 191 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 192 // Note: Not appending kForceCompositingMode switch here, since not all bots | 192 // Note: Not appending kForceCompositingMode switch here, since not all bots |
| 193 // support compositing. Some bots will run with compositing on, and others | 193 // support compositing. Some bots will run with compositing on, and others |
| 194 // won't. Therefore, the call to SetUpSourceSurface() later on will detect | 194 // won't. Therefore, the call to SetUpSourceSurface() later on will detect |
| 195 // whether compositing mode is actually on or not. If not, the tests will | 195 // whether compositing mode is actually on or not. If not, the tests will |
| 196 // pass blindly, logging a warning message, since we cannot test what the | 196 // pass blindly, logging a warning message, since we cannot test what the |
| 197 // platform/implementation does not support. | 197 // platform/implementation does not support. |
| 198 RenderWidgetHostViewBrowserTest::SetUpCommandLine(command_line); | 198 RenderWidgetHostViewBrowserTest::SetUpCommandLine(command_line); |
| 199 } | 199 } |
| 200 | 200 |
| 201 virtual GURL TestUrl() { | |
| 202 return net::FilePathToFileURL( | |
| 203 test_dir().AppendASCII("rwhv_compositing_animation.html")); | |
| 204 } | |
| 205 | |
| 201 virtual bool SetUpSourceSurface() OVERRIDE { | 206 virtual bool SetUpSourceSurface() OVERRIDE { |
| 202 if (!IsForceCompositingModeEnabled()) | 207 if (!IsForceCompositingModeEnabled()) |
| 203 return false; // See comment in SetUpCommandLine(). | 208 return false; // See comment in SetUpCommandLine(). |
| 204 #if defined(OS_MACOSX) | 209 #if defined(OS_MACOSX) |
| 205 CHECK(IOSurfaceSupport::Initialize()); | 210 CHECK(IOSurfaceSupport::Initialize()); |
| 206 #endif | 211 #endif |
| 207 NavigateToURL(shell(), net::FilePathToFileURL( | 212 NavigateToURL(shell(), TestUrl()); |
| 208 test_dir().AppendASCII("rwhv_compositing_animation.html"))); | |
| 209 #if !defined(USE_AURA) | 213 #if !defined(USE_AURA) |
| 210 if (!GetRenderWidgetHost()->is_accelerated_compositing_active()) | 214 if (!GetRenderWidgetHost()->is_accelerated_compositing_active()) |
| 211 return false; // Renderer did not turn on accelerated compositing. | 215 return false; // Renderer did not turn on accelerated compositing. |
| 212 #endif | 216 #endif |
| 213 | 217 |
| 214 // Using accelerated compositing, but a compositing surface might not be | 218 // Using accelerated compositing, but a compositing surface might not be |
| 215 // available yet. So, wait for it. | 219 // available yet. So, wait for it. |
| 216 WaitForCopySourceReady(); | 220 WaitForCopySourceReady(); |
| 217 return true; | 221 return true; |
| 218 } | 222 } |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 base::Unretained(this), | 415 base::Unretained(this), |
| 412 base::MessageLoopProxy::current(), | 416 base::MessageLoopProxy::current(), |
| 413 run_loop.QuitClosure(), | 417 run_loop.QuitClosure(), |
| 414 base::Time::Now())); | 418 base::Time::Now())); |
| 415 run_loop.Run(); | 419 run_loop.Run(); |
| 416 | 420 |
| 417 EXPECT_EQ(2, callback_invoke_count()); | 421 EXPECT_EQ(2, callback_invoke_count()); |
| 418 EXPECT_EQ(2, frames_captured()); | 422 EXPECT_EQ(2, frames_captured()); |
| 419 } | 423 } |
| 420 | 424 |
| 425 class CompositingRenderWidgetHostViewBrowserTestTabCapture | |
| 426 : public CompositingRenderWidgetHostViewBrowserTest { | |
| 427 public: | |
| 428 CompositingRenderWidgetHostViewBrowserTestTabCapture() | |
| 429 : expected_copy_from_compositing_surface_result_(false), | |
| 430 allowable_error_(0), | |
| 431 test_url_("data:text/html,<!doctype html>") {} | |
| 432 | |
| 433 void CopyFromCompositingSurfaceCallback(bool result, const SkBitmap& bitmap) { | |
| 434 EXPECT_EQ(expected_copy_from_compositing_surface_result_, result); | |
| 435 | |
| 436 const SkBitmap& expected_bitmap = | |
| 437 expected_copy_from_compositing_surface_bitmap_; | |
| 438 EXPECT_EQ(expected_bitmap.width(), bitmap.width()); | |
| 439 EXPECT_EQ(expected_bitmap.height(), bitmap.height()); | |
| 440 EXPECT_EQ(expected_bitmap.config(), bitmap.config()); | |
| 441 SkAutoLockPixels expected_bitmap_lock(expected_bitmap); | |
| 442 SkAutoLockPixels bitmap_lock(bitmap); | |
| 443 int fails = 0; | |
| 444 for (int i = 0; i < bitmap.width() && fails < 10; ++i) { | |
| 445 for (int j = 0; j < bitmap.height() && fails < 10; ++j) { | |
| 446 SkColor expected_color = expected_bitmap.getColor(i, j); | |
| 447 SkColor color = bitmap.getColor(i, j); | |
| 448 EXPECT_NEAR(expected_color, color, allowable_error_) | |
| 449 << "expected_color: " << std::hex << expected_color | |
| 450 << " color: " << color | |
| 451 << " Failed at " << std::dec << i << ", " << j; | |
| 452 if (static_cast<int>(std::abs(expected_color - color)) > | |
| 453 allowable_error_) | |
| 454 ++fails; | |
| 455 } | |
| 456 } | |
| 457 EXPECT_LT(fails, 10); | |
| 458 | |
| 459 base::MessageLoop::current()->Quit(); | |
|
piman
2013/06/28 03:23:13
You can pass in the RunLoop's QuitClosure, so that
danakj
2013/06/28 16:50:12
Ah! Ok, I was going to use the QuitClosure, but th
danakj
2013/06/28 17:58:39
Done.
| |
| 460 } | |
| 461 | |
| 462 void SetExpectedCopyFromCompositingSurfaceResult(bool result, | |
| 463 const SkBitmap& bitmap) { | |
| 464 expected_copy_from_compositing_surface_result_ = result; | |
| 465 expected_copy_from_compositing_surface_bitmap_ = bitmap; | |
| 466 } | |
| 467 | |
| 468 void SetAllowableError(int amount) { allowable_error_ = amount; } | |
| 469 | |
| 470 virtual GURL TestUrl() OVERRIDE { | |
| 471 return GURL(test_url_); | |
| 472 } | |
| 473 | |
| 474 virtual void SetUp() OVERRIDE { | |
| 475 ui::DisableTestCompositor(); | |
| 476 CompositingRenderWidgetHostViewBrowserTest::SetUp(); | |
| 477 } | |
| 478 | |
| 479 void SetTestUrl(std::string url) { test_url_ = url; } | |
| 480 | |
| 481 private: | |
| 482 bool expected_copy_from_compositing_surface_result_; | |
| 483 SkBitmap expected_copy_from_compositing_surface_bitmap_; | |
| 484 int allowable_error_; | |
| 485 std::string test_url_; | |
| 486 }; | |
| 487 | |
| 488 IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTestTabCapture, | |
| 489 CopyFromCompositingSurface_WholeSurface_Unscaled) { | |
| 490 SetTestUrl("data:text/html,<!doctype html>" | |
| 491 "<div class='left'></div>" | |
| 492 "<style>" | |
| 493 "body { background: #ff0; padding: 0; margin: 0; }" | |
| 494 ".left { background: #0ff;" | |
| 495 " width: 50%;" | |
| 496 " height: 506px;" | |
| 497 "}" | |
| 498 "</style>"); | |
| 499 | |
| 500 SET_UP_SURFACE_OR_PASS_TEST(); | |
| 501 | |
| 502 RenderViewHost* const rwh = | |
| 503 shell()->web_contents()->GetRenderViewHost(); | |
| 504 RenderWidgetHostViewPort* rwhvp = | |
| 505 static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); | |
| 506 | |
| 507 gfx::Rect bounds = gfx::Rect(rwhvp->GetViewBounds().size()); | |
| 508 EXPECT_EQ(gfx::Rect(766, 506).ToString(), bounds.ToString()); | |
|
piman
2013/06/28 03:23:13
Is this size expected to be stable across platform
danakj
2013/06/28 16:50:12
Ya I wasn't sure, so I put this to see and run the
danakj
2013/06/28 17:58:39
Using just the top left 400x300 now. We'll see wha
| |
| 509 | |
| 510 gfx::Size out_size = bounds.size(); | |
| 511 | |
| 512 SkBitmap expected_bitmap; | |
| 513 expected_bitmap.setConfig( | |
| 514 SkBitmap::kARGB_8888_Config, out_size.width(), out_size.height()); | |
| 515 expected_bitmap.allocPixels(); | |
| 516 // Left half is #0ff. | |
| 517 expected_bitmap.eraseARGB(255, 0, 255, 255); | |
| 518 // Right half is #0ff. | |
| 519 { | |
| 520 SkAutoLockPixels lock(expected_bitmap); | |
| 521 for (int i = 0; i < out_size.width() / 2; ++i) { | |
| 522 for (int j = 0; j < out_size.height(); ++j) { | |
| 523 *expected_bitmap.getAddr32(out_size.width() / 2 + i, j) = | |
| 524 SkColorSetARGB(255, 255, 255, 0);; | |
| 525 } | |
| 526 } | |
| 527 } | |
| 528 SetExpectedCopyFromCompositingSurfaceResult(true, expected_bitmap); | |
| 529 | |
| 530 base::Callback<void(bool, const SkBitmap&)> callback = base::Bind( | |
| 531 &CompositingRenderWidgetHostViewBrowserTestTabCapture:: | |
| 532 CopyFromCompositingSurfaceCallback, | |
| 533 base::Unretained(this)); | |
| 534 rwhvp->CopyFromCompositingSurface(bounds, out_size, callback); | |
| 535 | |
| 536 base::RunLoop run_loop; | |
| 537 run_loop.Run(); | |
| 538 } | |
| 539 | |
| 540 IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTestTabCapture, | |
| 541 CopyFromCompositingSurface_WholeSurface_Scaled) { | |
| 542 SetTestUrl("data:text/html,<!doctype html>" | |
| 543 "<div class='left'></div>" | |
| 544 "<style>" | |
| 545 "body { background: #ff0; padding: 0; margin: 0; }" | |
| 546 ".left { background: #0ff;" | |
| 547 " width: 50%;" | |
| 548 " height: 506px;" | |
| 549 "}" | |
| 550 "</style>"); | |
| 551 | |
| 552 SET_UP_SURFACE_OR_PASS_TEST(); | |
| 553 | |
| 554 RenderViewHost* const rwh = | |
| 555 shell()->web_contents()->GetRenderViewHost(); | |
| 556 RenderWidgetHostViewPort* rwhvp = | |
| 557 static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); | |
| 558 | |
| 559 gfx::Rect bounds = gfx::Rect(rwhvp->GetViewBounds().size()); | |
| 560 EXPECT_EQ(gfx::Rect(766, 506).ToString(), bounds.ToString()); | |
| 561 | |
| 562 // Scale the output to 400x300. | |
| 563 gfx::Size out_size(400, 300); | |
| 564 | |
| 565 SkBitmap expected_bitmap; | |
| 566 expected_bitmap.setConfig( | |
| 567 SkBitmap::kARGB_8888_Config, out_size.width(), out_size.height()); | |
| 568 expected_bitmap.allocPixels(); | |
| 569 // Left half is #0ff. | |
| 570 expected_bitmap.eraseARGB(255, 0, 255, 255); | |
| 571 // Right half is #0ff. | |
| 572 { | |
| 573 SkAutoLockPixels lock(expected_bitmap); | |
| 574 for (int i = 0; i < out_size.width() / 2; ++i) { | |
| 575 for (int j = 0; j < out_size.height(); ++j) { | |
| 576 *expected_bitmap.getAddr32(out_size.width() / 2 + i, j) = | |
| 577 SkColorSetARGB(255, 255, 255, 0);; | |
| 578 } | |
| 579 } | |
| 580 } | |
| 581 SetExpectedCopyFromCompositingSurfaceResult(true, expected_bitmap); | |
| 582 | |
| 583 base::Callback<void(bool, const SkBitmap&)> callback = base::Bind( | |
| 584 &CompositingRenderWidgetHostViewBrowserTestTabCapture:: | |
| 585 CopyFromCompositingSurfaceCallback, | |
| 586 base::Unretained(this)); | |
| 587 rwhvp->CopyFromCompositingSurface(bounds, out_size, callback); | |
| 588 | |
| 589 base::RunLoop run_loop; | |
| 590 run_loop.Run(); | |
| 591 } | |
| 592 | |
| 593 IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTestTabCapture, | |
| 594 CopyFromCompositingSurface_CroppedSurface_Unscaled) { | |
| 595 SetTestUrl("data:text/html,<!doctype html>" | |
| 596 "<div class='left'></div>" | |
| 597 "<style>" | |
| 598 "body { background: #ff0; padding: 0; margin: 0; }" | |
| 599 ".left { background: #0ff;" | |
| 600 " width: 50%;" | |
| 601 " height: 506px;" | |
| 602 "}" | |
| 603 "</style>"); | |
| 604 | |
| 605 SET_UP_SURFACE_OR_PASS_TEST(); | |
| 606 | |
| 607 RenderViewHost* const rwh = | |
| 608 shell()->web_contents()->GetRenderViewHost(); | |
| 609 RenderWidgetHostViewPort* rwhvp = | |
| 610 static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); | |
| 611 | |
| 612 gfx::Rect bounds = gfx::Rect(rwhvp->GetViewBounds().size()); | |
| 613 EXPECT_EQ(gfx::Rect(766, 506).ToString(), bounds.ToString()); | |
| 614 | |
| 615 // Grab 60x60 pixels from the center of the tab contents. | |
| 616 bounds = gfx::Rect(bounds.CenterPoint() - gfx::Vector2d(30, 30), | |
| 617 gfx::Size(60, 60)); | |
| 618 gfx::Size out_size = bounds.size(); | |
| 619 | |
| 620 SkBitmap expected_bitmap; | |
| 621 expected_bitmap.setConfig( | |
| 622 SkBitmap::kARGB_8888_Config, out_size.width(), out_size.height()); | |
| 623 expected_bitmap.allocPixels(); | |
| 624 // Left half is #0ff. | |
| 625 expected_bitmap.eraseARGB(255, 0, 255, 255); | |
| 626 // Right half is #0ff. | |
| 627 { | |
| 628 SkAutoLockPixels lock(expected_bitmap); | |
| 629 for (int i = 0; i < out_size.width() / 2; ++i) { | |
| 630 for (int j = 0; j < out_size.height(); ++j) { | |
| 631 *expected_bitmap.getAddr32(out_size.width() / 2 + i, j) = | |
| 632 SkColorSetARGB(255, 255, 255, 0);; | |
| 633 } | |
| 634 } | |
| 635 } | |
| 636 SetExpectedCopyFromCompositingSurfaceResult(true, expected_bitmap); | |
| 637 | |
| 638 base::Callback<void(bool, const SkBitmap&)> callback = base::Bind( | |
| 639 &CompositingRenderWidgetHostViewBrowserTestTabCapture:: | |
| 640 CopyFromCompositingSurfaceCallback, | |
| 641 base::Unretained(this)); | |
| 642 rwhvp->CopyFromCompositingSurface(bounds, out_size, callback); | |
| 643 | |
| 644 base::RunLoop run_loop; | |
| 645 run_loop.Run(); | |
| 646 } | |
| 647 | |
| 648 IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTestTabCapture, | |
| 649 CopyFromCompositingSurface_CroppedSurface_Scaled) { | |
| 650 SetTestUrl("data:text/html,<!doctype html>" | |
| 651 "<div class='left'></div>" | |
| 652 "<style>" | |
| 653 "body { background: #ff0; padding: 0; margin: 0; }" | |
| 654 ".left { background: #0ff;" | |
| 655 " width: 50%;" | |
| 656 " height: 506px;" | |
| 657 "}" | |
| 658 "</style>"); | |
| 659 | |
| 660 SET_UP_SURFACE_OR_PASS_TEST(); | |
| 661 | |
| 662 RenderViewHost* const rwh = | |
| 663 shell()->web_contents()->GetRenderViewHost(); | |
| 664 RenderWidgetHostViewPort* rwhvp = | |
| 665 static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); | |
| 666 | |
| 667 gfx::Rect bounds = gfx::Rect(rwhvp->GetViewBounds().size()); | |
| 668 EXPECT_EQ(gfx::Rect(766, 506).ToString(), bounds.ToString()); | |
| 669 | |
| 670 // Grab 60x60 pixels from the center of the tab contents. | |
| 671 bounds = gfx::Rect(bounds.CenterPoint() - gfx::Vector2d(30, 30), | |
| 672 gfx::Size(60, 60)); | |
| 673 | |
| 674 // Scale to 20 x 10. | |
| 675 gfx::Size out_size(20, 10); | |
| 676 | |
| 677 SkBitmap expected_bitmap; | |
| 678 expected_bitmap.setConfig( | |
| 679 SkBitmap::kARGB_8888_Config, out_size.width(), out_size.height()); | |
| 680 expected_bitmap.allocPixels(); | |
| 681 // Left half is #0ff. | |
| 682 expected_bitmap.eraseARGB(255, 0, 255, 255); | |
| 683 // Right half is #0ff. | |
| 684 { | |
| 685 SkAutoLockPixels lock(expected_bitmap); | |
| 686 for (int i = 0; i < out_size.width() / 2; ++i) { | |
| 687 for (int j = 0; j < out_size.height(); ++j) { | |
| 688 *expected_bitmap.getAddr32(out_size.width() / 2 + i, j) = | |
| 689 SkColorSetARGB(255, 255, 255, 0);; | |
| 690 } | |
| 691 } | |
| 692 } | |
| 693 SetExpectedCopyFromCompositingSurfaceResult(true, expected_bitmap); | |
| 694 | |
| 695 base::Callback<void(bool, const SkBitmap&)> callback = base::Bind( | |
| 696 &CompositingRenderWidgetHostViewBrowserTestTabCapture:: | |
| 697 CopyFromCompositingSurfaceCallback, | |
| 698 base::Unretained(this)); | |
| 699 rwhvp->CopyFromCompositingSurface(bounds, out_size, callback); | |
| 700 | |
| 701 base::RunLoop run_loop; | |
| 702 run_loop.Run(); | |
| 703 } | |
| 704 | |
| 421 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 705 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
| 422 | 706 |
| 423 } // namespace | 707 } // namespace |
| 424 } // namespace content | 708 } // namespace content |
| OLD | NEW |