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

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

Issue 681713002: Update from chromium https://crrev.com/301315 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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/gl.gyp ('k') | ui/gl/gpu_switching_manager.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 (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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 bool dwm_active = false; 77 bool dwm_active = false;
78 78
79 // Query the DWM timing info first if available. This will provide the most 79 // Query the DWM timing info first if available. This will provide the most
80 // precise values. 80 // precise values.
81 if (use_dwm_) { 81 if (use_dwm_) {
82 DWM_TIMING_INFO timing_info; 82 DWM_TIMING_INFO timing_info;
83 timing_info.cbSize = sizeof(timing_info); 83 timing_info.cbSize = sizeof(timing_info);
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
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
90 // timebase is zero.
91 if (gfx::FrameTime::TimestampsAreHighRes()) { 87 if (gfx::FrameTime::TimestampsAreHighRes()) {
88 // qpcRefreshPeriod is very accurate but noisy, and must be used with
89 // a high resolution timebase to avoid frequently missing Vsync.
92 timebase = gfx::FrameTime::FromQPCValue( 90 timebase = gfx::FrameTime::FromQPCValue(
93 static_cast<LONGLONG>(timing_info.qpcVBlank)); 91 static_cast<LONGLONG>(timing_info.qpcVBlank));
94 } 92 interval = base::TimeDelta::FromQPCValue(
93 static_cast<LONGLONG>(timing_info.qpcRefreshPeriod));
94 } else if (timing_info.rateRefresh.uiDenominator > 0 &&
95 timing_info.rateRefresh.uiNumerator > 0) {
96 // If FrameTime is not high resolution, we do not want to translate
97 // the QPC value provided by DWM into the low-resolution timebase,
98 // which would be error prone and jittery. As a fallback, we assume
99 // the timebase is zero and use rateRefresh, which may be rounded but
100 // isn't noisy like qpcRefreshPeriod, instead. The fact that we don't
101 // have a timebase here may lead to brief periods of jank when our
102 // scheduling becomes offset from the hardware vsync.
95 103
96 // Swap the numerator/denominator to convert frequency to period. 104 // Swap the numerator/denominator to convert frequency to period.
97 if (timing_info.rateRefresh.uiDenominator > 0 &&
98 timing_info.rateRefresh.uiNumerator > 0) {
99 interval = base::TimeDelta::FromMicroseconds( 105 interval = base::TimeDelta::FromMicroseconds(
100 timing_info.rateRefresh.uiDenominator * 106 timing_info.rateRefresh.uiDenominator *
101 base::Time::kMicrosecondsPerSecond / 107 base::Time::kMicrosecondsPerSecond /
102 timing_info.rateRefresh.uiNumerator); 108 timing_info.rateRefresh.uiNumerator);
103 } 109 }
104 } 110 }
105 } 111 }
106 112
107 // Double check DWM values against per-display refresh rates. 113 if (!dwm_active) {
108 // When DWM compositing is active all displays are normalized to the 114 // When DWM compositing is active all displays are normalized to the
109 // refresh rate of the primary display, and won't composite any faster. 115 // refresh rate of the primary display, and won't composite any faster.
110 // If the display refresh rate is higher than the DWM reported value we will 116 // If DWM compositing is disabled, though, we can use the refresh rates
111 // favor the DWM value because any additional frames produced will be 117 // reported by each display, which will help systems that have mis-matched
112 // discarded by the OS. If the display refresh rate is lower, however, we 118 // displays that run at different frequencies.
113 // can use that to limit the frames we produce more intelligently. 119 HMONITOR monitor = MonitorFromWindow(window_, MONITOR_DEFAULTTONEAREST);
114 // If DWM compositing is not active we will always use the display refresh. 120 MONITORINFOEX monitor_info;
115 HMONITOR monitor = MonitorFromWindow(window_, MONITOR_DEFAULTTONEAREST); 121 monitor_info.cbSize = sizeof(MONITORINFOEX);
116 MONITORINFOEX monitor_info; 122 BOOL result = GetMonitorInfo(monitor, &monitor_info);
117 monitor_info.cbSize = sizeof(MONITORINFOEX); 123 if (result) {
118 BOOL result = GetMonitorInfo(monitor, &monitor_info); 124 DEVMODE display_info;
119 if (result) { 125 display_info.dmSize = sizeof(DEVMODE);
120 DEVMODE display_info; 126 display_info.dmDriverExtra = 0;
121 display_info.dmSize = sizeof(DEVMODE); 127 result = EnumDisplaySettings(monitor_info.szDevice,
122 display_info.dmDriverExtra = 0; 128 ENUM_CURRENT_SETTINGS, &display_info);
123 result = EnumDisplaySettings(monitor_info.szDevice, ENUM_CURRENT_SETTINGS, 129 if (result && display_info.dmDisplayFrequency > 1) {
124 &display_info); 130 interval = base::TimeDelta::FromMicroseconds(
125 if (result && display_info.dmDisplayFrequency > 1) { 131 (1.0 / static_cast<double>(display_info.dmDisplayFrequency)) *
126 base::TimeDelta display_interval = base::TimeDelta::FromMicroseconds( 132 base::Time::kMicrosecondsPerSecond);
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 } 133 }
133 } 134 }
134 } 135 }
135 136
136 if (interval.ToInternalValue() != 0) { 137 if (interval.ToInternalValue() != 0) {
137 callback.Run(timebase, interval); 138 callback.Run(timebase, interval);
138 } 139 }
139 } 140 }
140 141
141 private: 142 private:
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 350 }
350 351
351 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { 352 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() {
352 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableD3D11) || 353 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableD3D11) ||
353 CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseWarp)) 354 CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseWarp))
354 return GetDC(NULL); 355 return GetDC(NULL);
355 return EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE; 356 return EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE;
356 } 357 }
357 358
358 } // namespace gfx 359 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl.gyp ('k') | ui/gl/gpu_switching_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698