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

Unified Diff: cc/scheduler/frame_rate_controller.cc

Issue 199523002: cc: Throttle swaps in Scheduler instead of OutputSurface (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: WIP: pulling FRC out of OS Created 6 years, 9 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/frame_rate_controller.cc
diff --git a/cc/scheduler/frame_rate_controller.cc b/cc/scheduler/frame_rate_controller.cc
index 243ef6b62918a1f4b753e24cf70e93d4ac3050dc..1e9e78150b84aa059dde93fac6bfc2057e3746f6 100644
--- a/cc/scheduler/frame_rate_controller.cc
+++ b/cc/scheduler/frame_rate_controller.cc
@@ -15,164 +15,64 @@
namespace cc {
-class FrameRateControllerTimeSourceAdapter : public TimeSourceClient {
- public:
- static scoped_ptr<FrameRateControllerTimeSourceAdapter> Create(
- FrameRateController* frame_rate_controller) {
- return make_scoped_ptr(
- new FrameRateControllerTimeSourceAdapter(frame_rate_controller));
- }
- virtual ~FrameRateControllerTimeSourceAdapter() {}
-
- virtual void OnTimerTick() OVERRIDE {
- frame_rate_controller_->OnTimerTick();
- }
-
- private:
- explicit FrameRateControllerTimeSourceAdapter(
- FrameRateController* frame_rate_controller)
- : frame_rate_controller_(frame_rate_controller) {}
-
- FrameRateController* frame_rate_controller_;
-};
-
-FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer)
- : client_(NULL),
- num_frames_pending_(0),
- max_swaps_pending_(0),
- interval_(BeginFrameArgs::DefaultInterval()),
- time_source_(timer),
- active_(false),
- is_time_source_throttling_(true),
- manual_tick_pending_(false),
- task_runner_(NULL),
- weak_factory_(this) {
- time_source_client_adapter_ =
- FrameRateControllerTimeSourceAdapter::Create(this);
- time_source_->SetClient(time_source_client_adapter_.get());
+BeginFrameSource::BeginFrameSource(base::TimeDelta interval,
+ base::SingleThreadTaskRunner* task_runner)
+ : client_(NULL), interval_(interval), active_(false) {
+ if (gfx::FrameTime::TimestampsAreHighRes())
+ time_source_ = DelayBasedTimeSourceHighRes::Create(interval, task_runner);
+ else
+ time_source_ = DelayBasedTimeSource::Create(interval, task_runner);
+ time_source_->SetClient(this);
}
-FrameRateController::FrameRateController(
- base::SingleThreadTaskRunner* task_runner)
- : client_(NULL),
- num_frames_pending_(0),
- max_swaps_pending_(0),
- interval_(BeginFrameArgs::DefaultInterval()),
- active_(false),
- is_time_source_throttling_(false),
- manual_tick_pending_(false),
- task_runner_(task_runner),
- weak_factory_(this) {}
+BeginFrameSource::~BeginFrameSource() { time_source_->SetActive(false); }
-FrameRateController::~FrameRateController() {
- if (is_time_source_throttling_)
- time_source_->SetActive(false);
-}
-
-BeginFrameArgs FrameRateController::SetActive(bool active) {
+BeginFrameArgs BeginFrameSource::SetActive(bool active) {
if (active_ == active)
return BeginFrameArgs();
- TRACE_EVENT1("cc", "FrameRateController::SetActive", "active", active);
+ TRACE_EVENT1("cc", "BeginFrameSource::SetActive", "active", active);
active_ = active;
- if (is_time_source_throttling_) {
- base::TimeTicks missed_tick_time = time_source_->SetActive(active);
- if (!missed_tick_time.is_null()) {
- base::TimeTicks deadline = NextTickTime();
- return BeginFrameArgs::Create(
- missed_tick_time, deadline + deadline_adjustment_, interval_);
- }
- } else {
- if (active) {
- PostManualTick();
- } else {
- weak_factory_.InvalidateWeakPtrs();
- manual_tick_pending_ = false;
- }
+ base::TimeTicks missed_tick_time = time_source_->SetActive(active);
+ if (!missed_tick_time.is_null()) {
+ base::TimeTicks deadline = NextTickTime();
+ return BeginFrameArgs::Create(
+ missed_tick_time, deadline + deadline_adjustment_, interval_);
}
return BeginFrameArgs();
}
-void FrameRateController::SetMaxSwapsPending(int max_swaps_pending) {
- DCHECK_GE(max_swaps_pending, 0);
- max_swaps_pending_ = max_swaps_pending;
-}
-
-void FrameRateController::SetTimebaseAndInterval(base::TimeTicks timebase,
- base::TimeDelta interval) {
+void BeginFrameSource::SetTimebaseAndInterval(base::TimeTicks timebase,
+ base::TimeDelta interval) {
interval_ = interval;
- if (is_time_source_throttling_)
- time_source_->SetTimebaseAndInterval(timebase, interval);
+ time_source_->SetTimebaseAndInterval(timebase, interval);
}
-void FrameRateController::SetDeadlineAdjustment(base::TimeDelta delta) {
+void BeginFrameSource::SetDeadlineAdjustment(base::TimeDelta delta) {
deadline_adjustment_ = delta;
}
-void FrameRateController::OnTimerTick() {
- TRACE_EVENT0("cc", "FrameRateController::OnTimerTick");
+void BeginFrameSource::OnTimerTick() {
+ TRACE_EVENT0("cc", "BeginFrameSource::OnTimerTick");
DCHECK(active_);
- // Check if we have too many frames in flight.
- bool throttled =
- max_swaps_pending_ && num_frames_pending_ >= max_swaps_pending_;
- TRACE_COUNTER_ID1("cc", "ThrottledCompositor", task_runner_, throttled);
-
if (client_) {
// TODO(brianderson): Use an adaptive parent compositor deadline.
base::TimeTicks frame_time = LastTickTime();
base::TimeTicks deadline = NextTickTime();
BeginFrameArgs args = BeginFrameArgs::Create(
frame_time, deadline + deadline_adjustment_, interval_);
- client_->FrameRateControllerTick(throttled, args);
- }
-
- if (!is_time_source_throttling_ && !throttled)
- PostManualTick();
-}
-
-void FrameRateController::PostManualTick() {
- if (active_ && !manual_tick_pending_) {
- manual_tick_pending_ = true;
- task_runner_->PostTask(FROM_HERE,
- base::Bind(&FrameRateController::ManualTick,
- weak_factory_.GetWeakPtr()));
+ client_->BeginImplFrame(args);
}
}
-void FrameRateController::ManualTick() {
- manual_tick_pending_ = false;
- OnTimerTick();
-}
-
-void FrameRateController::DidSwapBuffers() {
- num_frames_pending_++;
-}
-
-void FrameRateController::DidSwapBuffersComplete() {
- DCHECK_GT(num_frames_pending_, 0);
- num_frames_pending_--;
- if (!is_time_source_throttling_)
- PostManualTick();
+base::TimeTicks BeginFrameSource::NextTickTime() {
+ return time_source_->NextTickTime();
}
-void FrameRateController::DidAbortAllPendingFrames() {
- num_frames_pending_ = 0;
-}
-
-base::TimeTicks FrameRateController::NextTickTime() {
- if (is_time_source_throttling_)
- return time_source_->NextTickTime();
-
- return base::TimeTicks();
-}
-
-base::TimeTicks FrameRateController::LastTickTime() {
- if (is_time_source_throttling_)
- return time_source_->LastTickTime();
-
- return gfx::FrameTime::Now();
+base::TimeTicks BeginFrameSource::LastTickTime() {
+ return time_source_->LastTickTime();
}
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698