GetPixel bug!!!

François Gouget fgouget at codeweavers.com
Fri Feb 16 01:39:18 CST 2001



   After a long debugging session I discovered that GetPixel was giving
me garbage. The application is doing something like (very greatly
simplified):

   hdc=CreateCompatibleDC(0);
   SelectObject(hdc,some_bitmap);
   pixel=GetPixel(hdc,0,0);


   The problem is that GetPixel was not synchronizing the DIB (the
bitmap) with the DC's pixmap: it was taking data from the uninitialized
pixmap directly. Adding a X11DRV_LockDIBSection /
X11DRV_UnlockDIBSection pair fixes this problem.
   I did a quick review and found that SetPixel seems to suffer from the
same problem.


   There's only one thing bothering me: how come nobody found this
problem earlier? 

Changelog:

   François Gouget <fgouget at codeweavers.com>

 * graphics/x11drv/graphics.c

   Added DIB/pixmap synchronization for {Get,Set}Pixel


-- 
François Gouget
fgouget at codeweavers.com
-------------- next part --------------
Index: graphics/x11drv/graphics.c
===================================================================
RCS file: /home/cvs/wine/wine/graphics/x11drv/graphics.c,v
retrieving revision 1.36
diff -u -r1.36 graphics.c
--- graphics/x11drv/graphics.c	2001/01/24 19:38:11	1.36
+++ graphics/x11drv/graphics.c	2001/02/16 06:36:58
@@ -864,15 +864,18 @@
     x = dc->DCOrgX + INTERNAL_XWPTODP( dc, x, y );
     y = dc->DCOrgY + INTERNAL_YWPTODP( dc, x, y );
     pixel = X11DRV_PALETTE_ToPhysical( dc, color );
-    
+
+    /* Update the pixmap from the DIB section */
+    X11DRV_LockDIBSection(dc, DIB_Status_GdiMod, FALSE);
+
+    /* inefficient but simple... */
     TSXSetForeground( display, physDev->gc, pixel );
     TSXSetFunction( display, physDev->gc, GXcopy );
     TSXDrawPoint( display, physDev->drawable, physDev->gc, x, y );
 
-    /* inefficient but simple... */
+    /* Update the DIBSection from the pixmap */
+    X11DRV_UnlockDIBSection(dc, TRUE);
 
-    /* FIXME: the DIBSection pixel should be updated too */
-    
     return X11DRV_PALETTE_ToLogical(pixel);
 }
 
@@ -888,6 +891,9 @@
     int pixel;
     X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
+    /* Update the pixmap from the DIB section */
+    X11DRV_LockDIBSection(dc, DIB_Status_GdiMod, FALSE);
+
     x = dc->DCOrgX + INTERNAL_XWPTODP( dc, x, y );
     y = dc->DCOrgY + INTERNAL_YWPTODP( dc, x, y );
     wine_tsx11_lock();


More information about the wine-patches mailing list