client: allocate normally tbm_surface when attach buf is invalid 68/156668/2
authorChangyeon Lee <cyeon.lee@samsung.com>
Thu, 19 Oct 2017 10:13:21 +0000 (19:13 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Thu, 19 Oct 2017 10:18:53 +0000 (19:18 +0900)
if queue is activate and activate_flush and width,height,format aren't matched with queue,
normally tbm_surface is allocated and return to queue

Change-Id: Ic3a9006a0361c5941ffd306f42105a49a8b8b21a

src/wayland-tbm-client.c

index 5f33885..a388606 100644 (file)
@@ -935,6 +935,24 @@ _wayland_tbm_client_create_surface_from_param(tbm_bufmgr bufmgr,
        return tbm_surface;
 }
 
+static int
+_wayland_tbm_client_is_valid_attach_bufs(struct wayland_tbm_surface_queue *queue_info,
+        struct wayland_tbm_buffer *buffer)
+{
+       int width, height, format;
+
+       width = tbm_surface_get_width(buffer->tbm_surface);
+       height = tbm_surface_get_height(buffer->tbm_surface);
+       format = tbm_surface_get_format(buffer->tbm_surface);
+
+       if (queue_info->width != width ||
+               queue_info->height != height ||
+               queue_info->format != format)
+               return 0;
+
+       return 1;
+}
+
 static tbm_surface_h
 __wayland_tbm_client_surface_alloc_cb(tbm_surface_queue_h surface_queue, void *data)
 {
@@ -946,27 +964,32 @@ __wayland_tbm_client_surface_alloc_cb(tbm_surface_queue_h surface_queue, void *d
        if (queue_info->is_active && queue_info->active_flush) {
                wl_list_for_each_reverse(buffer, &queue_info->attach_bufs, link) {
                        if (!buffer->allocated) {
-                               surface = buffer->tbm_surface;
-                               /* ref.. pair of __wayland_tbm_client_surface_free_cb */
-                               tbm_surface_internal_ref(surface);
-                               buffer->allocated = 1;
-
+                               if (_wayland_tbm_client_is_valid_attach_bufs(queue_info, buffer)) {
+                                       surface = buffer->tbm_surface;
+                                       /* ref.. pair of __wayland_tbm_client_surface_free_cb */
+                                       tbm_surface_internal_ref(surface);
+                                       buffer->allocated = 1;
 #ifdef DEBUG_TRACE
-                               WL_TBM_TRACE("   pid:%d wl_buffer:%p tbm_surface:%p ACTIVE", getpid(), buffer->wl_buffer, buffer->tbm_surface);
+                                       WL_TBM_TRACE("   pid:%d wl_buffer:%p tbm_surface:%p ACTIVE", getpid(), buffer->wl_buffer, buffer->tbm_surface);
 #endif
+                               } else {
+                                       surface = tbm_surface_internal_create_with_flags(queue_info->width,
+                                               queue_info->height,
+                                               queue_info->format,
+                                               queue_info->flag);
+#ifdef DEBUG_TRACE
+                                       WL_TBM_TRACE("   pid:%d tbm_surface:%p invalid attach_bufs fallback", getpid(), surface);
+#endif
+                               }
+
                                break;
                        }
                }
-
        } else {
-               int width = tbm_surface_queue_get_width(queue_info->tbm_queue);
-               int height = tbm_surface_queue_get_height(queue_info->tbm_queue);
-               int format = tbm_surface_queue_get_format(queue_info->tbm_queue);
-
                /* ref.. pair of __wayland_tbm_client_surface_free_cb */
-               surface = tbm_surface_internal_create_with_flags(width,
-                                                       height,
-                                                       format,
+               surface = tbm_surface_internal_create_with_flags(queue_info->width,
+                                                       queue_info->height,
+                                                       queue_info->format,
                                                        queue_info->flag);
 
 #ifdef DEBUG_TRACE
@@ -1017,7 +1040,6 @@ handle_tbm_queue_buffer_attached(void *data,
        struct wayland_tbm_surface_queue *queue_info =
                                (struct wayland_tbm_surface_queue *)data;
        struct wayland_tbm_buffer *buffer;
-       int width, height;
 
        WL_TBM_RETURN_IF_FAIL(wl_buffer != NULL);
 
@@ -1036,18 +1058,6 @@ handle_tbm_queue_buffer_attached(void *data,
 
        wl_list_insert(&queue_info->attach_bufs, &buffer->link);
 
-       width = tbm_surface_get_width(buffer->tbm_surface);
-       height = tbm_surface_get_height(buffer->tbm_surface);
-
-       if (queue_info->width != width || queue_info->height != height) {
-               if (queue_info->is_active && queue_info->active_flush) {
-                       queue_info->is_active = 0;
-                       queue_info->active_flush = 0;
-
-                       _wayland_tbm_client_surface_queue_flush(queue_info);
-               }
-       }
-
 #ifdef DEBUG_TRACE
        WL_TBM_TRACE("pid:%d wl_buffer:%p tbm_surface:%p",
                        getpid(), buffer->wl_buffer, buffer->tbm_surface);
@@ -1219,16 +1229,6 @@ _handle_tbm_surface_queue_reset_notify(tbm_surface_queue_h surface_queue,
        height = tbm_surface_queue_get_height(surface_queue);
        format = tbm_surface_queue_get_format(surface_queue);
 
-       if (queue_info->width != width || queue_info->height != height ||
-               queue_info->format != format) {
-               /* remove the attach_bufs int the queue_info */
-               if (queue_info->is_active && queue_info->active_flush) {
-                       queue_info->is_active = 0;
-                       queue_info->active_flush = 0;
-                       _wayland_tbm_client_queue_destroy_attach_bufs(queue_info);
-               }
-       }
-
        queue_info->width = width;
        queue_info->height = height;
        queue_info->format = format;