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

Side by Side Diff: ui/gl/sync_control_vsync_provider.cc

Issue 1545113002: Switch to standard integer types in ui/gl/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 unified diff | Download patch
« no previous file with comments | « ui/gl/sync_control_vsync_provider.h ('k') | ui/gl/test/gl_image_test_support.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "build/build_config.h"
12 13
13 #if defined(OS_LINUX) 14 #if defined(OS_LINUX)
14 // These constants define a reasonable range for a calculated refresh interval. 15 // These constants define a reasonable range for a calculated refresh interval.
15 // Calculating refreshes out of this range will be considered a fatal error. 16 // Calculating refreshes out of this range will be considered a fatal error.
16 const int64 kMinVsyncIntervalUs = base::Time::kMicrosecondsPerSecond / 400; 17 const int64_t kMinVsyncIntervalUs = base::Time::kMicrosecondsPerSecond / 400;
17 const int64 kMaxVsyncIntervalUs = base::Time::kMicrosecondsPerSecond / 10; 18 const int64_t kMaxVsyncIntervalUs = base::Time::kMicrosecondsPerSecond / 10;
18 19
19 // How much noise we'll tolerate between successive computed intervals before 20 // How much noise we'll tolerate between successive computed intervals before
20 // we think the latest computed interval is invalid (noisey due to 21 // we think the latest computed interval is invalid (noisey due to
21 // monitor configuration change, moving a window between monitors, etc.). 22 // monitor configuration change, moving a window between monitors, etc.).
22 const double kRelativeIntervalDifferenceThreshold = 0.05; 23 const double kRelativeIntervalDifferenceThreshold = 0.05;
23 #endif 24 #endif
24 25
25 namespace gfx { 26 namespace gfx {
26 27
27 SyncControlVSyncProvider::SyncControlVSyncProvider() 28 SyncControlVSyncProvider::SyncControlVSyncProvider()
(...skipping 12 matching lines...) Expand all
40 #if defined(OS_LINUX) 41 #if defined(OS_LINUX)
41 base::TimeTicks timebase; 42 base::TimeTicks timebase;
42 43
43 // The actual clock used for the system time returned by glXGetSyncValuesOML 44 // The actual clock used for the system time returned by glXGetSyncValuesOML
44 // is unspecified. In practice, the clock used is likely to be either 45 // is unspecified. In practice, the clock used is likely to be either
45 // CLOCK_REALTIME or CLOCK_MONOTONIC, so we compare the returned time to the 46 // CLOCK_REALTIME or CLOCK_MONOTONIC, so we compare the returned time to the
46 // current time according to both clocks, and assume that the returned time 47 // current time according to both clocks, and assume that the returned time
47 // was produced by the clock whose current time is closest to it, subject 48 // was produced by the clock whose current time is closest to it, subject
48 // to the restriction that the returned time must not be in the future 49 // to the restriction that the returned time must not be in the future
49 // (since it is the time of a vblank that has already occurred). 50 // (since it is the time of a vblank that has already occurred).
50 int64 system_time; 51 int64_t system_time;
51 int64 media_stream_counter; 52 int64_t media_stream_counter;
52 int64 swap_buffer_counter; 53 int64_t swap_buffer_counter;
53 if (!GetSyncValues(&system_time, &media_stream_counter, &swap_buffer_counter)) 54 if (!GetSyncValues(&system_time, &media_stream_counter, &swap_buffer_counter))
54 return; 55 return;
55 56
56 // Both Intel and Mali drivers will return TRUE for GetSyncValues 57 // Both Intel and Mali drivers will return TRUE for GetSyncValues
57 // but a value of 0 for MSC if they cannot access the CRTC data structure 58 // but a value of 0 for MSC if they cannot access the CRTC data structure
58 // associated with the surface. crbug.com/231945 59 // associated with the surface. crbug.com/231945
59 bool prev_invalid_msc = invalid_msc_; 60 bool prev_invalid_msc = invalid_msc_;
60 invalid_msc_ = (media_stream_counter == 0); 61 invalid_msc_ = (media_stream_counter == 0);
61 if (invalid_msc_) { 62 if (invalid_msc_) {
62 LOG_IF(ERROR, !prev_invalid_msc) << "glXGetSyncValuesOML " 63 LOG_IF(ERROR, !prev_invalid_msc) << "glXGetSyncValuesOML "
63 "should not return TRUE with a media stream counter of 0."; 64 "should not return TRUE with a media stream counter of 0.";
64 return; 65 return;
65 } 66 }
66 67
67 struct timespec real_time; 68 struct timespec real_time;
68 struct timespec monotonic_time; 69 struct timespec monotonic_time;
69 clock_gettime(CLOCK_REALTIME, &real_time); 70 clock_gettime(CLOCK_REALTIME, &real_time);
70 clock_gettime(CLOCK_MONOTONIC, &monotonic_time); 71 clock_gettime(CLOCK_MONOTONIC, &monotonic_time);
71 72
72 int64 real_time_in_microseconds = 73 int64_t real_time_in_microseconds =
73 real_time.tv_sec * base::Time::kMicrosecondsPerSecond + 74 real_time.tv_sec * base::Time::kMicrosecondsPerSecond +
74 real_time.tv_nsec / base::Time::kNanosecondsPerMicrosecond; 75 real_time.tv_nsec / base::Time::kNanosecondsPerMicrosecond;
75 int64 monotonic_time_in_microseconds = 76 int64_t monotonic_time_in_microseconds =
76 monotonic_time.tv_sec * base::Time::kMicrosecondsPerSecond + 77 monotonic_time.tv_sec * base::Time::kMicrosecondsPerSecond +
77 monotonic_time.tv_nsec / base::Time::kNanosecondsPerMicrosecond; 78 monotonic_time.tv_nsec / base::Time::kNanosecondsPerMicrosecond;
78 79
79 // We need the time according to CLOCK_MONOTONIC, so if we've been given 80 // We need the time according to CLOCK_MONOTONIC, so if we've been given
80 // a time from CLOCK_REALTIME, we need to convert. 81 // a time from CLOCK_REALTIME, we need to convert.
81 bool time_conversion_needed = 82 bool time_conversion_needed =
82 llabs(system_time - real_time_in_microseconds) < 83 llabs(system_time - real_time_in_microseconds) <
83 llabs(system_time - monotonic_time_in_microseconds); 84 llabs(system_time - monotonic_time_in_microseconds);
84 85
85 if (time_conversion_needed) 86 if (time_conversion_needed)
86 system_time += monotonic_time_in_microseconds - real_time_in_microseconds; 87 system_time += monotonic_time_in_microseconds - real_time_in_microseconds;
87 88
88 // Return if |system_time| is more than 1 frames in the future. 89 // Return if |system_time| is more than 1 frames in the future.
89 int64 interval_in_microseconds = last_good_interval_.InMicroseconds(); 90 int64_t interval_in_microseconds = last_good_interval_.InMicroseconds();
90 if (system_time > monotonic_time_in_microseconds + interval_in_microseconds) 91 if (system_time > monotonic_time_in_microseconds + interval_in_microseconds)
91 return; 92 return;
92 93
93 // If |system_time| is slightly in the future, adjust it to the previous 94 // If |system_time| is slightly in the future, adjust it to the previous
94 // frame and use the last frame counter to prevent issues in the callback. 95 // frame and use the last frame counter to prevent issues in the callback.
95 if (system_time > monotonic_time_in_microseconds) { 96 if (system_time > monotonic_time_in_microseconds) {
96 system_time -= interval_in_microseconds; 97 system_time -= interval_in_microseconds;
97 media_stream_counter--; 98 media_stream_counter--;
98 } 99 }
99 if (monotonic_time_in_microseconds - system_time > 100 if (monotonic_time_in_microseconds - system_time >
100 base::Time::kMicrosecondsPerSecond) 101 base::Time::kMicrosecondsPerSecond)
101 return; 102 return;
102 103
103 timebase = base::TimeTicks::FromInternalValue(system_time); 104 timebase = base::TimeTicks::FromInternalValue(system_time);
104 105
105 // Only need the previous calculated interval for our filtering. 106 // Only need the previous calculated interval for our filtering.
106 while (last_computed_intervals_.size() > 1) 107 while (last_computed_intervals_.size() > 1)
107 last_computed_intervals_.pop(); 108 last_computed_intervals_.pop();
108 109
109 int32 numerator, denominator; 110 int32_t numerator, denominator;
110 if (GetMscRate(&numerator, &denominator)) { 111 if (GetMscRate(&numerator, &denominator)) {
111 last_computed_intervals_.push(base::TimeDelta::FromSeconds(denominator) / 112 last_computed_intervals_.push(base::TimeDelta::FromSeconds(denominator) /
112 numerator); 113 numerator);
113 } else if (!last_timebase_.is_null()) { 114 } else if (!last_timebase_.is_null()) {
114 base::TimeDelta timebase_diff = timebase - last_timebase_; 115 base::TimeDelta timebase_diff = timebase - last_timebase_;
115 int64 counter_diff = media_stream_counter - last_media_stream_counter_; 116 int64_t counter_diff = media_stream_counter - last_media_stream_counter_;
116 if (counter_diff > 0 && timebase > last_timebase_) 117 if (counter_diff > 0 && timebase > last_timebase_)
117 last_computed_intervals_.push(timebase_diff / counter_diff); 118 last_computed_intervals_.push(timebase_diff / counter_diff);
118 } 119 }
119 120
120 if (last_computed_intervals_.size() == 2) { 121 if (last_computed_intervals_.size() == 2) {
121 const base::TimeDelta& old_interval = last_computed_intervals_.front(); 122 const base::TimeDelta& old_interval = last_computed_intervals_.front();
122 const base::TimeDelta& new_interval = last_computed_intervals_.back(); 123 const base::TimeDelta& new_interval = last_computed_intervals_.back();
123 124
124 double relative_change = 125 double relative_change =
125 fabs(old_interval.InMillisecondsF() - new_interval.InMillisecondsF()) / 126 fabs(old_interval.InMillisecondsF() - new_interval.InMillisecondsF()) /
(...skipping 24 matching lines...) Expand all
150 } 151 }
151 } 152 }
152 153
153 last_timebase_ = timebase; 154 last_timebase_ = timebase;
154 last_media_stream_counter_ = media_stream_counter; 155 last_media_stream_counter_ = media_stream_counter;
155 callback.Run(timebase, last_good_interval_); 156 callback.Run(timebase, last_good_interval_);
156 #endif // defined(OS_LINUX) 157 #endif // defined(OS_LINUX)
157 } 158 }
158 159
159 } // namespace gfx 160 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/sync_control_vsync_provider.h ('k') | ui/gl/test/gl_image_test_support.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698