OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/test/test_simple_task_runner.h" | 5 #include "base/test/test_simple_task_runner.h" |
6 #include "cc/output/output_surface.h" | 6 #include "cc/output/output_surface.h" |
7 #include "cc/output/output_surface_client.h" | 7 #include "cc/output/output_surface_client.h" |
8 #include "cc/output/software_output_device.h" | 8 #include "cc/output/software_output_device.h" |
9 #include "cc/test/scheduler_test_common.h" | 9 #include "cc/test/scheduler_test_common.h" |
10 #include "cc/test/test_web_graphics_context_3d.h" | 10 #include "cc/test/test_web_graphics_context_3d.h" |
11 #include "gpu/GLES2/gl2extchromium.h" | 11 #include "gpu/GLES2/gl2extchromium.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 namespace { | 15 namespace { |
16 | 16 |
17 class TestOutputSurface : public OutputSurface { | 17 class TestOutputSurface : public OutputSurface { |
18 public: | 18 public: |
19 explicit TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d) | 19 explicit TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d) |
20 : OutputSurface(context3d.Pass()) {} | 20 : OutputSurface(context3d.Pass()), |
| 21 retroactive_begin_frame_deadline_enabled_(false) {} |
21 | 22 |
22 explicit TestOutputSurface( | 23 explicit TestOutputSurface( |
23 scoped_ptr<cc::SoftwareOutputDevice> software_device) | 24 scoped_ptr<cc::SoftwareOutputDevice> software_device) |
24 : OutputSurface(software_device.Pass()) {} | 25 : OutputSurface(software_device.Pass()), |
| 26 retroactive_begin_frame_deadline_enabled_(false) {} |
25 | 27 |
26 TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d, | 28 TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d, |
27 scoped_ptr<cc::SoftwareOutputDevice> software_device) | 29 scoped_ptr<cc::SoftwareOutputDevice> software_device) |
28 : OutputSurface(context3d.Pass(), software_device.Pass()) {} | 30 : OutputSurface(context3d.Pass(), software_device.Pass()), |
| 31 retroactive_begin_frame_deadline_enabled_(false) {} |
29 | 32 |
30 bool InitializeNewContext3D( | 33 bool InitializeNewContext3D( |
31 scoped_ptr<WebKit::WebGraphicsContext3D> new_context3d) { | 34 scoped_ptr<WebKit::WebGraphicsContext3D> new_context3d) { |
32 return InitializeAndSetContext3D(new_context3d.Pass(), | 35 return InitializeAndSetContext3D(new_context3d.Pass(), |
33 scoped_refptr<ContextProvider>()); | 36 scoped_refptr<ContextProvider>()); |
34 } | 37 } |
35 | 38 |
36 bool HasClientForTesting() { | 39 bool HasClientForTesting() { |
37 return HasClient(); | 40 return HasClient(); |
38 } | 41 } |
(...skipping 12 matching lines...) Expand all Loading... |
51 } | 54 } |
52 | 55 |
53 int pending_swap_buffers() { | 56 int pending_swap_buffers() { |
54 return pending_swap_buffers_; | 57 return pending_swap_buffers_; |
55 } | 58 } |
56 | 59 |
57 void OnSwapBuffersCompleteForTesting() { | 60 void OnSwapBuffersCompleteForTesting() { |
58 OnSwapBuffersComplete(NULL); | 61 OnSwapBuffersComplete(NULL); |
59 } | 62 } |
60 | 63 |
61 void SetRetroactiveBeginFramePeriod(base::TimeDelta period) { | 64 void EnableRetroactiveBeginFrameDeadline(bool enable) { |
62 retroactive_begin_frame_period_ = period; | 65 retroactive_begin_frame_deadline_enabled_ = enable; |
63 } | 66 } |
64 | 67 |
65 protected: | 68 protected: |
66 virtual void PostCheckForRetroactiveBeginFrame() OVERRIDE { | 69 virtual void PostCheckForRetroactiveBeginFrame() OVERRIDE { |
67 // For testing purposes, we check immediately rather than posting a task. | 70 // For testing purposes, we check immediately rather than posting a task. |
68 CheckForRetroactiveBeginFrame(); | 71 CheckForRetroactiveBeginFrame(); |
69 } | 72 } |
70 | 73 |
71 virtual base::TimeDelta RetroactiveBeginFramePeriod() OVERRIDE { | 74 virtual base::TimeTicks RetroactiveBeginFrameDeadline() OVERRIDE { |
72 return retroactive_begin_frame_period_; | 75 if (retroactive_begin_frame_deadline_enabled_) |
| 76 return OutputSurface::RetroactiveBeginFrameDeadline(); |
| 77 return base::TimeTicks(); |
73 } | 78 } |
74 | 79 |
75 base::TimeDelta retroactive_begin_frame_period_; | 80 bool retroactive_begin_frame_deadline_enabled_; |
76 }; | 81 }; |
77 | 82 |
78 class FakeOutputSurfaceClient : public OutputSurfaceClient { | 83 class FakeOutputSurfaceClient : public OutputSurfaceClient { |
79 public: | 84 public: |
80 FakeOutputSurfaceClient() | 85 FakeOutputSurfaceClient() |
81 : begin_frame_count_(0), | 86 : begin_frame_count_(0), |
82 deferred_initialize_result_(true), | 87 deferred_initialize_result_(true), |
83 deferred_initialize_called_(false), | 88 deferred_initialize_called_(false), |
84 did_lose_output_surface_called_(false) {} | 89 did_lose_output_surface_called_(false) {} |
85 | 90 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 bool throttle_frame_production = true; | 235 bool throttle_frame_production = true; |
231 const base::TimeDelta display_refresh_interval = | 236 const base::TimeDelta display_refresh_interval = |
232 BeginFrameArgs::DefaultInterval(); | 237 BeginFrameArgs::DefaultInterval(); |
233 | 238 |
234 output_surface.InitializeBeginFrameEmulation( | 239 output_surface.InitializeBeginFrameEmulation( |
235 task_runner.get(), | 240 task_runner.get(), |
236 throttle_frame_production, | 241 throttle_frame_production, |
237 display_refresh_interval); | 242 display_refresh_interval); |
238 | 243 |
239 output_surface.SetMaxFramesPending(2); | 244 output_surface.SetMaxFramesPending(2); |
240 output_surface.SetRetroactiveBeginFramePeriod( | 245 output_surface.EnableRetroactiveBeginFrameDeadline(false); |
241 base::TimeDelta::FromSeconds(-1)); | |
242 | 246 |
243 // We should start off with 0 BeginFrames | 247 // We should start off with 0 BeginFrames |
244 EXPECT_EQ(client.begin_frame_count(), 0); | 248 EXPECT_EQ(client.begin_frame_count(), 0); |
245 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | 249 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); |
246 | 250 |
247 // We should not have a pending task until a BeginFrame has been requested. | 251 // We should not have a pending task until a BeginFrame has been requested. |
248 EXPECT_FALSE(task_runner->HasPendingTask()); | 252 EXPECT_FALSE(task_runner->HasPendingTask()); |
249 output_surface.SetNeedsBeginFrame(true); | 253 output_surface.SetNeedsBeginFrame(true); |
250 EXPECT_TRUE(task_runner->HasPendingTask()); | 254 EXPECT_TRUE(task_runner->HasPendingTask()); |
251 | 255 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 TestOutputSurface output_surface( | 309 TestOutputSurface output_surface( |
306 context3d.PassAs<WebKit::WebGraphicsContext3D>()); | 310 context3d.PassAs<WebKit::WebGraphicsContext3D>()); |
307 EXPECT_FALSE(output_surface.HasClientForTesting()); | 311 EXPECT_FALSE(output_surface.HasClientForTesting()); |
308 | 312 |
309 FakeOutputSurfaceClient client; | 313 FakeOutputSurfaceClient client; |
310 EXPECT_TRUE(output_surface.BindToClient(&client)); | 314 EXPECT_TRUE(output_surface.BindToClient(&client)); |
311 EXPECT_TRUE(output_surface.HasClientForTesting()); | 315 EXPECT_TRUE(output_surface.HasClientForTesting()); |
312 EXPECT_FALSE(client.deferred_initialize_called()); | 316 EXPECT_FALSE(client.deferred_initialize_called()); |
313 | 317 |
314 output_surface.SetMaxFramesPending(2); | 318 output_surface.SetMaxFramesPending(2); |
315 | 319 output_surface.EnableRetroactiveBeginFrameDeadline(true); |
316 // Enable retroactive BeginFrames. | |
317 output_surface.SetRetroactiveBeginFramePeriod( | |
318 base::TimeDelta::FromSeconds(100000)); | |
319 | 320 |
320 // Optimistically injected BeginFrames should be throttled if | 321 // Optimistically injected BeginFrames should be throttled if |
321 // SetNeedsBeginFrame is false... | 322 // SetNeedsBeginFrame is false... |
322 output_surface.SetNeedsBeginFrame(false); | 323 output_surface.SetNeedsBeginFrame(false); |
323 output_surface.BeginFrameForTesting(); | 324 output_surface.BeginFrameForTesting(); |
324 EXPECT_EQ(client.begin_frame_count(), 0); | 325 EXPECT_EQ(client.begin_frame_count(), 0); |
325 // ...and retroactively triggered by a SetNeedsBeginFrame. | 326 // ...and retroactively triggered by a SetNeedsBeginFrame. |
326 output_surface.SetNeedsBeginFrame(true); | 327 output_surface.SetNeedsBeginFrame(true); |
327 EXPECT_EQ(client.begin_frame_count(), 1); | 328 EXPECT_EQ(client.begin_frame_count(), 1); |
328 | 329 |
(...skipping 18 matching lines...) Expand all Loading... |
347 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); | 348 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); |
348 output_surface.BeginFrameForTesting(); | 349 output_surface.BeginFrameForTesting(); |
349 EXPECT_EQ(client.begin_frame_count(), 3); | 350 EXPECT_EQ(client.begin_frame_count(), 3); |
350 // ...and retroactively triggered by OnSwapBuffersComplete | 351 // ...and retroactively triggered by OnSwapBuffersComplete |
351 output_surface.OnSwapBuffersCompleteForTesting(); | 352 output_surface.OnSwapBuffersCompleteForTesting(); |
352 EXPECT_EQ(client.begin_frame_count(), 4); | 353 EXPECT_EQ(client.begin_frame_count(), 4); |
353 } | 354 } |
354 | 355 |
355 } // namespace | 356 } // namespace |
356 } // namespace cc | 357 } // namespace cc |
OLD | NEW |