[Spice-devel] [spice-protocol PATCH 13/46] qxlhw: add qxlhw_push_cursor

Alon Levy alevy at redhat.com
Tue Apr 10 04:50:09 PDT 2012


cursor commands are now allocated on the stack in qxl_cursor.c and only
allocated on the pci bar in qxlhw_pci.
---
 src/qxl.h        |    1 -
 src/qxl_cursor.c |   58 ++++++++++++++++++++++--------------------------------
 src/qxlhw.c      |    5 +++++
 src/qxlhw.h      |    4 ++++
 src/qxlhw_pci.c  |   33 ++++++++++++++++++++++++++++++-
 5 files changed, 64 insertions(+), 37 deletions(-)

diff --git a/src/qxl.h b/src/qxl.h
index 4ca68a3..d72f64f 100644
--- a/src/qxl.h
+++ b/src/qxl.h
@@ -128,7 +128,6 @@ struct _qxl_screen_t
     /* These are the names QXL uses */
     
     struct qxl_ring *		command_ring;
-    struct qxl_ring *		cursor_ring;
     struct qxl_ring *		release_ring;
     
     int				num_modes;
diff --git a/src/qxl_cursor.c b/src/qxl_cursor.c
index 68ea3ce..5d8134f 100644
--- a/src/qxl_cursor.c
+++ b/src/qxl_cursor.c
@@ -29,50 +29,35 @@
 #endif
 
 #include <string.h>
+#include <cursorstr.h>
 #include "qxl.h"
 #include "qxl_ring.h"
-#include <cursorstr.h>
+#include "qxlhw.h"
 
 static void
 push_cursor (qxl_screen_t *qxl, struct QXLCursorCmd *cursor)
 {
-    struct QXLCommand cmd;
-
     /* See comment on push_command() in qxl_driver.c */
     if (qxl->pScrn->vtSema)
     {
-        cmd.type = QXL_CMD_CURSOR;
-        cmd.data = physical_address (qxl, cursor, qxl->main_mem_slot);
-      
-        qxl_ring_push (qxl->cursor_ring, &cmd);
+        qxlhw_push_cursor (qxl->hw, cursor);
     }
 }
 
-static struct QXLCursorCmd *
-qxl_alloc_cursor_cmd(qxl_screen_t *qxl)
-{
-    struct QXLCursorCmd *cmd =
-	qxl_allocnf (qxl, sizeof(struct QXLCursorCmd));
-
-    cmd->release_info.id = pointer_to_u64 (cmd) | 1;
-    
-    return cmd;
-}
-
 static void
 qxl_set_cursor_position(ScrnInfoPtr pScrn, int x, int y)
 {
     qxl_screen_t *qxl = pScrn->driverPrivate;
-    struct QXLCursorCmd *cmd = qxl_alloc_cursor_cmd(qxl);
+    struct QXLCursorCmd cmd;
 
     qxl->cur_x = x;
     qxl->cur_y = y;
     
-    cmd->type = QXL_CURSOR_MOVE;
-    cmd->u.position.x = qxl->cur_x + qxl->hot_x;
-    cmd->u.position.y = qxl->cur_y + qxl->hot_y;
+    cmd.type = QXL_CURSOR_MOVE;
+    cmd.u.position.x = qxl->cur_x + qxl->hot_x;
+    cmd.u.position.y = qxl->cur_y + qxl->hot_y;
     
-    push_cursor(qxl, cmd);
+    push_cursor(qxl, &cmd);
 }
 
 static void
@@ -94,10 +79,11 @@ qxl_load_cursor_argb (ScrnInfoPtr pScrn, CursorPtr pCurs)
     int h = pCurs->bits->height;
     int size = w * h * sizeof (CARD32);
 
-    struct QXLCursorCmd *cmd = qxl_alloc_cursor_cmd (qxl);
+    struct QXLCursorCmd cmd;
     struct QXLCursor *cursor =
-	qxl_allocnf(qxl, sizeof(struct QXLCursor) + size);
+        qxlhw_data_alloc(qxl->hw, sizeof(struct QXLCursor) + size);
 
+    memset(&cmd, 0, sizeof(cmd));
     cursor->header.unique = 0;
     cursor->header.type = SPICE_CURSOR_TYPE_ALPHA;
     cursor->header.width = w;
@@ -133,14 +119,14 @@ qxl_load_cursor_argb (ScrnInfoPtr pScrn, CursorPtr pCurs)
     qxl->hot_x = pCurs->bits->xhot;
     qxl->hot_y = pCurs->bits->yhot;
     
-    cmd->type = QXL_CURSOR_SET;
-    cmd->u.set.position.x = qxl->cur_x + qxl->hot_x;
-    cmd->u.set.position.y = qxl->cur_y + qxl->hot_y;
-    cmd->u.set.shape = physical_address (qxl, cursor, qxl->main_mem_slot);
-    cmd->u.set.visible = TRUE;
+    cmd.type = QXL_CURSOR_SET;
+    cmd.u.set.position.x = qxl->cur_x + qxl->hot_x;
+    cmd.u.set.position.y = qxl->cur_y + qxl->hot_y;
+    cmd.u.set.shape = pointer_to_u64(cursor);
+    cmd.u.set.visible = TRUE;
 
-    push_cursor(qxl, cmd);
-}    
+    push_cursor(qxl, &cmd);
+}
 
 static Bool
 qxl_use_hw_cursor (ScreenPtr pScrn, CursorPtr pCurs)
@@ -161,11 +147,13 @@ static void
 qxl_hide_cursor(ScrnInfoPtr pScrn)
 {
     qxl_screen_t *qxl = pScrn->driverPrivate;
-    struct QXLCursorCmd *cursor = qxl_alloc_cursor_cmd(qxl);
+    struct QXLCursorCmd cursor;
+
+    memset(&cursor, 0, sizeof(cursor));
 
-    cursor->type = QXL_CURSOR_HIDE;
+    cursor.type = QXL_CURSOR_HIDE;
 
-    push_cursor(qxl, cursor);
+    push_cursor(qxl, &cursor);
 }
 
 static void
diff --git a/src/qxlhw.c b/src/qxlhw.c
index 9706141..184cd7b 100644
--- a/src/qxlhw.c
+++ b/src/qxlhw.c
@@ -63,6 +63,11 @@ void qxlhw_update_area(struct qxlhw *base, int surface_id, struct QXLRect rect)
         base->update_area(base, surface_id, rect);
 }
 
+void qxlhw_push_cursor(struct qxlhw *base, struct QXLCursorCmd *base_cmd)
+{
+        base->push_cursor(base, base_cmd);
+}
+
 /* tried to avoid this. but qxl_surface.c wants to check when failing to find
  * a surface in the free list, which it populates using qxl_surface_alloc (should) */
 Bool qxlhw_handle_oom(struct qxlhw *base)
diff --git a/src/qxlhw.h b/src/qxlhw.h
index 741d951..730a623 100644
--- a/src/qxlhw.h
+++ b/src/qxlhw.h
@@ -21,6 +21,7 @@ struct qxlhw {
     void (*data_free)(struct qxlhw *base, void *p);
     void (*create_primary_surface)(struct qxlhw *base, QXLSurfaceCreate *create);
     void (*update_area)(struct qxlhw *base, int surface_id, struct QXLRect rect);
+    void (*push_cursor)(struct qxlhw *base, struct QXLCursorCmd *base_cmd);
     /* tried to avoid this. but qxl_surface.c wants to check when failing to
      * find a surface in the free list, which it populates using
      * qxl_surface_alloc (should) */
@@ -53,4 +54,7 @@ void qxlhw_data_free(struct qxlhw *base, void *p);
 
 Bool qxlhw_handle_oom(struct qxlhw *base);
 
+/* cursor */
+void qxlhw_push_cursor(struct qxlhw *base, QXLCursorCmd *base_cmd);
+
 #endif // QXLHW_H
diff --git a/src/qxlhw_pci.c b/src/qxlhw_pci.c
index ac8b6f8..d4b34c2 100644
--- a/src/qxlhw_pci.c
+++ b/src/qxlhw_pci.c
@@ -525,7 +525,6 @@ static void qxlhw_pci_reset(struct qxlhw *base)
 #endif
     base->qxl->mem_slots = hw->mem_slots;
     base->qxl->command_ring = hw->command_ring;
-    base->qxl->cursor_ring = hw->cursor_ring;
     base->qxl->release_ring = hw->release_ring;
     base->qxl->n_mem_slots = hw->n_mem_slots;
     base->qxl->slot_gen_bits = hw->slot_gen_bits;
@@ -618,6 +617,37 @@ static void qxlhw_pci_update_area(struct qxlhw *base, int surface_id, struct QXL
 #endif
 }
 
+static struct QXLCursorCmd *
+qxlhw_pci_alloc_cursor_cmd(struct qxlhw_pci *hw, QXLCursorCmd *base)
+{
+    struct QXLCursorCmd *cmd =
+	qxlhw_pci_allocnf (hw, hw->mem, sizeof(struct QXLCursorCmd));
+
+    memcpy(cmd, base, sizeof(*base));
+
+    cmd->release_info.id = pointer_to_u64 (cmd) | 1;
+
+    switch (cmd->type) {
+    case QXL_CURSOR_SET:
+        cmd->u.set.shape = qxlhw_physical_address (hw, (void *)cmd->u.set.shape,
+                                                   hw->main_mem_slot);
+        break;
+    }
+    return cmd;
+}
+
+static void qxlhw_pci_push_cursor(struct qxlhw *base, QXLCursorCmd *base_cmd)
+{
+    struct qxlhw_pci *hw = (struct qxlhw_pci *)base;
+    struct QXLCursorCmd *cursor = qxlhw_pci_alloc_cursor_cmd(hw, base_cmd);
+    struct QXLCommand cmd;
+
+    cmd.type = QXL_CMD_CURSOR;
+    cmd.data = qxlhw_physical_address (hw, cursor, hw->main_mem_slot);
+
+    qxl_ring_push (hw->cursor_ring, &cmd);
+}
+
 /* public entry point */
 struct qxlhw *create_qxlhw_pci(qxl_screen_t *qxl, ScrnInfoPtr pScrn)
 {
@@ -635,6 +665,7 @@ struct qxlhw *create_qxlhw_pci(qxl_screen_t *qxl, ScrnInfoPtr pScrn)
     base->data_free = qxlhw_pci_data_free;
     base->create_primary_surface = qxlhw_pci_create_primary_surface;
     base->update_area = qxlhw_pci_update_area;
+    base->push_cursor = qxlhw_pci_push_cursor;
     return base;
 }
 
-- 
1.7.9.3



More information about the Spice-devel mailing list