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 "cc/output/output_surface.h" | 5 #include "cc/output/output_surface.h" |
6 | 6 |
7 #include "base/test/test_simple_task_runner.h" | 7 #include "base/test/test_simple_task_runner.h" |
8 #include "cc/debug/test_context_provider.h" | 8 #include "cc/debug/test_context_provider.h" |
9 #include "cc/debug/test_web_graphics_context_3d.h" | 9 #include "cc/debug/test_web_graphics_context_3d.h" |
10 #include "cc/output/managed_memory_policy.h" | 10 #include "cc/output/managed_memory_policy.h" |
11 #include "cc/output/output_surface_client.h" | 11 #include "cc/output/output_surface_client.h" |
12 #include "cc/output/software_output_device.h" | 12 #include "cc/output/software_output_device.h" |
13 #include "cc/test/fake_output_surface.h" | 13 #include "cc/test/fake_output_surface.h" |
14 #include "cc/test/fake_output_surface_client.h" | 14 #include "cc/test/fake_output_surface_client.h" |
15 #include "cc/test/scheduler_test_common.h" | 15 #include "cc/test/scheduler_test_common.h" |
16 #include "gpu/GLES2/gl2extchromium.h" | 16 #include "gpu/GLES2/gl2extchromium.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 namespace { | 20 namespace { |
21 | 21 |
22 class TestOutputSurface : public OutputSurface { | 22 class TestOutputSurface : public OutputSurface { |
23 public: | 23 public: |
24 explicit TestOutputSurface(scoped_refptr<ContextProvider> context_provider) | 24 explicit TestOutputSurface(scoped_refptr<ContextProvider> context_provider) |
25 : OutputSurface(context_provider) {} | 25 : OutputSurface(context_provider), |
| 26 retroactive_begin_frame_deadline_enabled_(false), |
| 27 override_retroactive_period_(false) {} |
26 | 28 |
27 explicit TestOutputSurface( | 29 explicit TestOutputSurface( |
28 scoped_ptr<cc::SoftwareOutputDevice> software_device) | 30 scoped_ptr<cc::SoftwareOutputDevice> software_device) |
29 : OutputSurface(software_device.Pass()) {} | 31 : OutputSurface(software_device.Pass()), |
| 32 retroactive_begin_frame_deadline_enabled_(false), |
| 33 override_retroactive_period_(false) {} |
30 | 34 |
31 TestOutputSurface(scoped_refptr<ContextProvider> context_provider, | 35 TestOutputSurface(scoped_refptr<ContextProvider> context_provider, |
32 scoped_ptr<cc::SoftwareOutputDevice> software_device) | 36 scoped_ptr<cc::SoftwareOutputDevice> software_device) |
33 : OutputSurface(context_provider, software_device.Pass()) {} | 37 : OutputSurface(context_provider, software_device.Pass()), |
| 38 retroactive_begin_frame_deadline_enabled_(false), |
| 39 override_retroactive_period_(false) {} |
34 | 40 |
35 bool InitializeNewContext3d( | 41 bool InitializeNewContext3d( |
36 scoped_refptr<ContextProvider> new_context_provider) { | 42 scoped_refptr<ContextProvider> new_context_provider) { |
37 return InitializeAndSetContext3d(new_context_provider, | 43 return InitializeAndSetContext3d(new_context_provider, |
38 scoped_refptr<ContextProvider>()); | 44 scoped_refptr<ContextProvider>()); |
39 } | 45 } |
40 | 46 |
41 using OutputSurface::ReleaseGL; | 47 using OutputSurface::ReleaseGL; |
42 | 48 |
43 void OnVSyncParametersChangedForTesting(base::TimeTicks timebase, | 49 void OnVSyncParametersChangedForTesting(base::TimeTicks timebase, |
(...skipping 10 matching lines...) Expand all Loading... |
54 } | 60 } |
55 | 61 |
56 int pending_swap_buffers() { | 62 int pending_swap_buffers() { |
57 return pending_swap_buffers_; | 63 return pending_swap_buffers_; |
58 } | 64 } |
59 | 65 |
60 void OnSwapBuffersCompleteForTesting() { | 66 void OnSwapBuffersCompleteForTesting() { |
61 OnSwapBuffersComplete(NULL); | 67 OnSwapBuffersComplete(NULL); |
62 } | 68 } |
63 | 69 |
64 void SetAlternateRetroactiveBeginFramePeriod(base::TimeDelta period) { | 70 void EnableRetroactiveBeginFrameDeadline(bool enable, |
65 alternate_retroactive_begin_frame_period_ = period; | 71 bool override_retroactive_period, |
| 72 base::TimeDelta period_override) { |
| 73 retroactive_begin_frame_deadline_enabled_ = enable; |
| 74 override_retroactive_period_ = override_retroactive_period; |
| 75 retroactive_period_override_ = period_override; |
66 } | 76 } |
67 | 77 |
68 protected: | 78 protected: |
69 virtual void PostCheckForRetroactiveBeginFrame() OVERRIDE { | 79 virtual void PostCheckForRetroactiveBeginFrame() OVERRIDE { |
70 // For testing purposes, we check immediately rather than posting a task. | 80 // For testing purposes, we check immediately rather than posting a task. |
71 CheckForRetroactiveBeginFrame(); | 81 CheckForRetroactiveBeginFrame(); |
72 } | 82 } |
73 | 83 |
74 virtual base::TimeDelta AlternateRetroactiveBeginFramePeriod() OVERRIDE { | 84 virtual base::TimeTicks RetroactiveBeginFrameDeadline() OVERRIDE { |
75 return alternate_retroactive_begin_frame_period_; | 85 if (retroactive_begin_frame_deadline_enabled_) { |
| 86 if (override_retroactive_period_) { |
| 87 return skipped_begin_frame_args_.frame_time + |
| 88 retroactive_period_override_; |
| 89 } else { |
| 90 return OutputSurface::RetroactiveBeginFrameDeadline(); |
| 91 } |
| 92 } |
| 93 return base::TimeTicks(); |
76 } | 94 } |
77 | 95 |
78 base::TimeDelta alternate_retroactive_begin_frame_period_; | 96 bool retroactive_begin_frame_deadline_enabled_; |
| 97 bool override_retroactive_period_; |
| 98 base::TimeDelta retroactive_period_override_; |
79 }; | 99 }; |
80 | 100 |
81 class TestSoftwareOutputDevice : public SoftwareOutputDevice { | 101 class TestSoftwareOutputDevice : public SoftwareOutputDevice { |
82 public: | 102 public: |
83 TestSoftwareOutputDevice(); | 103 TestSoftwareOutputDevice(); |
84 virtual ~TestSoftwareOutputDevice(); | 104 virtual ~TestSoftwareOutputDevice(); |
85 | 105 |
86 // Overriden from cc:SoftwareOutputDevice | 106 // Overriden from cc:SoftwareOutputDevice |
87 virtual void DiscardBackbuffer() OVERRIDE; | 107 virtual void DiscardBackbuffer() OVERRIDE; |
88 virtual void EnsureBackbuffer() OVERRIDE; | 108 virtual void EnsureBackbuffer() OVERRIDE; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 bool throttle_frame_production = true; | 233 bool throttle_frame_production = true; |
214 const base::TimeDelta display_refresh_interval = | 234 const base::TimeDelta display_refresh_interval = |
215 BeginFrameArgs::DefaultInterval(); | 235 BeginFrameArgs::DefaultInterval(); |
216 | 236 |
217 output_surface.InitializeBeginFrameEmulation( | 237 output_surface.InitializeBeginFrameEmulation( |
218 task_runner.get(), | 238 task_runner.get(), |
219 throttle_frame_production, | 239 throttle_frame_production, |
220 display_refresh_interval); | 240 display_refresh_interval); |
221 | 241 |
222 output_surface.SetMaxFramesPending(2); | 242 output_surface.SetMaxFramesPending(2); |
223 output_surface.SetAlternateRetroactiveBeginFramePeriod( | 243 output_surface.EnableRetroactiveBeginFrameDeadline( |
224 base::TimeDelta::FromSeconds(-1)); | 244 false, false, base::TimeDelta()); |
225 | 245 |
226 // We should start off with 0 BeginFrames | 246 // We should start off with 0 BeginFrames |
227 EXPECT_EQ(client.begin_frame_count(), 0); | 247 EXPECT_EQ(client.begin_frame_count(), 0); |
228 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | 248 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); |
229 | 249 |
230 // We should not have a pending task until a BeginFrame has been requested. | 250 // We should not have a pending task until a BeginFrame has been requested. |
231 EXPECT_FALSE(task_runner->HasPendingTask()); | 251 EXPECT_FALSE(task_runner->HasPendingTask()); |
232 output_surface.SetNeedsBeginFrame(true); | 252 output_surface.SetNeedsBeginFrame(true); |
233 EXPECT_TRUE(task_runner->HasPendingTask()); | 253 EXPECT_TRUE(task_runner->HasPendingTask()); |
234 | 254 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) { | 307 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) { |
288 TestOutputSurface output_surface(TestContextProvider::Create()); | 308 TestOutputSurface output_surface(TestContextProvider::Create()); |
289 EXPECT_FALSE(output_surface.HasClient()); | 309 EXPECT_FALSE(output_surface.HasClient()); |
290 | 310 |
291 FakeOutputSurfaceClient client; | 311 FakeOutputSurfaceClient client; |
292 EXPECT_TRUE(output_surface.BindToClient(&client)); | 312 EXPECT_TRUE(output_surface.BindToClient(&client)); |
293 EXPECT_TRUE(output_surface.HasClient()); | 313 EXPECT_TRUE(output_surface.HasClient()); |
294 EXPECT_FALSE(client.deferred_initialize_called()); | 314 EXPECT_FALSE(client.deferred_initialize_called()); |
295 | 315 |
296 output_surface.SetMaxFramesPending(2); | 316 output_surface.SetMaxFramesPending(2); |
297 | 317 output_surface.EnableRetroactiveBeginFrameDeadline( |
298 // Enable retroactive BeginFrames. | 318 true, false, base::TimeDelta()); |
299 output_surface.SetAlternateRetroactiveBeginFramePeriod( | |
300 base::TimeDelta::FromSeconds(100000)); | |
301 | 319 |
302 // Optimistically injected BeginFrames should be throttled if | 320 // Optimistically injected BeginFrames should be throttled if |
303 // SetNeedsBeginFrame is false... | 321 // SetNeedsBeginFrame is false... |
304 output_surface.SetNeedsBeginFrame(false); | 322 output_surface.SetNeedsBeginFrame(false); |
305 output_surface.BeginFrameForTesting(); | 323 output_surface.BeginFrameForTesting(); |
306 EXPECT_EQ(client.begin_frame_count(), 0); | 324 EXPECT_EQ(client.begin_frame_count(), 0); |
307 // ...and retroactively triggered by a SetNeedsBeginFrame. | 325 // ...and retroactively triggered by a SetNeedsBeginFrame. |
308 output_surface.SetNeedsBeginFrame(true); | 326 output_surface.SetNeedsBeginFrame(true); |
309 EXPECT_EQ(client.begin_frame_count(), 1); | 327 EXPECT_EQ(client.begin_frame_count(), 1); |
310 | 328 |
(...skipping 30 matching lines...) Expand all Loading... |
341 TestContextProvider::Create(); | 359 TestContextProvider::Create(); |
342 | 360 |
343 TestOutputSurface output_surface(context_provider); | 361 TestOutputSurface output_surface(context_provider); |
344 EXPECT_FALSE(output_surface.HasClient()); | 362 EXPECT_FALSE(output_surface.HasClient()); |
345 | 363 |
346 FakeOutputSurfaceClient client; | 364 FakeOutputSurfaceClient client; |
347 EXPECT_TRUE(output_surface.BindToClient(&client)); | 365 EXPECT_TRUE(output_surface.BindToClient(&client)); |
348 EXPECT_TRUE(output_surface.HasClient()); | 366 EXPECT_TRUE(output_surface.HasClient()); |
349 EXPECT_FALSE(client.deferred_initialize_called()); | 367 EXPECT_FALSE(client.deferred_initialize_called()); |
350 | 368 |
351 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(1000); | 369 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(10); |
352 | 370 |
353 // Initialize BeginFrame emulation | 371 // Initialize BeginFrame emulation |
354 scoped_refptr<base::TestSimpleTaskRunner> task_runner = | 372 scoped_refptr<base::TestSimpleTaskRunner> task_runner = |
355 new base::TestSimpleTaskRunner; | 373 new base::TestSimpleTaskRunner; |
356 bool throttle_frame_production = true; | 374 bool throttle_frame_production = true; |
357 const base::TimeDelta display_refresh_interval = big_interval; | 375 const base::TimeDelta display_refresh_interval = big_interval; |
358 | 376 |
359 output_surface.InitializeBeginFrameEmulation( | 377 output_surface.InitializeBeginFrameEmulation( |
360 task_runner.get(), | 378 task_runner.get(), |
361 throttle_frame_production, | 379 throttle_frame_production, |
362 display_refresh_interval); | 380 display_refresh_interval); |
363 | 381 |
364 // We need to subtract an epsilon from Now() because some platforms have | 382 // We need to subtract an epsilon from Now() because some platforms have |
365 // a slow clock. | 383 // a slow clock. |
366 output_surface.OnVSyncParametersChangedForTesting( | 384 output_surface.OnVSyncParametersChangedForTesting( |
367 base::TimeTicks::Now() - base::TimeDelta::FromMilliseconds(1), | 385 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1), big_interval); |
368 display_refresh_interval); | |
369 | 386 |
370 output_surface.SetMaxFramesPending(2); | 387 output_surface.SetMaxFramesPending(2); |
371 output_surface.SetAlternateRetroactiveBeginFramePeriod( | 388 output_surface.EnableRetroactiveBeginFrameDeadline(true, true, big_interval); |
372 base::TimeDelta::FromSeconds(-1)); | |
373 | 389 |
374 // We should start off with 0 BeginFrames | 390 // We should start off with 0 BeginFrames |
375 EXPECT_EQ(client.begin_frame_count(), 0); | 391 EXPECT_EQ(client.begin_frame_count(), 0); |
376 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | 392 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); |
377 | 393 |
378 // The first SetNeedsBeginFrame(true) should start a retroactive BeginFrame. | 394 // The first SetNeedsBeginFrame(true) should start a retroactive BeginFrame. |
| 395 EXPECT_FALSE(task_runner->HasPendingTask()); |
379 output_surface.SetNeedsBeginFrame(true); | 396 output_surface.SetNeedsBeginFrame(true); |
380 EXPECT_TRUE(task_runner->HasPendingTask()); | 397 EXPECT_TRUE(task_runner->HasPendingTask()); |
381 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2); | 398 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2); |
382 EXPECT_EQ(client.begin_frame_count(), 1); | 399 EXPECT_EQ(client.begin_frame_count(), 1); |
383 | 400 |
384 output_surface.SetNeedsBeginFrame(false); | 401 output_surface.SetNeedsBeginFrame(false); |
385 EXPECT_TRUE(task_runner->HasPendingTask()); | 402 EXPECT_TRUE(task_runner->HasPendingTask()); |
386 EXPECT_EQ(client.begin_frame_count(), 1); | 403 EXPECT_EQ(client.begin_frame_count(), 1); |
387 | 404 |
388 // The second SetNeedBeginFrame(true) should not retroactively start a | 405 // The second SetNeedBeginFrame(true) should not retroactively start a |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); | 477 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); |
461 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); | 478 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); |
462 output_surface.DiscardBackbuffer(); | 479 output_surface.DiscardBackbuffer(); |
463 | 480 |
464 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); | 481 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); |
465 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); | 482 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); |
466 } | 483 } |
467 | 484 |
468 } // namespace | 485 } // namespace |
469 } // namespace cc | 486 } // namespace cc |
OLD | NEW |