From 323d9e428c02aa2f3ae5b637ae1f16fad27e431c Mon Sep 17 00:00:00 2001 From: Roderick Colenbrander Date: Wed, 1 Aug 2007 15:58:51 +0200 Subject: [PATCH] wgl: SetPixelFormat should fail on the root window. --- dlls/opengl32/tests/opengl.c | 39 ++++++++++++++++++++++++++++++++++++ dlls/winex11.drv/opengl.c | 7 +++++++ 2 files changed, 46 insertions(+) diff --git a/dlls/opengl32/tests/opengl.c b/dlls/opengl32/tests/opengl.c index ca2710cac8..17ca54ad39 100644 --- a/dlls/opengl32/tests/opengl.c +++ b/dlls/opengl32/tests/opengl.c @@ -151,6 +151,43 @@ 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) +{ + int res = 0; + int pf; + PIXELFORMATDESCRIPTOR pfd = { + sizeof(PIXELFORMATDESCRIPTOR), + 1, /* version */ + PFD_DRAW_TO_WINDOW | + PFD_SUPPORT_OPENGL | + PFD_DOUBLEBUFFER, + PFD_TYPE_RGBA, + 24, /* 24-bit color depth */ + 0, 0, 0, 0, 0, 0, /* color bits */ + 0, /* alpha buffer */ + 0, /* shift bit */ + 0, /* accumulation buffer */ + 0, 0, 0, 0, /* accum bits */ + 32, /* z-buffer */ + 0, /* stencil buffer */ + 0, /* auxiliary buffer */ + PFD_MAIN_PLANE, /* main layer */ + 0, /* reserved */ + 0, 0, 0 /* layer masks */ + }; + + HDC hdc = GetDC(0); + ok(hdc != 0, "GetDC(0) failed!\n"); + + /* This should pass even on the main device context */ + pf = ChoosePixelFormat(hdc, &pfd); + ok(pf != 0, "ChoosePixelFormat failed on main device context"); + + /* 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"); +} + START_TEST(opengl) { HWND hwnd; @@ -198,6 +235,8 @@ START_TEST(opengl) ok(res, "wglMakeCurrent failed!\n"); init_functions(); + test_setpixelformat(); + wgl_extensions = pwglGetExtensionsStringARB(hdc); if(wgl_extensions == NULL) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n"); diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c index 265e67f595..b3cbeef387 100644 --- a/dlls/winex11.drv/opengl.c +++ b/dlls/winex11.drv/opengl.c @@ -1298,6 +1298,13 @@ BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev, return 0; } + /* 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; + } + /* 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) {