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" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } | 52 } |
53 | 53 |
54 void BeginFrameForTesting() { | 54 void BeginFrameForTesting() { |
55 OutputSurface::BeginFrame(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() { | |
63 return pending_swap_buffers_; | |
64 } | |
65 | |
66 void OnSwapBuffersCompleteForTesting() { | 62 void OnSwapBuffersCompleteForTesting() { |
67 OnSwapBuffersComplete(); | 63 OnSwapBuffersComplete(); |
68 } | 64 } |
69 | 65 |
70 void EnableRetroactiveBeginFrameDeadline(bool enable, | 66 void EnableRetroactiveBeginFrameDeadline(bool enable, |
71 bool override_retroactive_period, | 67 bool override_retroactive_period, |
72 base::TimeDelta period_override) { | 68 base::TimeDelta period_override) { |
73 retroactive_begin_frame_deadline_enabled_ = enable; | 69 retroactive_begin_frame_deadline_enabled_ = enable; |
74 override_retroactive_period_ = override_retroactive_period; | 70 override_retroactive_period_ = override_retroactive_period; |
75 retroactive_period_override_ = period_override; | 71 retroactive_period_override_ = period_override; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 EXPECT_FALSE(output_surface.HasClient()); | 221 EXPECT_FALSE(output_surface.HasClient()); |
226 | 222 |
227 FakeOutputSurfaceClient client; | 223 FakeOutputSurfaceClient client; |
228 EXPECT_TRUE(output_surface.BindToClient(&client)); | 224 EXPECT_TRUE(output_surface.BindToClient(&client)); |
229 EXPECT_TRUE(output_surface.HasClient()); | 225 EXPECT_TRUE(output_surface.HasClient()); |
230 EXPECT_FALSE(client.deferred_initialize_called()); | 226 EXPECT_FALSE(client.deferred_initialize_called()); |
231 | 227 |
232 // Initialize BeginFrame emulation | 228 // Initialize BeginFrame emulation |
233 scoped_refptr<base::TestSimpleTaskRunner> task_runner = | 229 scoped_refptr<base::TestSimpleTaskRunner> task_runner = |
234 new base::TestSimpleTaskRunner; | 230 new base::TestSimpleTaskRunner; |
235 bool throttle_frame_production = true; | |
236 const base::TimeDelta display_refresh_interval = | 231 const base::TimeDelta display_refresh_interval = |
237 BeginFrameArgs::DefaultInterval(); | 232 BeginFrameArgs::DefaultInterval(); |
238 | 233 |
239 output_surface.InitializeBeginFrameEmulation( | 234 output_surface.InitializeBeginFrameEmulation(task_runner.get(), |
240 task_runner.get(), throttle_frame_production, display_refresh_interval); | 235 display_refresh_interval); |
241 | 236 |
242 output_surface.SetMaxFramesPending(2); | |
243 output_surface.EnableRetroactiveBeginFrameDeadline( | 237 output_surface.EnableRetroactiveBeginFrameDeadline( |
244 false, false, base::TimeDelta()); | 238 false, false, base::TimeDelta()); |
245 | 239 |
246 // We should start off with 0 BeginFrames | 240 // We should start off with 0 BeginFrames |
247 EXPECT_EQ(client.begin_frame_count(), 0); | 241 EXPECT_EQ(client.begin_frame_count(), 0); |
248 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | |
249 | 242 |
250 // We should not have a pending task until a BeginFrame has been | 243 // We should not have a pending task until a BeginFrame has been |
251 // requested. | 244 // requested. |
252 EXPECT_FALSE(task_runner->HasPendingTask()); | 245 EXPECT_FALSE(task_runner->HasPendingTask()); |
253 output_surface.SetNeedsBeginFrame(true); | 246 output_surface.SetNeedsBeginFrame(true); |
254 EXPECT_TRUE(task_runner->HasPendingTask()); | 247 EXPECT_TRUE(task_runner->HasPendingTask()); |
255 | 248 |
256 // BeginFrame should be called on the first tick. | 249 // BeginFrame should be called on the first tick. |
257 task_runner->RunPendingTasks(); | 250 task_runner->RunPendingTasks(); |
258 EXPECT_EQ(client.begin_frame_count(), 1); | 251 EXPECT_EQ(client.begin_frame_count(), 1); |
259 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | |
260 | 252 |
261 // BeginFrame should not be called when there is a pending BeginFrame. | 253 // BeginFrame should not be called when there is a pending BeginFrame. |
262 task_runner->RunPendingTasks(); | 254 task_runner->RunPendingTasks(); |
263 EXPECT_EQ(client.begin_frame_count(), 1); | 255 EXPECT_EQ(client.begin_frame_count(), 1); |
264 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | |
265 | |
266 // SetNeedsBeginFrame should clear the pending BeginFrame after | 256 // SetNeedsBeginFrame should clear the pending BeginFrame after |
267 // a SwapBuffers. | 257 // a SwapBuffers. |
268 output_surface.DidSwapBuffersForTesting(); | 258 output_surface.DidSwapBuffersForTesting(); |
269 output_surface.SetNeedsBeginFrame(true); | 259 output_surface.SetNeedsBeginFrame(true); |
270 EXPECT_EQ(client.begin_frame_count(), 1); | 260 EXPECT_EQ(client.begin_frame_count(), 1); |
271 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | |
272 task_runner->RunPendingTasks(); | 261 task_runner->RunPendingTasks(); |
273 EXPECT_EQ(client.begin_frame_count(), 2); | 262 EXPECT_EQ(client.begin_frame_count(), 2); |
274 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | |
275 | |
276 // BeginFrame should be throttled by pending swap buffers. | |
277 output_surface.DidSwapBuffersForTesting(); | |
278 output_surface.SetNeedsBeginFrame(true); | |
279 EXPECT_EQ(client.begin_frame_count(), 2); | |
280 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); | |
281 task_runner->RunPendingTasks(); | |
282 EXPECT_EQ(client.begin_frame_count(), 2); | |
283 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); | |
284 | |
285 // SwapAck should decrement pending swap buffers and unblock BeginFrame | |
286 // again. | |
287 output_surface.OnSwapBuffersCompleteForTesting(); | |
288 EXPECT_EQ(client.begin_frame_count(), 2); | |
289 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | |
290 task_runner->RunPendingTasks(); | |
291 EXPECT_EQ(client.begin_frame_count(), 3); | |
292 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | |
293 | 263 |
294 // Calling SetNeedsBeginFrame again indicates a swap did not occur but | 264 // Calling SetNeedsBeginFrame again indicates a swap did not occur but |
295 // the client still wants another BeginFrame. | 265 // the client still wants another BeginFrame. |
296 output_surface.SetNeedsBeginFrame(true); | 266 output_surface.SetNeedsBeginFrame(true); |
297 task_runner->RunPendingTasks(); | 267 task_runner->RunPendingTasks(); |
298 EXPECT_EQ(client.begin_frame_count(), 4); | 268 EXPECT_EQ(client.begin_frame_count(), 3); |
299 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | |
300 | 269 |
301 // Disabling SetNeedsBeginFrame should prevent further BeginFrames. | 270 // Disabling SetNeedsBeginFrame should prevent further BeginFrames. |
302 output_surface.SetNeedsBeginFrame(false); | 271 output_surface.SetNeedsBeginFrame(false); |
303 task_runner->RunPendingTasks(); | 272 task_runner->RunPendingTasks(); |
304 EXPECT_FALSE(task_runner->HasPendingTask()); | 273 EXPECT_FALSE(task_runner->HasPendingTask()); |
305 EXPECT_EQ(client.begin_frame_count(), 4); | 274 EXPECT_EQ(client.begin_frame_count(), 3); |
306 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | |
307 } | 275 } |
308 | 276 |
309 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) { | 277 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) { |
310 TestOutputSurface output_surface(TestContextProvider::Create()); | 278 TestOutputSurface output_surface(TestContextProvider::Create()); |
311 EXPECT_FALSE(output_surface.HasClient()); | 279 EXPECT_FALSE(output_surface.HasClient()); |
312 | 280 |
313 FakeOutputSurfaceClient client; | 281 FakeOutputSurfaceClient client; |
314 EXPECT_TRUE(output_surface.BindToClient(&client)); | 282 EXPECT_TRUE(output_surface.BindToClient(&client)); |
315 EXPECT_TRUE(output_surface.HasClient()); | 283 EXPECT_TRUE(output_surface.HasClient()); |
316 EXPECT_FALSE(client.deferred_initialize_called()); | 284 EXPECT_FALSE(client.deferred_initialize_called()); |
317 | 285 |
318 output_surface.SetMaxFramesPending(2); | |
319 output_surface.EnableRetroactiveBeginFrameDeadline( | 286 output_surface.EnableRetroactiveBeginFrameDeadline( |
320 true, false, base::TimeDelta()); | 287 true, false, base::TimeDelta()); |
321 | 288 |
322 // Optimistically injected BeginFrames should be throttled if | 289 // Optimistically injected BeginFrames should be throttled if |
323 // SetNeedsBeginFrame is false... | 290 // SetNeedsBeginFrame is false... |
324 output_surface.SetNeedsBeginFrame(false); | 291 output_surface.SetNeedsBeginFrame(false); |
325 output_surface.BeginFrameForTesting(); | 292 output_surface.BeginFrameForTesting(); |
326 EXPECT_EQ(client.begin_frame_count(), 0); | 293 EXPECT_EQ(client.begin_frame_count(), 0); |
327 // ...and retroactively triggered by a SetNeedsBeginFrame. | 294 // ...and retroactively triggered by a SetNeedsBeginFrame. |
328 output_surface.SetNeedsBeginFrame(true); | 295 output_surface.SetNeedsBeginFrame(true); |
329 EXPECT_EQ(client.begin_frame_count(), 1); | 296 EXPECT_EQ(client.begin_frame_count(), 1); |
330 | 297 |
331 // Optimistically injected BeginFrames should be throttled by pending | 298 // Optimistically injected BeginFrames should be throttled by pending |
332 // BeginFrames... | 299 // BeginFrames... |
333 output_surface.BeginFrameForTesting(); | 300 output_surface.BeginFrameForTesting(); |
334 EXPECT_EQ(client.begin_frame_count(), 1); | 301 EXPECT_EQ(client.begin_frame_count(), 1); |
335 // ...and retroactively triggered by a SetNeedsBeginFrame. | 302 // ...and retroactively triggered by a SetNeedsBeginFrame. |
336 output_surface.SetNeedsBeginFrame(true); | 303 output_surface.SetNeedsBeginFrame(true); |
337 EXPECT_EQ(client.begin_frame_count(), 2); | 304 EXPECT_EQ(client.begin_frame_count(), 2); |
338 // ...or retroactively triggered by a Swap. | 305 // ...or retroactively triggered by a Swap. |
339 output_surface.BeginFrameForTesting(); | 306 output_surface.BeginFrameForTesting(); |
340 EXPECT_EQ(client.begin_frame_count(), 2); | 307 EXPECT_EQ(client.begin_frame_count(), 2); |
341 output_surface.DidSwapBuffersForTesting(); | 308 output_surface.DidSwapBuffersForTesting(); |
342 output_surface.SetNeedsBeginFrame(true); | 309 output_surface.SetNeedsBeginFrame(true); |
343 EXPECT_EQ(client.begin_frame_count(), 3); | 310 EXPECT_EQ(client.begin_frame_count(), 3); |
344 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | |
345 | |
346 // Optimistically injected BeginFrames should be by throttled by pending | |
347 // swap buffers... | |
348 output_surface.DidSwapBuffersForTesting(); | |
349 output_surface.SetNeedsBeginFrame(true); | |
350 EXPECT_EQ(client.begin_frame_count(), 3); | |
351 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); | |
352 output_surface.BeginFrameForTesting(); | |
353 EXPECT_EQ(client.begin_frame_count(), 3); | |
354 // ...and retroactively triggered by OnSwapBuffersComplete | |
355 output_surface.OnSwapBuffersCompleteForTesting(); | |
356 EXPECT_EQ(client.begin_frame_count(), 4); | |
357 } | 311 } |
358 | 312 |
359 TEST(OutputSurfaceTest, RetroactiveBeginFrameDoesNotDoubleTickWhenEmulating) { | 313 TEST(OutputSurfaceTest, RetroactiveBeginFrameDoesNotDoubleTickWhenEmulating) { |
360 scoped_refptr<TestContextProvider> context_provider = | 314 scoped_refptr<TestContextProvider> context_provider = |
361 TestContextProvider::Create(); | 315 TestContextProvider::Create(); |
362 | 316 |
363 TestOutputSurface output_surface(context_provider); | 317 TestOutputSurface output_surface(context_provider); |
364 EXPECT_FALSE(output_surface.HasClient()); | 318 EXPECT_FALSE(output_surface.HasClient()); |
365 | 319 |
366 FakeOutputSurfaceClient client; | 320 FakeOutputSurfaceClient client; |
367 EXPECT_TRUE(output_surface.BindToClient(&client)); | 321 EXPECT_TRUE(output_surface.BindToClient(&client)); |
368 EXPECT_TRUE(output_surface.HasClient()); | 322 EXPECT_TRUE(output_surface.HasClient()); |
369 EXPECT_FALSE(client.deferred_initialize_called()); | 323 EXPECT_FALSE(client.deferred_initialize_called()); |
370 | 324 |
371 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(10); | 325 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(10); |
372 | 326 |
373 // Initialize BeginFrame emulation | 327 // Initialize BeginFrame emulation |
374 scoped_refptr<base::TestSimpleTaskRunner> task_runner = | 328 scoped_refptr<base::TestSimpleTaskRunner> task_runner = |
375 new base::TestSimpleTaskRunner; | 329 new base::TestSimpleTaskRunner; |
376 bool throttle_frame_production = true; | |
377 const base::TimeDelta display_refresh_interval = big_interval; | 330 const base::TimeDelta display_refresh_interval = big_interval; |
378 | 331 |
379 output_surface.InitializeBeginFrameEmulation( | 332 output_surface.InitializeBeginFrameEmulation(task_runner.get(), |
380 task_runner.get(), throttle_frame_production, display_refresh_interval); | 333 display_refresh_interval); |
381 | 334 |
382 // We need to subtract an epsilon from Now() because some platforms have | 335 // We need to subtract an epsilon from Now() because some platforms have |
383 // a slow clock. | 336 // a slow clock. |
384 output_surface.CommitVSyncParametersForTesting( | 337 output_surface.CommitVSyncParametersForTesting( |
385 gfx::FrameTime::Now() - base::TimeDelta::FromSeconds(1), big_interval); | 338 gfx::FrameTime::Now() - base::TimeDelta::FromSeconds(1), big_interval); |
386 | 339 |
387 output_surface.SetMaxFramesPending(2); | |
388 output_surface.EnableRetroactiveBeginFrameDeadline(true, true, big_interval); | 340 output_surface.EnableRetroactiveBeginFrameDeadline(true, true, big_interval); |
389 | 341 |
390 // We should start off with 0 BeginFrames | 342 // We should start off with 0 BeginFrames |
391 EXPECT_EQ(client.begin_frame_count(), 0); | 343 EXPECT_EQ(client.begin_frame_count(), 0); |
392 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | |
393 | 344 |
394 // The first SetNeedsBeginFrame(true) should start a retroactive | 345 // The first SetNeedsBeginFrame(true) should start a retroactive |
395 // BeginFrame. | 346 // BeginFrame. |
396 EXPECT_FALSE(task_runner->HasPendingTask()); | 347 EXPECT_FALSE(task_runner->HasPendingTask()); |
397 output_surface.SetNeedsBeginFrame(true); | 348 output_surface.SetNeedsBeginFrame(true); |
398 EXPECT_TRUE(task_runner->HasPendingTask()); | 349 EXPECT_TRUE(task_runner->HasPendingTask()); |
399 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2); | 350 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2); |
400 EXPECT_EQ(client.begin_frame_count(), 1); | 351 EXPECT_EQ(client.begin_frame_count(), 1); |
401 | 352 |
402 output_surface.SetNeedsBeginFrame(false); | 353 output_surface.SetNeedsBeginFrame(false); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); | 409 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); |
459 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); | 410 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); |
460 output_surface.DiscardBackbuffer(); | 411 output_surface.DiscardBackbuffer(); |
461 | 412 |
462 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); | 413 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); |
463 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); | 414 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); |
464 } | 415 } |
465 | 416 |
466 } // namespace | 417 } // namespace |
467 } // namespace cc | 418 } // namespace cc |
OLD | NEW |