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/output/managed_memory_policy.h" | 8 #include "cc/output/managed_memory_policy.h" |
9 #include "cc/output/output_surface_client.h" | 9 #include "cc/output/output_surface_client.h" |
10 #include "cc/output/software_output_device.h" | 10 #include "cc/output/software_output_device.h" |
11 #include "cc/test/fake_output_surface.h" | 11 #include "cc/test/fake_output_surface.h" |
12 #include "cc/test/fake_output_surface_client.h" | 12 #include "cc/test/fake_output_surface_client.h" |
13 #include "cc/test/scheduler_test_common.h" | 13 #include "cc/test/scheduler_test_common.h" |
14 #include "cc/test/test_context_provider.h" | 14 #include "cc/test/test_context_provider.h" |
15 #include "cc/test/test_web_graphics_context_3d.h" | 15 #include "cc/test/test_web_graphics_context_3d.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 #include "ui/gfx/frame_time.h" | 18 #include "ui/gfx/frame_time.h" |
19 | 19 |
20 namespace cc { | 20 namespace cc { |
21 namespace { | 21 namespace { |
22 | 22 |
23 class TestOutputSurface : public OutputSurface { | 23 class TestOutputSurface : public OutputSurface { |
24 public: | 24 public: |
25 explicit TestOutputSurface(scoped_refptr<ContextProvider> context_provider) | 25 explicit TestOutputSurface(scoped_refptr<ContextProvider> context_provider) |
26 : OutputSurface(context_provider), | 26 : OutputSurface(context_provider), |
27 retroactive_begin_impl_frame_deadline_enabled_(false), | 27 retroactive_begin_frame_deadline_enabled_(false), |
28 override_retroactive_period_(false) {} | 28 override_retroactive_period_(false) {} |
29 | 29 |
30 explicit TestOutputSurface(scoped_ptr<SoftwareOutputDevice> software_device) | 30 explicit TestOutputSurface(scoped_ptr<SoftwareOutputDevice> software_device) |
31 : OutputSurface(software_device.Pass()), | 31 : OutputSurface(software_device.Pass()), |
32 retroactive_begin_impl_frame_deadline_enabled_(false), | 32 retroactive_begin_frame_deadline_enabled_(false), |
33 override_retroactive_period_(false) {} | 33 override_retroactive_period_(false) {} |
34 | 34 |
35 TestOutputSurface(scoped_refptr<ContextProvider> context_provider, | 35 TestOutputSurface(scoped_refptr<ContextProvider> context_provider, |
36 scoped_ptr<SoftwareOutputDevice> software_device) | 36 scoped_ptr<SoftwareOutputDevice> software_device) |
37 : OutputSurface(context_provider, software_device.Pass()), | 37 : OutputSurface(context_provider, software_device.Pass()), |
38 retroactive_begin_impl_frame_deadline_enabled_(false), | 38 retroactive_begin_frame_deadline_enabled_(false), |
39 override_retroactive_period_(false) {} | 39 override_retroactive_period_(false) {} |
40 | 40 |
41 bool InitializeNewContext3d( | 41 bool InitializeNewContext3d( |
42 scoped_refptr<ContextProvider> new_context_provider) { | 42 scoped_refptr<ContextProvider> new_context_provider) { |
43 return InitializeAndSetContext3d(new_context_provider, | 43 return InitializeAndSetContext3d(new_context_provider, |
44 scoped_refptr<ContextProvider>()); | 44 scoped_refptr<ContextProvider>()); |
45 } | 45 } |
46 | 46 |
47 using OutputSurface::ReleaseGL; | 47 using OutputSurface::ReleaseGL; |
48 | 48 |
49 void CommitVSyncParametersForTesting(base::TimeTicks timebase, | 49 void CommitVSyncParametersForTesting(base::TimeTicks timebase, |
50 base::TimeDelta interval) { | 50 base::TimeDelta interval) { |
51 CommitVSyncParameters(timebase, interval); | 51 CommitVSyncParameters(timebase, interval); |
52 } | 52 } |
53 | 53 |
54 void BeginImplFrameForTesting() { | 54 void BeginFrameForTesting() { |
55 OutputSurface::BeginImplFrame(BeginFrameArgs::CreateExpiredForTesting()); | 55 OutputSurface::BeginFrame(BeginFrameArgs::CreateExpiredForTesting()); |
56 } | 56 } |
57 | 57 |
58 void DidSwapBuffersForTesting() { | 58 void DidSwapBuffersForTesting() { |
59 DidSwapBuffers(); | 59 DidSwapBuffers(); |
60 } | 60 } |
61 | 61 |
62 int pending_swap_buffers() { | 62 int pending_swap_buffers() { |
63 return pending_swap_buffers_; | 63 return pending_swap_buffers_; |
64 } | 64 } |
65 | 65 |
66 void OnSwapBuffersCompleteForTesting() { | 66 void OnSwapBuffersCompleteForTesting() { |
67 OnSwapBuffersComplete(); | 67 OnSwapBuffersComplete(); |
68 } | 68 } |
69 | 69 |
70 void EnableRetroactiveBeginImplFrameDeadline( | 70 void EnableRetroactiveBeginFrameDeadline(bool enable, |
71 bool enable, | 71 bool override_retroactive_period, |
72 bool override_retroactive_period, | 72 base::TimeDelta period_override) { |
73 base::TimeDelta period_override) { | 73 retroactive_begin_frame_deadline_enabled_ = enable; |
74 retroactive_begin_impl_frame_deadline_enabled_ = enable; | |
75 override_retroactive_period_ = override_retroactive_period; | 74 override_retroactive_period_ = override_retroactive_period; |
76 retroactive_period_override_ = period_override; | 75 retroactive_period_override_ = period_override; |
77 } | 76 } |
78 | 77 |
79 protected: | 78 protected: |
80 virtual void PostCheckForRetroactiveBeginImplFrame() OVERRIDE { | 79 virtual void PostCheckForRetroactiveBeginFrame() OVERRIDE { |
81 // For testing purposes, we check immediately rather than posting a task. | 80 // For testing purposes, we check immediately rather than posting a task. |
82 CheckForRetroactiveBeginImplFrame(); | 81 CheckForRetroactiveBeginFrame(); |
83 } | 82 } |
84 | 83 |
85 virtual base::TimeTicks RetroactiveBeginImplFrameDeadline() OVERRIDE { | 84 virtual base::TimeTicks RetroactiveBeginFrameDeadline() OVERRIDE { |
86 if (retroactive_begin_impl_frame_deadline_enabled_) { | 85 if (retroactive_begin_frame_deadline_enabled_) { |
87 if (override_retroactive_period_) { | 86 if (override_retroactive_period_) { |
88 return skipped_begin_impl_frame_args_.frame_time + | 87 return skipped_begin_frame_args_.frame_time + |
89 retroactive_period_override_; | 88 retroactive_period_override_; |
90 } else { | 89 } else { |
91 return OutputSurface::RetroactiveBeginImplFrameDeadline(); | 90 return OutputSurface::RetroactiveBeginFrameDeadline(); |
92 } | 91 } |
93 } | 92 } |
94 return base::TimeTicks(); | 93 return base::TimeTicks(); |
95 } | 94 } |
96 | 95 |
97 bool retroactive_begin_impl_frame_deadline_enabled_; | 96 bool retroactive_begin_frame_deadline_enabled_; |
98 bool override_retroactive_period_; | 97 bool override_retroactive_period_; |
99 base::TimeDelta retroactive_period_override_; | 98 base::TimeDelta retroactive_period_override_; |
100 }; | 99 }; |
101 | 100 |
102 class TestSoftwareOutputDevice : public SoftwareOutputDevice { | 101 class TestSoftwareOutputDevice : public SoftwareOutputDevice { |
103 public: | 102 public: |
104 TestSoftwareOutputDevice(); | 103 TestSoftwareOutputDevice(); |
105 virtual ~TestSoftwareOutputDevice(); | 104 virtual ~TestSoftwareOutputDevice(); |
106 | 105 |
107 // Overriden from cc:SoftwareOutputDevice | 106 // Overriden from cc:SoftwareOutputDevice |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 context_provider_->UnboundTestContext3d()->set_context_lost(true); | 213 context_provider_->UnboundTestContext3d()->set_context_lost(true); |
215 InitializeNewContextExpectFail(); | 214 InitializeNewContextExpectFail(); |
216 } | 215 } |
217 | 216 |
218 TEST_F(OutputSurfaceTestInitializeNewContext3d, ClientDeferredInitializeFails) { | 217 TEST_F(OutputSurfaceTestInitializeNewContext3d, ClientDeferredInitializeFails) { |
219 BindOutputSurface(); | 218 BindOutputSurface(); |
220 client_.set_deferred_initialize_result(false); | 219 client_.set_deferred_initialize_result(false); |
221 InitializeNewContextExpectFail(); | 220 InitializeNewContextExpectFail(); |
222 } | 221 } |
223 | 222 |
224 TEST(OutputSurfaceTest, BeginImplFrameEmulation) { | 223 TEST(OutputSurfaceTest, BeginFrameEmulation) { |
225 TestOutputSurface output_surface(TestContextProvider::Create()); | 224 TestOutputSurface output_surface(TestContextProvider::Create()); |
226 EXPECT_FALSE(output_surface.HasClient()); | 225 EXPECT_FALSE(output_surface.HasClient()); |
227 | 226 |
228 FakeOutputSurfaceClient client; | 227 FakeOutputSurfaceClient client; |
229 EXPECT_TRUE(output_surface.BindToClient(&client)); | 228 EXPECT_TRUE(output_surface.BindToClient(&client)); |
230 EXPECT_TRUE(output_surface.HasClient()); | 229 EXPECT_TRUE(output_surface.HasClient()); |
231 EXPECT_FALSE(client.deferred_initialize_called()); | 230 EXPECT_FALSE(client.deferred_initialize_called()); |
232 | 231 |
233 // Initialize BeginImplFrame emulation | 232 // Initialize BeginFrame emulation |
234 scoped_refptr<base::TestSimpleTaskRunner> task_runner = | 233 scoped_refptr<base::TestSimpleTaskRunner> task_runner = |
235 new base::TestSimpleTaskRunner; | 234 new base::TestSimpleTaskRunner; |
236 bool throttle_frame_production = true; | 235 bool throttle_frame_production = true; |
237 const base::TimeDelta display_refresh_interval = | 236 const base::TimeDelta display_refresh_interval = |
238 BeginFrameArgs::DefaultInterval(); | 237 BeginFrameArgs::DefaultInterval(); |
239 | 238 |
240 output_surface.InitializeBeginImplFrameEmulation( | 239 output_surface.InitializeBeginFrameEmulation( |
241 task_runner.get(), | 240 task_runner.get(), throttle_frame_production, display_refresh_interval); |
242 throttle_frame_production, | |
243 display_refresh_interval); | |
244 | 241 |
245 output_surface.SetMaxFramesPending(2); | 242 output_surface.SetMaxFramesPending(2); |
246 output_surface.EnableRetroactiveBeginImplFrameDeadline( | 243 output_surface.EnableRetroactiveBeginFrameDeadline( |
247 false, false, base::TimeDelta()); | 244 false, false, base::TimeDelta()); |
248 | 245 |
249 // We should start off with 0 BeginImplFrames | 246 // We should start off with 0 BeginFrames |
250 EXPECT_EQ(client.begin_impl_frame_count(), 0); | 247 EXPECT_EQ(client.begin_frame_count(), 0); |
251 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | 248 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); |
252 | 249 |
253 // We should not have a pending task until a BeginImplFrame has been | 250 // We should not have a pending task until a BeginFrame has been |
254 // requested. | 251 // requested. |
255 EXPECT_FALSE(task_runner->HasPendingTask()); | 252 EXPECT_FALSE(task_runner->HasPendingTask()); |
256 output_surface.SetNeedsBeginImplFrame(true); | 253 output_surface.SetNeedsBeginFrame(true); |
257 EXPECT_TRUE(task_runner->HasPendingTask()); | 254 EXPECT_TRUE(task_runner->HasPendingTask()); |
258 | 255 |
259 // BeginImplFrame should be called on the first tick. | 256 // BeginFrame should be called on the first tick. |
260 task_runner->RunPendingTasks(); | 257 task_runner->RunPendingTasks(); |
261 EXPECT_EQ(client.begin_impl_frame_count(), 1); | 258 EXPECT_EQ(client.begin_frame_count(), 1); |
262 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | 259 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); |
263 | 260 |
264 // BeginImplFrame should not be called when there is a pending BeginImplFrame. | 261 // BeginFrame should not be called when there is a pending BeginFrame. |
265 task_runner->RunPendingTasks(); | 262 task_runner->RunPendingTasks(); |
266 EXPECT_EQ(client.begin_impl_frame_count(), 1); | 263 EXPECT_EQ(client.begin_frame_count(), 1); |
267 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | 264 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); |
268 | 265 |
269 // SetNeedsBeginImplFrame should clear the pending BeginImplFrame after | 266 // SetNeedsBeginFrame should clear the pending BeginFrame after |
270 // a SwapBuffers. | 267 // a SwapBuffers. |
271 output_surface.DidSwapBuffersForTesting(); | 268 output_surface.DidSwapBuffersForTesting(); |
272 output_surface.SetNeedsBeginImplFrame(true); | 269 output_surface.SetNeedsBeginFrame(true); |
273 EXPECT_EQ(client.begin_impl_frame_count(), 1); | 270 EXPECT_EQ(client.begin_frame_count(), 1); |
274 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 271 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
275 task_runner->RunPendingTasks(); | 272 task_runner->RunPendingTasks(); |
276 EXPECT_EQ(client.begin_impl_frame_count(), 2); | 273 EXPECT_EQ(client.begin_frame_count(), 2); |
277 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 274 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
278 | 275 |
279 // BeginImplFrame should be throttled by pending swap buffers. | 276 // BeginFrame should be throttled by pending swap buffers. |
280 output_surface.DidSwapBuffersForTesting(); | 277 output_surface.DidSwapBuffersForTesting(); |
281 output_surface.SetNeedsBeginImplFrame(true); | 278 output_surface.SetNeedsBeginFrame(true); |
282 EXPECT_EQ(client.begin_impl_frame_count(), 2); | 279 EXPECT_EQ(client.begin_frame_count(), 2); |
283 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); | 280 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); |
284 task_runner->RunPendingTasks(); | 281 task_runner->RunPendingTasks(); |
285 EXPECT_EQ(client.begin_impl_frame_count(), 2); | 282 EXPECT_EQ(client.begin_frame_count(), 2); |
286 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); | 283 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); |
287 | 284 |
288 // SwapAck should decrement pending swap buffers and unblock BeginImplFrame | 285 // SwapAck should decrement pending swap buffers and unblock BeginFrame |
289 // again. | 286 // again. |
290 output_surface.OnSwapBuffersCompleteForTesting(); | 287 output_surface.OnSwapBuffersCompleteForTesting(); |
291 EXPECT_EQ(client.begin_impl_frame_count(), 2); | 288 EXPECT_EQ(client.begin_frame_count(), 2); |
292 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 289 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
293 task_runner->RunPendingTasks(); | 290 task_runner->RunPendingTasks(); |
294 EXPECT_EQ(client.begin_impl_frame_count(), 3); | 291 EXPECT_EQ(client.begin_frame_count(), 3); |
295 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 292 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
296 | 293 |
297 // Calling SetNeedsBeginImplFrame again indicates a swap did not occur but | 294 // Calling SetNeedsBeginFrame again indicates a swap did not occur but |
298 // the client still wants another BeginImplFrame. | 295 // the client still wants another BeginFrame. |
299 output_surface.SetNeedsBeginImplFrame(true); | 296 output_surface.SetNeedsBeginFrame(true); |
300 task_runner->RunPendingTasks(); | 297 task_runner->RunPendingTasks(); |
301 EXPECT_EQ(client.begin_impl_frame_count(), 4); | 298 EXPECT_EQ(client.begin_frame_count(), 4); |
302 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 299 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
303 | 300 |
304 // Disabling SetNeedsBeginImplFrame should prevent further BeginImplFrames. | 301 // Disabling SetNeedsBeginFrame should prevent further BeginFrames. |
305 output_surface.SetNeedsBeginImplFrame(false); | 302 output_surface.SetNeedsBeginFrame(false); |
306 task_runner->RunPendingTasks(); | 303 task_runner->RunPendingTasks(); |
307 EXPECT_FALSE(task_runner->HasPendingTask()); | 304 EXPECT_FALSE(task_runner->HasPendingTask()); |
308 EXPECT_EQ(client.begin_impl_frame_count(), 4); | 305 EXPECT_EQ(client.begin_frame_count(), 4); |
309 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 306 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
310 } | 307 } |
311 | 308 |
312 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginImplFrames) { | 309 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) { |
313 TestOutputSurface output_surface(TestContextProvider::Create()); | 310 TestOutputSurface output_surface(TestContextProvider::Create()); |
314 EXPECT_FALSE(output_surface.HasClient()); | 311 EXPECT_FALSE(output_surface.HasClient()); |
315 | 312 |
316 FakeOutputSurfaceClient client; | 313 FakeOutputSurfaceClient client; |
317 EXPECT_TRUE(output_surface.BindToClient(&client)); | 314 EXPECT_TRUE(output_surface.BindToClient(&client)); |
318 EXPECT_TRUE(output_surface.HasClient()); | 315 EXPECT_TRUE(output_surface.HasClient()); |
319 EXPECT_FALSE(client.deferred_initialize_called()); | 316 EXPECT_FALSE(client.deferred_initialize_called()); |
320 | 317 |
321 output_surface.SetMaxFramesPending(2); | 318 output_surface.SetMaxFramesPending(2); |
322 output_surface.EnableRetroactiveBeginImplFrameDeadline( | 319 output_surface.EnableRetroactiveBeginFrameDeadline( |
323 true, false, base::TimeDelta()); | 320 true, false, base::TimeDelta()); |
324 | 321 |
325 // Optimistically injected BeginImplFrames should be throttled if | 322 // Optimistically injected BeginFrames should be throttled if |
326 // SetNeedsBeginImplFrame is false... | 323 // SetNeedsBeginFrame is false... |
327 output_surface.SetNeedsBeginImplFrame(false); | 324 output_surface.SetNeedsBeginFrame(false); |
328 output_surface.BeginImplFrameForTesting(); | 325 output_surface.BeginFrameForTesting(); |
329 EXPECT_EQ(client.begin_impl_frame_count(), 0); | 326 EXPECT_EQ(client.begin_frame_count(), 0); |
330 // ...and retroactively triggered by a SetNeedsBeginImplFrame. | 327 // ...and retroactively triggered by a SetNeedsBeginFrame. |
331 output_surface.SetNeedsBeginImplFrame(true); | 328 output_surface.SetNeedsBeginFrame(true); |
332 EXPECT_EQ(client.begin_impl_frame_count(), 1); | 329 EXPECT_EQ(client.begin_frame_count(), 1); |
333 | 330 |
334 // Optimistically injected BeginImplFrames should be throttled by pending | 331 // Optimistically injected BeginFrames should be throttled by pending |
335 // BeginImplFrames... | 332 // BeginFrames... |
336 output_surface.BeginImplFrameForTesting(); | 333 output_surface.BeginFrameForTesting(); |
337 EXPECT_EQ(client.begin_impl_frame_count(), 1); | 334 EXPECT_EQ(client.begin_frame_count(), 1); |
338 // ...and retroactively triggered by a SetNeedsBeginImplFrame. | 335 // ...and retroactively triggered by a SetNeedsBeginFrame. |
339 output_surface.SetNeedsBeginImplFrame(true); | 336 output_surface.SetNeedsBeginFrame(true); |
340 EXPECT_EQ(client.begin_impl_frame_count(), 2); | 337 EXPECT_EQ(client.begin_frame_count(), 2); |
341 // ...or retroactively triggered by a Swap. | 338 // ...or retroactively triggered by a Swap. |
342 output_surface.BeginImplFrameForTesting(); | 339 output_surface.BeginFrameForTesting(); |
343 EXPECT_EQ(client.begin_impl_frame_count(), 2); | 340 EXPECT_EQ(client.begin_frame_count(), 2); |
344 output_surface.DidSwapBuffersForTesting(); | 341 output_surface.DidSwapBuffersForTesting(); |
345 output_surface.SetNeedsBeginImplFrame(true); | 342 output_surface.SetNeedsBeginFrame(true); |
346 EXPECT_EQ(client.begin_impl_frame_count(), 3); | 343 EXPECT_EQ(client.begin_frame_count(), 3); |
347 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 344 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
348 | 345 |
349 // Optimistically injected BeginImplFrames should be by throttled by pending | 346 // Optimistically injected BeginFrames should be by throttled by pending |
350 // swap buffers... | 347 // swap buffers... |
351 output_surface.DidSwapBuffersForTesting(); | 348 output_surface.DidSwapBuffersForTesting(); |
352 output_surface.SetNeedsBeginImplFrame(true); | 349 output_surface.SetNeedsBeginFrame(true); |
353 EXPECT_EQ(client.begin_impl_frame_count(), 3); | 350 EXPECT_EQ(client.begin_frame_count(), 3); |
354 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); | 351 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); |
355 output_surface.BeginImplFrameForTesting(); | 352 output_surface.BeginFrameForTesting(); |
356 EXPECT_EQ(client.begin_impl_frame_count(), 3); | 353 EXPECT_EQ(client.begin_frame_count(), 3); |
357 // ...and retroactively triggered by OnSwapBuffersComplete | 354 // ...and retroactively triggered by OnSwapBuffersComplete |
358 output_surface.OnSwapBuffersCompleteForTesting(); | 355 output_surface.OnSwapBuffersCompleteForTesting(); |
359 EXPECT_EQ(client.begin_impl_frame_count(), 4); | 356 EXPECT_EQ(client.begin_frame_count(), 4); |
360 } | 357 } |
361 | 358 |
362 TEST(OutputSurfaceTest, | 359 TEST(OutputSurfaceTest, RetroactiveBeginFrameDoesNotDoubleTickWhenEmulating) { |
363 RetroactiveBeginImplFrameDoesNotDoubleTickWhenEmulating) { | |
364 scoped_refptr<TestContextProvider> context_provider = | 360 scoped_refptr<TestContextProvider> context_provider = |
365 TestContextProvider::Create(); | 361 TestContextProvider::Create(); |
366 | 362 |
367 TestOutputSurface output_surface(context_provider); | 363 TestOutputSurface output_surface(context_provider); |
368 EXPECT_FALSE(output_surface.HasClient()); | 364 EXPECT_FALSE(output_surface.HasClient()); |
369 | 365 |
370 FakeOutputSurfaceClient client; | 366 FakeOutputSurfaceClient client; |
371 EXPECT_TRUE(output_surface.BindToClient(&client)); | 367 EXPECT_TRUE(output_surface.BindToClient(&client)); |
372 EXPECT_TRUE(output_surface.HasClient()); | 368 EXPECT_TRUE(output_surface.HasClient()); |
373 EXPECT_FALSE(client.deferred_initialize_called()); | 369 EXPECT_FALSE(client.deferred_initialize_called()); |
374 | 370 |
375 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(10); | 371 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(10); |
376 | 372 |
377 // Initialize BeginImplFrame emulation | 373 // Initialize BeginFrame emulation |
378 scoped_refptr<base::TestSimpleTaskRunner> task_runner = | 374 scoped_refptr<base::TestSimpleTaskRunner> task_runner = |
379 new base::TestSimpleTaskRunner; | 375 new base::TestSimpleTaskRunner; |
380 bool throttle_frame_production = true; | 376 bool throttle_frame_production = true; |
381 const base::TimeDelta display_refresh_interval = big_interval; | 377 const base::TimeDelta display_refresh_interval = big_interval; |
382 | 378 |
383 output_surface.InitializeBeginImplFrameEmulation( | 379 output_surface.InitializeBeginFrameEmulation( |
384 task_runner.get(), | 380 task_runner.get(), throttle_frame_production, display_refresh_interval); |
385 throttle_frame_production, | |
386 display_refresh_interval); | |
387 | 381 |
388 // 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 |
389 // a slow clock. | 383 // a slow clock. |
390 output_surface.CommitVSyncParametersForTesting( | 384 output_surface.CommitVSyncParametersForTesting( |
391 gfx::FrameTime::Now() - base::TimeDelta::FromSeconds(1), big_interval); | 385 gfx::FrameTime::Now() - base::TimeDelta::FromSeconds(1), big_interval); |
392 | 386 |
393 output_surface.SetMaxFramesPending(2); | 387 output_surface.SetMaxFramesPending(2); |
394 output_surface.EnableRetroactiveBeginImplFrameDeadline( | 388 output_surface.EnableRetroactiveBeginFrameDeadline(true, true, big_interval); |
395 true, true, big_interval); | |
396 | 389 |
397 // We should start off with 0 BeginImplFrames | 390 // We should start off with 0 BeginFrames |
398 EXPECT_EQ(client.begin_impl_frame_count(), 0); | 391 EXPECT_EQ(client.begin_frame_count(), 0); |
399 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | 392 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); |
400 | 393 |
401 // The first SetNeedsBeginImplFrame(true) should start a retroactive | 394 // The first SetNeedsBeginFrame(true) should start a retroactive |
402 // BeginImplFrame. | 395 // BeginFrame. |
403 EXPECT_FALSE(task_runner->HasPendingTask()); | 396 EXPECT_FALSE(task_runner->HasPendingTask()); |
404 output_surface.SetNeedsBeginImplFrame(true); | 397 output_surface.SetNeedsBeginFrame(true); |
405 EXPECT_TRUE(task_runner->HasPendingTask()); | 398 EXPECT_TRUE(task_runner->HasPendingTask()); |
406 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2); | 399 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2); |
407 EXPECT_EQ(client.begin_impl_frame_count(), 1); | 400 EXPECT_EQ(client.begin_frame_count(), 1); |
408 | 401 |
409 output_surface.SetNeedsBeginImplFrame(false); | 402 output_surface.SetNeedsBeginFrame(false); |
410 EXPECT_TRUE(task_runner->HasPendingTask()); | 403 EXPECT_TRUE(task_runner->HasPendingTask()); |
411 EXPECT_EQ(client.begin_impl_frame_count(), 1); | 404 EXPECT_EQ(client.begin_frame_count(), 1); |
412 | 405 |
413 // The second SetNeedBeginImplFrame(true) should not retroactively start a | 406 // The second SetNeedBeginFrame(true) should not retroactively start a |
414 // BeginImplFrame if the timestamp would be the same as the previous | 407 // BeginFrame if the timestamp would be the same as the previous |
415 // BeginImplFrame. | 408 // BeginFrame. |
416 output_surface.SetNeedsBeginImplFrame(true); | 409 output_surface.SetNeedsBeginFrame(true); |
417 EXPECT_TRUE(task_runner->HasPendingTask()); | 410 EXPECT_TRUE(task_runner->HasPendingTask()); |
418 EXPECT_EQ(client.begin_impl_frame_count(), 1); | 411 EXPECT_EQ(client.begin_frame_count(), 1); |
419 } | 412 } |
420 | 413 |
421 TEST(OutputSurfaceTest, MemoryAllocation) { | 414 TEST(OutputSurfaceTest, MemoryAllocation) { |
422 scoped_refptr<TestContextProvider> context_provider = | 415 scoped_refptr<TestContextProvider> context_provider = |
423 TestContextProvider::Create(); | 416 TestContextProvider::Create(); |
424 | 417 |
425 TestOutputSurface output_surface(context_provider); | 418 TestOutputSurface output_surface(context_provider); |
426 | 419 |
427 FakeOutputSurfaceClient client; | 420 FakeOutputSurfaceClient client; |
428 EXPECT_TRUE(output_surface.BindToClient(&client)); | 421 EXPECT_TRUE(output_surface.BindToClient(&client)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); | 458 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); |
466 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); | 459 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); |
467 output_surface.DiscardBackbuffer(); | 460 output_surface.DiscardBackbuffer(); |
468 | 461 |
469 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); | 462 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); |
470 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); | 463 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); |
471 } | 464 } |
472 | 465 |
473 } // namespace | 466 } // namespace |
474 } // namespace cc | 467 } // namespace cc |
OLD | NEW |