Fix add by rid bug 15/132315/10
authorHyunho Kang <hhstark.kang@samsung.com>
Fri, 2 Jun 2017 07:34:04 +0000 (16:34 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Fri, 9 Jun 2017 11:23:45 +0000 (11:23 +0000)
- Only main viewer should remove prev tbm buffer.
- Resources which generated by add_by_rid should be managed

Change-Id: Icf2dfdc47b131e2efd86b82aabdb1ff683d30203
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
screen_connector_watcher/include/screen_connector_toolkit.h
screen_connector_watcher/src/screen_connector_toolkit.c
screen_connector_watcher_evas/src/screen_connector_toolkit_evas.c

index 39968b1..7fe718c 100644 (file)
@@ -74,13 +74,16 @@ void *screen_connector_toolkit_get_user_data(screen_connector_toolkit_h h);
 
 unsigned int screen_connector_toolkit_get_event_filter(screen_connector_toolkit_h h);
 int screen_connector_toolkit_check_input_disabled(screen_connector_toolkit_h h,        screen_connector_input_type_e input);
-screen_connector_toolkit_h screen_connector_toolkit_create_handle(char *id, int surface_id,
-       screen_connector_toolkit_ops *ops, void *data);
+screen_connector_toolkit_h screen_connector_toolkit_add_by_rid(screen_connector_toolkit_ops *ops, char *id,
+       screen_connector_screen_type_e type, int surface_id, void *data);
 struct tizen_remote_surface *screen_connector_toolkit_get_trs(screen_connector_toolkit_h h);
 int screen_connector_toolkit_redirect_surface(screen_connector_toolkit_h info);
 screen_connector_toolkit_h screen_connector_toolkit_add_with_surface(screen_connector_toolkit_ops *ops, char *id,
        screen_connector_screen_type_e type, struct wl_surface *surface, void *data);
 
+int screen_connector_toolkit_bind(screen_connector_toolkit_h h, struct wl_surface *surface);
+int screen_connector_toolkit_unbind(screen_connector_toolkit_h h);
+
 #ifdef __cplusplus
 }
 #endif
index 3a36df2..0227d48 100644 (file)
@@ -247,11 +247,18 @@ EXPORT_API int screen_connector_toolkit_fini(screen_connector_screen_type_e type
        return ret;
 }
 
-EXPORT_API screen_connector_toolkit_h screen_connector_toolkit_create_handle(char *id, int surface_id,
-       screen_connector_toolkit_ops *ops, void *data)
+EXPORT_API screen_connector_toolkit_h screen_connector_toolkit_add_by_rid(screen_connector_toolkit_ops *ops, char *id,
+       screen_connector_screen_type_e type, int surface_id, void *data)
 {
        screen_connector_toolkit_h toolkit_h = NULL;
        screen_connector_toolkit_ops *ops_copy;
+       screen_connector_type_h type_h;
+
+       type_h = g_hash_table_lookup(__type_table, GINT_TO_POINTER(type));
+       if (type_h == NULL) {
+               LOGE("type %d is not initialized !!", type);
+               return NULL;
+       }
 
        ops_copy = (screen_connector_toolkit_ops *)calloc(1, sizeof(screen_connector_toolkit_ops));
        if (ops_copy == NULL) {
@@ -271,6 +278,18 @@ EXPORT_API screen_connector_toolkit_h screen_connector_toolkit_create_handle(cha
        toolkit_h->instance_id = strdup(id);
        toolkit_h->data = data;
        toolkit_h->ops = ops_copy;
+       toolkit_h->type_h = type_h;
+
+       if (type_h->toolkit_table == NULL)
+               type_h->toolkit_table = g_hash_table_new_full(g_str_hash,
+                               g_str_equal, free, __destroy_toolkit_h);
+
+       g_hash_table_insert(type_h->toolkit_table, strdup(id), toolkit_h);
+
+       if (type_h->aul_handle == NULL)
+               aul_screen_connector_add_screen_viewer(__aul_screen_viewer_cb, type, true, type_h, &type_h->aul_handle);
+
+       screen_connector_toolkit_redirect_surface(toolkit_h);
 
        return toolkit_h;
 }
index dc5e989..d2ef2f3 100644 (file)
@@ -25,6 +25,7 @@
 #include <tizen-remote-surface-client-protocol.h>
 #include <tbm_surface.h>
 #include <tbm_surface_internal.h>
+#include <uuid/uuid.h>
 
 #include "screen_connector_toolkit.h"
 #include "screen_connector_toolkit_evas.h"
@@ -41,6 +42,12 @@ struct _screen_connector_type_evas_h {
        Evas_Object *viewer_win;
 };
 
+struct _cur_buffer_info_h {
+       struct wl_buffer *cur_buffer;
+       int ref_count;
+};
+typedef struct _cur_buffer_info_h *cur_buffer_info_h;
+
 struct _screen_connector_toolkit_evas_h {
        screen_connector_toolkit_evas_ops *ops;
        screen_connector_toolkit_h toolkit_h;
@@ -50,12 +57,13 @@ struct _screen_connector_toolkit_evas_h {
        Evas_Object *img_tbm;
        Evas_Object *img_file;
        uint32_t img_type;
-       struct wl_buffer *pre_buffer;
+       struct wl_buffer *cur_buffer;
        struct _screen_connector_type_evas_h *type_h;
        guint resuming_timer;
        void *data;
 };
 
+static GHashTable *__cur_buffer_table = NULL;
 static GHashTable *__type_table = NULL;
 static Ecore_Event_Handler *__visibility_listener;
 static int __delayed_resuming_time;
@@ -73,6 +81,37 @@ static void __destroy_type_h(gpointer data)
        free(type_h);
 }
 
+static void __cur_buffer_info_ref(cur_buffer_info_h info)
+{
+       info->ref_count++;
+}
+
+static void __cur_buffer_info_unref(struct tizen_remote_surface *trs, cur_buffer_info_h info)
+{
+       tbm_surface_h cur_tbm_surface;
+
+       info->ref_count--;
+       if (info->ref_count == 0) {
+               tizen_remote_surface_release(trs, info->cur_buffer);
+               cur_tbm_surface = (tbm_surface_h)wl_buffer_get_user_data(info->cur_buffer);
+               tbm_surface_internal_unref(cur_tbm_surface);
+               g_hash_table_remove(__cur_buffer_table, info->cur_buffer);
+       }
+}
+
+static void __destroy_cur_buffer(gpointer data)
+{
+       cur_buffer_info_h info = (cur_buffer_info_h)data;
+
+       if (!info)
+               return;
+
+       if (info->cur_buffer)
+               wl_buffer_destroy(info->cur_buffer);
+
+       free(info);
+}
+
 static void __clear_img_tbm(screen_connector_toolkit_evas_h toolkit_evas_h)
 {
        char *plug_id;
@@ -130,6 +169,9 @@ EXPORT_API int screen_connector_toolkit_evas_init(Evas_Object *win, screen_conne
        if (__type_table == NULL)
                __type_table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, __destroy_type_h);
 
+       if (__cur_buffer_table == NULL)
+               __cur_buffer_table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, __destroy_cur_buffer);
+
        type_h = g_hash_table_lookup(__type_table, GINT_TO_POINTER(type));
        if (type_h == NULL) {
 
@@ -168,6 +210,10 @@ EXPORT_API int screen_connector_toolkit_evas_fini(screen_connector_screen_type_e
        if (g_hash_table_size(__type_table) == 0) {
                g_hash_table_destroy(__type_table);
                __type_table = NULL;
+
+               if (__cur_buffer_table)
+                       g_hash_table_destroy(__cur_buffer_table);
+               __cur_buffer_table = NULL;
        }
 
        __delayed_resuming_time = 0;
@@ -493,7 +539,7 @@ static void __toolkit_update_cb(struct tizen_remote_surface *trs, uint32_t type,
        char format[] = "png";
        char plug_id[256];
        screen_connector_toolkit_evas_h toolkit_evas_h;
-       tbm_surface_h pre_tbm_surface;
+       cur_buffer_info_h c_buf_info;
 
        toolkit_evas_h = (screen_connector_toolkit_evas_h)data;
        if (toolkit_evas_h->img_tbm == NULL)    {
@@ -572,15 +618,24 @@ static void __toolkit_update_cb(struct tizen_remote_surface *trs, uint32_t type,
                evas_object_image_native_surface_set(toolkit_evas_h->img_tbm, NULL); /* set null to previous object for the tbm type */
        }
 
-       if (toolkit_evas_h->pre_buffer) {
+       if (toolkit_evas_h->cur_buffer) {
                if (tizen_remote_surface_get_version(trs) >= TIZEN_REMOTE_SURFACE_RELEASE_SINCE_VERSION) {
-                       tizen_remote_surface_release(trs, toolkit_evas_h->pre_buffer);
-                       pre_tbm_surface = (tbm_surface_h)wl_buffer_get_user_data(toolkit_evas_h->pre_buffer);
-                       tbm_surface_internal_unref(pre_tbm_surface);
-                       wl_buffer_destroy(toolkit_evas_h->pre_buffer);
+                       c_buf_info = g_hash_table_lookup(__cur_buffer_table, toolkit_evas_h->cur_buffer);
+                       if (c_buf_info != NULL)
+                               __cur_buffer_info_unref(trs, c_buf_info);
                }
        }
-       toolkit_evas_h->pre_buffer = tbm;
+
+       toolkit_evas_h->cur_buffer = tbm;
+       c_buf_info = g_hash_table_lookup(__cur_buffer_table, toolkit_evas_h->cur_buffer);
+       if (c_buf_info == NULL) {
+               c_buf_info = (cur_buffer_info_h)calloc(1, sizeof(struct _cur_buffer_info_h));
+               c_buf_info->cur_buffer = toolkit_evas_h->cur_buffer;
+               __cur_buffer_info_ref(c_buf_info);
+               g_hash_table_insert(__cur_buffer_table, toolkit_evas_h->cur_buffer, c_buf_info);
+       } else {
+               __cur_buffer_info_ref(c_buf_info);
+       }
 
        if (is_added) {
                LOGD("call added !!!! %s, type %d", appid, type);
@@ -594,7 +649,6 @@ static void __toolkit_update_cb(struct tizen_remote_surface *trs, uint32_t type,
                        __clear_img_file(toolkit_evas_h);
                }
        } else {
-               LOGD("call updated !!!! %s, type %d", appid, type);
                if (type == TIZEN_REMOTE_SURFACE_BUFFER_TYPE_IMAGE_FILE) {
                        toolkit_evas_h->ops->updated_cb(appid, instance_id, pid, toolkit_evas_h->img_file,
                                        toolkit_evas_h->data);
@@ -970,7 +1024,9 @@ EXPORT_API screen_connector_toolkit_evas_h screen_connector_toolkit_evas_add_by_
        screen_connector_toolkit_evas_ops *evas_ops;
        screen_connector_toolkit_ops toolkit_ops;
        screen_connector_type_evas_h type_h;
-       char rid_str[32];
+       char id_str[70];
+       char uuid[37];
+       uuid_t u;
 
        type_h = g_hash_table_lookup(__type_table, GINT_TO_POINTER(type));
        if (type_h == NULL) {
@@ -1000,9 +1056,10 @@ EXPORT_API screen_connector_toolkit_evas_h screen_connector_toolkit_evas_add_by_
        handle->data = data;
        handle->type_h = type_h;
 
-       snprintf(rid_str, sizeof(rid_str), "%d", res_id);
-       handle->toolkit_h = screen_connector_toolkit_create_handle(rid_str, res_id, &toolkit_ops, handle);
-       screen_connector_toolkit_redirect_surface(handle->toolkit_h);
+       uuid_generate(u);
+       uuid_unparse(u, uuid);
+       snprintf(id_str, sizeof(id_str), "%s:%d", uuid, res_id);
+       handle->toolkit_h = screen_connector_toolkit_add_by_rid(&toolkit_ops, id_str, type, res_id, handle);
 
        return handle;
 }