OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/gl/sync_control_vsync_provider.h" | 5 #include "ui/gl/sync_control_vsync_provider.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 | 11 |
12 #if defined(OS_LINUX) | 12 #if defined(OS_LINUX) |
13 // These constants define a reasonable range for a calculated refresh interval. | |
14 // Calculating refreshes out of this range will be considered a fatal error. | |
15 const int64 kMinVsyncIntervalUs = base::Time::kMicrosecondsPerSecond / 400; | |
16 const int64 kMaxVsyncIntervalUs = base::Time::kMicrosecondsPerSecond / 10; | |
17 | |
18 // How much noise we'll tolerate between successive computed intervals before | 13 // How much noise we'll tolerate between successive computed intervals before |
19 // we think the latest computed interval is invalid (noisey due to | 14 // we think the latest computed interval is invalid (noisey due to |
20 // monitor configuration change, moving a window between monitors, etc.). | 15 // monitor configuration change, moving a window between monitors, etc.). |
21 const double kRelativeIntervalDifferenceThreshold = 0.05; | 16 const double kRelativeIntervalDifferenceThreshold = 0.05; |
22 #endif | 17 #endif |
23 | 18 |
24 namespace gfx { | 19 namespace gfx { |
25 | 20 |
26 SyncControlVSyncProvider::SyncControlVSyncProvider() | 21 SyncControlVSyncProvider::SyncControlVSyncProvider() |
27 : VSyncProvider(), last_media_stream_counter_(0), invalid_msc_(false) { | 22 : VSyncProvider(), last_media_stream_counter_(0), invalid_msc_(false) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 last_computed_intervals_.push(timebase_diff / counter_diff); | 110 last_computed_intervals_.push(timebase_diff / counter_diff); |
116 } | 111 } |
117 | 112 |
118 if (last_computed_intervals_.size() == 2) { | 113 if (last_computed_intervals_.size() == 2) { |
119 const base::TimeDelta& old_interval = last_computed_intervals_.front(); | 114 const base::TimeDelta& old_interval = last_computed_intervals_.front(); |
120 const base::TimeDelta& new_interval = last_computed_intervals_.back(); | 115 const base::TimeDelta& new_interval = last_computed_intervals_.back(); |
121 | 116 |
122 double relative_change = | 117 double relative_change = |
123 fabs(old_interval.InMillisecondsF() - new_interval.InMillisecondsF()) / | 118 fabs(old_interval.InMillisecondsF() - new_interval.InMillisecondsF()) / |
124 new_interval.InMillisecondsF(); | 119 new_interval.InMillisecondsF(); |
125 if (relative_change < kRelativeIntervalDifferenceThreshold) { | 120 if (relative_change < kRelativeIntervalDifferenceThreshold) |
126 if (new_interval.InMicroseconds() < kMinVsyncIntervalUs || | 121 last_good_interval_ = new_interval; |
piman
2014/02/04 04:51:01
I'd rather we either leave the LOG(FATAL) here, or
sheu
2014/02/04 22:01:45
We can't leave the LOG(FATAL) here -- that is the
| |
127 new_interval.InMicroseconds() > kMaxVsyncIntervalUs) { | |
128 LOG(FATAL) << "Calculated bogus refresh interval of " | |
129 << new_interval.InMicroseconds() << " us. " | |
130 << "Last time base of " << last_timebase_.ToInternalValue() | |
131 << " us. " | |
132 << "Current time base of " << timebase.ToInternalValue() | |
133 << " us. " | |
134 << "Last media stream count of " | |
135 << last_media_stream_counter_ << ". " | |
136 << "Current media stream count of " << media_stream_counter | |
137 << "."; | |
138 } else { | |
139 last_good_interval_ = new_interval; | |
140 } | |
141 } | |
142 } | 122 } |
143 | 123 |
144 last_timebase_ = timebase; | 124 last_timebase_ = timebase; |
145 last_media_stream_counter_ = media_stream_counter; | 125 last_media_stream_counter_ = media_stream_counter; |
146 callback.Run(timebase, last_good_interval_); | 126 callback.Run(timebase, last_good_interval_); |
147 #endif // defined(OS_LINUX) | 127 #endif // defined(OS_LINUX) |
148 } | 128 } |
149 | 129 |
150 } // namespace gfx | 130 } // namespace gfx |
OLD | NEW |