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

Unified Diff: cc/scheduler/scheduler_unittest.cc

Issue 23796002: cc: Implement deadine scheduling disabled by default (Closed) Base URL: http://git.chromium.org/chromium/src.git@schedReadback4
Patch Set: rebase? Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: cc/scheduler/scheduler_unittest.cc
diff --git a/cc/scheduler/scheduler_unittest.cc b/cc/scheduler/scheduler_unittest.cc
index 7074bbef4f7a41dbd027ac3cde8f23c6ba741d66..c43b184439450389246101304e35d41fd86db4ca 100644
--- a/cc/scheduler/scheduler_unittest.cc
+++ b/cc/scheduler/scheduler_unittest.cc
@@ -1,7 +1,6 @@
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
#include "cc/scheduler/scheduler.h"
#include <string>
@@ -35,9 +34,10 @@ void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler) {
scheduler->FinishCommit();
// Go through the motions to draw the commit.
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
- // We need another BeginFrame so scheduler calls SetNeedsBeginFrame(false).
- scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
+ // We need another BeginFrame so Scheduler calls SetNeedsBeginFrame(false).
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
}
class FakeSchedulerClient : public SchedulerClient {
@@ -148,6 +148,14 @@ class FakeSchedulerClient : public SchedulerClient {
return base::TimeDelta();
}
+ virtual void PostBeginFrameDeadline(const base::Closure& closure,
+ base::TimeTicks deadline) OVERRIDE {
+ actions_.push_back("PostBeginFrameDeadlineTask");
+ states_.push_back(scheduler_->StateAsValue().release());
+ }
+
+ virtual void DidBeginFrameDeadlineOnImplThread() OVERRIDE {}
+
protected:
bool needs_begin_frame_;
bool draw_will_happen_;
@@ -183,11 +191,21 @@ TEST(SchedulerTest, RequestCommit) {
EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
InitializeOutputSurfaceAndFirstCommit(scheduler);
- // SetNeedsCommit should begin the frame.
+ // SetNeedsCommit should begin the frame on the next BeginFrame.
client.Reset();
scheduler->SetNeedsCommit();
+ EXPECT_TRUE(client.needs_begin_frame());
+ client.Reset();
+
+ scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2);
- EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
+ EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
+ EXPECT_TRUE(client.needs_begin_frame());
+ client.Reset();
+
+ // If we don't swap on the deadline, we need to request another BeginFrame.
+ scheduler->OnBeginFrameDeadline();
+ EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
EXPECT_TRUE(client.needs_begin_frame());
client.Reset();
@@ -197,10 +215,25 @@ TEST(SchedulerTest, RequestCommit) {
EXPECT_TRUE(client.needs_begin_frame());
client.Reset();
- // BeginFrame should draw.
+ // BeginFrame should prepare the draw.
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
- EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
- EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
+ EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
+ EXPECT_TRUE(client.needs_begin_frame());
+ client.Reset();
+
+ // BeginFrame deadline should draw.
+ scheduler->OnBeginFrameDeadline();
+ EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client);
+ client.Reset();
+
+ // The following BeginFrame deadline should SetNeedsBeginFrame(false) to avoid
+ // excessive toggles.
+ scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
+ client.Reset();
+
+ scheduler->OnBeginFrameDeadline();
+ EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
EXPECT_FALSE(client.needs_begin_frame());
client.Reset();
}
@@ -217,32 +250,53 @@ TEST(SchedulerTest, RequestCommitAfterBeginFrameSentToMainThread) {
InitializeOutputSurfaceAndFirstCommit(scheduler);
client.Reset();
- // SetNedsCommit should begin the frame.
+ // SetNeddsCommit should begin the frame.
scheduler->SetNeedsCommit();
+ EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
+ client.Reset();
+ scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2);
- EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
+ EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
+ EXPECT_TRUE(client.needs_begin_frame());
client.Reset();
- // Now SetNeedsCommit again. Calling here means we need a second frame.
+ // Now SetNeedsCommit again. Calling here means we need a second commit.
scheduler->SetNeedsCommit();
+ EXPECT_EQ(client.num_actions_(), 0);
+ client.Reset();
- // Finish the commit for the first frame.
+ // Finish the first commit.
scheduler->FinishCommit();
- EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
+ EXPECT_ACTION("ScheduledActionCommit", client, 0, 2);
+ EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
+ client.Reset();
+ scheduler->OnBeginFrameDeadline();
+ EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client);
client.Reset();
- // Tick should draw but then begin another frame for the second commit.
+ // Since another commit is needed, the next BeginFrame should initiate
+ // the second commit.
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
- EXPECT_TRUE(client.needs_begin_frame());
- EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
- EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 2);
+ EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2);
+ EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
client.Reset();
- // Finish the second commit to go back to quiescent state and verify we no
- // longer request BeginFrames.
+ // Finishing the commit before the deadline should post a new deadline task
+ // to trigger the deadline early.
scheduler->FinishCommit();
+ EXPECT_ACTION("ScheduledActionCommit", client, 0, 2);
+ EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
+ client.Reset();
+ scheduler->OnBeginFrameDeadline();
+ EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client);
+ EXPECT_TRUE(client.needs_begin_frame());
+
+ // On the next BeginFrame, go back to quiescent state and verify we no longer
+ // request BeginFrames.
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
EXPECT_FALSE(client.needs_begin_frame());
+ client.Reset();
}
TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) {
@@ -263,10 +317,12 @@ TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) {
client.Reset();
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
- EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
- EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
+ EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
+
+ client.Reset();
+ scheduler->OnBeginFrameDeadline();
+ EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client);
EXPECT_FALSE(scheduler->RedrawPending());
- EXPECT_FALSE(client.needs_begin_frame());
client.Reset();
scheduler->SetMainThreadNeedsLayerTextures();
@@ -277,36 +333,47 @@ TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) {
client.Reset();
scheduler->SetNeedsRedraw();
EXPECT_TRUE(scheduler->RedrawPending());
- EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
- EXPECT_TRUE(client.needs_begin_frame());
+ EXPECT_EQ(0, client.num_actions_());
// No draw happens since the textures are acquired by the main thread.
client.Reset();
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
+
+ client.Reset();
+ scheduler->OnBeginFrameDeadline();
EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
EXPECT_TRUE(scheduler->RedrawPending());
EXPECT_TRUE(client.needs_begin_frame());
+ client.Reset();
scheduler->SetNeedsCommit();
- EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 0, 2);
- EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 2);
- EXPECT_TRUE(client.needs_begin_frame());
+ EXPECT_EQ(0, client.num_actions_());
+
+ client.Reset();
+ scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2);
+ EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
// Commit will release the texture.
client.Reset();
scheduler->FinishCommit();
- EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
+ EXPECT_ACTION("ScheduledActionCommit", client, 0, 2);
+ EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
EXPECT_TRUE(scheduler->RedrawPending());
- EXPECT_TRUE(client.needs_begin_frame());
// Now we can draw again after the commit happens.
client.Reset();
- scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
- EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
- EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
+ scheduler->OnBeginFrameDeadline();
+ EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client);
EXPECT_FALSE(scheduler->RedrawPending());
+
+ // SetNeedsBeginFrame(false) should be deferred to the end of the next
+ // BeginFrame to avoid excessive toggling.
+ EXPECT_TRUE(client.needs_begin_frame());
+ scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
EXPECT_FALSE(client.needs_begin_frame());
- client.Reset();
}
TEST(SchedulerTest, TextureAcquisitionCollision) {
@@ -323,11 +390,18 @@ TEST(SchedulerTest, TextureAcquisitionCollision) {
client.Reset();
scheduler->SetNeedsCommit();
scheduler->SetMainThreadNeedsLayerTextures();
- EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 3);
- EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 3);
+ EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 0, 2);
EXPECT_ACTION(
- "ScheduledActionAcquireLayerTexturesForMainThread", client, 2, 3);
+ "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 2);
+
+ client.Reset();
+ scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2);
+ EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
+
client.Reset();
+ scheduler->OnBeginFrameDeadline();
+ EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
// Although the compositor cannot draw because textures are locked by main
// thread, we continue requesting SetNeedsBeginFrame in anticipation of the
@@ -337,32 +411,34 @@ TEST(SchedulerTest, TextureAcquisitionCollision) {
// Trigger the commit
scheduler->FinishCommit();
EXPECT_TRUE(client.needs_begin_frame());
- client.Reset();
// Between commit and draw, texture acquisition for main thread delayed,
// and main thread blocks.
+ client.Reset();
scheduler->SetMainThreadNeedsLayerTextures();
EXPECT_EQ(0, client.num_actions_());
- client.Reset();
// No implicit commit is expected.
+ client.Reset();
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
- EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3);
- EXPECT_ACTION("ScheduledActionAcquireLayerTexturesForMainThread",
- client,
- 1,
- 3);
- EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3);
+ EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
+
client.Reset();
+ scheduler->OnBeginFrameDeadline();
+ EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
+ EXPECT_ACTION(
+ "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 2);
- // Compositor not scheduled to draw because textures are locked by main
- // thread.
- EXPECT_FALSE(client.needs_begin_frame());
+ // Although the compositor is not scheduled to draw because textures are
+ // locked by main thread, we proactively request the begin frame.
+ EXPECT_TRUE(client.needs_begin_frame());
// Needs an explicit commit from the main thread.
+ client.Reset();
scheduler->SetNeedsCommit();
+ scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2);
- EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
+ EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
client.Reset();
// Trigger the commit
@@ -383,6 +459,8 @@ TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) {
scheduler->DidCreateAndInitializeOutputSurface();
scheduler->SetNeedsCommit();
+ scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
scheduler->FinishCommit();
scheduler->SetMainThreadNeedsLayerTextures();
scheduler->SetNeedsCommit();
@@ -392,19 +470,20 @@ TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) {
scheduler->SetVisible(false);
EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread",
client);
- client.Reset();
// Already sent a begin frame on this current frame, so wait.
+ client.Reset();
scheduler->SetVisible(true);
EXPECT_EQ(0, client.num_actions_());
- client.Reset();
+ EXPECT_TRUE(client.needs_begin_frame());
// Regaining visibility with textures acquired by main thread while
// compositor is waiting for first draw should result in a request
// for a new frame in order to escape a deadlock.
+ client.Reset();
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2);
- EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
+ EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
}
class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient {
@@ -451,13 +530,19 @@ TEST(SchedulerTest, RequestRedrawInsideDraw) {
EXPECT_EQ(0, client.num_draws());
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
EXPECT_EQ(1, client.num_draws());
EXPECT_TRUE(scheduler->RedrawPending());
EXPECT_TRUE(client.needs_begin_frame());
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
EXPECT_EQ(2, client.num_draws());
EXPECT_FALSE(scheduler->RedrawPending());
+ EXPECT_TRUE(client.needs_begin_frame());
+
+ scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
EXPECT_FALSE(client.needs_begin_frame());
}
@@ -481,6 +566,7 @@ TEST(SchedulerTest, RequestRedrawInsideFailedDraw) {
// Fail the draw.
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
EXPECT_EQ(1, client.num_draws());
// We have a commit pending and the draw failed, and we didn't lose the redraw
@@ -491,6 +577,7 @@ TEST(SchedulerTest, RequestRedrawInsideFailedDraw) {
// Fail the draw again.
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
EXPECT_EQ(2, client.num_draws());
EXPECT_TRUE(scheduler->CommitPending());
EXPECT_TRUE(scheduler->RedrawPending());
@@ -499,6 +586,7 @@ TEST(SchedulerTest, RequestRedrawInsideFailedDraw) {
// Draw successfully.
client.SetDrawWillHappen(true);
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
EXPECT_EQ(3, client.num_draws());
EXPECT_TRUE(scheduler->CommitPending());
EXPECT_FALSE(scheduler->RedrawPending());
@@ -551,6 +639,7 @@ TEST(SchedulerTest, RequestCommitInsideDraw) {
InitializeOutputSurfaceAndFirstCommit(scheduler);
client.Reset();
+ EXPECT_FALSE(client.needs_begin_frame());
scheduler->SetNeedsRedraw();
EXPECT_TRUE(scheduler->RedrawPending());
EXPECT_EQ(0, client.num_draws());
@@ -558,15 +647,23 @@ TEST(SchedulerTest, RequestCommitInsideDraw) {
client.SetNeedsCommitOnNextDraw();
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ client.SetNeedsCommitOnNextDraw();
+ scheduler->OnBeginFrameDeadline();
EXPECT_EQ(1, client.num_draws());
EXPECT_TRUE(scheduler->CommitPending());
EXPECT_TRUE(client.needs_begin_frame());
scheduler->FinishCommit();
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
- EXPECT_EQ(2, client.num_draws());;
+ scheduler->OnBeginFrameDeadline();
+ EXPECT_EQ(2, client.num_draws());
+
EXPECT_FALSE(scheduler->RedrawPending());
EXPECT_FALSE(scheduler->CommitPending());
+ EXPECT_TRUE(client.needs_begin_frame());
+
+ scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
EXPECT_FALSE(client.needs_begin_frame());
}
@@ -590,6 +687,7 @@ TEST(SchedulerTest, RequestCommitInsideFailedDraw) {
// Fail the draw.
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
EXPECT_EQ(1, client.num_draws());
// We have a commit pending and the draw failed, and we didn't lose the commit
@@ -600,6 +698,7 @@ TEST(SchedulerTest, RequestCommitInsideFailedDraw) {
// Fail the draw again.
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
EXPECT_EQ(2, client.num_draws());
EXPECT_TRUE(scheduler->CommitPending());
EXPECT_TRUE(scheduler->RedrawPending());
@@ -608,6 +707,7 @@ TEST(SchedulerTest, RequestCommitInsideFailedDraw) {
// Draw successfully.
client.SetDrawWillHappen(true);
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
EXPECT_EQ(3, client.num_draws());
EXPECT_TRUE(scheduler->CommitPending());
EXPECT_FALSE(scheduler->RedrawPending());
@@ -632,6 +732,7 @@ TEST(SchedulerTest, NoSwapWhenDrawFails) {
// Draw successfully, this starts a new frame.
client.SetNeedsCommitOnNextDraw();
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
EXPECT_EQ(1, client.num_draws());
scheduler->SetNeedsRedraw();
@@ -642,6 +743,7 @@ TEST(SchedulerTest, NoSwapWhenDrawFails) {
client.SetDrawWillHappen(false);
client.SetNeedsCommitOnNextDraw();
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
EXPECT_EQ(2, client.num_draws());
}

Powered by Google App Engine
This is Rietveld 408576698