| 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/compositor_util.h" | 9 #include "content/browser/gpu/compositor_util.h" |
| 10 #include "content/browser/gpu/gpu_data_manager_impl.h" | 10 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 return rwh; | 99 return rwh; |
| 100 } | 100 } |
| 101 | 101 |
| 102 RenderWidgetHostViewBase* GetRenderWidgetHostView() const { | 102 RenderWidgetHostViewBase* GetRenderWidgetHostView() const { |
| 103 return static_cast<RenderWidgetHostViewBase*>( | 103 return static_cast<RenderWidgetHostViewBase*>( |
| 104 GetRenderViewHost()->GetView()); | 104 GetRenderViewHost()->GetView()); |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Callback when using CopyFromBackingStore() API. | 107 // Callback when using CopyFromBackingStore() API. |
| 108 void FinishCopyFromBackingStore(const base::Closure& quit_closure, | 108 void FinishCopyFromBackingStore(const base::Closure& quit_closure, |
| 109 bool frame_captured, | 109 const SkBitmap& bitmap, |
| 110 const SkBitmap& bitmap) { | 110 ReadbackResponse response) { |
| 111 ++callback_invoke_count_; | 111 ++callback_invoke_count_; |
| 112 if (frame_captured) { | 112 if (response == READBACK_SUCCESS) { |
| 113 ++frames_captured_; | 113 ++frames_captured_; |
| 114 EXPECT_FALSE(bitmap.empty()); | 114 EXPECT_FALSE(bitmap.empty()); |
| 115 } | 115 } |
| 116 if (!quit_closure.is_null()) | 116 if (!quit_closure.is_null()) |
| 117 quit_closure.Run(); | 117 quit_closure.Run(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Callback when using CopyFromCompositingSurfaceToVideoFrame() API. | 120 // Callback when using CopyFromCompositingSurfaceToVideoFrame() API. |
| 121 void FinishCopyFromCompositingSurface(const base::Closure& quit_closure, | 121 void FinishCopyFromCompositingSurface(const base::Closure& quit_closure, |
| 122 bool frame_captured) { | 122 bool frame_captured) { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 CompositingRenderWidgetHostViewBrowserTestTabCapture() | 397 CompositingRenderWidgetHostViewBrowserTestTabCapture() |
| 398 : expected_copy_from_compositing_surface_result_(false), | 398 : expected_copy_from_compositing_surface_result_(false), |
| 399 allowable_error_(0), | 399 allowable_error_(0), |
| 400 test_url_("data:text/html,<!doctype html>") {} | 400 test_url_("data:text/html,<!doctype html>") {} |
| 401 | 401 |
| 402 void SetUp() override { | 402 void SetUp() override { |
| 403 EnablePixelOutput(); | 403 EnablePixelOutput(); |
| 404 CompositingRenderWidgetHostViewBrowserTest::SetUp(); | 404 CompositingRenderWidgetHostViewBrowserTest::SetUp(); |
| 405 } | 405 } |
| 406 | 406 |
| 407 void CopyFromCompositingSurfaceCallback(base::Closure quit_callback, | 407 void ReadbackRequestCallbackTest(base::Closure quit_callback, |
| 408 bool result, | 408 const SkBitmap& bitmap, |
| 409 const SkBitmap& bitmap) { | 409 ReadbackResponse response) { |
| 410 bool result = (response == READBACK_SUCCESS); |
| 410 EXPECT_EQ(expected_copy_from_compositing_surface_result_, result); | 411 EXPECT_EQ(expected_copy_from_compositing_surface_result_, result); |
| 411 if (!result) { | 412 if (!result) { |
| 412 quit_callback.Run(); | 413 quit_callback.Run(); |
| 413 return; | 414 return; |
| 414 } | 415 } |
| 415 | 416 |
| 416 const SkBitmap& expected_bitmap = | 417 const SkBitmap& expected_bitmap = |
| 417 expected_copy_from_compositing_surface_bitmap_; | 418 expected_copy_from_compositing_surface_bitmap_; |
| 418 EXPECT_EQ(expected_bitmap.width(), bitmap.width()); | 419 EXPECT_EQ(expected_bitmap.width(), bitmap.width()); |
| 419 EXPECT_EQ(expected_bitmap.height(), bitmap.height()); | 420 EXPECT_EQ(expected_bitmap.height(), bitmap.height()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 << " color: " << color | 457 << " color: " << color |
| 457 << " Failed at " << std::dec << i << ", " << j | 458 << " Failed at " << std::dec << i << ", " << j |
| 458 << " Failure " << ++fails; | 459 << " Failure " << ++fails; |
| 459 } | 460 } |
| 460 } | 461 } |
| 461 EXPECT_LT(fails, 10); | 462 EXPECT_LT(fails, 10); |
| 462 | 463 |
| 463 quit_callback.Run(); | 464 quit_callback.Run(); |
| 464 } | 465 } |
| 465 | 466 |
| 466 void CopyFromCompositingSurfaceCallbackForVideo( | 467 void ReadbackRequestCallbackForVideo( |
| 467 scoped_refptr<media::VideoFrame> video_frame, | 468 scoped_refptr<media::VideoFrame> video_frame, |
| 468 base::Closure quit_callback, | 469 base::Closure quit_callback, |
| 469 bool result) { | 470 bool result) { |
| 470 EXPECT_EQ(expected_copy_from_compositing_surface_result_, result); | 471 EXPECT_EQ(expected_copy_from_compositing_surface_result_, result); |
| 471 if (!result) { | 472 if (!result) { |
| 472 quit_callback.Run(); | 473 quit_callback.Run(); |
| 473 return; | 474 return; |
| 474 } | 475 } |
| 475 | 476 |
| 476 media::SkCanvasVideoRenderer video_renderer; | 477 media::SkCanvasVideoRenderer video_renderer; |
| 477 | 478 |
| 478 SkBitmap bitmap; | 479 SkBitmap bitmap; |
| 479 bitmap.allocN32Pixels(video_frame->visible_rect().width(), | 480 bitmap.allocN32Pixels(video_frame->visible_rect().width(), |
| 480 video_frame->visible_rect().height()); | 481 video_frame->visible_rect().height()); |
| 481 // Don't clear the canvas because drawing a video frame by Src mode. | 482 // Don't clear the canvas because drawing a video frame by Src mode. |
| 482 SkCanvas canvas(bitmap); | 483 SkCanvas canvas(bitmap); |
| 483 video_renderer.Copy(video_frame, &canvas); | 484 video_renderer.Copy(video_frame, &canvas); |
| 485 ReadbackResponse response = result ? READBACK_SUCCESS : READBACK_FAILED; |
| 484 | 486 |
| 485 CopyFromCompositingSurfaceCallback(quit_callback, | 487 ReadbackRequestCallbackTest(quit_callback, bitmap, response); |
| 486 result, | |
| 487 bitmap); | |
| 488 } | 488 } |
| 489 | 489 |
| 490 void SetExpectedCopyFromCompositingSurfaceResult(bool result, | 490 void SetExpectedCopyFromCompositingSurfaceResult(bool result, |
| 491 const SkBitmap& bitmap) { | 491 const SkBitmap& bitmap) { |
| 492 expected_copy_from_compositing_surface_result_ = result; | 492 expected_copy_from_compositing_surface_result_ = result; |
| 493 expected_copy_from_compositing_surface_bitmap_ = bitmap; | 493 expected_copy_from_compositing_surface_bitmap_ = bitmap; |
| 494 } | 494 } |
| 495 | 495 |
| 496 void SetAllowableError(int amount) { allowable_error_ = amount; } | 496 void SetAllowableError(int amount) { allowable_error_ = amount; } |
| 497 void SetExcludeRect(gfx::Rect exclude) { exclude_rect_ = exclude; } | 497 void SetExcludeRect(gfx::Rect exclude) { exclude_rect_ = exclude; } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 | 576 |
| 577 scoped_refptr<media::VideoFrame> video_frame = | 577 scoped_refptr<media::VideoFrame> video_frame = |
| 578 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | 578 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
| 579 output_size, | 579 output_size, |
| 580 gfx::Rect(output_size), | 580 gfx::Rect(output_size), |
| 581 output_size, | 581 output_size, |
| 582 base::TimeDelta()); | 582 base::TimeDelta()); |
| 583 | 583 |
| 584 base::Callback<void(bool success)> callback = | 584 base::Callback<void(bool success)> callback = |
| 585 base::Bind(&CompositingRenderWidgetHostViewBrowserTestTabCapture:: | 585 base::Bind(&CompositingRenderWidgetHostViewBrowserTestTabCapture:: |
| 586 CopyFromCompositingSurfaceCallbackForVideo, | 586 ReadbackRequestCallbackForVideo, |
| 587 base::Unretained(this), | 587 base::Unretained(this), |
| 588 video_frame, | 588 video_frame, |
| 589 run_loop.QuitClosure()); | 589 run_loop.QuitClosure()); |
| 590 rwhv->CopyFromCompositingSurfaceToVideoFrame(copy_rect, | 590 rwhv->CopyFromCompositingSurfaceToVideoFrame( |
| 591 video_frame, | 591 copy_rect, video_frame, callback); |
| 592 callback); | |
| 593 } else { | 592 } else { |
| 594 if (IsDelegatedRendererEnabled()) { | 593 if (IsDelegatedRendererEnabled()) { |
| 595 if (!content::GpuDataManager::GetInstance() | 594 if (!content::GpuDataManager::GetInstance() |
| 596 ->CanUseGpuBrowserCompositor()) { | 595 ->CanUseGpuBrowserCompositor()) { |
| 597 // Skia rendering can cause color differences, particularly in the | 596 // Skia rendering can cause color differences, particularly in the |
| 598 // middle two columns. | 597 // middle two columns. |
| 599 SetAllowableError(2); | 598 SetAllowableError(2); |
| 600 SetExcludeRect(gfx::Rect( | 599 SetExcludeRect(gfx::Rect( |
| 601 output_size.width() / 2 - 1, 0, 2, output_size.height())); | 600 output_size.width() / 2 - 1, 0, 2, output_size.height())); |
| 602 } | 601 } |
| 603 } | 602 } |
| 604 | 603 |
| 605 base::Callback<void(bool, const SkBitmap&)> callback = | 604 ReadbackRequestCallback callback = |
| 606 base::Bind(&CompositingRenderWidgetHostViewBrowserTestTabCapture:: | 605 base::Bind(&CompositingRenderWidgetHostViewBrowserTestTabCapture:: |
| 607 CopyFromCompositingSurfaceCallback, | 606 ReadbackRequestCallbackTest, |
| 608 base::Unretained(this), | 607 base::Unretained(this), |
| 609 run_loop.QuitClosure()); | 608 run_loop.QuitClosure()); |
| 610 rwhv->CopyFromCompositingSurface(copy_rect, | 609 rwhv->CopyFromCompositingSurface( |
| 611 output_size, | 610 copy_rect, output_size, callback, kN32_SkColorType); |
| 612 callback, | |
| 613 kN32_SkColorType); | |
| 614 } | 611 } |
| 615 run_loop.Run(); | 612 run_loop.Run(); |
| 616 } | 613 } |
| 617 | 614 |
| 618 // Sets up |bitmap| to have size |copy_size|. It floods the left half with | 615 // Sets up |bitmap| to have size |copy_size|. It floods the left half with |
| 619 // #0ff and the right half with #ff0. | 616 // #0ff and the right half with #ff0. |
| 620 void SetupLeftRightBitmap(const gfx::Size& copy_size, SkBitmap* bitmap) { | 617 void SetupLeftRightBitmap(const gfx::Size& copy_size, SkBitmap* bitmap) { |
| 621 bitmap->allocN32Pixels(copy_size.width(), copy_size.height()); | 618 bitmap->allocN32Pixels(copy_size.width(), copy_size.height()); |
| 622 // Left half is #0ff. | 619 // Left half is #0ff. |
| 623 bitmap->eraseARGB(255, 0, 255, 255); | 620 bitmap->eraseARGB(255, 0, 255, 255); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 650 base::Unretained(this), | 647 base::Unretained(this), |
| 651 &saw_cyan_pixel, | 648 &saw_cyan_pixel, |
| 652 run_loop.QuitClosure()), | 649 run_loop.QuitClosure()), |
| 653 kN32_SkColorType); | 650 kN32_SkColorType); |
| 654 run_loop.Run(); | 651 run_loop.Run(); |
| 655 return saw_cyan_pixel; | 652 return saw_cyan_pixel; |
| 656 } | 653 } |
| 657 | 654 |
| 658 void CheckResultForCyanPixel(bool* saw_cyan_pixel, | 655 void CheckResultForCyanPixel(bool* saw_cyan_pixel, |
| 659 base::Closure done_callback, | 656 base::Closure done_callback, |
| 660 bool result, | 657 const SkBitmap& bitmap, |
| 661 const SkBitmap& bitmap) { | 658 ReadbackResponse response) { |
| 662 if (result) { | 659 if (response == READBACK_SUCCESS) { |
| 663 SkAutoLockPixels bitmap_lock(bitmap); | 660 SkAutoLockPixels bitmap_lock(bitmap); |
| 664 if (bitmap.width() > 0 && bitmap.height() > 0 && | 661 if (bitmap.width() > 0 && bitmap.height() > 0 && |
| 665 bitmap.getColor(0, 0) == SK_ColorCYAN) { | 662 bitmap.getColor(0, 0) == SK_ColorCYAN) { |
| 666 *saw_cyan_pixel = true; | 663 *saw_cyan_pixel = true; |
| 667 } | 664 } |
| 668 } | 665 } |
| 669 done_callback.Run(); | 666 done_callback.Run(); |
| 670 } | 667 } |
| 671 | 668 |
| 672 bool expected_copy_from_compositing_surface_result_; | 669 bool expected_copy_from_compositing_surface_result_; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); | 915 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); |
| 919 INSTANTIATE_TEST_CASE_P( | 916 INSTANTIATE_TEST_CASE_P( |
| 920 GLAndSoftwareCompositing, | 917 GLAndSoftwareCompositing, |
| 921 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, | 918 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
| 922 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); | 919 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); |
| 923 | 920 |
| 924 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 921 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
| 925 | 922 |
| 926 } // namespace | 923 } // namespace |
| 927 } // namespace content | 924 } // namespace content |
| OLD | NEW |