winex11: Factor out the 'alpha_zero' test and use it for legacy cursor support.

This commit is contained in:
Andrew Riedi 2008-12-30 17:41:17 -08:00 committed by Alexandre Julliard
parent 6bdcdc4232
commit 73393fab16
1 changed files with 47 additions and 33 deletions

View File

@ -399,6 +399,47 @@ void X11DRV_send_mouse_input( HWND hwnd, DWORD flags, DWORD x, DWORD y,
}
/***********************************************************************
* check_alpha_zero
*
* Generally 32 bit bitmaps have an alpha channel which is used in favor of the
* AND mask. However, if all pixels have alpha = 0x00, the bitmap is treated
* like one without alpha and the masks are used. As soon as one pixel has
* alpha != 0x00, and the mask ignored as described in the docs.
*
* This is most likely for applications which create the bitmaps with
* CreateDIBitmap, which creates a device dependent bitmap, so the format that
* arrives when loading depends on the screen's bpp. Apps that were written at
* 8 / 16 bpp times do not know about the 32 bit alpha, so they would get a
* completely transparent cursor on 32 bit displays.
*
* Non-32 bit bitmaps always use the AND mask.
*/
static BOOL check_alpha_zero(CURSORICONINFO *ptr, unsigned char *xor_bits)
{
int x, y;
unsigned char *xor_ptr;
if (ptr->bBitsPerPixel == 32)
{
for (y = 0; y < ptr->nHeight; ++y)
{
xor_ptr = xor_bits + (y * ptr->nWidthBytes);
for (x = 0; x < ptr->nWidth; ++x)
{
if (xor_ptr[3] != 0x00)
{
return FALSE;
}
xor_ptr+=4;
}
}
}
return TRUE;
}
#ifdef SONAME_LIBXCURSOR
/***********************************************************************
@ -434,7 +475,7 @@ static XcursorImage *create_cursor_image( CURSORICONINFO *ptr )
XcursorPixel *pixel_ptr;
XcursorImage *image;
unsigned char tmp;
BOOL alpha_zero = TRUE;
BOOL alpha_zero;
and_width_bytes = 2 * ((ptr->nWidth+15) / 16);
xor_width_bytes = ptr->nWidthBytes;
@ -447,36 +488,7 @@ static XcursorImage *create_cursor_image( CURSORICONINFO *ptr )
image = pXcursorImageCreate( ptr->nWidth, ptr->nHeight );
pixel_ptr = image->pixels;
/* Generally 32 bit bitmaps have an alpha channel which is used in favor
* of the AND mask. However, if all pixels have alpha = 0x00, the bitmap
* is treated like one without alpha and the masks are used. As soon as
* one pixel has alpha != 0x00, and the mask ignored as described in the
* docs.
*
* This is most likely for applications which create the bitmaps with
* CreateDIBitmap, which creates a device dependent bitmap, so the format
* that arrives when loading depends on the screen's bpp. Apps that were
* written at 8 / 16 bpp times do not know about the 32 bit alpha, so
* they would get a completely transparent cursor on 32 bit displays.
*
* Non-32 bit bitmaps always use the AND mask
*/
if(ptr->bBitsPerPixel == 32)
{
for (y = 0; alpha_zero && y < ptr->nHeight; ++y)
{
xor_ptr = xor_bits + (y * xor_width_bytes);
for (x = 0; x < ptr->nWidth; ++x)
{
if (xor_ptr[3] != 0x00)
{
alpha_zero = FALSE;
break;
}
xor_ptr+=4;
}
}
}
alpha_zero = check_alpha_zero(ptr, xor_bits);
/* On windows, to calculate the color for a pixel, first an AND is done
* with the background and the "and" bitmap, then an XOR with the "xor"
@ -618,6 +630,7 @@ static Cursor create_cursor( Display *display, CURSORICONINFO *ptr )
Cursor cursor = None;
POINT hotspot;
char *bitMask32 = NULL;
BOOL alpha_zero = TRUE;
#ifdef SONAME_LIBXCURSOR
if (pXcursorImageLoadCursor) return create_xcursor_cursor( display, ptr );
@ -733,6 +746,7 @@ static Cursor create_cursor( Display *display, CURSORICONINFO *ptr )
ptr->nWidth, ptr->nHeight);
}
ymax = (ptr->nHeight > 32) ? 32 : ptr->nHeight;
alpha_zero = check_alpha_zero(ptr, theImage);
memset(pXorBits, 0, 128);
for (y=0; y<ymax; y++)
@ -841,7 +855,7 @@ static Cursor create_cursor( Display *display, CURSORICONINFO *ptr )
/* Now create the 2 pixmaps for bits and mask */
pixmapBits = XCreatePixmap( display, root_window, ptr->nWidth, ptr->nHeight, 1 );
if (ptr->bBitsPerPixel != 32)
if (alpha_zero)
{
pixmapMaskInv = XCreatePixmap( display, root_window, ptr->nWidth, ptr->nHeight, 1 );
pixmapMask = XCreatePixmap( display, root_window, ptr->nWidth, ptr->nHeight, 1 );
@ -901,7 +915,6 @@ static Cursor create_cursor( Display *display, CURSORICONINFO *ptr )
pixmapMask = XCreateBitmapFromData( display, root_window,
bitMask32, ptr->nWidth,
ptr->nHeight );
HeapFree( GetProcessHeap(), 0, bitMask32 );
}
/* Make sure hotspot is valid */
@ -924,6 +937,7 @@ static Cursor create_cursor( Display *display, CURSORICONINFO *ptr )
if (pixmapBits) XFreePixmap( display, pixmapBits );
if (pixmapMask) XFreePixmap( display, pixmapMask );
if (pixmapMaskInv) XFreePixmap( display, pixmapMaskInv );
HeapFree( GetProcessHeap(), 0, bitMask32 );
XFreeGC( display, gc );
}
return cursor;