From 87e3cd66ab46a6234424749ed56c018e83e9d889 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 19 Sep 2007 03:21:08 -0700 Subject: [PATCH] wgl: Don't set a pixel format on windows that already have one. --- dlls/opengl32/tests/opengl.c | 17 +++++++++++++++-- dlls/winex11.drv/opengl.c | 13 ++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/dlls/opengl32/tests/opengl.c b/dlls/opengl32/tests/opengl.c index 2d08cfb9258..c244bb804fd 100644 --- a/dlls/opengl32/tests/opengl.c +++ b/dlls/opengl32/tests/opengl.c @@ -176,10 +176,12 @@ static void test_pbuffers(HDC hdc) else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n"); } -static void test_setpixelformat(void) +static void test_setpixelformat(HDC winhdc) { int res = 0; + int nCfgs; int pf; + int i; PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, /* version */ @@ -211,6 +213,17 @@ static void test_setpixelformat(void) /* SetPixelFormat on the main device context 'X root window' should fail */ res = SetPixelFormat(hdc, pf, &pfd); ok(res == 0, "SetPixelFormat on main device context should fail\n"); + + /* Setting the same format that was set on the HDC is allowed; other + formats fail */ + nCfgs = DescribePixelFormat(winhdc, 0, 0, NULL); + pf = GetPixelFormat(winhdc); + for(i = 1;i <= nCfgs;i++) + { + int res = SetPixelFormat(winhdc, i, NULL); + if(i == pf) ok(res, "Failed to set the same pixel format\n"); + else ok(!res, "Unexpectedly set an alternate pixel format\n"); + } } static void test_colorbits(HDC hdc) @@ -366,7 +379,7 @@ START_TEST(opengl) ok(res, "wglMakeCurrent failed!\n"); init_functions(); - test_setpixelformat(); + test_setpixelformat(hdc); test_colorbits(hdc); test_gdi_dbuf(hdc); diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c index fc331434ddc..091aee5eabd 100644 --- a/dlls/winex11.drv/opengl.c +++ b/dlls/winex11.drv/opengl.c @@ -1369,35 +1369,38 @@ BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev, if (!has_opengl()) { ERR("No libGL on this box - disabling OpenGL support !\n"); - return 0; + return FALSE; } /* SetPixelFormat is not allowed on the X root_window e.g. GetDC(0) */ if(get_glxdrawable(physDev) == root_window) { ERR("Invalid operation on root_window\n"); - return 0; + return FALSE; } /* Check if iPixelFormat is in our list of supported formats to see if it is supported. */ fmt = ConvertPixelFormatWGLtoGLX(gdi_display, iPixelFormat, FALSE /* Offscreen */, &value); if(!fmt) { ERR("Invalid iPixelFormat: %d\n", iPixelFormat); - return 0; + return FALSE; } + if(physDev->current_pf) /* cannot change it if already set */ + return (physDev->current_pf == iPixelFormat); + pglXGetFBConfigAttrib(gdi_display, fmt->fbconfig, GLX_DRAWABLE_TYPE, &value); hwnd = WindowFromDC(physDev->hdc); if(hwnd) { if(!(value&GLX_WINDOW_BIT)) { WARN("Pixel format %d is not compatible for window rendering\n", iPixelFormat); - return 0; + return FALSE; } if(!SendMessageW(hwnd, WM_X11DRV_SET_WIN_FORMAT, (WPARAM)fmt->fmt_id, 0)) { ERR("Couldn't set format of the window, returning failure\n"); - return 0; + return FALSE; } }