Fix tbm buffer and file fd management logic 82/111782/1 tizen_3.0_tv accepted/tizen/3.0/common/20170201.164602 accepted/tizen/3.0/ivi/20170201.091710 accepted/tizen/3.0/mobile/20170201.091536 accepted/tizen/3.0/tv/20170201.091608 accepted/tizen/3.0/wearable/20170201.091631 submit/tizen_3.0/20170201.003016
authorHyunho Kang <hhstark.kang@samsung.com>
Tue, 24 Jan 2017 02:59:16 +0000 (11:59 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Tue, 24 Jan 2017 03:57:04 +0000 (12:57 +0900)
Change-Id: I8bb5c15ea0a247c33e9450698d0529926a1a0f86
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
screen_connector_watcher/src/screen_connector_watcher.c
screen_connector_watcher_evas/src/screen_connector_watcher_evas.c

index 9077d76..a52fee4 100644 (file)
@@ -181,7 +181,7 @@ EXPORT_API int screen_connector_watcher_init(void)
                if (!strcmp(global->interface, "tizen_remote_surface_manager")) {
                        __rsm = wl_registry_bind(registry, global->id,
                                        &tizen_remote_surface_manager_interface,
-                                       global->version < 2 ? global->version : 2);
+                                       global->version < 4 ? global->version : 4);
                }
        }
 
index a690fff..f9774f5 100644 (file)
@@ -41,6 +41,7 @@ struct _screen_connector_watcher_evas_h {
        bool cancel_touch;
        Evas_Object *img_tbm;
        Evas_Object *img_file;
+       uint32_t img_type;
        struct wl_buffer *pre_buffer;
        void *data;
 };
@@ -55,6 +56,7 @@ static void __destroy_watcher_evas_handle(screen_connector_watcher_evas_h h)
                return;
        free(h->ops);
        free(h);
+       h = NULL;
 }
 
 EXPORT_API int screen_connector_watcher_evas_init(Evas_Object *win)
@@ -296,6 +298,25 @@ static void __rs_cb_resize(void *data, Evas *e, Evas_Object *obj, void *event_in
        __obj_update_visibility(data, e, obj, event_info);
 }
 
+static void __clear_img_tbm(screen_connector_watcher_evas_h watcher_evas_h)
+{
+       if (watcher_evas_h->img_tbm == NULL)
+               return;
+
+       g_hash_table_remove(__watcher_tbl, watcher_evas_h->img_tbm);
+       evas_object_del(watcher_evas_h->img_tbm);
+       watcher_evas_h->img_tbm = NULL;
+}
+
+static void __clear_img_file(screen_connector_watcher_evas_h watcher_evas_h)
+{
+       if (watcher_evas_h->img_file == NULL)
+               return;
+
+       evas_object_del(watcher_evas_h->img_file);
+       watcher_evas_h->img_file = NULL;
+}
+
 static void __watcher_change_cb(struct tizen_remote_surface *trs, uint32_t type, struct wl_buffer *tbm,
                int32_t img_file_fd, uint32_t img_file_size, uint32_t time, struct wl_array *keys, void *data)
 {
@@ -352,9 +373,11 @@ static void __watcher_change_cb(struct tizen_remote_surface *trs, uint32_t type,
                evas_object_data_set(watcher_evas_h->img_tbm, "___PLUGID", strdup(plug_id));
                evas_object_event_callback_add(watcher_evas_h->img_tbm,
                                EVAS_CALLBACK_MOVE, __obj_update_visibility, watcher_evas_h);
+       }
 
+       if (watcher_evas_h->img_type != type)
                is_added = true;
-       }
+       watcher_evas_h->img_type = type;
 
        /* check type of given buffer */
        if (type == TIZEN_REMOTE_SURFACE_BUFFER_TYPE_TBM) {
@@ -382,7 +405,6 @@ static void __watcher_change_cb(struct tizen_remote_surface *trs, uint32_t type,
                evas_object_image_fill_set(watcher_evas_h->img_file, 0, 0, width, height);
                evas_object_resize(watcher_evas_h->img_file, width, height);
                munmap(map, img_file_size);
-               close(img_file_fd); /* close passed fd */
 
                evas_object_image_native_surface_set(watcher_evas_h->img_tbm, NULL); /* set null to previous object for the tbm type */
        }
@@ -394,14 +416,29 @@ static void __watcher_change_cb(struct tizen_remote_surface *trs, uint32_t type,
        watcher_evas_h->pre_buffer = tbm;
 
        if (is_added) {
-               LOGD("call added !!!! %s", appid);
-               watcher_evas_h->ops->added(appid, watcher_evas_h->img_tbm,
-                               watcher_evas_h->data);
+               LOGD("call added !!!! %s, type %d", appid, type);
+               if (type == TIZEN_REMOTE_SURFACE_BUFFER_TYPE_IMAGE_FILE) {
+                       watcher_evas_h->ops->added(appid, watcher_evas_h->img_file,
+                                       watcher_evas_h->data);
+                       __clear_img_tbm(watcher_evas_h);
+               } else {
+                       watcher_evas_h->ops->added(appid, watcher_evas_h->img_tbm,
+                                       watcher_evas_h->data);
+                       __clear_img_file(watcher_evas_h);
+               }
        } else {
-               LOGD("call updated !!!! %s", appid);
-               watcher_evas_h->ops->updated(appid, watcher_evas_h->img_tbm,
-                               watcher_evas_h->data);
+               LOGD("call updated !!!! %s, type %d", appid, type);
+               if (type == TIZEN_REMOTE_SURFACE_BUFFER_TYPE_IMAGE_FILE) {
+                       watcher_evas_h->ops->updated(appid, watcher_evas_h->img_file,
+                                       watcher_evas_h->data);
+                       __clear_img_tbm(watcher_evas_h);
+               } else {
+                       watcher_evas_h->ops->updated(appid, watcher_evas_h->img_tbm,
+                                       watcher_evas_h->data);
+                       __clear_img_file(watcher_evas_h);
+               }
        }
+       close(img_file_fd); /* close passed fd */
 }
 
 static void __watcher_update_cb(struct tizen_remote_surface *trs, struct wl_buffer *buffer, uint32_t time, void *data)
@@ -450,7 +487,10 @@ static void __watcher_missing_cb(struct tizen_remote_surface *trs, void *data)
        }
 
        appid = screen_connector_watcher_get_appid(watcher_evas_h->watcher_h);
-       watcher_evas_h->ops->removed(appid, watcher_evas_h->img_tbm, watcher_evas_h->data);
+       if (watcher_evas_h->img_tbm != NULL)
+               watcher_evas_h->ops->removed(appid, watcher_evas_h->img_tbm, watcher_evas_h->data);
+       else
+               watcher_evas_h->ops->removed(appid, watcher_evas_h->img_file, watcher_evas_h->data);
        __free_watcher_evas_h(watcher_evas_h);
 }
 
@@ -476,6 +516,7 @@ EXPORT_API screen_connector_watcher_evas_h screen_connector_watcher_evas_add(scr
                LOGE("handle calloc fail");
                return NULL;
        }
+       handle->img_type = -1;
        handle->ops = evas_ops;
        handle->data = data;
        handle->watcher_h = screen_connector_watcher_add(&watcher_ops, id, handle);