Improve tbm_surface_internal_dump_buffer() to show gem name 06/139506/4
authorYoungJun Cho <yj44.cho@samsung.com>
Wed, 19 Jul 2017 07:06:59 +0000 (16:06 +0900)
committerYoungJun Cho <yj44.cho@samsung.com>
Thu, 20 Jul 2017 00:59:13 +0000 (09:59 +0900)
This patch improves tbm_surface_internal_dump_buffer() to show gem name.

Change-Id: I3f2cbc5b325f2c6c36eeb628e88a8559b8b0cc30
Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
src/tbm_surface_internal.c

index df77fe7..09c298b 100644 (file)
@@ -1876,6 +1876,52 @@ cant_convert:
        return TBM_SURFACE_ERROR_INVALID_OPERATION;
 }
 
+#define MAX_BOS                4       // This value is came from bos[4] in struct _tbm_surface
+#define KEY_LEN                5       // "_XXXX"
+#define KEYS_LEN       KEY_LEN * MAX_BOS
+
+static char *_tbm_surface_internal_get_keys(tbm_surface_h surface)
+{
+       char *keys, temp_key[KEY_LEN + 1];
+       struct _tbm_surface *surf;
+       int i, num_bos;
+       tbm_bo bo;
+
+       _tbm_surface_mutex_lock();
+
+       TBM_SURFACE_RETURN_VAL_IF_FAIL(_tbm_surface_internal_is_valid(surface), NULL);
+
+       surf = (struct _tbm_surface *)surface;
+
+       num_bos = surf->num_bos;
+       if (num_bos > MAX_BOS)
+               num_bos = MAX_BOS;
+
+       keys = calloc(KEYS_LEN + 1, sizeof(char));
+       if (!keys) {
+               TBM_LOG_E("Failed to alloc memory");
+               _tbm_surface_mutex_unlock();
+               return NULL;
+       }
+
+       for (i = 0; i < num_bos; i++) {
+               memset(temp_key, 0x00, KEY_LEN + 1);
+               bo = surf->bos[i];
+               snprintf(temp_key, KEY_LEN, "_%d", tbm_bo_export(bo));
+               strncat(keys, temp_key, KEY_LEN);
+       }
+
+       _tbm_surface_mutex_unlock();
+
+       return keys;
+}
+
+static void _tbm_surface_internal_put_keys(char *keys)
+{
+       if (keys)
+               free(keys);
+}
+
 void
 tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type)
 {
@@ -1887,6 +1933,7 @@ tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type)
        tbm_surface_info_s info;
        tbm_bo_handle bo_handle;
        const char *postfix;
+       char *keys;
        int ret;
 
        if (!g_dump_info)
@@ -1949,10 +1996,18 @@ tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type)
        else
                postfix = dump_postfix[1];
 
+       keys = _tbm_surface_internal_get_keys(surface);
+       if (!keys) {
+               TBM_LOG_E("fail to get keys");
+               tbm_surface_unmap(surface);
+               return;
+       }
+
        /* dump */
        bo_handle = tbm_bo_map(buf_info->bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
        if (!bo_handle.ptr) {
                TBM_LOG_E("fail to map bo");
+               _tbm_surface_internal_put_keys(keys);
                tbm_surface_unmap(surface);
                return;
        }
@@ -1962,9 +2017,9 @@ tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type)
        case TBM_FORMAT_ARGB8888:
        case TBM_FORMAT_XRGB8888:
                snprintf(buf_info->name, sizeof(buf_info->name),
-                               "%10.3f_%03d_%p-%s.%s",
+                               "%10.3f_%03d%s_%p-%s.%s",
                                 _tbm_surface_internal_get_time(),
-                                g_dump_info->count++, surface, type, postfix);
+                                g_dump_info->count++, keys, surface, type, postfix);
 
                if (scale_factor > 0.0) {
                        ret = _tbm_surface_internal_buffer_scale(info.planes[0].ptr,
@@ -1978,6 +2033,7 @@ tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type)
                        if (ret != TBM_SURFACE_ERROR_NONE) {
                                TBM_LOG_E("fail to scale buffer");
                                tbm_bo_unmap(buf_info->bo);
+                               _tbm_surface_internal_put_keys(keys);
                                tbm_surface_unmap(surface);
                                return;
                        }
@@ -1987,9 +2043,9 @@ tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type)
        case TBM_FORMAT_YVU420:
        case TBM_FORMAT_YUV420:
                snprintf(buf_info->name, sizeof(buf_info->name),
-                               "%10.3f_%03d-%s_%dx%d_%c%c%c%c.%s",
+                               "%10.3f_%03d%s-%s_%dx%d_%c%c%c%c.%s",
                                 _tbm_surface_internal_get_time(),
-                                g_dump_info->count++, type, info.planes[0].stride,
+                                g_dump_info->count++, keys, type, info.planes[0].stride,
                                info.height, FOURCC_STR(info.format), postfix);
                memcpy(bo_handle.ptr, info.planes[0].ptr, info.planes[0].stride * info.height);
                bo_handle.ptr += info.planes[0].stride * info.height;
@@ -2000,9 +2056,9 @@ tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type)
        case TBM_FORMAT_NV12:
        case TBM_FORMAT_NV21:
                snprintf(buf_info->name, sizeof(buf_info->name),
-                               "%10.3f_%03d-%s_%dx%d_%c%c%c%c.%s",
+                               "%10.3f_%03d%s-%s_%dx%d_%c%c%c%c.%s",
                                 _tbm_surface_internal_get_time(),
-                                g_dump_info->count++, type, info.planes[0].stride,
+                                g_dump_info->count++, keys, type, info.planes[0].stride,
                                info.height, FOURCC_STR(info.format), postfix);
                memcpy(bo_handle.ptr, info.planes[0].ptr, info.planes[0].stride * info.height);
                bo_handle.ptr += info.planes[0].stride * info.height;
@@ -2011,21 +2067,24 @@ tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type)
        case TBM_FORMAT_YUYV:
        case TBM_FORMAT_UYVY:
                snprintf(buf_info->name, sizeof(buf_info->name),
-                               "%10.3f_%03d-%s_%dx%d_%c%c%c%c.%s",
+                               "%10.3f_%03d%s-%s_%dx%d_%c%c%c%c.%s",
                                 _tbm_surface_internal_get_time(),
-                                g_dump_info->count++, type, info.planes[0].stride,
+                                g_dump_info->count++, keys, type, info.planes[0].stride,
                                info.height, FOURCC_STR(info.format), postfix);
                memcpy(bo_handle.ptr, info.planes[0].ptr, info.planes[0].stride * info.height);
                break;
        default:
                TBM_LOG_E("can't copy %c%c%c%c buffer", FOURCC_STR(info.format));
                tbm_bo_unmap(buf_info->bo);
+               _tbm_surface_internal_put_keys(keys);
                tbm_surface_unmap(surface);
                return;
        }
 
        tbm_bo_unmap(buf_info->bo);
 
+       _tbm_surface_internal_put_keys(keys);
+
        tbm_surface_unmap(surface);
 
        buf_info->dirty = 1;