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

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: address enne's comments 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 9269fc5712f97704a912611381fcd92859a26f66..78e4f774bab739a3a847a3c19d3a08c6d659e397 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,26 @@ TEST(SchedulerTest, RequestCommit) {
EXPECT_TRUE(client.needs_begin_frame());
client.Reset();
- // BeginFrame should draw.
+ // BeginFrame should prepare the draw.
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
+ EXPECT_TRUE(client.needs_begin_frame());
+ client.Reset();
+
+ // BeginFrame deadline should draw.
+ scheduler->OnBeginFrameDeadline();
EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
+ 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,33 +251,55 @@ 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_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
+ EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
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, 3);
- EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 3);
- EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3);
+ 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_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
+ EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
+ 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) {
@@ -264,10 +320,13 @@ TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) {
client.Reset();
scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
+
+ client.Reset();
+ scheduler->OnBeginFrameDeadline();
EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
EXPECT_FALSE(scheduler->RedrawPending());
- EXPECT_FALSE(client.needs_begin_frame());
client.Reset();
scheduler->SetMainThreadNeedsLayerTextures();
@@ -278,36 +337,48 @@ 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());
+ scheduler->OnBeginFrameDeadline();
EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
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) {
@@ -324,11 +395,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
@@ -338,32 +416,35 @@ 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_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
+
+ client.Reset();
+ scheduler->OnBeginFrameDeadline();
EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3);
- EXPECT_ACTION("ScheduledActionAcquireLayerTexturesForMainThread",
- client,
- 1,
- 3);
+ EXPECT_ACTION(
+ "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 3);
EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3);
- client.Reset();
- // 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
@@ -384,6 +465,8 @@ TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) {
scheduler->DidCreateAndInitializeOutputSurface();
scheduler->SetNeedsCommit();
+ scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
+ scheduler->OnBeginFrameDeadline();
scheduler->FinishCommit();
scheduler->SetMainThreadNeedsLayerTextures();
scheduler->SetNeedsCommit();
@@ -393,19 +476,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 {
@@ -452,13 +536,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());
}
@@ -482,6 +572,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
@@ -492,6 +583,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());
@@ -500,6 +592,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());
@@ -552,6 +645,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());
@@ -559,15 +653,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());
}
@@ -591,6 +693,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
@@ -601,6 +704,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());
@@ -609,6 +713,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());
@@ -633,6 +738,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();
@@ -643,6 +749,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