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" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 RenderWidgetHostViewBrowserTest() : finish_called_(false), size_(400, 300) {} | 31 RenderWidgetHostViewBrowserTest() : finish_called_(false), size_(400, 300) {} |
32 | 32 |
33 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 33 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
34 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_dir_)); | 34 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_dir_)); |
35 } | 35 } |
36 | 36 |
37 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 37 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
38 ui::DisableTestCompositor(); | 38 ui::DisableTestCompositor(); |
39 } | 39 } |
40 | 40 |
41 bool CheckAcceleratedCompositingActive() { | 41 bool IsAcceleratedCompositingActive() { |
42 RenderWidgetHostImpl* impl = | 42 RenderWidgetHostImpl* impl = |
43 RenderWidgetHostImpl::From( | 43 RenderWidgetHostImpl::From( |
44 shell()->web_contents()->GetRenderWidgetHostView()-> | 44 shell()->web_contents()->GetRenderWidgetHostView()-> |
45 GetRenderWidgetHost()); | 45 GetRenderWidgetHost()); |
46 return impl->is_accelerated_compositing_active(); | 46 return impl->is_accelerated_compositing_active(); |
47 } | 47 } |
48 | 48 |
49 bool CheckCompositingSurface() { | 49 bool IsCompositingSurfaceReady() { |
50 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
51 if (!GpuDataManagerImpl::GetInstance()->IsUsingAcceleratedSurface()) | 51 if (!GpuDataManagerImpl::GetInstance()->IsUsingAcceleratedSurface()) |
52 return false; | 52 return false; |
53 #endif | 53 #endif |
54 | 54 |
55 RenderViewHost* const rwh = | 55 RenderViewHost* const rwh = |
56 shell()->web_contents()->GetRenderViewHost(); | 56 shell()->web_contents()->GetRenderViewHost(); |
57 RenderWidgetHostViewPort* rwhvp = | 57 RenderWidgetHostViewPort* rwhvp = |
58 static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); | 58 static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); |
59 bool ret = !rwhvp->GetCompositingSurface().is_null(); | 59 bool ret = !rwhvp->GetCompositingSurface().is_null(); |
60 #if defined(OS_MACOSX) | 60 #if defined(OS_MACOSX) |
61 ret &= rwhvp->HasAcceleratedSurface(gfx::Size()); | 61 ret &= rwhvp->HasAcceleratedSurface(gfx::Size()); |
62 #endif | 62 #endif |
63 return ret; | 63 return ret; |
64 } | 64 } |
65 | 65 |
66 bool IsBackingStoreReady() { | |
67 RenderWidgetHostImpl* const rwh = RenderWidgetHostImpl::From( | |
68 shell()->web_contents()->GetRenderWidgetHostView()-> | |
69 GetRenderWidgetHost()); | |
70 // Note: Passing false to GetBackingStore() asks for the backing store | |
71 // without forcing its creation. We want to the browser to create it via | |
72 // its normal mechanism. | |
73 return rwh->GetBackingStore(false) != NULL; | |
74 } | |
75 | |
76 // Waits until either the compositing surface or the backing store is ready as | |
77 // a source for copying. | |
78 void WaitForCopySourceReady(bool is_compositing_surface) { | |
79 while ((is_compositing_surface && !IsCompositingSurfaceReady()) || | |
80 (!is_compositing_surface && !IsBackingStoreReady())) { | |
81 base::RunLoop run_loop; | |
82 MessageLoop::current()->PostDelayedTask( | |
83 FROM_HERE, | |
84 run_loop.QuitClosure(), | |
85 base::TimeDelta::FromMilliseconds(10)); | |
86 run_loop.Run(); | |
87 } | |
88 } | |
89 | |
66 bool SetupCompositingSurface() { | 90 bool SetupCompositingSurface() { |
67 #if defined(OS_MACOSX) | 91 #if defined(OS_MACOSX) |
68 if (!IOSurfaceSupport::Initialize()) | 92 if (!IOSurfaceSupport::Initialize()) |
69 return false; | 93 return false; |
70 #endif | 94 #endif |
71 NavigateToURL(shell(), net::FilePathToFileURL( | 95 NavigateToURL(shell(), net::FilePathToFileURL( |
72 test_dir_.AppendASCII("rwhv_compositing_animation.html"))); | 96 test_dir_.AppendASCII("rwhv_compositing_animation.html"))); |
73 if (!CheckAcceleratedCompositingActive()) | 97 if (!IsAcceleratedCompositingActive()) |
74 return false; | 98 return false; |
75 | 99 |
76 // The page is now accelerated composited but a compositing surface might | 100 // The page is now accelerated composited but a compositing surface might |
77 // not be available immediately so wait for it. | 101 // not be available immediately so wait for it. |
78 while (!CheckCompositingSurface()) { | 102 WaitForCopySourceReady(true); |
79 base::RunLoop run_loop; | |
80 MessageLoop::current()->PostDelayedTask( | |
81 FROM_HERE, | |
82 run_loop.QuitClosure(), | |
83 base::TimeDelta::FromMilliseconds(10)); | |
84 run_loop.Run(); | |
85 } | |
86 return true; | 103 return true; |
87 } | 104 } |
88 | 105 |
89 bool SetupNonCompositing() { | 106 bool SetupNonCompositing() { |
107 // Assumption: Static HTML pages with only text will cause the RenderWidget | |
108 // to turn on compositing. | |
ncarter (slow)
2013/04/29 23:34:21
The text here describes the opposite of what the n
| |
90 NavigateToURL(shell(), net::FilePathToFileURL( | 109 NavigateToURL(shell(), net::FilePathToFileURL( |
91 test_dir_.AppendASCII("rwhv_compositing_static.html"))); | 110 test_dir_.AppendASCII("rwhv_compositing_static.html"))); |
92 return !CheckCompositingSurface(); | 111 WaitForCopySourceReady(false); |
112 return true; | |
93 } | 113 } |
94 | 114 |
95 void FinishCopyFromBackingStore(bool expected_result, | 115 void FinishCopyFromBackingStore(bool expected_result, |
96 const base::Closure& quit_closure, | 116 const base::Closure& quit_closure, |
97 bool result, | 117 bool result, |
98 const SkBitmap& bitmap) { | 118 const SkBitmap& bitmap) { |
99 quit_closure.Run(); | 119 quit_closure.Run(); |
100 EXPECT_EQ(expected_result, result); | 120 EXPECT_EQ(expected_result, result); |
101 if (expected_result) | 121 if (expected_result) |
102 EXPECT_FALSE(bitmap.empty()); | 122 EXPECT_FALSE(bitmap.empty()); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 new FakeFrameSubscriber(base::Bind(&DeliverFrameFunc, | 268 new FakeFrameSubscriber(base::Bind(&DeliverFrameFunc, |
249 base::MessageLoopProxy::current(), | 269 base::MessageLoopProxy::current(), |
250 run_loop.QuitClosure(), | 270 run_loop.QuitClosure(), |
251 &frame_captured))); | 271 &frame_captured))); |
252 view->BeginFrameSubscription(subscriber.Pass()); | 272 view->BeginFrameSubscription(subscriber.Pass()); |
253 run_loop.Run(); | 273 run_loop.Run(); |
254 view->EndFrameSubscription(); | 274 view->EndFrameSubscription(); |
255 EXPECT_TRUE(frame_captured); | 275 EXPECT_TRUE(frame_captured); |
256 } | 276 } |
257 | 277 |
258 // Test copying from backing store when page is non-accelerated-composited. | 278 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest, CopyFromBackingStore) { |
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(); | 279 SetupNonCompositing(); |
280 LOG_IF(WARNING, IsCompositingSurfaceReady()) | |
281 << "Accelerated compositing is still running for a static HTML page."; | |
Ken Russell (switch to Gerrit)
2013/04/29 23:08:54
It looks to me like this test's assumptions are br
ncarter (slow)
2013/04/29 23:34:21
Agree, and I'm not such a big fan of a LOG_WARNING
| |
282 | |
268 base::RunLoop run_loop; | 283 base::RunLoop run_loop; |
269 | |
270 shell()->web_contents()->GetRenderViewHost()->CopyFromBackingStore( | 284 shell()->web_contents()->GetRenderViewHost()->CopyFromBackingStore( |
271 gfx::Rect(), | 285 gfx::Rect(), |
272 size_, | 286 size_, |
273 base::Bind(&RenderWidgetHostViewBrowserTest::FinishCopyFromBackingStore, | 287 base::Bind(&RenderWidgetHostViewBrowserTest::FinishCopyFromBackingStore, |
274 base::Unretained(this), true, run_loop.QuitClosure())); | 288 base::Unretained(this), true, run_loop.QuitClosure())); |
275 run_loop.Run(); | 289 run_loop.Run(); |
276 | 290 |
277 EXPECT_TRUE(finish_called_); | 291 EXPECT_TRUE(finish_called_); |
278 } | 292 } |
279 #endif | 293 #endif |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 &second_frame_captured, | 327 &second_frame_captured, |
314 base::Time::Now())); | 328 base::Time::Now())); |
315 run_loop.Run(); | 329 run_loop.Run(); |
316 | 330 |
317 EXPECT_TRUE(first_frame_captured); | 331 EXPECT_TRUE(first_frame_captured); |
318 EXPECT_TRUE(second_frame_captured); | 332 EXPECT_TRUE(second_frame_captured); |
319 } | 333 } |
320 #endif | 334 #endif |
321 | 335 |
322 } // namespace content | 336 } // namespace content |
OLD | NEW |