Added X11DRV_get_pixmap and X11DRV_set_pixmap functions to avoid

direct accesses to the physBitmap field of the bitmap structure.
This commit is contained in:
Alexandre Julliard 2005-03-27 18:30:51 +00:00
parent edcbd13665
commit 5fd13261a0
6 changed files with 58 additions and 42 deletions

View File

@ -80,7 +80,7 @@ HBITMAP X11DRV_SelectBitmap( X11DRV_PDEVICE *physDev, HBITMAP hbitmap )
if (hbitmap == BITMAP_stock_bitmap) if (hbitmap == BITMAP_stock_bitmap)
physDev->drawable = BITMAP_stock_pixmap; physDev->drawable = BITMAP_stock_pixmap;
else else
physDev->drawable = (Pixmap)bmp->physBitmap; physDev->drawable = X11DRV_get_pixmap( hbitmap );
/* Change GC depth if needed */ /* 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 ) BOOL X11DRV_CreateBitmap( X11DRV_PDEVICE *physDev, HBITMAP hbitmap )
{ {
Pixmap pixmap;
BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
if(!bmp) { if(!bmp) {
@ -141,16 +142,16 @@ BOOL X11DRV_CreateBitmap( X11DRV_PDEVICE *physDev, HBITMAP hbitmap )
/* Create the pixmap */ /* Create the pixmap */
wine_tsx11_lock(); wine_tsx11_lock();
bmp->physBitmap = (void *)XCreatePixmap(gdi_display, root_window, pixmap = XCreatePixmap(gdi_display, root_window,
bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, bmp->bitmap.bmBitsPixel);
bmp->bitmap.bmBitsPixel);
wine_tsx11_unlock(); wine_tsx11_unlock();
if (!bmp->physBitmap) if (!pixmap)
{ {
WARN("Can't create Pixmap\n"); WARN("Can't create Pixmap\n");
GDI_ReleaseObj( hbitmap ); GDI_ReleaseObj( hbitmap );
return FALSE; return FALSE;
} }
X11DRV_set_pixmap( hbitmap, pixmap );
if (bmp->bitmap.bmBits) /* Set bitmap bits */ if (bmp->bitmap.bmBits) /* Set bitmap bits */
X11DRV_SetBitmapBits( hbitmap, bmp->bitmap.bmBits, 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 ); BITMAPOBJ *bmp = GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
LONG old_height, height; LONG old_height, height;
Pixmap pixmap = X11DRV_get_pixmap( hbitmap );
XImage *image; XImage *image;
LPBYTE tbuf, startline; LPBYTE tbuf, startline;
int h, w; int h, w;
@ -187,8 +189,7 @@ LONG X11DRV_GetBitmapBits( HBITMAP hbitmap, void *buffer, LONG count )
old_height = bmp->bitmap.bmHeight; old_height = bmp->bitmap.bmHeight;
height = bmp->bitmap.bmHeight = count / bmp->bitmap.bmWidthBytes; height = bmp->bitmap.bmHeight = count / bmp->bitmap.bmWidthBytes;
image = XGetImage( gdi_display, (Pixmap)bmp->physBitmap, image = XGetImage( gdi_display, pixmap, 0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
AllPlanes, ZPixmap ); AllPlanes, ZPixmap );
bmp->bitmap.bmHeight = old_height; 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 ) LONG X11DRV_SetBitmapBits( HBITMAP hbitmap, const void *bits, LONG count )
{ {
BITMAPOBJ *bmp = GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); BITMAPOBJ *bmp = GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
Pixmap pixmap = X11DRV_get_pixmap( hbitmap );
LONG height; LONG height;
XImage *image; XImage *image;
const BYTE *sbuf, *startline; 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); 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 ); image, 0, 0, 0, 0, bmp->bitmap.bmWidth, height );
XDestroyImage( image ); /* frees image->data too */ XDestroyImage( image ); /* frees image->data too */
wine_tsx11_unlock(); wine_tsx11_unlock();
@ -420,10 +422,11 @@ BOOL X11DRV_DeleteBitmap( HBITMAP hbitmap )
BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
if (bmp) if (bmp)
{ {
Pixmap pixmap;
if (bmp->dib) X11DRV_DIB_DeleteDIBSection( bmp ); if (bmp->dib) X11DRV_DIB_DeleteDIBSection( bmp );
pixmap = X11DRV_set_pixmap( hbitmap, 0 );
wine_tsx11_lock(); wine_tsx11_lock();
if (bmp->physBitmap) XFreePixmap( gdi_display, (Pixmap)bmp->physBitmap ); if (pixmap) XFreePixmap( gdi_display, pixmap );
bmp->physBitmap = NULL;
wine_tsx11_unlock(); wine_tsx11_unlock();
GDI_ReleaseObj( hbitmap ); GDI_ReleaseObj( hbitmap );
} }
@ -440,8 +443,8 @@ BOOL X11DRV_DeleteBitmap( HBITMAP hbitmap )
HBITMAP X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(HDC hdc, Pixmap pixmap) HBITMAP X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(HDC hdc, Pixmap pixmap)
{ {
HDC hdcMem; HDC hdcMem;
Pixmap old_pixmap;
HBITMAP hBmp = 0, old; HBITMAP hBmp = 0, old;
BITMAPOBJ *pBmp = NULL;
Window root; Window root;
int x,y; /* Unused */ int x,y; /* Unused */
unsigned border_width; /* Unused */ unsigned border_width; /* Unused */
@ -467,11 +470,10 @@ HBITMAP X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(HDC hdc, Pixmap pixmap)
hdcMem = CreateCompatibleDC( hdc ); hdcMem = CreateCompatibleDC( hdc );
old = SelectObject( hdcMem, hBmp ); old = SelectObject( hdcMem, hBmp );
pBmp = (BITMAPOBJ *)GDI_GetObjPtr( hBmp, BITMAP_MAGIC ); old_pixmap = X11DRV_set_pixmap( hBmp, pixmap );
wine_tsx11_lock();
if (pBmp->physBitmap) XFreePixmap( gdi_display, (Pixmap)pBmp->physBitmap ); if (old_pixmap) XFreePixmap( gdi_display, old_pixmap );
pBmp->physBitmap = (void *)pixmap; wine_tsx11_unlock();
GDI_ReleaseObj( hBmp );
SelectObject( hdcMem, old ); SelectObject( hdcMem, old );
DeleteDC( hdcMem ); 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; Pixmap ret = 0;
BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); BITMAPOBJ *bmp = (BITMAPOBJ *)GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
if (bmp) { if (bmp)
pixmap = (Pixmap)bmp->physBitmap; {
GDI_ReleaseObj( hbitmap ); ret = (Pixmap)bmp->physBitmap;
bmp->physBitmap = (void *)pixmap;
GDI_ReleaseObj( hbitmap );
} }
else { return ret;
ERR("handle %p returned no obj\n", hbitmap); }
pixmap = 0;
/***********************************************************************
* 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; return pixmap;
} }

View File

@ -176,10 +176,11 @@ static void BRUSH_SelectSolidBrush( X11DRV_PDEVICE *physDev, COLORREF color )
static BOOL BRUSH_SelectPatternBrush( X11DRV_PDEVICE *physDev, HBITMAP hbitmap ) static BOOL BRUSH_SelectPatternBrush( X11DRV_PDEVICE *physDev, HBITMAP hbitmap )
{ {
BOOL ret = FALSE; BOOL ret = FALSE;
Pixmap pixmap;
BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
if (!bmp) return FALSE; if (!bmp) return FALSE;
if(!bmp->physBitmap) goto done; if (!(pixmap = X11DRV_get_pixmap( hbitmap ))) goto done;
wine_tsx11_lock(); wine_tsx11_lock();
if ((physDev->depth == 1) && (bmp->bitmap.bmBitsPixel != 1)) 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, physDev->brush.pixmap = XCreatePixmap( gdi_display, root_window,
bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, 1); bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, 1);
/* FIXME: should probably convert to monochrome instead */ /* 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 ); BITMAP_monoGC, 0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, 0, 0, 1 );
} }
else else
@ -196,7 +197,7 @@ static BOOL BRUSH_SelectPatternBrush( X11DRV_PDEVICE *physDev, HBITMAP hbitmap )
physDev->brush.pixmap = XCreatePixmap( gdi_display, root_window, physDev->brush.pixmap = XCreatePixmap( gdi_display, root_window,
bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
bmp->bitmap.bmBitsPixel ); 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 ); BITMAP_GC(bmp), 0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, 0, 0 );
} }
wine_tsx11_unlock(); wine_tsx11_unlock();

View File

@ -3881,7 +3881,7 @@ INT X11DRV_SetDIBits( X11DRV_PDEVICE *physDev, HBITMAP hbitmap, UINT startscan,
descr.palentry = NULL; descr.palentry = NULL;
descr.lines = tmpheight >= 0 ? lines : -lines; descr.lines = tmpheight >= 0 ? lines : -lines;
descr.depth = bmp->bitmap.bmBitsPixel; descr.depth = bmp->bitmap.bmBitsPixel;
descr.drawable = (Pixmap)bmp->physBitmap; descr.drawable = X11DRV_get_pixmap( hbitmap );
descr.gc = BITMAP_GC(bmp); descr.gc = BITMAP_GC(bmp);
descr.xSrc = 0; descr.xSrc = 0;
descr.ySrc = 0; descr.ySrc = 0;
@ -4002,7 +4002,7 @@ INT X11DRV_GetDIBits( X11DRV_PDEVICE *physDev, HBITMAP hbitmap, UINT startscan,
descr.image = NULL; descr.image = NULL;
descr.lines = lines; descr.lines = lines;
descr.depth = bmp->bitmap.bmBitsPixel; descr.depth = bmp->bitmap.bmBitsPixel;
descr.drawable = (Pixmap)bmp->physBitmap; descr.drawable = X11DRV_get_pixmap( hbitmap );
descr.gc = BITMAP_GC(bmp); descr.gc = BITMAP_GC(bmp);
descr.width = bmp->bitmap.bmWidth; descr.width = bmp->bitmap.bmWidth;
descr.height = bmp->bitmap.bmHeight; descr.height = bmp->bitmap.bmHeight;
@ -5080,7 +5080,7 @@ HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc, BOOL bDeletePixma
if (!bDeletePixmap) if (!bDeletePixmap)
{ {
/* Clear the physBitmap to prevent the Pixmap from being deleted by DeleteObject */ /* Clear the physBitmap to prevent the Pixmap from being deleted by DeleteObject */
pBmp->physBitmap = NULL; X11DRV_set_pixmap( hBmp, 0 );
pBmp->funcs = NULL; pBmp->funcs = NULL;
} }
GDI_ReleaseObj( hBmp ); GDI_ReleaseObj( hBmp );
@ -5131,9 +5131,8 @@ Pixmap X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB, HDC hdc )
pBmp = (BITMAPOBJ *) GDI_GetObjPtr( hBmp, BITMAP_MAGIC ); pBmp = (BITMAPOBJ *) GDI_GetObjPtr( hBmp, BITMAP_MAGIC );
pixmap = (Pixmap)pBmp->physBitmap;
/* clear the physBitmap so that we can steal its pixmap */ /* clear the physBitmap so that we can steal its pixmap */
pBmp->physBitmap = NULL; pixmap = X11DRV_set_pixmap( hBmp, 0 );
pBmp->funcs = NULL; pBmp->funcs = NULL;
/* Delete the DDB we created earlier now that we have stolen its pixmap */ /* Delete the DDB we created earlier now that we have stolen its pixmap */

View File

@ -336,8 +336,8 @@ static void set_icon_hints( Display *display, struct x11drv_win_data *data,
data->hWMIconBitmap = ii.hbmColor; data->hWMIconBitmap = ii.hbmColor;
data->hWMIconMask = ii.hbmMask; data->hWMIconMask = ii.hbmMask;
hints->icon_pixmap = X11DRV_BITMAP_Pixmap(data->hWMIconBitmap); hints->icon_pixmap = X11DRV_get_pixmap(data->hWMIconBitmap);
hints->icon_mask = X11DRV_BITMAP_Pixmap(data->hWMIconMask); hints->icon_mask = X11DRV_get_pixmap(data->hWMIconMask);
destroy_icon_window( display, data ); destroy_icon_window( display, data );
hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint; hints->flags = (hints->flags & ~IconWindowHint) | IconPixmapHint | IconMaskHint;
} }

View File

@ -51,10 +51,7 @@ static void SetPrimaryDIB(HBITMAP hBmp)
{ {
X11DRV_DD_PrimaryDIB = hBmp; X11DRV_DD_PrimaryDIB = hBmp;
if (hBmp) { if (hBmp) {
BITMAPOBJ *bmp; X11DRV_DD_PrimaryDrawable = X11DRV_get_pixmap( hBmp );
bmp = (BITMAPOBJ *)GDI_GetObjPtr( hBmp, BITMAP_MAGIC );
X11DRV_DD_PrimaryDrawable = (Pixmap)bmp->physBitmap;
GDI_ReleaseObj( hBmp );
} else { } else {
X11DRV_DD_PrimaryDrawable = 0; X11DRV_DD_PrimaryDrawable = 0;
} }

View File

@ -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_CreateDIBFromBitmap(HDC hdc, HBITMAP hBmp);
extern HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc, BOOL bDeletePixmap); extern HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc, BOOL bDeletePixmap);
extern Pixmap X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB, HDC hdc ); 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 ); extern RGNDATA *X11DRV_GetRegionData( HRGN hrgn, HDC hdc_lptodp );