add shm buffer dump API 84/69584/2 accepted/tizen/common/20160517.173839 accepted/tizen/ivi/20160517.032145 accepted/tizen/mobile/20160517.032125 accepted/tizen/tv/20160517.032133 accepted/tizen/wearable/20160517.032227 submit/tizen/20160516.074649
authorJunkyeong Kim <jk0430.kim@samsung.com>
Mon, 16 May 2016 03:36:01 +0000 (12:36 +0900)
committerJunkyeong Kim <jk0430.kim@samsung.com>
Mon, 16 May 2016 07:23:31 +0000 (16:23 +0900)
Change-Id: Ib47f3a727c9694c1230a2b4dee452efdb8de6e77
Signed-off-by: Junkyeong Kim <jk0430.kim@samsung.com>
src/tbm_surface_internal.c
src/tbm_surface_internal.h

index f1a94b3..4f79c10 100644 (file)
@@ -1153,6 +1153,9 @@ struct _tbm_surface_dump_buf_info
        tbm_bo bo;
        int size;
        int dirty;
+       int dirty_shm;
+       int shm_stride;
+       int shm_h;
        char name[1024];
 
        tbm_surface_info_s info;
@@ -1368,8 +1371,9 @@ tbm_surface_internal_dump_end(void)
        /* make files */
        if (!LIST_IS_EMPTY(&g_dump_info->surface_list)) {
                LIST_FOR_EACH_ENTRY_SAFE(buf_info, tmp, &g_dump_info->surface_list, link) {
+                       char file[2048];
+
                        if (buf_info->dirty) {
-                               char file[2048];
                                void *ptr1 = NULL;
                                void *ptr2 = NULL;
 
@@ -1384,7 +1388,7 @@ tbm_surface_internal_dump_end(void)
                                case TBM_FORMAT_ARGB8888:
                                case TBM_FORMAT_XRGB8888:
                                        _tbm_surface_internal_dump_file_png(file, bo_handle.ptr,
-                                                                                       buf_info->info.planes[0].stride >> 2, buf_info->info.height);
+                                                                       buf_info->info.planes[0].stride >> 2, buf_info->info.height);
                                        break;
                                case TBM_FORMAT_YVU420:
                                case TBM_FORMAT_YUV420:
@@ -1419,6 +1423,18 @@ tbm_surface_internal_dump_end(void)
                                }
 
                                tbm_bo_unmap(buf_info->bo);
+                       } else if (buf_info->dirty_shm) {
+                               bo_handle = tbm_bo_map(buf_info->bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
+                               if (bo_handle.ptr == NULL)
+                                       continue;
+
+                               snprintf(file, sizeof(file), "%s/%s", g_dump_info->path, buf_info->name);
+                               TBM_LOG("Dump File.. %s generated.\n", file);
+
+                               _tbm_surface_internal_dump_file_png(file, bo_handle.ptr,
+                                                               buf_info->shm_stride >> 2, buf_info->shm_h);
+
+                               tbm_bo_unmap(buf_info->bo);
                        }
                }
        }
@@ -1528,6 +1544,63 @@ tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type)
        tbm_surface_unmap(surface);
 
        buf_info->dirty = 1;
+       buf_info->dirty_shm = 0;
+
+       if (g_dump_info->count == 1000)
+               g_dump_info->count = 0;
+
+       g_dump_info->link = next_link;
+
+       TBM_LOG("Dump %s \n", buf_info->name);
+}
+
+void tbm_surface_internal_dump_shm_buffer(void *ptr, int w, int h, int  stride, const char *type)
+{
+       TBM_RETURN_IF_FAIL(ptr != NULL);
+       TBM_RETURN_IF_FAIL(w > 0);
+       TBM_RETURN_IF_FAIL(h > 0);
+       TBM_RETURN_IF_FAIL(stride > 0);
+       TBM_RETURN_IF_FAIL(type != NULL);
+
+       tbm_surface_dump_buf_info *buf_info;
+       struct list_head *next_link;
+       tbm_bo_handle bo_handle;
+
+       if (!g_dump_info)
+               return;
+
+       next_link = g_dump_info->link->next;
+       TBM_RETURN_IF_FAIL(next_link != NULL);
+
+       if (next_link == &g_dump_info->surface_list) {
+               next_link = next_link->next;
+               TBM_RETURN_IF_FAIL(next_link != NULL);
+       }
+
+       buf_info = LIST_ENTRY(tbm_surface_dump_buf_info, next_link, link);
+       TBM_RETURN_IF_FAIL(buf_info != NULL);
+
+       if (stride * h > buf_info->size) {
+               TBM_LOG("Dump skip. shm buffer over created buffer size(%d, %d)\n", stride * h, buf_info->size);
+               return;
+       }
+
+       /* dump */
+       bo_handle = tbm_bo_map(buf_info->bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
+       TBM_RETURN_IF_FAIL(bo_handle.ptr != NULL);
+       memset(bo_handle.ptr, 0x00, buf_info->size);
+       memset(&buf_info->info, 0x00, sizeof(tbm_surface_info_s));
+
+
+       snprintf(buf_info->name, sizeof(buf_info->name), "%03d-%s.%s", g_dump_info->count++, type, dump_postfix[0]);
+       memcpy(bo_handle.ptr, ptr, stride * h);
+
+       tbm_bo_unmap(buf_info->bo);
+
+       buf_info->dirty = 0;
+       buf_info->dirty_shm = 1;
+       buf_info->shm_stride = stride;
+       buf_info->shm_h = h;
 
        if (g_dump_info->count == 1000)
                g_dump_info->count = 0;
index fbda74a..6240494 100644 (file)
@@ -430,11 +430,23 @@ void tbm_surface_internal_dump_end(void);
  * The filename extension should be "png" for TBM_FORMAT_ARGB8888 and TBM_FORMAT_XRGB8888
  * or "yuv" for YUV formats.
  * @param[in] surface : a tbm surface
- * @param[in] type : a string used by a file name.
+ * @param[in] type : a string used by a file name
  */
 void tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type);
 
 /**
+ * @brief Dump a shared memory buffer
+ * @details
+ * This function supports shared memory buffer dump.
+ * @param[in] ptr : a pointer of dump buffer
+ * @param[in] w : a width of dump buffer
+ * @param[in] h : a height of dump buffer
+ * @param[in] stride : a stride of dump buffer
+ * @param[in] type : a string used by a file name
+ */
+void tbm_surface_internal_dump_shm_buffer(void *ptr, int w, int h, int stride, const char *type);
+
+/**
  * @brief check valid tbm surface.
  * @since_tizen 3.0
  * @param[in] surface : the tbm surface.