Chromium Code Reviews| 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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 virtual bool SupportsPostSubBuffer() OVERRIDE; | 52 virtual bool SupportsPostSubBuffer() OVERRIDE; |
| 53 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 53 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 gfx::AcceleratedWidget window_; | 56 gfx::AcceleratedWidget window_; |
| 57 HDC device_context_; | 57 HDC device_context_; |
| 58 | 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa); | 59 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 class DWMVSyncProvider : public VSyncProvider { | 62 class WinVSyncProvider : public VSyncProvider { |
| 63 public: | 63 public: |
| 64 explicit DWMVSyncProvider() {} | 64 explicit WinVSyncProvider(gfx::AcceleratedWidget window) : |
| 65 window_(window) | |
| 66 { | |
| 67 use_dwm_ = (base::win::GetVersion() >= base::win::VERSION_VISTA); | |
| 68 } | |
| 65 | 69 |
| 66 virtual ~DWMVSyncProvider() {} | 70 virtual ~WinVSyncProvider() {} |
| 67 | 71 |
| 68 virtual void GetVSyncParameters(const UpdateVSyncCallback& callback) { | 72 virtual void GetVSyncParameters(const UpdateVSyncCallback& callback) { |
| 69 TRACE_EVENT0("gpu", "DWMVSyncProvider::GetVSyncParameters"); | 73 TRACE_EVENT0("gpu", "WinVSyncProvider::GetVSyncParameters"); |
| 70 DWM_TIMING_INFO timing_info; | |
| 71 timing_info.cbSize = sizeof(timing_info); | |
| 72 HRESULT result = DwmGetCompositionTimingInfo(NULL, &timing_info); | |
| 73 if (result != S_OK) | |
| 74 return; | |
| 75 | 74 |
| 76 base::TimeTicks timebase; | 75 base::TimeTicks timebase; |
| 77 // If FrameTime is not high resolution, we do not want to translate the | 76 base::TimeDelta interval; |
| 78 // QPC value provided by DWM into the low-resolution timebase, which | 77 bool dwm_active = false; |
| 79 // would be error prone and jittery. As a fallback, we assume the timebase | 78 |
| 80 // is zero. | 79 // Query the DWM timing info first if available. This will provide the most |
| 81 if (gfx::FrameTime::TimestampsAreHighRes()) { | 80 // precise values. |
| 82 timebase = gfx::FrameTime::FromQPCValue( | 81 if (use_dwm_) { |
| 83 static_cast<LONGLONG>(timing_info.qpcVBlank)); | 82 DWM_TIMING_INFO timing_info; |
| 83 timing_info.cbSize = sizeof(timing_info); | |
| 84 HRESULT result = DwmGetCompositionTimingInfo(NULL, &timing_info); | |
| 85 if (result == S_OK) { | |
| 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()) { | |
| 92 timebase = gfx::FrameTime::FromQPCValue( | |
| 93 static_cast<LONGLONG>(timing_info.qpcVBlank)); | |
| 94 } | |
| 95 | |
| 96 // 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( | |
| 100 timing_info.rateRefresh.uiDenominator * | |
| 101 base::Time::kMicrosecondsPerSecond / | |
| 102 timing_info.rateRefresh.uiNumerator); | |
| 103 } | |
| 104 } | |
| 84 } | 105 } |
| 85 | 106 |
| 86 // Swap the numerator/denominator to convert frequency to period. | 107 // Double check DWM values against per-display refresh rates. |
| 87 if (timing_info.rateRefresh.uiDenominator > 0 && | 108 // When DWM compositing is active all displays are normalized to the |
| 88 timing_info.rateRefresh.uiNumerator > 0) { | 109 // refresh rate of the primary display, and won't composite any faster. |
| 89 base::TimeDelta interval = base::TimeDelta::FromMicroseconds( | 110 // If the display refresh rate is higher than the DWM reported value we will |
| 90 timing_info.rateRefresh.uiDenominator * | 111 // favor the DWM value because any additional frames produced will be |
| 91 base::Time::kMicrosecondsPerSecond / | 112 // discarded by the OS. If the display refresh rate is lower, however, we |
| 92 timing_info.rateRefresh.uiNumerator); | 113 // can use that to limit the frames we produce more intelligently. |
| 114 // If DWM compositing is not active we will always use the display refresh. | |
| 115 HMONITOR monitor = MonitorFromWindow(window_, MONITOR_DEFAULTTONEAREST); | |
| 116 MONITORINFOEX monitor_info; | |
| 117 monitor_info.cbSize = sizeof(MONITORINFOEX); | |
| 118 BOOL result = GetMonitorInfo(monitor, &monitor_info); | |
| 119 if (result != 0) { | |
|
jbauman
2014/09/29 19:37:07
if (result) {
| |
| 120 DEVMODE display_info; | |
| 121 result = EnumDisplaySettings(monitor_info.szDevice, ENUM_CURRENT_SETTINGS, | |
| 122 &display_info); | |
| 123 if (result != 0 && display_info.dmDisplayFrequency > 0) { | |
|
jbauman
2014/09/29 19:37:07
if (result && display_info.dmDisplayFrequency > 1)
| |
| 124 base::TimeDelta display_interval = base::TimeDelta::FromMicroseconds( | |
| 125 (1.0 / static_cast<double>(display_info.dmDisplayFrequency)) * | |
| 126 base::Time::kMicrosecondsPerSecond); | |
| 127 | |
| 128 if (!dwm_active || display_interval > interval) { | |
| 129 interval = display_interval; | |
| 130 } | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 if (interval.ToInternalValue() != 0) { | |
| 93 callback.Run(timebase, interval); | 135 callback.Run(timebase, interval); |
| 94 } | 136 } |
| 95 } | 137 } |
| 96 | 138 |
| 97 private: | 139 private: |
| 98 DISALLOW_COPY_AND_ASSIGN(DWMVSyncProvider); | 140 DISALLOW_COPY_AND_ASSIGN(WinVSyncProvider); |
| 141 | |
| 142 gfx::AcceleratedWidget window_; | |
| 143 bool use_dwm_; | |
| 99 }; | 144 }; |
| 100 | 145 |
| 101 // Helper routine that does one-off initialization like determining the | 146 // Helper routine that does one-off initialization like determining the |
| 102 // pixel format. | 147 // pixel format. |
| 103 bool GLSurface::InitializeOneOffInternal() { | 148 bool GLSurface::InitializeOneOffInternal() { |
| 104 switch (GetGLImplementation()) { | 149 switch (GetGLImplementation()) { |
| 105 case kGLImplementationDesktopGL: | 150 case kGLImplementationDesktopGL: |
| 106 if (!GLSurfaceWGL::InitializeOneOff()) { | 151 if (!GLSurfaceWGL::InitializeOneOff()) { |
| 107 LOG(ERROR) << "GLSurfaceWGL::InitializeOneOff failed."; | 152 LOG(ERROR) << "GLSurfaceWGL::InitializeOneOff failed."; |
| 108 return false; | 153 return false; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 if (!surface->Initialize()) | 283 if (!surface->Initialize()) |
| 239 return NULL; | 284 return NULL; |
| 240 | 285 |
| 241 return surface; | 286 return surface; |
| 242 } | 287 } |
| 243 case kGLImplementationEGLGLES2: { | 288 case kGLImplementationEGLGLES2: { |
| 244 DCHECK(window != gfx::kNullAcceleratedWidget); | 289 DCHECK(window != gfx::kNullAcceleratedWidget); |
| 245 scoped_refptr<NativeViewGLSurfaceEGL> surface( | 290 scoped_refptr<NativeViewGLSurfaceEGL> surface( |
| 246 new NativeViewGLSurfaceEGL(window)); | 291 new NativeViewGLSurfaceEGL(window)); |
| 247 scoped_ptr<VSyncProvider> sync_provider; | 292 scoped_ptr<VSyncProvider> sync_provider; |
| 248 if (base::win::GetVersion() >= base::win::VERSION_VISTA) | 293 sync_provider.reset(new WinVSyncProvider(window)); |
| 249 sync_provider.reset(new DWMVSyncProvider); | |
| 250 if (!surface->Initialize(sync_provider.Pass())) | 294 if (!surface->Initialize(sync_provider.Pass())) |
| 251 return NULL; | 295 return NULL; |
| 252 | 296 |
| 253 return surface; | 297 return surface; |
| 254 } | 298 } |
| 255 case kGLImplementationDesktopGL: { | 299 case kGLImplementationDesktopGL: { |
| 256 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceWGL( | 300 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceWGL( |
| 257 window)); | 301 window)); |
| 258 if (!surface->Initialize()) | 302 if (!surface->Initialize()) |
| 259 return NULL; | 303 return NULL; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 } | 347 } |
| 304 | 348 |
| 305 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 349 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 306 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableD3D11) || | 350 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableD3D11) || |
| 307 CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseWarp)) | 351 CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseWarp)) |
| 308 return GetDC(NULL); | 352 return GetDC(NULL); |
| 309 return EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE; | 353 return EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE; |
| 310 } | 354 } |
| 311 | 355 |
| 312 } // namespace gfx | 356 } // namespace gfx |
| OLD | NEW |