]> git.proxmox.com Git - spiceterm.git/blobdiff - screen.c
cleanup clipboard owner handling
[spiceterm.git] / screen.c
index ff36f18d98ef35ffd4449c48b7c8060ad5184312..5c908c9bb16235c094f0708414821c0bda0cb89a 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -55,9 +55,6 @@ static int debug = 0;
 
 #define MEM_SLOT_GROUP_ID 0
 
-#define NOTIFY_DISPLAY_BATCH (SINGLE_PART/2)
-#define NOTIFY_CURSOR_BATCH 10
-
 /* these colours are from linux kernel drivers/char/vt.c */
 /* the default colour table, for VGA+ colour systems */
 int default_red[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,
@@ -70,10 +67,11 @@ int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa,
 /* Parts cribbed from spice-display.h/.c/qxl.c */
 
 typedef struct SimpleSpiceUpdate {
-    QXLCommandExt ext; // first
+    QXLCommandExt ext; // needs to be first member
     QXLDrawable drawable;
     QXLImage image;
     uint8_t *bitmap;
+    int cache_id; // do not free bitmap if cache_id != 0
 } SimpleSpiceUpdate;
 
 static void 
@@ -86,7 +84,10 @@ spice_screen_destroy_update(SimpleSpiceUpdate *update)
         uint8_t *ptr = (uint8_t*)update->drawable.clip.data;
         free(ptr);
     }
-    g_free(update->bitmap);
+    if (update->bitmap && !update->cache_id) {
+        g_free(update->bitmap);
+    }
+
     g_free(update);
 }
 
@@ -114,6 +115,8 @@ simple_set_release_info(QXLReleaseInfo *info, intptr_t ptr)
 static void 
 push_command(SpiceScreen *spice_screen, QXLCommandExt *ext)
 {
+    int need_wakeup = 1;
+
     g_mutex_lock(spice_screen->command_mutex);
 
     while (spice_screen->commands_end - spice_screen->commands_start >= COMMANDS_SIZE) {
@@ -122,12 +125,19 @@ push_command(SpiceScreen *spice_screen, QXLCommandExt *ext)
 
     g_assert(spice_screen->commands_end - spice_screen->commands_start < COMMANDS_SIZE);
 
+    if ((spice_screen->commands_end - spice_screen->commands_start) > 0) {
+        need_wakeup = 0;
+    }
+
     spice_screen->commands[spice_screen->commands_end % COMMANDS_SIZE] = ext;
     spice_screen->commands_end++;
 
+    if (need_wakeup) {
+        spice_screen->qxl_worker->wakeup(spice_screen->qxl_worker);
+    }
+
     g_mutex_unlock(spice_screen->command_mutex);
 
-    spice_screen->qxl_worker->wakeup(spice_screen->qxl_worker);
 }
 
 /* bitmap are freed, so they must be allocated with g_malloc */
@@ -165,6 +175,8 @@ spice_screen_update_from_bitmap_cmd(uint32_t surface_id, QXLRect bbox, uint8_t *
 
     if (cache_id) {
         QXL_SET_IMAGE_ID(image, QXL_IMAGE_GROUP_DEVICE, cache_id);
+        image->descriptor.flags = SPICE_IMAGE_FLAGS_CACHE_ME;
+        update->cache_id = cache_id;
     } else {
         QXL_SET_IMAGE_ID(image, QXL_IMAGE_GROUP_DEVICE, ++unique);
     }
@@ -188,14 +200,18 @@ spice_screen_draw_char_cmd(SpiceScreen *spice_screen, int x, int y, int c,
 {
     int top, left;
     uint8_t *dst;
-    uint8_t *bitmap;
+    uint8_t *bitmap = NULL;
     int bw, bh;
     int i, j;
     QXLRect bbox;
     int cache_id = 0;
+    CachedImage *ce;
 
     if (!uline && c < 256) {
         cache_id = ((fg << 12) | (bg << 8) | (c & 255)) & 0x0ffff;
+        if ((ce = (CachedImage *)g_hash_table_lookup(spice_screen->image_cache, &cache_id))) {
+            bitmap = ce->bitmap;
+        }
     }
 
     left = x*8;
@@ -204,42 +220,48 @@ spice_screen_draw_char_cmd(SpiceScreen *spice_screen, int x, int y, int c,
     bw       = 8;
     bh       = 16;
 
-    bitmap = dst = g_malloc(bw * bh * 4);
-
-    unsigned char *data = vt_font_data + c*16;
-    unsigned char d = *data;
-
-    g_assert(fg >= 0 && fg < 16);
-    g_assert(bg >= 0 && bg < 16);
-
-    unsigned char fgc_red = default_red[fg];
-    unsigned char fgc_blue = default_blu[fg];
-    unsigned char fgc_green = default_grn[fg];
-    unsigned char bgc_red = default_red[bg];
-    unsigned char bgc_blue = default_blu[bg];
-    unsigned char bgc_green = default_grn[bg];
-
-    for (j = 0; j < 16; j++) {
-        gboolean ul = (j == 14) && uline;
-        for (i = 0; i < 8; i++) {
-            if (i == 0) {
-                d=*data;
-                data++;
+    if (!bitmap) {
+        bitmap = dst = g_malloc(bw * bh * 4);
+        
+        unsigned char *data = vt_font_data + c*16;
+        unsigned char d = *data;
+
+        g_assert(fg >= 0 && fg < 16);
+        g_assert(bg >= 0 && bg < 16);
+
+        unsigned char fgc_red = default_red[fg];
+        unsigned char fgc_blue = default_blu[fg];
+        unsigned char fgc_green = default_grn[fg];
+        unsigned char bgc_red = default_red[bg];
+        unsigned char bgc_blue = default_blu[bg];
+        unsigned char bgc_green = default_grn[bg];
+
+        for (j = 0; j < 16; j++) {
+            gboolean ul = (j == 14) && uline;
+            for (i = 0; i < 8; i++) {
+                if (i == 0) {
+                    d=*data;
+                    data++;
+                }
+                if (ul || d&0x80) {
+                    *(dst) = fgc_blue;
+                    *(dst+1) = fgc_green;
+                    *(dst+2) = fgc_red;
+                    *(dst+3) = 0;
+                } else {
+                    *(dst) = bgc_blue;
+                    *(dst+1) = bgc_green;
+                    *(dst+2) = bgc_red;
+                    *(dst+3) = 0;
+                }
+                d<<=1;
+                dst += 4;
             }
-            if (ul || d&0x80) {
-                 *(dst) = fgc_blue;
-                 *(dst+1) = fgc_green;
-                 *(dst+2) = fgc_red;
-                 *(dst+3) = 0;
-            } else {
-                 *(dst) = bgc_blue;
-                 *(dst+1) = bgc_green;
-                 *(dst+2) = bgc_red;
-                 *(dst+3) = 0;
-            }
-            d<<=1;
-            dst += 4;
         }
+        ce = g_new(CachedImage, 1);
+        ce->cache_id = cache_id;
+        ce->bitmap = bitmap;
+        g_hash_table_insert(spice_screen->image_cache, &ce->cache_id, ce);
     }
 
     bbox.left = left; bbox.top = top;
@@ -325,11 +347,15 @@ create_primary_surface(SpiceScreen *spice_screen, uint32_t width,
     QXLWorker *qxl_worker = spice_screen->qxl_worker;
     QXLDevSurfaceCreate surface = { 0, };
 
-    g_assert(height <= MAX_HEIGHT);
-    g_assert(width <= MAX_WIDTH);
     g_assert(height > 0);
     g_assert(width > 0);
 
+    if (height > MAX_HEIGHT)
+        height = MAX_HEIGHT;
+
+    if (width > MAX_WIDTH)
+        width = MAX_WIDTH;
+
     surface.format     = SPICE_SURFACE_FMT_32_xRGB;
     surface.width      = spice_screen->primary_width = width;
     surface.height     = spice_screen->primary_height = height;
@@ -360,6 +386,8 @@ spice_screen_resize(SpiceScreen *spice_screen, uint32_t width,
     qxl_worker->destroy_primary_surface(qxl_worker, 0);
 
     create_primary_surface(spice_screen, width, height);
+
+    spice_screen_clear(spice_screen, 0, 0, width, height);
 }
                        
 
@@ -504,41 +532,33 @@ cursor_init()
 static int 
 get_cursor_command(QXLInstance *qin, struct QXLCommandExt *ext)
 {
-    SpiceScreen *spice_screen = SPICE_CONTAINEROF(qin, SpiceScreen, qxl_instance);
+    //SpiceScreen *spice_screen = SPICE_CONTAINEROF(qin, SpiceScreen, qxl_instance);
     static int set = 1;
-    static int x = 0, y = 0;
     QXLCursorCmd *cursor_cmd;
     QXLCommandExt *cmd;
 
-    if (!spice_screen->cursor_notify) {
-        return FALSE;
-    }
-
-    spice_screen->cursor_notify--;
+    if (!set) return FALSE;
+    set = 0;
+  
+    
     cmd = calloc(sizeof(QXLCommandExt), 1);
     cursor_cmd = calloc(sizeof(QXLCursorCmd), 1);
 
     cursor_cmd->release_info.id = (unsigned long)cmd;
 
-    if (set) {
-        cursor_cmd->type = QXL_CURSOR_SET;
-        cursor_cmd->u.set.position.x = 0;
-        cursor_cmd->u.set.position.y = 0;
-        cursor_cmd->u.set.visible = TRUE;
-        cursor_cmd->u.set.shape = (unsigned long)&cursor;
-        // white rect as cursor
-        memset(cursor.data, 255, sizeof(cursor.data));
-        set = 0;
-    } else {
-        cursor_cmd->type = QXL_CURSOR_MOVE;
-        cursor_cmd->u.position.x = x++ % spice_screen->primary_width;
-        cursor_cmd->u.position.y = y++ % spice_screen->primary_height;
-    }
+    cursor_cmd->type = QXL_CURSOR_SET;
+    cursor_cmd->u.set.position.x = 0;
+    cursor_cmd->u.set.position.y = 0;
+    cursor_cmd->u.set.visible = TRUE;
+    cursor_cmd->u.set.shape = (unsigned long)&cursor;
+    // white rect as cursor
+    memset(cursor.data, 255, sizeof(cursor.data));
 
     cmd->cmd.data = (unsigned long)cursor_cmd;
     cmd->cmd.type = QXL_CMD_CURSOR;
     cmd->group_id = MEM_SLOT_GROUP_ID;
-    cmd->flags    = 0;
+    cmd->flags = 0;
     *ext = *cmd;
 
     return TRUE;
@@ -702,8 +722,6 @@ spice_screen_new(SpiceCoreInterface *core, uint32_t width, uint32_t height, guin
     spice_screen->core = core;
     spice_screen->server = server;
 
-    spice_screen->cursor_notify = NOTIFY_CURSOR_BATCH;
-
     printf("listening on port %d (unsecure)\n", port);
 
     spice_server_set_port(server, port);