Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/scheduler/frame_rate_controller.h" | 5 #include "cc/scheduler/frame_rate_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 BeginFrameArgs FrameRateController::SetActive(bool active) { | 69 BeginFrameArgs FrameRateController::SetActive(bool active) { |
| 70 if (active_ == active) | 70 if (active_ == active) |
| 71 return BeginFrameArgs(); | 71 return BeginFrameArgs(); |
| 72 TRACE_EVENT1("cc", "FrameRateController::SetActive", "active", active); | 72 TRACE_EVENT1("cc", "FrameRateController::SetActive", "active", active); |
| 73 active_ = active; | 73 active_ = active; |
| 74 | 74 |
| 75 if (is_time_source_throttling_) { | 75 if (is_time_source_throttling_) { |
| 76 base::TimeTicks missed_tick_time = time_source_->SetActive(active); | 76 base::TimeTicks missed_tick_time = time_source_->SetActive(active); |
| 77 if (!missed_tick_time.is_null()) { | 77 if (!missed_tick_time.is_null()) { |
| 78 base::TimeTicks deadline = NextTickTime(); | 78 base::TimeTicks deadline = NextTickTime(); |
| 79 return BeginFrameArgs::Create(missed_tick_time, | 79 BeginFrameArgs args = |
| 80 deadline, | 80 BeginFrameArgs::Create(missed_tick_time, deadline, interval_); |
| 81 interval_); | 81 args.deadline += deadline_adjustment_; |
|
danakj
2013/09/17 20:26:19
Is this covered by a unit test?
brianderson
2013/09/17 21:08:24
There are few ways to handle the first frame's dea
| |
| 82 return args; | |
| 82 } | 83 } |
| 83 } else { | 84 } else { |
| 84 if (active) | 85 if (active) |
| 85 PostManualTick(); | 86 PostManualTick(); |
| 86 else | 87 else |
| 87 weak_factory_.InvalidateWeakPtrs(); | 88 weak_factory_.InvalidateWeakPtrs(); |
| 88 } | 89 } |
| 89 | 90 |
| 90 return BeginFrameArgs(); | 91 return BeginFrameArgs(); |
| 91 } | 92 } |
| 92 | 93 |
| 93 void FrameRateController::SetMaxSwapsPending(int max_swaps_pending) { | 94 void FrameRateController::SetMaxSwapsPending(int max_swaps_pending) { |
| 94 DCHECK_GE(max_swaps_pending, 0); | 95 DCHECK_GE(max_swaps_pending, 0); |
| 95 max_swaps_pending_ = max_swaps_pending; | 96 max_swaps_pending_ = max_swaps_pending; |
| 96 } | 97 } |
| 97 | 98 |
| 98 void FrameRateController::SetTimebaseAndInterval(base::TimeTicks timebase, | 99 void FrameRateController::SetTimebaseAndInterval(base::TimeTicks timebase, |
| 99 base::TimeDelta interval) { | 100 base::TimeDelta interval) { |
| 100 interval_ = interval; | 101 interval_ = interval; |
| 101 if (is_time_source_throttling_) | 102 if (is_time_source_throttling_) |
| 102 time_source_->SetTimebaseAndInterval(timebase, interval); | 103 time_source_->SetTimebaseAndInterval(timebase, interval); |
| 103 } | 104 } |
| 104 | 105 |
| 105 void FrameRateController::SetDeadlineAdjustment(base::TimeDelta delta) { | 106 void FrameRateController::SetDeadlineAdjustment(base::TimeDelta delta) { |
|
danakj
2013/09/17 20:26:19
I find no callers of this function, is it just dea
brianderson
2013/09/17 21:08:24
It's called in OutputSurface::InitializeBeginFrame
| |
| 106 deadline_adjustment_ = delta; | 107 deadline_adjustment_ = delta; |
| 107 } | 108 } |
| 108 | 109 |
| 109 void FrameRateController::OnTimerTick() { | 110 void FrameRateController::OnTimerTick() { |
| 110 TRACE_EVENT0("cc", "FrameRateController::OnTimerTick"); | 111 TRACE_EVENT0("cc", "FrameRateController::OnTimerTick"); |
| 111 DCHECK(active_); | 112 DCHECK(active_); |
| 112 | 113 |
| 113 // Check if we have too many frames in flight. | 114 // Check if we have too many frames in flight. |
| 114 bool throttled = | 115 bool throttled = |
| 115 max_swaps_pending_ && num_frames_pending_ >= max_swaps_pending_; | 116 max_swaps_pending_ && num_frames_pending_ >= max_swaps_pending_; |
| 116 TRACE_COUNTER_ID1("cc", "ThrottledCompositor", task_runner_, throttled); | 117 TRACE_COUNTER_ID1("cc", "ThrottledCompositor", task_runner_, throttled); |
| 117 | 118 |
| 118 if (client_) { | 119 if (client_) { |
| 119 // TODO(brianderson): Use an adaptive parent compositor deadline. | 120 // TODO(brianderson): Use an adaptive parent compositor deadline. |
| 120 base::TimeTicks frame_time = LastTickTime(); | 121 base::TimeTicks frame_time = LastTickTime(); |
| 121 base::TimeTicks deadline = NextTickTime() + deadline_adjustment_; | 122 base::TimeTicks deadline = NextTickTime(); |
| 122 client_->FrameRateControllerTick( | 123 BeginFrameArgs args = |
| 123 throttled, | 124 BeginFrameArgs::Create(frame_time, deadline, interval_); |
| 124 BeginFrameArgs::Create(frame_time, deadline, interval_)); | 125 args.deadline += deadline_adjustment_; |
|
danakj
2013/09/17 20:26:19
why adjust the deadline after instead of just pass
brianderson
2013/09/17 21:08:24
I used to have an AdjustDeadline method that would
| |
| 126 client_->FrameRateControllerTick(throttled, args); | |
| 125 } | 127 } |
| 126 | 128 |
| 127 if (!is_time_source_throttling_ && !throttled) | 129 if (!is_time_source_throttling_ && !throttled) |
| 128 PostManualTick(); | 130 PostManualTick(); |
| 129 } | 131 } |
| 130 | 132 |
| 131 void FrameRateController::PostManualTick() { | 133 void FrameRateController::PostManualTick() { |
| 132 if (active_) { | 134 if (active_) { |
| 133 task_runner_->PostTask(FROM_HERE, | 135 task_runner_->PostTask(FROM_HERE, |
| 134 base::Bind(&FrameRateController::ManualTick, | 136 base::Bind(&FrameRateController::ManualTick, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 163 } | 165 } |
| 164 | 166 |
| 165 base::TimeTicks FrameRateController::LastTickTime() { | 167 base::TimeTicks FrameRateController::LastTickTime() { |
| 166 if (is_time_source_throttling_) | 168 if (is_time_source_throttling_) |
| 167 return time_source_->LastTickTime(); | 169 return time_source_->LastTickTime(); |
| 168 | 170 |
| 169 return base::TimeTicks::Now(); | 171 return base::TimeTicks::Now(); |
| 170 } | 172 } |
| 171 | 173 |
| 172 } // namespace cc | 174 } // namespace cc |
| OLD | NEW |