display-kmscube: Add support for RGB texture
authorRamprasad N <x0038811@ti.com>
Thu, 4 May 2017 07:46:11 +0000 (13:16 +0530)
committerKarthik Ramanan <a0393906@ti.com>
Wed, 10 May 2017 10:43:12 +0000 (16:13 +0530)
For RGB as texture on kmscube, gbm_bo import from
a dmabuf-fd is required. This is followed by creating
eglImage with EGL_NATIVE_PIXMAP_KHR as target.

To demonstrate this feature filevpedisplay can be used

filevpesiplay airshow_p352x288.yuv 352 288 nv12 720 480 abgr32 0 0 352 288 0 1
 --kmscube --connector 36 --fps 10

vpe output with is added as texture on kmscube.

Signed-off-by: Ramprasad N <x0038811@ti.com>
util/display-kmscube.c

index 33b296427edbc1586d4318a79a7dde2abc89e4a2..458c957de2570df3f8a595718443d76add11d9a6 100644 (file)
@@ -57,6 +57,7 @@
 
 #include "util.h"
 
 
 #include "util.h"
 
+#include <linux/videodev2.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -112,6 +113,7 @@ struct display_kmscube {
        struct {
                struct gbm_device *dev;
                struct gbm_surface *surface;
        struct {
                struct gbm_device *dev;
                struct gbm_surface *surface;
+               struct gbm_bo *bo;
        } gbm;
 
        // DRM.
        } gbm;
 
        // DRM.
@@ -778,7 +780,18 @@ alloc_buffer(struct display *disp, uint32_t fourcc, uint32_t w, uint32_t h)
                return NULL;
        }
        buf = &buf_kmsc->base;
                return NULL;
        }
        buf = &buf_kmsc->base;
-
+       switch(fourcc) {
+               case V4L2_PIX_FMT_RGB24:
+               case V4L2_PIX_FMT_BGR24:
+                       fourcc = FOURCC('R','G','2','4');
+                       break;
+               case V4L2_PIX_FMT_BGR32:
+               case V4L2_PIX_FMT_RGB32:
+                       fourcc = FOURCC('A','R','2','4');
+                       break;
+               default:
+                       break;
+       }
        buf->fourcc = fourcc;
        buf->width = w;
        buf->height = h;
        buf->fourcc = fourcc;
        buf->width = w;
        buf->height = h;
@@ -795,6 +808,12 @@ alloc_buffer(struct display *disp, uint32_t fourcc, uint32_t w, uint32_t h)
                buf->bo[0] = alloc_bo(disp, 32, buf->width, buf->height,
                                &bo_handles[0], &buf->pitches[0]);
                break;
                buf->bo[0] = alloc_bo(disp, 32, buf->width, buf->height,
                                &bo_handles[0], &buf->pitches[0]);
                break;
+       case FOURCC('R','G','2','4'):
+               buf->nbo = 1;
+               buf->bo[0] = alloc_bo(disp, 24, buf->width, buf->height,
+                               &bo_handles[0], &buf->pitches[0]);
+               break;
+
        case FOURCC('U','Y','V','Y'):
        case FOURCC('Y','U','Y','V'):
                buf->nbo = 1;
        case FOURCC('U','Y','V','Y'):
        case FOURCC('Y','U','Y','V'):
                buf->nbo = 1;
@@ -1073,7 +1092,16 @@ create_texture(struct display_kmscube *disp_kmsc, struct buffer *buf)
        // Create EGLImage and return.
        // TODO: cropping attributes when this will be supported.
        EGLint attr[20];
        // Create EGLImage and return.
        // TODO: cropping attributes when this will be supported.
        EGLint attr[20];
+       bool isRGB;
        int dfd = omap_bo_dmabuf(buf->bo[0]);
        int dfd = omap_bo_dmabuf(buf->bo[0]);
+       struct gbm_import_fd_data gbm_dmabuf = {
+               .fd     = dfd,
+               .width  = buf->width,
+               .height = buf->height,
+               .stride = buf->pitches[0],
+               .format = GBM_FORMAT_ARGB8888
+       };
+
        if(buf->fourcc == FOURCC('Y','U','Y','V')) {
                EGLint __attr[] = {
                        EGL_WIDTH,                      buf->width,
        if(buf->fourcc == FOURCC('Y','U','Y','V')) {
                EGLint __attr[] = {
                        EGL_WIDTH,                      buf->width,
@@ -1085,6 +1113,7 @@ create_texture(struct display_kmscube *disp_kmsc, struct buffer *buf)
                        EGL_NONE
                };
                memcpy(attr, __attr, sizeof(__attr));
                        EGL_NONE
                };
                memcpy(attr, __attr, sizeof(__attr));
+               isRGB = false;
        } else if(buf->fourcc == FOURCC('N','V','1','2')) {
                /*
                 * Please note that multiple dmabuf fds are not supported,
        } else if(buf->fourcc == FOURCC('N','V','1','2')) {
                /*
                 * Please note that multiple dmabuf fds are not supported,
@@ -1107,14 +1136,29 @@ create_texture(struct display_kmscube *disp_kmsc, struct buffer *buf)
                        EGL_NONE
                };
                memcpy(attr, __attr, sizeof(__attr));
                        EGL_NONE
                };
                memcpy(attr, __attr, sizeof(__attr));
+               isRGB = false;
+       } else if(buf->fourcc == FOURCC('A','R','2','4')) {
+               disp_kmsc->gbm.bo  = gbm_bo_import(disp_kmsc->gbm.dev, GBM_BO_IMPORT_FD, &gbm_dmabuf,
+                               GBM_BO_USE_SCANOUT);
+               if(!disp_kmsc->gbm.bo){
+                       ERROR("gbm_bo_import failed\n");
+                       return -1;
+               }
+
+               isRGB = true;
        } else {
                return -1;
        }
        } else {
                return -1;
        }
-
-       buf_kmsc->egl_img =
-       disp_kmsc->gl.eglCreateImageKHR(disp_kmsc->gl.display, EGL_NO_CONTEXT,
+       if(isRGB == false) {
+               buf_kmsc->egl_img =
+                       disp_kmsc->gl.eglCreateImageKHR(disp_kmsc->gl.display, EGL_NO_CONTEXT,
                                        EGL_LINUX_DMA_BUF_EXT, NULL, attr);
                                        EGL_LINUX_DMA_BUF_EXT, NULL, attr);
-
+       } else {
+               EGLint attrib_list = EGL_NONE;
+               buf_kmsc->egl_img =
+                       disp_kmsc->gl.eglCreateImageKHR(disp_kmsc->gl.display, EGL_NO_CONTEXT,
+                                       EGL_NATIVE_PIXMAP_KHR, disp_kmsc->gbm.bo, &attrib_list);
+       }
        if (buf_kmsc->egl_img == EGL_NO_IMAGE_KHR) {
                ERROR("eglCreateImageKHR failed!\n");
                goto fail;
        if (buf_kmsc->egl_img == EGL_NO_IMAGE_KHR) {
                ERROR("eglCreateImageKHR failed!\n");
                goto fail;