From: gb Date: Fri, 2 Apr 2010 11:27:23 +0000 (+0000) Subject: Fix TFP logic and simplify the FBO model. i.e. it's not necessary X-Git-Tag: accepted/trunk/20120822.173359~532 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b8aadb9e82fa9b4f5e5fb6e7d191e21261ca0dce;p=profile%2Fivi%2Fgstreamer-vaapi.git Fix TFP logic and simplify the FBO model. i.e. it's not necessary to create another texture (and storage) for the TFP, simply a new texture name. --- diff --git a/gst-libs/gst/vaapi/gstvaapitexture.c b/gst-libs/gst/vaapi/gstvaapitexture.c index 199ea11..083f034 100644 --- a/gst-libs/gst/vaapi/gstvaapitexture.c +++ b/gst-libs/gst/vaapi/gstvaapitexture.c @@ -593,7 +593,6 @@ _gst_vaapi_texture_put_surface( #else guint surface_width, surface_height; GLContextState old_cs; - GLTextureState ts; gboolean success = FALSE; gst_vaapi_surface_get_size(surface, &surface_width, &surface_height); @@ -613,19 +612,16 @@ _gst_vaapi_texture_put_surface( return FALSE; GST_VAAPI_OBJECT_LOCK_DISPLAY(texture); - success = gl_set_current_context(priv->gl_context, &old_cs); - if (!success) - goto end; - - if (!gl_bind_texture(&ts, priv->target, GST_VAAPI_OBJECT_ID(texture))) { - GST_DEBUG("could not bind texture %u", GST_VAAPI_OBJECT_ID(texture)); - goto out_reset_context; + if (priv->gl_context) { + success = gl_set_current_context(priv->gl_context, &old_cs); + if (!success) + goto end; } success = gl_bind_framebuffer_object(priv->fbo); if (!success) { GST_DEBUG("could not bind FBO"); - goto out_unbind_texture; + goto out_reset_context; } GST_VAAPI_OBJECT_UNLOCK_DISPLAY(texture); @@ -661,10 +657,8 @@ _gst_vaapi_texture_put_surface( out_unbind_fbo: if (!gl_unbind_framebuffer_object(priv->fbo)) success = FALSE; -out_unbind_texture: - gl_unbind_texture(&ts); out_reset_context: - if (!gl_set_current_context(&old_cs, NULL)) + if (priv->gl_context && !gl_set_current_context(&old_cs, NULL)) success = FALSE; end: GST_VAAPI_OBJECT_UNLOCK_DISPLAY(texture); diff --git a/gst-libs/gst/vaapi/gstvaapiutils_glx.c b/gst-libs/gst/vaapi/gstvaapiutils_glx.c index 60a7bc7..3e6632b 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_glx.c +++ b/gst-libs/gst/vaapi/gstvaapiutils_glx.c @@ -474,7 +474,7 @@ gl_bind_texture(GLTextureState *ts, GLenum target, GLuint texture) return FALSE; } - if (ts->was_enabled && !gl_get_param(texture_binding, &ts->old_texture)) + if (!gl_get_param(texture_binding, &ts->old_texture)) return FALSE; ts->was_bound = texture == ts->old_texture; @@ -780,7 +780,7 @@ gl_create_pixmap_object(Display *dpy, guint width, guint height) int fbconfig_attrs[32] = { GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT, - GLX_DOUBLEBUFFER, GL_TRUE, + GLX_DOUBLEBUFFER, GL_FALSE, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_X_RENDERABLE, GL_TRUE, GLX_Y_INVERTED_EXT, GL_TRUE, @@ -855,7 +855,7 @@ gl_create_pixmap_object(Display *dpy, guint width, guint height) if (!fbconfig) goto error; - /* Initialize GLX Pixmap attrutes */ + /* Initialize GLX Pixmap attributes */ for (attr = pixmap_attrs; *attr != GL_NONE; attr += 2) ; *attr++ = GLX_TEXTURE_FORMAT_EXT; @@ -870,6 +870,14 @@ gl_create_pixmap_object(Display *dpy, guint width, guint height) free(fbconfig); if (x11_untrap_errors() != 0) goto error; + + pixo->target = GL_TEXTURE_2D; + glGenTextures(1, &pixo->texture); + if (!gl_bind_texture(&pixo->old_texture, pixo->target, pixo->texture)) + goto error; + glTexParameteri(pixo->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(pixo->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + gl_unbind_texture(&pixo->old_texture); return pixo; error: @@ -891,6 +899,11 @@ gl_destroy_pixmap_object(GLPixmapObject *pixo) gl_unbind_pixmap_object(pixo); + if (pixo->texture) { + glDeleteTextures(1, &pixo->texture); + pixo->texture = 0; + } + if (pixo->glx_pixmap) { glXDestroyPixmap(pixo->dpy, pixo->glx_pixmap); pixo->glx_pixmap = None; @@ -921,6 +934,9 @@ gl_bind_pixmap_object(GLPixmapObject *pixo) if (pixo->is_bound) return TRUE; + if (!gl_bind_texture(&pixo->old_texture, pixo->target, pixo->texture)) + return FALSE; + x11_trap_errors(); gl_vtable->glx_bind_tex_image( pixo->dpy, @@ -966,6 +982,8 @@ gl_unbind_pixmap_object(GLPixmapObject *pixo) return FALSE; } + gl_unbind_texture(&pixo->old_texture); + pixo->is_bound = FALSE; return TRUE; } @@ -992,9 +1010,7 @@ gl_create_framebuffer_object( { GLVTable * const gl_vtable = gl_get_vtable(); GLFramebufferObject *fbo; - GLTextureState ts; GLenum status; - gboolean texture_was_bound; if (!gl_vtable || !gl_vtable->has_framebuffer_object) return NULL; @@ -1010,35 +1026,22 @@ gl_create_framebuffer_object( fbo->width = width; fbo->height = height; fbo->fbo = 0; - fbo->fbo_buffer = 0; - fbo->fbo_target = target; - fbo->fbo_texture = 0; fbo->old_fbo = 0; fbo->is_bound = FALSE; - fbo->fbo_texture = gl_create_texture(target, GL_BGRA, width, height); - if (!fbo->fbo_texture) - goto error; - gl_get_param(GL_FRAMEBUFFER_BINDING, &fbo->old_fbo); gl_vtable->gl_gen_framebuffers(1, &fbo->fbo); gl_vtable->gl_bind_framebuffer(GL_FRAMEBUFFER_EXT, fbo->fbo); - gl_vtable->gl_gen_renderbuffers(1, &fbo->fbo_buffer); - gl_vtable->gl_bind_renderbuffer(GL_RENDERBUFFER_EXT, fbo->fbo_buffer); - - texture_was_bound = gl_bind_texture(&ts, target, texture); - if (texture_was_bound) { - gl_vtable->gl_framebuffer_texture_2d( - GL_FRAMEBUFFER_EXT, - GL_COLOR_ATTACHMENT0_EXT, - target, texture, - 0 - ); - gl_unbind_texture(&ts); - } + gl_vtable->gl_framebuffer_texture_2d( + GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + target, texture, + 0 + ); + status = gl_vtable->gl_check_framebuffer_status(GL_DRAW_FRAMEBUFFER_EXT); gl_vtable->gl_bind_framebuffer(GL_FRAMEBUFFER_EXT, fbo->old_fbo); - if (!texture_was_bound || status != GL_FRAMEBUFFER_COMPLETE_EXT) + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) goto error; return fbo; @@ -1063,16 +1066,6 @@ gl_destroy_framebuffer_object(GLFramebufferObject *fbo) gl_unbind_framebuffer_object(fbo); - if (fbo->fbo_texture) { - glDeleteTextures(1, &fbo->fbo_texture); - fbo->fbo_texture = 0; - } - - if (fbo->fbo_buffer) { - gl_vtable->gl_delete_renderbuffers(1, &fbo->fbo_buffer); - fbo->fbo_buffer = 0; - } - if (fbo->fbo) { gl_vtable->gl_delete_framebuffers(1, &fbo->fbo); fbo->fbo = 0; @@ -1117,9 +1110,6 @@ gl_bind_framebuffer_object(GLFramebufferObject *fbo) glTranslatef(-1.0f, -1.0f, 0.0f); glScalef(2.0f / width, 2.0f / height, 1.0f); - if (!gl_bind_texture(&fbo->old_texture, fbo->fbo_target, fbo->fbo_texture)) - return FALSE; - fbo->is_bound = TRUE; return TRUE; } diff --git a/gst-libs/gst/vaapi/gstvaapiutils_glx.h b/gst-libs/gst/vaapi/gstvaapiutils_glx.h index 58b85b4..4d09fdd 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_glx.h +++ b/gst-libs/gst/vaapi/gstvaapiutils_glx.h @@ -148,12 +148,15 @@ gl_get_vtable(void) typedef struct _GLPixmapObject GLPixmapObject; struct _GLPixmapObject { - Display *dpy; - guint width; - guint height; - Pixmap pixmap; - GLXPixmap glx_pixmap; - guint is_bound : 1; + Display *dpy; + GLenum target; + GLuint texture; + GLTextureState old_texture; + guint width; + guint height; + Pixmap pixmap; + GLXPixmap glx_pixmap; + guint is_bound : 1; }; GLPixmapObject * @@ -177,11 +180,7 @@ struct _GLFramebufferObject { guint width; guint height; GLuint fbo; - GLuint fbo_buffer; - GLenum fbo_target; - GLuint fbo_texture; GLuint old_fbo; - GLTextureState old_texture; guint is_bound : 1; };