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 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) { | 101 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) { |
82 TestOutputSurface output_surface(TestContextProvider::Create()); | 102 TestOutputSurface output_surface(TestContextProvider::Create()); |
83 EXPECT_FALSE(output_surface.HasClient()); | 103 EXPECT_FALSE(output_surface.HasClient()); |
84 | 104 |
85 FakeOutputSurfaceClient client; | 105 FakeOutputSurfaceClient client; |
86 EXPECT_TRUE(output_surface.BindToClient(&client)); | 106 EXPECT_TRUE(output_surface.BindToClient(&client)); |
87 EXPECT_TRUE(output_surface.HasClient()); | 107 EXPECT_TRUE(output_surface.HasClient()); |
88 EXPECT_FALSE(client.deferred_initialize_called()); | 108 EXPECT_FALSE(client.deferred_initialize_called()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 bool throttle_frame_production = true; | 201 bool throttle_frame_production = true; |
182 const base::TimeDelta display_refresh_interval = | 202 const base::TimeDelta display_refresh_interval = |
183 BeginFrameArgs::DefaultInterval(); | 203 BeginFrameArgs::DefaultInterval(); |
184 | 204 |
185 output_surface.InitializeBeginFrameEmulation( | 205 output_surface.InitializeBeginFrameEmulation( |
186 task_runner.get(), | 206 task_runner.get(), |
187 throttle_frame_production, | 207 throttle_frame_production, |
188 display_refresh_interval); | 208 display_refresh_interval); |
189 | 209 |
190 output_surface.SetMaxFramesPending(2); | 210 output_surface.SetMaxFramesPending(2); |
191 output_surface.SetAlternateRetroactiveBeginFramePeriod( | 211 output_surface.EnableRetroactiveBeginFrameDeadline( |
192 base::TimeDelta::FromSeconds(-1)); | 212 false, false, base::TimeDelta()); |
193 | 213 |
194 // We should start off with 0 BeginFrames | 214 // We should start off with 0 BeginFrames |
195 EXPECT_EQ(client.begin_frame_count(), 0); | 215 EXPECT_EQ(client.begin_frame_count(), 0); |
196 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | 216 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); |
197 | 217 |
198 // We should not have a pending task until a BeginFrame has been requested. | 218 // We should not have a pending task until a BeginFrame has been requested. |
199 EXPECT_FALSE(task_runner->HasPendingTask()); | 219 EXPECT_FALSE(task_runner->HasPendingTask()); |
200 output_surface.SetNeedsBeginFrame(true); | 220 output_surface.SetNeedsBeginFrame(true); |
201 EXPECT_TRUE(task_runner->HasPendingTask()); | 221 EXPECT_TRUE(task_runner->HasPendingTask()); |
202 | 222 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) { | 274 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) { |
255 TestOutputSurface output_surface(TestContextProvider::Create()); | 275 TestOutputSurface output_surface(TestContextProvider::Create()); |
256 EXPECT_FALSE(output_surface.HasClient()); | 276 EXPECT_FALSE(output_surface.HasClient()); |
257 | 277 |
258 FakeOutputSurfaceClient client; | 278 FakeOutputSurfaceClient client; |
259 EXPECT_TRUE(output_surface.BindToClient(&client)); | 279 EXPECT_TRUE(output_surface.BindToClient(&client)); |
260 EXPECT_TRUE(output_surface.HasClient()); | 280 EXPECT_TRUE(output_surface.HasClient()); |
261 EXPECT_FALSE(client.deferred_initialize_called()); | 281 EXPECT_FALSE(client.deferred_initialize_called()); |
262 | 282 |
263 output_surface.SetMaxFramesPending(2); | 283 output_surface.SetMaxFramesPending(2); |
264 | 284 output_surface.EnableRetroactiveBeginFrameDeadline( |
265 // Enable retroactive BeginFrames. | 285 true, false, base::TimeDelta()); |
266 output_surface.SetAlternateRetroactiveBeginFramePeriod( | |
267 base::TimeDelta::FromSeconds(100000)); | |
268 | 286 |
269 // Optimistically injected BeginFrames should be throttled if | 287 // Optimistically injected BeginFrames should be throttled if |
270 // SetNeedsBeginFrame is false... | 288 // SetNeedsBeginFrame is false... |
271 output_surface.SetNeedsBeginFrame(false); | 289 output_surface.SetNeedsBeginFrame(false); |
272 output_surface.BeginFrameForTesting(); | 290 output_surface.BeginFrameForTesting(); |
273 EXPECT_EQ(client.begin_frame_count(), 0); | 291 EXPECT_EQ(client.begin_frame_count(), 0); |
274 // ...and retroactively triggered by a SetNeedsBeginFrame. | 292 // ...and retroactively triggered by a SetNeedsBeginFrame. |
275 output_surface.SetNeedsBeginFrame(true); | 293 output_surface.SetNeedsBeginFrame(true); |
276 EXPECT_EQ(client.begin_frame_count(), 1); | 294 EXPECT_EQ(client.begin_frame_count(), 1); |
277 | 295 |
(...skipping 30 matching lines...) Expand all Loading... |
308 TestContextProvider::Create(); | 326 TestContextProvider::Create(); |
309 | 327 |
310 TestOutputSurface output_surface(context_provider); | 328 TestOutputSurface output_surface(context_provider); |
311 EXPECT_FALSE(output_surface.HasClient()); | 329 EXPECT_FALSE(output_surface.HasClient()); |
312 | 330 |
313 FakeOutputSurfaceClient client; | 331 FakeOutputSurfaceClient client; |
314 EXPECT_TRUE(output_surface.BindToClient(&client)); | 332 EXPECT_TRUE(output_surface.BindToClient(&client)); |
315 EXPECT_TRUE(output_surface.HasClient()); | 333 EXPECT_TRUE(output_surface.HasClient()); |
316 EXPECT_FALSE(client.deferred_initialize_called()); | 334 EXPECT_FALSE(client.deferred_initialize_called()); |
317 | 335 |
318 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(1000); | 336 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(10); |
319 | 337 |
320 // Initialize BeginFrame emulation | 338 // Initialize BeginFrame emulation |
321 scoped_refptr<base::TestSimpleTaskRunner> task_runner = | 339 scoped_refptr<base::TestSimpleTaskRunner> task_runner = |
322 new base::TestSimpleTaskRunner; | 340 new base::TestSimpleTaskRunner; |
323 bool throttle_frame_production = true; | 341 bool throttle_frame_production = true; |
324 const base::TimeDelta display_refresh_interval = big_interval; | 342 const base::TimeDelta display_refresh_interval = big_interval; |
325 | 343 |
326 output_surface.InitializeBeginFrameEmulation( | 344 output_surface.InitializeBeginFrameEmulation( |
327 task_runner.get(), | 345 task_runner.get(), |
328 throttle_frame_production, | 346 throttle_frame_production, |
329 display_refresh_interval); | 347 display_refresh_interval); |
330 | 348 |
331 // We need to subtract an epsilon from Now() because some platforms have | 349 // We need to subtract an epsilon from Now() because some platforms have |
332 // a slow clock. | 350 // a slow clock. |
333 output_surface.OnVSyncParametersChangedForTesting( | 351 output_surface.OnVSyncParametersChangedForTesting( |
334 base::TimeTicks::Now() - base::TimeDelta::FromMilliseconds(1), | 352 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1), big_interval); |
335 display_refresh_interval); | |
336 | 353 |
337 output_surface.SetMaxFramesPending(2); | 354 output_surface.SetMaxFramesPending(2); |
338 output_surface.SetAlternateRetroactiveBeginFramePeriod( | 355 output_surface.EnableRetroactiveBeginFrameDeadline(true, true, big_interval); |
339 base::TimeDelta::FromSeconds(-1)); | |
340 | 356 |
341 // We should start off with 0 BeginFrames | 357 // We should start off with 0 BeginFrames |
342 EXPECT_EQ(client.begin_frame_count(), 0); | 358 EXPECT_EQ(client.begin_frame_count(), 0); |
343 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | 359 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); |
344 | 360 |
345 // The first SetNeedsBeginFrame(true) should start a retroactive BeginFrame. | 361 // The first SetNeedsBeginFrame(true) should start a retroactive BeginFrame. |
| 362 EXPECT_FALSE(task_runner->HasPendingTask()); |
346 output_surface.SetNeedsBeginFrame(true); | 363 output_surface.SetNeedsBeginFrame(true); |
347 EXPECT_TRUE(task_runner->HasPendingTask()); | 364 EXPECT_TRUE(task_runner->HasPendingTask()); |
348 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2); | 365 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2); |
349 EXPECT_EQ(client.begin_frame_count(), 1); | 366 EXPECT_EQ(client.begin_frame_count(), 1); |
350 | 367 |
351 output_surface.SetNeedsBeginFrame(false); | 368 output_surface.SetNeedsBeginFrame(false); |
352 EXPECT_TRUE(task_runner->HasPendingTask()); | 369 EXPECT_TRUE(task_runner->HasPendingTask()); |
353 EXPECT_EQ(client.begin_frame_count(), 1); | 370 EXPECT_EQ(client.begin_frame_count(), 1); |
354 | 371 |
355 // The second SetNeedBeginFrame(true) should not retroactively start a | 372 // The second SetNeedBeginFrame(true) should not retroactively start a |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 423 |
407 // 0 bytes limit should be ignored. | 424 // 0 bytes limit should be ignored. |
408 policy.bytes_limit_when_visible = 0; | 425 policy.bytes_limit_when_visible = 0; |
409 context_provider->SetMemoryAllocation(policy, | 426 context_provider->SetMemoryAllocation(policy, |
410 discard_backbuffer_when_not_visible); | 427 discard_backbuffer_when_not_visible); |
411 EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible); | 428 EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible); |
412 } | 429 } |
413 | 430 |
414 } // namespace | 431 } // namespace |
415 } // namespace cc | 432 } // namespace cc |
OLD | NEW |