| 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/barrier_closure.h" | 5 #include "base/barrier_closure.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/location.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 #include "base/thread_task_runner_handle.h" | |
| 12 #include "content/browser/gpu/compositor_util.h" | 10 #include "content/browser/gpu/compositor_util.h" |
| 13 #include "content/browser/gpu/gpu_data_manager_impl.h" | 11 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 14 #include "content/browser/renderer_host/dip_util.h" | 12 #include "content/browser/renderer_host/dip_util.h" |
| 15 #include "content/browser/renderer_host/render_widget_host_impl.h" | 13 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 16 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 14 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 17 #include "content/public/browser/gpu_data_manager.h" | 15 #include "content/public/browser/gpu_data_manager.h" |
| 18 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
| 19 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 17 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
| 20 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/common/content_paths.h" | 19 #include "content/public/common/content_paths.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 void FinishCopyFromCompositingSurface(const base::Closure& quit_closure, | 122 void FinishCopyFromCompositingSurface(const base::Closure& quit_closure, |
| 125 bool frame_captured) { | 123 bool frame_captured) { |
| 126 ++callback_invoke_count_; | 124 ++callback_invoke_count_; |
| 127 if (frame_captured) | 125 if (frame_captured) |
| 128 ++frames_captured_; | 126 ++frames_captured_; |
| 129 if (!quit_closure.is_null()) | 127 if (!quit_closure.is_null()) |
| 130 quit_closure.Run(); | 128 quit_closure.Run(); |
| 131 } | 129 } |
| 132 | 130 |
| 133 // Callback when using frame subscriber API. | 131 // Callback when using frame subscriber API. |
| 134 void FrameDelivered( | 132 void FrameDelivered(const scoped_refptr<base::MessageLoopProxy>& loop, |
| 135 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 133 base::Closure quit_closure, |
| 136 base::Closure quit_closure, | 134 base::TimeTicks timestamp, |
| 137 base::TimeTicks timestamp, | 135 bool frame_captured) { |
| 138 bool frame_captured) { | |
| 139 ++callback_invoke_count_; | 136 ++callback_invoke_count_; |
| 140 if (frame_captured) | 137 if (frame_captured) |
| 141 ++frames_captured_; | 138 ++frames_captured_; |
| 142 if (!quit_closure.is_null()) | 139 if (!quit_closure.is_null()) |
| 143 task_runner->PostTask(FROM_HERE, quit_closure); | 140 loop->PostTask(FROM_HERE, quit_closure); |
| 144 } | 141 } |
| 145 | 142 |
| 146 // Copy one frame using the CopyFromBackingStore API. | 143 // Copy one frame using the CopyFromBackingStore API. |
| 147 void RunBasicCopyFromBackingStoreTest() { | 144 void RunBasicCopyFromBackingStoreTest() { |
| 148 SET_UP_SURFACE_OR_PASS_TEST(NULL); | 145 SET_UP_SURFACE_OR_PASS_TEST(NULL); |
| 149 | 146 |
| 150 // Repeatedly call CopyFromBackingStore() since, on some platforms (e.g., | 147 // Repeatedly call CopyFromBackingStore() since, on some platforms (e.g., |
| 151 // Windows), the operation will fail until the first "present" has been | 148 // Windows), the operation will fail until the first "present" has been |
| 152 // made. | 149 // made. |
| 153 int count_attempts = 0; | 150 int count_attempts = 0; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 178 // Waits until the source is available for copying. | 175 // Waits until the source is available for copying. |
| 179 void WaitForCopySourceReady() { | 176 void WaitForCopySourceReady() { |
| 180 while (!GetRenderWidgetHostView()->IsSurfaceAvailableForCopy()) | 177 while (!GetRenderWidgetHostView()->IsSurfaceAvailableForCopy()) |
| 181 GiveItSomeTime(); | 178 GiveItSomeTime(); |
| 182 } | 179 } |
| 183 | 180 |
| 184 // Run the current message loop for a short time without unwinding the current | 181 // Run the current message loop for a short time without unwinding the current |
| 185 // call stack. | 182 // call stack. |
| 186 static void GiveItSomeTime() { | 183 static void GiveItSomeTime() { |
| 187 base::RunLoop run_loop; | 184 base::RunLoop run_loop; |
| 188 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 185 base::MessageLoop::current()->PostDelayedTask( |
| 189 FROM_HERE, run_loop.QuitClosure(), | 186 FROM_HERE, |
| 187 run_loop.QuitClosure(), |
| 190 base::TimeDelta::FromMilliseconds(10)); | 188 base::TimeDelta::FromMilliseconds(10)); |
| 191 run_loop.Run(); | 189 run_loop.Run(); |
| 192 } | 190 } |
| 193 | 191 |
| 194 private: | 192 private: |
| 195 const gfx::Size frame_size_; | 193 const gfx::Size frame_size_; |
| 196 base::FilePath test_dir_; | 194 base::FilePath test_dir_; |
| 197 int callback_invoke_count_; | 195 int callback_invoke_count_; |
| 198 int frames_captured_; | 196 int frames_captured_; |
| 199 }; | 197 }; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 SET_UP_SURFACE_OR_PASS_TEST(NULL); | 332 SET_UP_SURFACE_OR_PASS_TEST(NULL); |
| 335 RenderWidgetHostViewBase* const view = GetRenderWidgetHostView(); | 333 RenderWidgetHostViewBase* const view = GetRenderWidgetHostView(); |
| 336 if (!view->CanSubscribeFrame()) { | 334 if (!view->CanSubscribeFrame()) { |
| 337 LOG(WARNING) << ("Blindly passing this test: Frame subscription not " | 335 LOG(WARNING) << ("Blindly passing this test: Frame subscription not " |
| 338 "supported on this platform."); | 336 "supported on this platform."); |
| 339 return; | 337 return; |
| 340 } | 338 } |
| 341 | 339 |
| 342 base::RunLoop run_loop; | 340 base::RunLoop run_loop; |
| 343 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber( | 341 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber( |
| 344 new FakeFrameSubscriber(base::Bind( | 342 new FakeFrameSubscriber( |
| 345 &RenderWidgetHostViewBrowserTest::FrameDelivered, | 343 base::Bind(&RenderWidgetHostViewBrowserTest::FrameDelivered, |
| 346 base::Unretained(this), base::ThreadTaskRunnerHandle::Get(), | 344 base::Unretained(this), |
| 347 run_loop.QuitClosure()))); | 345 base::MessageLoopProxy::current(), |
| 346 run_loop.QuitClosure()))); |
| 348 view->BeginFrameSubscription(subscriber.Pass()); | 347 view->BeginFrameSubscription(subscriber.Pass()); |
| 349 run_loop.Run(); | 348 run_loop.Run(); |
| 350 view->EndFrameSubscription(); | 349 view->EndFrameSubscription(); |
| 351 | 350 |
| 352 EXPECT_LE(1, callback_invoke_count()); | 351 EXPECT_LE(1, callback_invoke_count()); |
| 353 EXPECT_LE(1, frames_captured()); | 352 EXPECT_LE(1, frames_captured()); |
| 354 } | 353 } |
| 355 | 354 |
| 356 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTest, CopyTwice) { | 355 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTest, CopyTwice) { |
| 357 SET_UP_SURFACE_OR_PASS_TEST(NULL); | 356 SET_UP_SURFACE_OR_PASS_TEST(NULL); |
| 358 RenderWidgetHostViewBase* const view = GetRenderWidgetHostView(); | 357 RenderWidgetHostViewBase* const view = GetRenderWidgetHostView(); |
| 359 if (!view->CanCopyToVideoFrame()) { | 358 if (!view->CanCopyToVideoFrame()) { |
| 360 LOG(WARNING) << ("Blindly passing this test: " | 359 LOG(WARNING) << ("Blindly passing this test: " |
| 361 "CopyFromCompositingSurfaceToVideoFrame() not supported " | 360 "CopyFromCompositingSurfaceToVideoFrame() not supported " |
| 362 "on this platform."); | 361 "on this platform."); |
| 363 return; | 362 return; |
| 364 } | 363 } |
| 365 | 364 |
| 366 base::RunLoop run_loop; | 365 base::RunLoop run_loop; |
| 367 scoped_refptr<media::VideoFrame> first_output = | 366 scoped_refptr<media::VideoFrame> first_output = |
| 368 media::VideoFrame::CreateBlackFrame(frame_size()); | 367 media::VideoFrame::CreateBlackFrame(frame_size()); |
| 369 ASSERT_TRUE(first_output.get()); | 368 ASSERT_TRUE(first_output.get()); |
| 370 scoped_refptr<media::VideoFrame> second_output = | 369 scoped_refptr<media::VideoFrame> second_output = |
| 371 media::VideoFrame::CreateBlackFrame(frame_size()); | 370 media::VideoFrame::CreateBlackFrame(frame_size()); |
| 372 ASSERT_TRUE(second_output.get()); | 371 ASSERT_TRUE(second_output.get()); |
| 373 base::Closure closure = base::BarrierClosure(2, run_loop.QuitClosure()); | 372 base::Closure closure = base::BarrierClosure(2, run_loop.QuitClosure()); |
| 374 view->CopyFromCompositingSurfaceToVideoFrame( | 373 view->CopyFromCompositingSurfaceToVideoFrame( |
| 375 gfx::Rect(view->GetViewBounds().size()), first_output, | 374 gfx::Rect(view->GetViewBounds().size()), first_output, |
| 376 base::Bind(&RenderWidgetHostViewBrowserTest::FrameDelivered, | 375 base::Bind(&RenderWidgetHostViewBrowserTest::FrameDelivered, |
| 377 base::Unretained(this), base::ThreadTaskRunnerHandle::Get(), | 376 base::Unretained(this), base::MessageLoopProxy::current(), |
| 378 closure, base::TimeTicks::Now())); | 377 closure, base::TimeTicks::Now())); |
| 379 view->CopyFromCompositingSurfaceToVideoFrame( | 378 view->CopyFromCompositingSurfaceToVideoFrame( |
| 380 gfx::Rect(view->GetViewBounds().size()), second_output, | 379 gfx::Rect(view->GetViewBounds().size()), second_output, |
| 381 base::Bind(&RenderWidgetHostViewBrowserTest::FrameDelivered, | 380 base::Bind(&RenderWidgetHostViewBrowserTest::FrameDelivered, |
| 382 base::Unretained(this), base::ThreadTaskRunnerHandle::Get(), | 381 base::Unretained(this), base::MessageLoopProxy::current(), |
| 383 closure, base::TimeTicks::Now())); | 382 closure, base::TimeTicks::Now())); |
| 384 run_loop.Run(); | 383 run_loop.Run(); |
| 385 | 384 |
| 386 EXPECT_EQ(2, callback_invoke_count()); | 385 EXPECT_EQ(2, callback_invoke_count()); |
| 387 EXPECT_EQ(2, frames_captured()); | 386 EXPECT_EQ(2, frames_captured()); |
| 388 } | 387 } |
| 389 | 388 |
| 390 class CompositingRenderWidgetHostViewBrowserTestTabCapture | 389 class CompositingRenderWidgetHostViewBrowserTestTabCapture |
| 391 : public CompositingRenderWidgetHostViewBrowserTest { | 390 : public CompositingRenderWidgetHostViewBrowserTest { |
| 392 public: | 391 public: |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 kTestCompositingModes); | 956 kTestCompositingModes); |
| 958 INSTANTIATE_TEST_CASE_P( | 957 INSTANTIATE_TEST_CASE_P( |
| 959 GLAndSoftwareCompositing, | 958 GLAndSoftwareCompositing, |
| 960 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, | 959 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
| 961 kTestCompositingModes); | 960 kTestCompositingModes); |
| 962 | 961 |
| 963 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 962 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
| 964 | 963 |
| 965 } // namespace | 964 } // namespace |
| 966 } // namespace content | 965 } // namespace content |
| OLD | NEW |