From 7c791171a15c9192f4b025a810dde11b7dae2e51 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Wed, 17 Apr 2013 08:38:19 +0200 Subject: Calling wglMakeCurrent on an already current context gives 100% cpu load The problem occurs at least with nvidia cards when vsync is enabled in the control panel. Task-number: QTBUG-29686 Change-Id: I6fd2a3560a5baeeac7c3fe0440db85904c45026d Reviewed-by: Friedemann Kleint --- src/plugins/platforms/windows/qwindowsglcontext.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/plugins/platforms/windows/qwindowsglcontext.cpp b/src/plugins/platforms/windows/qwindowsglcontext.cpp index da3e2a6a6a..ae66ef8a3d 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.cpp +++ b/src/plugins/platforms/windows/qwindowsglcontext.cpp @@ -1052,8 +1052,16 @@ bool QWindowsGLContext::makeCurrent(QPlatformSurface *surface) // Do we already have a DC entry for that window? QWindowsWindow *window = static_cast(surface); const HWND hwnd = window->handle(); - if (const QOpenGLContextData *contextData = findByHWND(m_windowContexts, hwnd)) + if (const QOpenGLContextData *contextData = findByHWND(m_windowContexts, hwnd)) { + // Repeated calls to wglMakeCurrent when vsync is enabled in the driver will + // often result in 100% cpuload. This check is cheap and avoids the problem. + // This is reproducable on NVidia cards and Intel onboard chips. + if (wglGetCurrentContext() == contextData->renderingContext + && wglGetCurrentDC() == contextData->hdc) { + return true; + } return wglMakeCurrent(contextData->hdc, contextData->renderingContext); + } // Create a new entry. const QOpenGLContextData newContext(m_renderingContext, hwnd, GetDC(hwnd)); if (!newContext.hdc) -- cgit v1.2.3