From 5fd13261a005f4c7e4003d86ba50860f6a0983a0 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sun, 27 Mar 2005 18:30:51 +0000 Subject: [PATCH] Added X11DRV_get_pixmap and X11DRV_set_pixmap functions to avoid direct accesses to the physBitmap field of the bitmap structure. --- dlls/x11drv/bitmap.c | 72 ++++++++++++++++++++++++++---------------- dlls/x11drv/brush.c | 7 ++-- dlls/x11drv/dib.c | 9 +++--- dlls/x11drv/window.c | 4 +-- dlls/x11drv/x11ddraw.c | 5 +-- dlls/x11drv/x11drv.h | 3 +- 6 files changed, 58 insertions(+), 42 deletions(-) diff --git a/dlls/x11drv/bitmap.c b/dlls/x11drv/bitmap.c index 9b08e6978f8..81c159a127f 100644 --- a/dlls/x11drv/bitmap.c +++ b/dlls/x11drv/bitmap.c @@ -80,7 +80,7 @@ HBITMAP X11DRV_SelectBitmap( X11DRV_PDEVICE *physDev, HBITMAP hbitmap ) if (hbitmap == BITMAP_stock_bitmap) physDev->drawable = BITMAP_stock_pixmap; else - physDev->drawable = (Pixmap)bmp->physBitmap; + physDev->drawable = X11DRV_get_pixmap( hbitmap ); /* Change GC depth if needed */ @@ -109,6 +109,7 @@ HBITMAP X11DRV_SelectBitmap( X11DRV_PDEVICE *physDev, HBITMAP hbitmap ) */ BOOL X11DRV_CreateBitmap( X11DRV_PDEVICE *physDev, HBITMAP hbitmap ) { + Pixmap pixmap; BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); if(!bmp) { @@ -141,16 +142,16 @@ BOOL X11DRV_CreateBitmap( X11DRV_PDEVICE *physDev, HBITMAP hbitmap ) /* Create the pixmap */ wine_tsx11_lock(); - bmp->physBitmap = (void *)XCreatePixmap(gdi_display, root_window, - bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, - bmp->bitmap.bmBitsPixel); + pixmap = XCreatePixmap(gdi_display, root_window, + bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, bmp->bitmap.bmBitsPixel); wine_tsx11_unlock(); - if (!bmp->physBitmap) + if (!pixmap) { WARN("Can't create Pixmap\n"); GDI_ReleaseObj( hbitmap ); return FALSE; } + X11DRV_set_pixmap( hbitmap, pixmap ); if (bmp->bitmap.bmBits) /* Set bitmap bits */ X11DRV_SetBitmapBits( hbitmap, bmp->bitmap.bmBits, @@ -172,6 +173,7 @@ LONG X11DRV_GetBitmapBits( HBITMAP hbitmap, void *buffer, LONG count ) { BITMAPOBJ *bmp = GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); LONG old_height, height; + Pixmap pixmap = X11DRV_get_pixmap( hbitmap ); XImage *image; LPBYTE tbuf, startline; int h, w; @@ -187,8 +189,7 @@ LONG X11DRV_GetBitmapBits( HBITMAP hbitmap, void *buffer, LONG count ) old_height = bmp->bitmap.bmHeight; height = bmp->bitmap.bmHeight = count / bmp->bitmap.bmWidthBytes; - image = XGetImage( gdi_display, (Pixmap)bmp->physBitmap, - 0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, + image = XGetImage( gdi_display, pixmap, 0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, AllPlanes, ZPixmap ); bmp->bitmap.bmHeight = old_height; @@ -301,6 +302,7 @@ LONG X11DRV_GetBitmapBits( HBITMAP hbitmap, void *buffer, LONG count ) LONG X11DRV_SetBitmapBits( HBITMAP hbitmap, const void *bits, LONG count ) { BITMAPOBJ *bmp = GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); + Pixmap pixmap = X11DRV_get_pixmap( hbitmap ); LONG height; XImage *image; const BYTE *sbuf, *startline; @@ -404,7 +406,7 @@ LONG X11DRV_SetBitmapBits( HBITMAP hbitmap, const void *bits, LONG count ) FIXME("Unhandled bits:%d\n", bmp->bitmap.bmBitsPixel); } - XPutImage( gdi_display, (Pixmap)bmp->physBitmap, BITMAP_GC(bmp), + XPutImage( gdi_display, pixmap, BITMAP_GC(bmp), image, 0, 0, 0, 0, bmp->bitmap.bmWidth, height ); XDestroyImage( image ); /* frees image->data too */ wine_tsx11_unlock(); @@ -420,10 +422,11 @@ BOOL X11DRV_DeleteBitmap( HBITMAP hbitmap ) BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); if (bmp) { + Pixmap pixmap; if (bmp->dib) X11DRV_DIB_DeleteDIBSection( bmp ); + pixmap = X11DRV_set_pixmap( hbitmap, 0 ); wine_tsx11_lock(); - if (bmp->physBitmap) XFreePixmap( gdi_display, (Pixmap)bmp->physBitmap ); - bmp->physBitmap = NULL; + if (pixmap) XFreePixmap( gdi_display, pixmap ); wine_tsx11_unlock(); GDI_ReleaseObj( hbitmap ); } @@ -440,8 +443,8 @@ BOOL X11DRV_DeleteBitmap( HBITMAP hbitmap ) HBITMAP X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(HDC hdc, Pixmap pixmap) { HDC hdcMem; + Pixmap old_pixmap; HBITMAP hBmp = 0, old; - BITMAPOBJ *pBmp = NULL; Window root; int x,y; /* Unused */ unsigned border_width; /* Unused */ @@ -467,11 +470,10 @@ HBITMAP X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(HDC hdc, Pixmap pixmap) hdcMem = CreateCompatibleDC( hdc ); old = SelectObject( hdcMem, hBmp ); - pBmp = (BITMAPOBJ *)GDI_GetObjPtr( hBmp, BITMAP_MAGIC ); - - if (pBmp->physBitmap) XFreePixmap( gdi_display, (Pixmap)pBmp->physBitmap ); - pBmp->physBitmap = (void *)pixmap; - GDI_ReleaseObj( hBmp ); + old_pixmap = X11DRV_set_pixmap( hBmp, pixmap ); + wine_tsx11_lock(); + if (old_pixmap) XFreePixmap( gdi_display, old_pixmap ); + wine_tsx11_unlock(); SelectObject( hdcMem, old ); DeleteDC( hdcMem ); @@ -483,21 +485,37 @@ END: /*********************************************************************** - * X11DRV_BITMAP_Pixmap + * X11DRV_set_pixmap * - * This function exists solely for x11 driver of the window system. + * Set the pixmap associated to a bitmap, and return the previous one. */ -Pixmap X11DRV_BITMAP_Pixmap(HBITMAP hbitmap) +Pixmap X11DRV_set_pixmap( HBITMAP hbitmap, Pixmap pixmap ) { - Pixmap pixmap; - BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); - if (bmp) { - pixmap = (Pixmap)bmp->physBitmap; - GDI_ReleaseObj( hbitmap ); + Pixmap ret = 0; + BITMAPOBJ *bmp = (BITMAPOBJ *)GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); + if (bmp) + { + ret = (Pixmap)bmp->physBitmap; + bmp->physBitmap = (void *)pixmap; + GDI_ReleaseObj( hbitmap ); } - else { - ERR("handle %p returned no obj\n", hbitmap); - pixmap = 0; + return ret; +} + + +/*********************************************************************** + * X11DRV_get_pixmap + * + * Retrieve the pixmap associated to a bitmap. + */ +Pixmap X11DRV_get_pixmap( HBITMAP hbitmap ) +{ + Pixmap pixmap = 0; + BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); + if (bmp) + { + pixmap = (Pixmap)bmp->physBitmap; + GDI_ReleaseObj( hbitmap ); } return pixmap; } diff --git a/dlls/x11drv/brush.c b/dlls/x11drv/brush.c index 315540a21d5..9b80ee33443 100644 --- a/dlls/x11drv/brush.c +++ b/dlls/x11drv/brush.c @@ -176,10 +176,11 @@ static void BRUSH_SelectSolidBrush( X11DRV_PDEVICE *physDev, COLORREF color ) static BOOL BRUSH_SelectPatternBrush( X11DRV_PDEVICE *physDev, HBITMAP hbitmap ) { BOOL ret = FALSE; + Pixmap pixmap; BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); if (!bmp) return FALSE; - if(!bmp->physBitmap) goto done; + if (!(pixmap = X11DRV_get_pixmap( hbitmap ))) goto done; wine_tsx11_lock(); if ((physDev->depth == 1) && (bmp->bitmap.bmBitsPixel != 1)) @@ -188,7 +189,7 @@ static BOOL BRUSH_SelectPatternBrush( X11DRV_PDEVICE *physDev, HBITMAP hbitmap ) physDev->brush.pixmap = XCreatePixmap( gdi_display, root_window, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, 1); /* FIXME: should probably convert to monochrome instead */ - XCopyPlane( gdi_display, (Pixmap)bmp->physBitmap, physDev->brush.pixmap, + XCopyPlane( gdi_display, pixmap, physDev->brush.pixmap, BITMAP_monoGC, 0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, 0, 0, 1 ); } else @@ -196,7 +197,7 @@ static BOOL BRUSH_SelectPatternBrush( X11DRV_PDEVICE *physDev, HBITMAP hbitmap ) physDev->brush.pixmap = XCreatePixmap( gdi_display, root_window, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, bmp->bitmap.bmBitsPixel ); - XCopyArea( gdi_display, (Pixmap)bmp->physBitmap, physDev->brush.pixmap, + XCopyArea( gdi_display, pixmap, physDev->brush.pixmap, BITMAP_GC(bmp), 0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, 0, 0 ); } wine_tsx11_unlock(); diff --git a/dlls/x11drv/dib.c b/dlls/x11drv/dib.c index 1daa8c56c4d..1353c00a8c5 100644 --- a/dlls/x11drv/dib.c +++ b/dlls/x11drv/dib.c @@ -3881,7 +3881,7 @@ INT X11DRV_SetDIBits( X11DRV_PDEVICE *physDev, HBITMAP hbitmap, UINT startscan, descr.palentry = NULL; descr.lines = tmpheight >= 0 ? lines : -lines; descr.depth = bmp->bitmap.bmBitsPixel; - descr.drawable = (Pixmap)bmp->physBitmap; + descr.drawable = X11DRV_get_pixmap( hbitmap ); descr.gc = BITMAP_GC(bmp); descr.xSrc = 0; descr.ySrc = 0; @@ -4002,7 +4002,7 @@ INT X11DRV_GetDIBits( X11DRV_PDEVICE *physDev, HBITMAP hbitmap, UINT startscan, descr.image = NULL; descr.lines = lines; descr.depth = bmp->bitmap.bmBitsPixel; - descr.drawable = (Pixmap)bmp->physBitmap; + descr.drawable = X11DRV_get_pixmap( hbitmap ); descr.gc = BITMAP_GC(bmp); descr.width = bmp->bitmap.bmWidth; descr.height = bmp->bitmap.bmHeight; @@ -5080,7 +5080,7 @@ HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc, BOOL bDeletePixma if (!bDeletePixmap) { /* Clear the physBitmap to prevent the Pixmap from being deleted by DeleteObject */ - pBmp->physBitmap = NULL; + X11DRV_set_pixmap( hBmp, 0 ); pBmp->funcs = NULL; } GDI_ReleaseObj( hBmp ); @@ -5131,9 +5131,8 @@ Pixmap X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB, HDC hdc ) pBmp = (BITMAPOBJ *) GDI_GetObjPtr( hBmp, BITMAP_MAGIC ); - pixmap = (Pixmap)pBmp->physBitmap; /* clear the physBitmap so that we can steal its pixmap */ - pBmp->physBitmap = NULL; + pixmap = X11DRV_set_pixmap( hBmp, 0 ); pBmp->funcs = NULL; /* Delete the DDB we created earlier now that we have stolen its pixmap */ diff --git a/dlls/x11drv/window.c b/dlls/x11drv/window.c index ff8175a2541..fc4311242c6 100644 --- a/dlls/x11drv/window.c +++ b/dlls/x11drv/window.c @@ -336,8 +336,8 @@ static void set_icon_hints( Display *display, struct x11drv_win_data *data, data->hWMIconBitmap = ii.hbmColor; data->hWMIconMask = ii.hbmMask; - hints->icon_pixmap = X11DRV_BITMAP_Pixmap(data->hWMIconBitmap); - hints->icon_mask = X11DRV_BITMAP_Pixmap(data->hWMIconMask); + hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap); + hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask); destroy_icon_window( display, data ); hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint; } diff --git a/dlls/x11drv/x11ddraw.c b/dlls/x11drv/x11ddraw.c index f12cdb24fcd..9712ca009cd 100644 --- a/dlls/x11drv/x11ddraw.c +++ b/dlls/x11drv/x11ddraw.c @@ -51,10 +51,7 @@ static void SetPrimaryDIB(HBITMAP hBmp) { X11DRV_DD_PrimaryDIB = hBmp; if (hBmp) { - BITMAPOBJ *bmp; - bmp = (BITMAPOBJ *)GDI_GetObjPtr( hBmp, BITMAP_MAGIC ); - X11DRV_DD_PrimaryDrawable = (Pixmap)bmp->physBitmap; - GDI_ReleaseObj( hBmp ); + X11DRV_DD_PrimaryDrawable = X11DRV_get_pixmap( hBmp ); } else { X11DRV_DD_PrimaryDrawable = 0; } diff --git a/dlls/x11drv/x11drv.h b/dlls/x11drv/x11drv.h index b1e8aeb3cda..4f1f01334ba 100644 --- a/dlls/x11drv/x11drv.h +++ b/dlls/x11drv/x11drv.h @@ -208,7 +208,8 @@ extern HBITMAP X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(HDC hdc, Pixmap pixmap extern HGLOBAL X11DRV_DIB_CreateDIBFromBitmap(HDC hdc, HBITMAP hBmp); extern HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc, BOOL bDeletePixmap); extern Pixmap X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB, HDC hdc ); -extern Pixmap X11DRV_BITMAP_Pixmap( HBITMAP ); +extern Pixmap X11DRV_set_pixmap( HBITMAP hbitmap, Pixmap pixmap ); +extern Pixmap X11DRV_get_pixmap( HBITMAP hbitmap ); extern RGNDATA *X11DRV_GetRegionData( HRGN hrgn, HDC hdc_lptodp );