Commit 90ef43ab authored by Alexandre Julliard's avatar Alexandre Julliard

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

parent 816f57cb
......@@ -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();
}
}
......
......@@ -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;
}
......
......@@ -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();
}
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment