winex11: Allocate image data from the process heap where possible.

This commit is contained in:
Alexandre Julliard 2008-08-29 13:34:11 +02:00
parent 816f57cbb1
commit 90ef43ab26
4 changed files with 33 additions and 18 deletions

View File

@ -896,7 +896,7 @@ static int BITBLT_GetSrcAreaStretch( X11DRV_PDEVICE *physDevSrc, X11DRV_PDEVICE
XPutImage( gdi_display, pixmap, gc, imageDst, 0, 0, 0, 0, XPutImage( gdi_display, pixmap, gc, imageDst, 0, 0, 0, 0,
rectDst.right - rectDst.left, rectDst.bottom - rectDst.top ); rectDst.right - rectDst.left, rectDst.bottom - rectDst.top );
XDestroyImage( imageSrc ); XDestroyImage( imageSrc );
XDestroyImage( imageDst ); X11DRV_DIB_DestroyXImage( imageDst );
wine_tsx11_unlock(); wine_tsx11_unlock();
return 0; /* no exposure events generated */ 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, XPutImage( gdi_display, pixmap, gc, imageDst,
0, 0, 0, 0, width, height ); 0, 0, 0, 0, width, height );
XDestroyImage( imageSrc ); XDestroyImage( imageSrc );
XDestroyImage( imageDst ); X11DRV_DIB_DestroyXImage( imageDst );
wine_tsx11_unlock(); wine_tsx11_unlock();
} }
} }

View File

@ -316,7 +316,7 @@ LONG X11DRV_SetBitmapBits( HBITMAP hbitmap, const void *bits, LONG count )
wine_tsx11_lock(); wine_tsx11_lock();
image = XCreateImage( gdi_display, visual, physBitmap->pixmap_depth, ZPixmap, 0, NULL, image = XCreateImage( gdi_display, visual, physBitmap->pixmap_depth, ZPixmap, 0, NULL,
bitmap.bmWidth, height, 32, 0 ); 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"); WARN("No memory to create image data.\n");
XDestroyImage( image ); XDestroyImage( image );
@ -407,7 +407,9 @@ LONG X11DRV_SetBitmapBits( HBITMAP hbitmap, const void *bits, LONG count )
} }
XPutImage( gdi_display, physBitmap->pixmap, BITMAP_GC(physBitmap), XPutImage( gdi_display, physBitmap->pixmap, BITMAP_GC(physBitmap),
image, 0, 0, 0, 0, bitmap.bmWidth, height ); 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(); wine_tsx11_unlock();
return count; return count;
} }

View File

@ -221,18 +221,35 @@ int bitmap_info_size( const BITMAPINFO * info, WORD coloruse )
XImage *X11DRV_DIB_CreateXImage( int width, int height, int depth ) XImage *X11DRV_DIB_CreateXImage( int width, int height, int depth )
{ {
int width_bytes; int width_bytes;
XImage *image; XImage *image = NULL;
void *data;
wine_tsx11_lock(); wine_tsx11_lock();
width_bytes = X11DRV_DIB_GetXImageWidthBytes( width, depth ); width_bytes = X11DRV_DIB_GetXImageWidthBytes( width, depth );
image = XCreateImage( gdi_display, visual, depth, ZPixmap, 0, data = HeapAlloc( GetProcessHeap(), 0, height * width_bytes );
calloc( height, width_bytes ), if (data) image = XCreateImage( gdi_display, visual, depth, ZPixmap, 0,
width, height, 32, width_bytes ); data, width, height, 32, width_bytes );
if (!image) HeapFree( GetProcessHeap(), 0, data );
wine_tsx11_unlock(); wine_tsx11_unlock();
return image; 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 * DIB_GetBitmapInfoEx
* *
@ -3520,7 +3537,7 @@ static int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr )
else { else {
bmpImage = XCreateImage( gdi_display, visual, descr->depth, ZPixmap, 0, NULL, bmpImage = XCreateImage( gdi_display, visual, descr->depth, ZPixmap, 0, NULL,
descr->infoWidth, lines, 32, 0 ); 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) { if(bmpImage->data == NULL) {
ERR("Out of memory!\n"); ERR("Out of memory!\n");
XDestroyImage( bmpImage ); 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->xSrc, descr->ySrc, descr->xDest, descr->yDest,
descr->width, descr->height ); descr->width, descr->height );
} }
if (!descr->image) XDestroyImage( bmpImage ); if (!descr->image) X11DRV_DIB_DestroyXImage( bmpImage );
wine_tsx11_unlock(); wine_tsx11_unlock();
return lines; return lines;
} }
@ -3649,7 +3666,7 @@ static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr )
else { else {
bmpImage = XCreateImage( gdi_display, visual, descr->depth, ZPixmap, 0, NULL, bmpImage = XCreateImage( gdi_display, visual, descr->depth, ZPixmap, 0, NULL,
descr->infoWidth, lines, 32, 0 ); 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) { if(bmpImage->data == NULL) {
ERR("Out of memory!\n"); ERR("Out of memory!\n");
XDestroyImage( bmpImage ); XDestroyImage( bmpImage );
@ -3766,12 +3783,7 @@ static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr )
break; break;
} }
if (!descr->image) if (!descr->image) X11DRV_DIB_DestroyXImage( bmpImage );
{
wine_tsx11_lock();
XDestroyImage( bmpImage );
wine_tsx11_unlock();
}
return lines; return lines;
} }
@ -4751,7 +4763,7 @@ void X11DRV_DIB_DeleteDIBSection(X_PHYSBITMAP *physBitmap, DIBSECTION *dib)
} }
else else
#endif #endif
XDestroyImage( physBitmap->image ); X11DRV_DIB_DestroyXImage( physBitmap->image );
wine_tsx11_unlock(); wine_tsx11_unlock();
} }

View File

@ -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 int bitmap_info_size( const BITMAPINFO * info, WORD coloruse );
extern XImage *X11DRV_DIB_CreateXImage( int width, int height, int depth ); 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_CreateDIBFromBitmap(HDC hdc, HBITMAP hBmp);
extern HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc); extern HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc);
extern Pixmap X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB, HDC hdc ); extern Pixmap X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB, HDC hdc );