Chris Robinson : wgl: Don' t set a pixel format on windows that already have one.

Alexandre Julliard julliard at winehq.org
Thu Sep 20 10:30:10 CDT 2007


Module: wine
Branch: master
Commit: 87e3cd66ab46a6234424749ed56c018e83e9d889
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=87e3cd66ab46a6234424749ed56c018e83e9d889

Author: Chris Robinson <chris.kcat at gmail.com>
Date:   Wed Sep 19 03:21:08 2007 -0700

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 2d08cfb..c244bb8 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 fc33143..091aee5 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;
         }
     }
 




More information about the wine-cvs mailing list