wined3d: CreateFakeGLContext should also work when we have a context [3rd try]

Alexandre Julliard julliard at winehq.org
Tue Oct 10 08:50:05 CDT 2006


Jan Zerebecki <jan.wine at zerebecki.de> writes:

> +static void WineD3D_CreateFakeGLContext(void) {
> +    TRACE_(d3d_caps)("getting context...\n");
> +    if(wined3d_fake_gl_context_ref > 0) goto ret;
> +    assert(0 == wined3d_fake_gl_context_ref);
> +
> +    wined3d_fake_gl_context_foreign = TRUE;
> +    Display*   display = WineD3D_GetDisplay();
> +    XVisualInfo* visInfo = NULL;
> +    GLXContext   glCtx = glXGetCurrentContext();

This isn't thread-safe. Also please avoid mixing declarations and
code.

> -  gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_RED_SIZE,   &rb);
> -  gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_GREEN_SIZE, &gb);
> -  gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_BLUE_SIZE,  &bb);
> -  gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_ALPHA_SIZE, &ab);
> -  gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_RENDER_TYPE, &type);
> -  gl_test = glXGetFBConfigAttrib(ctx->display, cfgs, GLX_BUFFER_SIZE, &buf_sz);
> +  gl_test = glXGetFBConfigAttrib(WineD3D_GetDisplay(), cfgs, GLX_RED_SIZE,   &rb);
> +  gl_test = glXGetFBConfigAttrib(WineD3D_GetDisplay(), cfgs, GLX_GREEN_SIZE, &gb);
> +  gl_test = glXGetFBConfigAttrib(WineD3D_GetDisplay(), cfgs, GLX_BLUE_SIZE,  &bb);
> +  gl_test = glXGetFBConfigAttrib(WineD3D_GetDisplay(), cfgs, GLX_ALPHA_SIZE, &ab);
> +  gl_test = glXGetFBConfigAttrib(WineD3D_GetDisplay(), cfgs, GLX_RENDER_TYPE, &type);
> +  gl_test = glXGetFBConfigAttrib(WineD3D_GetDisplay(), cfgs, GLX_BUFFER_SIZE, &buf_sz);

This will be slow, you should retrieve the display only once.

> +    WineD3D_CreateFakeGLContext();
> +    if(wined3d_fake_gl_context_ref > 0)
> +        cfgs = glXGetFBConfigs(WineD3D_GetDisplay(), DefaultScreen(WineD3D_GetDisplay()), &nCfgs);

The ref count should be internal to the get/release functions, you
shouldn't use it here.

> +extern int             wined3d_fake_gl_context_ref;
> +extern BOOL            wined3d_fake_gl_context_foreign;

No reason to export these, they should be static.

-- 
Alexandre Julliard
julliard at winehq.org



More information about the wine-devel mailing list