Commit 65e4d345 authored by Alexandre Julliard's avatar Alexandre Julliard

Merged X11DRV_BITMAP_CreateBitmapHeaderFromPixmap into

X11DRV_DIB_CreateDIBFromPixmap and simplified the code a bit.
parent 6c42be25
...@@ -433,56 +433,6 @@ BOOL X11DRV_DeleteBitmap( HBITMAP hbitmap ) ...@@ -433,56 +433,6 @@ BOOL X11DRV_DeleteBitmap( HBITMAP hbitmap )
return TRUE; return TRUE;
} }
/**************************************************************************
* X11DRV_BITMAP_CreateBitmapHeaderFromPixmap
*
* Allocates an HBITMAP which references the Pixmap passed in.
* Note: This function makes the bitmap an owner of the Pixmap so subsequently
* calling DeleteObject on this will free the Pixmap as well.
*/
HBITMAP X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(HDC hdc, Pixmap pixmap)
{
HDC hdcMem;
Pixmap old_pixmap;
HBITMAP hBmp = 0, old;
Window root;
int x,y; /* Unused */
unsigned border_width; /* Unused */
unsigned int depth, width, height;
/* Get the Pixmap dimensions and bit depth */
wine_tsx11_lock();
if (!XGetGeometry(gdi_display, pixmap, &root, &x, &y, &width, &height,
&border_width, &depth)) depth = 0;
wine_tsx11_unlock();
if (!depth) goto END;
TRACE("\tPixmap properties: width=%d, height=%d, depth=%d\n",
width, height, depth);
/*
* Create an HBITMAP with the same dimensions and BPP as the pixmap,
* and make it a container for the pixmap passed.
*/
hBmp = CreateBitmap( width, height, 1, depth, NULL );
/* force bitmap to be owned by a screen DC */
hdcMem = CreateCompatibleDC( hdc );
old = SelectObject( hdcMem, 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 );
END:
TRACE("\tReturning HBITMAP %p\n", hBmp);
return hBmp;
}
/*********************************************************************** /***********************************************************************
* X11DRV_set_pixmap * X11DRV_set_pixmap
......
...@@ -1216,7 +1216,7 @@ HANDLE X11DRV_CLIPBOARD_ImportXAPIXMAP(LPBYTE lpdata, UINT cBytes) ...@@ -1216,7 +1216,7 @@ HANDLE X11DRV_CLIPBOARD_ImportXAPIXMAP(LPBYTE lpdata, UINT cBytes)
HWND hwnd = GetOpenClipboardWindow(); HWND hwnd = GetOpenClipboardWindow();
HDC hdc = GetDC(hwnd); HDC hdc = GetDC(hwnd);
hTargetImage = X11DRV_DIB_CreateDIBFromPixmap(*pPixmap, hdc, TRUE); hTargetImage = X11DRV_DIB_CreateDIBFromPixmap(*pPixmap, hdc);
ReleaseDC(hwnd, hdc); ReleaseDC(hwnd, hdc);
......
...@@ -5048,21 +5048,46 @@ HGLOBAL X11DRV_DIB_CreateDIBFromBitmap(HDC hdc, HBITMAP hBmp) ...@@ -5048,21 +5048,46 @@ HGLOBAL X11DRV_DIB_CreateDIBFromBitmap(HDC hdc, HBITMAP hBmp)
* X11DRV_DIB_CreateDIBFromPixmap * X11DRV_DIB_CreateDIBFromPixmap
* *
* Allocates a packed DIB and copies the Pixmap data into it. * Allocates a packed DIB and copies the Pixmap data into it.
* If bDeletePixmap is TRUE, the Pixmap passed in is deleted after the conversion. * The Pixmap passed in is deleted after the conversion.
*/ */
HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc, BOOL bDeletePixmap) HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc)
{ {
HBITMAP hBmp = 0; HDC hdcMem;
BITMAPOBJ *pBmp = NULL; Pixmap old_pixmap;
HBITMAP hBmp = 0, old;
HGLOBAL hPackedDIB = 0; HGLOBAL hPackedDIB = 0;
Window root;
int x,y; /* Unused */
unsigned border_width; /* Unused */
unsigned int depth, width, height;
/* Allocates an HBITMAP which references the Pixmap passed to us */ /* Get the Pixmap dimensions and bit depth */
hBmp = X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(hdc, pixmap); wine_tsx11_lock();
if (!hBmp) if (!XGetGeometry(gdi_display, pixmap, &root, &x, &y, &width, &height,
{ &border_width, &depth)) depth = 0;
TRACE("\tCould not create bitmap header for Pixmap\n"); wine_tsx11_unlock();
goto END; if (!depth) return 0;
}
TRACE("\tPixmap properties: width=%d, height=%d, depth=%d\n",
width, height, depth);
/*
* Create an HBITMAP with the same dimensions and BPP as the pixmap,
* and make it a container for the pixmap passed.
*/
hBmp = CreateBitmap( width, height, 1, depth, NULL );
/* force bitmap to be owned by a screen DC */
hdcMem = CreateCompatibleDC( hdc );
old = SelectObject( hdcMem, 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 );
/* /*
* Create a packed DIB from the Pixmap wrapper bitmap created above. * Create a packed DIB from the Pixmap wrapper bitmap created above.
...@@ -5071,22 +5096,11 @@ HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc, BOOL bDeletePixma ...@@ -5071,22 +5096,11 @@ HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc, BOOL bDeletePixma
*/ */
hPackedDIB = X11DRV_DIB_CreateDIBFromBitmap(hdc, hBmp); hPackedDIB = X11DRV_DIB_CreateDIBFromBitmap(hdc, hBmp);
/* Get a pointer to the BITMAPOBJ structure */
pBmp = (BITMAPOBJ *)GDI_GetObjPtr( hBmp, BITMAP_MAGIC );
/* We can now get rid of the HBITMAP wrapper we created earlier. /* We can now get rid of the HBITMAP wrapper we created earlier.
* Note: Simply calling DeleteObject will free the embedded Pixmap as well. * Note: Simply calling DeleteObject will free the embedded Pixmap as well.
*/ */
if (!bDeletePixmap)
{
/* Clear the physBitmap to prevent the Pixmap from being deleted by DeleteObject */
X11DRV_set_pixmap( hBmp, 0 );
pBmp->funcs = NULL;
}
GDI_ReleaseObj( hBmp );
DeleteObject(hBmp); DeleteObject(hBmp);
END:
TRACE("\tReturning packed DIB %p\n", hPackedDIB); TRACE("\tReturning packed DIB %p\n", hPackedDIB);
return hPackedDIB; return hPackedDIB;
} }
...@@ -5099,46 +5113,24 @@ END: ...@@ -5099,46 +5113,24 @@ END:
*/ */
Pixmap X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB, HDC hdc ) Pixmap X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB, HDC hdc )
{ {
Pixmap pixmap = None; Pixmap pixmap;
HBITMAP hBmp = 0; HBITMAP hBmp;
BITMAPOBJ *pBmp = NULL; LPBITMAPINFO pbmi;
LPBYTE pPackedDIB = NULL;
LPBITMAPINFO pbmi = NULL;
LPBITMAPINFOHEADER pbmiHeader = NULL;
LPBYTE pbits = NULL;
/* Get a pointer to the packed DIB's data */
pPackedDIB = (LPBYTE)GlobalLock(hPackedDIB);
pbmiHeader = (LPBITMAPINFOHEADER)pPackedDIB;
pbmi = (LPBITMAPINFO)pPackedDIB;
pbits = (LPBYTE)(pPackedDIB
+ X11DRV_DIB_BitmapInfoSize( (LPBITMAPINFO)pbmiHeader, DIB_RGB_COLORS ));
/* Create a DDB from the DIB */ /* Create a DDB from the DIB */
hBmp = CreateDIBitmap(hdc, pbmi = GlobalLock(hPackedDIB);
pbmiHeader, hBmp = CreateDIBitmap(hdc, &pbmi->bmiHeader, CBM_INIT,
CBM_INIT, (LPBYTE)pbmi + X11DRV_DIB_BitmapInfoSize( pbmi, DIB_RGB_COLORS ),
(LPVOID)pbits, pbmi, DIB_RGB_COLORS);
pbmi,
DIB_RGB_COLORS);
GlobalUnlock(hPackedDIB); GlobalUnlock(hPackedDIB);
TRACE("CreateDIBitmap returned %p\n", hBmp);
/* Retrieve the internal Pixmap from the DDB */
pBmp = (BITMAPOBJ *) GDI_GetObjPtr( hBmp, BITMAP_MAGIC );
/* clear the physBitmap so that we can steal its pixmap */ /* clear the physBitmap so that we can steal its pixmap */
pixmap = X11DRV_set_pixmap( hBmp, 0 ); pixmap = X11DRV_set_pixmap( hBmp, 0 );
pBmp->funcs = NULL;
/* Delete the DDB we created earlier now that we have stolen its pixmap */ /* Delete the DDB we created earlier now that we have stolen its pixmap */
GDI_ReleaseObj( hBmp );
DeleteObject(hBmp); DeleteObject(hBmp);
TRACE("\tReturning Pixmap %ld\n", pixmap); TRACE("Returning Pixmap %ld\n", pixmap);
return pixmap; return pixmap;
} }
...@@ -202,11 +202,9 @@ extern void X11DRV_BITMAP_Init(void); ...@@ -202,11 +202,9 @@ extern void X11DRV_BITMAP_Init(void);
extern void X11DRV_FONT_Init( int log_pixels_x, int log_pixels_y ); extern void X11DRV_FONT_Init( int log_pixels_x, int log_pixels_y );
extern int X11DRV_DIB_BitmapInfoSize( const BITMAPINFO * info, WORD coloruse ); extern int X11DRV_DIB_BitmapInfoSize( const BITMAPINFO * info, WORD coloruse );
extern XImage *X11DRV_BITMAP_GetXImage( const struct tagBITMAPOBJ *bmp );
extern XImage *X11DRV_DIB_CreateXImage( int width, int height, int depth ); extern XImage *X11DRV_DIB_CreateXImage( int width, int height, int depth );
extern HBITMAP X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(HDC hdc, Pixmap pixmap);
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, BOOL bDeletePixmap); 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 );
extern Pixmap X11DRV_set_pixmap( HBITMAP hbitmap, Pixmap pixmap ); extern Pixmap X11DRV_set_pixmap( HBITMAP hbitmap, Pixmap pixmap );
extern Pixmap X11DRV_get_pixmap( HBITMAP hbitmap ); extern Pixmap X11DRV_get_pixmap( HBITMAP hbitmap );
......
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