A proposed extension to create eglImageExternal buffers from YUV data.

Notes:

  • There would (probably?) be needed a variant of this that takes dmabuf and/or GEM buffer handles for integration with UMM.

  • I'm not picky on the name.. it can be called "linaro" instead of TI if other members would like to implement the same
  • Need to get a block of extension #'s reserved, can this be done thru linaro?
  • Need a sane way for client to find which color formats are supported
  • Need a sane way to pass multi-planar data as multiple pointers (and query if that is supported)

   1 #ifndef EGL_TI_raw_video
   2 #  define EGL_TI_raw_video 1
   3 #  define EGL_RAW_VIDEO_TI                                              0x333A  /* eglCreateImageKHR target */
   4 #  define EGL_GL_VIDEO_FOURCC_TI                                0x3331  /* eglCreateImageKHR attribute */
   5 #  define EGL_GL_VIDEO_WIDTH_TI                                 0x3332  /* eglCreateImageKHR attribute */
   6 #  define EGL_GL_VIDEO_HEIGHT_TI                                0x3333  /* eglCreateImageKHR attribute */
   7 #  define EGL_GL_VIDEO_BYTE_STRIDE_TI                   0x3334  /* eglCreateImageKHR attribute */
   8 #  define EGL_GL_VIDEO_BYTE_SIZE_TI                             0x3335  /* eglCreateImageKHR attribute */
   9 #  define EGL_GL_VIDEO_YUV_FLAGS_TI                             0x3336  /* eglCreateImageKHR attribute */
  10 #endif
  11 

example usage:

   1     const char *exts = (const char *)glGetString(GL_EXTENSIONS);
   2     if (!(strstr(exts, "GL_OES_EGL_image_external") &&
   3         strstr(exts, "GL_TI_image_external_raw_video"))) {
   4         printf("not supported!\n");
   5         return false;
   6     }
   7 
   8     PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR =
   9             (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR");
  10     PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES =
  11             (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
  12 
  13     EGLint attr[] = {
  14             EGL_GL_VIDEO_FOURCC_TI,      FOURCC_FROM_STR("NV12"),
  15             EGL_GL_VIDEO_WIDTH_TI,       VID_WIDTH,
  16             EGL_GL_VIDEO_HEIGHT_TI,      VID_HEIGHT,
  17             EGL_GL_VIDEO_BYTE_STRIDE_TI, VID_WIDTH,
  18             EGL_GL_VIDEO_BYTE_SIZE_TI,   VID_SIZE,
  19             EGL_GL_VIDEO_YUV_FLAGS_TI,   EGLIMAGE_FLAGS_YUV_CONFORMANT_RANGE | EGLIMAGE_FLAGS_YUV_BT601,
  20             EGL_NONE
  21     };
  22 
  23     unsigned char *ptr = (unsigned char *)malloc(VID_SIZE + PAGE_SIZE);
  24     ptr = (unsigned char *)((uint32_t)ptr & ~(PAGE_SIZE - 1));
  25 
  26     // fill test pattern with NV12:
  27     unsigned char *y = ptr;
  28     unsigned char *u = y + (VID_HEIGHT * VID_WIDTH);
  29     unsigned char *v = u + 1;
  30     fill420(y, u, v, 2, 0, VID_WIDTH, VID_HEIGHT, VID_WIDTH);
  31 
  32     EGLImageKHR img = eglCreateImageKHR(dpy, EGL_NO_CONTEXT, EGL_RAW_VIDEO_TI, ptr, attr);
  33     if (img == EGL_NO_IMAGE_KHR) {
  34         printf("eglCreateImageKHR failed\n");
  35         return false;
  36     }
  37 
  38     glGenTextures(1, &yuvTex);
  39     glBindTexture(GL_TEXTURE_EXTERNAL_OES, yuvTex);
  40     glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  41     glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  42     glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, (GLeglImageOES)img);
  43 
  44     return true;

WorkingGroups/Middleware/Graphics/Projects/eglImageExternal (last modified 2011-11-30 15:30:30)