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

Unified Diff: cc/scheduler/scheduler.cc

Issue 15836005: cc: Emulate BeginFrame in OutputSurfaces that don't support it natively (Closed) Base URL: http://git.chromium.org/chromium/src.git@nofrc
Patch Set: Created 7 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 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 737ffc1bb1222b2af5fec3d72e7a468abd4fa2ad..cf3fad51c7cc264d95e1692c7ab726f57d4d815f 100644
--- a/cc/scheduler/scheduler.cc
+++ b/cc/scheduler/scheduler.cc
@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "cc/base/thread.h"
#include "cc/scheduler/scheduler.h"
+#include "cc/trees/proxy.h"
#include "base/auto_reset.h"
#include "base/debug/trace_event.h"
@@ -11,19 +13,26 @@
namespace cc {
Scheduler::Scheduler(SchedulerClient* client,
- scoped_ptr<FrameRateController> frame_rate_controller,
- const SchedulerSettings& scheduler_settings)
+ const SchedulerSettings& scheduler_settings,
+ Thread *thread)
: settings_(scheduler_settings),
client_(client),
- frame_rate_controller_(frame_rate_controller.Pass()),
+ weak_factory_(this),
+ thread_(thread),
+ last_set_needs_begin_frame_(false),
+ pending_begin_frames_(0),
+ last_begin_frame_time_(base::TimeTicks::Now()),
+ //TODO(brianderson): Pass with BeginFrame in the near future.
+ interval_(base::TimeDelta::FromMicroseconds(16666)),
state_machine_(scheduler_settings),
inside_process_scheduled_actions_(false) {
DCHECK(client_);
- frame_rate_controller_->SetClient(this);
DCHECK(!state_machine_.BeginFrameNeededByImplThread());
}
-Scheduler::~Scheduler() { frame_rate_controller_->SetActive(false); }
+Scheduler::~Scheduler() {
+ client_->SetNeedsBeginFrameOnImplThread(false);
+}
void Scheduler::SetCanStart() {
state_machine_.SetCanStart();
@@ -88,25 +97,8 @@ void Scheduler::BeginFrameAbortedByMainThread() {
ProcessScheduledActions();
}
-void Scheduler::SetMaxFramesPending(int max_frames_pending) {
- frame_rate_controller_->SetMaxFramesPending(max_frames_pending);
-}
-
-int Scheduler::MaxFramesPending() const {
- return frame_rate_controller_->MaxFramesPending();
-}
-
-int Scheduler::NumFramesPendingForTesting() const {
- return frame_rate_controller_->NumFramesPendingForTesting();
-}
-
-void Scheduler::SetSwapBuffersCompleteSupported(bool supported) {
- frame_rate_controller_->SetSwapBuffersCompleteSupported(supported);
-}
-
-void Scheduler::DidSwapBuffersComplete() {
- TRACE_EVENT0("cc", "Scheduler::DidSwapBuffersComplete");
- frame_rate_controller_->DidSwapBuffersComplete();
+void Scheduler::DidSwapBuffers() {
+ pending_begin_frames_--;
}
void Scheduler::DidLoseOutputSurface() {
@@ -117,31 +109,73 @@ void Scheduler::DidLoseOutputSurface() {
void Scheduler::DidCreateAndInitializeOutputSurface() {
TRACE_EVENT0("cc", "Scheduler::DidCreateAndInitializeOutputSurface");
- frame_rate_controller_->DidAbortAllPendingFrames();
state_machine_.DidCreateAndInitializeOutputSurface();
+ last_set_needs_begin_frame_ = false;
ProcessScheduledActions();
}
-void Scheduler::SetTimebaseAndInterval(base::TimeTicks timebase,
- base::TimeDelta interval) {
- frame_rate_controller_->SetTimebaseAndInterval(timebase, interval);
-}
-
base::TimeTicks Scheduler::AnticipatedDrawTime() {
- return frame_rate_controller_->NextTickTime();
+ TRACE_EVENT0("cc", "Scheduler::AnticipatedDrawTime");
+ base::TimeTicks now = base::TimeTicks::Now();
+ base::TimeTicks draw_time = last_begin_frame_time_;
+ while (draw_time < now) {
+ draw_time += interval_;
+ }
brianderson 2013/06/01 04:30:29 This is way hacky, but will be hard to improve unt
Sami 2013/06/03 17:30:33 Is this the only instance where we're requesting a
brianderson 2013/06/03 18:51:40 Later we'll want to request a new BeginFrame anyti
+
+ return draw_time;
}
base::TimeTicks Scheduler::LastBeginFrameOnImplThreadTime() {
- return frame_rate_controller_->LastTickTime();
+ return last_begin_frame_time_;
+}
+
+void Scheduler::SetNeedsBeginFrameIfNeeded() {
+ // 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.
+ bool needs_begin_frame = state_machine_.BeginFrameNeededByImplThread();
+ if ((needs_begin_frame ||
+ state_machine_.inside_begin_frame() ||
+ settings_.using_synchronous_renderer_compositor) &&
+ (needs_begin_frame != last_set_needs_begin_frame_)) {
brianderson 2013/06/01 04:30:29 I'll need someone working on the synchronous compo
+ client_->SetNeedsBeginFrameOnImplThread(needs_begin_frame);
+ last_set_needs_begin_frame_ = needs_begin_frame;
+ }
+
+ if (state_machine_.inside_begin_frame()) {
+ if (pending_begin_frames_ && !needs_begin_frame) {
+ // Balance out the unhandled BeginFrames with Swaps.
+ // TODO(brianderson): Replace this duplicate swap with a "SwapSkip".
brianderson 2013/06/01 04:30:29 I should move this into a function; it's duplicate
+ ScheduledActionDrawAndSwapResult result =
+ client_->ScheduledActionDrawAndSwapForced();
+ if (result.did_swap)
+ DidSwapBuffers();
+ }
+ if (pending_begin_frames_) {
+ // Self tick to retry a failed BeginFrame
+ // TODO(brianderson): Implement smarter polling when deadlines are added.
+ thread_->PostDelayedTask(
+ base::Bind(&Scheduler::BeginFrameRetry, weak_factory_.GetWeakPtr()),
+ interval_);
+ }
+ }
+}
+
+void Scheduler::BeginFrame(base::TimeTicks frame_time) {
+ TRACE_EVENT0("cc", "Scheduler::BeginFrame");
+ pending_begin_frames_++;
+ last_begin_frame_time_ = frame_time;
+ state_machine_.DidEnterBeginFrame();
+ ProcessScheduledActions();
+ state_machine_.DidLeaveBeginFrame();
}
-void Scheduler::BeginFrame(bool throttled) {
- TRACE_EVENT1("cc", "Scheduler::BeginFrame", "throttled", throttled);
- if (!throttled)
- state_machine_.DidEnterBeginFrame();
+void Scheduler::BeginFrameRetry() {
+ TRACE_EVENT0("cc", "Scheduler::BeginFrameRetry");
+ state_machine_.DidEnterBeginFrame();
ProcessScheduledActions();
- if (!throttled)
- state_machine_.DidLeaveBeginFrame();
+ state_machine_.DidLeaveBeginFrame();
}
void Scheduler::ProcessScheduledActions() {
@@ -155,8 +189,10 @@ void Scheduler::ProcessScheduledActions() {
SchedulerStateMachine::Action action = state_machine_.NextAction();
while (action != SchedulerStateMachine::ACTION_NONE) {
state_machine_.UpdateState(action);
- TRACE_EVENT1(
- "cc", "Scheduler::ProcessScheduledActions()", "action", action);
+ TRACE_EVENT2(
+ "cc", "Scheduler::ProcessScheduledActions()",
+ "action", action,
+ "state", state_machine_.ToString());
switch (action) {
case SchedulerStateMachine::ACTION_NONE:
@@ -178,14 +214,14 @@ void Scheduler::ProcessScheduledActions() {
client_->ScheduledActionDrawAndSwapIfPossible();
state_machine_.DidDrawIfPossibleCompleted(result.did_draw);
if (result.did_swap)
- frame_rate_controller_->DidSwapBuffers();
+ DidSwapBuffers();
break;
}
case SchedulerStateMachine::ACTION_DRAW_FORCED: {
ScheduledActionDrawAndSwapResult result =
client_->ScheduledActionDrawAndSwapForced();
if (result.did_swap)
- frame_rate_controller_->DidSwapBuffers();
+ DidSwapBuffers();
break;
}
case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION:
@@ -198,10 +234,8 @@ void Scheduler::ProcessScheduledActions() {
action = state_machine_.NextAction();
}
- // Activate or deactivate the frame rate controller.
- frame_rate_controller_->SetActive(
- state_machine_.BeginFrameNeededByImplThread());
- client_->DidAnticipatedDrawTimeChange(frame_rate_controller_->NextTickTime());
+ SetNeedsBeginFrameIfNeeded();
+ client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime());
}
bool Scheduler::WillDrawIfNeeded() const {

Powered by Google App Engine
This is Rietveld 408576698