add tbm bo allocation for tizen waylandsink 49/153749/6
authorKwangCheol Lee <kclee@dignsys.com>
Fri, 29 Sep 2017 08:45:51 +0000 (17:45 +0900)
committerKwangCheol Lee <kclee@dignsys.com>
Mon, 16 Oct 2017 06:09:09 +0000 (15:09 +0900)
Change-Id: Ib2713a7ac8747df6e5c1ea99085010e4f8bd0616
Signed-off-by: KwangCheol Lee <kclee@dignsys.com>
packaging/nx-video-api.spec
src/Makefile.am
src/nx_video_alloc.c
src/nx_video_alloc.h

index f219054..f4adaec 100644 (file)
@@ -8,6 +8,7 @@ Source:  %{name}-%{version}.tar.gz
 
 BuildRequires:  pkgconfig automake autoconf libtool
 BuildRequires:  pkgconfig(libdrm)
+BuildRequires:  pkgconfig(libtbm)
 
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
index a93bb81..1d443ac 100644 (file)
@@ -1,11 +1,12 @@
 AM_CFLAGS = \
        $(WARN_CFLAGS)  \
+       -DTIZEN_FEATURE_ARTIK530 \
        -I./include             \
        -I${includedir}
 
 libnx_video_api_la_LTLIBRARIES = libnx_video_api.la
 libnx_video_api_ladir = ${libdir}
-libnx_video_api_la_LDFLAGS = -L${libdir} -ldrm
+libnx_video_api_la_LDFLAGS = -L${libdir} -ldrm -ltbm
 
 libnx_video_api_la_SOURCES = \
        nx_video_alloc.c        \
index 8ee1972..effd3f8 100644 (file)
@@ -25,6 +25,9 @@
 #include <libdrm/drm_fourcc.h>
 #include <linux/videodev2.h>
 #include <linux/videodev2_nxp_media.h>
+#ifdef TIZEN_FEATURE_ARTIK530
+#include <tbm_bufmgr.h>
+#endif
 
 #define DRM_DEVICE_NAME "/dev/dri/card0"
 
@@ -355,6 +358,15 @@ NX_AllocateVideoMemory (int width, int height, int32_t planes, uint32_t format,
   }
 
   pVidMem = (NX_VID_MEMORY_INFO *) calloc (1, sizeof (NX_VID_MEMORY_INFO));
+  if (!pVidMem)
+    goto ErrorExit;
+
+#ifdef TIZEN_FEATURE_ARTIK530
+  pVidMem->bufmgr = tbm_bufmgr_init (drmFd);
+  if (!pVidMem->bufmgr)
+    goto ErrorExit;
+#endif
+
   pVidMem->width = width;
   pVidMem->height = height;
   pVidMem->align = align;
@@ -367,9 +379,22 @@ NX_AllocateVideoMemory (int width, int height, int32_t planes, uint32_t format,
     pVidMem->size[i] = size[i];
     pVidMem->stride[i] = stride[i];
     pVidMem->flink[i] = flink[i];
+#ifdef TIZEN_FEATURE_ARTIK530
+    pVidMem->bo[i] = tbm_bo_import (pVidMem->bufmgr, flink[i]);
+    if (!pVidMem->bo[i])
+      goto alloc_bo_fail;
+#endif
   }
   return pVidMem;
 
+#ifdef TIZEN_FEATURE_ARTIK530
+alloc_bo_fail:
+  for (i = 0; i < planes; i++) {
+    if (pVidMem->bo[i])
+      tbm_bo_unref (pVidMem->bo[i]);
+  }
+#endif
+
 ErrorExit:
   for (i = 0; i < planes; i++) {
     if (gemFd[i] > 0) {
@@ -379,6 +404,13 @@ ErrorExit:
       close (dmaFd[i]);
     }
   }
+  if (pVidMem) {
+#ifdef TIZEN_FEATURE_ARTIK530
+    if (pVidMem->bufmgr)
+      tbm_bufmgr_deinit (pVidMem->bufmgr);
+#endif
+    free(pVidMem);
+  }
   if (drmFd > 0)
     close (drmFd);
 
@@ -391,12 +423,20 @@ NX_FreeVideoMemory (NX_VID_MEMORY_INFO * pMem)
   int32_t i;
   if (pMem) {
     for (i = 0; i < pMem->planes; i++) {
+#ifdef TIZEN_FEATURE_ARTIK530
+      if (pMem->bo[i])
+        tbm_bo_unref (pMem->bo[i]);
+#endif
       if (pMem->pBuffer[i]) {
         munmap (pMem->pBuffer[i], pMem->size[i]);
       }
       free_gem (pMem->drmFd, pMem->gemFd[i]);
       close (pMem->dmaFd[i]);
     }
+#ifdef TIZEN_FEATURE_ARTIK530
+    if (pMem->bufmgr)
+      tbm_bufmgr_deinit (pMem->bufmgr);
+#endif
     close (pMem->drmFd);
     free (pMem);
   }
index a612a4b..1049437 100644 (file)
@@ -51,6 +51,10 @@ extern "C"
     int32_t stride[NX_MAX_PLANES];      //      Each plane's stride.
     void *pBuffer[NX_MAX_PLANES];       //      virtual address.
     uint32_t reserved[NX_MAX_PLANES];   //      for debugging or future user.
+#ifdef TIZEN_FEATURE_ARTIK530
+    void *bufmgr;
+    void *bo[NX_MAX_PLANES]; // tbm bo
+#endif
   } NX_VID_MEMORY_INFO, *NX_VID_MEMORY_HANDLE;
 
 //      Nexell Private Memory Allocator