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

Side by Side Diff: cc/scheduler/scheduler_unittest.cc

Issue 1133673004: cc: Heuristic for Renderer latency recovery (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 7 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 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/scheduler/scheduler.h" 5 #include "cc/scheduler/scheduler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 PushAction("ScheduledActionPrepareTiles"); 143 PushAction("ScheduledActionPrepareTiles");
144 } 144 }
145 void ScheduledActionInvalidateOutputSurface() override { 145 void ScheduledActionInvalidateOutputSurface() override {
146 actions_.push_back("ScheduledActionInvalidateOutputSurface"); 146 actions_.push_back("ScheduledActionInvalidateOutputSurface");
147 states_.push_back(scheduler_->AsValue()); 147 states_.push_back(scheduler_->AsValue());
148 } 148 }
149 void DidAnticipatedDrawTimeChange(base::TimeTicks) override { 149 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {
150 if (log_anticipated_draw_time_change_) 150 if (log_anticipated_draw_time_change_)
151 PushAction("DidAnticipatedDrawTimeChange"); 151 PushAction("DidAnticipatedDrawTimeChange");
152 } 152 }
153 base::TimeDelta DrawDurationEstimate() override { return base::TimeDelta(); } 153
154 // Use really long estimations by default so we don't inadvertently
155 // test latency recovery logic unless a test explicitly wants to.
156 base::TimeDelta DrawDurationEstimate() override {
157 return base::TimeDelta::FromHours(1);
158 }
154 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { 159 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override {
155 return base::TimeDelta(); 160 return base::TimeDelta::FromHours(1);
156 } 161 }
157 base::TimeDelta CommitToActivateDurationEstimate() override { 162 base::TimeDelta CommitToActivateDurationEstimate() override {
158 return base::TimeDelta(); 163 return base::TimeDelta::FromHours(1);
159 } 164 }
160 165
161 void SendBeginFramesToChildren(const BeginFrameArgs& args) override { 166 void SendBeginFramesToChildren(const BeginFrameArgs& args) override {
162 begin_frame_args_sent_to_children_ = args; 167 begin_frame_args_sent_to_children_ = args;
163 } 168 }
164 169
165 void SendBeginMainFrameNotExpectedSoon() override { 170 void SendBeginMainFrameNotExpectedSoon() override {
166 PushAction("SendBeginMainFrameNotExpectedSoon"); 171 PushAction("SendBeginMainFrameNotExpectedSoon");
167 } 172 }
168 173
(...skipping 27 matching lines...) Expand all
196 int num_draws_; 201 int num_draws_;
197 bool log_anticipated_draw_time_change_; 202 bool log_anticipated_draw_time_change_;
198 BeginFrameArgs begin_frame_args_sent_to_children_; 203 BeginFrameArgs begin_frame_args_sent_to_children_;
199 base::TimeTicks posted_begin_impl_frame_deadline_; 204 base::TimeTicks posted_begin_impl_frame_deadline_;
200 std::vector<const char*> actions_; 205 std::vector<const char*> actions_;
201 std::vector<scoped_refptr<base::trace_event::ConvertableToTraceFormat>> 206 std::vector<scoped_refptr<base::trace_event::ConvertableToTraceFormat>>
202 states_; 207 states_;
203 TestScheduler* scheduler_; 208 TestScheduler* scheduler_;
204 }; 209 };
205 210
206 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { 211 class SchedulerClientWithCustomEstimates : public FakeSchedulerClient {
207 public: 212 public:
208 SchedulerClientWithFixedEstimates( 213 SchedulerClientWithCustomEstimates(
209 base::TimeDelta draw_duration, 214 base::TimeDelta draw_duration,
210 base::TimeDelta begin_main_frame_to_commit_duration, 215 base::TimeDelta begin_main_frame_to_commit_duration,
211 base::TimeDelta commit_to_activate_duration) 216 base::TimeDelta commit_to_activate_duration)
212 : draw_duration_(draw_duration), 217 : draw_duration_(draw_duration),
213 begin_main_frame_to_commit_duration_( 218 begin_main_frame_to_commit_duration_(
214 begin_main_frame_to_commit_duration), 219 begin_main_frame_to_commit_duration),
215 commit_to_activate_duration_(commit_to_activate_duration) {} 220 commit_to_activate_duration_(commit_to_activate_duration) {}
216 221
217 base::TimeDelta DrawDurationEstimate() override { return draw_duration_; } 222 base::TimeDelta DrawDurationEstimate() override { return draw_duration_; }
218 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { 223 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override {
219 return begin_main_frame_to_commit_duration_; 224 return begin_main_frame_to_commit_duration_;
220 } 225 }
221 base::TimeDelta CommitToActivateDurationEstimate() override { 226 base::TimeDelta CommitToActivateDurationEstimate() override {
222 return commit_to_activate_duration_; 227 return commit_to_activate_duration_;
223 } 228 }
224 229
225 private: 230 public:
226 base::TimeDelta draw_duration_; 231 base::TimeDelta draw_duration_;
227 base::TimeDelta begin_main_frame_to_commit_duration_; 232 base::TimeDelta begin_main_frame_to_commit_duration_;
228 base::TimeDelta commit_to_activate_duration_; 233 base::TimeDelta commit_to_activate_duration_;
229 }; 234 };
230 235
231 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn { 236 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn {
232 public: 237 public:
233 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) 238 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client)
234 : client_(client) {} 239 : client_(client) {}
235 ~FakeExternalBeginFrameSource() override {} 240 ~FakeExternalBeginFrameSource() override {}
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 416
412 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { 417 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const {
413 return fake_external_begin_frame_source_; 418 return fake_external_begin_frame_source_;
414 } 419 }
415 420
416 void MainFrameInHighLatencyMode( 421 void MainFrameInHighLatencyMode(
417 int64 begin_main_frame_to_commit_estimate_in_ms, 422 int64 begin_main_frame_to_commit_estimate_in_ms,
418 int64 commit_to_activate_estimate_in_ms, 423 int64 commit_to_activate_estimate_in_ms,
419 bool impl_latency_takes_priority, 424 bool impl_latency_takes_priority,
420 bool should_send_begin_main_frame); 425 bool should_send_begin_main_frame);
426 void ImplFrameInHighLatencyMode(
427 int64 begin_main_frame_to_commit_estimate_in_ms,
428 int64 commit_to_activate_estimate_in_ms,
429 bool swap_ack_before_deadline,
430 bool should_begin_impl_frame_in_high_latency);
421 void BeginFramesNotFromClient(bool use_external_begin_frame_source, 431 void BeginFramesNotFromClient(bool use_external_begin_frame_source,
422 bool throttle_frame_production); 432 bool throttle_frame_production);
423 void BeginFramesNotFromClient_SwapThrottled( 433 void BeginFramesNotFromClient_SwapThrottled(
424 bool use_external_begin_frame_source, 434 bool use_external_begin_frame_source,
425 bool throttle_frame_production); 435 bool throttle_frame_production);
426 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( 436 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(
427 bool impl_side_painting); 437 bool impl_side_painting);
428 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting); 438 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting);
429 439
430 scoped_refptr<TestNowSource> now_src_; 440 scoped_refptr<TestNowSource> now_src_;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); 487 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
478 EXPECT_TRUE(client_->needs_begin_frames()); 488 EXPECT_TRUE(client_->needs_begin_frames());
479 489
480 client_->Reset(); 490 client_->Reset();
481 EXPECT_SCOPED(AdvanceFrame()); 491 EXPECT_SCOPED(AdvanceFrame());
482 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); 492 EXPECT_TRUE(client_->begin_frame_is_sent_to_children());
483 } 493 }
484 494
485 TEST_F(SchedulerTest, SendBeginFramesToChildrenDeadlineNotAdjusted) { 495 TEST_F(SchedulerTest, SendBeginFramesToChildrenDeadlineNotAdjusted) {
486 // Set up client with specified estimates. 496 // Set up client with specified estimates.
487 SchedulerClientWithFixedEstimates* client = 497 SchedulerClientWithCustomEstimates* client =
488 new SchedulerClientWithFixedEstimates( 498 new SchedulerClientWithCustomEstimates(
489 base::TimeDelta::FromMilliseconds(1), 499 base::TimeDelta::FromMilliseconds(1),
490 base::TimeDelta::FromMilliseconds(2), 500 base::TimeDelta::FromMilliseconds(2),
491 base::TimeDelta::FromMilliseconds(4)); 501 base::TimeDelta::FromMilliseconds(4));
492 scheduler_settings_.use_external_begin_frame_source = true; 502 scheduler_settings_.use_external_begin_frame_source = true;
493 SetUpScheduler(make_scoped_ptr(client).Pass(), true); 503 SetUpScheduler(make_scoped_ptr(client).Pass(), true);
494 504
495 EXPECT_FALSE(client_->needs_begin_frames()); 505 EXPECT_FALSE(client_->needs_begin_frames());
496 scheduler_->SetChildrenNeedBeginFrames(true); 506 scheduler_->SetChildrenNeedBeginFrames(true);
497 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); 507 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
498 EXPECT_TRUE(client_->needs_begin_frames()); 508 EXPECT_TRUE(client_->needs_begin_frames());
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3); 1319 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 3);
1310 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); 1320 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3);
1311 } 1321 }
1312 1322
1313 void SchedulerTest::MainFrameInHighLatencyMode( 1323 void SchedulerTest::MainFrameInHighLatencyMode(
1314 int64 begin_main_frame_to_commit_estimate_in_ms, 1324 int64 begin_main_frame_to_commit_estimate_in_ms,
1315 int64 commit_to_activate_estimate_in_ms, 1325 int64 commit_to_activate_estimate_in_ms,
1316 bool impl_latency_takes_priority, 1326 bool impl_latency_takes_priority,
1317 bool should_send_begin_main_frame) { 1327 bool should_send_begin_main_frame) {
1318 // Set up client with specified estimates (draw duration is set to 1). 1328 // Set up client with specified estimates (draw duration is set to 1).
1319 SchedulerClientWithFixedEstimates* client = 1329 SchedulerClientWithCustomEstimates* client =
1320 new SchedulerClientWithFixedEstimates( 1330 new SchedulerClientWithCustomEstimates(
1321 base::TimeDelta::FromMilliseconds(1), 1331 base::TimeDelta::FromMilliseconds(1),
1322 base::TimeDelta::FromMilliseconds( 1332 base::TimeDelta::FromMilliseconds(
1323 begin_main_frame_to_commit_estimate_in_ms), 1333 begin_main_frame_to_commit_estimate_in_ms),
1324 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); 1334 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms));
1325 1335
1326 scheduler_settings_.use_external_begin_frame_source = true; 1336 scheduler_settings_.use_external_begin_frame_source = true;
1327 SetUpScheduler(make_scoped_ptr(client).Pass(), true); 1337 SetUpScheduler(make_scoped_ptr(client).Pass(), true);
1328 1338
1329 scheduler_->SetImplLatencyTakesPriority(impl_latency_takes_priority); 1339 scheduler_->SetImplLatencyTakesPriority(impl_latency_takes_priority);
1330 1340
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 EXPECT_SCOPED(MainFrameInHighLatencyMode(1, 10, false, true)); 1381 EXPECT_SCOPED(MainFrameInHighLatencyMode(1, 10, false, true));
1372 } 1382 }
1373 1383
1374 TEST_F(SchedulerTest, NotSkipMainFrameInPreferImplLatencyMode) { 1384 TEST_F(SchedulerTest, NotSkipMainFrameInPreferImplLatencyMode) {
1375 // Set up client so that estimates indicate that we can commit and activate 1385 // Set up client so that estimates indicate that we can commit and activate
1376 // before the deadline (~8ms by default), but also enable impl latency takes 1386 // before the deadline (~8ms by default), but also enable impl latency takes
1377 // priority mode. 1387 // priority mode.
1378 EXPECT_SCOPED(MainFrameInHighLatencyMode(1, 1, true, true)); 1388 EXPECT_SCOPED(MainFrameInHighLatencyMode(1, 1, true, true));
1379 } 1389 }
1380 1390
1391 void SchedulerTest::ImplFrameInHighLatencyMode(
1392 int64 begin_main_frame_to_commit_estimate_in_ms,
1393 int64 commit_to_activate_estimate_in_ms,
1394 bool swap_ack_before_deadline,
1395 bool should_begin_impl_frame_in_high_latency) {
1396 // Set up client with specified estimates (draw duration is set to 1).
1397 SchedulerClientWithCustomEstimates* client =
1398 new SchedulerClientWithCustomEstimates(
1399 base::TimeDelta::FromMilliseconds(1),
1400 base::TimeDelta::FromMilliseconds(
1401 begin_main_frame_to_commit_estimate_in_ms),
1402 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms));
1403
1404 scheduler_settings_.use_external_begin_frame_source = true;
1405 SetUpScheduler(make_scoped_ptr(client).Pass(), true);
1406 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1407
1408 // To get into a high latency state, this test disables automatic swap acks.
1409 scheduler_->SetMaxSwapsPending(1);
1410 client_->SetAutomaticSwapAck(false);
1411
1412 // Draw and swap for first BeginFrame
1413 client->Reset();
1414 scheduler_->SetNeedsRedraw();
1415 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1416 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1417 EXPECT_SCOPED(AdvanceFrame());
1418 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1419 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1420 task_runner().RunPendingTasks(); // Run posted deadline.
1421 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible"));
1422
1423 // Not calling scheduler_->DidSwapBuffersComplete() until after next frame
1424 // puts impl thread in high latency mode.
1425 client->Reset();
1426 scheduler_->SetNeedsRedraw();
1427 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1428 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1429 EXPECT_SCOPED(AdvanceFrame());
1430 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1431 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1432 if (swap_ack_before_deadline) {
1433 scheduler_->DidSwapBuffersComplete();
1434 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1435 EXPECT_TRUE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1436 task_runner().RunPendingTasks(); // Run posted deadline.
1437 EXPECT_TRUE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1438 } else {
1439 task_runner().RunPendingTasks(); // Run posted deadline.
1440 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1441 EXPECT_TRUE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1442 scheduler_->DidSwapBuffersComplete();
1443 EXPECT_TRUE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1444 }
1445
1446 // Now that we are in a high latency mode, test if we recover or not.
1447 client->Reset();
1448 scheduler_->SetNeedsRedraw();
1449 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1450 EXPECT_TRUE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1451 SendNextBeginFrame();
1452 EXPECT_EQ(should_begin_impl_frame_in_high_latency,
1453 client->HasAction("WillBeginImplFrame"));
1454
1455 // Verify that we make forward progress even when we aren't expecting
1456 // another swap ack.
1457 if (!swap_ack_before_deadline) {
1458 client->Reset();
1459 SendNextBeginFrame();
1460 EXPECT_TRUE(client->HasAction("WillBeginImplFrame"));
1461 }
1462 }
1463
1464 TEST_F(SchedulerTest,
1465 SkipImplFrameIfHighLatencyAndCanDrawBeforeDeadline_SwapAckThenDeadline) {
1466 // Set up client so that estimates indicate that we can commit and activate
1467 // before the deadline (~8ms by default).
1468 EXPECT_SCOPED(ImplFrameInHighLatencyMode(1, 1, true, false));
1469 }
1470
1471 TEST_F(SchedulerTest,
1472 SkipImplFrameIfHighLatencyAndCanDrawBeforeDeadline_DeadlineThenSwapAck) {
1473 // Set up client so that estimates indicate that we can commit and activate
1474 // before the deadline (~8ms by default).
1475 EXPECT_SCOPED(ImplFrameInHighLatencyMode(1, 1, false, false));
1476 }
1477
1478 TEST_F(SchedulerTest, NotSkipImplFrameIfHighLatencyAndCanCommitTooLong) {
1479 // Set up client so that estimates indicate that the commit cannot finish
1480 // before the deadline (~8ms by default).
1481 EXPECT_SCOPED(ImplFrameInHighLatencyMode(10, 1, true, true));
1482 }
1483
1484 TEST_F(SchedulerTest, NotSkipImplFrameIfHighLatencyAndCanActivateTooLong) {
1485 // Set up client so that estimates indicate that the activate cannot finish
1486 // before the deadline (~8ms by default).
1487 EXPECT_SCOPED(ImplFrameInHighLatencyMode(1, 10, true, true));
1488 }
1489
1490 TEST_F(SchedulerTest, MainAndImplFrameInHighLatencyMode) {
1491 // Set up client with custom estimates.
1492 // This test starts off with expensive estimates to prevent latency recovery
1493 // initially, the lowers the estimates to enable it once both the main
1494 // and impl threads are in a high latency mode.
1495 auto fast_duration = base::TimeDelta::FromMilliseconds(1);
1496 auto slow_duration = base::TimeDelta::FromMilliseconds(10);
1497 SchedulerClientWithCustomEstimates* client =
1498 new SchedulerClientWithCustomEstimates(slow_duration, slow_duration,
1499 slow_duration);
1500
1501 scheduler_settings_.use_external_begin_frame_source = true;
1502 SetUpScheduler(make_scoped_ptr(client).Pass(), true);
1503 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1504
1505 // To get into a high latency state, this test disables automatic swap acks.
1506 scheduler_->SetMaxSwapsPending(1);
1507 client_->SetAutomaticSwapAck(false);
1508
1509 // Impl thread hits deadline before commit finishes to make
1510 // MainThreadIsInHighLatencyMode true
1511 client->Reset();
1512 scheduler_->SetNeedsCommit();
1513 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1514 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1515 EXPECT_SCOPED(AdvanceFrame());
1516 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1517 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1518 task_runner().RunPendingTasks(); // Run posted deadline.
1519 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode());
1520 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1521 scheduler_->NotifyBeginMainFrameStarted();
1522 scheduler_->NotifyReadyToCommit();
1523 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode());
1524 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1525 EXPECT_TRUE(client->HasAction("WillBeginImplFrame"));
1526 EXPECT_TRUE(client->HasAction("ScheduledActionSendBeginMainFrame"));
1527
1528 // Draw and swap for first commit, start second commit.
1529 client->Reset();
1530 scheduler_->SetNeedsCommit();
1531 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode());
1532 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1533 EXPECT_SCOPED(AdvanceFrame());
1534 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode());
1535 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1536 task_runner().RunPendingTasks(); // Run posted deadline.
1537 scheduler_->NotifyBeginMainFrameStarted();
1538 scheduler_->NotifyReadyToCommit();
1539 EXPECT_TRUE(client->HasAction("WillBeginImplFrame"));
1540 EXPECT_TRUE(client->HasAction("ScheduledActionSendBeginMainFrame"));
1541 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible"));
1542
1543 // Don't call scheduler_->DidSwapBuffersComplete() until after next frame
1544 // to make ImplThreadIsLikelyInHighLatencyMode true.
1545 client->Reset();
1546 scheduler_->SetNeedsCommit();
1547 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode());
1548 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1549 EXPECT_SCOPED(AdvanceFrame());
1550 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode());
1551 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1552 task_runner().RunPendingTasks(); // Run posted deadline.
1553 scheduler_->DidSwapBuffersComplete();
1554 EXPECT_TRUE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1555 EXPECT_TRUE(client->HasAction("WillBeginImplFrame"));
1556 // Note: BeginMainFrame and BeginImplFrame are skipped here because
1557 // of backpressure, not because of latency recovery.
1558 EXPECT_FALSE(client->HasAction("ScheduledActionSendBeginMainFrame"));
1559 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible"));
1560
1561 // Lower estimates so that the scheduler will attempt latency recovery.
1562 client->begin_main_frame_to_commit_duration_ = fast_duration;
1563 client->commit_to_activate_duration_ = fast_duration;
1564 client->draw_duration_ = fast_duration;
1565
1566 // Now that both threads are in a high latency mode, make sure we
1567 // skip the BeginMainFrame, then the BeginImplFrame, but not both
1568 // at the same time.
1569
1570 // Verify we skip BeginMainFrame first.
1571 client->Reset();
1572 EXPECT_TRUE(scheduler_->NeedsCommit()); // Previous commit still outstanding.
1573 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode());
1574 EXPECT_TRUE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1575 SendNextBeginFrame();
1576 task_runner().RunPendingTasks(); // Run posted deadline.
1577 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1578 EXPECT_TRUE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1579 EXPECT_TRUE(client->HasAction("WillBeginImplFrame"));
1580 EXPECT_FALSE(client->HasAction("ScheduledActionSendBeginMainFrame"));
1581 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible"));
1582
1583 // Verify we skip the BeginImplFrame second.
1584 client->Reset();
1585 EXPECT_TRUE(scheduler_->NeedsCommit()); // Previous commit still outstanding.
1586 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1587 EXPECT_TRUE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1588 SendNextBeginFrame();
1589 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1590 EXPECT_TRUE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1591 scheduler_->DidSwapBuffersComplete();
1592 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1593 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1594 EXPECT_FALSE(client->HasAction("WillBeginImplFrame"));
1595 EXPECT_FALSE(client->HasAction("ScheduledActionSendBeginMainFrame"));
1596 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible"));
1597
1598 // Then verify we operate in a low latency mode.
1599 client->Reset();
1600 EXPECT_TRUE(scheduler_->NeedsCommit()); // Previous commit still outstanding.
1601 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1602 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1603 SendNextBeginFrame();
1604 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1605 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1606 scheduler_->NotifyBeginMainFrameStarted();
1607 scheduler_->NotifyReadyToCommit();
1608 task_runner().RunPendingTasks(); // Run posted deadline.
1609 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1610 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1611 scheduler_->DidSwapBuffersComplete();
1612 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1613 EXPECT_FALSE(scheduler_->ImplThreadIsLikelyInHighLatencyMode());
1614 EXPECT_TRUE(client->HasAction("WillBeginImplFrame"));
1615 EXPECT_TRUE(client->HasAction("ScheduledActionSendBeginMainFrame"));
1616 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible"));
1617 }
1618
1381 TEST_F(SchedulerTest, PollForCommitCompletion) { 1619 TEST_F(SchedulerTest, PollForCommitCompletion) {
1382 // Since we are simulating a long commit, set up a client with draw duration 1620 // Since we are simulating a long commit, set up a client with draw duration
1383 // estimates that prevent skipping main frames to get to low latency mode. 1621 // estimates that prevent skipping main frames to get to low latency mode.
1384 SchedulerClientWithFixedEstimates* client = 1622 SchedulerClientWithCustomEstimates* client =
1385 new SchedulerClientWithFixedEstimates( 1623 new SchedulerClientWithCustomEstimates(
1386 base::TimeDelta::FromMilliseconds(1), 1624 base::TimeDelta::FromMilliseconds(1),
1387 base::TimeDelta::FromMilliseconds(32), 1625 base::TimeDelta::FromMilliseconds(32),
1388 base::TimeDelta::FromMilliseconds(32)); 1626 base::TimeDelta::FromMilliseconds(32));
1389 scheduler_settings_.use_external_begin_frame_source = true; 1627 scheduler_settings_.use_external_begin_frame_source = true;
1390 SetUpScheduler(make_scoped_ptr(client).Pass(), true); 1628 SetUpScheduler(make_scoped_ptr(client).Pass(), true);
1391 1629
1392 client->set_log_anticipated_draw_time_change(true); 1630 client->set_log_anticipated_draw_time_change(true);
1393 1631
1394 BeginFrameArgs frame_args = 1632 BeginFrameArgs frame_args =
1395 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); 1633 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src());
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after
2639 2877
2640 // At the next BeginFrame, authoritative interval is used instead of previous 2878 // At the next BeginFrame, authoritative interval is used instead of previous
2641 // interval. 2879 // interval.
2642 EXPECT_NE(initial_interval, scheduler_->begin_impl_frame_args().interval); 2880 EXPECT_NE(initial_interval, scheduler_->begin_impl_frame_args().interval);
2643 EXPECT_EQ(authoritative_interval, 2881 EXPECT_EQ(authoritative_interval,
2644 scheduler_->begin_impl_frame_args().interval); 2882 scheduler_->begin_impl_frame_args().interval);
2645 } 2883 }
2646 2884
2647 } // namespace 2885 } // namespace
2648 } // namespace cc 2886 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698