Module: wine Branch: master Commit: 90ef43ab26a9bac0ddb3aa9deaf75ad951e2c60a URL: http://source.winehq.org/git/wine.git/?a=commit;h=90ef43ab26a9bac0ddb3aa9dea...
Author: Alexandre Julliard julliard@winehq.org Date: Fri Aug 29 13:34:11 2008 +0200
winex11: Allocate image data from the process heap where possible.
---
dlls/winex11.drv/bitblt.c | 4 ++-- dlls/winex11.drv/bitmap.c | 6 ++++-- dlls/winex11.drv/dib.c | 40 ++++++++++++++++++++++++++-------------- dlls/winex11.drv/x11drv.h | 1 + 4 files changed, 33 insertions(+), 18 deletions(-)
diff --git a/dlls/winex11.drv/bitblt.c b/dlls/winex11.drv/bitblt.c index 8bbc252..dcde11b 100644 --- a/dlls/winex11.drv/bitblt.c +++ b/dlls/winex11.drv/bitblt.c @@ -896,7 +896,7 @@ static int BITBLT_GetSrcAreaStretch( X11DRV_PDEVICE *physDevSrc, X11DRV_PDEVICE XPutImage( gdi_display, pixmap, gc, imageDst, 0, 0, 0, 0, rectDst.right - rectDst.left, rectDst.bottom - rectDst.top ); XDestroyImage( imageSrc ); - XDestroyImage( imageDst ); + X11DRV_DIB_DestroyXImage( imageDst ); wine_tsx11_unlock(); return 0; /* no exposure events generated */ } @@ -1026,7 +1026,7 @@ static int BITBLT_GetSrcArea( X11DRV_PDEVICE *physDevSrc, X11DRV_PDEVICE *physDe XPutImage( gdi_display, pixmap, gc, imageDst, 0, 0, 0, 0, width, height ); XDestroyImage( imageSrc ); - XDestroyImage( imageDst ); + X11DRV_DIB_DestroyXImage( imageDst ); wine_tsx11_unlock(); } } diff --git a/dlls/winex11.drv/bitmap.c b/dlls/winex11.drv/bitmap.c index 0bcb087..32018c8 100644 --- a/dlls/winex11.drv/bitmap.c +++ b/dlls/winex11.drv/bitmap.c @@ -316,7 +316,7 @@ LONG X11DRV_SetBitmapBits( HBITMAP hbitmap, const void *bits, LONG count ) wine_tsx11_lock(); image = XCreateImage( gdi_display, visual, physBitmap->pixmap_depth, ZPixmap, 0, NULL, bitmap.bmWidth, height, 32, 0 ); - if (!(image->data = malloc(image->bytes_per_line * height))) + if (!(image->data = HeapAlloc( GetProcessHeap(), 0, image->bytes_per_line * height ))) { WARN("No memory to create image data.\n"); XDestroyImage( image ); @@ -407,7 +407,9 @@ LONG X11DRV_SetBitmapBits( HBITMAP hbitmap, const void *bits, LONG count ) } XPutImage( gdi_display, physBitmap->pixmap, BITMAP_GC(physBitmap), image, 0, 0, 0, 0, bitmap.bmWidth, height ); - XDestroyImage( image ); /* frees image->data too */ + HeapFree( GetProcessHeap(), 0, image->data ); + image->data = NULL; + XDestroyImage( image ); wine_tsx11_unlock(); return count; } diff --git a/dlls/winex11.drv/dib.c b/dlls/winex11.drv/dib.c index b2a5b5a..461da16 100644 --- a/dlls/winex11.drv/dib.c +++ b/dlls/winex11.drv/dib.c @@ -221,19 +221,36 @@ int bitmap_info_size( const BITMAPINFO * info, WORD coloruse ) XImage *X11DRV_DIB_CreateXImage( int width, int height, int depth ) { int width_bytes; - XImage *image; + XImage *image = NULL; + void *data;
wine_tsx11_lock(); width_bytes = X11DRV_DIB_GetXImageWidthBytes( width, depth ); - image = XCreateImage( gdi_display, visual, depth, ZPixmap, 0, - calloc( height, width_bytes ), - width, height, 32, width_bytes ); + data = HeapAlloc( GetProcessHeap(), 0, height * width_bytes ); + if (data) image = XCreateImage( gdi_display, visual, depth, ZPixmap, 0, + data, width, height, 32, width_bytes ); + if (!image) HeapFree( GetProcessHeap(), 0, data ); wine_tsx11_unlock(); return image; }
/*********************************************************************** + * X11DRV_DIB_DestroyXImage + * + * Destroy an X image created with X11DRV_DIB_CreateXImage. + */ +void X11DRV_DIB_DestroyXImage( XImage *image ) +{ + HeapFree( GetProcessHeap(), 0, image->data ); + image->data = NULL; + wine_tsx11_lock(); + XDestroyImage( image ); + wine_tsx11_unlock(); +} + + +/*********************************************************************** * DIB_GetBitmapInfoEx * * Get the info from a bitmap header. @@ -3520,7 +3537,7 @@ static int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr ) else { bmpImage = XCreateImage( gdi_display, visual, descr->depth, ZPixmap, 0, NULL, descr->infoWidth, lines, 32, 0 ); - bmpImage->data = calloc( lines, bmpImage->bytes_per_line ); + bmpImage->data = HeapAlloc( GetProcessHeap(), 0, lines * bmpImage->bytes_per_line ); if(bmpImage->data == NULL) { ERR("Out of memory!\n"); XDestroyImage( bmpImage ); @@ -3628,7 +3645,7 @@ static int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr ) descr->xSrc, descr->ySrc, descr->xDest, descr->yDest, descr->width, descr->height ); } - if (!descr->image) XDestroyImage( bmpImage ); + if (!descr->image) X11DRV_DIB_DestroyXImage( bmpImage ); wine_tsx11_unlock(); return lines; } @@ -3649,7 +3666,7 @@ static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr ) else { bmpImage = XCreateImage( gdi_display, visual, descr->depth, ZPixmap, 0, NULL, descr->infoWidth, lines, 32, 0 ); - bmpImage->data = calloc( lines, bmpImage->bytes_per_line ); + bmpImage->data = HeapAlloc( GetProcessHeap(), 0, lines * bmpImage->bytes_per_line ); if(bmpImage->data == NULL) { ERR("Out of memory!\n"); XDestroyImage( bmpImage ); @@ -3766,12 +3783,7 @@ static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr ) break; }
- if (!descr->image) - { - wine_tsx11_lock(); - XDestroyImage( bmpImage ); - wine_tsx11_unlock(); - } + if (!descr->image) X11DRV_DIB_DestroyXImage( bmpImage ); return lines; }
@@ -4751,7 +4763,7 @@ void X11DRV_DIB_DeleteDIBSection(X_PHYSBITMAP *physBitmap, DIBSECTION *dib) } else #endif - XDestroyImage( physBitmap->image ); + X11DRV_DIB_DestroyXImage( physBitmap->image ); wine_tsx11_unlock(); }
diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h index 7bcec06..8f5c828 100644 --- a/dlls/winex11.drv/x11drv.h +++ b/dlls/winex11.drv/x11drv.h @@ -237,6 +237,7 @@ extern void X11DRV_FONT_Init( int log_pixels_x, int log_pixels_y );
extern int bitmap_info_size( const BITMAPINFO * info, WORD coloruse ); extern XImage *X11DRV_DIB_CreateXImage( int width, int height, int depth ); +extern void X11DRV_DIB_DestroyXImage( XImage *image ); extern HGLOBAL X11DRV_DIB_CreateDIBFromBitmap(HDC hdc, HBITMAP hBmp); extern HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc); extern Pixmap X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB, HDC hdc );