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.
This commit is contained in:
gb 2010-04-02 11:27:23 +00:00
parent 8e6dea5b74
commit b8aadb9e82
3 changed files with 43 additions and 60 deletions

View file

@ -593,7 +593,6 @@ _gst_vaapi_texture_put_surface(
#else #else
guint surface_width, surface_height; guint surface_width, surface_height;
GLContextState old_cs; GLContextState old_cs;
GLTextureState ts;
gboolean success = FALSE; gboolean success = FALSE;
gst_vaapi_surface_get_size(surface, &surface_width, &surface_height); gst_vaapi_surface_get_size(surface, &surface_width, &surface_height);
@ -613,19 +612,16 @@ _gst_vaapi_texture_put_surface(
return FALSE; return FALSE;
GST_VAAPI_OBJECT_LOCK_DISPLAY(texture); GST_VAAPI_OBJECT_LOCK_DISPLAY(texture);
success = gl_set_current_context(priv->gl_context, &old_cs); if (priv->gl_context) {
if (!success) success = gl_set_current_context(priv->gl_context, &old_cs);
goto end; 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;
} }
success = gl_bind_framebuffer_object(priv->fbo); success = gl_bind_framebuffer_object(priv->fbo);
if (!success) { if (!success) {
GST_DEBUG("could not bind FBO"); GST_DEBUG("could not bind FBO");
goto out_unbind_texture; goto out_reset_context;
} }
GST_VAAPI_OBJECT_UNLOCK_DISPLAY(texture); GST_VAAPI_OBJECT_UNLOCK_DISPLAY(texture);
@ -661,10 +657,8 @@ _gst_vaapi_texture_put_surface(
out_unbind_fbo: out_unbind_fbo:
if (!gl_unbind_framebuffer_object(priv->fbo)) if (!gl_unbind_framebuffer_object(priv->fbo))
success = FALSE; success = FALSE;
out_unbind_texture:
gl_unbind_texture(&ts);
out_reset_context: out_reset_context:
if (!gl_set_current_context(&old_cs, NULL)) if (priv->gl_context && !gl_set_current_context(&old_cs, NULL))
success = FALSE; success = FALSE;
end: end:
GST_VAAPI_OBJECT_UNLOCK_DISPLAY(texture); GST_VAAPI_OBJECT_UNLOCK_DISPLAY(texture);

View file

@ -474,7 +474,7 @@ gl_bind_texture(GLTextureState *ts, GLenum target, GLuint texture)
return FALSE; 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; return FALSE;
ts->was_bound = texture == ts->old_texture; 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] = { int fbconfig_attrs[32] = {
GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT, GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
GLX_DOUBLEBUFFER, GL_TRUE, GLX_DOUBLEBUFFER, GL_FALSE,
GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_X_RENDERABLE, GL_TRUE, GLX_X_RENDERABLE, GL_TRUE,
GLX_Y_INVERTED_EXT, GL_TRUE, GLX_Y_INVERTED_EXT, GL_TRUE,
@ -855,7 +855,7 @@ gl_create_pixmap_object(Display *dpy, guint width, guint height)
if (!fbconfig) if (!fbconfig)
goto error; goto error;
/* Initialize GLX Pixmap attrutes */ /* Initialize GLX Pixmap attributes */
for (attr = pixmap_attrs; *attr != GL_NONE; attr += 2) for (attr = pixmap_attrs; *attr != GL_NONE; attr += 2)
; ;
*attr++ = GLX_TEXTURE_FORMAT_EXT; *attr++ = GLX_TEXTURE_FORMAT_EXT;
@ -870,6 +870,14 @@ gl_create_pixmap_object(Display *dpy, guint width, guint height)
free(fbconfig); free(fbconfig);
if (x11_untrap_errors() != 0) if (x11_untrap_errors() != 0)
goto error; 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; return pixo;
error: error:
@ -891,6 +899,11 @@ gl_destroy_pixmap_object(GLPixmapObject *pixo)
gl_unbind_pixmap_object(pixo); gl_unbind_pixmap_object(pixo);
if (pixo->texture) {
glDeleteTextures(1, &pixo->texture);
pixo->texture = 0;
}
if (pixo->glx_pixmap) { if (pixo->glx_pixmap) {
glXDestroyPixmap(pixo->dpy, pixo->glx_pixmap); glXDestroyPixmap(pixo->dpy, pixo->glx_pixmap);
pixo->glx_pixmap = None; pixo->glx_pixmap = None;
@ -921,6 +934,9 @@ gl_bind_pixmap_object(GLPixmapObject *pixo)
if (pixo->is_bound) if (pixo->is_bound)
return TRUE; return TRUE;
if (!gl_bind_texture(&pixo->old_texture, pixo->target, pixo->texture))
return FALSE;
x11_trap_errors(); x11_trap_errors();
gl_vtable->glx_bind_tex_image( gl_vtable->glx_bind_tex_image(
pixo->dpy, pixo->dpy,
@ -966,6 +982,8 @@ gl_unbind_pixmap_object(GLPixmapObject *pixo)
return FALSE; return FALSE;
} }
gl_unbind_texture(&pixo->old_texture);
pixo->is_bound = FALSE; pixo->is_bound = FALSE;
return TRUE; return TRUE;
} }
@ -992,9 +1010,7 @@ gl_create_framebuffer_object(
{ {
GLVTable * const gl_vtable = gl_get_vtable(); GLVTable * const gl_vtable = gl_get_vtable();
GLFramebufferObject *fbo; GLFramebufferObject *fbo;
GLTextureState ts;
GLenum status; GLenum status;
gboolean texture_was_bound;
if (!gl_vtable || !gl_vtable->has_framebuffer_object) if (!gl_vtable || !gl_vtable->has_framebuffer_object)
return NULL; return NULL;
@ -1010,35 +1026,22 @@ gl_create_framebuffer_object(
fbo->width = width; fbo->width = width;
fbo->height = height; fbo->height = height;
fbo->fbo = 0; fbo->fbo = 0;
fbo->fbo_buffer = 0;
fbo->fbo_target = target;
fbo->fbo_texture = 0;
fbo->old_fbo = 0; fbo->old_fbo = 0;
fbo->is_bound = FALSE; 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_get_param(GL_FRAMEBUFFER_BINDING, &fbo->old_fbo);
gl_vtable->gl_gen_framebuffers(1, &fbo->fbo); gl_vtable->gl_gen_framebuffers(1, &fbo->fbo);
gl_vtable->gl_bind_framebuffer(GL_FRAMEBUFFER_EXT, fbo->fbo); gl_vtable->gl_bind_framebuffer(GL_FRAMEBUFFER_EXT, fbo->fbo);
gl_vtable->gl_gen_renderbuffers(1, &fbo->fbo_buffer); gl_vtable->gl_framebuffer_texture_2d(
gl_vtable->gl_bind_renderbuffer(GL_RENDERBUFFER_EXT, fbo->fbo_buffer); GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
target, texture,
0
);
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);
}
status = gl_vtable->gl_check_framebuffer_status(GL_DRAW_FRAMEBUFFER_EXT); status = gl_vtable->gl_check_framebuffer_status(GL_DRAW_FRAMEBUFFER_EXT);
gl_vtable->gl_bind_framebuffer(GL_FRAMEBUFFER_EXT, fbo->old_fbo); 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; goto error;
return fbo; return fbo;
@ -1063,16 +1066,6 @@ gl_destroy_framebuffer_object(GLFramebufferObject *fbo)
gl_unbind_framebuffer_object(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) { if (fbo->fbo) {
gl_vtable->gl_delete_framebuffers(1, &fbo->fbo); gl_vtable->gl_delete_framebuffers(1, &fbo->fbo);
fbo->fbo = 0; fbo->fbo = 0;
@ -1117,9 +1110,6 @@ gl_bind_framebuffer_object(GLFramebufferObject *fbo)
glTranslatef(-1.0f, -1.0f, 0.0f); glTranslatef(-1.0f, -1.0f, 0.0f);
glScalef(2.0f / width, 2.0f / height, 1.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; fbo->is_bound = TRUE;
return TRUE; return TRUE;
} }

View file

@ -148,12 +148,15 @@ gl_get_vtable(void)
typedef struct _GLPixmapObject GLPixmapObject; typedef struct _GLPixmapObject GLPixmapObject;
struct _GLPixmapObject { struct _GLPixmapObject {
Display *dpy; Display *dpy;
guint width; GLenum target;
guint height; GLuint texture;
Pixmap pixmap; GLTextureState old_texture;
GLXPixmap glx_pixmap; guint width;
guint is_bound : 1; guint height;
Pixmap pixmap;
GLXPixmap glx_pixmap;
guint is_bound : 1;
}; };
GLPixmapObject * GLPixmapObject *
@ -177,11 +180,7 @@ struct _GLFramebufferObject {
guint width; guint width;
guint height; guint height;
GLuint fbo; GLuint fbo;
GLuint fbo_buffer;
GLenum fbo_target;
GLuint fbo_texture;
GLuint old_fbo; GLuint old_fbo;
GLTextureState old_texture;
guint is_bound : 1; guint is_bound : 1;
}; };