Interface to provider is changed
[platform/framework/web/livebox-viewer.git] / src / fb.c
index d1fe2de..13f6658 100644 (file)
--- a/src/fb.c
+++ b/src/fb.c
@@ -1,11 +1,11 @@
 /*
  * Copyright 2013  Samsung Electronics Co., Ltd
  *
- * Licensed under the Flora License, Version 1.0 (the "License");
+ * Licensed under the Flora License, Version 1.1 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://www.tizenopensource.org/license
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -54,7 +54,7 @@ struct fb_info {
 struct buffer { /*!< Must has to be sync with slave & provider */
        enum {
                CREATED = 0x00beef00,
-               DESTROYED = 0x00dead00,
+               DESTROYED = 0x00dead00
        } state;
        enum buffer_type type;
        int refcnt;
@@ -113,8 +113,9 @@ static inline int sync_for_file(struct fb_info *info)
 
        buffer = info->buffer;
 
-       if (!buffer) /* Ignore this sync request */
+       if (!buffer) /* Ignore this sync request */
                return LB_STATUS_SUCCESS;
+       }
 
        if (buffer->state != CREATED) {
                ErrPrint("Invalid state of a FB\n");
@@ -122,7 +123,7 @@ static inline int sync_for_file(struct fb_info *info)
        }
 
        if (buffer->type != BUFFER_TYPE_FILE) {
-               DbgPrint("Invalid buffer\n");
+               ErrPrint("Invalid buffer\n");
                return LB_STATUS_SUCCESS;
        }
 
@@ -143,7 +144,9 @@ static inline int sync_for_file(struct fb_info *info)
 
        if (read(fd, buffer->data, info->bufsz) != info->bufsz) {
                ErrPrint("read: %s\n", strerror(errno));
-               close(fd);
+               if (close(fd) < 0) {
+                       ErrPrint("close: %s\n", strerror(errno));
+               }
 
                /*!
                 * \note
@@ -155,7 +158,9 @@ static inline int sync_for_file(struct fb_info *info)
                return LB_STATUS_SUCCESS;
        }
 
-       close(fd);
+       if (close(fd) < 0) {
+               ErrPrint("close: %s\n", strerror(errno));
+       }
        return LB_STATUS_SUCCESS;
 }
 
@@ -166,8 +171,9 @@ static inline __attribute__((always_inline)) int sync_for_pixmap(struct fb_info
        XImage *xim;
 
        buffer = info->buffer;
-       if (!buffer) /*!< Ignore this sync request */
+       if (!buffer) /*!< Ignore this sync request */
                return LB_STATUS_SUCCESS;
+       }
 
        if (buffer->state != CREATED) {
                ErrPrint("Invalid state of a FB\n");
@@ -175,7 +181,7 @@ static inline __attribute__((always_inline)) int sync_for_pixmap(struct fb_info
        }
 
        if (buffer->type != BUFFER_TYPE_PIXMAP) {
-               DbgPrint("Invalid buffer\n");
+               ErrPrint("Invalid buffer\n");
                return LB_STATUS_SUCCESS;
        }
 
@@ -197,7 +203,7 @@ static inline __attribute__((always_inline)) int sync_for_pixmap(struct fb_info
        }
 
        if (info->handle == 0) {
-               DbgPrint("Pixmap ID is not valid\n");
+               ErrPrint("Pixmap ID is not valid\n");
                return LB_STATUS_ERROR_INVALID;
        }
 
@@ -215,9 +221,9 @@ static inline __attribute__((always_inline)) int sync_for_pixmap(struct fb_info
        si.readOnly = False;
        si.shmaddr = shmat(si.shmid, NULL, 0);
        if (si.shmaddr == (void *)-1) {
-
-               if (shmctl(si.shmid, IPC_RMID, 0) < 0)
+               if (shmctl(si.shmid, IPC_RMID, 0) < 0) {
                        ErrPrint("shmctl: %s\n", strerror(errno));
+               }
 
                return LB_STATUS_ERROR_FAULT;
        }
@@ -227,15 +233,17 @@ static inline __attribute__((always_inline)) int sync_for_pixmap(struct fb_info
         * Use the 24 bits Pixmap for Video player
         */
        xim = XShmCreateImage(s_info.disp, s_info.visual,
-                               24 /* (s_info.depth << 3) */, ZPixmap, NULL,
+                               (s_info.depth << 3), ZPixmap, NULL,
                                &si,
                                info->w, info->h);
        if (xim == NULL) {
-               if (shmdt(si.shmaddr) < 0)
+               if (shmdt(si.shmaddr) < 0) {
                        ErrPrint("shmdt: %s\n", strerror(errno));
+               }
 
-               if (shmctl(si.shmid, IPC_RMID, 0) < 0)
+               if (shmctl(si.shmid, IPC_RMID, 0) < 0) {
                        ErrPrint("shmctl: %s\n", strerror(errno));
+               }
 
                return LB_STATUS_ERROR_FAULT;
        }
@@ -251,11 +259,13 @@ static inline __attribute__((always_inline)) int sync_for_pixmap(struct fb_info
        XShmDetach(s_info.disp, &si);
        XDestroyImage(xim);
 
-       if (shmdt(si.shmaddr) < 0)
+       if (shmdt(si.shmaddr) < 0) {
                ErrPrint("shmdt: %s\n", strerror(errno));
+       }
 
-       if (shmctl(si.shmid, IPC_RMID, 0) < 0)
+       if (shmctl(si.shmid, IPC_RMID, 0) < 0) {
                ErrPrint("shmctl: %s\n", strerror(errno));
+       }
 
        return LB_STATUS_SUCCESS;
 }
@@ -447,7 +457,7 @@ int fb_release_buffer(void *data)
        struct buffer *buffer;
 
        if (!data) {
-               DbgPrint("buffer data == NIL\n");
+               ErrPrint("buffer data == NIL\n");
                return 0;
        }
 
@@ -460,8 +470,9 @@ int fb_release_buffer(void *data)
 
        switch (buffer->type) {
        case BUFFER_TYPE_SHM:
-               if (shmdt(buffer) < 0)
+               if (shmdt(buffer) < 0) {
                        ErrPrint("shmdt: %s\n", strerror(errno));
+               }
                break;
        case BUFFER_TYPE_PIXMAP:
                buffer->refcnt--;
@@ -472,8 +483,9 @@ int fb_release_buffer(void *data)
                        buffer->state = DESTROYED;
                        free(buffer);
                
-                       if (info && info->buffer == buffer)
+                       if (info && info->buffer == buffer) {
                                info->buffer = NULL;
+                       }
                }
                break;
        case BUFFER_TYPE_FILE:
@@ -485,8 +497,9 @@ int fb_release_buffer(void *data)
                        buffer->state = DESTROYED;
                        free(buffer);
 
-                       if (info && info->buffer == buffer)
+                       if (info && info->buffer == buffer) {
                                info->buffer = NULL;
+                       }
                }
                break;
        default:
@@ -503,8 +516,9 @@ int fb_refcnt(void *data)
        struct shmid_ds buf;
        int ret;
 
-       if (!data)
+       if (!data) {
                return LB_STATUS_ERROR_INVALID;
+       }
 
        buffer = container_of(data, struct buffer, data);
 
@@ -555,8 +569,12 @@ int fb_get_size(struct fb_info *info, int *w, int *h)
 
 int fb_size(struct fb_info *info)
 {
+       if (!info) {
+               return 0;
+       }
+
        info->bufsz = info->w * info->h * s_info.depth;
-       return info ? info->bufsz : 0;
+       return info->bufsz;
 }
 
 /* End of a file */