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