From: gb Date: Fri, 16 Apr 2010 13:47:30 +0000 (+0000) Subject: Fix gl_create_context() to find a GLXFBConfig compatible with the parent GL context. X-Git-Tag: accepted/trunk/20120822.173359~531 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d1709fef62ac07358e5e55663c5c7dbfe77fd7c4;p=profile%2Fivi%2Fgstreamer-vaapi.git Fix gl_create_context() to find a GLXFBConfig compatible with the parent GL context. --- diff --git a/gst-libs/gst/vaapi/gstvaapiutils_glx.c b/gst-libs/gst/vaapi/gstvaapiutils_glx.c index 3e6632b..6cd88af 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_glx.c +++ b/gst-libs/gst/vaapi/gstvaapiutils_glx.c @@ -287,16 +287,17 @@ GLContextState * gl_create_context(Display *dpy, int screen, GLContextState *parent) { GLContextState *cs; - GLXFBConfig *fb_configs = NULL; - int n_fb_configs; + GLXFBConfig *fbconfigs = NULL; + int fbconfig_id, val, n, n_fbconfigs; + Status status; - static GLint fb_config_attrs[] = { + static GLint fbconfig_attrs[] = { GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DOUBLEBUFFER, True, - GLX_RED_SIZE, 1, - GLX_GREEN_SIZE, 1, - GLX_BLUE_SIZE, 1, + GLX_RED_SIZE, 8, + GLX_GREEN_SIZE, 8, + GLX_BLUE_SIZE, 8, None }; @@ -310,17 +311,49 @@ gl_create_context(Display *dpy, int screen, GLContextState *parent) cs->context = NULL; cs->swapped_buffers = FALSE; - fb_configs = glXChooseFBConfig(dpy, screen, fb_config_attrs, &n_fb_configs); - if (!fb_configs) - goto error; - - cs->visual = glXGetVisualFromFBConfig(dpy, fb_configs[0]); - if (!cs->visual) - goto error; + if (parent && parent->context) { + status = glXQueryContext( + parent->display, + parent->context, + GLX_FBCONFIG_ID, &fbconfig_id + ); + if (status != Success) + goto error; + + fbconfigs = glXGetFBConfigs(dpy, screen, &n_fbconfigs); + if (!fbconfigs) + goto error; + + /* Find out a GLXFBConfig compatible with the parent context */ + for (n = 0; n < n_fbconfigs; n++) { + status = glXGetFBConfigAttrib( + dpy, + fbconfigs[n], + GLX_FBCONFIG_ID, &val + ); + if (status == Success && val == fbconfig_id) + break; + } + if (n == n_fbconfigs) + goto error; + } + else { + fbconfigs = glXChooseFBConfig( + dpy, + screen, + fbconfig_attrs, &n_fbconfigs + ); + if (!fbconfigs) + goto error; + + /* Select the first one */ + n = 0; + } + cs->visual = glXGetVisualFromFBConfig(dpy, fbconfigs[n]); cs->context = glXCreateNewContext( dpy, - fb_configs[0], + fbconfigs[n], GLX_RGBA_TYPE, parent ? parent->context : NULL, True @@ -332,8 +365,8 @@ error: gl_destroy_context(cs); cs = NULL; end: - if (fb_configs) - XFree(fb_configs); + if (fbconfigs) + XFree(fbconfigs); return cs; }