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 be called after a swap if we aren't swap throttled. |
265 task_runner->RunPendingTasks(); | |
266 EXPECT_EQ(client.begin_impl_frame_count(), 1); | |
267 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | |
268 | |
269 // SetNeedsBeginImplFrame should clear the pending BeginImplFrame after | |
270 // a SwapBuffers. | |
271 output_surface.DidSwapBuffersForTesting(); | 262 output_surface.DidSwapBuffersForTesting(); |
272 output_surface.SetNeedsBeginImplFrame(true); | 263 EXPECT_EQ(client.begin_frame_count(), 1); |
273 EXPECT_EQ(client.begin_impl_frame_count(), 1); | |
274 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 264 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
275 task_runner->RunPendingTasks(); | 265 task_runner->RunPendingTasks(); |
276 EXPECT_EQ(client.begin_impl_frame_count(), 2); | 266 EXPECT_EQ(client.begin_frame_count(), 2); |
277 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 267 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
278 | 268 |
279 // BeginImplFrame should be throttled by pending swap buffers. | 269 // BeginFrame should be throttled by pending swap buffers. |
280 output_surface.DidSwapBuffersForTesting(); | 270 output_surface.DidSwapBuffersForTesting(); |
281 output_surface.SetNeedsBeginImplFrame(true); | 271 EXPECT_EQ(client.begin_frame_count(), 2); |
282 EXPECT_EQ(client.begin_impl_frame_count(), 2); | |
283 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); | 272 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); |
284 task_runner->RunPendingTasks(); | 273 task_runner->RunPendingTasks(); |
285 EXPECT_EQ(client.begin_impl_frame_count(), 2); | 274 EXPECT_EQ(client.begin_frame_count(), 2); |
286 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); | 275 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); |
287 | 276 |
288 // SwapAck should decrement pending swap buffers and unblock BeginImplFrame | 277 // SwapAck should decrement pending swap buffers and unblock BeginFrame |
289 // again. | 278 // again. |
290 output_surface.OnSwapBuffersCompleteForTesting(); | 279 output_surface.OnSwapBuffersCompleteForTesting(); |
291 EXPECT_EQ(client.begin_impl_frame_count(), 2); | 280 EXPECT_EQ(client.begin_frame_count(), 2); |
292 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 281 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
293 task_runner->RunPendingTasks(); | 282 task_runner->RunPendingTasks(); |
294 EXPECT_EQ(client.begin_impl_frame_count(), 3); | 283 EXPECT_EQ(client.begin_frame_count(), 3); |
295 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 284 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
296 | 285 |
297 // Calling SetNeedsBeginImplFrame again indicates a swap did not occur but | 286 // Calling SetNeedsBeginFrame again indicates a swap did not occur but |
298 // the client still wants another BeginImplFrame. | 287 // the client still wants another BeginFrame. |
299 output_surface.SetNeedsBeginImplFrame(true); | |
300 task_runner->RunPendingTasks(); | 288 task_runner->RunPendingTasks(); |
301 EXPECT_EQ(client.begin_impl_frame_count(), 4); | 289 EXPECT_EQ(client.begin_frame_count(), 4); |
302 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 290 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
303 | 291 |
304 // Disabling SetNeedsBeginImplFrame should prevent further BeginImplFrames. | 292 // Disabling SetNeedsBeginFrame should prevent further BeginFrames. |
305 output_surface.SetNeedsBeginImplFrame(false); | 293 output_surface.SetNeedsBeginFrame(false); |
306 task_runner->RunPendingTasks(); | 294 task_runner->RunPendingTasks(); |
307 EXPECT_FALSE(task_runner->HasPendingTask()); | 295 EXPECT_FALSE(task_runner->HasPendingTask()); |
308 EXPECT_EQ(client.begin_impl_frame_count(), 4); | 296 EXPECT_EQ(client.begin_frame_count(), 4); |
309 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 297 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
310 } | 298 } |
311 | 299 |
312 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginImplFrames) { | 300 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) { |
313 TestOutputSurface output_surface(TestContextProvider::Create()); | 301 TestOutputSurface output_surface(TestContextProvider::Create()); |
314 EXPECT_FALSE(output_surface.HasClient()); | 302 EXPECT_FALSE(output_surface.HasClient()); |
315 | 303 |
316 FakeOutputSurfaceClient client; | 304 FakeOutputSurfaceClient client; |
317 EXPECT_TRUE(output_surface.BindToClient(&client)); | 305 EXPECT_TRUE(output_surface.BindToClient(&client)); |
318 EXPECT_TRUE(output_surface.HasClient()); | 306 EXPECT_TRUE(output_surface.HasClient()); |
319 EXPECT_FALSE(client.deferred_initialize_called()); | 307 EXPECT_FALSE(client.deferred_initialize_called()); |
320 | 308 |
321 output_surface.SetMaxFramesPending(2); | 309 output_surface.SetMaxFramesPending(2); |
322 output_surface.EnableRetroactiveBeginImplFrameDeadline( | 310 output_surface.EnableRetroactiveBeginFrameDeadline( |
323 true, false, base::TimeDelta()); | 311 true, false, base::TimeDelta()); |
324 | 312 |
325 // Optimistically injected BeginImplFrames should be throttled if | 313 // Optimistically injected BeginFrames should be throttled if |
326 // SetNeedsBeginImplFrame is false... | 314 // SetNeedsBeginFrame is false... |
327 output_surface.SetNeedsBeginImplFrame(false); | 315 output_surface.SetNeedsBeginFrame(false); |
328 output_surface.BeginImplFrameForTesting(); | 316 output_surface.BeginFrameForTesting(); |
329 EXPECT_EQ(client.begin_impl_frame_count(), 0); | 317 EXPECT_EQ(client.begin_frame_count(), 0); |
330 // ...and retroactively triggered by a SetNeedsBeginImplFrame. | 318 // ...and retroactively triggered by a SetNeedsBeginFrame. |
331 output_surface.SetNeedsBeginImplFrame(true); | 319 output_surface.SetNeedsBeginFrame(true); |
332 EXPECT_EQ(client.begin_impl_frame_count(), 1); | 320 EXPECT_EQ(client.begin_frame_count(), 1); |
333 | 321 |
334 // Optimistically injected BeginImplFrames should be throttled by pending | 322 // Optimistically injected BeginFrames should not be throttled by pending |
335 // BeginImplFrames... | 323 // BeginFrames |
336 output_surface.BeginImplFrameForTesting(); | 324 output_surface.BeginFrameForTesting(); |
337 EXPECT_EQ(client.begin_impl_frame_count(), 1); | 325 EXPECT_EQ(client.begin_frame_count(), 2); |
338 // ...and retroactively triggered by a SetNeedsBeginImplFrame. | 326 // Optimistically injected BeginFrames should not be throttled when |
339 output_surface.SetNeedsBeginImplFrame(true); | 327 // we are not swap limitted. |
340 EXPECT_EQ(client.begin_impl_frame_count(), 2); | |
341 // ...or retroactively triggered by a Swap. | |
342 output_surface.BeginImplFrameForTesting(); | |
343 EXPECT_EQ(client.begin_impl_frame_count(), 2); | |
344 output_surface.DidSwapBuffersForTesting(); | 328 output_surface.DidSwapBuffersForTesting(); |
345 output_surface.SetNeedsBeginImplFrame(true); | 329 output_surface.BeginFrameForTesting(); |
346 EXPECT_EQ(client.begin_impl_frame_count(), 3); | 330 EXPECT_EQ(client.begin_frame_count(), 3); |
347 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 331 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
348 | 332 |
349 // Optimistically injected BeginImplFrames should be by throttled by pending | 333 // Optimistically injected BeginFrames should be by throttled when |
350 // swap buffers... | 334 // we are swap limitted. |
351 output_surface.DidSwapBuffersForTesting(); | 335 output_surface.DidSwapBuffersForTesting(); |
352 output_surface.SetNeedsBeginImplFrame(true); | 336 EXPECT_EQ(client.begin_frame_count(), 3); |
353 EXPECT_EQ(client.begin_impl_frame_count(), 3); | |
354 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); | 337 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); |
355 output_surface.BeginImplFrameForTesting(); | 338 output_surface.BeginFrameForTesting(); |
356 EXPECT_EQ(client.begin_impl_frame_count(), 3); | 339 EXPECT_EQ(client.begin_frame_count(), 3); |
357 // ...and retroactively triggered by OnSwapBuffersComplete | 340 // ...and retroactively triggered by OnSwapBuffersComplete |
358 output_surface.OnSwapBuffersCompleteForTesting(); | 341 output_surface.OnSwapBuffersCompleteForTesting(); |
359 EXPECT_EQ(client.begin_impl_frame_count(), 4); | 342 EXPECT_EQ(client.begin_frame_count(), 4); |
360 } | 343 } |
361 | 344 |
362 TEST(OutputSurfaceTest, | 345 TEST(OutputSurfaceTest, RetroactiveBeginFrameDoesNotDoubleTickWhenEmulating) { |
363 RetroactiveBeginImplFrameDoesNotDoubleTickWhenEmulating) { | |
364 scoped_refptr<TestContextProvider> context_provider = | 346 scoped_refptr<TestContextProvider> context_provider = |
365 TestContextProvider::Create(); | 347 TestContextProvider::Create(); |
366 | 348 |
367 TestOutputSurface output_surface(context_provider); | 349 TestOutputSurface output_surface(context_provider); |
368 EXPECT_FALSE(output_surface.HasClient()); | 350 EXPECT_FALSE(output_surface.HasClient()); |
369 | 351 |
370 FakeOutputSurfaceClient client; | 352 FakeOutputSurfaceClient client; |
371 EXPECT_TRUE(output_surface.BindToClient(&client)); | 353 EXPECT_TRUE(output_surface.BindToClient(&client)); |
372 EXPECT_TRUE(output_surface.HasClient()); | 354 EXPECT_TRUE(output_surface.HasClient()); |
373 EXPECT_FALSE(client.deferred_initialize_called()); | 355 EXPECT_FALSE(client.deferred_initialize_called()); |
374 | 356 |
375 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(10); | 357 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(10); |
376 | 358 |
377 // Initialize BeginImplFrame emulation | 359 // Initialize BeginFrame emulation |
378 scoped_refptr<base::TestSimpleTaskRunner> task_runner = | 360 scoped_refptr<base::TestSimpleTaskRunner> task_runner = |
379 new base::TestSimpleTaskRunner; | 361 new base::TestSimpleTaskRunner; |
380 bool throttle_frame_production = true; | 362 bool throttle_frame_production = true; |
381 const base::TimeDelta display_refresh_interval = big_interval; | 363 const base::TimeDelta display_refresh_interval = big_interval; |
382 | 364 |
383 output_surface.InitializeBeginImplFrameEmulation( | 365 output_surface.InitializeBeginFrameEmulation( |
384 task_runner.get(), | 366 task_runner.get(), throttle_frame_production, display_refresh_interval); |
385 throttle_frame_production, | |
386 display_refresh_interval); | |
387 | 367 |
388 // We need to subtract an epsilon from Now() because some platforms have | 368 // We need to subtract an epsilon from Now() because some platforms have |
389 // a slow clock. | 369 // a slow clock. |
390 output_surface.CommitVSyncParametersForTesting( | 370 output_surface.CommitVSyncParametersForTesting( |
391 gfx::FrameTime::Now() - base::TimeDelta::FromSeconds(1), big_interval); | 371 gfx::FrameTime::Now() - base::TimeDelta::FromSeconds(1), big_interval); |
392 | 372 |
393 output_surface.SetMaxFramesPending(2); | 373 output_surface.SetMaxFramesPending(2); |
394 output_surface.EnableRetroactiveBeginImplFrameDeadline( | 374 output_surface.EnableRetroactiveBeginFrameDeadline(true, true, big_interval); |
395 true, true, big_interval); | |
396 | 375 |
397 // We should start off with 0 BeginImplFrames | 376 // We should start off with 0 BeginFrames |
398 EXPECT_EQ(client.begin_impl_frame_count(), 0); | 377 EXPECT_EQ(client.begin_frame_count(), 0); |
399 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | 378 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); |
400 | 379 |
401 // The first SetNeedsBeginImplFrame(true) should start a retroactive | 380 // The first SetNeedsBeginFrame(true) should start a retroactive |
402 // BeginImplFrame. | 381 // BeginFrame. |
403 EXPECT_FALSE(task_runner->HasPendingTask()); | 382 EXPECT_FALSE(task_runner->HasPendingTask()); |
404 output_surface.SetNeedsBeginImplFrame(true); | 383 output_surface.SetNeedsBeginFrame(true); |
405 EXPECT_TRUE(task_runner->HasPendingTask()); | 384 EXPECT_TRUE(task_runner->HasPendingTask()); |
406 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2); | 385 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2); |
407 EXPECT_EQ(client.begin_impl_frame_count(), 1); | 386 EXPECT_EQ(client.begin_frame_count(), 1); |
408 | 387 |
409 output_surface.SetNeedsBeginImplFrame(false); | 388 output_surface.SetNeedsBeginFrame(false); |
410 EXPECT_TRUE(task_runner->HasPendingTask()); | 389 EXPECT_TRUE(task_runner->HasPendingTask()); |
411 EXPECT_EQ(client.begin_impl_frame_count(), 1); | 390 EXPECT_EQ(client.begin_frame_count(), 1); |
412 | 391 |
413 // The second SetNeedBeginImplFrame(true) should not retroactively start a | 392 // The second SetNeedBeginFrame(true) should not retroactively start a |
414 // BeginImplFrame if the timestamp would be the same as the previous | 393 // BeginFrame if the timestamp would be the same as the previous |
415 // BeginImplFrame. | 394 // BeginFrame. |
416 output_surface.SetNeedsBeginImplFrame(true); | 395 output_surface.SetNeedsBeginFrame(true); |
417 EXPECT_TRUE(task_runner->HasPendingTask()); | 396 EXPECT_TRUE(task_runner->HasPendingTask()); |
418 EXPECT_EQ(client.begin_impl_frame_count(), 1); | 397 EXPECT_EQ(client.begin_frame_count(), 1); |
419 } | 398 } |
420 | 399 |
421 TEST(OutputSurfaceTest, MemoryAllocation) { | 400 TEST(OutputSurfaceTest, MemoryAllocation) { |
422 scoped_refptr<TestContextProvider> context_provider = | 401 scoped_refptr<TestContextProvider> context_provider = |
423 TestContextProvider::Create(); | 402 TestContextProvider::Create(); |
424 | 403 |
425 TestOutputSurface output_surface(context_provider); | 404 TestOutputSurface output_surface(context_provider); |
426 | 405 |
427 FakeOutputSurfaceClient client; | 406 FakeOutputSurfaceClient client; |
428 EXPECT_TRUE(output_surface.BindToClient(&client)); | 407 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()); | 444 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); |
466 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); | 445 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); |
467 output_surface.DiscardBackbuffer(); | 446 output_surface.DiscardBackbuffer(); |
468 | 447 |
469 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); | 448 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); |
470 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); | 449 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); |
471 } | 450 } |
472 | 451 |
473 } // namespace | 452 } // namespace |
474 } // namespace cc | 453 } // namespace cc |
OLD | NEW |