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_proxy.h" | 6 #include "base/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/gpu_data_manager_impl.h" | 9 #include "content/browser/gpu/gpu_data_manager_impl.h" |
10 #include "content/browser/renderer_host/render_widget_host_impl.h" | 10 #include "content/browser/renderer_host/render_widget_host_impl.h" |
11 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" | 11 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" |
12 #include "content/port/browser/render_widget_host_view_port.h" | 12 #include "content/port/browser/render_widget_host_view_port.h" |
13 #include "content/public/browser/compositor_util.h" | |
13 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
15 #include "content/public/common/content_paths.h" | 16 #include "content/public/common/content_paths.h" |
17 #include "content/public/common/content_switches.h" | |
16 #include "content/shell/shell.h" | 18 #include "content/shell/shell.h" |
17 #include "content/test/content_browser_test.h" | 19 #include "content/test/content_browser_test.h" |
18 #include "content/test/content_browser_test_utils.h" | 20 #include "content/test/content_browser_test_utils.h" |
19 #include "media/base/video_frame.h" | 21 #include "media/base/video_frame.h" |
20 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
21 #include "skia/ext/platform_canvas.h" | |
22 #include "ui/compositor/compositor_setup.h" | 23 #include "ui/compositor/compositor_setup.h" |
23 #if defined(OS_MACOSX) | 24 #if defined(OS_MACOSX) |
24 #include "ui/surface/io_surface_support_mac.h" | 25 #include "ui/surface/io_surface_support_mac.h" |
25 #endif | 26 #endif |
26 | 27 |
27 namespace content { | 28 namespace content { |
28 | 29 namespace { |
30 | |
31 // Convenience macro: Short-cicuit a pass for the tests where platform support | |
32 // for forced-compositing mode (or disabled-compositing mode) is lacking. | |
33 #define SET_UP_SURFACE_OR_PASS_TEST() \ | |
34 if (!SetUpSourceSurface()) { \ | |
35 LOG(WARNING) \ | |
36 << ("Blindly passing this test: This platform does not support " \ | |
37 "forced compositing (or forced-disabled compositing) mode."); \ | |
38 return; \ | |
39 } | |
40 | |
41 // Common base class for browser tests. This is subclassed twice: Once to test | |
42 // the browser in forced-compositing mode, and once to test with compositing | |
43 // mode disabled. | |
29 class RenderWidgetHostViewBrowserTest : public ContentBrowserTest { | 44 class RenderWidgetHostViewBrowserTest : public ContentBrowserTest { |
30 public: | 45 public: |
31 RenderWidgetHostViewBrowserTest() : finish_called_(false), size_(400, 300) {} | 46 RenderWidgetHostViewBrowserTest() |
47 : frame_size_(400, 300), | |
48 callback_invoke_count_(0), | |
49 frames_captured_(0) {} | |
32 | 50 |
33 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 51 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
34 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_dir_)); | 52 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_dir_)); |
35 } | 53 ContentBrowserTest::SetUpInProcessBrowserTestFixture(); |
36 | 54 } |
55 | |
56 // Attempts to set up the source surface. Returns false if unsupported on the | |
57 // current platform. | |
58 virtual bool SetUpSourceSurface() = 0; | |
59 | |
60 int callback_invoke_count() const { | |
61 return callback_invoke_count_; | |
62 } | |
63 | |
64 int frames_captured() const { | |
65 return frames_captured_; | |
66 } | |
67 | |
68 const gfx::Size& frame_size() const { | |
69 return frame_size_; | |
70 } | |
71 | |
72 const base::FilePath& test_dir() const { | |
73 return test_dir_; | |
74 } | |
75 | |
76 RenderViewHost* GetRenderViewHost() const { | |
77 RenderViewHost* const rvh = shell()->web_contents()->GetRenderViewHost(); | |
78 CHECK(rvh); | |
79 return rvh; | |
80 } | |
81 | |
82 RenderWidgetHostImpl* GetRenderWidgetHost() const { | |
83 RenderWidgetHostImpl* const rwh = RenderWidgetHostImpl::From( | |
84 shell()->web_contents()->GetRenderWidgetHostView()-> | |
85 GetRenderWidgetHost()); | |
86 CHECK(rwh); | |
87 return rwh; | |
88 } | |
89 | |
90 RenderWidgetHostViewPort* GetRenderWidgetHostViewPort() const { | |
91 RenderWidgetHostViewPort* const view = | |
92 RenderWidgetHostViewPort::FromRWHV(GetRenderViewHost()->GetView()); | |
93 CHECK(view); | |
94 return view; | |
95 } | |
96 | |
97 // Callback when using CopyFromBackingStore() API. | |
98 void FinishCopyFromBackingStore(const base::Closure& quit_closure, | |
99 bool frame_captured, | |
100 const SkBitmap& bitmap) { | |
101 ++callback_invoke_count_; | |
102 if (frame_captured) { | |
103 ++frames_captured_; | |
104 EXPECT_FALSE(bitmap.empty()); | |
105 } | |
106 if (!quit_closure.is_null()) | |
107 quit_closure.Run(); | |
108 } | |
109 | |
110 // Callback when using CopyFromCompositingSurfaceToVideoFrame() API. | |
111 void FinishCopyFromCompositingSurface(const base::Closure& quit_closure, | |
112 bool frame_captured) { | |
113 ++callback_invoke_count_; | |
114 if (frame_captured) | |
115 ++frames_captured_; | |
116 if (!quit_closure.is_null()) | |
117 quit_closure.Run(); | |
118 } | |
119 | |
120 // Callback when using frame subscriber API. | |
121 void FrameDelivered(const scoped_refptr<base::MessageLoopProxy>& loop, | |
122 base::Closure quit_closure, | |
123 base::Time timestamp, | |
124 bool frame_captured) { | |
125 ++callback_invoke_count_; | |
126 if (frame_captured) | |
127 ++frames_captured_; | |
128 if (!quit_closure.is_null()) | |
129 loop->PostTask(FROM_HERE, quit_closure); | |
130 } | |
131 | |
132 // Copy one frame using the CopyFromBackingStore API. | |
133 void RunBasicCopyFromBackingStoreTest() { | |
134 SET_UP_SURFACE_OR_PASS_TEST(); | |
135 | |
136 // Repeatedly call CopyFromBackingStore() since, on some platforms (e.g., | |
137 // Windows), the operation will fail until the first "present" has been | |
138 // made. | |
139 int count_attempts = 0; | |
140 while (true) { | |
141 ++count_attempts; | |
142 base::RunLoop run_loop; | |
143 GetRenderViewHost()->CopyFromBackingStore( | |
144 gfx::Rect(), | |
145 frame_size(), | |
146 base::Bind( | |
147 &RenderWidgetHostViewBrowserTest::FinishCopyFromBackingStore, | |
148 base::Unretained(this), | |
149 run_loop.QuitClosure())); | |
150 run_loop.Run(); | |
151 | |
152 if (frames_captured()) | |
153 break; | |
154 else | |
155 GiveItSomeTime(); | |
156 } | |
157 | |
158 EXPECT_EQ(count_attempts, callback_invoke_count()); | |
159 EXPECT_EQ(1, frames_captured()); | |
160 } | |
161 | |
162 protected: | |
163 // Waits until the source is available for copying. | |
164 void WaitForCopySourceReady() { | |
165 while (!GetRenderWidgetHostViewPort()->IsSurfaceAvailableForCopy()) | |
166 GiveItSomeTime(); | |
167 } | |
168 | |
169 // Run the current message loop for a short time without unwinding the current | |
170 // call stack. | |
171 static void GiveItSomeTime() { | |
172 base::RunLoop run_loop; | |
173 MessageLoop::current()->PostDelayedTask( | |
174 FROM_HERE, | |
175 run_loop.QuitClosure(), | |
176 base::TimeDelta::FromMilliseconds(10)); | |
177 run_loop.Run(); | |
178 } | |
179 | |
180 private: | |
181 const gfx::Size frame_size_; | |
182 base::FilePath test_dir_; | |
183 int callback_invoke_count_; | |
184 int frames_captured_; | |
185 }; | |
186 | |
187 class CompositingRenderWidgetHostViewBrowserTest | |
188 : public RenderWidgetHostViewBrowserTest { | |
189 public: | |
37 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 190 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
38 ui::DisableTestCompositor(); | 191 // Note: Not appending kForceCompositingMode switch here, since not all bots |
39 } | 192 // support compositing. |
40 | 193 RenderWidgetHostViewBrowserTest::SetUpCommandLine(command_line); |
41 bool CheckAcceleratedCompositingActive() { | 194 } |
42 RenderWidgetHostImpl* impl = | 195 |
43 RenderWidgetHostImpl::From( | 196 virtual bool SetUpSourceSurface() OVERRIDE { |
44 shell()->web_contents()->GetRenderWidgetHostView()-> | 197 if (!IsForceCompositingModeEnabled()) |
45 GetRenderWidgetHost()); | 198 return false; // Not supported due to hardware or blacklisting. |
Ken Russell (switch to Gerrit)
2013/05/14 20:04:08
It's confusing that SetUpCommandLine says that it
miu
2013/05/15 00:21:40
Improved code comments to explain why this is nece
| |
46 return impl->is_accelerated_compositing_active(); | |
47 } | |
48 | |
49 bool CheckCompositingSurface() { | |
50 #if defined(OS_WIN) | |
51 if (!GpuDataManagerImpl::GetInstance()->IsUsingAcceleratedSurface()) | |
52 return false; | |
53 #endif | |
54 | |
55 RenderViewHost* const rwh = | |
56 shell()->web_contents()->GetRenderViewHost(); | |
57 RenderWidgetHostViewPort* rwhvp = | |
58 static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); | |
59 bool ret = !rwhvp->GetCompositingSurface().is_null(); | |
60 #if defined(OS_MACOSX) | 199 #if defined(OS_MACOSX) |
61 ret &= rwhvp->HasAcceleratedSurface(gfx::Size()); | 200 CHECK(IOSurfaceSupport::Initialize()); |
62 #endif | |
63 return ret; | |
64 } | |
65 | |
66 bool SetupCompositingSurface() { | |
67 #if defined(OS_MACOSX) | |
68 if (!IOSurfaceSupport::Initialize()) | |
69 return false; | |
70 #endif | 201 #endif |
71 NavigateToURL(shell(), net::FilePathToFileURL( | 202 NavigateToURL(shell(), net::FilePathToFileURL( |
72 test_dir_.AppendASCII("rwhv_compositing_animation.html"))); | 203 test_dir().AppendASCII("rwhv_compositing_animation.html"))); |
73 if (!CheckAcceleratedCompositingActive()) | 204 #if !defined(USE_AURA) |
74 return false; | 205 if (!GetRenderWidgetHost()->is_accelerated_compositing_active()) |
75 | 206 return false; // Renderer did not turn on accelerated compositing. |
76 // The page is now accelerated composited but a compositing surface might | 207 #endif |
77 // not be available immediately so wait for it. | 208 |
78 while (!CheckCompositingSurface()) { | 209 // Using accelerated compositing, but a compositing surface might not be |
79 base::RunLoop run_loop; | 210 // available yet. So, wait for it. |
80 base::MessageLoop::current()->PostDelayedTask( | 211 WaitForCopySourceReady(); |
81 FROM_HERE, | |
82 run_loop.QuitClosure(), | |
83 base::TimeDelta::FromMilliseconds(10)); | |
84 run_loop.Run(); | |
85 } | |
86 return true; | 212 return true; |
87 } | 213 } |
88 | |
89 bool SetupNonCompositing() { | |
90 NavigateToURL(shell(), net::FilePathToFileURL( | |
91 test_dir_.AppendASCII("rwhv_compositing_static.html"))); | |
92 return !CheckCompositingSurface(); | |
93 } | |
94 | |
95 void FinishCopyFromBackingStore(bool expected_result, | |
96 const base::Closure& quit_closure, | |
97 bool result, | |
98 const SkBitmap& bitmap) { | |
99 quit_closure.Run(); | |
100 EXPECT_EQ(expected_result, result); | |
101 if (expected_result) | |
102 EXPECT_FALSE(bitmap.empty()); | |
103 finish_called_ = true; | |
104 } | |
105 | |
106 void FinishCopyFromCompositingSurface(bool expected_result, | |
107 const base::Closure& quit_closure, | |
108 bool result) { | |
109 if (!quit_closure.is_null()) | |
110 quit_closure.Run(); | |
111 EXPECT_EQ(expected_result, result); | |
112 finish_called_ = true; | |
113 } | |
114 | |
115 protected: | |
116 base::FilePath test_dir_; | |
117 bool finish_called_; | |
118 gfx::Size size_; | |
119 }; | 214 }; |
120 | 215 |
216 class NonCompositingRenderWidgetHostViewBrowserTest | |
217 : public RenderWidgetHostViewBrowserTest { | |
218 public: | |
219 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
220 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); | |
221 RenderWidgetHostViewBrowserTest::SetUpCommandLine(command_line); | |
222 } | |
223 | |
224 virtual bool SetUpSourceSurface() OVERRIDE { | |
225 if (IsForceCompositingModeEnabled()) | |
226 return false; // Only compositing mode is supported on this platform. | |
227 NavigateToURL(shell(), GURL("about:blank")); | |
228 WaitForCopySourceReady(); | |
229 // Return whether the renderer left accelerated compositing turned off. | |
230 return !GetRenderWidgetHost()->is_accelerated_compositing_active(); | |
231 } | |
232 }; | |
233 | |
121 class FakeFrameSubscriber : public RenderWidgetHostViewFrameSubscriber { | 234 class FakeFrameSubscriber : public RenderWidgetHostViewFrameSubscriber { |
122 public: | 235 public: |
123 FakeFrameSubscriber( | 236 FakeFrameSubscriber( |
124 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback) | 237 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback) |
125 : callback_(callback) { | 238 : callback_(callback) { |
126 } | 239 } |
127 | 240 |
128 virtual bool ShouldCaptureFrame( | 241 virtual bool ShouldCaptureFrame( |
129 base::Time present_time, | 242 base::Time present_time, |
130 scoped_refptr<media::VideoFrame>* storage, | 243 scoped_refptr<media::VideoFrame>* storage, |
131 DeliverFrameCallback* callback) OVERRIDE { | 244 DeliverFrameCallback* callback) OVERRIDE { |
132 // Only allow one frame capture to be made. Otherwise, the compositor could | 245 // Only allow one frame capture to be made. Otherwise, the compositor could |
133 // start multiple captures, unbounded, and eventually its own limiter logic | 246 // start multiple captures, unbounded, and eventually its own limiter logic |
134 // will begin invoking |callback| with a |false| result. This flakes out | 247 // will begin invoking |callback| with a |false| result. This flakes out |
135 // the unit tests, since they receive a "failed" callback before the later | 248 // the unit tests, since they receive a "failed" callback before the later |
136 // "success" callbacks. | 249 // "success" callbacks. |
137 if (callback_.is_null()) | 250 if (callback_.is_null()) |
138 return false; | 251 return false; |
139 *storage = media::VideoFrame::CreateBlackFrame(gfx::Size(100, 100)); | 252 *storage = media::VideoFrame::CreateBlackFrame(gfx::Size(100, 100)); |
140 *callback = callback_; | 253 *callback = callback_; |
141 callback_.Reset(); | 254 callback_.Reset(); |
142 return true; | 255 return true; |
143 } | 256 } |
144 | 257 |
145 private: | 258 private: |
146 DeliverFrameCallback callback_; | 259 DeliverFrameCallback callback_; |
147 }; | 260 }; |
148 | 261 |
149 #if defined(OS_MACOSX) || defined(OS_WIN) | 262 // Disable tests for Android and IOS as these platforms have incomplete |
263 // implementation. | |
264 #if !defined(OS_ANDROID) && !defined(OS_IOS) | |
150 | 265 |
151 static void DeliverFrameFunc(const scoped_refptr<base::MessageLoopProxy>& loop, | 266 // The CopyFromBackingStore() API should work on all platforms when compositing |
152 base::Closure quit_closure, | 267 // is enabled. |
153 bool* frame_captured_out, | 268 IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTest, |
154 base::Time timestamp, | 269 CopyFromBackingStore) { |
155 bool frame_captured) { | 270 RunBasicCopyFromBackingStoreTest(); |
156 *frame_captured_out = frame_captured; | |
157 if (!quit_closure.is_null()) | |
158 loop->PostTask(FROM_HERE, quit_closure); | |
159 } | 271 } |
160 | 272 |
161 #endif | 273 // The CopyFromBackingStore() API should work on all platforms when compositing |
274 // is disabled. | |
275 IN_PROC_BROWSER_TEST_F(NonCompositingRenderWidgetHostViewBrowserTest, | |
276 CopyFromBackingStore) { | |
277 RunBasicCopyFromBackingStoreTest(); | |
278 } | |
162 | 279 |
163 #if defined(OS_MACOSX) | 280 // Tests that the callback passed to CopyFromBackingStore is always called, |
164 // Tests that the callback passed to CopyFromBackingStore is always called, even | 281 // even when the RenderWidgetHost is deleting in the middle of an async copy. |
165 // when the RenderWidgetHost is deleting in the middle of an async copy. | 282 IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTest, |
166 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest, | 283 CopyFromBackingStore_CallbackDespiteDelete) { |
167 MacAsyncCopyFromBackingStoreCallbackTest) { | 284 SET_UP_SURFACE_OR_PASS_TEST(); |
168 if (!SetupCompositingSurface()) { | |
169 LOG(WARNING) << "Accelerated compositing not running."; | |
170 return; | |
171 } | |
172 | 285 |
173 base::RunLoop run_loop; | 286 base::RunLoop run_loop; |
174 RenderViewHost* const rwh = | 287 GetRenderViewHost()->CopyFromBackingStore( |
175 shell()->web_contents()->GetRenderViewHost(); | |
176 RenderWidgetHostViewPort* rwhvp = | |
177 static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); | |
178 | |
179 rwh->CopyFromBackingStore( | |
180 gfx::Rect(), | 288 gfx::Rect(), |
181 size_, | 289 frame_size(), |
182 base::Bind(&RenderWidgetHostViewBrowserTest::FinishCopyFromBackingStore, | 290 base::Bind(&RenderWidgetHostViewBrowserTest::FinishCopyFromBackingStore, |
183 base::Unretained(this), false, run_loop.QuitClosure())); | 291 base::Unretained(this), run_loop.QuitClosure())); |
184 | 292 // Delete the surface before the callback is run. |
185 // Delete the surface before the callback is run. This is synchronous until | 293 GetRenderWidgetHostViewPort()->AcceleratedSurfaceRelease(); |
186 // we get to the copy_timer_, so we will always end up in the destructor | |
187 // before the timer fires. | |
188 rwhvp->AcceleratedSurfaceRelease(); | |
189 run_loop.Run(); | 294 run_loop.Run(); |
190 | 295 |
191 EXPECT_TRUE(finish_called_); | 296 EXPECT_EQ(1, callback_invoke_count()); |
192 } | 297 } |
193 | 298 |
194 // Tests that the callback passed to CopyFromCompositingSurfaceToVideoFrame is | 299 // Tests that the callback passed to CopyFromCompositingSurfaceToVideoFrame is |
195 // always called, even when the RenderWidgetHost is deleting in the middle of | 300 // always called, even when the RenderWidgetHost is deleting in the middle of |
196 // an async copy. | 301 // an async copy. |
197 IN_PROC_BROWSER_TEST_F( | 302 IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTest, |
198 RenderWidgetHostViewBrowserTest, | 303 CopyFromCompositingSurface_CallbackDespiteDelete) { |
199 MacAsyncCopyFromCompositingSurfaceToVideoFrameCallbackTest) { | 304 SET_UP_SURFACE_OR_PASS_TEST(); |
200 if (!SetupCompositingSurface()) { | 305 RenderWidgetHostViewPort* const view = GetRenderWidgetHostViewPort(); |
201 LOG(WARNING) << "Accelerated compositing not running."; | 306 if (!view->CanCopyToVideoFrame()) { |
307 LOG(WARNING) << | |
308 ("Blindly passing this test: CopyFromCompositingSurfaceToVideoFrame() " | |
309 "not supported on this platform."); | |
202 return; | 310 return; |
203 } | 311 } |
204 | 312 |
205 base::RunLoop run_loop; | 313 base::RunLoop run_loop; |
206 RenderViewHost* const rwh = | |
207 shell()->web_contents()->GetRenderViewHost(); | |
208 RenderWidgetHostViewPort* rwhvp = | |
209 static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); | |
210 | |
211 scoped_refptr<media::VideoFrame> dest = | 314 scoped_refptr<media::VideoFrame> dest = |
212 media::VideoFrame::CreateBlackFrame(size_); | 315 media::VideoFrame::CreateBlackFrame(frame_size()); |
213 rwhvp->CopyFromCompositingSurfaceToVideoFrame( | 316 view->CopyFromCompositingSurfaceToVideoFrame( |
214 gfx::Rect(rwhvp->GetViewBounds().size()), dest, base::Bind( | 317 gfx::Rect(view->GetViewBounds().size()), dest, base::Bind( |
215 &RenderWidgetHostViewBrowserTest::FinishCopyFromCompositingSurface, | 318 &RenderWidgetHostViewBrowserTest::FinishCopyFromCompositingSurface, |
216 base::Unretained(this), false, run_loop.QuitClosure())); | 319 base::Unretained(this), run_loop.QuitClosure())); |
217 | 320 // Delete the surface before the callback is run. |
218 // Delete the surface before the callback is run. This is synchronous until | 321 view->AcceleratedSurfaceRelease(); |
219 // we get to the copy_timer_, so we will always end up in the destructor | |
220 // before the timer fires. | |
221 rwhvp->AcceleratedSurfaceRelease(); | |
222 run_loop.Run(); | 322 run_loop.Run(); |
223 | 323 |
224 ASSERT_TRUE(finish_called_); | 324 EXPECT_EQ(1, callback_invoke_count()); |
225 } | 325 } |
326 | |
327 // With compositing turned off, no platforms should support the | |
328 // CopyFromCompositingSurfaceToVideoFrame() API. | |
329 IN_PROC_BROWSER_TEST_F(NonCompositingRenderWidgetHostViewBrowserTest, | |
330 CopyFromCompositingSurfaceToVideoFrameCallbackTest) { | |
331 SET_UP_SURFACE_OR_PASS_TEST(); | |
332 EXPECT_FALSE(GetRenderWidgetHostViewPort()->CanCopyToVideoFrame()); | |
333 } | |
334 | |
335 // Test basic frame subscription functionality. We subscribe, and then run | |
336 // until at least one DeliverFrameCallback has been invoked. | |
337 IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTest, | |
338 FrameSubscriberTest) { | |
339 SET_UP_SURFACE_OR_PASS_TEST(); | |
340 RenderWidgetHostViewPort* const view = GetRenderWidgetHostViewPort(); | |
341 if (!view->CanSubscribeFrame()) { | |
342 LOG(WARNING) << ("Blindly passing this test: Frame subscription not " | |
343 "supported on this platform."); | |
344 return; | |
345 } | |
346 #if defined(USE_AURA) | |
347 if (ui::IsTestCompositorEnabled()) { | |
348 LOG(WARNING) << ("Blindly passing this test: Aura test compositor doesn't " | |
349 "support frame subscription."); | |
350 // TODO(miu): Aura test compositor should support frame subscription for | |
351 // testing. http://crbug.com/240572 | |
352 return; | |
353 } | |
226 #endif | 354 #endif |
227 | 355 |
228 #if (defined(OS_WIN) && !defined(USE_AURA)) || defined(OS_MACOSX) | 356 base::RunLoop run_loop; |
229 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest, | 357 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber( |
230 FrameSubscriberTest) { | 358 new FakeFrameSubscriber( |
231 if (!SetupCompositingSurface()) { | 359 base::Bind(&RenderWidgetHostViewBrowserTest::FrameDelivered, |
232 LOG(WARNING) << "Accelerated compositing not running."; | 360 base::Unretained(this), |
361 base::MessageLoopProxy::current(), | |
362 run_loop.QuitClosure()))); | |
363 view->BeginFrameSubscription(subscriber.Pass()); | |
364 run_loop.Run(); | |
365 view->EndFrameSubscription(); | |
366 | |
367 EXPECT_LE(1, callback_invoke_count()); | |
368 EXPECT_LE(1, frames_captured()); | |
369 } | |
370 | |
371 // Test that we can copy twice from an accelerated composited page. | |
372 IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTest, CopyTwice) { | |
373 SET_UP_SURFACE_OR_PASS_TEST(); | |
374 RenderWidgetHostViewPort* const view = GetRenderWidgetHostViewPort(); | |
375 if (!view->CanCopyToVideoFrame()) { | |
376 LOG(WARNING) << ("Blindly passing this test: " | |
377 "CopyFromCompositingSurfaceToVideoFrame() not supported " | |
378 "on this platform."); | |
233 return; | 379 return; |
234 } | 380 } |
235 | 381 |
236 base::RunLoop run_loop; | 382 base::RunLoop run_loop; |
237 RenderWidgetHostViewPort* view = RenderWidgetHostViewPort::FromRWHV( | 383 scoped_refptr<media::VideoFrame> first_output = |
238 shell()->web_contents()->GetRenderViewHost()->GetView()); | 384 media::VideoFrame::CreateBlackFrame(frame_size()); |
239 ASSERT_TRUE(view); | 385 ASSERT_TRUE(first_output); |
240 | 386 scoped_refptr<media::VideoFrame> second_output = |
241 if (!view->CanSubscribeFrame()) { | 387 media::VideoFrame::CreateBlackFrame(frame_size()); |
242 LOG(WARNING) << "Frame subscription no supported on this platform."; | 388 ASSERT_TRUE(second_output); |
243 return; | 389 view->CopyFromCompositingSurfaceToVideoFrame( |
244 } | 390 gfx::Rect(view->GetViewBounds().size()), first_output, |
245 | 391 base::Bind(&RenderWidgetHostViewBrowserTest::FrameDelivered, |
246 bool frame_captured = false; | 392 base::Unretained(this), |
247 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber( | |
248 new FakeFrameSubscriber(base::Bind(&DeliverFrameFunc, | |
249 base::MessageLoopProxy::current(), | |
250 run_loop.QuitClosure(), | |
251 &frame_captured))); | |
252 view->BeginFrameSubscription(subscriber.Pass()); | |
253 run_loop.Run(); | |
254 view->EndFrameSubscription(); | |
255 EXPECT_TRUE(frame_captured); | |
256 } | |
257 | |
258 // Test copying from backing store when page is non-accelerated-composited. | |
259 // Flaky. http://crbug.com/224351 | |
260 #if defined(OS_MACOSX) || defined(OS_WIN) | |
261 #define MAYBE_CopyFromBackingStore DISABLED_CopyFromBackingStore | |
262 #else | |
263 #define MAYBE_CopyFromBackingStore CopyFromBackingStore | |
264 #endif | |
265 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest, | |
266 MAYBE_CopyFromBackingStore) { | |
267 SetupNonCompositing(); | |
268 base::RunLoop run_loop; | |
269 | |
270 shell()->web_contents()->GetRenderViewHost()->CopyFromBackingStore( | |
271 gfx::Rect(), | |
272 size_, | |
273 base::Bind(&RenderWidgetHostViewBrowserTest::FinishCopyFromBackingStore, | |
274 base::Unretained(this), true, run_loop.QuitClosure())); | |
275 run_loop.Run(); | |
276 | |
277 EXPECT_TRUE(finish_called_); | |
278 } | |
279 #endif | |
280 | |
281 #if defined(OS_MACOSX) | |
282 // Test that we can copy twice from an accelerated composited page. | |
283 // This test is only running on Mac because this is the only platform that | |
284 // we can reliably detect that accelerated surface is in use. | |
285 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest, CopyTwice) { | |
286 if (!SetupCompositingSurface()) { | |
287 LOG(WARNING) << "Accelerated compositing not running."; | |
288 return; | |
289 } | |
290 | |
291 base::RunLoop run_loop; | |
292 RenderViewHost* const rwh = | |
293 shell()->web_contents()->GetRenderViewHost(); | |
294 RenderWidgetHostViewPort* rwhvp = | |
295 static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); | |
296 scoped_refptr<media::VideoFrame> dest = | |
297 media::VideoFrame::CreateBlackFrame(size_); | |
298 | |
299 bool first_frame_captured = false; | |
300 bool second_frame_captured = false; | |
301 rwhvp->CopyFromCompositingSurfaceToVideoFrame( | |
302 gfx::Rect(rwhvp->GetViewBounds().size()), dest, | |
303 base::Bind(&DeliverFrameFunc, | |
304 base::MessageLoopProxy::current(), | 393 base::MessageLoopProxy::current(), |
305 base::Closure(), | 394 base::Closure(), |
306 &first_frame_captured, | |
307 base::Time::Now())); | 395 base::Time::Now())); |
308 rwhvp->CopyFromCompositingSurfaceToVideoFrame( | 396 view->CopyFromCompositingSurfaceToVideoFrame( |
309 gfx::Rect(rwhvp->GetViewBounds().size()), dest, | 397 gfx::Rect(view->GetViewBounds().size()), second_output, |
310 base::Bind(&DeliverFrameFunc, | 398 base::Bind(&RenderWidgetHostViewBrowserTest::FrameDelivered, |
399 base::Unretained(this), | |
311 base::MessageLoopProxy::current(), | 400 base::MessageLoopProxy::current(), |
312 run_loop.QuitClosure(), | 401 run_loop.QuitClosure(), |
313 &second_frame_captured, | |
314 base::Time::Now())); | 402 base::Time::Now())); |
315 run_loop.Run(); | 403 run_loop.Run(); |
316 | 404 |
317 EXPECT_TRUE(first_frame_captured); | 405 EXPECT_EQ(2, callback_invoke_count()); |
318 EXPECT_TRUE(second_frame_captured); | 406 EXPECT_EQ(2, frames_captured()); |
319 } | 407 } |
320 #endif | |
321 | 408 |
409 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | |
410 | |
411 } // namespace | |
322 } // namespace content | 412 } // namespace content |
OLD | NEW |