client: create surface with tbm_surface_queue_set_alloc_cb2 19/283519/2
authorChangyeon Lee <cyeon.lee@samsung.com>
Fri, 28 Oct 2022 02:23:01 +0000 (11:23 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Fri, 28 Oct 2022 07:30:48 +0000 (16:30 +0900)
surface queue infomation can be mismatched when tbm_surface_queue_reset and
tbm_surface_queue_can_dequeue_wait_timeout are called in different thread.

1. tbm_surface_queue_can_dequeue_wait_timeout is called in thread1
   and it wait free buffer
2. tbm_surface_queue_reset is called in thread2
3. waiting of thread1 is finished but wayland_tbm create surface with queue_info
4. _handle_tbm_surface_queue_reset_notify is called and queue_info is updated

for resolving this problem, libtbm add queue infomation in alloc ballback
and wayland_tbm create surface with argument of alloc callback.

Change-Id: Iad0986aaf86d56073095be2d2f2b49ed8d70da2b

src/wayland-tbm-client.c

index b3a5903a5138c1c5dbea8683ac2c646927218eb4..91a6d0e724d28d94dafdb90729bce1160fa12ecb 100644 (file)
@@ -982,7 +982,8 @@ allocate:
 }
 
 static tbm_surface_h
-__wayland_tbm_client_surface_alloc_cb(tbm_surface_queue_h surface_queue, void *data)
+__wayland_tbm_client_surface_alloc_cb2(tbm_surface_queue_h surface_queue, int width, int height,
+                       int format, int flags, void *data)
 {
        struct wayland_tbm_surface_queue *queue_info =
                                (struct wayland_tbm_surface_queue *)data;
@@ -990,6 +991,11 @@ __wayland_tbm_client_surface_alloc_cb(tbm_surface_queue_h surface_queue, void *d
 
        pthread_mutex_lock(&queue_info->lock);
 
+       queue_info->width = width;
+       queue_info->height = height;
+       queue_info->format = format;
+       queue_info->flag = flags;
+
        if (_wayland_tbm_client_use_attach_bufs(queue_info)) {
                surface = _wayland_tbm_client_get_usable_attach_buf(queue_info);
                /* ref.. pair of __wayland_tbm_client_surface_free_cb */
@@ -1009,10 +1015,10 @@ __wayland_tbm_client_surface_alloc_cb(tbm_surface_queue_h surface_queue, void *d
 
        if (!surface) {
                /* ref.. pair of __wayland_tbm_client_surface_free_cb */
-               surface = tbm_surface_internal_create_with_flags(queue_info->width,
-                                                       queue_info->height,
-                                                       queue_info->format,
-                                                       queue_info->flag);
+               surface = tbm_surface_internal_create_with_flags(width,
+                                                       height,
+                                                       format,
+                                                       flags);
 
                WL_TBM_TRACE("surface_queue:%p tbm_surface:%p DEACTIVE",
                        surface_queue, surface);
@@ -1551,8 +1557,8 @@ wayland_tbm_client_create_surface_queue(struct wayland_tbm_client *tbm_client,
                                width, height, format, 0);
        WL_TBM_GOTO_IF_FAIL(queue_info->tbm_queue != NULL, fail);
 
-       tbm_surface_queue_set_alloc_cb(queue_info->tbm_queue,
-                                       __wayland_tbm_client_surface_alloc_cb,
+       tbm_surface_queue_set_alloc_cb2(queue_info->tbm_queue,
+                                       __wayland_tbm_client_surface_alloc_cb2,
                                        __wayland_tbm_client_surface_free_cb,
                                        queue_info);
 
@@ -1623,8 +1629,8 @@ wayland_tbm_client_create_surface_queue_tiled(struct wayland_tbm_client *tbm_cli
                                width, height, format, TBM_BO_TILED);
        WL_TBM_GOTO_IF_FAIL(queue_info->tbm_queue != NULL, fail);
 
-       tbm_surface_queue_set_alloc_cb(queue_info->tbm_queue,
-                                       __wayland_tbm_client_surface_alloc_cb,
+       tbm_surface_queue_set_alloc_cb2(queue_info->tbm_queue,
+                                       __wayland_tbm_client_surface_alloc_cb2,
                                        __wayland_tbm_client_surface_free_cb,
                                        queue_info);