wayland-cursor: fix cursor image broken problem
authorSung-Jin Park <sj76.park@samsung.com>
Wed, 17 May 2017 05:29:50 +0000 (14:29 +0900)
committerJunkyeong Kim <jk0430.kim@samsung.com>
Thu, 16 Feb 2023 10:00:33 +0000 (19:00 +0900)
This fixes a bug related to recreate/use a new shm pool for cursor(s).
When recreating a shm pool, we usually need to copy the existing contents
in the old shm pool to the new shm pool. Otherwise, cursor images in the
old shm pool will be lost and they will be displayed abnormaly.

Change-Id: Id7515f9d15d8406c3dfb1ad52072a2442ce0c1aa
Signed-off-by: Sung-Jin Park <sj76.park@samsung.com>
cursor/wayland-cursor.c [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index f966079..5b770ca
@@ -285,6 +285,7 @@ wl_cursor_create_from_xcursor_images(struct xcursor_images *images,
        struct cursor *cursor;
        struct cursor_image *image;
        int i, size, origin_size;;
+       struct shm_pool *old_shm_pool;
 
        cursor = malloc(sizeof *cursor);
        if (!cursor)
@@ -317,12 +318,18 @@ wl_cursor_create_from_xcursor_images(struct xcursor_images *images,
                size = image->image.width * image->image.height * 4;
                if ((theme->pool->used + size) > theme->pool->size) {
                        origin_size = theme->pool->size;
-                       shm_pool_destroy(theme->pool);
+                       old_shm_pool = theme->pool;
                        theme->pool = shm_pool_create(theme->shm, 2 * origin_size + size);
                        if (!theme->pool) {
+                               shm_pool_destroy(old_shm_pool);
                                free(image);
                                break;
                        }
+
+                       /* copy contents from old shm pool to a newly created shm pool */
+                       memcpy(theme->pool->data, old_shm_pool->data, old_shm_pool->used);
+                       theme->pool->used = old_shm_pool->used;
+                       shm_pool_destroy(old_shm_pool);
                }
 
                image->offset = shm_pool_allocate(theme->pool, size);