[4/10] x11drv / user : Draw the cursor using the 32-bits handle

H. Verbeet hverbeet at gmail.com
Sat Aug 5 16:39:27 CDT 2006


This draws the cursor using the 32-bits handle instead of the 16-bits one.
-------------- next part --------------
diff --git a/dlls/user/cursoricon.c b/dlls/user/cursoricon.c
index d58dedc..edb74cc 100644
--- a/dlls/user/cursoricon.c
+++ b/dlls/user/cursoricon.c
@@ -149,6 +149,8 @@ typedef struct {
     struct list     entry32;
 } cursor_map_entry_t;
 
+static int get_bitmap_width_bytes( int width, int bpp );
+
 static struct list cursor16to32[CURSOR_HASH_SIZE];
 static struct list cursor32to16[CURSOR_HASH_SIZE];
 
@@ -318,6 +320,64 @@ static BOOL get_cursor_frame( HCURSOR cu
     return TRUE;
 }
 
+/* Retrieve a cursor and all its frames from the server */
+static cursor_t *get_cursor_object( HCURSOR handle )
+{
+    unsigned int i;
+    cursor_t *cursor = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(cursor_t) );
+
+    SERVER_START_REQ(get_cursor_info)
+    {
+        req->handle = handle;
+        if (!wine_server_call_err( req ))
+        {
+            cursor->num_frames = reply->num_frames;
+            cursor->delay = reply->delay;
+        }
+    }
+    SERVER_END_REQ;
+
+    if (!cursor->num_frames)
+    {
+        HeapFree( GetProcessHeap(), 0, cursor );
+        return NULL;
+    }
+
+    cursor->frames = HeapAlloc( GetProcessHeap(), 0, cursor->num_frames * sizeof(cursor_frame_t) );
+    for (i = 0; i < cursor->num_frames; ++i)
+    {
+        if (!get_cursor_frame( handle, i, &cursor->frames[i] ))
+        {
+            unsigned int j;
+
+            for (j = 0; j < i; ++j)
+            {
+                HeapFree( GetProcessHeap(), 0, cursor->frames[j].bits );
+            }
+            HeapFree( GetProcessHeap(), 0, cursor->frames );
+            HeapFree( GetProcessHeap(), 0, cursor );
+
+            return NULL;
+        }
+    }
+
+    return cursor;
+}
+
+static void destroy_cursor_object( cursor_t *cursor )
+{
+    unsigned int i;
+
+    if (!cursor) return;
+
+    for (i = 0; i < cursor->num_frames; ++i)
+    {
+        HeapFree( GetProcessHeap(), 0, cursor->frames[i].bits );
+    }
+    HeapFree( GetProcessHeap(), 0, cursor->frames );
+    HeapFree( GetProcessHeap(), 0, cursor );
+}
+
 /* Lookup the cursor's 16-bit handle. Create one if it doesn't already exist. */
 HCURSOR16 get_cursor_handle16( HCURSOR cursor32, BOOL create )
 {
@@ -388,6 +448,36 @@ HCURSOR get_cursor_handle32( HCURSOR16 c
     return 0;
 }
 
+static void update_cursor_32from16( HCURSOR cursor32 )
+{
+    size_t bits_size;
+    HCURSOR16 cursor16;
+    cursor_frame_t frame;
+    CURSORICONINFO *info;
+
+    if (!cursor32) return;
+
+    cursor16 = get_cursor_handle16( cursor32, FALSE );
+    if (!cursor16) return;
+
+    info = (CURSORICONINFO *)GlobalLock16( cursor16 );
+    frame.xhot = info->ptHotSpot.x;
+    frame.yhot = info->ptHotSpot.y;
+    frame.width = info->nWidth;
+    frame.height = info->nHeight;
+    frame.and_width_bytes = get_bitmap_width_bytes( info->nWidth, 1 );
+    frame.xor_width_bytes = info->nWidthBytes;
+    frame.planes = info->bPlanes;
+    frame.bpp = info->bBitsPerPixel;
+    bits_size = (frame.and_width_bytes + frame.xor_width_bytes) * frame.height;
+    frame.bits = HeapAlloc( GetProcessHeap(), 0, bits_size );
+    CopyMemory( frame.bits, info + 1, bits_size );
+    GlobalUnlock16( cursor16 );
+
+    set_cursor_frame( cursor32, 0, &frame );
+    HeapFree( GetProcessHeap(), 0, frame.bits );
+}
+
 /***********************************************************************
  *             map_fileW
  *
@@ -1768,8 +1858,12 @@ HCURSOR WINAPI SetCursor( HCURSOR hCurso
     /* Change the cursor shape only if it is visible */
     if (thread_info->cursor_count >= 0)
     {
-        USER_Driver->pSetCursor( (CURSORICONINFO*)GlobalLock16(HCURSOR_16(hCursor)) );
-        GlobalUnlock16(HCURSOR_16(hCursor));
+        cursor_t *cursor;
+
+        update_cursor_32from16( hCursor );
+        cursor = get_cursor_object( hCursor );
+        USER_Driver->pSetCursor( cursor );
+        destroy_cursor_object( cursor );
     }
     return hOldCursor;
 }
@@ -1787,8 +1881,12 @@ INT WINAPI ShowCursor( BOOL bShow )
     {
         if (++thread_info->cursor_count == 0) /* Show it */
         {
-            USER_Driver->pSetCursor((CURSORICONINFO*)GlobalLock16(HCURSOR_16(thread_info->cursor)));
-            GlobalUnlock16(HCURSOR_16(thread_info->cursor));
+            cursor_t *cursor;
+
+            update_cursor_32from16( thread_info->cursor );
+            cursor = get_cursor_object( thread_info->cursor );
+            USER_Driver->pSetCursor( cursor );
+            destroy_cursor_object( cursor );
         }
     }
     else
diff --git a/dlls/user/display.c b/dlls/user/display.c
index 4288738..3254c43 100644
--- a/dlls/user/display.c
+++ b/dlls/user/display.c
@@ -50,7 +50,7 @@ WORD WINAPI DISPLAY_Inquire(LPCURSORINFO
 /***********************************************************************
  *           SetCursor			(DISPLAY.102)
  */
-VOID WINAPI DISPLAY_SetCursor( struct tagCURSORICONINFO *lpCursor )
+VOID WINAPI DISPLAY_SetCursor( const struct cursor_t *lpCursor )
 {
     USER_Driver->pSetCursor(lpCursor);
 }
diff --git a/dlls/user/driver.c b/dlls/user/driver.c
index 15f2e92..30286a8 100644
--- a/dlls/user/driver.c
+++ b/dlls/user/driver.c
@@ -215,7 +215,7 @@ static SHORT nulldrv_VkKeyScanEx( WCHAR 
     return -1;
 }
 
-static void nulldrv_SetCursor( struct tagCURSORICONINFO *info )
+static void nulldrv_SetCursor( const struct cursor_t *cursor )
 {
 }
 
@@ -533,9 +533,9 @@ static SHORT loaderdrv_VkKeyScanEx( WCHA
     return load_driver()->pVkKeyScanEx( ch, layout );
 }
 
-static void loaderdrv_SetCursor( struct tagCURSORICONINFO *info )
+static void loaderdrv_SetCursor( const struct cursor_t *cursor )
 {
-    load_driver()->pSetCursor( info );
+    load_driver()->pSetCursor( cursor );
 }
 
 static BOOL loaderdrv_GetCursorPos( LPPOINT pt )
diff --git a/dlls/user/user_private.h b/dlls/user/user_private.h
index f41e37a..c2b57a9 100644
--- a/dlls/user/user_private.h
+++ b/dlls/user/user_private.h
@@ -97,7 +97,7 @@ enum wine_internal_message
     WM_WINE_LAST_DRIVER_MSG = 0x80001fff
 };
 
-struct tagCURSORICONINFO;
+struct cursor_t;
 
 typedef struct tagUSER_DRIVER {
     /* keyboard functions */
@@ -115,7 +115,7 @@ typedef struct tagUSER_DRIVER {
     BOOL   (*pUnloadKeyboardLayout)(HKL);
     SHORT  (*pVkKeyScanEx)(WCHAR, HKL);
     /* mouse functions */
-    void   (*pSetCursor)(struct tagCURSORICONINFO *);
+    void   (*pSetCursor)(const struct cursor_t *);
     BOOL   (*pGetCursorPos)(LPPOINT);
     BOOL   (*pSetCursorPos)(INT,INT);
     /* screen saver functions */
diff --git a/dlls/winex11.drv/mouse.c b/dlls/winex11.drv/mouse.c
index 1373a88..f9c3e54 100644
--- a/dlls/winex11.drv/mouse.c
+++ b/dlls/winex11.drv/mouse.c
@@ -356,7 +356,7 @@ void X11DRV_send_mouse_input( HWND hwnd,
  *
  * Create an X cursor from a Windows one.
  */
-static Cursor create_cursor( Display *display, CURSORICONINFO *ptr )
+static Cursor create_cursor( Display *display, const cursor_t *ptr )
 {
     Pixmap pixmapBits, pixmapMask, pixmapMaskInv, pixmapAll;
     XColor fg, bg;
@@ -377,12 +377,13 @@ static Cursor create_cursor( Display *di
     }
     else  /* Create the X cursor from the bits */
     {
+        cursor_frame_t *frame = &ptr->frames[0];
         XImage *image;
         GC gc;
 
         TRACE("Bitmap %dx%d planes=%d bpp=%d bytesperline=%d\n",
-            ptr->nWidth, ptr->nHeight, ptr->bPlanes, ptr->bBitsPerPixel,
-            ptr->nWidthBytes);
+            frame->width, frame->height, frame->planes, frame->bpp,
+            frame->xor_width_bytes);
         /* Create a pixmap and transfer all the bits to it */
 
         /* NOTE: Following hack works, but only because XFree depth
@@ -394,11 +395,11 @@ static Cursor create_cursor( Display *di
          *  the mask and the second is the image.
          */
         if (!(pixmapAll = XCreatePixmap( display, root_window,
-                  ptr->nWidth, ptr->nHeight * 2, 1 )))
+                  frame->width, frame->height * 2, 1 )))
             return 0;
         if (!(image = XCreateImage( display, visual,
-                1, ZPixmap, 0, (char *)(ptr + 1), ptr->nWidth,
-                ptr->nHeight * 2, 16, ptr->nWidthBytes/ptr->bBitsPerPixel)))
+                1, ZPixmap, 0, (char *)frame->bits, frame->width,
+                frame->height * 2, 16, frame->xor_width_bytes/frame->bpp)))
         {
             XFreePixmap( display, pixmapAll );
             return 0;
@@ -409,13 +410,13 @@ static Cursor create_cursor( Display *di
         image->bitmap_bit_order = MSBFirst;
         image->bitmap_unit = 16;
         _XInitImageFuncPtrs(image);
-        if (ptr->bPlanes * ptr->bBitsPerPixel == 1)
+        if (frame->planes * frame->bpp == 1)
         {
             /* A plain old white on black cursor. */
             fg.red = fg.green = fg.blue = 0xffff;
             bg.red = bg.green = bg.blue = 0x0000;
             XPutImage( display, pixmapAll, gc, image,
-                0, 0, 0, 0, ptr->nWidth, ptr->nHeight * 2 );
+                0, 0, 0, 0, frame->width, frame->height * 2 );
         }
         else
         {
@@ -427,7 +428,7 @@ static Cursor create_cursor( Display *di
             int     threshold, fgBits, bgBits, bitShifted;
             BYTE    pXorBits[128];   /* Up to 32x32 icons */
 
-            switch (ptr->bBitsPerPixel)
+            switch (frame->bpp)
             {
             case 24:
                 rbits = 8;
@@ -443,7 +444,7 @@ static Cursor create_cursor( Display *di
                 break;
             default:
                 FIXME("Currently no support for cursors with %d bits per pixel\n",
-                  ptr->bBitsPerPixel);
+                  frame->bpp);
                 XFreePixmap( display, pixmapAll );
                 XFreeGC( display, gc );
                 image->data = NULL;
@@ -451,23 +452,23 @@ static Cursor create_cursor( Display *di
                 return 0;
             }
             /* The location of the mask. */
-            theMask = (unsigned char *)(ptr + 1);
+            theMask = frame->bits;
             /* The mask should still be 1 bit per pixel. The color image
              * should immediately follow the mask.
              */
-            theImage = &theMask[ptr->nWidth/8 * ptr->nHeight];
+            theImage = &theMask[frame->width/8 * frame->height];
             rfg = gfg = bfg = rbg = gbg = bbg = 0;
             bitIndex = 0;
             byteIndex = 0;
             xorIndex = 0;
             fgBits = 0;
             bitShifted = 0x01;
-            xmax = (ptr->nWidth > 32) ? 32 : ptr->nWidth;
-            if (ptr->nWidth > 32) {
+            xmax = (frame->width > 32) ? 32 : frame->width;
+            if (frame->width > 32) {
                 ERR("Got a %dx%d cursor. Cannot handle larger than 32x32.\n",
-                  ptr->nWidth, ptr->nHeight);
+                  frame->width, frame->height);
             }
-            ymax = (ptr->nHeight > 32) ? 32 : ptr->nHeight;
+            ymax = (frame->height > 32) ? 32 : frame->height;
 
             memset(pXorBits, 0, 128);
             for (y=0; y<ymax; y++)
@@ -475,7 +476,7 @@ static Cursor create_cursor( Display *di
                 for (x=0; x<xmax; x++)
                 {
                    	red = green = blue = 0;
-                   	switch (ptr->bBitsPerPixel)
+                   	switch (frame->bpp)
                    	{
                    	case 24:
                    	    theChar = theImage[byteIndex++];
@@ -548,11 +549,11 @@ static Cursor create_cursor( Display *di
 
             /* Put the mask. */
             XPutImage( display, pixmapAll, gc, image,
-                   0, 0, 0, 0, ptr->nWidth, ptr->nHeight );
+                   0, 0, 0, 0, frame->width, frame->height );
             XSetFunction( display, gc, GXcopy );
             /* Put the image */
             XCopyArea( display, pixmapBits, pixmapAll, gc,
-                       0, 0, xmax, ymax, 0, ptr->nHeight );
+                       0, 0, xmax, ymax, 0, frame->height );
             XFreePixmap( display, pixmapBits );
         }
         image->data = NULL;
@@ -560,9 +561,9 @@ static Cursor create_cursor( Display *di
 
         /* Now create the 2 pixmaps for bits and mask */
 
-        pixmapBits = XCreatePixmap( display, root_window, ptr->nWidth, ptr->nHeight, 1 );
-        pixmapMask = XCreatePixmap( display, root_window, ptr->nWidth, ptr->nHeight, 1 );
-        pixmapMaskInv = XCreatePixmap( display, root_window, ptr->nWidth, ptr->nHeight, 1 );
+        pixmapBits = XCreatePixmap( display, root_window, frame->width, frame->height, 1 );
+        pixmapMask = XCreatePixmap( display, root_window, frame->width, frame->height, 1 );
+        pixmapMaskInv = XCreatePixmap( display, root_window, frame->width, frame->height, 1 );
 
         /* Make sure everything went OK so far */
 
@@ -594,36 +595,36 @@ static Cursor create_cursor( Display *di
              */
             XSetFunction( display, gc, GXcopy );
             XCopyArea( display, pixmapAll, pixmapBits, gc,
-                       0, 0, ptr->nWidth, ptr->nHeight, 0, 0 );
+                       0, 0, frame->width, frame->height, 0, 0 );
             XCopyArea( display, pixmapAll, pixmapMask, gc,
-                       0, 0, ptr->nWidth, ptr->nHeight, 0, 0 );
+                       0, 0, frame->width, frame->height, 0, 0 );
             XCopyArea( display, pixmapAll, pixmapMaskInv, gc,
-                       0, 0, ptr->nWidth, ptr->nHeight, 0, 0 );
+                       0, 0, frame->width, frame->height, 0, 0 );
             XSetFunction( display, gc, GXand );
             XCopyArea( display, pixmapAll, pixmapMaskInv, gc,
-                       0, ptr->nHeight, ptr->nWidth, ptr->nHeight, 0, 0 );
+                       0, frame->height, frame->width, frame->height, 0, 0 );
             XSetFunction( display, gc, GXandReverse );
             XCopyArea( display, pixmapAll, pixmapBits, gc,
-                       0, ptr->nHeight, ptr->nWidth, ptr->nHeight, 0, 0 );
+                       0, frame->height, frame->width, frame->height, 0, 0 );
             XSetFunction( display, gc, GXorReverse );
             XCopyArea( display, pixmapAll, pixmapMask, gc,
-                       0, ptr->nHeight, ptr->nWidth, ptr->nHeight, 0, 0 );
+                       0, frame->height, frame->width, frame->height, 0, 0 );
             /* Additional white */
             XSetFunction( display, gc, GXor );
             XCopyArea( display, pixmapMaskInv, pixmapMask, gc,
-                       0, 0, ptr->nWidth, ptr->nHeight, 1, 1 );
+                       0, 0, frame->width, frame->height, 1, 1 );
             XCopyArea( display, pixmapMaskInv, pixmapBits, gc,
-                       0, 0, ptr->nWidth, ptr->nHeight, 1, 1 );
+                       0, 0, frame->width, frame->height, 1, 1 );
             XSetFunction( display, gc, GXcopy );
 
             /* Make sure hotspot is valid */
-            hotspot.x = ptr->ptHotSpot.x;
-            hotspot.y = ptr->ptHotSpot.y;
-            if (hotspot.x < 0 || hotspot.x >= ptr->nWidth ||
-                hotspot.y < 0 || hotspot.y >= ptr->nHeight)
+            hotspot.x = frame->xhot;
+            hotspot.y = frame->yhot;
+            if (hotspot.x < 0 || hotspot.x >= frame->width ||
+                hotspot.y < 0 || hotspot.y >= frame->height)
             {
-                hotspot.x = ptr->nWidth / 2;
-                hotspot.y = ptr->nHeight / 2;
+                hotspot.x = frame->width / 2;
+                hotspot.y = frame->height / 2;
             }
             cursor = XCreatePixmapCursor( display, pixmapBits, pixmapMask,
                                           &fg, &bg, hotspot.x, hotspot.y );
@@ -644,7 +645,7 @@ static Cursor create_cursor( Display *di
 /***********************************************************************
  *		SetCursor (X11DRV.@)
  */
-void X11DRV_SetCursor( CURSORICONINFO *lpCursor )
+void X11DRV_SetCursor( const cursor_t *cursor_object )
 {
     Cursor cursor;
 
@@ -653,7 +654,7 @@ void X11DRV_SetCursor( CURSORICONINFO *l
         /* If in desktop mode, set the cursor on the desktop window */
 
         wine_tsx11_lock();
-        cursor = create_cursor( gdi_display, lpCursor );
+        cursor = create_cursor( gdi_display, cursor_object );
         if (cursor)
         {
             XDefineCursor( gdi_display, root_window, cursor );
@@ -668,7 +669,7 @@ void X11DRV_SetCursor( CURSORICONINFO *l
         struct x11drv_thread_data *data = x11drv_thread_data();
 
         wine_tsx11_lock();
-        cursor = create_cursor( data->display, lpCursor );
+        cursor = create_cursor( data->display, cursor_object );
         if (cursor)
         {
             if (data->cursor) XFreeCursor( data->display, data->cursor );


More information about the wine-patches mailing list