From: Erich Hoover Subject: [PATCH 3/3] winex11: Add support for animated cursors in X11 driver. Message-Id: Date: Sun, 26 Sep 2010 15:27:44 -0600 Real Name: Erich Hoover Description: Use DrawIconEx to extract the multiple frames of an animated cursor. Please note that this patch does not add support for the delay between frames, as I have not yet found a good way to extract this information. ChangeLog: winex11: Add support for animated cursors in X11 driver. From 70f49c5609af3e9205367c97f37220ab3e1eba4d Mon Sep 17 00:00:00 2001 From: Erich Hoover Date: Sun, 26 Sep 2010 15:10:00 -0600 Subject: winex11: Add support for animated cursors in X11 driver. --- dlls/winex11.drv/mouse.c | 114 ++++++++++++++++++++++++++++++++++++---------- 1 files changed, 89 insertions(+), 25 deletions(-) diff --git a/dlls/winex11.drv/mouse.c b/dlls/winex11.drv/mouse.c index 922df65..79eb8b8 100644 --- a/dlls/winex11.drv/mouse.c +++ b/dlls/winex11.drv/mouse.c @@ -32,6 +32,9 @@ static void *xcursor_handle; MAKE_FUNCPTR(XcursorImageCreate); MAKE_FUNCPTR(XcursorImageDestroy); MAKE_FUNCPTR(XcursorImageLoadCursor); +MAKE_FUNCPTR(XcursorImagesCreate); +MAKE_FUNCPTR(XcursorImagesDestroy); +MAKE_FUNCPTR(XcursorImagesLoadCursor); # undef MAKE_FUNCPTR #endif /* SONAME_LIBXCURSOR */ @@ -114,6 +117,9 @@ void X11DRV_Xcursor_Init(void) LOAD_FUNCPTR(XcursorImageCreate); LOAD_FUNCPTR(XcursorImageDestroy); LOAD_FUNCPTR(XcursorImageLoadCursor); + LOAD_FUNCPTR(XcursorImagesCreate); + LOAD_FUNCPTR(XcursorImagesDestroy); + LOAD_FUNCPTR(XcursorImagesLoadCursor); #undef LOAD_FUNCPTR #endif /* SONAME_LIBXCURSOR */ } @@ -470,32 +476,35 @@ void X11DRV_send_mouse_input( HWND hwnd, DWORD flags, DWORD x, DWORD y, #ifdef SONAME_LIBXCURSOR /*********************************************************************** - * create_xcursor_cursor + * create_xcursor_frame * - * Use Xcursor to create an X cursor from a Windows one. + * Use Xcursor to create a frame of an X cursor from a Windows one. */ -static Cursor create_xcursor_cursor( HDC hdc, ICONINFO *icon, int width, int height ) +static XcursorImage *create_xcursor_frame( ICONINFO *iinfo, HANDLE icon, int width, int height, int istep ) { + HBITMAP hbmColor = 0, hbmMask = 0; + XcursorImage *image, *ret = NULL; + unsigned char *mem_bits; int x, y, i, has_alpha; - BITMAPINFO *info; - Cursor cursor; - XcursorImage *image; XcursorPixel *ptr; + BITMAPINFO *info; + HDC hdc; - if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) return 0; + if (!(hdc = CreateCompatibleDC( 0 ))) return 0; + if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) goto cleanup; wine_tsx11_lock(); image = pXcursorImageCreate( width, height ); wine_tsx11_unlock(); if (!image) { - HeapFree( GetProcessHeap(), 0, info ); - return 0; + ERR("X11 failed to produce a cursor!\n"); + goto cleanup; } - image->xhot = icon->xHotspot; - image->yhot = icon->yHotspot; - image->delay = 0; + image->xhot = iinfo->xHotspot; + image->yhot = iinfo->yHotspot; + image->delay = 100; /* TODO: find a way to get the proper delay */ info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); info->bmiHeader.biWidth = width; @@ -508,35 +517,90 @@ static Cursor create_xcursor_cursor( HDC hdc, ICONINFO *icon, int width, int hei info->bmiHeader.biYPelsPerMeter = 0; info->bmiHeader.biClrUsed = 0; info->bmiHeader.biClrImportant = 0; - GetDIBits( hdc, icon->hbmColor, 0, height, image->pixels, info, DIB_RGB_COLORS ); + hbmColor = CreateDIBSection( hdc, info, DIB_RGB_COLORS, (VOID **) &mem_bits, NULL, 0); + if (!hbmColor) + { + ERR("Failed to create DIB section for image!\n"); + goto cleanup; + } + SelectObject( hdc, hbmColor ); + if (!DrawIconEx( hdc, 0, 0, icon, width, height, istep, NULL, DI_NORMAL )) + { + TRACE("Could not draw frame %d (walk past end of frames).\n", istep); + goto cleanup; + } + memcpy(image->pixels, mem_bits, info->bmiHeader.biSizeImage); for (i = 0, ptr = image->pixels; i < width * height; i++, ptr++) if ((has_alpha = (*ptr & 0xff000000) != 0)) break; if (!has_alpha) { - unsigned char *mask_bits; unsigned int width_bytes = (width + 31) / 32 * 4; /* generate alpha channel from the mask */ info->bmiHeader.biBitCount = 1; info->bmiHeader.biSizeImage = width_bytes * height; - if ((mask_bits = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage ))) + hbmMask = CreateDIBSection( hdc, info, DIB_RGB_COLORS, (VOID **) &mem_bits, NULL, 0); + if (!hbmMask) { - GetDIBits( hdc, icon->hbmMask, 0, height, mask_bits, info, DIB_RGB_COLORS ); - for (y = 0, ptr = image->pixels; y < height; y++) - for (x = 0; x < width; x++, ptr++) - if (!((mask_bits[y * width_bytes + x / 8] << (x % 8)) & 0x80)) - *ptr |= 0xff000000; - HeapFree( GetProcessHeap(), 0, mask_bits ); + ERR("Failed to create DIB section for mask!\n"); + goto cleanup; } + memset(mem_bits, 0xFF, info->bmiHeader.biSizeImage); + SelectObject( hdc, hbmMask ); + if (!DrawIconEx( hdc, 0, 0, icon, width, height, istep, NULL, DI_MASK )) + { + ERR("Failed to draw frame mask %d.\n", istep); + goto cleanup; + } + for (y = 0, ptr = image->pixels; y < height; y++) + for (x = 0; x < width; x++, ptr++) + if (!((mem_bits[y * width_bytes + x / 8] << (x % 8)) & 0x80)) + *ptr |= 0xff000000; } + ret = image; + +cleanup: + DeleteDC( hdc ); + if (hbmColor) + DeleteObject( hbmColor ); + if (hbmMask) + DeleteObject( hbmMask ); + if (ret == NULL) + pXcursorImageDestroy( image ); HeapFree( GetProcessHeap(), 0, info ); + return ret; +} +/*********************************************************************** + * create_xcursor_cursor + * + * Use Xcursor to create an X cursor from a Windows one. + */ +static Cursor create_xcursor_cursor( ICONINFO *iinfo, HANDLE icon, int width, int height ) +{ + XcursorImage **imgs, *image; + XcursorImages *images; + Cursor cursor = 0; + int nFrames = 0; + + if (!(imgs = HeapAlloc( GetProcessHeap(), 0, sizeof(XcursorImage*) ))) return 0; + do + { + image = create_xcursor_frame( iinfo, icon, width, height, nFrames ); + if (image && !HeapReAlloc( GetProcessHeap(), 0, imgs, nFrames*sizeof(XcursorImage*) )) goto done; + if (image) imgs[nFrames++] = image; + } while( image != 0 ); + images = pXcursorImagesCreate( nFrames ); + for (images->nimage = 0; images->nimage < nFrames; images->nimage++) + images->images[images->nimage] = imgs[images->nimage]; wine_tsx11_lock(); - cursor = pXcursorImageLoadCursor( gdi_display, image ); - pXcursorImageDestroy( image ); + cursor = pXcursorImagesLoadCursor( gdi_display, images ); wine_tsx11_unlock(); + +done: + HeapFree( GetProcessHeap(), 0, imgs ); return cursor; } @@ -774,7 +838,7 @@ static Cursor create_cursor( HANDLE handle ) if (info.hbmColor) { #ifdef SONAME_LIBXCURSOR - if (pXcursorImageLoadCursor) cursor = create_xcursor_cursor( hdc, &info, bm.bmWidth, bm.bmHeight ); + if (pXcursorImagesLoadCursor) cursor = create_xcursor_cursor( &info, handle, bm.bmWidth, bm.bmHeight ); #endif if (!cursor) cursor = create_xlib_cursor( hdc, &info, bm.bmWidth, bm.bmHeight ); DeleteObject( info.hbmColor ); -- 1.7.0.4