eglglessink: Update for GLTextureUploadMeta and EGL API changes
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 17 Apr 2013 08:48:31 +0000 (10:48 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 17 Apr 2013 08:51:18 +0000 (10:51 +0200)
ext/eglgles/gstegladaptation.c
ext/eglgles/gstegladaptation.h
ext/eglgles/gstegladaptation_egl.c
ext/eglgles/gsteglglessink.c
ext/eglgles/gsteglglessink.h

index 7b0c7e3..0731cbd 100644 (file)
@@ -104,18 +104,6 @@ static const char *frag_COPY_prog = {
       "}"
 };
 
-/* Direct fragments copy without stride-scaling */
-static const char *frag_COPY_DIRECT_prog = {
-  "precision mediump float;"
-      "varying vec2 opos;"
-      "uniform sampler2D tex;"
-      "void main(void)"
-      "{"
-      " vec4 t = texture2D(tex, opos);"
-      " gl_FragColor = vec4(t.rgb, 1.0);"
-      "}"
-};
-
 /* Channel reordering for XYZ <-> ZYX conversion */
 static const char *frag_REORDER_prog = {
   "precision mediump float;"
@@ -323,12 +311,12 @@ gst_egl_adaptation_cleanup (GstEglAdaptationContext * ctx)
   }
 
   if (ctx->have_texture) {
-    glDeleteTextures (ctx->n_textures + 1, ctx->texture);
+    glDeleteTextures (ctx->n_textures, ctx->texture);
     ctx->have_texture = FALSE;
     ctx->n_textures = 0;
   }
 
-  for (i = 0; i < 3; i++) {
+  for (i = 0; i < 2; i++) {
     if (ctx->glslprogram[i]) {
       glDetachShader (ctx->glslprogram[i], ctx->fragshader[i]);
       glDetachShader (ctx->glslprogram[i], ctx->vertshader[i]);
@@ -611,30 +599,6 @@ gst_egl_adaptation_init_egl_surface (GstEglAdaptationContext * ctx,
         glGetUniformLocation (ctx->glslprogram[0], texnames[i]);
   }
 
-  /* custom rendering shader */
-
-  if (!create_shader_program (ctx,
-          &ctx->glslprogram[2],
-          &ctx->vertshader[2],
-          &ctx->fragshader[2], vert_COPY_prog, frag_COPY_DIRECT_prog)) {
-    if (free_frag_prog)
-      g_free (frag_prog);
-    frag_prog = NULL;
-    goto HANDLE_ERROR;
-  }
-  if (free_frag_prog)
-    g_free (frag_prog);
-  frag_prog = NULL;
-
-  ctx->position_loc[2] = glGetAttribLocation (ctx->glslprogram[2], "position");
-  ctx->texpos_loc[1] = glGetAttribLocation (ctx->glslprogram[2], "texpos");
-
-  glEnableVertexAttribArray (ctx->position_loc[2]);
-  if (got_gl_error ("glEnableVertexAttribArray"))
-    goto HANDLE_ERROR;
-
-  ctx->tex_loc[1][0] = glGetUniformLocation (ctx->glslprogram[2], "tex");
-
   if (!ctx->buffer_preserved) {
     /* Build shader program for black borders */
     if (!create_shader_program (ctx,
@@ -655,11 +619,11 @@ gst_egl_adaptation_init_egl_surface (GstEglAdaptationContext * ctx,
   if (!ctx->have_texture) {
     GST_INFO_OBJECT (ctx->element, "Performing initial texture setup");
 
-    glGenTextures (ctx->n_textures + 1, ctx->texture);
+    glGenTextures (ctx->n_textures, ctx->texture);
     if (got_gl_error ("glGenTextures"))
       goto HANDLE_ERROR_LOCKED;
 
-    for (i = 0; i < ctx->n_textures + 1; i++) {
+    for (i = 0; i < ctx->n_textures; i++) {
       glBindTexture (GL_TEXTURE_2D, ctx->texture[i]);
       if (got_gl_error ("glBindTexture"))
         goto HANDLE_ERROR;
index 63eec95..e30b570 100644 (file)
@@ -126,15 +126,15 @@ struct _GstEglAdaptationContext
   GstEGLDisplay *display, *set_display;
   EGLNativeWindowType window, used_window;
 
-  GLuint fragshader[3]; /* frame, border, frame-custom */
-  GLuint vertshader[3]; /* frame, border, frame-custom */
-  GLuint glslprogram[3]; /* frame, border, frame-custom */
-  GLuint texture[4]; /* RGB/Y, U/UV, V, custom */
+  GLuint fragshader[2]; /* frame, border */
+  GLuint vertshader[2]; /* frame, border */
+  GLuint glslprogram[2]; /* frame, border */
+  GLuint texture[3]; /* RGB/Y, U/UV, V */
   /* shader vars */
-  GLuint position_loc[3]; /* frame, border, frame-custom */
-  GLuint texpos_loc[2]; /* frame, frame-custom */
+  GLuint position_loc[2]; /* frame, border */
+  GLuint texpos_loc[1]; /* frame */
   GLuint tex_scale_loc[1][3]; /* [frame] RGB/Y, U/UV, V */
-  GLuint tex_loc[2][3]; /* [frame,frame-custom] RGB/Y, U/UV, V */
+  GLuint tex_loc[1][3]; /* [frame] RGB/Y, U/UV, V */
   coord5 position_array[16];    /* 4 x Frame x-normal,y-normal, 4x Frame x-normal,y-flip, 4 x Border1, 4 x Border2 */
   unsigned short index_array[4];
   unsigned int position_buffer, index_buffer;
index edd360a..50df421 100644 (file)
@@ -440,7 +440,7 @@ gst_egl_adaptation_allocate_eglimage (GstEglAdaptationContext * ctx,
 
       mem[0] =
           gst_egl_image_allocator_alloc (allocator, ctx->display,
-          GST_EGL_IMAGE_MEMORY_TYPE_RGB, GST_VIDEO_INFO_WIDTH (&info),
+          GST_VIDEO_GL_TEXTURE_TYPE_RGB, GST_VIDEO_INFO_WIDTH (&info),
           GST_VIDEO_INFO_HEIGHT (&info), &size);
       if (mem[0]) {
         stride[0] = size / GST_VIDEO_INFO_HEIGHT (&info);
@@ -488,7 +488,7 @@ gst_egl_adaptation_allocate_eglimage (GstEglAdaptationContext * ctx,
 
         mem[0] =
             gst_egl_image_allocator_wrap (allocator, ctx->display,
-            image, GST_EGL_IMAGE_MEMORY_TYPE_RGB,
+            image, GST_VIDEO_GL_TEXTURE_TYPE_RGB,
             flags, size, data, (GDestroyNotify) gst_egl_gles_image_data_free);
         n_mem = 1;
       }
@@ -500,7 +500,7 @@ gst_egl_adaptation_allocate_eglimage (GstEglAdaptationContext * ctx,
 
       mem[0] =
           gst_egl_image_allocator_alloc (allocator, ctx->display,
-          GST_EGL_IMAGE_MEMORY_TYPE_RGB, GST_VIDEO_INFO_WIDTH (&info),
+          GST_VIDEO_GL_TEXTURE_TYPE_RGB, GST_VIDEO_INFO_WIDTH (&info),
           GST_VIDEO_INFO_HEIGHT (&info), &size);
       if (mem[0]) {
         stride[0] = size / GST_VIDEO_INFO_HEIGHT (&info);
@@ -549,7 +549,7 @@ gst_egl_adaptation_allocate_eglimage (GstEglAdaptationContext * ctx,
 
         mem[0] =
             gst_egl_image_allocator_wrap (allocator, ctx->display,
-            image, GST_EGL_IMAGE_MEMORY_TYPE_RGB,
+            image, GST_VIDEO_GL_TEXTURE_TYPE_RGB,
             flags, size, data, (GDestroyNotify) gst_egl_gles_image_data_free);
         n_mem = 1;
       }
@@ -562,11 +562,11 @@ gst_egl_adaptation_allocate_eglimage (GstEglAdaptationContext * ctx,
 
       mem[0] =
           gst_egl_image_allocator_alloc (allocator, ctx->display,
-          GST_EGL_IMAGE_MEMORY_TYPE_LUMINANCE, GST_VIDEO_INFO_COMP_WIDTH (&info,
+          GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE, GST_VIDEO_INFO_COMP_WIDTH (&info,
               0), GST_VIDEO_INFO_COMP_HEIGHT (&info, 0), &size[0]);
       mem[1] =
           gst_egl_image_allocator_alloc (allocator, ctx->display,
-          GST_EGL_IMAGE_MEMORY_TYPE_LUMINANCE_ALPHA,
+          GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE_ALPHA,
           GST_VIDEO_INFO_COMP_WIDTH (&info, 1),
           GST_VIDEO_INFO_COMP_HEIGHT (&info, 1), &size[1]);
 
@@ -639,8 +639,8 @@ gst_egl_adaptation_allocate_eglimage (GstEglAdaptationContext * ctx,
               gst_egl_image_allocator_wrap (allocator, ctx->display,
               image,
               (i ==
-                  0 ? GST_EGL_IMAGE_MEMORY_TYPE_LUMINANCE :
-                  GST_EGL_IMAGE_MEMORY_TYPE_LUMINANCE_ALPHA),
+                  0 ? GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE :
+                  GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE_ALPHA),
               flags, size[i], data,
               (GDestroyNotify) gst_egl_gles_image_data_free);
         }
@@ -659,15 +659,15 @@ gst_egl_adaptation_allocate_eglimage (GstEglAdaptationContext * ctx,
 
       mem[0] =
           gst_egl_image_allocator_alloc (allocator, ctx->display,
-          GST_EGL_IMAGE_MEMORY_TYPE_LUMINANCE, GST_VIDEO_INFO_COMP_WIDTH (&info,
+          GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE, GST_VIDEO_INFO_COMP_WIDTH (&info,
               0), GST_VIDEO_INFO_COMP_HEIGHT (&info, 0), &size[0]);
       mem[1] =
           gst_egl_image_allocator_alloc (allocator, ctx->display,
-          GST_EGL_IMAGE_MEMORY_TYPE_LUMINANCE, GST_VIDEO_INFO_COMP_WIDTH (&info,
+          GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE, GST_VIDEO_INFO_COMP_WIDTH (&info,
               1), GST_VIDEO_INFO_COMP_HEIGHT (&info, 1), &size[1]);
       mem[2] =
           gst_egl_image_allocator_alloc (allocator, ctx->display,
-          GST_EGL_IMAGE_MEMORY_TYPE_LUMINANCE, GST_VIDEO_INFO_COMP_WIDTH (&info,
+          GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE, GST_VIDEO_INFO_COMP_WIDTH (&info,
               2), GST_VIDEO_INFO_COMP_HEIGHT (&info, 2), &size[2]);
 
       if (mem[0] && mem[1] && mem[2]) {
@@ -740,7 +740,7 @@ gst_egl_adaptation_allocate_eglimage (GstEglAdaptationContext * ctx,
 
           mem[i] =
               gst_egl_image_allocator_wrap (allocator, ctx->display,
-              image, GST_EGL_IMAGE_MEMORY_TYPE_LUMINANCE,
+              image, GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE,
               flags, size[i], data,
               (GDestroyNotify) gst_egl_gles_image_data_free);
         }
@@ -763,7 +763,7 @@ gst_egl_adaptation_allocate_eglimage (GstEglAdaptationContext * ctx,
 
       mem[0] =
           gst_egl_image_allocator_alloc (allocator, ctx->display,
-          GST_EGL_IMAGE_MEMORY_TYPE_RGBA, GST_VIDEO_INFO_WIDTH (&info),
+          GST_VIDEO_GL_TEXTURE_TYPE_RGBA, GST_VIDEO_INFO_WIDTH (&info),
           GST_VIDEO_INFO_HEIGHT (&info), &size);
       if (mem[0]) {
         stride[0] = size / GST_VIDEO_INFO_HEIGHT (&info);
@@ -811,7 +811,7 @@ gst_egl_adaptation_allocate_eglimage (GstEglAdaptationContext * ctx,
 
         mem[0] =
             gst_egl_image_allocator_wrap (allocator, ctx->display,
-            image, GST_EGL_IMAGE_MEMORY_TYPE_RGBA,
+            image, GST_VIDEO_GL_TEXTURE_TYPE_RGBA,
             flags, size, data, (GDestroyNotify) gst_egl_gles_image_data_free);
 
         n_mem = 1;
index 4526132..8236e5c 100644 (file)
@@ -1513,24 +1513,35 @@ gst_eglglessink_upload (GstEglGlesSink * eglglessink, GstBuffer * buf)
     }
 
     if (upload_meta) {
-      glActiveTexture (GL_TEXTURE0);
-      glBindTexture (GL_TEXTURE_2D,
-          eglglessink->egl_context->texture[eglglessink->
-              egl_context->n_textures]);
-      if (!gst_video_gl_texture_upload_meta_upload (upload_meta, GL_RGBA,
-              eglglessink->egl_context->texture[eglglessink->
-                  egl_context->n_textures]))
+      gint i;
+
+      if (upload_meta->n_textures != eglglessink->egl_context->n_textures)
         goto HANDLE_ERROR;
 
-      eglglessink->orientation = GST_EGL_IMAGE_ORIENTATION_X_NORMAL_Y_NORMAL;
-      eglglessink->custom_format = TRUE;
+      for (i = 0; i < eglglessink->egl_context->n_textures; i++) {
+        if (i == 0)
+          glActiveTexture (GL_TEXTURE0);
+        else if (i == 1)
+          glActiveTexture (GL_TEXTURE1);
+        else if (i == 2)
+          glActiveTexture (GL_TEXTURE2);
+
+        glBindTexture (GL_TEXTURE_2D, eglglessink->egl_context->texture[i]);
+      }
+
+      if (!gst_video_gl_texture_upload_meta_upload (upload_meta,
+              eglglessink->egl_context->texture))
+        goto HANDLE_ERROR;
+
+      eglglessink->orientation = upload_meta->texture_orientation;
+      eglglessink->stride[0] = 1;
+      eglglessink->stride[1] = 1;
+      eglglessink->stride[2] = 1;
     } else if (gst_buffer_n_memory (buf) >= 1 &&
         (mem = gst_buffer_peek_memory (buf, 0))
         && gst_is_egl_image_memory (mem)) {
       guint n, i;
 
-      eglglessink->custom_format = FALSE;
-
       n = gst_buffer_n_memory (buf);
 
       for (i = 0; i < n; i++) {
@@ -1552,9 +1563,9 @@ gst_eglglessink_upload (GstEglGlesSink * eglglessink, GstBuffer * buf)
           goto HANDLE_ERROR;
         eglglessink->orientation = gst_egl_image_memory_get_orientation (mem);
         if (eglglessink->orientation !=
-            GST_EGL_IMAGE_ORIENTATION_X_NORMAL_Y_NORMAL
+            GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL
             && eglglessink->orientation !=
-            GST_EGL_IMAGE_ORIENTATION_X_NORMAL_Y_FLIP) {
+            GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_FLIP) {
           GST_ERROR_OBJECT (eglglessink, "Unsupported EGLImage orientation");
           return GST_FLOW_ERROR;
         }
@@ -1564,9 +1575,8 @@ gst_eglglessink_upload (GstEglGlesSink * eglglessink, GstBuffer * buf)
       eglglessink->stride[1] = 1;
       eglglessink->stride[2] = 1;
     } else {
-      eglglessink->custom_format = FALSE;
-
-      eglglessink->orientation = GST_EGL_IMAGE_ORIENTATION_X_NORMAL_Y_NORMAL;
+      eglglessink->orientation =
+          GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL;
       if (!gst_eglglessink_fill_texture (eglglessink, buf))
         goto HANDLE_ERROR;
     }
@@ -1706,66 +1716,46 @@ gst_eglglessink_render (GstEglGlesSink * eglglessink)
   /* Draw video frame */
   GST_DEBUG_OBJECT (eglglessink, "Drawing video frame");
 
-  if (eglglessink->custom_format) {
-    glUseProgram (eglglessink->egl_context->glslprogram[2]);
+  glUseProgram (eglglessink->egl_context->glslprogram[0]);
 
-    glUniform1i (eglglessink->egl_context->tex_loc[1][0], 0);
+  glUniform2f (eglglessink->egl_context->tex_scale_loc[0][0],
+      eglglessink->stride[0], 1);
+  glUniform2f (eglglessink->egl_context->tex_scale_loc[0][1],
+      eglglessink->stride[1], 1);
+  glUniform2f (eglglessink->egl_context->tex_scale_loc[0][2],
+      eglglessink->stride[2], 1);
+
+  for (i = 0; i < eglglessink->egl_context->n_textures; i++) {
+    glUniform1i (eglglessink->egl_context->tex_loc[0][i], i);
     if (got_gl_error ("glUniform1i"))
       goto HANDLE_ERROR;
+  }
 
-    glVertexAttribPointer (eglglessink->egl_context->position_loc[2], 3,
-        GL_FLOAT, GL_FALSE, sizeof (coord5), (gpointer) (0));
+  if (eglglessink->orientation ==
+      GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL) {
+    glVertexAttribPointer (eglglessink->egl_context->position_loc[0], 3,
+        GL_FLOAT, GL_FALSE, sizeof (coord5), (gpointer) (0 * sizeof (coord5)));
     if (got_gl_error ("glVertexAttribPointer"))
       goto HANDLE_ERROR;
 
-    glVertexAttribPointer (eglglessink->egl_context->texpos_loc[1], 2,
+    glVertexAttribPointer (eglglessink->egl_context->texpos_loc[0], 2,
         GL_FLOAT, GL_FALSE, sizeof (coord5), (gpointer) (3 * sizeof (gfloat)));
     if (got_gl_error ("glVertexAttribPointer"))
       goto HANDLE_ERROR;
-  } else {
-    glUseProgram (eglglessink->egl_context->glslprogram[0]);
-
-    glUniform2f (eglglessink->egl_context->tex_scale_loc[0][0],
-        eglglessink->stride[0], 1);
-    glUniform2f (eglglessink->egl_context->tex_scale_loc[0][1],
-        eglglessink->stride[1], 1);
-    glUniform2f (eglglessink->egl_context->tex_scale_loc[0][2],
-        eglglessink->stride[2], 1);
-
-    for (i = 0; i < eglglessink->egl_context->n_textures; i++) {
-      glUniform1i (eglglessink->egl_context->tex_loc[0][i], i);
-      if (got_gl_error ("glUniform1i"))
-        goto HANDLE_ERROR;
-    }
-
-    if (eglglessink->orientation == GST_EGL_IMAGE_ORIENTATION_X_NORMAL_Y_NORMAL) {
-      glVertexAttribPointer (eglglessink->egl_context->position_loc[0], 3,
-          GL_FLOAT, GL_FALSE, sizeof (coord5),
-          (gpointer) (0 * sizeof (coord5)));
-      if (got_gl_error ("glVertexAttribPointer"))
-        goto HANDLE_ERROR;
-
-      glVertexAttribPointer (eglglessink->egl_context->texpos_loc[0], 2,
-          GL_FLOAT, GL_FALSE, sizeof (coord5),
-          (gpointer) (3 * sizeof (gfloat)));
-      if (got_gl_error ("glVertexAttribPointer"))
-        goto HANDLE_ERROR;
-    } else if (eglglessink->orientation ==
-        GST_EGL_IMAGE_ORIENTATION_X_NORMAL_Y_FLIP) {
-      glVertexAttribPointer (eglglessink->egl_context->position_loc[0], 3,
-          GL_FLOAT, GL_FALSE, sizeof (coord5),
-          (gpointer) (4 * sizeof (coord5)));
-      if (got_gl_error ("glVertexAttribPointer"))
-        goto HANDLE_ERROR;
+  } else if (eglglessink->orientation ==
+      GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_FLIP) {
+    glVertexAttribPointer (eglglessink->egl_context->position_loc[0], 3,
+        GL_FLOAT, GL_FALSE, sizeof (coord5), (gpointer) (4 * sizeof (coord5)));
+    if (got_gl_error ("glVertexAttribPointer"))
+      goto HANDLE_ERROR;
 
-      glVertexAttribPointer (eglglessink->egl_context->texpos_loc[0], 2,
-          GL_FLOAT, GL_FALSE, sizeof (coord5),
-          (gpointer) (4 * sizeof (coord5) + 3 * sizeof (gfloat)));
-      if (got_gl_error ("glVertexAttribPointer"))
-        goto HANDLE_ERROR;
-    } else {
-      g_assert_not_reached ();
-    }
+    glVertexAttribPointer (eglglessink->egl_context->texpos_loc[0], 2,
+        GL_FLOAT, GL_FALSE, sizeof (coord5),
+        (gpointer) (4 * sizeof (coord5) + 3 * sizeof (gfloat)));
+    if (got_gl_error ("glVertexAttribPointer"))
+      goto HANDLE_ERROR;
+  } else {
+    g_assert_not_reached ();
   }
 
   glDrawElements (GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, 0);
index e46f2e3..6a4ea9a 100644 (file)
@@ -106,8 +106,7 @@ struct _GstEglGlesSink
   GstCaps *current_caps, *configured_caps;
   GstVideoInfo configured_info;
   gfloat stride[3];
-  GstEGLImageOrientation orientation;
-  gboolean custom_format; /* If it's a single texture that is just copied */
+  GstVideoGLTextureOrientation orientation;
   GstBufferPool *pool;
 
   GstEglAdaptationContext *egl_context;