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)
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;
}

View File

@ -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();

View File

@ -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 */

View File

@ -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;
}

View File

@ -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;
}

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_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 );