Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_browsertest.cc

Issue 593503003: Support error handling for Surface readbacks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use content namespace to resolve readback params. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 bool frame_captured = (response == READBACK_SUCCESS);
112 if (frame_captured) { 113 if (frame_captured) {
piman 2014/11/07 01:55:42 nit: no need for the intermediate 'frame_captured'
sivag 2014/11/07 12:27:41 Done.
113 ++frames_captured_; 114 ++frames_captured_;
114 EXPECT_FALSE(bitmap.empty()); 115 EXPECT_FALSE(bitmap.empty());
115 } 116 }
116 if (!quit_closure.is_null()) 117 if (!quit_closure.is_null())
117 quit_closure.Run(); 118 quit_closure.Run();
118 } 119 }
119 120
120 // Callback when using CopyFromCompositingSurfaceToVideoFrame() API. 121 // Callback when using CopyFromCompositingSurfaceToVideoFrame() API.
121 void FinishCopyFromCompositingSurface(const base::Closure& quit_closure, 122 void FinishCopyFromCompositingSurface(const base::Closure& quit_closure,
122 bool frame_captured) { 123 bool frame_captured) {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 CompositingRenderWidgetHostViewBrowserTestTabCapture() 407 CompositingRenderWidgetHostViewBrowserTestTabCapture()
407 : expected_copy_from_compositing_surface_result_(false), 408 : expected_copy_from_compositing_surface_result_(false),
408 allowable_error_(0), 409 allowable_error_(0),
409 test_url_("data:text/html,<!doctype html>") {} 410 test_url_("data:text/html,<!doctype html>") {}
410 411
411 void SetUp() override { 412 void SetUp() override {
412 EnablePixelOutput(); 413 EnablePixelOutput();
413 CompositingRenderWidgetHostViewBrowserTest::SetUp(); 414 CompositingRenderWidgetHostViewBrowserTest::SetUp();
414 } 415 }
415 416
416 void CopyFromCompositingSurfaceCallback(base::Closure quit_callback, 417 void ReadbackRequestCallbackTest(base::Closure quit_callback,
417 bool result, 418 const SkBitmap& bitmap,
418 const SkBitmap& bitmap) { 419 const ReadbackResponse& response) {
420 bool result = (response == READBACK_SUCCESS);
419 EXPECT_EQ(expected_copy_from_compositing_surface_result_, result); 421 EXPECT_EQ(expected_copy_from_compositing_surface_result_, result);
420 if (!result) { 422 if (!result) {
421 quit_callback.Run(); 423 quit_callback.Run();
422 return; 424 return;
423 } 425 }
424 426
425 const SkBitmap& expected_bitmap = 427 const SkBitmap& expected_bitmap =
426 expected_copy_from_compositing_surface_bitmap_; 428 expected_copy_from_compositing_surface_bitmap_;
427 EXPECT_EQ(expected_bitmap.width(), bitmap.width()); 429 EXPECT_EQ(expected_bitmap.width(), bitmap.width());
428 EXPECT_EQ(expected_bitmap.height(), bitmap.height()); 430 EXPECT_EQ(expected_bitmap.height(), bitmap.height());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 << " color: " << color 467 << " color: " << color
466 << " Failed at " << std::dec << i << ", " << j 468 << " Failed at " << std::dec << i << ", " << j
467 << " Failure " << ++fails; 469 << " Failure " << ++fails;
468 } 470 }
469 } 471 }
470 EXPECT_LT(fails, 10); 472 EXPECT_LT(fails, 10);
471 473
472 quit_callback.Run(); 474 quit_callback.Run();
473 } 475 }
474 476
475 void CopyFromCompositingSurfaceCallbackForVideo( 477 void ReadbackRequestCallbackForVideo(
476 scoped_refptr<media::VideoFrame> video_frame, 478 scoped_refptr<media::VideoFrame> video_frame,
477 base::Closure quit_callback, 479 base::Closure quit_callback,
478 bool result) { 480 bool result) {
479 EXPECT_EQ(expected_copy_from_compositing_surface_result_, result); 481 EXPECT_EQ(expected_copy_from_compositing_surface_result_, result);
480 if (!result) { 482 if (!result) {
481 quit_callback.Run(); 483 quit_callback.Run();
482 return; 484 return;
483 } 485 }
484 486
485 media::SkCanvasVideoRenderer video_renderer; 487 media::SkCanvasVideoRenderer video_renderer;
486 488
487 SkBitmap bitmap; 489 SkBitmap bitmap;
488 bitmap.allocN32Pixels(video_frame->visible_rect().width(), 490 bitmap.allocN32Pixels(video_frame->visible_rect().width(),
489 video_frame->visible_rect().height()); 491 video_frame->visible_rect().height());
490 // Don't clear the canvas because drawing a video frame by Src mode. 492 // Don't clear the canvas because drawing a video frame by Src mode.
491 SkCanvas canvas(bitmap); 493 SkCanvas canvas(bitmap);
492 video_renderer.Copy(video_frame, &canvas); 494 video_renderer.Copy(video_frame, &canvas);
495 ReadbackResponse response = result ? READBACK_SUCCESS : READBACK_FAILED;
493 496
494 CopyFromCompositingSurfaceCallback(quit_callback, 497 ReadbackRequestCallbackTest(quit_callback, bitmap, response);
495 result,
496 bitmap);
497 } 498 }
498 499
499 void SetExpectedCopyFromCompositingSurfaceResult(bool result, 500 void SetExpectedCopyFromCompositingSurfaceResult(bool result,
500 const SkBitmap& bitmap) { 501 const SkBitmap& bitmap) {
501 expected_copy_from_compositing_surface_result_ = result; 502 expected_copy_from_compositing_surface_result_ = result;
502 expected_copy_from_compositing_surface_bitmap_ = bitmap; 503 expected_copy_from_compositing_surface_bitmap_ = bitmap;
503 } 504 }
504 505
505 void SetAllowableError(int amount) { allowable_error_ = amount; } 506 void SetAllowableError(int amount) { allowable_error_ = amount; }
506 void SetExcludeRect(gfx::Rect exclude) { exclude_rect_ = exclude; } 507 void SetExcludeRect(gfx::Rect exclude) { exclude_rect_ = exclude; }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 SetExcludeRect( 590 SetExcludeRect(
590 gfx::Rect(output_size.width() / 2 - 1, 0, 2, output_size.height())); 591 gfx::Rect(output_size.width() / 2 - 1, 0, 2, output_size.height()));
591 592
592 scoped_refptr<media::VideoFrame> video_frame = 593 scoped_refptr<media::VideoFrame> video_frame =
593 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, 594 media::VideoFrame::CreateFrame(media::VideoFrame::YV12,
594 output_size, 595 output_size,
595 gfx::Rect(output_size), 596 gfx::Rect(output_size),
596 output_size, 597 output_size,
597 base::TimeDelta()); 598 base::TimeDelta());
598 599
599 base::Callback<void(bool success)> callback = 600 base::Callback<void(bool success)> callback = base::Bind(
600 base::Bind(&CompositingRenderWidgetHostViewBrowserTestTabCapture:: 601 &CompositingRenderWidgetHostViewBrowserTestTabCapture::
601 CopyFromCompositingSurfaceCallbackForVideo, 602 ReadbackRequestCallbackForVideo,
602 base::Unretained(this), 603 base::Unretained(this), video_frame, run_loop.QuitClosure());
603 video_frame,
604 run_loop.QuitClosure());
605 rwhvp->CopyFromCompositingSurfaceToVideoFrame(copy_rect, 604 rwhvp->CopyFromCompositingSurfaceToVideoFrame(copy_rect,
606 video_frame, 605 video_frame,
607 callback); 606 callback);
608 } else { 607 } else {
609 if (IsDelegatedRendererEnabled()) { 608 if (IsDelegatedRendererEnabled()) {
610 if (!content::GpuDataManager::GetInstance() 609 if (!content::GpuDataManager::GetInstance()
611 ->CanUseGpuBrowserCompositor()) { 610 ->CanUseGpuBrowserCompositor()) {
612 // Skia rendering can cause color differences, particularly in the 611 // Skia rendering can cause color differences, particularly in the
613 // middle two columns. 612 // middle two columns.
614 SetAllowableError(2); 613 SetAllowableError(2);
615 SetExcludeRect(gfx::Rect( 614 SetExcludeRect(gfx::Rect(
616 output_size.width() / 2 - 1, 0, 2, output_size.height())); 615 output_size.width() / 2 - 1, 0, 2, output_size.height()));
617 } 616 }
618 } 617 }
619 618
620 base::Callback<void(bool, const SkBitmap&)> callback = 619 ReadbackRequestCallback callback =
621 base::Bind(&CompositingRenderWidgetHostViewBrowserTestTabCapture:: 620 base::Bind(&CompositingRenderWidgetHostViewBrowserTestTabCapture::
622 CopyFromCompositingSurfaceCallback, 621 ReadbackRequestCallbackTest,
623 base::Unretained(this), 622 base::Unretained(this), run_loop.QuitClosure());
624 run_loop.QuitClosure());
625 rwhvp->CopyFromCompositingSurface(copy_rect, 623 rwhvp->CopyFromCompositingSurface(copy_rect,
626 output_size, 624 output_size,
627 callback, 625 callback,
628 kN32_SkColorType); 626 kN32_SkColorType);
629 } 627 }
630 run_loop.Run(); 628 run_loop.Run();
631 } 629 }
632 630
633 // Sets up |bitmap| to have size |copy_size|. It floods the left half with 631 // Sets up |bitmap| to have size |copy_size|. It floods the left half with
634 // #0ff and the right half with #ff0. 632 // #0ff and the right half with #ff0.
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); 904 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING));
907 INSTANTIATE_TEST_CASE_P( 905 INSTANTIATE_TEST_CASE_P(
908 GLAndSoftwareCompositing, 906 GLAndSoftwareCompositing,
909 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, 907 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI,
910 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); 908 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING));
911 909
912 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) 910 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
913 911
914 } // namespace 912 } // namespace
915 } // namespace content 913 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698