From 042614751cc15f8e12390d4f4f1e96e8f0f0c9d2 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 13 Apr 2005 15:23:15 +0000 Subject: [PATCH] Use an X context to associate the phys bitmap data to a bitmap handle instead of directly accessing the bitmap structure. --- dlls/x11drv/bitmap.c | 112 +++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 68 deletions(-) diff --git a/dlls/x11drv/bitmap.c b/dlls/x11drv/bitmap.c index 2707b8139d5..310a048112f 100644 --- a/dlls/x11drv/bitmap.c +++ b/dlls/x11drv/bitmap.c @@ -23,12 +23,10 @@ #include #include -#include "gdi.h" +#include "windef.h" +#include "wingdi.h" #include "wine/debug.h" #include "x11drv.h" -#include "wingdi.h" -#include "windef.h" -#include "wine/winuser16.h" WINE_DEFAULT_DEBUG_CHANNEL(x11drv); @@ -36,6 +34,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(x11drv); GC BITMAP_monoGC = 0, BITMAP_colorGC = 0; X_PHYSBITMAP BITMAP_stock_phys_bitmap = { 0 }; /* phys bitmap for the default stock bitmap */ +static XContext bitmap_context; /* X context to associate a phys bitmap to a handle */ + /*********************************************************************** * X11DRV_BITMAP_Init */ @@ -46,6 +46,7 @@ void X11DRV_BITMAP_Init(void) /* Create the necessary GCs */ wine_tsx11_lock(); + bitmap_context = XUniqueContext(); BITMAP_stock_phys_bitmap.pixmap_depth = 1; BITMAP_stock_phys_bitmap.pixmap = XCreatePixmap( gdi_display, root_window, 1, 1, 1 ); BITMAP_monoGC = XCreateGC( gdi_display, BITMAP_stock_phys_bitmap.pixmap, 0, NULL ); @@ -108,56 +109,45 @@ HBITMAP X11DRV_SelectBitmap( X11DRV_PDEVICE *physDev, HBITMAP hbitmap ) BOOL X11DRV_CreateBitmap( X11DRV_PDEVICE *physDev, HBITMAP hbitmap ) { X_PHYSBITMAP *physBitmap; - BOOL ret = FALSE; - BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); + BITMAP bitmap; - if(!bmp) { - WARN("Bad bitmap handle %p\n", hbitmap); - return FALSE; - } + if (!GetObjectW( hbitmap, sizeof(bitmap), &bitmap )) return FALSE; /* Check parameters */ - if (bmp->bitmap.bmPlanes != 1) goto done; + if (bitmap.bmPlanes != 1) return FALSE; - if ((bmp->bitmap.bmBitsPixel != 1) && (bmp->bitmap.bmBitsPixel != screen_depth)) + if ((bitmap.bmBitsPixel != 1) && (bitmap.bmBitsPixel != screen_depth)) { ERR("Trying to make bitmap with planes=%d, bpp=%d\n", - bmp->bitmap.bmPlanes, bmp->bitmap.bmBitsPixel); - goto done; + bitmap.bmPlanes, bitmap.bmBitsPixel); + return FALSE; } if (hbitmap == BITMAP_stock_phys_bitmap.hbitmap) { ERR( "called for stock bitmap, please report\n" ); - goto done; + return FALSE; } - TRACE("(%p) %dx%d %d bpp\n", hbitmap, bmp->bitmap.bmWidth, - bmp->bitmap.bmHeight, bmp->bitmap.bmBitsPixel); + TRACE("(%p) %dx%d %d bpp\n", hbitmap, bitmap.bmWidth, bitmap.bmHeight, bitmap.bmBitsPixel); - if (!(physBitmap = X11DRV_init_phys_bitmap( hbitmap ))) goto done; + if (!(physBitmap = X11DRV_init_phys_bitmap( hbitmap ))) return FALSE; /* Create the pixmap */ wine_tsx11_lock(); + physBitmap->pixmap_depth = bitmap.bmBitsPixel; physBitmap->pixmap = XCreatePixmap(gdi_display, root_window, - bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, - bmp->bitmap.bmBitsPixel); + bitmap.bmWidth, bitmap.bmHeight, bitmap.bmBitsPixel); wine_tsx11_unlock(); if (!physBitmap->pixmap) { WARN("Can't create Pixmap\n"); HeapFree( GetProcessHeap(), 0, physBitmap ); - goto done; + return FALSE; } - bmp->physBitmap = physBitmap; - ret = TRUE; - if (bmp->bitmap.bmBits) /* Set bitmap bits */ - X11DRV_SetBitmapBits( hbitmap, bmp->bitmap.bmBits, - bmp->bitmap.bmHeight * bmp->bitmap.bmWidthBytes ); - -done: - GDI_ReleaseObj( hbitmap ); - return ret; + if (bitmap.bmBits) /* Set bitmap bits */ + X11DRV_SetBitmapBits( hbitmap, bitmap.bmBits, bitmap.bmHeight * bitmap.bmWidthBytes ); + return TRUE; } @@ -417,25 +407,20 @@ LONG X11DRV_SetBitmapBits( HBITMAP hbitmap, const void *bits, LONG count ) */ BOOL X11DRV_DeleteBitmap( HBITMAP hbitmap ) { - BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); - if (bmp) + X_PHYSBITMAP *physBitmap = X11DRV_get_phys_bitmap( hbitmap ); + + if (physBitmap) { - X_PHYSBITMAP *physBitmap = bmp->physBitmap; + DIBSECTION dib; - if (physBitmap) - { - DIBSECTION dib; + if (GetObjectW( hbitmap, sizeof(dib), &dib ) == sizeof(dib)) + X11DRV_DIB_DeleteDIBSection( physBitmap, &dib ); - if (GetObjectW( hbitmap, sizeof(dib), &dib ) == sizeof(dib)) - X11DRV_DIB_DeleteDIBSection( physBitmap, &dib ); - - wine_tsx11_lock(); - if (physBitmap->pixmap) XFreePixmap( gdi_display, physBitmap->pixmap ); - wine_tsx11_unlock(); - HeapFree( GetProcessHeap(), 0, physBitmap ); - bmp->physBitmap = NULL; - } - GDI_ReleaseObj( hbitmap ); + wine_tsx11_lock(); + if (physBitmap->pixmap) XFreePixmap( gdi_display, physBitmap->pixmap ); + XDeleteContext( gdi_display, (XID)hbitmap, bitmap_context ); + wine_tsx11_unlock(); + HeapFree( GetProcessHeap(), 0, physBitmap ); } return TRUE; } @@ -448,13 +433,11 @@ BOOL X11DRV_DeleteBitmap( HBITMAP hbitmap ) */ X_PHYSBITMAP *X11DRV_get_phys_bitmap( HBITMAP hbitmap ) { - X_PHYSBITMAP *ret = NULL; - BITMAPOBJ *bmp = GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); - if (bmp) - { - ret = bmp->physBitmap; - GDI_ReleaseObj( hbitmap ); - } + X_PHYSBITMAP *ret; + + wine_tsx11_lock(); + if (XFindContext( gdi_display, (XID)hbitmap, bitmap_context, (char **)&ret )) ret = NULL; + wine_tsx11_unlock(); return ret; } @@ -462,25 +445,18 @@ X_PHYSBITMAP *X11DRV_get_phys_bitmap( HBITMAP hbitmap ) /*********************************************************************** * X11DRV_init_phys_bitmap * - * Initialize the X physical bitmap info if necessary. + * Initialize the X physical bitmap info. */ X_PHYSBITMAP *X11DRV_init_phys_bitmap( HBITMAP hbitmap ) { - X_PHYSBITMAP *ret = NULL; - BITMAPOBJ *bmp = GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); - if (bmp) + X_PHYSBITMAP *ret; + + if ((ret = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret) )) != NULL) { - if (!(ret = bmp->physBitmap)) - { - if ((ret = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret) )) != NULL) - { - ret->hbitmap = hbitmap; - ret->pixmap = 0; - ret->pixmap_depth = bmp->bitmap.bmBitsPixel; - bmp->physBitmap = ret; - } - } - GDI_ReleaseObj( hbitmap ); + ret->hbitmap = hbitmap; + wine_tsx11_lock(); + XSaveContext( gdi_display, (XID)hbitmap, bitmap_context, (char *)ret ); + wine_tsx11_unlock(); } return ret; }