From ad6b4113cd27e7c57908081c0a20ab956d418f06 Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Thu, 24 Jul 2014 12:26:22 +0100 Subject: [PATCH] hw/xwin/glx: Fallback to ChoosePixelFormat() if wglChoosePixelFormatARB() fails In glxWinSetPixelFormat() handle the case where wglChoosePixelFormatARB() fails and fallback to ChoosePixelFormat() It seems for some drivers, wglChoosePixelFormatARB() can fail when the provided DC doesn't belong to the driver (e.g. it's a compatible DC for a bitmap, so allow a fallback to ChoosePixelFormat() if it fails. Signed-off-by: Jon Turney Reviewed-by: Colin Harrison --- hw/xwin/glx/indirect.c | 44 +++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/hw/xwin/glx/indirect.c b/hw/xwin/glx/indirect.c index 5d2defb05..91fb6cffe 100644 --- a/hw/xwin/glx/indirect.c +++ b/hw/xwin/glx/indirect.c @@ -1133,7 +1133,30 @@ glxWinSetPixelFormat(HDC hdc, int bppOverride, int drawableTypeOverride, (config->redBits + config->greenBits + config->blueBits), bppOverride, config->drawableType, drawableTypeOverride); - if (!winScreen->has_WGL_ARB_pixel_format) { + if (winScreen->has_WGL_ARB_pixel_format) { + int pixelFormat = + fbConfigToPixelFormatIndex(hdc, config, + drawableTypeOverride, winScreen); + if (pixelFormat != 0) { + GLWIN_DEBUG_MSG("wglChoosePixelFormat: chose pixelFormatIndex %d", + pixelFormat); + ErrorF + ("wglChoosePixelFormat: chose pixelFormatIndex %d (rather than %d as originally planned)\n", + pixelFormat, winConfig->pixelFormatIndex); + + if (!SetPixelFormat(hdc, pixelFormat, NULL)) { + ErrorF("SetPixelFormat error: %s\n", glxWinErrorMessage()); + return FALSE; + } + } + } + + /* + For some drivers, wglChoosePixelFormatARB() can fail when the provided + DC doesn't belong to the driver (e.g. it's a compatible DC for a bitmap, + so allow fallback to ChoosePixelFormat() + */ + { PIXELFORMATDESCRIPTOR pfd; int pixelFormat; @@ -1169,25 +1192,6 @@ glxWinSetPixelFormat(HDC hdc, int bppOverride, int drawableTypeOverride, return FALSE; } } - else { - int pixelFormat = fbConfigToPixelFormatIndex(hdc, config, - drawableTypeOverride, - winScreen); - if (pixelFormat == 0) { - return FALSE; - } - - GLWIN_DEBUG_MSG("wglChoosePixelFormat: chose pixelFormatIndex %d", - pixelFormat); - ErrorF - ("wglChoosePixelFormat: chose pixelFormatIndex %d (rather than %d as originally planned)\n", - pixelFormat, winConfig->pixelFormatIndex); - - if (!SetPixelFormat(hdc, pixelFormat, NULL)) { - ErrorF("SetPixelFormat error: %s\n", glxWinErrorMessage()); - return FALSE; - } - } return TRUE; }