Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: cc/output/output_surface_unittest.cc

Issue 199523002: cc: Throttle swaps in Scheduler instead of OutputSurface (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: WIP: pulling FRC out of OS Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
52 } 52 }
53 53
54 void BeginImplFrameForTesting() { 54 void BeginImplFrameForTesting() {
55 OutputSurface::BeginImplFrame(BeginFrameArgs::CreateExpiredForTesting()); 55 OutputSurface::BeginImplFrame(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 EnableRetroactiveBeginImplFrameDeadline( 66 void EnableRetroactiveBeginImplFrameDeadline(
71 bool enable, 67 bool enable,
72 bool override_retroactive_period, 68 bool override_retroactive_period,
73 base::TimeDelta period_override) { 69 base::TimeDelta period_override) {
74 retroactive_begin_impl_frame_deadline_enabled_ = enable; 70 retroactive_begin_impl_frame_deadline_enabled_ = enable;
75 override_retroactive_period_ = override_retroactive_period; 71 override_retroactive_period_ = override_retroactive_period;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 EXPECT_FALSE(output_surface.HasClient()); 222 EXPECT_FALSE(output_surface.HasClient());
227 223
228 FakeOutputSurfaceClient client; 224 FakeOutputSurfaceClient client;
229 EXPECT_TRUE(output_surface.BindToClient(&client)); 225 EXPECT_TRUE(output_surface.BindToClient(&client));
230 EXPECT_TRUE(output_surface.HasClient()); 226 EXPECT_TRUE(output_surface.HasClient());
231 EXPECT_FALSE(client.deferred_initialize_called()); 227 EXPECT_FALSE(client.deferred_initialize_called());
232 228
233 // Initialize BeginImplFrame emulation 229 // Initialize BeginImplFrame emulation
234 scoped_refptr<base::TestSimpleTaskRunner> task_runner = 230 scoped_refptr<base::TestSimpleTaskRunner> task_runner =
235 new base::TestSimpleTaskRunner; 231 new base::TestSimpleTaskRunner;
236 bool throttle_frame_production = true;
237 const base::TimeDelta display_refresh_interval = 232 const base::TimeDelta display_refresh_interval =
238 BeginFrameArgs::DefaultInterval(); 233 BeginFrameArgs::DefaultInterval();
239 234
240 output_surface.InitializeBeginImplFrameEmulation( 235 output_surface.InitializeBeginImplFrameEmulation(
241 task_runner.get(), 236 task_runner.get(),
242 throttle_frame_production,
243 display_refresh_interval); 237 display_refresh_interval);
244 238
245 output_surface.SetMaxFramesPending(2);
246 output_surface.EnableRetroactiveBeginImplFrameDeadline( 239 output_surface.EnableRetroactiveBeginImplFrameDeadline(
247 false, false, base::TimeDelta()); 240 false, false, base::TimeDelta());
248 241
249 // We should start off with 0 BeginImplFrames 242 // We should start off with 0 BeginImplFrames
250 EXPECT_EQ(client.begin_impl_frame_count(), 0); 243 EXPECT_EQ(client.begin_impl_frame_count(), 0);
251 EXPECT_EQ(output_surface.pending_swap_buffers(), 0);
252 244
253 // We should not have a pending task until a BeginImplFrame has been 245 // We should not have a pending task until a BeginImplFrame has been
254 // requested. 246 // requested.
255 EXPECT_FALSE(task_runner->HasPendingTask()); 247 EXPECT_FALSE(task_runner->HasPendingTask());
256 output_surface.SetNeedsBeginImplFrame(true); 248 output_surface.SetNeedsBeginImplFrame(true);
257 EXPECT_TRUE(task_runner->HasPendingTask()); 249 EXPECT_TRUE(task_runner->HasPendingTask());
258 250
259 // BeginImplFrame should be called on the first tick. 251 // BeginImplFrame should be called on the first tick.
260 task_runner->RunPendingTasks(); 252 task_runner->RunPendingTasks();
261 EXPECT_EQ(client.begin_impl_frame_count(), 1); 253 EXPECT_EQ(client.begin_impl_frame_count(), 1);
262 EXPECT_EQ(output_surface.pending_swap_buffers(), 0);
263 254
264 // BeginImplFrame should not be called when there is a pending BeginImplFrame. 255 // BeginImplFrame should not be called when there is a pending BeginImplFrame.
265 task_runner->RunPendingTasks(); 256 task_runner->RunPendingTasks();
266 EXPECT_EQ(client.begin_impl_frame_count(), 1); 257 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 258 // SetNeedsBeginImplFrame should clear the pending BeginImplFrame after
270 // a SwapBuffers. 259 // a SwapBuffers.
271 output_surface.DidSwapBuffersForTesting(); 260 output_surface.DidSwapBuffersForTesting();
272 output_surface.SetNeedsBeginImplFrame(true); 261 output_surface.SetNeedsBeginImplFrame(true);
273 EXPECT_EQ(client.begin_impl_frame_count(), 1); 262 EXPECT_EQ(client.begin_impl_frame_count(), 1);
274 EXPECT_EQ(output_surface.pending_swap_buffers(), 1);
275 task_runner->RunPendingTasks(); 263 task_runner->RunPendingTasks();
276 EXPECT_EQ(client.begin_impl_frame_count(), 2); 264 EXPECT_EQ(client.begin_impl_frame_count(), 2);
277 EXPECT_EQ(output_surface.pending_swap_buffers(), 1);
278
279 // BeginImplFrame should be throttled by pending swap buffers.
280 output_surface.DidSwapBuffersForTesting();
281 output_surface.SetNeedsBeginImplFrame(true);
282 EXPECT_EQ(client.begin_impl_frame_count(), 2);
283 EXPECT_EQ(output_surface.pending_swap_buffers(), 2);
284 task_runner->RunPendingTasks();
285 EXPECT_EQ(client.begin_impl_frame_count(), 2);
286 EXPECT_EQ(output_surface.pending_swap_buffers(), 2);
287
288 // SwapAck should decrement pending swap buffers and unblock BeginImplFrame
289 // again.
290 output_surface.OnSwapBuffersCompleteForTesting();
291 EXPECT_EQ(client.begin_impl_frame_count(), 2);
292 EXPECT_EQ(output_surface.pending_swap_buffers(), 1);
293 task_runner->RunPendingTasks();
294 EXPECT_EQ(client.begin_impl_frame_count(), 3);
295 EXPECT_EQ(output_surface.pending_swap_buffers(), 1);
296 265
297 // Calling SetNeedsBeginImplFrame again indicates a swap did not occur but 266 // Calling SetNeedsBeginImplFrame again indicates a swap did not occur but
298 // the client still wants another BeginImplFrame. 267 // the client still wants another BeginImplFrame.
299 output_surface.SetNeedsBeginImplFrame(true); 268 output_surface.SetNeedsBeginImplFrame(true);
300 task_runner->RunPendingTasks(); 269 task_runner->RunPendingTasks();
301 EXPECT_EQ(client.begin_impl_frame_count(), 4); 270 EXPECT_EQ(client.begin_impl_frame_count(), 3);
302 EXPECT_EQ(output_surface.pending_swap_buffers(), 1);
303 271
304 // Disabling SetNeedsBeginImplFrame should prevent further BeginImplFrames. 272 // Disabling SetNeedsBeginImplFrame should prevent further BeginImplFrames.
305 output_surface.SetNeedsBeginImplFrame(false); 273 output_surface.SetNeedsBeginImplFrame(false);
306 task_runner->RunPendingTasks(); 274 task_runner->RunPendingTasks();
307 EXPECT_FALSE(task_runner->HasPendingTask()); 275 EXPECT_FALSE(task_runner->HasPendingTask());
308 EXPECT_EQ(client.begin_impl_frame_count(), 4); 276 EXPECT_EQ(client.begin_impl_frame_count(), 3);
309 EXPECT_EQ(output_surface.pending_swap_buffers(), 1);
310 } 277 }
311 278
312 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginImplFrames) { 279 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginImplFrames) {
313 TestOutputSurface output_surface(TestContextProvider::Create()); 280 TestOutputSurface output_surface(TestContextProvider::Create());
314 EXPECT_FALSE(output_surface.HasClient()); 281 EXPECT_FALSE(output_surface.HasClient());
315 282
316 FakeOutputSurfaceClient client; 283 FakeOutputSurfaceClient client;
317 EXPECT_TRUE(output_surface.BindToClient(&client)); 284 EXPECT_TRUE(output_surface.BindToClient(&client));
318 EXPECT_TRUE(output_surface.HasClient()); 285 EXPECT_TRUE(output_surface.HasClient());
319 EXPECT_FALSE(client.deferred_initialize_called()); 286 EXPECT_FALSE(client.deferred_initialize_called());
320 287
321 output_surface.SetMaxFramesPending(2);
322 output_surface.EnableRetroactiveBeginImplFrameDeadline( 288 output_surface.EnableRetroactiveBeginImplFrameDeadline(
323 true, false, base::TimeDelta()); 289 true, false, base::TimeDelta());
324 290
325 // Optimistically injected BeginImplFrames should be throttled if 291 // Optimistically injected BeginImplFrames should be throttled if
326 // SetNeedsBeginImplFrame is false... 292 // SetNeedsBeginImplFrame is false...
327 output_surface.SetNeedsBeginImplFrame(false); 293 output_surface.SetNeedsBeginImplFrame(false);
328 output_surface.BeginImplFrameForTesting(); 294 output_surface.BeginImplFrameForTesting();
329 EXPECT_EQ(client.begin_impl_frame_count(), 0); 295 EXPECT_EQ(client.begin_impl_frame_count(), 0);
330 // ...and retroactively triggered by a SetNeedsBeginImplFrame. 296 // ...and retroactively triggered by a SetNeedsBeginImplFrame.
331 output_surface.SetNeedsBeginImplFrame(true); 297 output_surface.SetNeedsBeginImplFrame(true);
332 EXPECT_EQ(client.begin_impl_frame_count(), 1); 298 EXPECT_EQ(client.begin_impl_frame_count(), 1);
333 299
334 // Optimistically injected BeginImplFrames should be throttled by pending 300 // Optimistically injected BeginImplFrames should be throttled by pending
335 // BeginImplFrames... 301 // BeginImplFrames...
336 output_surface.BeginImplFrameForTesting(); 302 output_surface.BeginImplFrameForTesting();
337 EXPECT_EQ(client.begin_impl_frame_count(), 1); 303 EXPECT_EQ(client.begin_impl_frame_count(), 1);
338 // ...and retroactively triggered by a SetNeedsBeginImplFrame. 304 // ...and retroactively triggered by a SetNeedsBeginImplFrame.
339 output_surface.SetNeedsBeginImplFrame(true); 305 output_surface.SetNeedsBeginImplFrame(true);
340 EXPECT_EQ(client.begin_impl_frame_count(), 2); 306 EXPECT_EQ(client.begin_impl_frame_count(), 2);
341 // ...or retroactively triggered by a Swap. 307 // ...or retroactively triggered by a Swap.
342 output_surface.BeginImplFrameForTesting(); 308 output_surface.BeginImplFrameForTesting();
343 EXPECT_EQ(client.begin_impl_frame_count(), 2); 309 EXPECT_EQ(client.begin_impl_frame_count(), 2);
344 output_surface.DidSwapBuffersForTesting(); 310 output_surface.DidSwapBuffersForTesting();
345 output_surface.SetNeedsBeginImplFrame(true); 311 output_surface.SetNeedsBeginImplFrame(true);
346 EXPECT_EQ(client.begin_impl_frame_count(), 3); 312 EXPECT_EQ(client.begin_impl_frame_count(), 3);
347 EXPECT_EQ(output_surface.pending_swap_buffers(), 1);
348
349 // Optimistically injected BeginImplFrames should be by throttled by pending
350 // swap buffers...
351 output_surface.DidSwapBuffersForTesting();
352 output_surface.SetNeedsBeginImplFrame(true);
353 EXPECT_EQ(client.begin_impl_frame_count(), 3);
354 EXPECT_EQ(output_surface.pending_swap_buffers(), 2);
355 output_surface.BeginImplFrameForTesting();
356 EXPECT_EQ(client.begin_impl_frame_count(), 3);
357 // ...and retroactively triggered by OnSwapBuffersComplete
358 output_surface.OnSwapBuffersCompleteForTesting();
359 EXPECT_EQ(client.begin_impl_frame_count(), 4);
360 } 313 }
361 314
362 TEST(OutputSurfaceTest, 315 TEST(OutputSurfaceTest,
363 RetroactiveBeginImplFrameDoesNotDoubleTickWhenEmulating) { 316 RetroactiveBeginImplFrameDoesNotDoubleTickWhenEmulating) {
364 scoped_refptr<TestContextProvider> context_provider = 317 scoped_refptr<TestContextProvider> context_provider =
365 TestContextProvider::Create(); 318 TestContextProvider::Create();
366 319
367 TestOutputSurface output_surface(context_provider); 320 TestOutputSurface output_surface(context_provider);
368 EXPECT_FALSE(output_surface.HasClient()); 321 EXPECT_FALSE(output_surface.HasClient());
369 322
370 FakeOutputSurfaceClient client; 323 FakeOutputSurfaceClient client;
371 EXPECT_TRUE(output_surface.BindToClient(&client)); 324 EXPECT_TRUE(output_surface.BindToClient(&client));
372 EXPECT_TRUE(output_surface.HasClient()); 325 EXPECT_TRUE(output_surface.HasClient());
373 EXPECT_FALSE(client.deferred_initialize_called()); 326 EXPECT_FALSE(client.deferred_initialize_called());
374 327
375 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(10); 328 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(10);
376 329
377 // Initialize BeginImplFrame emulation 330 // Initialize BeginImplFrame emulation
378 scoped_refptr<base::TestSimpleTaskRunner> task_runner = 331 scoped_refptr<base::TestSimpleTaskRunner> task_runner =
379 new base::TestSimpleTaskRunner; 332 new base::TestSimpleTaskRunner;
380 bool throttle_frame_production = true;
381 const base::TimeDelta display_refresh_interval = big_interval; 333 const base::TimeDelta display_refresh_interval = big_interval;
382 334
383 output_surface.InitializeBeginImplFrameEmulation( 335 output_surface.InitializeBeginImplFrameEmulation(
384 task_runner.get(), 336 task_runner.get(),
385 throttle_frame_production,
386 display_refresh_interval); 337 display_refresh_interval);
387 338
388 // We need to subtract an epsilon from Now() because some platforms have 339 // We need to subtract an epsilon from Now() because some platforms have
389 // a slow clock. 340 // a slow clock.
390 output_surface.CommitVSyncParametersForTesting( 341 output_surface.CommitVSyncParametersForTesting(
391 gfx::FrameTime::Now() - base::TimeDelta::FromSeconds(1), big_interval); 342 gfx::FrameTime::Now() - base::TimeDelta::FromSeconds(1), big_interval);
392 343
393 output_surface.SetMaxFramesPending(2);
394 output_surface.EnableRetroactiveBeginImplFrameDeadline( 344 output_surface.EnableRetroactiveBeginImplFrameDeadline(
395 true, true, big_interval); 345 true, true, big_interval);
396 346
397 // We should start off with 0 BeginImplFrames 347 // We should start off with 0 BeginImplFrames
398 EXPECT_EQ(client.begin_impl_frame_count(), 0); 348 EXPECT_EQ(client.begin_impl_frame_count(), 0);
399 EXPECT_EQ(output_surface.pending_swap_buffers(), 0);
400 349
401 // The first SetNeedsBeginImplFrame(true) should start a retroactive 350 // The first SetNeedsBeginImplFrame(true) should start a retroactive
402 // BeginImplFrame. 351 // BeginImplFrame.
403 EXPECT_FALSE(task_runner->HasPendingTask()); 352 EXPECT_FALSE(task_runner->HasPendingTask());
404 output_surface.SetNeedsBeginImplFrame(true); 353 output_surface.SetNeedsBeginImplFrame(true);
405 EXPECT_TRUE(task_runner->HasPendingTask()); 354 EXPECT_TRUE(task_runner->HasPendingTask());
406 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2); 355 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2);
407 EXPECT_EQ(client.begin_impl_frame_count(), 1); 356 EXPECT_EQ(client.begin_impl_frame_count(), 1);
408 357
409 output_surface.SetNeedsBeginImplFrame(false); 358 output_surface.SetNeedsBeginImplFrame(false);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); 414 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count());
466 EXPECT_EQ(0, software_output_device->discard_backbuffer_count()); 415 EXPECT_EQ(0, software_output_device->discard_backbuffer_count());
467 output_surface.DiscardBackbuffer(); 416 output_surface.DiscardBackbuffer();
468 417
469 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count()); 418 EXPECT_EQ(1, software_output_device->ensure_backbuffer_count());
470 EXPECT_EQ(1, software_output_device->discard_backbuffer_count()); 419 EXPECT_EQ(1, software_output_device->discard_backbuffer_count());
471 } 420 }
472 421
473 } // namespace 422 } // namespace
474 } // namespace cc 423 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698