Re: [Mesa-dev] [PATCH weston] compositor: add support for OES_EGL_image_external

2012-08-17 Thread Pekka Paalanen
On Thu, 16 Aug 2012 17:28:20 -0500
Rob Clark rob.cl...@linaro.org wrote:

 From: Rob Clark r...@ti.com
 
 In cases where the GPU can natively handle certain YUV formats,
 eglQueryWaylandBufferWL() can return the value EGL_TEXTURE_EXTERNAL_WL
 and the compositor will treat the buffer as a single egl-image-external.
 
 See:
 http://www.khronos.org/registry/gles/extensions/OES/OES_EGL_image_external.txt
 
 v1: original
 v2: rename EGL_TEXTURE_EXTERNAL_OES - EGL_TEXTURE_EXTERNAL_WL and query
 for the extension
 
 Signed-off-by: Rob Clark r...@ti.com

Looks good to me now. The only thing I could still say is that maybe it
would be nice to log a warning, if the extension is not detected, but
querySurface still returns EGL_TEXTURE_EXTERNAL_WL.

Hmm, that reminds me, I don't think we have any EGL or GL error
reporting in Weston... but that's a whole different story.


Thanks,
pq


 ---
  src/compositor.c |   47 +--
  src/compositor.h |2 ++
  src/weston-egl-ext.h |1 +
  3 files changed, 40 insertions(+), 10 deletions(-)
 
 diff --git a/src/compositor.c b/src/compositor.c
 index b2a3ae9..5c6782e 100644
 --- a/src/compositor.c
 +++ b/src/compositor.c
 @@ -719,14 +719,14 @@ ensure_textures(struct weston_surface *es, int 
 num_textures)
  
   for (i = es-num_textures; i  num_textures; i++) {
   glGenTextures(1, es-textures[i]);
 - glBindTexture(GL_TEXTURE_2D, es-textures[i]);
 - glTexParameteri(GL_TEXTURE_2D,
 + glBindTexture(es-target, es-textures[i]);
 + glTexParameteri(es-target,
   GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 - glTexParameteri(GL_TEXTURE_2D,
 + glTexParameteri(es-target,
   GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   }
   es-num_textures = num_textures;
 - glBindTexture(GL_TEXTURE_2D, 0);
 + glBindTexture(es-target, 0);
  }
  
  static void
 @@ -771,6 +771,7 @@ weston_surface_attach(struct wl_surface *surface, struct 
 wl_buffer *buffer)
   if (wl_buffer_is_shm(buffer)) {
   es-pitch = wl_shm_buffer_get_stride(buffer) / 4;
   es-shader = ec-texture_shader_rgba;
 + es-target = GL_TEXTURE_2D;
  
   ensure_textures(es, 1);
   glBindTexture(GL_TEXTURE_2D, es-textures[0]);
 @@ -786,7 +787,7 @@ weston_surface_attach(struct wl_surface *surface, struct 
 wl_buffer *buffer)
   for (i = 0; i  es-num_images; i++)
   ec-destroy_image(ec-egl_display, es-images[i]);
   es-num_images = 0;
 -
 + es-target = GL_TEXTURE_2D;
   switch (format) {
   case EGL_TEXTURE_RGB:
   case EGL_TEXTURE_RGBA:
 @@ -794,6 +795,11 @@ weston_surface_attach(struct wl_surface *surface, struct 
 wl_buffer *buffer)
   num_planes = 1;
   es-shader = ec-texture_shader_rgba;
   break;
 + case EGL_TEXTURE_EXTERNAL_WL:
 + num_planes = 1;
 + es-target = GL_TEXTURE_EXTERNAL_OES;
 + es-shader = ec-texture_shader_egl_external;
 + break;
   case EGL_TEXTURE_Y_UV_WL:
   num_planes = 2;
   es-shader = ec-texture_shader_y_uv;
 @@ -824,8 +830,8 @@ weston_surface_attach(struct wl_surface *surface, struct 
 wl_buffer *buffer)
   es-num_images++;
  
   glActiveTexture(GL_TEXTURE0 + i);
 - glBindTexture(GL_TEXTURE_2D, es-textures[i]);
 - ec-image_target_texture_2d(GL_TEXTURE_2D,
 + glBindTexture(es-target, es-textures[i]);
 + ec-image_target_texture_2d(es-target,
   es-images[i]);
   }
  
 @@ -942,9 +948,9 @@ weston_surface_draw(struct weston_surface *es, struct 
 weston_output *output,
   for (i = 0; i  es-num_textures; i++) {
   glUniform1i(es-shader-tex_uniforms[i], i);
   glActiveTexture(GL_TEXTURE0 + i);
 - glBindTexture(GL_TEXTURE_2D, es-textures[i]);
 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
 + glBindTexture(es-target, es-textures[i]);
 + glTexParameteri(es-target, GL_TEXTURE_MIN_FILTER, filter);
 + glTexParameteri(es-target, GL_TEXTURE_MAG_FILTER, filter);
   }
  
   v = ec-vertices.data;
 @@ -2842,6 +2848,19 @@ static const char texture_fragment_shader_rgba[] =
   FRAGMENT_SHADER_EXIT
   }\n;
  
 +static const char texture_fragment_shader_egl_external[] =
 + #extension GL_OES_EGL_image_external : require\n
 + precision mediump float;\n
 + varying vec2 v_texcoord;\n
 + uniform 

Re: [Mesa-dev] [PATCH weston] compositor: add support for OES_EGL_image_external

2012-08-17 Thread Rob Clark
On Fri, Aug 17, 2012 at 1:09 AM, Pekka Paalanen ppaala...@gmail.com wrote:
 On Thu, 16 Aug 2012 17:28:20 -0500
 Rob Clark rob.cl...@linaro.org wrote:

 From: Rob Clark r...@ti.com

 In cases where the GPU can natively handle certain YUV formats,
 eglQueryWaylandBufferWL() can return the value EGL_TEXTURE_EXTERNAL_WL
 and the compositor will treat the buffer as a single egl-image-external.

 See:
 http://www.khronos.org/registry/gles/extensions/OES/OES_EGL_image_external.txt

 v1: original
 v2: rename EGL_TEXTURE_EXTERNAL_OES - EGL_TEXTURE_EXTERNAL_WL and query
 for the extension

 Signed-off-by: Rob Clark r...@ti.com

 Looks good to me now. The only thing I could still say is that maybe it
 would be nice to log a warning, if the extension is not detected, but
 querySurface still returns EGL_TEXTURE_EXTERNAL_WL.

I was debating about putting an assert in there to make it more
explicit that query_surface should never return
EGL_TEXTURE_EXTERNAL_WL if the gl driver doesn't support
OES_EGL_image_external.  I guess it could be a warning too, although
there is nothing really sane that weston could do as a fallback

BR,
-R

 Hmm, that reminds me, I don't think we have any EGL or GL error
 reporting in Weston... but that's a whole different story.


 Thanks,
 pq


 ---
  src/compositor.c |   47 +--
  src/compositor.h |2 ++
  src/weston-egl-ext.h |1 +
  3 files changed, 40 insertions(+), 10 deletions(-)

 diff --git a/src/compositor.c b/src/compositor.c
 index b2a3ae9..5c6782e 100644
 --- a/src/compositor.c
 +++ b/src/compositor.c
 @@ -719,14 +719,14 @@ ensure_textures(struct weston_surface *es, int 
 num_textures)

   for (i = es-num_textures; i  num_textures; i++) {
   glGenTextures(1, es-textures[i]);
 - glBindTexture(GL_TEXTURE_2D, es-textures[i]);
 - glTexParameteri(GL_TEXTURE_2D,
 + glBindTexture(es-target, es-textures[i]);
 + glTexParameteri(es-target,
   GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 - glTexParameteri(GL_TEXTURE_2D,
 + glTexParameteri(es-target,
   GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   }
   es-num_textures = num_textures;
 - glBindTexture(GL_TEXTURE_2D, 0);
 + glBindTexture(es-target, 0);
  }

  static void
 @@ -771,6 +771,7 @@ weston_surface_attach(struct wl_surface *surface, struct 
 wl_buffer *buffer)
   if (wl_buffer_is_shm(buffer)) {
   es-pitch = wl_shm_buffer_get_stride(buffer) / 4;
   es-shader = ec-texture_shader_rgba;
 + es-target = GL_TEXTURE_2D;

   ensure_textures(es, 1);
   glBindTexture(GL_TEXTURE_2D, es-textures[0]);
 @@ -786,7 +787,7 @@ weston_surface_attach(struct wl_surface *surface, struct 
 wl_buffer *buffer)
   for (i = 0; i  es-num_images; i++)
   ec-destroy_image(ec-egl_display, es-images[i]);
   es-num_images = 0;
 -
 + es-target = GL_TEXTURE_2D;
   switch (format) {
   case EGL_TEXTURE_RGB:
   case EGL_TEXTURE_RGBA:
 @@ -794,6 +795,11 @@ weston_surface_attach(struct wl_surface *surface, 
 struct wl_buffer *buffer)
   num_planes = 1;
   es-shader = ec-texture_shader_rgba;
   break;
 + case EGL_TEXTURE_EXTERNAL_WL:
 + num_planes = 1;
 + es-target = GL_TEXTURE_EXTERNAL_OES;
 + es-shader = ec-texture_shader_egl_external;
 + break;
   case EGL_TEXTURE_Y_UV_WL:
   num_planes = 2;
   es-shader = ec-texture_shader_y_uv;
 @@ -824,8 +830,8 @@ weston_surface_attach(struct wl_surface *surface, struct 
 wl_buffer *buffer)
   es-num_images++;

   glActiveTexture(GL_TEXTURE0 + i);
 - glBindTexture(GL_TEXTURE_2D, es-textures[i]);
 - ec-image_target_texture_2d(GL_TEXTURE_2D,
 + glBindTexture(es-target, es-textures[i]);
 + ec-image_target_texture_2d(es-target,
   es-images[i]);
   }

 @@ -942,9 +948,9 @@ weston_surface_draw(struct weston_surface *es, struct 
 weston_output *output,
   for (i = 0; i  es-num_textures; i++) {
   glUniform1i(es-shader-tex_uniforms[i], i);
   glActiveTexture(GL_TEXTURE0 + i);
 - glBindTexture(GL_TEXTURE_2D, es-textures[i]);
 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
 + glBindTexture(es-target, es-textures[i]);
 + glTexParameteri(es-target, GL_TEXTURE_MIN_FILTER, filter);
 + glTexParameteri(es-target, GL_TEXTURE_MAG_FILTER,