[Spice-devel] [spice-protocol PATCH 20/46] qxlhw: qxl_surface: split qxlhw_image_alloc inside qxl_surface

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


---
 src/qxl_image.c |  181 +++++++++++++++++++++++++++++--------------------------
 1 file changed, 97 insertions(+), 84 deletions(-)

diff --git a/src/qxl_image.c b/src/qxl_image.c
index b0ffef9..8cd6e49 100644
--- a/src/qxl_image.c
+++ b/src/qxl_image.c
@@ -130,102 +130,115 @@ remove_image_info (image_info_t *info)
 #define MAX(a,b)  (((a) > (b))? (a) : (b))
 #define MIN(a,b)  (((a) < (b))? (a) : (b))
 
-struct QXLImage *
-qxl_image_create (qxl_screen_t *qxl, const uint8_t *data,
+static struct QXLImage *
+qxlhw_image_alloc(struct qxlhw *base, const uint8_t *data,
 		  int x, int y, int width, int height,
-		  int stride, int Bpp, Bool fallback)
+		  int stride, int Bpp, uint32_t *hash)
 {
-	uint32_t hash;
-	image_info_t *info;
-	struct QXLImage *image;
-	struct QXLDataChunk *head;
-	struct QXLDataChunk *tail;
-	int dest_stride = width * Bpp;
-	int h;
+    struct QXLImage *image;
+    struct qxlhw_mem image_mem;
+    struct QXLDataChunk *head;
+    struct QXLDataChunk *tail;
+    int dest_stride = width * Bpp;
+    int h;
 
-	data += y * stride + x * Bpp;
+    data += y * stride + x * Bpp;
 
-#if 0
-	ErrorF ("Must create new image of size %d %d\n", width, height);
-#endif
-	
-	/* Chunk */
+    /* Chunk */
 
-	/* FIXME: Check integer overflow */
+    /* FIXME: Check integer overflow */
 
-	head = tail = NULL;
+    head = tail = NULL;
 
-	hash = 0;
-	h = height;
-	while (h)
-	{
-	    int chunk_size = MAX (512 * 512, dest_stride);
-	    int n_lines = MIN ((chunk_size / dest_stride), h);
-	    QXLDataChunk *chunk =
-		qxl_allocnf (qxl, sizeof *chunk + n_lines * dest_stride);
-
-	    chunk->data_size = n_lines * dest_stride;
-	    hash = hash_and_copy (data, stride,
-				  chunk->data, dest_stride,
-				  Bpp, width, n_lines, hash);
-	    
-	    if (tail)
-	    {
-		tail->next_chunk = physical_address (qxl, chunk, qxl->main_mem_slot);
-		chunk->prev_chunk = physical_address (qxl, tail, qxl->main_mem_slot);
-		chunk->next_chunk = 0;
-		
-		tail = chunk;
-	    }
-	    else
-	    {
-		head = tail = chunk;
-		chunk->next_chunk = 0;
-		chunk->prev_chunk = 0;
-	    }
+    *hash = 0;
+    h = height;
+    while (h)
+    {
+        int chunk_size = MAX (512 * 512, dest_stride);
+        int n_lines = MIN ((chunk_size / dest_stride), h);
+        QXLDataChunk *chunk;
+        struct qxlhw_mem chunk_mem =
+            qxlhw_data_alloc (base, sizeof *chunk + n_lines * dest_stride);
+
+        chunk = chunk_mem.addr;
+        chunk->data_size = n_lines * dest_stride;
+        *hash = hash_and_copy (data, stride,
+                               chunk->data, dest_stride,
+                               Bpp, width, n_lines, *hash);
+
+        if (tail)
+        {
+            tail->next_chunk = physical_address(base->qxl, chunk, base->qxl->main_mem_slot);
+            chunk->prev_chunk = physical_address(base->qxl, tail, base->qxl->main_mem_slot);
+            chunk->next_chunk = 0;
+
+            tail = chunk;
+        }
+        else
+        {
+            head = tail = chunk;
+            chunk->next_chunk = 0;
+            chunk->prev_chunk = 0;
+        }
+
+        data += n_lines * stride;
+        h -= n_lines;
+    }
 
-	    data += n_lines * stride;
-	    h -= n_lines;
-	}
+    /* Image */
+    image_mem = qxlhw_data_alloc (base, sizeof *image);
+    image = image_mem.addr;
 
-	/* Image */
-	image = qxl_allocnf (qxl, sizeof *image);
+    image->descriptor.id = 0;
+    image->descriptor.type = SPICE_IMAGE_TYPE_BITMAP;
 
-	image->descriptor.id = 0;
-	image->descriptor.type = SPICE_IMAGE_TYPE_BITMAP;
-	
-	image->descriptor.flags = 0;
-	image->descriptor.width = width;
-	image->descriptor.height = height;
+    image->descriptor.flags = 0;
+    image->descriptor.width = width;
+    image->descriptor.height = height;
+    if (Bpp == 2)
+    {
+        image->bitmap.format = SPICE_BITMAP_FMT_16BIT;
+    }
+    else if (Bpp == 1)
+    {
+        image->bitmap.format = SPICE_BITMAP_FMT_8BIT;
+    }
+    else if (Bpp == 4)
+    {
+        image->bitmap.format = SPICE_BITMAP_FMT_32BIT;
+    }
+    else
+    {
+        abort();
+    }
 
-	if (Bpp == 2)
-	{
-	    image->bitmap.format = SPICE_BITMAP_FMT_16BIT;
-	}
-	else if (Bpp == 1)
-	{
-	    image->bitmap.format = SPICE_BITMAP_FMT_8BIT;
-	}
-	else if (Bpp == 4)
-	{
-	    image->bitmap.format = SPICE_BITMAP_FMT_32BIT;
-	}
-	else
-	{
-	    abort();
-	}
+    image->bitmap.flags = SPICE_BITMAP_FLAGS_TOP_DOWN;
+    image->bitmap.x = width;
+    image->bitmap.y = height;
+    image->bitmap.stride = width * Bpp;
+    image->bitmap.palette = 0;
+    image->bitmap.data = physical_address (base->qxl, head, base->qxl->main_mem_slot);
 
-	image->bitmap.flags = SPICE_BITMAP_FLAGS_TOP_DOWN;
-	image->bitmap.x = width;
-	image->bitmap.y = height;
-	image->bitmap.stride = width * Bpp;
-	image->bitmap.palette = 0;
-	image->bitmap.data = physical_address (qxl, head, qxl->main_mem_slot);
+#if 0
+    ErrorF ("%p has size %d %d\n", image, width, height);
+#endif
+    return image;
+}
+
+struct QXLImage *
+qxl_image_create (qxl_screen_t *qxl, const uint8_t *data,
+		  int x, int y, int width, int height,
+		  int stride, int Bpp, Bool fallback)
+{
+	uint32_t hash;
+	image_info_t *info;
+	struct QXLImage *image = qxlhw_image_alloc(qxl->hw, data, x, y, width, height,
+                                                   stride, Bpp, &hash);
 
 #if 0
-	ErrorF ("%p has size %d %d\n", image, width, height);
+	ErrorF ("Must create new image of size %d %d\n", width, height);
 #endif
-	
+
 	/* Add to hash table if caching is enabled */
 	if ((fallback && qxl->enable_fallback_cache)	||
 	    (!fallback && qxl->enable_image_cache))
@@ -282,10 +295,10 @@ qxl_image_destroy (qxl_screen_t *qxl,
 
        chunk = virtual->next_chunk;
 
-	qxl_free (qxl->mem, virtual);
+       qxlhw_data_free (qxl->hw, virtual);
     }
-    
-    qxl_free (qxl->mem, image);
+
+    qxlhw_data_free (qxl->hw, image);
 }
 
 void
-- 
1.7.9.3



More information about the Spice-devel mailing list