st/nine: Handle when cursor stride is not what is expected
authorAxel Davy <axel.davy@ens.fr>
Mon, 24 Oct 2016 19:48:13 +0000 (21:48 +0200)
committerAxel Davy <axel.davy@ens.fr>
Tue, 20 Dec 2016 22:44:21 +0000 (23:44 +0100)
SetCursor assumes for now a 32x32 argb cursor with pitch 128.
32x32 argb doesn't have pitch 128 on all hw, thus use a
temporary surface with the correct pitch when needed.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
src/gallium/state_trackers/nine/device9.c
src/gallium/state_trackers/nine/device9.h

index ddac548..a78d18e 100644 (file)
@@ -315,6 +315,11 @@ NineDevice9_ctor( struct NineDevice9 *This,
         This->cursor.image = pScreen->resource_create(pScreen, &tmpl);
         if (!This->cursor.image)
             return D3DERR_OUTOFVIDEOMEMORY;
+
+        /* For uploading 32x32 (argb) cursor */
+        This->cursor.hw_upload_temp = MALLOC(32 * 4 * 32);
+        if (!This->cursor.hw_upload_temp)
+            return D3DERR_OUTOFVIDEOMEMORY;
     }
 
     /* Create constant buffers. */
@@ -506,6 +511,8 @@ NineDevice9_dtor( struct NineDevice9 *This )
     FREE(This->state.vs_const_b);
     FREE(This->state.vs_const_f_swvp);
 
+    FREE(This->cursor.hw_upload_temp);
+
     if (This->swapchains) {
         for (i = 0; i < This->nswapchains; ++i)
             if (This->swapchains[i])
@@ -709,11 +716,20 @@ NineDevice9_SetCursorProperties( struct NineDevice9 *This,
                                  lock.pBits, lock.Pitch,
                                  This->cursor.w, This->cursor.h);
 
-        if (hw_cursor)
+        if (hw_cursor) {
+            void *data = lock.pBits;
+            /* SetCursor assumes 32x32 argb with pitch 128 */
+            if (lock.Pitch != 128) {
+                sfmt->unpack_rgba_8unorm(This->cursor.hw_upload_temp, 128,
+                                         lock.pBits, lock.Pitch,
+                                         32, 32);
+                data = This->cursor.hw_upload_temp;
+            }
             hw_cursor = ID3DPresent_SetCursor(This->swapchains[0]->present,
-                                              lock.pBits,
+                                              data,
                                               &This->cursor.hotspot,
                                               This->cursor.visible) == D3D_OK;
+        }
 
         NineSurface9_UnlockRect(surf);
     }
index 12be643..d698cee 100644 (file)
@@ -112,6 +112,7 @@ struct NineDevice9
         POINT pos;
         BOOL visible;
         boolean software;
+        void *hw_upload_temp;
     } cursor;
 
     struct {