| OLD | NEW |
| (Empty) |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/scheduler/frame_rate_controller.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/debug/trace_event.h" | |
| 9 #include "base/location.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "base/single_thread_task_runner.h" | |
| 12 #include "cc/scheduler/delay_based_time_source.h" | |
| 13 #include "cc/scheduler/time_source.h" | |
| 14 #include "ui/gfx/frame_time.h" | |
| 15 | |
| 16 namespace cc { | |
| 17 | |
| 18 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) | |
| 19 : client_(NULL), | |
| 20 interval_(BeginFrameArgs::DefaultInterval()), | |
| 21 time_source_(timer), | |
| 22 active_(false) { | |
| 23 time_source_->SetClient(this); | |
| 24 } | |
| 25 | |
| 26 FrameRateController::~FrameRateController() { time_source_->SetActive(false); } | |
| 27 | |
| 28 BeginFrameArgs FrameRateController::SetActive(bool active) { | |
| 29 if (active_ == active) | |
| 30 return BeginFrameArgs(); | |
| 31 TRACE_EVENT1("cc", "FrameRateController::SetActive", "active", active); | |
| 32 active_ = active; | |
| 33 | |
| 34 base::TimeTicks missed_tick_time = time_source_->SetActive(active); | |
| 35 if (!missed_tick_time.is_null()) { | |
| 36 base::TimeTicks deadline = NextTickTime(); | |
| 37 return BeginFrameArgs::Create( | |
| 38 missed_tick_time, deadline + deadline_adjustment_, interval_); | |
| 39 } | |
| 40 | |
| 41 return BeginFrameArgs(); | |
| 42 } | |
| 43 | |
| 44 void FrameRateController::SetTimebaseAndInterval(base::TimeTicks timebase, | |
| 45 base::TimeDelta interval) { | |
| 46 interval_ = interval; | |
| 47 time_source_->SetTimebaseAndInterval(timebase, interval); | |
| 48 } | |
| 49 | |
| 50 void FrameRateController::SetDeadlineAdjustment(base::TimeDelta delta) { | |
| 51 deadline_adjustment_ = delta; | |
| 52 } | |
| 53 | |
| 54 void FrameRateController::OnTimerTick() { | |
| 55 TRACE_EVENT0("cc", "FrameRateController::OnTimerTick"); | |
| 56 DCHECK(active_); | |
| 57 | |
| 58 if (client_) { | |
| 59 // TODO(brianderson): Use an adaptive parent compositor deadline. | |
| 60 base::TimeTicks frame_time = LastTickTime(); | |
| 61 base::TimeTicks deadline = NextTickTime(); | |
| 62 BeginFrameArgs args = BeginFrameArgs::Create( | |
| 63 frame_time, deadline + deadline_adjustment_, interval_); | |
| 64 client_->FrameRateControllerTick(args); | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 base::TimeTicks FrameRateController::NextTickTime() { | |
| 69 return time_source_->NextTickTime(); | |
| 70 } | |
| 71 | |
| 72 base::TimeTicks FrameRateController::LastTickTime() { | |
| 73 return time_source_->LastTickTime(); | |
| 74 } | |
| 75 | |
| 76 } // namespace cc | |
| OLD | NEW |