lock/unlock outside of the helper function
[platform/core/uifw/libtdm.git] / src / tdm_helper.c
index 4adbcb8..cf05aa0 100644 (file)
@@ -44,6 +44,7 @@
 #include <string.h>
 #include <time.h>
 #include <pixman.h>
+#include <inttypes.h>
 
 #include "tdm.h"
 #include "tdm_private.h"
@@ -216,7 +217,7 @@ tdm_helper_dump_buffer_str(tbm_surface_h buffer, char *dir, char *str)
        tbm_surface_info_s info;
        const char *ext;
        char file[TDM_PATH_LEN];
-       int ret, bw;
+       int ret, bw, bh;
 
        TDM_RETURN_IF_FAIL(buffer != NULL);
        TDM_RETURN_IF_FAIL(dir != NULL);
@@ -225,16 +226,15 @@ tdm_helper_dump_buffer_str(tbm_surface_h buffer, char *dir, char *str)
        ret = tbm_surface_get_info(buffer, &info);
        TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
 
-       if (info.format == TBM_FORMAT_ARGB8888 || info.format == TBM_FORMAT_XRGB8888) {
+       if (IS_RGB(info.format))
                ext = file_exts[0];
-               bw = info.planes[0].stride >> 2;
-       } else {
+       else
                ext = file_exts[1];
-               bw = info.planes[0].stride;
-       }
 
-       snprintf(file, TDM_PATH_LEN, "%s/%c%c%c%c_%dx%d_%s.%s",
-                        dir, FOURCC_STR(info.format), bw, info.height, str, ext);
+       tdm_helper_get_buffer_full_size(buffer, &bw, &bh);
+
+       snprintf(file, TDM_PATH_LEN, "%s/%c%c%c%c_%dx%d_%dx%d_%s.%s",
+                        dir, FOURCC_STR(info.format), bw, bh, info.width, info.height, str, ext);
 
        tdm_helper_dump_buffer(buffer, file);
 }
@@ -246,6 +246,7 @@ tdm_helper_dump_buffer(tbm_surface_h buffer, const char *file)
        int len, ret;
        const char *ext;
        int bo_cnt;
+       int bw, bh;
 
        TDM_RETURN_IF_FAIL(buffer != NULL);
        TDM_RETURN_IF_FAIL(file != NULL);
@@ -254,7 +255,7 @@ tdm_helper_dump_buffer(tbm_surface_h buffer, const char *file)
        TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
 
        len = strnlen(file, 1024);
-       if (info.format == TBM_FORMAT_ARGB8888 || info.format == TBM_FORMAT_XRGB8888)
+       if (IS_RGB(info.format))
                ext = file_exts[0];
        else
                ext = file_exts[1];
@@ -265,9 +266,11 @@ tdm_helper_dump_buffer(tbm_surface_h buffer, const char *file)
                return;
        }
 
+       tdm_helper_get_buffer_full_size(buffer, &bw, &bh);
+
        bo_cnt = tbm_surface_internal_get_num_bos(buffer);
-       TDM_DBG("buffer: bo_cnt(%d) %dx%d %c%c%c%c, plane: (%p+%d, %d,%d) (%p+%d, %d,%d) (%p+%d, %d,%d)",
-                       bo_cnt, info.width, info.height, FOURCC_STR(info.format),
+       TDM_DBG("buffer: bo_cnt(%d) %dx%d(%dx%d) %c%c%c%c, plane: (%p+%d, %d,%d) (%p+%d, %d,%d) (%p+%d, %d,%d)",
+                       bo_cnt, bw, bh, info.width, info.height, FOURCC_STR(info.format),
                        info.planes[0].ptr, info.planes[0].offset, info.planes[0].stride, info.planes[0].size,
                        info.planes[1].ptr, info.planes[1].offset, info.planes[1].stride, info.planes[1].size,
                        info.planes[2].ptr, info.planes[2].offset, info.planes[2].stride, info.planes[2].size);
@@ -275,37 +278,32 @@ tdm_helper_dump_buffer(tbm_surface_h buffer, const char *file)
        switch (info.format) {
        case TBM_FORMAT_ARGB8888:
        case TBM_FORMAT_XRGB8888:
-               _tdm_helper_dump_png(file, info.planes[0].ptr,
-                                                        info.planes[0].stride >> 2, info.height);
+               _tdm_helper_dump_png(file, info.planes[0].ptr, bw, bh);
                break;
        case TBM_FORMAT_YVU420:
        case TBM_FORMAT_YUV420:
                _tdm_helper_dump_raw(file,
                                                         info.planes[0].ptr,
-                                                        info.planes[0].stride * info.height,
+                                                        info.planes[0].size,
                                                         info.planes[1].ptr,
-                                                        info.planes[1].stride * (info.height >> 1),
+                                                        info.planes[1].size,
                                                         info.planes[2].ptr,
-                                                        info.planes[2].stride * (info.height >> 1));
+                                                        info.planes[2].size);
                break;
        case TBM_FORMAT_NV12:
        case TBM_FORMAT_NV21:
-               if (bo_cnt == 1 &&
-                       (info.planes[0].ptr + info.planes[0].stride * info.height) != info.planes[1].ptr)
-                       TDM_WRN("%p != %p", info.planes[0].ptr + info.planes[0].stride * info.height, info.planes[1].ptr);
-
                _tdm_helper_dump_raw(file,
                                                         info.planes[0].ptr,
-                                                        info.planes[0].stride * info.height,
+                                                        info.planes[0].size,
                                                         info.planes[1].ptr,
-                                                        info.planes[1].stride * (info.height >> 1), NULL,
+                                                        info.planes[1].size, NULL,
                                                         0);
                break;
        case TBM_FORMAT_YUYV:
        case TBM_FORMAT_UYVY:
                _tdm_helper_dump_raw(file,
                                                         info.planes[0].ptr,
-                                                        info.planes[0].stride * info.height, NULL, 0,
+                                                        info.planes[0].size, NULL, 0,
                                                         NULL, 0);
                break;
        default:
@@ -390,6 +388,28 @@ tdm_helper_clear_buffer(tbm_surface_h buffer)
        tdm_helper_clear_buffer_pos(buffer, NULL);
 }
 
+EXTERN void
+tdm_helper_get_buffer_full_size(tbm_surface_h buffer, int *buffer_w, int *buffer_h)
+{
+       tbm_surface_info_s info;
+       int ret;
+
+       TDM_RETURN_IF_FAIL(buffer != NULL);
+
+       ret = tbm_surface_get_info(buffer, &info);
+       TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
+
+       if (buffer_w) {
+               if (IS_RGB(info.format))
+                       *buffer_w = info.planes[0].stride >> 2;
+               else
+                       *buffer_w = info.planes[0].stride;
+       }
+
+       if (buffer_h)
+               *buffer_h = info.planes[0].size / info.planes[0].stride;
+}
+
 static pixman_format_code_t
 _tdm_helper_pixman_format_get(tbm_format format)
 {
@@ -528,7 +548,7 @@ tdm_helper_get_fd(const char *env)
        if (!value)
                return -1;
 
-       const long sl = strtol(value, &end, 10);
+       const long int sl = strtol(value, &end, 10);
        if (end == value) {
                TDM_ERR("%s: not a decimal number\n", value);
                return -1;
@@ -538,10 +558,10 @@ tdm_helper_get_fd(const char *env)
        } else if ((sl == LONG_MIN || sl == LONG_MAX) && errno == ERANGE) {
                TDM_ERR("%s out of range of type long\n", value);
                return -1;
-       } else if (sl > INT_MAX) {
+       } else if (sl >= INT_MAX) {
                TDM_ERR("%ld greater than INT_MAX\n", sl);
                return -1;
-       } else if (sl < INT_MIN) {
+       } else if (sl <= INT_MIN) {
                TDM_ERR("%ld less than INT_MIN\n", sl);
                return -1;
        } else {
@@ -769,7 +789,6 @@ tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len)
        private_display = dpy;
        func_output = &private_display->func_output;
        func_layer = &private_display->func_layer;
-       _pthread_mutex_lock(&private_display->lock);
 
        /* module information */
        module_data = private_display->module_data;
@@ -805,9 +824,9 @@ tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len)
                if (private_output->caps.mode_count > 0) {
                        const tdm_output_mode *current_mode = NULL;
 
-                       TDM_DBG_GOTO_IF_FAIL(func_output->output_get_mode, unlock);
+                       TDM_DBG_RETURN_IF_FAIL(func_output->output_get_mode);
                        ret = func_output->output_get_mode(private_output->output_backend, &current_mode);
-                       TDM_DBG_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
+                       TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
 
                        TDM_SNPRINTF(reply, len, "\t\t name refresh (Hz) clk hdisp hss hse htot vdisp vss vse vtot vscan\n");
                        for (i = 0; i < private_output->caps.mode_count; i++) {
@@ -835,18 +854,36 @@ tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len)
 
                TDM_SNPRINTF(reply, len, "\t%d properties:\n", private_output->caps.prop_count);
                if (private_output->caps.prop_count > 0) {
-                       TDM_SNPRINTF(reply, len, "\t\tname\tidx\tvalue\n");
+                       TDM_SNPRINTF(reply, len, "\t\tname\ttype\tidx\tvalue\n");
                        for (i = 0; i < private_output->caps.prop_count; i++) {
                                tdm_value value;
-                               TDM_DBG_GOTO_IF_FAIL(func_output->output_get_property, unlock);
+                               TDM_DBG_RETURN_IF_FAIL(func_output->output_get_property);
                                ret = func_output->output_get_property(private_output->output_backend,
                                                                                                           private_output->caps.props[i].id,
                                                                                                           &value);
-                               TDM_DBG_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
-                               TDM_SNPRINTF(reply, len, "\t\t%s\t%u\t%u\n",
+                               TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
+                               TDM_SNPRINTF(reply, len, "\t\t%s\t%s\t%u\t",
                                                         private_output->caps.props[i].name,
-                                                        private_output->caps.props[i].id,
-                                                        value.u32);
+                                                        tdm_value_type_str(private_output->caps.props[i].type),
+                                                        private_output->caps.props[i].id);
+                               switch (private_output->caps.props[i].type) {
+                               case TDM_VALUE_TYPE_PTR:
+                                       TDM_SNPRINTF(reply, len, "%p\n", value.ptr);
+                                       break;
+                               case TDM_VALUE_TYPE_INT32:
+                                       TDM_SNPRINTF(reply, len, "%d\n", value.s32);
+                                       break;
+                               case TDM_VALUE_TYPE_INT64:
+                                       TDM_SNPRINTF(reply, len, "%"PRId64"\n", value.s64);
+                                       break;
+                               case TDM_VALUE_TYPE_UINT64:
+                                       TDM_SNPRINTF(reply, len, "%"PRIu64"\n", value.u64);
+                                       break;
+                               case TDM_VALUE_TYPE_UINT32:
+                               default:
+                                       TDM_SNPRINTF(reply, len, "%u\n", value.u32);
+                                       break;
+                               }
                        }
                }
        }
@@ -865,10 +902,10 @@ tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len)
                                tdm_size size;
                                tbm_surface_info_s buf_info;
 
-                               TDM_DBG_GOTO_IF_FAIL(func_layer->layer_get_info, unlock);
+                               TDM_DBG_RETURN_IF_FAIL(func_layer->layer_get_info);
                                memset(&info, 0, sizeof info);
                                ret = func_layer->layer_get_info(private_layer->layer_backend, &info);
-                               TDM_DBG_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
+                               TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
 
                                if (!private_layer->showing_buffer)
                                        continue;
@@ -918,18 +955,36 @@ tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len)
 
                        TDM_SNPRINTF(reply, len, "\t%u properties:\n", private_layer->caps.prop_count);
                        if (private_layer->caps.prop_count > 0) {
-                               TDM_SNPRINTF(reply, len, "\t\tname\tidx\tvalue\n");
+                               TDM_SNPRINTF(reply, len, "\t\tname\ttype\tidx\tvalue\n");
                                for (i = 0; i < private_layer->caps.prop_count; i++) {
                                        tdm_value value;
-                                       TDM_DBG_GOTO_IF_FAIL(func_layer->layer_get_property, unlock);
+                                       TDM_DBG_RETURN_IF_FAIL(func_layer->layer_get_property);
                                        ret = func_layer->layer_get_property(private_layer->layer_backend,
                                                                                                                 private_layer->caps.props[i].id,
                                                                                                                 &value);
-                                       TDM_DBG_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
-                                       TDM_SNPRINTF(reply, len, "\t\t%s\t%u\t%u\n",
+                                       TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
+                                       TDM_SNPRINTF(reply, len, "\t\t%s\t%s\t%u\t",
                                                                 private_layer->caps.props[i].name,
-                                                                private_layer->caps.props[i].id,
-                                                                value.u32);
+                                                                tdm_value_type_str(private_output->caps.props[i].type),
+                                                                private_layer->caps.props[i].id);
+                               switch (private_layer->caps.props[i].type) {
+                               case TDM_VALUE_TYPE_PTR:
+                                       TDM_SNPRINTF(reply, len, "%p\n", value.ptr);
+                                       break;
+                               case TDM_VALUE_TYPE_INT32:
+                                       TDM_SNPRINTF(reply, len, "%d\n", value.s32);
+                                       break;
+                               case TDM_VALUE_TYPE_INT64:
+                                       TDM_SNPRINTF(reply, len, "%"PRId64"\n", value.s64);
+                                       break;
+                               case TDM_VALUE_TYPE_UINT64:
+                                       TDM_SNPRINTF(reply, len, "%"PRIu64"\n", value.u64);
+                                       break;
+                               case TDM_VALUE_TYPE_UINT32:
+                               default:
+                                       TDM_SNPRINTF(reply, len, "%u\n", value.u32);
+                                       break;
+                               }
                                }
                        }
                }
@@ -1018,9 +1073,6 @@ tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len)
                TDM_SNPRINTF(reply, len, "[No Capture capability]\n");
        }
        TDM_SNPRINTF(reply, len, "\n");
-
-unlock:
-       _pthread_mutex_unlock(&private_display->lock);
 }
 
 EXTERN int