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

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

Issue 668273003: Get high resolution frame timebase and interval on compatible systems (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor whitespace cleanup Created 6 years, 2 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
« ui/gfx/frame_time.h ('K') | « ui/gfx/frame_time.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 HRESULT result = DwmGetCompositionTimingInfo(NULL, &timing_info); 84 HRESULT result = DwmGetCompositionTimingInfo(NULL, &timing_info);
85 if (result == S_OK) { 85 if (result == S_OK) {
86 dwm_active = true; 86 dwm_active = true;
87 // If FrameTime is not high resolution, we do not want to translate the 87 // If FrameTime is not high resolution, we do not want to translate the
88 // QPC value provided by DWM into the low-resolution timebase, which 88 // QPC value provided by DWM into the low-resolution timebase, which
89 // would be error prone and jittery. As a fallback, we assume the 89 // would be error prone and jittery. As a fallback, we assume the
90 // timebase is zero. 90 // timebase is zero.
91 if (gfx::FrameTime::TimestampsAreHighRes()) { 91 if (gfx::FrameTime::TimestampsAreHighRes()) {
92 timebase = gfx::FrameTime::FromQPCValue( 92 timebase = gfx::FrameTime::FromQPCValue(
93 static_cast<LONGLONG>(timing_info.qpcVBlank)); 93 static_cast<LONGLONG>(timing_info.qpcVBlank));
94 } 94 interval = base::TimeDelta::FromQPCValue(
95 95 static_cast<LONGLONG>(timing_info.qpcRefreshPeriod));
brianderson 2014/10/22 23:05:30 +tansell for fyi: Apparently qpcRefreshPeriod is a
96 // Swap the numerator/denominator to convert frequency to period. 96 } else if (timing_info.rateRefresh.uiDenominator > 0 &&
97 if (timing_info.rateRefresh.uiDenominator > 0 &&
98 timing_info.rateRefresh.uiNumerator > 0) { 97 timing_info.rateRefresh.uiNumerator > 0) {
98 // Swap the numerator/denominator to convert frequency to period.
brianderson 2014/10/22 23:05:30 Can you add some comments regarding why you don't
99 interval = base::TimeDelta::FromMicroseconds( 99 interval = base::TimeDelta::FromMicroseconds(
100 timing_info.rateRefresh.uiDenominator * 100 timing_info.rateRefresh.uiDenominator *
101 base::Time::kMicrosecondsPerSecond / 101 base::Time::kMicrosecondsPerSecond /
102 timing_info.rateRefresh.uiNumerator); 102 timing_info.rateRefresh.uiNumerator);
103 } 103 }
104 } 104 }
105 } 105 } else {
106 106 // When DWM compositing is active all displays are normalized to the
107 // Double check DWM values against per-display refresh rates. 107 // refresh rate of the primary display, and won't composite any faster.
108 // When DWM compositing is active all displays are normalized to the 108 // If DWM compositing is disabled, though, we can use the refresh rates
109 // refresh rate of the primary display, and won't composite any faster. 109 // reported by each display, which will help systems that have mis-matched
110 // If the display refresh rate is higher than the DWM reported value we will 110 // displays that run at different frequencies.
111 // favor the DWM value because any additional frames produced will be 111 HMONITOR monitor = MonitorFromWindow(window_, MONITOR_DEFAULTTONEAREST);
112 // discarded by the OS. If the display refresh rate is lower, however, we 112 MONITORINFOEX monitor_info;
113 // can use that to limit the frames we produce more intelligently. 113 monitor_info.cbSize = sizeof(MONITORINFOEX);
114 // If DWM compositing is not active we will always use the display refresh. 114 BOOL result = GetMonitorInfo(monitor, &monitor_info);
115 HMONITOR monitor = MonitorFromWindow(window_, MONITOR_DEFAULTTONEAREST); 115 if (result) {
116 MONITORINFOEX monitor_info; 116 DEVMODE display_info;
117 monitor_info.cbSize = sizeof(MONITORINFOEX); 117 display_info.dmSize = sizeof(DEVMODE);
118 BOOL result = GetMonitorInfo(monitor, &monitor_info); 118 display_info.dmDriverExtra = 0;
119 if (result) { 119 result = EnumDisplaySettings(monitor_info.szDevice,
120 DEVMODE display_info; 120 ENUM_CURRENT_SETTINGS, &display_info);
121 display_info.dmSize = sizeof(DEVMODE); 121 if (result && display_info.dmDisplayFrequency > 1) {
122 display_info.dmDriverExtra = 0; 122 interval = base::TimeDelta::FromMicroseconds(
123 result = EnumDisplaySettings(monitor_info.szDevice, ENUM_CURRENT_SETTINGS, 123 (1.0 / static_cast<double>(display_info.dmDisplayFrequency)) *
124 &display_info); 124 base::Time::kMicrosecondsPerSecond);
125 if (result && display_info.dmDisplayFrequency > 1) {
126 base::TimeDelta display_interval = base::TimeDelta::FromMicroseconds(
127 (1.0 / static_cast<double>(display_info.dmDisplayFrequency)) *
128 base::Time::kMicrosecondsPerSecond);
129
130 if (!dwm_active || display_interval > interval) {
131 interval = display_interval;
132 } 125 }
133 } 126 }
134 } 127 }
135 128
136 if (interval.ToInternalValue() != 0) { 129 if (interval.ToInternalValue() != 0) {
137 callback.Run(timebase, interval); 130 callback.Run(timebase, interval);
138 } 131 }
139 } 132 }
140 133
141 private: 134 private:
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 342 }
350 343
351 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { 344 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() {
352 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableD3D11) || 345 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableD3D11) ||
353 CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseWarp)) 346 CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseWarp))
354 return GetDC(NULL); 347 return GetDC(NULL);
355 return EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE; 348 return EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE;
356 } 349 }
357 350
358 } // namespace gfx 351 } // namespace gfx
OLDNEW
« ui/gfx/frame_time.h ('K') | « ui/gfx/frame_time.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698