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 const 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 CompositingRenderWidgetHostViewBrowserTestTabCapture() | 406 CompositingRenderWidgetHostViewBrowserTestTabCapture() |
407 : expected_copy_from_compositing_surface_result_(false), | 407 : expected_copy_from_compositing_surface_result_(false), |
408 allowable_error_(0), | 408 allowable_error_(0), |
409 test_url_("data:text/html,<!doctype html>") {} | 409 test_url_("data:text/html,<!doctype html>") {} |
410 | 410 |
411 void SetUp() override { | 411 void SetUp() override { |
412 EnablePixelOutput(); | 412 EnablePixelOutput(); |
413 CompositingRenderWidgetHostViewBrowserTest::SetUp(); | 413 CompositingRenderWidgetHostViewBrowserTest::SetUp(); |
414 } | 414 } |
415 | 415 |
416 void CopyFromCompositingSurfaceCallback(base::Closure quit_callback, | 416 void ReadbackRequestCallbackTest(base::Closure quit_callback, |
417 bool result, | 417 const SkBitmap& bitmap, |
418 const SkBitmap& bitmap) { | 418 const ReadbackResponse& response) { |
| 419 bool result = (response == READBACK_SUCCESS); |
419 EXPECT_EQ(expected_copy_from_compositing_surface_result_, result); | 420 EXPECT_EQ(expected_copy_from_compositing_surface_result_, result); |
420 if (!result) { | 421 if (!result) { |
421 quit_callback.Run(); | 422 quit_callback.Run(); |
422 return; | 423 return; |
423 } | 424 } |
424 | 425 |
425 const SkBitmap& expected_bitmap = | 426 const SkBitmap& expected_bitmap = |
426 expected_copy_from_compositing_surface_bitmap_; | 427 expected_copy_from_compositing_surface_bitmap_; |
427 EXPECT_EQ(expected_bitmap.width(), bitmap.width()); | 428 EXPECT_EQ(expected_bitmap.width(), bitmap.width()); |
428 EXPECT_EQ(expected_bitmap.height(), bitmap.height()); | 429 EXPECT_EQ(expected_bitmap.height(), bitmap.height()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 << " color: " << color | 466 << " color: " << color |
466 << " Failed at " << std::dec << i << ", " << j | 467 << " Failed at " << std::dec << i << ", " << j |
467 << " Failure " << ++fails; | 468 << " Failure " << ++fails; |
468 } | 469 } |
469 } | 470 } |
470 EXPECT_LT(fails, 10); | 471 EXPECT_LT(fails, 10); |
471 | 472 |
472 quit_callback.Run(); | 473 quit_callback.Run(); |
473 } | 474 } |
474 | 475 |
475 void CopyFromCompositingSurfaceCallbackForVideo( | 476 void ReadbackRequestCallbackForVideo( |
476 scoped_refptr<media::VideoFrame> video_frame, | 477 scoped_refptr<media::VideoFrame> video_frame, |
477 base::Closure quit_callback, | 478 base::Closure quit_callback, |
478 bool result) { | 479 bool result) { |
479 EXPECT_EQ(expected_copy_from_compositing_surface_result_, result); | 480 EXPECT_EQ(expected_copy_from_compositing_surface_result_, result); |
480 if (!result) { | 481 if (!result) { |
481 quit_callback.Run(); | 482 quit_callback.Run(); |
482 return; | 483 return; |
483 } | 484 } |
484 | 485 |
485 media::SkCanvasVideoRenderer video_renderer; | 486 media::SkCanvasVideoRenderer video_renderer; |
486 | 487 |
487 SkBitmap bitmap; | 488 SkBitmap bitmap; |
488 bitmap.allocN32Pixels(video_frame->visible_rect().width(), | 489 bitmap.allocN32Pixels(video_frame->visible_rect().width(), |
489 video_frame->visible_rect().height()); | 490 video_frame->visible_rect().height()); |
490 // Don't clear the canvas because drawing a video frame by Src mode. | 491 // Don't clear the canvas because drawing a video frame by Src mode. |
491 SkCanvas canvas(bitmap); | 492 SkCanvas canvas(bitmap); |
492 video_renderer.Copy(video_frame, &canvas); | 493 video_renderer.Copy(video_frame, &canvas); |
| 494 ReadbackResponse response = result ? READBACK_SUCCESS : READBACK_FAILED; |
493 | 495 |
494 CopyFromCompositingSurfaceCallback(quit_callback, | 496 ReadbackRequestCallbackTest(quit_callback, bitmap, response); |
495 result, | |
496 bitmap); | |
497 } | 497 } |
498 | 498 |
499 void SetExpectedCopyFromCompositingSurfaceResult(bool result, | 499 void SetExpectedCopyFromCompositingSurfaceResult(bool result, |
500 const SkBitmap& bitmap) { | 500 const SkBitmap& bitmap) { |
501 expected_copy_from_compositing_surface_result_ = result; | 501 expected_copy_from_compositing_surface_result_ = result; |
502 expected_copy_from_compositing_surface_bitmap_ = bitmap; | 502 expected_copy_from_compositing_surface_bitmap_ = bitmap; |
503 } | 503 } |
504 | 504 |
505 void SetAllowableError(int amount) { allowable_error_ = amount; } | 505 void SetAllowableError(int amount) { allowable_error_ = amount; } |
506 void SetExcludeRect(gfx::Rect exclude) { exclude_rect_ = exclude; } | 506 void SetExcludeRect(gfx::Rect exclude) { exclude_rect_ = exclude; } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 SetExcludeRect( | 589 SetExcludeRect( |
590 gfx::Rect(output_size.width() / 2 - 1, 0, 2, output_size.height())); | 590 gfx::Rect(output_size.width() / 2 - 1, 0, 2, output_size.height())); |
591 | 591 |
592 scoped_refptr<media::VideoFrame> video_frame = | 592 scoped_refptr<media::VideoFrame> video_frame = |
593 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | 593 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
594 output_size, | 594 output_size, |
595 gfx::Rect(output_size), | 595 gfx::Rect(output_size), |
596 output_size, | 596 output_size, |
597 base::TimeDelta()); | 597 base::TimeDelta()); |
598 | 598 |
599 base::Callback<void(bool success)> callback = | 599 base::Callback<void(bool success)> callback = base::Bind( |
600 base::Bind(&CompositingRenderWidgetHostViewBrowserTestTabCapture:: | 600 &CompositingRenderWidgetHostViewBrowserTestTabCapture:: |
601 CopyFromCompositingSurfaceCallbackForVideo, | 601 ReadbackRequestCallbackForVideo, |
602 base::Unretained(this), | 602 base::Unretained(this), video_frame, run_loop.QuitClosure()); |
603 video_frame, | |
604 run_loop.QuitClosure()); | |
605 rwhvp->CopyFromCompositingSurfaceToVideoFrame(copy_rect, | 603 rwhvp->CopyFromCompositingSurfaceToVideoFrame(copy_rect, |
606 video_frame, | 604 video_frame, |
607 callback); | 605 callback); |
608 } else { | 606 } else { |
609 if (IsDelegatedRendererEnabled()) { | 607 if (IsDelegatedRendererEnabled()) { |
610 if (!content::GpuDataManager::GetInstance() | 608 if (!content::GpuDataManager::GetInstance() |
611 ->CanUseGpuBrowserCompositor()) { | 609 ->CanUseGpuBrowserCompositor()) { |
612 // Skia rendering can cause color differences, particularly in the | 610 // Skia rendering can cause color differences, particularly in the |
613 // middle two columns. | 611 // middle two columns. |
614 SetAllowableError(2); | 612 SetAllowableError(2); |
615 SetExcludeRect(gfx::Rect( | 613 SetExcludeRect(gfx::Rect( |
616 output_size.width() / 2 - 1, 0, 2, output_size.height())); | 614 output_size.width() / 2 - 1, 0, 2, output_size.height())); |
617 } | 615 } |
618 } | 616 } |
619 | 617 |
620 base::Callback<void(bool, const SkBitmap&)> callback = | 618 ReadbackRequestCallback callback = |
621 base::Bind(&CompositingRenderWidgetHostViewBrowserTestTabCapture:: | 619 base::Bind(&CompositingRenderWidgetHostViewBrowserTestTabCapture:: |
622 CopyFromCompositingSurfaceCallback, | 620 ReadbackRequestCallbackTest, |
623 base::Unretained(this), | 621 base::Unretained(this), run_loop.QuitClosure()); |
624 run_loop.QuitClosure()); | |
625 rwhvp->CopyFromCompositingSurface(copy_rect, | 622 rwhvp->CopyFromCompositingSurface(copy_rect, |
626 output_size, | 623 output_size, |
627 callback, | 624 callback, |
628 kN32_SkColorType); | 625 kN32_SkColorType); |
629 } | 626 } |
630 run_loop.Run(); | 627 run_loop.Run(); |
631 } | 628 } |
632 | 629 |
633 // Sets up |bitmap| to have size |copy_size|. It floods the left half with | 630 // Sets up |bitmap| to have size |copy_size|. It floods the left half with |
634 // #0ff and the right half with #ff0. | 631 // #0ff and the right half with #ff0. |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); | 903 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); |
907 INSTANTIATE_TEST_CASE_P( | 904 INSTANTIATE_TEST_CASE_P( |
908 GLAndSoftwareCompositing, | 905 GLAndSoftwareCompositing, |
909 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, | 906 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
910 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); | 907 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); |
911 | 908 |
912 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 909 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
913 | 910 |
914 } // namespace | 911 } // namespace |
915 } // namespace content | 912 } // namespace content |
OLD | NEW |