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

Unified Diff: cc/scheduler/scheduler.cc

Issue 16871016: cc: Use BeginFrameArgs (Closed) Base URL: http://git.chromium.org/chromium/src.git@bfargs2
Patch Set: else if typo Created 7 years, 5 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.cc
diff --git a/cc/scheduler/scheduler.cc b/cc/scheduler/scheduler.cc
index edf5e2549d54d0554995c6352db047a1018c27e9..48a723686f92a62eead034cd69ec43928dde1010 100644
--- a/cc/scheduler/scheduler.cc
+++ b/cc/scheduler/scheduler.cc
@@ -4,6 +4,7 @@
#include "cc/scheduler/scheduler.h"
+#include <algorithm>
#include "base/auto_reset.h"
#include "base/debug/trace_event.h"
#include "base/logging.h"
@@ -43,9 +44,12 @@ void Scheduler::SetCanDraw(bool can_draw) {
ProcessScheduledActions();
}
-void Scheduler::SetHasPendingTree(bool has_pending_tree) {
- state_machine_.SetHasPendingTree(has_pending_tree);
+void Scheduler::SetHasTrees(bool has_pending_tree, bool active_tree_is_null) {
+ state_machine_.SetHasTrees(has_pending_tree, active_tree_is_null);
ProcessScheduledActions();
+
+ if (state_machine_.ShouldTriggerBeginFrameDeadlineEarly())
+ PostBeginFrameDeadline(base::TimeTicks());
}
void Scheduler::SetNeedsCommit() {
@@ -83,6 +87,9 @@ void Scheduler::FinishCommit() {
TRACE_EVENT0("cc", "Scheduler::FinishCommit");
state_machine_.FinishCommit();
ProcessScheduledActions();
+
+ if (state_machine_.ShouldTriggerBeginFrameDeadlineEarly())
+ PostBeginFrameDeadline(base::TimeTicks());
}
void Scheduler::BeginFrameAbortedByMainThread() {
@@ -113,12 +120,11 @@ base::TimeTicks Scheduler::AnticipatedDrawTime() {
last_begin_frame_args_.interval <= base::TimeDelta())
return base::TimeTicks();
- // TODO(brianderson): Express this in terms of the deadline.
base::TimeTicks now = base::TimeTicks::Now();
- int64 intervals = 1 + ((now - last_begin_frame_args_.frame_time) /
- last_begin_frame_args_.interval);
- return last_begin_frame_args_.frame_time +
- (last_begin_frame_args_.interval * intervals);
+ base::TimeTicks timebase = std::max(last_begin_frame_args_.frame_time,
+ last_begin_frame_args_.deadline);
+ int64 intervals = 1 + ((now - timebase) / last_begin_frame_args_.interval);
+ return timebase + (last_begin_frame_args_.interval * intervals);
}
base::TimeTicks Scheduler::LastBeginFrameOnImplThreadTime() {
@@ -128,41 +134,37 @@ base::TimeTicks Scheduler::LastBeginFrameOnImplThreadTime() {
void Scheduler::SetupNextBeginFrameIfNeeded() {
bool needs_begin_frame_to_draw =
state_machine_.BeginFrameNeededToDrawByImplThread();
- // We want to avoid proactive begin frames with the synchronous compositor
- // because every SetNeedsBeginFrame will force a redraw.
bool proactive_begin_frame_wanted =
- state_machine_.ProactiveBeginFrameWantedByImplThread() &&
- !settings_.using_synchronous_renderer_compositor &&
- settings_.throttle_frame_production;
+ state_machine_.ProactiveBeginFrameWantedByImplThread();
+
+ // We want to avoid proactive begin frames with the synchronous
+ // compositor because every SetNeedsBeginFrame will force a redraw.
bool needs_begin_frame = needs_begin_frame_to_draw ||
proactive_begin_frame_wanted;
- bool immediate_disables_needed =
- settings_.using_synchronous_renderer_compositor;
+
+ bool should_call_set_needs_begin_frame =
+ // The synchronous renderer compositor needs immediate enables/disables.
+ (settings_.using_synchronous_renderer_compositor &&
+ needs_begin_frame != last_set_needs_begin_frame_) ||
+ // Always request the BeginFrame immediately if it wasn't needed before.
+ (needs_begin_frame && !last_set_needs_begin_frame_) ||
+ // Only disable the BeginFrame after a BeginFrame where we didn't swap.
+ (!needs_begin_frame && last_set_needs_begin_frame_ &&
+ has_pending_begin_frame_ && !state_machine_.InsideBeginFrame()) ||
+ // We did not draw and swap this BeginFrame,
+ // so we need to explicitly request another BeginFrame.
+ (needs_begin_frame && has_pending_begin_frame_ &&
+ state_machine_.InsideBeginFrame());
if (needs_begin_frame_to_draw)
safe_to_expect_begin_frame_ = true;
- // Determine if we need BeginFrame notifications.
- // If we do, always request the BeginFrame immediately.
- // If not, only disable on the next BeginFrame to avoid unnecessary toggles.
- // The synchronous renderer compositor requires immediate disables though.
- if ((needs_begin_frame ||
- state_machine_.inside_begin_frame() ||
- immediate_disables_needed) &&
- (needs_begin_frame != last_set_needs_begin_frame_)) {
+ if (should_call_set_needs_begin_frame) {
has_pending_begin_frame_ = false;
client_->SetNeedsBeginFrameOnImplThread(needs_begin_frame);
if (safe_to_expect_begin_frame_)
last_set_needs_begin_frame_ = needs_begin_frame;
}
-
- // Request another BeginFrame if we haven't drawn for now until we have
- // deadlines implemented.
- if (state_machine_.inside_begin_frame() && has_pending_begin_frame_) {
- has_pending_begin_frame_ = false;
- client_->SetNeedsBeginFrameOnImplThread(true);
- return;
- }
}
void Scheduler::BeginFrame(const BeginFrameArgs& args) {
@@ -171,9 +173,32 @@ void Scheduler::BeginFrame(const BeginFrameArgs& args) {
has_pending_begin_frame_ = true;
safe_to_expect_begin_frame_ = true;
last_begin_frame_args_ = args;
- state_machine_.DidEnterBeginFrame(args);
+ last_begin_frame_args_.AdjustDeadline(-client_->DrawDurationEstimate());
+ state_machine_.OnBeginFrame(last_begin_frame_args_);
ProcessScheduledActions();
- state_machine_.DidLeaveBeginFrame();
+
+ if (settings_.using_synchronous_renderer_compositor)
brianderson 2013/07/10 21:58:04 Bo, does this method fix WebView so it always draw
boliu 2013/07/10 23:39:52 Yep I think so. So just to confirm I understand t
brianderson 2013/07/11 00:25:43 Yes. BeginFrame will never exit in the DEADLINE_PE
+ OnBeginFrameDeadline();
+ else if (state_machine_.ShouldTriggerBeginFrameDeadlineEarly())
+ PostBeginFrameDeadline(base::TimeTicks());
+ else
+ PostBeginFrameDeadline(last_begin_frame_args_.deadline);
+}
+
+void Scheduler::PostBeginFrameDeadline(base::TimeTicks deadline) {
+ begin_frame_deadline_closure_.Cancel();
+ begin_frame_deadline_closure_.Reset(
+ base::Bind(&Scheduler::OnBeginFrameDeadline, weak_factory_.GetWeakPtr()));
+ client_->PostBeginFrameDeadline(
+ begin_frame_deadline_closure_.callback(), deadline);
+}
+
+void Scheduler::OnBeginFrameDeadline() {
+ TRACE_EVENT0("cc", "Scheduler::OnBeginFrameDeadline");
+ begin_frame_deadline_closure_.Cancel();
+ state_machine_.OnBeginFrameDeadline();
+ ProcessScheduledActions();
+ client_->DidBeginFrameDeadlineOnImplThread();
}
void Scheduler::DrawAndSwapIfPossible() {
@@ -199,8 +224,11 @@ void Scheduler::ProcessScheduledActions() {
base::AutoReset<bool> mark_inside(&inside_process_scheduled_actions_, true);
- SchedulerStateMachine::Action action = state_machine_.NextAction();
- while (action != SchedulerStateMachine::ACTION_NONE) {
+ SchedulerStateMachine::Action action;
+ do {
+ TRACE_EVENT1("cc", "SchedulerStateMachine",
+ "state", state_machine_.ToString());
+ action = state_machine_.NextAction();
state_machine_.UpdateState(action);
switch (action) {
case SchedulerStateMachine::ACTION_NONE:
@@ -230,8 +258,7 @@ void Scheduler::ProcessScheduledActions() {
client_->ScheduledActionAcquireLayerTexturesForMainThread();
break;
}
- action = state_machine_.NextAction();
- }
+ } while (action != SchedulerStateMachine::ACTION_NONE);
SetupNextBeginFrameIfNeeded();
client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime());

Powered by Google App Engine
This is Rietveld 408576698