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. | 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. | 14 // Calculating refreshes out of this range will be considered a fatal error. |
15 const int64 kMinVsyncIntervalUs = base::Time::kMicrosecondsPerSecond / 400; | 15 const int64 kMinVsyncIntervalUs = base::Time::kMicrosecondsPerSecond / 400; |
16 const int64 kMaxVsyncIntervalUs = base::Time::kMicrosecondsPerSecond / 10; | 16 const int64 kMaxVsyncIntervalUs = base::Time::kMicrosecondsPerSecond / 10; |
17 | 17 |
18 // How much noise we'll tolerate between successive computed intervals before | 18 // How much noise we'll tolerate between successive computed intervals before |
19 // we think the latest computed interval is invalid (noisey due to | 19 // we think the latest computed interval is invalid (noisey due to |
20 // monitor configuration change, moving a window between monitors, etc.). | 20 // monitor configuration change, moving a window between monitors, etc.). |
21 const double kRelativeIntervalDifferenceThreshold = 0.05; | 21 const double kRelativeIntervalDifferenceThreshold = 0.05; |
22 #endif | 22 #endif |
23 | 23 |
24 namespace gfx { | 24 namespace gfx { |
25 | 25 |
26 SyncControlVSyncProvider::SyncControlVSyncProvider() | 26 SyncControlVSyncProvider::SyncControlVSyncProvider() |
27 : VSyncProvider(), last_media_stream_counter_(0) { | 27 : VSyncProvider(), last_media_stream_counter_(0), invalid_msc_(false) { |
28 // On platforms where we can't get an accurate reading on the refresh | 28 // On platforms where we can't get an accurate reading on the refresh |
29 // rate we fall back to the assumption that we're displaying 60 frames | 29 // rate we fall back to the assumption that we're displaying 60 frames |
30 // per second. | 30 // per second. |
31 last_good_interval_ = base::TimeDelta::FromSeconds(1) / 60; | 31 last_good_interval_ = base::TimeDelta::FromSeconds(1) / 60; |
32 } | 32 } |
33 | 33 |
34 SyncControlVSyncProvider::~SyncControlVSyncProvider() {} | 34 SyncControlVSyncProvider::~SyncControlVSyncProvider() {} |
35 | 35 |
36 void SyncControlVSyncProvider::GetVSyncParameters( | 36 void SyncControlVSyncProvider::GetVSyncParameters( |
37 const UpdateVSyncCallback& callback) { | 37 const UpdateVSyncCallback& callback) { |
38 #if defined(OS_LINUX) | 38 #if defined(OS_LINUX) |
39 base::TimeTicks timebase; | 39 base::TimeTicks timebase; |
40 | 40 |
41 // The actual clock used for the system time returned by glXGetSyncValuesOML | 41 // The actual clock used for the system time returned by glXGetSyncValuesOML |
42 // is unspecified. In practice, the clock used is likely to be either | 42 // is unspecified. In practice, the clock used is likely to be either |
43 // CLOCK_REALTIME or CLOCK_MONOTONIC, so we compare the returned time to the | 43 // CLOCK_REALTIME or CLOCK_MONOTONIC, so we compare the returned time to the |
44 // current time according to both clocks, and assume that the returned time | 44 // current time according to both clocks, and assume that the returned time |
45 // was produced by the clock whose current time is closest to it, subject | 45 // was produced by the clock whose current time is closest to it, subject |
46 // to the restriction that the returned time must not be in the future | 46 // to the restriction that the returned time must not be in the future |
47 // (since it is the time of a vblank that has already occurred). | 47 // (since it is the time of a vblank that has already occurred). |
48 int64 system_time; | 48 int64 system_time; |
49 int64 media_stream_counter; | 49 int64 media_stream_counter; |
50 int64 swap_buffer_counter; | 50 int64 swap_buffer_counter; |
51 if (!GetSyncValues(&system_time, &media_stream_counter, &swap_buffer_counter)) | 51 if (!GetSyncValues(&system_time, &media_stream_counter, &swap_buffer_counter)) |
52 return; | 52 return; |
53 | 53 |
54 // Both Intel and Mali drivers will return TRUE for GetSyncValues | 54 // Both Intel and Mali drivers will return TRUE for GetSyncValues |
55 // but a value of 0 for MSC if they cannot access the CRTC data structure | 55 // but a value of 0 for MSC if they cannot access the CRTC data structure |
56 // associated with the surface. crbug.com/231945 | 56 // associated with the surface. crbug.com/231945 |
57 if (media_stream_counter == 0) { | 57 bool prev_invalid_msc = invalid_msc_; |
58 LOG(ERROR) << "glXGetSyncValuesOML should not return TRUE with a " | 58 invalid_msc_ = (media_stream_counter == 0); |
59 << "media stream counter of 0."; | 59 if (invalid_msc_) { |
| 60 LOG_IF(ERROR, !prev_invalid_msc) << "glXGetSyncValuesOML " |
| 61 "should not return TRUE with a media stream counter of 0."; |
60 return; | 62 return; |
61 } | 63 } |
62 | 64 |
63 struct timespec real_time; | 65 struct timespec real_time; |
64 struct timespec monotonic_time; | 66 struct timespec monotonic_time; |
65 clock_gettime(CLOCK_REALTIME, &real_time); | 67 clock_gettime(CLOCK_REALTIME, &real_time); |
66 clock_gettime(CLOCK_MONOTONIC, &monotonic_time); | 68 clock_gettime(CLOCK_MONOTONIC, &monotonic_time); |
67 | 69 |
68 int64 real_time_in_microseconds = | 70 int64 real_time_in_microseconds = |
69 real_time.tv_sec * base::Time::kMicrosecondsPerSecond + | 71 real_time.tv_sec * base::Time::kMicrosecondsPerSecond + |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 } | 141 } |
140 } | 142 } |
141 | 143 |
142 last_timebase_ = timebase; | 144 last_timebase_ = timebase; |
143 last_media_stream_counter_ = media_stream_counter; | 145 last_media_stream_counter_ = media_stream_counter; |
144 callback.Run(timebase, last_good_interval_); | 146 callback.Run(timebase, last_good_interval_); |
145 #endif // defined(OS_LINUX) | 147 #endif // defined(OS_LINUX) |
146 } | 148 } |
147 | 149 |
148 } // namespace gfx | 150 } // namespace gfx |
OLD | NEW |