OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/gl_surface.h" | 5 #include "ui/gl/gl_surface.h" |
6 | 6 |
7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.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 bool dwm_active = false; | 69 bool dwm_active = false; |
70 | 70 |
71 // Query the DWM timing info first if available. This will provide the most | 71 // Query the DWM timing info first if available. This will provide the most |
72 // precise values. | 72 // precise values. |
73 if (use_dwm_) { | 73 if (use_dwm_) { |
74 DWM_TIMING_INFO timing_info; | 74 DWM_TIMING_INFO timing_info; |
75 timing_info.cbSize = sizeof(timing_info); | 75 timing_info.cbSize = sizeof(timing_info); |
76 HRESULT result = DwmGetCompositionTimingInfo(NULL, &timing_info); | 76 HRESULT result = DwmGetCompositionTimingInfo(NULL, &timing_info); |
77 if (result == S_OK) { | 77 if (result == S_OK) { |
78 dwm_active = true; | 78 dwm_active = true; |
79 | |
80 // Calculate a backup interval value using the rateRefresh numerator and | |
81 // denominator. | |
82 base::TimeDelta interval2; | |
jbauman
2015/05/14 22:42:39
Nit, maybe call this "backup_interval".
brucedawson
2015/05/14 22:51:57
How about 'rate_interval'. That gives more of a re
sunnyps
2015/05/14 23:05:14
I don't care much about the name but I like low_re
| |
83 if (timing_info.rateRefresh.uiDenominator > 0 && | |
84 timing_info.rateRefresh.uiNumerator > 0) { | |
85 // Swap the numerator/denominator to convert frequency to period. | |
86 interval2 = base::TimeDelta::FromMicroseconds( | |
87 timing_info.rateRefresh.uiDenominator * | |
88 base::Time::kMicrosecondsPerSecond / | |
89 timing_info.rateRefresh.uiNumerator); | |
90 } | |
91 | |
79 if (gfx::FrameTime::TimestampsAreHighRes()) { | 92 if (gfx::FrameTime::TimestampsAreHighRes()) { |
80 // qpcRefreshPeriod is very accurate but noisy, and must be used with | 93 // qpcRefreshPeriod is very accurate but noisy, and must be used with |
81 // a high resolution timebase to avoid frequently missing Vsync. | 94 // a high resolution timebase to avoid frequently missing Vsync. |
82 timebase = gfx::FrameTime::FromQPCValue( | 95 timebase = gfx::FrameTime::FromQPCValue( |
83 static_cast<LONGLONG>(timing_info.qpcVBlank)); | 96 static_cast<LONGLONG>(timing_info.qpcVBlank)); |
84 interval = base::TimeDelta::FromQPCValue( | 97 interval = base::TimeDelta::FromQPCValue( |
85 static_cast<LONGLONG>(timing_info.qpcRefreshPeriod)); | 98 static_cast<LONGLONG>(timing_info.qpcRefreshPeriod)); |
86 } else if (timing_info.rateRefresh.uiDenominator > 0 && | 99 // Check for interval values that are impossibly low. A 29 microsecond |
87 timing_info.rateRefresh.uiNumerator > 0) { | 100 // interval was seen (from a qpcRefreshPeriod of 60). |
101 if (interval < base::TimeDelta::FromMilliseconds(1)) { | |
102 interval = interval2; | |
103 } | |
104 // Check for the qpcRefreshPeriod interval being improbably small | |
105 // compared to the rateRefresh calculated interval, as another | |
106 // attempt at detecting driver bugs. | |
107 if (!interval2.is_zero() && interval < interval2 / 2) { | |
108 interval = interval2; | |
109 } | |
110 } else { | |
88 // If FrameTime is not high resolution, we do not want to translate | 111 // If FrameTime is not high resolution, we do not want to translate |
89 // the QPC value provided by DWM into the low-resolution timebase, | 112 // the QPC value provided by DWM into the low-resolution timebase, |
90 // which would be error prone and jittery. As a fallback, we assume | 113 // which would be error prone and jittery. As a fallback, we assume |
91 // the timebase is zero and use rateRefresh, which may be rounded but | 114 // the timebase is zero and use rateRefresh, which may be rounded but |
92 // isn't noisy like qpcRefreshPeriod, instead. The fact that we don't | 115 // isn't noisy like qpcRefreshPeriod, instead. The fact that we don't |
93 // have a timebase here may lead to brief periods of jank when our | 116 // have a timebase here may lead to brief periods of jank when our |
94 // scheduling becomes offset from the hardware vsync. | 117 // scheduling becomes offset from the hardware vsync. |
95 | 118 interval = interval2; |
96 // Swap the numerator/denominator to convert frequency to period. | |
97 interval = base::TimeDelta::FromMicroseconds( | |
98 timing_info.rateRefresh.uiDenominator * | |
99 base::Time::kMicrosecondsPerSecond / | |
100 timing_info.rateRefresh.uiNumerator); | |
101 } | 119 } |
102 } | 120 } |
103 } | 121 } |
104 | 122 |
105 if (!dwm_active) { | 123 if (!dwm_active) { |
106 // When DWM compositing is active all displays are normalized to the | 124 // When DWM compositing is active all displays are normalized to the |
107 // refresh rate of the primary display, and won't composite any faster. | 125 // refresh rate of the primary display, and won't composite any faster. |
108 // If DWM compositing is disabled, though, we can use the refresh rates | 126 // If DWM compositing is disabled, though, we can use the refresh rates |
109 // reported by each display, which will help systems that have mis-matched | 127 // reported by each display, which will help systems that have mis-matched |
110 // displays that run at different frequencies. | 128 // displays that run at different frequencies. |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 NOTREACHED(); | 357 NOTREACHED(); |
340 return NULL; | 358 return NULL; |
341 } | 359 } |
342 } | 360 } |
343 | 361 |
344 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 362 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
345 return GetDC(NULL); | 363 return GetDC(NULL); |
346 } | 364 } |
347 | 365 |
348 } // namespace gfx | 366 } // namespace gfx |
OLD | NEW |