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

Unified Diff: cc/scheduler/scheduler.cc

Issue 16871016: cc: Use BeginFrameArgs (Closed) Base URL: http://git.chromium.org/chromium/src.git@bfargs2
Patch Set: Many optimizations. Address comments. Created 7 years, 6 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 d1997ea65eaf278be1276ab2852f80bb2d43ac22..33a4a9dd9f7b555dde5edda0e05a50fa3cc0422e 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"
@@ -46,6 +47,9 @@ void Scheduler::SetCanDraw(bool can_draw) {
void Scheduler::SetHasPendingTree(bool has_pending_tree) {
state_machine_.SetHasPendingTree(has_pending_tree);
ProcessScheduledActions();
+
+ if (state_machine_.ShouldTriggerBeginFrameDeadlineEarly())
+ OnBeginFrameDeadline();
}
void Scheduler::SetNeedsCommit() {
@@ -83,6 +87,9 @@ void Scheduler::FinishCommit() {
TRACE_EVENT0("cc", "Scheduler::FinishCommit");
state_machine_.FinishCommit();
ProcessScheduledActions();
+
+ if (state_machine_.ShouldTriggerBeginFrameDeadlineEarly())
+ OnBeginFrameDeadline();
}
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,40 +134,38 @@ 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;
+ state_machine_.ProactiveBeginFrameWantedByImplThread();
+
+ // We want to avoid proactive begin frames with the synchronous
+ // compositor because every SetNeedsBeginFrame will force a redraw.s
bool needs_begin_frame = needs_begin_frame_to_draw ||
- proactive_begin_frame_wanted;
- bool immediate_disables_needed =
- settings_.using_synchronous_renderer_compositor;
+ (proactive_begin_frame_wanted &&
+ !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) {
@@ -170,9 +174,28 @@ 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_.deadline +=
+ BeginFrameArgs::DefaultDeadlineAdjustment();
+ state_machine_.OnBeginFrame(last_begin_frame_args_);
+ ProcessScheduledActions();
+
+ if (state_machine_.ShouldTriggerBeginFrameDeadlineEarly()) {
+ OnBeginFrameDeadline();
+ } else {
+ begin_frame_deadline_closure_.Reset(
+ base::Bind(&Scheduler::OnBeginFrameDeadline,
+ weak_factory_.GetWeakPtr()));
+ client_->PostBeginFrameDeadline(
+ begin_frame_deadline_closure_.callback(),
+ last_begin_frame_args_.deadline);
+ }
+}
+
+void Scheduler::OnBeginFrameDeadline() {
+ TRACE_EVENT0("cc", "Scheduler::OnBeginFrameDeadline");
+ begin_frame_deadline_closure_.Cancel();
+ state_machine_.OnBeginFrameDeadline();
ProcessScheduledActions();
- state_machine_.DidLeaveBeginFrame();
}
void Scheduler::DrawAndSwapIfPossible() {
@@ -198,8 +221,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());
nduca 2013/06/21 01:21:40 medium term, might as well make StateMachine have
brianderson 2013/06/21 01:42:47 Ooh, neat. I wasn't planing to commit the TRACE_EV
+ action = state_machine_.NextAction();
state_machine_.UpdateState(action);
switch (action) {
case SchedulerStateMachine::ACTION_NONE:
@@ -229,8 +255,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