Update buffer management code.
authorSung-jae Park <nicesj.park@samsung.com>
Tue, 14 Aug 2012 03:03:21 +0000 (12:03 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Tue, 14 Aug 2012 03:03:21 +0000 (12:03 +0900)
PIXMAP type is added (not yet implemented)

include/fb.h
include/livebox.h
sample/sample.c
src/client.c
src/fb.c
src/livebox.c

index 0276d32..f60954a 100644 (file)
@@ -3,6 +3,7 @@ struct fb_info;
 enum buffer_type { /*!< Must have to be sync with libprovider, liblivebox-viewer */
        BUFFER_TYPE_FILE,
        BUFFER_TYPE_SHM,
+       BUFFER_TYPE_PIXMAP,
        BUFFER_TYPE_ERROR,
 };
 
index 1a2c8fb..149256e 100644 (file)
@@ -45,6 +45,7 @@ enum content_event_type {
        PD_EVENT_MAX = 0xFFFFFFFF,
 };
 
+/* Exported to user app */
 enum livebox_lb_type {
        LB_TYPE_IMAGE = 0x01,
        LB_TYPE_BUFFER = 0x02,
index 1c8f0fc..585798b 100644 (file)
@@ -214,8 +214,9 @@ static inline int create_new_box(struct livebox *handler)
                                evas_object_image_colorspace_set(info->box, EVAS_COLORSPACE_ARGB8888);
                                evas_object_image_alpha_set(info->box, EINA_TRUE);
                                evas_object_image_fill_set(info->box, 0, 0, w, h);
-                               evas_object_image_data_copy_set(info->box, fb);
+                               evas_object_image_data_set(info->box, fb);
                                evas_object_image_data_update_add(info->box, 0, 0, w, h);
+                               evas_object_image_reload(info->box);
 
                                evas_object_event_callback_add(info->box, EVAS_CALLBACK_MOUSE_DOWN, lb_mouse_down_cb, info);
                                evas_object_event_callback_add(info->box, EVAS_CALLBACK_MOUSE_MOVE, lb_mouse_move_cb, info);
@@ -322,6 +323,7 @@ static void pd_destroyed_cb(struct livebox *handler, int ret, void *data)
 static inline int create_new_pd(struct livebox *handler)
 {
        struct box_info *info;
+       Evas_Coord w, h;
 
        info = find_box_info(handler);
        if (!info)
@@ -330,15 +332,15 @@ static inline int create_new_pd(struct livebox *handler)
        if (info->pd)
                return -EEXIST;
 
-       info->pd = evas_object_image_add(evas_object_evas_get(s_info.win));
+       livebox_get_pdsize(handler, &w, &h);
+
+       info->pd = evas_object_image_filled_add(evas_object_evas_get(s_info.win));
        if (!info->pd) {
                fprintf(stderr, "Failed to add an image object for pd\n");
        } else {
-               Evas_Coord w, h;
                Evas_Coord x, y;
                void *fb;
 
-               livebox_get_pdsize(handler, &w, &h);
                fprintf(stderr, "PDSize: %dx%d\n", w, h);
                fb = livebox_acquire_pdfb(handler);
                if (fb) {
@@ -348,7 +350,7 @@ static inline int create_new_pd(struct livebox *handler)
 
                        evas_object_image_fill_set(info->pd, 0, 0, w, h);
                        fprintf(stderr, "PD ptr: %p\n", fb);
-                       evas_object_image_data_copy_set(info->pd, fb);
+                       evas_object_image_data_set(info->pd, fb);
                        evas_object_image_data_update_add(info->pd, 0, 0, w, h);
                        evas_object_resize(info->pd, w, h);
                        if (s_info.w != w)
@@ -366,7 +368,8 @@ static inline int create_new_pd(struct livebox *handler)
                        evas_object_event_callback_add(info->pd, EVAS_CALLBACK_MOUSE_DOWN, pd_mouse_down_cb, info);
                        evas_object_event_callback_add(info->pd, EVAS_CALLBACK_MOUSE_MOVE, pd_mouse_move_cb, info);
                        evas_object_event_callback_add(info->pd, EVAS_CALLBACK_MOUSE_UP, pd_mouse_up_cb, info);
-                       fprintf(stderr, "PD created: %p\n", fb);
+                       evas_object_image_reload(info->pd);
+                       fprintf(stderr, "PD created: %p (%dx%d)\n", fb, x, y);
                        livebox_release_pdfb(fb);
                }
        }
@@ -422,13 +425,11 @@ static inline void reload_buffer(Evas_Object *box, void *buffer, double priority
        y += ((oh - h) / 2);
 
        evas_object_move(box, x, y);
-       if (ow != w || oh != h) {
-               evas_object_image_size_set(box, w, h);
-               evas_object_image_fill_set(box, 0, 0, w, h);
-               evas_object_image_data_copy_set(box, buffer);
-               evas_object_resize(box, w, h);
-       }
 
+       evas_object_image_size_set(box, w, h);
+       evas_object_image_fill_set(box, 0, 0, w, h);
+       evas_object_resize(box, w, h);
+       evas_object_image_data_set(box, buffer);
        evas_object_image_data_update_add(box, 0, 0, w, h);
        evas_object_show(box);
 }
@@ -493,6 +494,7 @@ static inline int update_box(struct livebox *handler)
                                if (fb) {
                                        fprintf(stderr, "pd: updated %p\n", fb);
                                        reload_buffer(info->box, fb, 1.0, w, h);
+                                       evas_object_image_reload(info->box);
                                        livebox_release_fb(fb);
                                } else {
                                        fprintf(stderr, ">>>>>>>>>>> Buffer is not exists\n");
@@ -525,6 +527,7 @@ static inline int update_pd(struct livebox *handler)
                                if (fb) {
                                        fprintf(stderr, "pd: updated %p\n", fb);
                                        reload_buffer(info->pd, fb, 1.0, w, h);
+                                       evas_object_image_reload(info->pd);
                                        livebox_release_pdfb(fb);
                                } else {
                                        fprintf(stderr, "!!!!!!!!!!!!!!! pd buffer is not valid\n");
@@ -828,7 +831,7 @@ static int app_create(void *data)
        int h = 0;
 
        livebox_init();
-       livebox_subscribe_group("*", "*");
+//     livebox_subscribe_group("*", "*");
 
        s_info.win = elm_win_add(NULL, "test", ELM_WIN_BASIC);
        if (!s_info.win)
index 409ff8f..e0754b0 100644 (file)
@@ -237,10 +237,12 @@ static struct packet *master_lb_updated(pid_t pid, int handle, const struct pack
        if (lb_text_lb(handler)) {
                lb_set_size(handler, lb_w, lb_h);
                ret = parse_desc(handler, URI_TO_PATH(id), 0);
+               /*!
+                * \note
+                * DESC parser will call the "text event callback".
+                */
                goto out;
-       }
-
-       if (lb_get_lb_fb(handler)) {
+       } else if (lb_get_lb_fb(handler)) {
                lb_set_size(handler, lb_w, lb_h);
                lb_set_lb_fb(handler, fbfile);
                ret = fb_sync(lb_get_lb_fb(handler));
index 7075be2..40ea9d3 100644 (file)
--- a/src/fb.c
+++ b/src/fb.c
@@ -25,6 +25,7 @@ struct fb_info {
                FB_TYPE_UNKNOWN,
                FB_TYPE_FILE,
                FB_TYPE_SHM,
+               FB_TYPE_PIXMAP,
        } type;
        char *id;
        int w;
@@ -96,7 +97,7 @@ int fb_sync(struct fb_info *info)
                return 0;
        }
 
-       if (info->type == FB_TYPE_UNKNOWN) {
+       if (info->type != FB_TYPE_FILE) {
                DbgPrint("Ingore sync\n");
                return 0;
        }
@@ -150,6 +151,8 @@ struct fb_info *fb_create(const char *id, int w, int h)
                info->handle = -EINVAL;
        } else if (sscanf(info->id, "shm://%d", &info->handle) == 1) {
                info->type = FB_TYPE_SHM;
+       } else if (sscanf(info->id, "pixmap://%d", &info->handle) == 1) {
+               info->type = FB_TYPE_PIXMAP;
        } else {
                info->type = FB_TYPE_FILE;
                info->handle = -EINVAL;
@@ -187,20 +190,30 @@ int fb_create_buffer(struct fb_info *info)
                }
 
                buffer->type = BUFFER_TYPE_FILE;
-       } else {
+               buffer->refcnt = 1;
+               buffer->state = CREATED;
+       } else if (info->type == FB_TYPE_SHM) {
                DbgPrint("SHMID: %d\n", info->handle);
+               if (info->handle < 0) {
+                       DbgPrint("SHM is not prepared yet\n");
+                       info->bufsz = 0;
+                       return 0;
+               }
 
                buffer = shmat(info->handle, NULL, 0);
-               if (!buffer) {
+               if (buffer == (void *)-1) {
                        ErrPrint("shmat: %s\n", strerror(errno));
                        info->bufsz = 0;
                        return -EFAULT;
                }
-
-               buffer->type = BUFFER_TYPE_SHM;
+       } else if (info->type == FB_TYPE_PIXMAP) {
+               buffer = NULL;
+               ErrPrint("pixmap is not supported yet\n");
+       } else {
+               ErrPrint("Invalid FB type\n");
+               return -EINVAL;
        }
-       buffer->refcnt = 1;
-       buffer->state = CREATED;
+
        info->buffer = buffer;
 
        DbgPrint("FB allocated (%p)\n", info->buffer);
@@ -263,14 +276,31 @@ void *fb_acquire_buffer(struct fb_info *info)
 {
        struct buffer *buffer;
 
-       if (!info)
+       if (!info) {
+               ErrPrint("info == NIL\n");
                return NULL;
+       }
 
        buffer = info->buffer;
-       if (!buffer)
+       if (!buffer) {
+               ErrPrint("info->buffer == NIL\n");
                return NULL;
+       }
+
+       if (buffer->type == BUFFER_TYPE_SHM) {
+               buffer = shmat(info->handle, NULL, 0);
+               if (buffer == (void *)-1) {
+                       ErrPrint("shmat: %s\n", strerror(errno));
+                       return NULL;
+               }
+       } else if (buffer->type == BUFFER_TYPE_PIXMAP) {
+               ErrPrint("Pixmap is not supported yet\n");
+               return NULL;
+       } else {
+               buffer->refcnt++;
+               DbgPrint("FB acquired (%p) %d\n", buffer, buffer->refcnt);
+       }
 
-       buffer->refcnt++;
        return buffer->data;
 }
 
@@ -279,7 +309,7 @@ int fb_release_buffer(void *data)
        struct buffer *buffer;
 
        if (!data) {
-               DbgPrint("Here?\n");
+               DbgPrint("buffer data == NIL\n");
                return 0;
        }
 
@@ -290,16 +320,26 @@ int fb_release_buffer(void *data)
                return -EINVAL;
        }
 
-       buffer->refcnt--;
-       if (buffer->refcnt == 0) {
-               DbgPrint("FB released (%p)\n", buffer);
-               buffer->state = DESTROYED;
-
-               if (buffer->type == BUFFER_TYPE_SHM) {
-                       if (shmdt(buffer) < 0)
-                               ErrPrint("shmdt: %s\n", strerror(errno));
-               } else if (buffer->type == BUFFER_TYPE_FILE) {
-                       free(buffer);
+       if (buffer->type == BUFFER_TYPE_SHM) {
+               if (shmdt(buffer) < 0)
+                       ErrPrint("shmdt: %s\n", strerror(errno));
+       } else if (buffer->type == BUFFER_TYPE_PIXMAP) {
+               ErrPrint("Pixmap is not supported yet\n");
+               return -ENOTSUP;
+       } else {
+               buffer->refcnt--;
+               if (buffer->refcnt == 0) {
+                       DbgPrint("FB released (%p)\n", buffer);
+                       buffer->state = DESTROYED;
+
+                       if (buffer->type == BUFFER_TYPE_SHM) {
+                               if (shmdt(buffer) < 0)
+                                       ErrPrint("shmdt: %s\n", strerror(errno));
+                       } else if (buffer->type == BUFFER_TYPE_FILE) {
+                               free(buffer);
+                       }
+               } else {
+                       DbgPrint("FB decrease[%p] refcnt: %d\n", buffer, buffer->refcnt);
                }
        }
 
@@ -309,6 +349,7 @@ int fb_release_buffer(void *data)
 int fb_refcnt(void *data)
 {
        struct buffer *buffer;
+       int ret;
 
        if (!data)
                return -EINVAL;
@@ -320,7 +361,23 @@ int fb_refcnt(void *data)
                return -EINVAL;
        }
 
-       return buffer->refcnt;
+       if (buffer->type == BUFFER_TYPE_SHM) {
+               struct shmid_ds buf;
+
+               if (shmctl(buffer->refcnt, IPC_STAT, &buf) < 0) {
+                       ErrPrint("Error: %s\n", strerror(errno));
+                       return -EFAULT;
+               }
+
+               ret = buf.shm_nattch;
+       } else if (buffer->type == BUFFER_TYPE_PIXMAP) {
+               ErrPrint("Pixmap is not supported yet\n");
+               return -ENOTSUP;
+       } else {
+               ret = buffer->refcnt;
+       }
+
+       return ret;
 }
 
 const char *fb_id(struct fb_info *info)
index 9f3e5aa..727c5b7 100644 (file)
@@ -1139,6 +1139,20 @@ EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
 
        *w = handler->pd.width;
        *h = handler->pd.height;
+
+       switch (handler->pd.type) {
+       case _PD_TYPE_BUFFER:
+       case _PD_TYPE_SCRIPT:
+               if (!fb_is_created(handler->pd.data.fb)) {
+                       DbgPrint("Buffer is not created yet - reset size\n");
+                       *w = 0;
+                       *h = 0;
+               }
+               break;
+       default:
+               break;
+       }
+
        return 0;
 }
 
@@ -1164,6 +1178,20 @@ EAPI int livebox_get_size(struct livebox *handler, int *w, int *h)
 
        *w = handler->lb.width;
        *h = handler->lb.height;
+
+       switch (handler->lb.type) {
+       case _LB_TYPE_BUFFER:
+       case _LB_TYPE_SCRIPT:
+               if (!fb_is_created(handler->lb.data.fb)) {
+                       DbgPrint("Buffer is not created yet - reset size\n");
+                       *w = 0;
+                       *h = 0;
+               }
+               break;
+       default:
+               break;
+       }
+
        return 0;
 }
 
@@ -1394,8 +1422,13 @@ EAPI void *livebox_acquire_fb(struct livebox *handler)
                return NULL;
        }
 
-       if (handler->state != CREATE || !handler->id || handler->lb.type != _LB_TYPE_SCRIPT) {
-               ErrPrint("Handler is not valid\n");
+       if (handler->state != CREATE || !handler->id) {
+               ErrPrint("Invalid handle\n");
+               return NULL;
+       }
+
+       if (handler->lb.type != _LB_TYPE_SCRIPT && handler->lb.type != _LB_TYPE_BUFFER) {
+               ErrPrint("Handler is not valid type\n");
                return NULL;
        }
 
@@ -1404,7 +1437,6 @@ EAPI void *livebox_acquire_fb(struct livebox *handler)
 
 EAPI int livebox_release_fb(void *buffer)
 {
-       DbgPrint("Release buffer: %p\n", buffer);
        return fb_release_buffer(buffer);
 }
 
@@ -1420,8 +1452,13 @@ EAPI void *livebox_acquire_pdfb(struct livebox *handler)
                return NULL;
        }
 
-       if (handler->state != CREATE || !handler->id || handler->pd.type != _PD_TYPE_SCRIPT) {
-               ErrPrint("Handler is not valid\n");
+       if (handler->state != CREATE || !handler->id) {
+               ErrPrint("Invalid handler\n");
+               return NULL;
+       }
+
+       if (handler->pd.type != _PD_TYPE_SCRIPT && handler->pd.type != _PD_TYPE_BUFFER) {
+               ErrPrint("Handler is not valid type\n");
                return NULL;
        }
 
@@ -1651,12 +1688,14 @@ int lb_set_group(struct livebox *handler, const char *cluster, const char *categ
 
 void lb_set_size(struct livebox *handler, int w, int h)
 {
+       DbgPrint("LB[%s] Size: %dx%d\n", util_basename(fb_id(handler->lb.data.fb)), w, h);
        handler->lb.width = w;
        handler->lb.height = h;
 }
 
 void lb_set_pdsize(struct livebox *handler, int w, int h)
 {
+       DbgPrint("PD[%s] Size: %dx%d\n", util_basename(fb_id(handler->pd.data.fb)), w, h);
        handler->pd.width = w;
        handler->pd.height = h;
 }
@@ -1939,7 +1978,6 @@ int lb_set_lb_fb(struct livebox *handler, const char *filename)
                return -EFAULT;
        }
 
-       handler->lb.type = _LB_TYPE_SCRIPT;
        if (fb)
                fb_destroy(fb);
        return 0;
@@ -1976,7 +2014,6 @@ int lb_set_pd_fb(struct livebox *handler, const char *filename)
                return -EFAULT;
        }
 
-       handler->pd.type = _PD_TYPE_SCRIPT;
        if (fb)
                fb_destroy(fb);
        return 0;