From a296d96de45d38a6ed0b3c817334d443facc169b Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Mon, 19 Jul 2010 10:51:09 -0400 Subject: glx: Rename various DRI structs away from obnoxious __GLXfooRec convention Enough is enough. --- src/glx/drisw_glx.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'src/glx/drisw_glx.c') diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index cdb1d9f4dc..3b9e8139af 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -28,23 +28,19 @@ #include #include "dri_common.h" -typedef struct __GLXDRIdisplayPrivateRec __GLXDRIdisplayPrivate; -typedef struct __GLXDRIcontextPrivateRec __GLXDRIcontextPrivate; -typedef struct __GLXDRIdrawablePrivateRec __GLXDRIdrawablePrivate; - -struct __GLXDRIdisplayPrivateRec +struct drisw_display { __GLXDRIdisplay base; }; -struct __GLXDRIcontextPrivateRec +struct drisw_context { __GLXDRIcontext base; __DRIcontext *driContext; __GLXscreenConfigs *psc; }; -struct __GLXDRIdrawablePrivateRec +struct drisw_drawable { __GLXDRIdrawable base; @@ -56,7 +52,7 @@ struct __GLXDRIdrawablePrivateRec }; static Bool -XCreateDrawable(__GLXDRIdrawablePrivate * pdp, +XCreateDrawable(struct drisw_drawable * pdp, Display * dpy, XID drawable, int visualid) { XGCValues gcvalues; @@ -94,7 +90,7 @@ XCreateDrawable(__GLXDRIdrawablePrivate * pdp, } static void -XDestroyDrawable(__GLXDRIdrawablePrivate * pdp, Display * dpy, XID drawable) +XDestroyDrawable(struct drisw_drawable * pdp, Display * dpy, XID drawable) { XDestroyImage(pdp->ximage); XFree(pdp->visinfo); @@ -112,7 +108,7 @@ swrastGetDrawableInfo(__DRIdrawable * draw, int *x, int *y, int *w, int *h, void *loaderPrivate) { - __GLXDRIdrawablePrivate *pdp = loaderPrivate; + struct drisw_drawable *pdp = loaderPrivate; __GLXDRIdrawable *pdraw = &(pdp->base); Display *dpy = pdraw->psc->dpy; Drawable drawable; @@ -156,7 +152,7 @@ swrastPutImage(__DRIdrawable * draw, int op, int x, int y, int w, int h, char *data, void *loaderPrivate) { - __GLXDRIdrawablePrivate *pdp = loaderPrivate; + struct drisw_drawable *pdp = loaderPrivate; __GLXDRIdrawable *pdraw = &(pdp->base); Display *dpy = pdraw->psc->dpy; Drawable drawable; @@ -192,7 +188,7 @@ swrastGetImage(__DRIdrawable * read, int x, int y, int w, int h, char *data, void *loaderPrivate) { - __GLXDRIdrawablePrivate *prp = loaderPrivate; + struct drisw_drawable *prp = loaderPrivate; __GLXDRIdrawable *pread = &(prp->base); Display *dpy = pread->psc->dpy; Drawable readable; @@ -232,7 +228,7 @@ static void driDestroyContext(__GLXDRIcontext * context, __GLXscreenConfigs * psc, Display * dpy) { - __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; + struct drisw_context *pcp = (struct drisw_context *) context; const __DRIcoreExtension *core = pcp->psc->core; (*core->destroyContext) (pcp->driContext); @@ -244,7 +240,7 @@ static Bool driBindContext(__GLXDRIcontext * context, __GLXDRIdrawable * draw, __GLXDRIdrawable * read) { - __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; + struct drisw_context *pcp = (struct drisw_context *) context; const __DRIcoreExtension *core = pcp->psc->core; return (*core->bindContext) (pcp->driContext, @@ -254,7 +250,7 @@ driBindContext(__GLXDRIcontext * context, static void driUnbindContext(__GLXDRIcontext * context) { - __GLXDRIcontextPrivate *pcp = (__GLXDRIcontextPrivate *) context; + struct drisw_context *pcp = (struct drisw_context *) context; const __DRIcoreExtension *core = pcp->psc->core; (*core->unbindContext) (pcp->driContext); @@ -265,7 +261,7 @@ driCreateContext(__GLXscreenConfigs * psc, const __GLcontextModes * mode, GLXContext gc, GLXContext shareList, int renderType) { - __GLXDRIcontextPrivate *pcp, *pcp_shared; + struct drisw_context *pcp, *pcp_shared; __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode; const __DRIcoreExtension *core; __DRIcontext *shared = NULL; @@ -276,7 +272,7 @@ driCreateContext(__GLXscreenConfigs * psc, core = psc->core; if (shareList) { - pcp_shared = (__GLXDRIcontextPrivate *) shareList->driContext; + pcp_shared = (struct drisw_context *) shareList->driContext; shared = pcp_shared->driContext; } @@ -303,7 +299,7 @@ driCreateContext(__GLXscreenConfigs * psc, static void driDestroyDrawable(__GLXDRIdrawable * pdraw) { - __GLXDRIdrawablePrivate *pdp = (__GLXDRIdrawablePrivate *) pdraw; + struct drisw_drawable *pdp = (struct drisw_drawable *) pdraw; const __DRIcoreExtension *core = pdraw->psc->core; (*core->destroyDrawable) (pdraw->driDrawable); @@ -318,7 +314,7 @@ driCreateDrawable(__GLXscreenConfigs * psc, GLXDrawable drawable, const __GLcontextModes * modes) { __GLXDRIdrawable *pdraw; - __GLXDRIdrawablePrivate *pdp; + struct drisw_drawable *pdp; __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes; const __DRIswrastExtension *swrast = psc->swrast; @@ -476,7 +472,7 @@ driDestroyDisplay(__GLXDRIdisplay * dpy) _X_HIDDEN __GLXDRIdisplay * driswCreateDisplay(Display * dpy) { - __GLXDRIdisplayPrivate *pdpyp; + struct drisw_display *pdpyp; pdpyp = Xmalloc(sizeof *pdpyp); if (pdpyp == NULL) -- cgit v1.2.3 From f972115d33e391499e049b83a1559959f2ca9f72 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Mon, 19 Jul 2010 14:57:59 -0400 Subject: glx: Add screen privates for dri drivers and moved some fields there GLXscreenConfigs is badly named and a dumping ground for a lot of stuff. This patch creates private screen structs for the dri drivers and moves some of their fields over there. --- src/glx/dri2_glx.c | 130 ++++++++++++++++++++++++++++++-------------------- src/glx/dri_common.c | 17 ++----- src/glx/dri_common.h | 9 ++-- src/glx/dri_glx.c | 127 +++++++++++++++++++++++++++++------------------- src/glx/drisw_glx.c | 126 ++++++++++++++++++++++++++++-------------------- src/glx/glx_pbuffer.c | 4 +- src/glx/glxclient.h | 16 +++---- src/glx/glxcmds.c | 22 ++++----- src/glx/glxcurrent.c | 2 +- src/glx/glxext.c | 89 ++++++++++++++++++++-------------- 10 files changed, 315 insertions(+), 227 deletions(-) (limited to 'src/glx/drisw_glx.c') diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index be48194b14..b35663d5ed 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -75,6 +75,16 @@ struct dri2_display const __DRIextension *loader_extensions[4]; }; +struct dri2_screen { + __GLXscreenConfigs base; + + __GLXDRIscreen driScreen; + const __DRIdri2Extension *dri2; + const __DRIcoreExtension *core; + void *driver; + int fd; +}; + struct dri2_context { __GLXDRIcontext base; @@ -94,43 +104,44 @@ struct dri2_drawable }; static void -dri2DestroyContext(__GLXDRIcontext * context, - __GLXscreenConfigs * psc, Display * dpy) +dri2DestroyContext(__GLXDRIcontext *context, + __GLXscreenConfigs *base, Display *dpy) { struct dri2_context *pcp = (struct dri2_context *) context; - const __DRIcoreExtension *core = pcp->psc->core; + struct dri2_screen *psc = (struct dri2_screen *) base; - (*core->destroyContext) (pcp->driContext); + (*psc->core->destroyContext) (pcp->driContext); Xfree(pcp); } static Bool -dri2BindContext(__GLXDRIcontext * context, - __GLXDRIdrawable * draw, __GLXDRIdrawable * read) +dri2BindContext(__GLXDRIcontext *context, + __GLXDRIdrawable *draw, __GLXDRIdrawable *read) { struct dri2_context *pcp = (struct dri2_context *) context; - const __DRIcoreExtension *core = pcp->psc->core; + struct dri2_screen *psc = (struct dri2_screen *) pcp->psc; - return (*core->bindContext) (pcp->driContext, - draw->driDrawable, read->driDrawable); + return (*psc->core->bindContext) (pcp->driContext, + draw->driDrawable, read->driDrawable); } static void -dri2UnbindContext(__GLXDRIcontext * context) +dri2UnbindContext(__GLXDRIcontext *context) { struct dri2_context *pcp = (struct dri2_context *) context; - const __DRIcoreExtension *core = pcp->psc->core; + struct dri2_screen *psc = (struct dri2_screen *) pcp->psc; - (*core->unbindContext) (pcp->driContext); + (*psc->core->unbindContext) (pcp->driContext); } static __GLXDRIcontext * -dri2CreateContext(__GLXscreenConfigs * psc, +dri2CreateContext(__GLXscreenConfigs *base, const __GLcontextModes * mode, GLXContext gc, GLXContext shareList, int renderType) { struct dri2_context *pcp, *pcp_shared; + struct dri2_screen *psc = (struct dri2_screen *) base; __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode; __DRIcontext *shared = NULL; @@ -143,9 +154,9 @@ dri2CreateContext(__GLXscreenConfigs * psc, if (pcp == NULL) return NULL; - pcp->psc = psc; + pcp->psc = &psc->base; pcp->driContext = - (*psc->dri2->createNewContext) (psc->__driScreen, + (*psc->dri2->createNewContext) (psc->base.__driScreen, config->driConfig, shared, pcp); gc->__driContext = pcp->driContext; @@ -164,7 +175,7 @@ dri2CreateContext(__GLXscreenConfigs * psc, static void dri2DestroyDrawable(__GLXDRIdrawable *pdraw) { - const __DRIcoreExtension *core = pdraw->psc->core; + struct dri2_screen *psc = (struct dri2_screen *) pdraw->psc; __GLXdisplayPrivate *dpyPriv; struct dri2_display *pdp; @@ -172,17 +183,17 @@ dri2DestroyDrawable(__GLXDRIdrawable *pdraw) pdp = (struct dri2_display *)dpyPriv->dri2Display; __glxHashDelete(pdp->dri2Hash, pdraw->xDrawable); - (*core->destroyDrawable) (pdraw->driDrawable); - DRI2DestroyDrawable(pdraw->psc->dpy, pdraw->xDrawable); + (*psc->core->destroyDrawable) (pdraw->driDrawable); + DRI2DestroyDrawable(psc->base.dpy, pdraw->xDrawable); Xfree(pdraw); } static __GLXDRIdrawable * -dri2CreateDrawable(__GLXscreenConfigs * psc, - XID xDrawable, - GLXDrawable drawable, const __GLcontextModes * modes) +dri2CreateDrawable(__GLXscreenConfigs *base, XID xDrawable, + GLXDrawable drawable, const __GLcontextModes * modes) { struct dri2_drawable *pdraw; + struct dri2_screen *psc = (struct dri2_screen *) base; __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes; __GLXdisplayPrivate *dpyPriv; struct dri2_display *pdp; @@ -195,13 +206,14 @@ dri2CreateDrawable(__GLXscreenConfigs * psc, pdraw->base.destroyDrawable = dri2DestroyDrawable; pdraw->base.xDrawable = xDrawable; pdraw->base.drawable = drawable; - pdraw->base.psc = psc; + pdraw->base.psc = &psc->base; pdraw->bufferCount = 0; pdraw->swap_interval = 1; /* default may be overridden below */ pdraw->have_back = 0; - if (psc->config) - psc->config->configQueryi(psc->__driScreen, "vblank_mode", &vblank_mode); + if (psc->base.config) + psc->base.config->configQueryi(psc->base.__driScreen, + "vblank_mode", &vblank_mode); switch (vblank_mode) { case DRI_CONF_VBLANK_NEVER: @@ -215,24 +227,24 @@ dri2CreateDrawable(__GLXscreenConfigs * psc, break; } - DRI2CreateDrawable(psc->dpy, xDrawable); + DRI2CreateDrawable(psc->base.dpy, xDrawable); - dpyPriv = __glXInitialize(psc->dpy); + dpyPriv = __glXInitialize(psc->base.dpy); pdp = (struct dri2_display *)dpyPriv->dri2Display;; /* Create a new drawable */ pdraw->base.driDrawable = - (*psc->dri2->createNewDrawable) (psc->__driScreen, + (*psc->dri2->createNewDrawable) (psc->base.__driScreen, config->driConfig, pdraw); if (!pdraw->base.driDrawable) { - DRI2DestroyDrawable(psc->dpy, xDrawable); + DRI2DestroyDrawable(psc->base.dpy, xDrawable); Xfree(pdraw); return NULL; } if (__glxHashInsert(pdp->dri2Hash, xDrawable, pdraw)) { (*psc->core->destroyDrawable) (pdraw->base.driDrawable); - DRI2DestroyDrawable(psc->dpy, xDrawable); + DRI2DestroyDrawable(psc->base.dpy, xDrawable); Xfree(pdraw); return None; } @@ -244,7 +256,7 @@ dri2CreateDrawable(__GLXscreenConfigs * psc, * drawable. */ if (pdp->swapAvailable) - DRI2SwapInterval(psc->dpy, xDrawable, pdraw->swap_interval); + DRI2SwapInterval(psc->base.dpy, xDrawable, pdraw->swap_interval); #endif return &pdraw->base; @@ -377,12 +389,15 @@ dri2FlushFrontBuffer(__DRIdrawable *driDrawable, void *loaderPrivate) static void -dri2DestroyScreen(__GLXscreenConfigs * psc) +dri2DestroyScreen(__GLXscreenConfigs *base) { + struct dri2_screen *psc = (struct dri2_screen *) base; + /* Free the direct rendering per screen data */ - (*psc->core->destroyScreen) (psc->__driScreen); + (*psc->core->destroyScreen) (psc->base.__driScreen); close(psc->fd); - psc->__driScreen = NULL; + base->__driScreen = NULL; + Xfree(psc); } /** @@ -610,26 +625,30 @@ static const struct glx_context_vtable dri2_context_vtable = { dri2_release_tex_image, }; -static __GLXDRIscreen * -dri2CreateScreen(__GLXscreenConfigs * psc, int screen, - __GLXdisplayPrivate * priv) +static __GLXscreenConfigs * +dri2CreateScreen(int screen, __GLXdisplayPrivate * priv) { const __DRIconfig **driver_configs; const __DRIextension **extensions; const struct dri2_display *const pdp = (struct dri2_display *) priv->dri2Display; + struct dri2_screen *psc; __GLXDRIscreen *psp; char *driverName, *deviceName; drm_magic_t magic; int i; - psp = Xmalloc(sizeof *psp); - if (psp == NULL) + psc = Xmalloc(sizeof *psc); + if (psc == NULL) return NULL; - if (!DRI2Connect(psc->dpy, RootWindow(psc->dpy, screen), + memset(psc, 0, sizeof *psc); + if (!glx_screen_init(&psc->base, screen, priv)) + return NULL; + + if (!DRI2Connect(priv->dpy, RootWindow(priv->dpy, screen), &driverName, &deviceName)) { - XFree(psp); + XFree(psc); return NULL; } @@ -668,7 +687,7 @@ dri2CreateScreen(__GLXscreenConfigs * psc, int screen, goto handle_error; } - if (!DRI2Authenticate(psc->dpy, RootWindow(psc->dpy, screen), magic)) { + if (!DRI2Authenticate(priv->dpy, RootWindow(priv->dpy, screen), magic)) { ErrorMessageF("failed to authenticate magic %d\n", magic); goto handle_error; } @@ -677,25 +696,30 @@ dri2CreateScreen(__GLXscreenConfigs * psc, int screen, /* If the server does not support the protocol for * DRI2GetBuffersWithFormat, don't supply that interface to the driver. */ - psc->__driScreen = + psc->base.__driScreen = psc->dri2->createNewScreen(screen, psc->fd, (const __DRIextension **) &pdp->loader_extensions[0], &driver_configs, psc); - if (psc->__driScreen == NULL) { + if (psc->base.__driScreen == NULL) { ErrorMessageF("failed to create dri screen\n"); goto handle_error; } - driBindCommonExtensions(psc); - dri2BindExtensions(psc); + extensions = psc->core->getExtensions(psc->base.__driScreen); + driBindCommonExtensions(&psc->base, extensions); + dri2BindExtensions(&psc->base, extensions); - psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs); - psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs); + psc->base.configs = + driConvertConfigs(psc->core, psc->base.configs, driver_configs); + psc->base.visuals = + driConvertConfigs(psc->core, psc->base.visuals, driver_configs); - psc->driver_configs = driver_configs; + psc->base.driver_configs = driver_configs; + psp = &psc->driScreen; + psc->base.driScreen = psp; psp->destroyScreen = dri2DestroyScreen; psp->createContext = dri2CreateContext; psp->createDrawable = dri2CreateDrawable; @@ -721,26 +745,26 @@ dri2CreateScreen(__GLXscreenConfigs * psc, int screen, psp->getSwapInterval = dri2GetSwapInterval; #endif #if defined(X_DRI2GetMSC) && defined(X_DRI2WaitMSC) && defined(X_DRI2SwapInterval) - __glXEnableDirectExtension(psc, "GLX_OML_sync_control"); + __glXEnableDirectExtension(&psc->base, "GLX_OML_sync_control"); #endif } /* DRI2 suports SubBuffer through DRI2CopyRegion, so it's always * available.*/ psp->copySubBuffer = dri2CopySubBuffer; - __glXEnableDirectExtension(psc, "GLX_MESA_copy_sub_buffer"); + __glXEnableDirectExtension(&psc->base, "GLX_MESA_copy_sub_buffer"); - psc->direct_context_vtable = &dri2_context_vtable; + psc->base.direct_context_vtable = &dri2_context_vtable; Xfree(driverName); Xfree(deviceName); - return psp; + return &psc->base; handle_error: Xfree(driverName); Xfree(deviceName); - XFree(psp); + XFree(psc); /* FIXME: clean up here */ diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c index 429fc6d891..19936ff57a 100644 --- a/src/glx/dri_common.c +++ b/src/glx/dri_common.c @@ -338,13 +338,10 @@ driConvertConfigs(const __DRIcoreExtension * core, /* Bind DRI1 specific extensions */ _X_HIDDEN void -driBindExtensions(__GLXscreenConfigs *psc) +driBindExtensions(__GLXscreenConfigs *psc, const __DRIextension **extensions) { - const __DRIextension **extensions; int i; - extensions = psc->core->getExtensions(psc->__driScreen); - for (i = 0; extensions[i]; i++) { #ifdef __DRI_SWAP_CONTROL /* No DRI2 support for swap_control at the moment, since SwapBuffers @@ -375,13 +372,11 @@ driBindExtensions(__GLXscreenConfigs *psc) /* Bind DRI2 specific extensions */ _X_HIDDEN void -dri2BindExtensions(__GLXscreenConfigs *psc) +dri2BindExtensions(__GLXscreenConfigs *psc, + const __DRIextension **extensions) { - const __DRIextension **extensions; int i; - extensions = psc->core->getExtensions(psc->__driScreen); - for (i = 0; extensions[i]; i++) { #ifdef __DRI_TEX_BUFFER if ((strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0)) { @@ -413,13 +408,11 @@ dri2BindExtensions(__GLXscreenConfigs *psc) /* Bind extensions common to DRI1 and DRI2 */ _X_HIDDEN void -driBindCommonExtensions(__GLXscreenConfigs *psc) +driBindCommonExtensions(__GLXscreenConfigs *psc, + const __DRIextension **extensions) { - const __DRIextension **extensions; int i; - extensions = psc->core->getExtensions(psc->__driScreen); - for (i = 0; extensions[i]; i++) { #ifdef __DRI_COPY_SUB_BUFFER if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) { diff --git a/src/glx/dri_common.h b/src/glx/dri_common.h index bb178db787..7cd9ac2dac 100644 --- a/src/glx/dri_common.h +++ b/src/glx/dri_common.h @@ -56,8 +56,11 @@ extern void ErrorMessageF(const char *f, ...); extern void *driOpenDriver(const char *driverName); -extern void driBindExtensions(__GLXscreenConfigs * psc); -extern void dri2BindExtensions(__GLXscreenConfigs * psc); -extern void driBindCommonExtensions(__GLXscreenConfigs * psc); +extern void driBindExtensions(__GLXscreenConfigs * psc, + const __DRIextension **extensions); +extern void dri2BindExtensions(__GLXscreenConfigs * psc, + const __DRIextension **extensions); +extern void driBindCommonExtensions(__GLXscreenConfigs * psc, + const __DRIextension **extensions); #endif /* _DRI_COMMON_H */ diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c index b3ae5e6b78..e14bc62e63 100644 --- a/src/glx/dri_glx.c +++ b/src/glx/dri_glx.c @@ -59,6 +59,17 @@ struct dri_display int driPatch; }; +struct dri_screen +{ + __GLXscreenConfigs base; + + __GLXDRIscreen driScreen; + const __DRIlegacyExtension *legacy; + const __DRIcoreExtension *core; + void *driver; + int fd; +}; + struct dri_context { __GLXDRIcontext base; @@ -290,7 +301,7 @@ static const __DRIextension *loader_extensions[] = { * the client-side driver on success, or \c NULL on failure. */ static void * -CallCreateNewScreen(Display * dpy, int scrn, __GLXscreenConfigs * psc, +CallCreateNewScreen(Display *dpy, int scrn, struct dri_screen *psc, struct dri_display * driDpy) { void *psp = NULL; @@ -421,16 +432,18 @@ CallCreateNewScreen(Display * dpy, int scrn, __GLXscreenConfigs * psc, goto handle_error; } - psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs); - psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs); + psc->base.configs = + driConvertConfigs(psc->core, psc->base.configs, driver_configs); + psc->base.visuals = + driConvertConfigs(psc->core, psc->base.visuals, driver_configs); - psc->driver_configs = driver_configs; + psc->base.driver_configs = driver_configs; /* Visuals with depth != screen depth are subject to automatic compositing * in the X server, so DRI1 can't render to them properly. Mark them as * non-conformant to prevent apps from picking them up accidentally. */ - for (visual = psc->visuals; visual; visual = visual->next) { + for (visual = psc->base.visuals; visual; visual = visual->next) { XVisualInfo template; XVisualInfo *visuals; int num_visuals; @@ -472,47 +485,49 @@ CallCreateNewScreen(Display * dpy, int scrn, __GLXscreenConfigs * psc, static void driDestroyContext(__GLXDRIcontext * context, - __GLXscreenConfigs * psc, Display * dpy) + __GLXscreenConfigs *base, Display * dpy) { struct dri_context *pcp = (struct dri_context *) context; + struct dri_screen *psc = (struct dri_screen *) base; (*psc->core->destroyContext) (pcp->driContext); - XF86DRIDestroyContext(psc->dpy, psc->scr, pcp->hwContextID); + XF86DRIDestroyContext(psc->base.dpy, psc->base.scr, pcp->hwContextID); Xfree(pcp); } static Bool -driBindContext(__GLXDRIcontext * context, - __GLXDRIdrawable * draw, __GLXDRIdrawable * read) +driBindContext(__GLXDRIcontext *context, + __GLXDRIdrawable *draw, __GLXDRIdrawable *read) { struct dri_context *pcp = (struct dri_context *) context; - const __DRIcoreExtension *core = pcp->psc->core; + struct dri_screen *psc = (struct dri_screen *) pcp->psc; - return (*core->bindContext) (pcp->driContext, - draw->driDrawable, read->driDrawable); + return (*psc->core->bindContext) (pcp->driContext, + draw->driDrawable, read->driDrawable); } static void driUnbindContext(__GLXDRIcontext * context) { struct dri_context *pcp = (struct dri_context *) context; - const __DRIcoreExtension *core = pcp->psc->core; + struct dri_screen *psc = (struct dri_screen *) pcp->psc; - (*core->unbindContext) (pcp->driContext); + (*psc->core->unbindContext) (pcp->driContext); } static __GLXDRIcontext * -driCreateContext(__GLXscreenConfigs * psc, +driCreateContext(__GLXscreenConfigs *base, const __GLcontextModes * mode, GLXContext gc, GLXContext shareList, int renderType) { struct dri_context *pcp, *pcp_shared; + struct dri_screen *psc = (struct dri_screen *) base; drm_context_t hwContext; __DRIcontext *shared = NULL; __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode; - if (!psc || !psc->driScreen) + if (!psc->base.driScreen) return NULL; if (shareList) { @@ -524,8 +539,8 @@ driCreateContext(__GLXscreenConfigs * psc, if (pcp == NULL) return NULL; - pcp->psc = psc; - if (!XF86DRICreateContextWithConfig(psc->dpy, psc->scr, + pcp->psc = &psc->base; + if (!XF86DRICreateContextWithConfig(psc->base.dpy, psc->base.scr, mode->visualID, &pcp->hwContextID, &hwContext)) { Xfree(pcp); @@ -533,11 +548,11 @@ driCreateContext(__GLXscreenConfigs * psc, } pcp->driContext = - (*psc->legacy->createNewContext) (psc->__driScreen, + (*psc->legacy->createNewContext) (psc->base.__driScreen, config->driConfig, renderType, shared, hwContext, pcp); if (pcp->driContext == NULL) { - XF86DRIDestroyContext(psc->dpy, psc->scr, pcp->hwContextID); + XF86DRIDestroyContext(psc->base.dpy, psc->base.scr, pcp->hwContextID); Xfree(pcp); return NULL; } @@ -552,15 +567,15 @@ driCreateContext(__GLXscreenConfigs * psc, static void driDestroyDrawable(__GLXDRIdrawable * pdraw) { - __GLXscreenConfigs *psc = pdraw->psc; + struct dri_screen *psc = (struct dri_screen *) pdraw->psc; (*psc->core->destroyDrawable) (pdraw->driDrawable); - XF86DRIDestroyDrawable(psc->dpy, psc->scr, pdraw->drawable); + XF86DRIDestroyDrawable(psc->base.dpy, psc->base.scr, pdraw->drawable); Xfree(pdraw); } static __GLXDRIdrawable * -driCreateDrawable(__GLXscreenConfigs * psc, +driCreateDrawable(__GLXscreenConfigs *base, XID xDrawable, GLXDrawable drawable, const __GLcontextModes * modes) { @@ -568,6 +583,7 @@ driCreateDrawable(__GLXscreenConfigs * psc, drm_drawable_t hwDrawable; void *empty_attribute_list = NULL; __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes; + struct dri_screen *psc = (struct dri_screen *) base; /* Old dri can't handle GLX 1.3+ drawable constructors. */ if (xDrawable != drawable) @@ -578,23 +594,24 @@ driCreateDrawable(__GLXscreenConfigs * psc, return NULL; pdraw->drawable = drawable; - pdraw->psc = psc; + pdraw->psc = &psc->base; - if (!XF86DRICreateDrawable(psc->dpy, psc->scr, drawable, &hwDrawable)) { + if (!XF86DRICreateDrawable(psc->base.dpy, psc->base.scr, + drawable, &hwDrawable)) { Xfree(pdraw); return NULL; } /* Create a new drawable */ pdraw->driDrawable = - (*psc->legacy->createNewDrawable) (psc->__driScreen, + (*psc->legacy->createNewDrawable) (psc->base.__driScreen, config->driConfig, hwDrawable, GLX_WINDOW_BIT, empty_attribute_list, pdraw); if (!pdraw->driDrawable) { - XF86DRIDestroyDrawable(psc->dpy, psc->scr, drawable); + XF86DRIDestroyDrawable(psc->base.dpy, psc->base.scr, drawable); Xfree(pdraw); return NULL; } @@ -608,7 +625,9 @@ static int64_t driSwapBuffers(__GLXDRIdrawable * pdraw, int64_t unused1, int64_t unused2, int64_t unused3) { - (*pdraw->psc->core->swapBuffers) (pdraw->driDrawable); + struct dri_screen *psc = (struct dri_screen *) pdraw->psc; + + (*psc->core->swapBuffers) (pdraw->driDrawable); return 0; } @@ -621,12 +640,14 @@ driCopySubBuffer(__GLXDRIdrawable * pdraw, } static void -driDestroyScreen(__GLXscreenConfigs * psc) +driDestroyScreen(__GLXscreenConfigs *base) { + struct dri_screen *psc = (struct dri_screen *) base; + /* Free the direct rendering per screen data */ - if (psc->__driScreen) - (*psc->core->destroyScreen) (psc->__driScreen); - psc->__driScreen = NULL; + if (psc->base.__driScreen) + (*psc->core->destroyScreen) (psc->base.__driScreen); + psc->base.__driScreen = NULL; if (psc->driver) dlclose(psc->driver); } @@ -636,36 +657,40 @@ static const struct glx_context_vtable dri_context_vtable = { NULL, }; -static __GLXDRIscreen * -driCreateScreen(__GLXscreenConfigs * psc, int screen, - __GLXdisplayPrivate * priv) +static __GLXscreenConfigs * +driCreateScreen(int screen, __GLXdisplayPrivate *priv) { struct dri_display *pdp; __GLXDRIscreen *psp; const __DRIextension **extensions; + struct dri_screen *psc; char *driverName; int i; - psp = Xcalloc(1, sizeof *psp); - if (psp == NULL) + psc = Xcalloc(1, sizeof *psc); + if (psc == NULL) return NULL; + memset(psc, 0, sizeof *psc); + if (!glx_screen_init(&psc->base, screen, priv)) + return NULL; + if (!driGetDriverName(priv->dpy, screen, &driverName)) { - Xfree(psp); + Xfree(psc); return NULL; } psc->driver = driOpenDriver(driverName); Xfree(driverName); if (psc->driver == NULL) { - Xfree(psp); + Xfree(psc); return NULL; } extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS); if (extensions == NULL) { ErrorMessageF("driver exports no extensions (%s)\n", dlerror()); - Xfree(psp); + Xfree(psc); return NULL; } @@ -677,22 +702,26 @@ driCreateScreen(__GLXscreenConfigs * psc, int screen, } if (psc->core == NULL || psc->legacy == NULL) { - Xfree(psp); + Xfree(psc); return NULL; } pdp = (struct dri_display *) priv->driDisplay; - psc->__driScreen = CallCreateNewScreen(psc->dpy, screen, psc, pdp); - if (psc->__driScreen == NULL) { + psc->base.__driScreen = + CallCreateNewScreen(psc->base.dpy, screen, psc, pdp); + if (psc->base.__driScreen == NULL) { dlclose(psc->driver); - Xfree(psp); + Xfree(psc); return NULL; } - driBindExtensions(psc); - driBindCommonExtensions(psc); + extensions = psc->core->getExtensions(psc->base.__driScreen); + driBindExtensions(&psc->base, extensions); + driBindCommonExtensions(&psc->base, extensions); - if (psc->driCopySubBuffer) + psp = &psc->driScreen; + psc->base.driScreen = psp; + if (psc->base.driCopySubBuffer) psp->copySubBuffer = driCopySubBuffer; psp->destroyScreen = driDestroyScreen; @@ -702,9 +731,9 @@ driCreateScreen(__GLXscreenConfigs * psc, int screen, psp->waitX = NULL; psp->waitGL = NULL; - psc->direct_context_vtable = &dri_context_vtable; + psc->base.direct_context_vtable = &dri_context_vtable; - return psp; + return &psc->base; } /* Called from __glXFreeDisplayPrivate. diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index 3b9e8139af..4ed13a3ac7 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -40,6 +40,16 @@ struct drisw_context __GLXscreenConfigs *psc; }; +struct drisw_screen +{ + __GLXscreenConfigs base; + + __GLXDRIscreen driScreen; + const __DRIcoreExtension *core; + const __DRIswrastExtension *swrast; + void *driver; +}; + struct drisw_drawable { __GLXDRIdrawable base; @@ -225,52 +235,50 @@ static const __DRIextension *loader_extensions[] = { */ static void -driDestroyContext(__GLXDRIcontext * context, - __GLXscreenConfigs * psc, Display * dpy) +driDestroyContext(__GLXDRIcontext *context, + __GLXscreenConfigs *base, Display *dpy) { struct drisw_context *pcp = (struct drisw_context *) context; - const __DRIcoreExtension *core = pcp->psc->core; + struct drisw_screen *psc = (struct drisw_screen *) base; - (*core->destroyContext) (pcp->driContext); + (*psc->core->destroyContext) (pcp->driContext); Xfree(pcp); } static Bool driBindContext(__GLXDRIcontext * context, - __GLXDRIdrawable * draw, __GLXDRIdrawable * read) + __GLXDRIdrawable * draw, __GLXDRIdrawable * read) { struct drisw_context *pcp = (struct drisw_context *) context; - const __DRIcoreExtension *core = pcp->psc->core; + struct drisw_screen *psc = (struct drisw_screen *) pcp->psc; - return (*core->bindContext) (pcp->driContext, - draw->driDrawable, read->driDrawable); + return (*psc->core->bindContext) (pcp->driContext, + draw->driDrawable, read->driDrawable); } static void driUnbindContext(__GLXDRIcontext * context) { struct drisw_context *pcp = (struct drisw_context *) context; - const __DRIcoreExtension *core = pcp->psc->core; + struct drisw_screen *psc = (struct drisw_screen *) pcp->psc; - (*core->unbindContext) (pcp->driContext); + (*psc->core->unbindContext) (pcp->driContext); } static __GLXDRIcontext * -driCreateContext(__GLXscreenConfigs * psc, - const __GLcontextModes * mode, - GLXContext gc, GLXContext shareList, int renderType) +driCreateContext(__GLXscreenConfigs *base, + const __GLcontextModes *mode, + GLXContext gc, GLXContext shareList, int renderType) { struct drisw_context *pcp, *pcp_shared; __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode; - const __DRIcoreExtension *core; + struct drisw_screen *psc = (struct drisw_screen *) base; __DRIcontext *shared = NULL; - if (!psc || !psc->driScreen) + if (!psc->base.driScreen) return NULL; - core = psc->core; - if (shareList) { pcp_shared = (struct drisw_context *) shareList->driContext; shared = pcp_shared->driContext; @@ -280,10 +288,10 @@ driCreateContext(__GLXscreenConfigs * psc, if (pcp == NULL) return NULL; - pcp->psc = psc; + pcp->psc = &psc->base; pcp->driContext = - (*core->createNewContext) (psc->__driScreen, - config->driConfig, shared, pcp); + (*psc->core->createNewContext) (psc->base.__driScreen, + config->driConfig, shared, pcp); if (pcp->driContext == NULL) { Xfree(pcp); return NULL; @@ -300,22 +308,23 @@ static void driDestroyDrawable(__GLXDRIdrawable * pdraw) { struct drisw_drawable *pdp = (struct drisw_drawable *) pdraw; - const __DRIcoreExtension *core = pdraw->psc->core; + struct drisw_screen *psc = (struct drisw_screen *) pdp->base.psc; - (*core->destroyDrawable) (pdraw->driDrawable); + (*psc->core->destroyDrawable) (pdraw->driDrawable); XDestroyDrawable(pdp, pdraw->psc->dpy, pdraw->drawable); Xfree(pdp); } static __GLXDRIdrawable * -driCreateDrawable(__GLXscreenConfigs * psc, - XID xDrawable, - GLXDrawable drawable, const __GLcontextModes * modes) +driCreateDrawable(__GLXscreenConfigs *base, XID xDrawable, + GLXDrawable drawable, const __GLcontextModes * modes) { __GLXDRIdrawable *pdraw; struct drisw_drawable *pdp; __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes; + struct drisw_screen *psc = (struct drisw_screen *) base; + const __DRIswrastExtension *swrast = psc->swrast; /* Old dri can't handle GLX 1.3+ drawable constructors. */ @@ -329,16 +338,17 @@ driCreateDrawable(__GLXscreenConfigs * psc, pdraw = &(pdp->base); pdraw->xDrawable = xDrawable; pdraw->drawable = drawable; - pdraw->psc = psc; + pdraw->psc = &psc->base; - XCreateDrawable(pdp, psc->dpy, xDrawable, modes->visualID); + XCreateDrawable(pdp, psc->base.dpy, xDrawable, modes->visualID); /* Create a new drawable */ pdraw->driDrawable = - (*swrast->createNewDrawable) (psc->__driScreen, config->driConfig, pdp); + (*swrast->createNewDrawable) (psc->base.__driScreen, + config->driConfig, pdp); if (!pdraw->driDrawable) { - XDestroyDrawable(pdp, psc->dpy, xDrawable); + XDestroyDrawable(pdp, psc->base.dpy, xDrawable); Xfree(pdp); return NULL; } @@ -352,21 +362,26 @@ static int64_t driSwapBuffers(__GLXDRIdrawable * pdraw, int64_t target_msc, int64_t divisor, int64_t remainder) { + struct drisw_drawable *pdp = (struct drisw_drawable *) pdraw; + struct drisw_screen *psc = (struct drisw_screen *) pdp->base.psc; + (void) target_msc; (void) divisor; (void) remainder; - (*pdraw->psc->core->swapBuffers) (pdraw->driDrawable); + (*psc->core->swapBuffers) (pdraw->driDrawable); return 0; } static void -driDestroyScreen(__GLXscreenConfigs * psc) +driDestroyScreen(__GLXscreenConfigs *base) { + struct drisw_screen *psc = (struct drisw_screen *) base; + /* Free the direct rendering per screen data */ - (*psc->core->destroyScreen) (psc->__driScreen); - psc->__driScreen = NULL; + (*psc->core->destroyScreen) (psc->base.__driScreen); + psc->base.__driScreen = NULL; if (psc->driver) dlclose(psc->driver); } @@ -385,19 +400,23 @@ driOpenSwrast(void) return driver; } -static __GLXDRIscreen * -driCreateScreen(__GLXscreenConfigs * psc, int screen, - __GLXdisplayPrivate * priv) +static __GLXscreenConfigs * +driCreateScreen(int screen, __GLXdisplayPrivate *priv) { __GLXDRIscreen *psp; const __DRIconfig **driver_configs; const __DRIextension **extensions; + struct drisw_screen *psc; int i; - psp = Xcalloc(1, sizeof *psp); - if (psp == NULL) + psc = Xcalloc(1, sizeof *psc); + if (psc == NULL) return NULL; + memset(psc, 0, sizeof *psc); + if (!glx_screen_init(&psc->base, screen, priv)) + return NULL; + psc->driver = driOpenSwrast(); if (psc->driver == NULL) goto handle_error; @@ -410,9 +429,9 @@ driCreateScreen(__GLXscreenConfigs * psc, int screen, for (i = 0; extensions[i]; i++) { if (strcmp(extensions[i]->name, __DRI_CORE) == 0) - psc->core = (__DRIcoreExtension *) extensions[i]; + psc->core = (__DRIcoreExtension *) extensions[i]; if (strcmp(extensions[i]->name, __DRI_SWRAST) == 0) - psc->swrast = (__DRIswrastExtension *) extensions[i]; + psc->swrast = (__DRIswrastExtension *) extensions[i]; } if (psc->core == NULL || psc->swrast == NULL) { @@ -420,22 +439,27 @@ driCreateScreen(__GLXscreenConfigs * psc, int screen, goto handle_error; } - psc->__driScreen = - psc->swrast->createNewScreen(screen, - loader_extensions, &driver_configs, psc); - if (psc->__driScreen == NULL) { + psc->base.__driScreen = + psc->swrast->createNewScreen(screen, loader_extensions, + &driver_configs, psc); + if (psc->base.__driScreen == NULL) { ErrorMessageF("failed to create dri screen\n"); goto handle_error; } - driBindExtensions(psc); - driBindCommonExtensions(psc); + extensions = psc->core->getExtensions(psc->base.__driScreen); + driBindExtensions(&psc->base, extensions); + driBindCommonExtensions(&psc->base, extensions); - psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs); - psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs); + psc->base.configs = + driConvertConfigs(psc->core, psc->base.configs, driver_configs); + psc->base.visuals = + driConvertConfigs(psc->core, psc->base.visuals, driver_configs); - psc->driver_configs = driver_configs; + psc->base.driver_configs = driver_configs; + psp = &psc->driScreen; + psc->base.driScreen = psp; psp->destroyScreen = driDestroyScreen; psp->createContext = driCreateContext; psp->createDrawable = driCreateDrawable; @@ -443,10 +467,10 @@ driCreateScreen(__GLXscreenConfigs * psc, int screen, psp->waitX = NULL; psp->waitGL = NULL; - return psp; + return &psc->base; handle_error: - Xfree(psp); + Xfree(psc); if (psc->driver) dlclose(psc->driver); diff --git a/src/glx/glx_pbuffer.c b/src/glx/glx_pbuffer.c index f6f931df7d..bbdba34ebd 100644 --- a/src/glx/glx_pbuffer.c +++ b/src/glx/glx_pbuffer.c @@ -191,7 +191,7 @@ CreateDRIDrawable(Display *dpy, const __GLcontextModes *fbconfig, __GLXDRIdrawable *pdraw; __GLXscreenConfigs *psc; - psc = &priv->screenConfigs[fbconfig->screen]; + psc = priv->screenConfigs[fbconfig->screen]; if (psc->driScreen == NULL) return; @@ -217,7 +217,7 @@ DestroyDRIDrawable(Display *dpy, GLXDrawable drawable, int destroy_xdrawable) int screen; __GLXdisplayPrivate *const priv = __glXInitialize(dpy); __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen); - __GLXscreenConfigs *psc = &priv->screenConfigs[screen]; + __GLXscreenConfigs *psc = priv->screenConfigs[screen]; if (pdraw != NULL) { if (destroy_xdrawable) diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h index ef46a39928..10baedea4c 100644 --- a/src/glx/glxclient.h +++ b/src/glx/glxclient.h @@ -121,8 +121,7 @@ struct __GLXDRIdisplayRec */ void (*destroyDisplay) (__GLXDRIdisplay * display); - __GLXDRIscreen *(*createScreen) (__GLXscreenConfigs * psc, int screen, - __GLXdisplayPrivate * priv); + __GLXscreenConfigs *(*createScreen)(int screen, __GLXdisplayPrivate * priv); }; struct __GLXDRIscreenRec { @@ -530,14 +529,9 @@ struct __GLXscreenConfigsRec * Per screen direct rendering interface functions and data. */ __DRIscreen *__driScreen; - const __DRIcoreExtension *core; - const __DRIlegacyExtension *legacy; - const __DRIswrastExtension *swrast; - const __DRIdri2Extension *dri2; __glxHashTable *drawHash; Display *dpy; - int scr, fd; - void *driver; + int scr; __GLXDRIscreen *driScreen; @@ -638,7 +632,7 @@ struct __GLXdisplayPrivateRec * Also, per screen data which now includes the server \c GLX_EXTENSION * string. */ - __GLXscreenConfigs *screenConfigs; + __GLXscreenConfigs **screenConfigs; #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) /** @@ -650,6 +644,10 @@ struct __GLXdisplayPrivateRec #endif }; +extern int +glx_screen_init(__GLXscreenConfigs *psc, + int screen, __GLXdisplayPrivate * priv); + extern __GLXDRIdrawable * dri2GetGlxDrawableFromXDrawableId(Display *dpy, XID id); diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 16c4eef6ba..0721c27827 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -137,7 +137,7 @@ GetGLXDRIDrawable(Display * dpy, GLXDrawable drawable, int *const scrn_num) return NULL; for (i = 0; i < screen_count; i++) { - psc = &priv->screenConfigs[i]; + psc = priv->screenConfigs[i]; if (psc->drawHash == NULL) continue; @@ -175,7 +175,7 @@ GetGLXScreenConfigs(Display * dpy, int scrn) return (priv && priv->screenConfigs != - NULL) ? &priv->screenConfigs[scrn] : NULL; + NULL) ? priv->screenConfigs[scrn] : NULL; } @@ -202,7 +202,7 @@ GetGLXPrivScreenConfig(Display * dpy, int scrn, __GLXdisplayPrivate ** ppriv, } /* Check to see if the GL is supported on this screen */ - *ppsc = &((*ppriv)->screenConfigs[scrn]); + *ppsc = (*ppriv)->screenConfigs[scrn]; if ((*ppsc)->configs == NULL) { /* No support for GL on this screen regardless of visual */ return GLX_BAD_VISUAL; @@ -233,7 +233,7 @@ ValidateGLXFBConfig(Display * dpy, GLXFBConfig config) if (priv != NULL) { for (i = 0; i < num_screens; i++) { - for (modes = priv->screenConfigs[i].configs; modes != NULL; + for (modes = priv->screenConfigs[i]->configs; modes != NULL; modes = modes->next) { if (modes == (__GLcontextModes *) config) { return (__GLcontextModes *) config; @@ -992,7 +992,7 @@ glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap) __GLXscreenConfigs *psc; __GLcontextModes *modes; - psc = &priv->screenConfigs[vis->screen]; + psc = priv->screenConfigs[vis->screen]; if (psc->driScreen == NULL) break; modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid); @@ -1045,7 +1045,7 @@ glXDestroyGLXPixmap(Display * dpy, GLXPixmap glxpixmap) int screen; __GLXdisplayPrivate *const priv = __glXInitialize(dpy); __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, glxpixmap, &screen); - __GLXscreenConfigs *psc = &priv->screenConfigs[screen]; + __GLXscreenConfigs *psc = priv->screenConfigs[screen]; if (pdraw != NULL) { (*pdraw->destroyDrawable) (pdraw); @@ -1958,14 +1958,14 @@ glXGetFBConfigs(Display * dpy, int screen, int *nelements) *nelements = 0; if (priv && (priv->screenConfigs != NULL) && (screen >= 0) && (screen <= ScreenCount(dpy)) - && (priv->screenConfigs[screen].configs != NULL) - && (priv->screenConfigs[screen].configs->fbconfigID + && (priv->screenConfigs[screen]->configs != NULL) + && (priv->screenConfigs[screen]->configs->fbconfigID != (int) GLX_DONT_CARE)) { unsigned num_configs = 0; __GLcontextModes *modes; - for (modes = priv->screenConfigs[screen].configs; modes != NULL; + for (modes = priv->screenConfigs[screen]->configs; modes != NULL; modes = modes->next) { if (modes->fbconfigID != (int) GLX_DONT_CARE) { num_configs++; @@ -1977,7 +1977,7 @@ glXGetFBConfigs(Display * dpy, int screen, int *nelements) if (config != NULL) { *nelements = num_configs; i = 0; - for (modes = priv->screenConfigs[screen].configs; modes != NULL; + for (modes = priv->screenConfigs[screen]->configs; modes != NULL; modes = modes->next) { if (modes->fbconfigID != (int) GLX_DONT_CARE) { config[i] = modes; @@ -2544,7 +2544,7 @@ __glXGetSyncValuesOML(Display * dpy, GLXDrawable drawable, #ifdef GLX_DIRECT_RENDERING pdraw = GetGLXDRIDrawable(dpy, drawable, &i); #endif - psc = &priv->screenConfigs[i]; + psc = priv->screenConfigs[i]; #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER) if (pdraw && psc->sbc && psc->msc) diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c index 691e8dfadf..c423ffcbdf 100644 --- a/src/glx/glxcurrent.c +++ b/src/glx/glxcurrent.c @@ -295,7 +295,7 @@ FetchDRIDrawable(Display * dpy, GLXDrawable glxDrawable, GLXContext gc) if (priv == NULL) return NULL; - psc = &priv->screenConfigs[gc->screen]; + psc = priv->screenConfigs[gc->screen]; if (psc->drawHash == NULL) return NULL; diff --git a/src/glx/glxext.c b/src/glx/glxext.c index 69a7b29eb2..320246cc4f 100644 --- a/src/glx/glxext.c +++ b/src/glx/glxext.c @@ -244,9 +244,9 @@ FreeScreenConfigs(__GLXdisplayPrivate * priv) GLint i, screens; /* Free screen configuration information */ - psc = priv->screenConfigs; screens = ScreenCount(priv->dpy); - for (i = 0; i < screens; i++, psc++) { + for (i = 0; i < screens; i++) { + psc = priv->screenConfigs[i]; if (psc->configs) { _gl_context_modes_destroy(psc->configs); if (psc->effectiveGLXexts) @@ -268,11 +268,14 @@ FreeScreenConfigs(__GLXdisplayPrivate * priv) psc->driver_configs = NULL; } if (psc->driScreen) { - psc->driScreen->destroyScreen(psc); __glxHashDestroy(psc->drawHash); - XFree(psc->driScreen); + psc->driScreen->destroyScreen(psc); psc->driScreen = NULL; + } else { + Xfree(psc); } +#else + Xfree(psc); #endif } XFree((char *) priv->screenConfigs); @@ -672,15 +675,15 @@ createConfigsFromProperties(Display * dpy, int nvisuals, int nprops, } static GLboolean -getVisualConfigs(Display * dpy, __GLXdisplayPrivate * priv, int screen) +getVisualConfigs(__GLXscreenConfigs *psc, + __GLXdisplayPrivate *priv, int screen) { xGLXGetVisualConfigsReq *req; - __GLXscreenConfigs *psc; xGLXGetVisualConfigsReply reply; + Display *dpy = priv->dpy; LockDisplay(dpy); - psc = priv->screenConfigs + screen; psc->visuals = NULL; GetReq(GLXGetVisualConfigs, req); req->reqType = priv->majorOpcode; @@ -701,15 +704,14 @@ getVisualConfigs(Display * dpy, __GLXdisplayPrivate * priv, int screen) } static GLboolean -getFBConfigs(Display * dpy, __GLXdisplayPrivate * priv, int screen) +getFBConfigs(__GLXscreenConfigs *psc, __GLXdisplayPrivate *priv, int screen) { xGLXGetFBConfigsReq *fb_req; xGLXGetFBConfigsSGIXReq *sgi_req; xGLXVendorPrivateWithReplyReq *vpreq; xGLXGetFBConfigsReply reply; - __GLXscreenConfigs *psc; + Display *dpy = priv->dpy; - psc = priv->screenConfigs + screen; psc->serverGLXexts = __glXQueryServerString(dpy, priv->majorOpcode, screen, GLX_EXTENSIONS); @@ -748,6 +750,35 @@ getFBConfigs(Display * dpy, __GLXdisplayPrivate * priv, int screen) return psc->configs != NULL; } +_X_HIDDEN Bool +glx_screen_init(__GLXscreenConfigs *psc, + int screen, __GLXdisplayPrivate * priv) +{ + /* Initialize per screen dynamic client GLX extensions */ + psc->ext_list_first_time = GL_TRUE; + psc->scr = screen; + psc->dpy = priv->dpy; + psc->drawHash = __glxHashCreate(); + if (psc->drawHash == NULL) + return GL_FALSE; + + getVisualConfigs(psc, priv, screen); + getFBConfigs(psc, priv, screen); + + return GL_TRUE; +} + +static __GLXscreenConfigs * +createIndirectScreen() +{ + __GLXscreenConfigs *psc; + + psc = Xmalloc(sizeof *psc); + memset(psc, 0, sizeof *psc); + + return psc; +} + /* ** Allocate the memory for the per screen configs for each screen. ** If that works then fetch the per screen configs data. @@ -762,12 +793,9 @@ AllocAndFetchScreenConfigs(Display * dpy, __GLXdisplayPrivate * priv) ** First allocate memory for the array of per screen configs. */ screens = ScreenCount(dpy); - psc = (__GLXscreenConfigs *) Xmalloc(screens * sizeof(__GLXscreenConfigs)); - if (!psc) { + priv->screenConfigs = Xmalloc(screens * sizeof *priv->screenConfigs); + if (!priv->screenConfigs) return GL_FALSE; - } - memset(psc, 0, screens * sizeof(__GLXscreenConfigs)); - priv->screenConfigs = psc; priv->serverGLXversion = __glXQueryServerString(dpy, priv->majorOpcode, 0, GLX_VERSION); @@ -777,33 +805,22 @@ AllocAndFetchScreenConfigs(Display * dpy, __GLXdisplayPrivate * priv) } for (i = 0; i < screens; i++, psc++) { - getVisualConfigs(dpy, priv, i); - getFBConfigs(dpy, priv, i); - #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) - psc->scr = i; - psc->dpy = dpy; - psc->drawHash = __glxHashCreate(); - if (psc->drawHash == NULL) - continue; - - /* Initialize per screen dynamic client GLX extensions */ - psc->ext_list_first_time = GL_TRUE; - if (priv->dri2Display) - psc->driScreen = (*priv->dri2Display->createScreen) (psc, i, priv); - - if (psc->driScreen == NULL && priv->driDisplay) - psc->driScreen = (*priv->driDisplay->createScreen) (psc, i, priv); - - if (psc->driScreen == NULL && priv->driswDisplay) - psc->driScreen = (*priv->driswDisplay->createScreen) (psc, i, priv); - - if (psc->driScreen == NULL) { + psc = (*priv->dri2Display->createScreen) (i, priv); + if (psc == NULL && priv->driDisplay) + psc = (*priv->driDisplay->createScreen) (i, priv); + if (psc == NULL && priv->driswDisplay) + psc = (*priv->driswDisplay->createScreen) (i, priv); + if (psc == NULL) + psc = createIndirectScreen (i, priv); + + if (psc == NULL) { __glxHashDestroy(psc->drawHash); psc->drawHash = NULL; } #endif + priv->screenConfigs[i] = psc; } SyncHandle(); return GL_TRUE; -- cgit v1.2.3 From 089fc37c6fa158824279e08e3b378ced94d6f803 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Mon, 19 Jul 2010 16:39:53 -0400 Subject: glx: Move DRI1 specific extensions and code to DRI1 screen private --- src/glx/dri2_glx.c | 8 ++-- src/glx/dri_common.c | 34 -------------- src/glx/dri_common.h | 2 - src/glx/dri_glx.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/glx/drisw_glx.c | 1 - src/glx/glxclient.h | 10 +---- src/glx/glxcmds.c | 113 ++-------------------------------------------- 7 files changed, 132 insertions(+), 160 deletions(-) (limited to 'src/glx/drisw_glx.c') diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index e00dffeab1..7d0a8603e0 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -522,7 +522,7 @@ dri2GetBuffersWithFormat(__DRIdrawable * driDrawable, #ifdef X_DRI2SwapInterval -static void +static int dri2SetSwapInterval(__GLXDRIdrawable *pdraw, int interval) { struct dri2_drawable *priv = (struct dri2_drawable *) pdraw; @@ -535,10 +535,10 @@ dri2SetSwapInterval(__GLXDRIdrawable *pdraw, int interval) switch (vblank_mode) { case DRI_CONF_VBLANK_NEVER: - return; + return GLX_BAD_VALUE; case DRI_CONF_VBLANK_ALWAYS_SYNC: if (interval <= 0) - return; + return GLX_BAD_VALUE; break; default: break; @@ -546,6 +546,8 @@ dri2SetSwapInterval(__GLXDRIdrawable *pdraw, int interval) DRI2SwapInterval(priv->base.psc->dpy, priv->base.xDrawable, interval); priv->swap_interval = interval; + + return 0; } static unsigned int diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c index 78636cd310..907b05f639 100644 --- a/src/glx/dri_common.c +++ b/src/glx/dri_common.c @@ -336,40 +336,6 @@ driConvertConfigs(const __DRIcoreExtension * core, return head.next; } -/* Bind DRI1 specific extensions */ -_X_HIDDEN void -driBindExtensions(__GLXscreenConfigs *psc, const __DRIextension **extensions) -{ - int i; - - for (i = 0; extensions[i]; i++) { -#ifdef __DRI_SWAP_CONTROL - /* No DRI2 support for swap_control at the moment, since SwapBuffers - * is done by the X server */ - if (strcmp(extensions[i]->name, __DRI_SWAP_CONTROL) == 0) { - psc->swapControl = (__DRIswapControlExtension *) extensions[i]; - __glXEnableDirectExtension(psc, "GLX_SGI_swap_control"); - __glXEnableDirectExtension(psc, "GLX_MESA_swap_control"); - } -#endif - -#ifdef __DRI_MEDIA_STREAM_COUNTER - if (strcmp(extensions[i]->name, __DRI_MEDIA_STREAM_COUNTER) == 0) { - psc->msc = (__DRImediaStreamCounterExtension *) extensions[i]; - __glXEnableDirectExtension(psc, "GLX_SGI_video_sync"); - } -#endif - -#ifdef __DRI_SWAP_BUFFER_COUNTER - /* No driver supports this at this time and the extension is - * not defined in dri_interface.h. Will enable - * GLX_OML_sync_control if implemented. */ -#endif - - /* Ignore unknown extensions */ - } -} - /* Bind extensions common to DRI1 and DRI2 */ _X_HIDDEN void driBindCommonExtensions(__GLXscreenConfigs *psc, diff --git a/src/glx/dri_common.h b/src/glx/dri_common.h index 9c07a0f6d4..7ed7767c92 100644 --- a/src/glx/dri_common.h +++ b/src/glx/dri_common.h @@ -56,8 +56,6 @@ extern void ErrorMessageF(const char *f, ...); extern void *driOpenDriver(const char *driverName); -extern void driBindExtensions(__GLXscreenConfigs * psc, - const __DRIextension **extensions); extern void driBindCommonExtensions(__GLXscreenConfigs * psc, const __DRIextension **extensions); diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c index e14bc62e63..42d5994b2e 100644 --- a/src/glx/dri_glx.c +++ b/src/glx/dri_glx.c @@ -66,6 +66,9 @@ struct dri_screen __GLXDRIscreen driScreen; const __DRIlegacyExtension *legacy; const __DRIcoreExtension *core; + const __DRIswapControlExtension *swapControl; + const __DRImediaStreamCounterExtension *msc; + void *driver; int fd; }; @@ -657,6 +660,116 @@ static const struct glx_context_vtable dri_context_vtable = { NULL, }; +#ifdef __DRI_SWAP_BUFFER_COUNTER + +static int +driDrawableGetMSC(__GLXscreenConfigs *base, __GLXDRIdrawable *pdraw, + int64_t *ust, int64_t *msc, int64_t *sbc) +{ + struct dri_screen *psc = (struct dri_screen *) base; + + if (pdraw && psc->sbc && psc->msc) + return ( (*psc->msc->getMSC)(psc->driScreen, msc) == 0 && + (*psc->sbc->getSBC)(pdraw->driDrawable, sbc) == 0 && + __glXGetUST(ust) == 0 ); +} + +static int +driWaitForMSC(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor, + int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc) +{ + struct dri_screen *psc = (struct dri_screen *) pdraw->psc; + + if (pdraw != NULL && psc->msc != NULL) { + ret = (*psc->msc->waitForMSC) (pdraw->driDrawable, target_msc, + divisor, remainder, msc, sbc); + + /* __glXGetUST returns zero on success and non-zero on failure. + * This function returns True on success and False on failure. + */ + return ret == 0 && __glXGetUST(ust) == 0; + } +} + +static int +driWaitForSBC(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust, + int64_t *msc, int64_t *sbc) +{ + if (pdraw != NULL && psc->sbc != NULL) { + ret = + (*psc->sbc->waitForSBC) (pdraw->driDrawable, target_sbc, msc, sbc); + + /* __glXGetUST returns zero on success and non-zero on failure. + * This function returns True on success and False on failure. + */ + return ((ret == 0) && (__glXGetUST(ust) == 0)); + } + + return DRI2WaitSBC(pdraw->psc->dpy, pdraw->xDrawable, target_sbc, ust, msc, + sbc); +} + +#endif + +static int +driSetSwapInterval(__GLXDRIdrawable *pdraw, int interval) +{ + GLXContext gc = __glXGetCurrentContext(); + struct dri_screen *psc; + + if (gc->driContext) { + psc = (struct dri_screen *) pdraw->psc; + + if (psc->swapControl != NULL && pdraw != NULL) { + psc->swapControl->setSwapInterval(pdraw->driDrawable, interval); + return 0; + } + } + + return GLX_BAD_CONTEXT; +} + +static int +driGetSwapInterval(__GLXDRIdrawable *pdraw) +{ + GLXContext gc = __glXGetCurrentContext(); + struct dri_screen *psc; + + if (gc != NULL && gc->driContext) { + psc = (struct dri_screen *) pdraw->psc; + + if (psc->swapControl != NULL && pdraw != NULL) { + return psc->swapControl->getSwapInterval(pdraw->driDrawable); + } + } + + return 0; +} + +/* Bind DRI1 specific extensions */ +static void +driBindExtensions(struct dri_screen *psc, const __DRIextension **extensions) +{ + int i; + + for (i = 0; extensions[i]; i++) { + /* No DRI2 support for swap_control at the moment, since SwapBuffers + * is done by the X server */ + if (strcmp(extensions[i]->name, __DRI_SWAP_CONTROL) == 0) { + psc->swapControl = (__DRIswapControlExtension *) extensions[i]; + __glXEnableDirectExtension(&psc->base, "GLX_SGI_swap_control"); + __glXEnableDirectExtension(&psc->base, "GLX_MESA_swap_control"); + } + + if (strcmp(extensions[i]->name, __DRI_MEDIA_STREAM_COUNTER) == 0) { + psc->msc = (__DRImediaStreamCounterExtension *) extensions[i]; + __glXEnableDirectExtension(&psc->base, "GLX_SGI_video_sync"); + } + + /* Ignore unknown extensions */ + } +} + static __GLXscreenConfigs * driCreateScreen(int screen, __GLXdisplayPrivate *priv) { @@ -716,7 +829,7 @@ driCreateScreen(int screen, __GLXdisplayPrivate *priv) } extensions = psc->core->getExtensions(psc->base.__driScreen); - driBindExtensions(&psc->base, extensions); + driBindExtensions(psc, extensions); driBindCommonExtensions(&psc->base, extensions); psp = &psc->driScreen; @@ -731,6 +844,15 @@ driCreateScreen(int screen, __GLXdisplayPrivate *priv) psp->waitX = NULL; psp->waitGL = NULL; +#ifdef __DRI_SWAP_BUFFER_COUNTER + psp->getDrawableMSC = driDrawableGetMSC; + psp->waitForMSC = driWaitForMSC; + psp->waitForSBC = driWaitForSBC; +#endif + + psp->setSwapInterval = driSetSwapInterval; + psp->getSwapInterval = driGetSwapInterval; + psc->base.direct_context_vtable = &dri_context_vtable; return &psc->base; diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index 4ed13a3ac7..d403b23537 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -448,7 +448,6 @@ driCreateScreen(int screen, __GLXdisplayPrivate *priv) } extensions = psc->core->getExtensions(psc->base.__driScreen); - driBindExtensions(&psc->base, extensions); driBindCommonExtensions(&psc->base, extensions); psc->base.configs = diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h index 22c9843713..b865e24b36 100644 --- a/src/glx/glxclient.h +++ b/src/glx/glxclient.h @@ -151,7 +151,7 @@ struct __GLXDRIscreenRec { int64_t *msc, int64_t *sbc); int (*waitForSBC)(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust, int64_t *msc, int64_t *sbc); - void (*setSwapInterval)(__GLXDRIdrawable *pdraw, int interval); + int (*setSwapInterval)(__GLXDRIdrawable *pdraw, int interval); int (*getSwapInterval)(__GLXDRIdrawable *pdraw); }; @@ -541,18 +541,10 @@ struct __GLXscreenConfigsRec const __DRIcopySubBufferExtension *driCopySubBuffer; #endif -#ifdef __DRI_SWAP_CONTROL - const __DRIswapControlExtension *swapControl; -#endif - #ifdef __DRI_FRAME_TRACKING const __DRIframeTrackingExtension *frameTracking; #endif -#ifdef __DRI_MEDIA_STREAM_COUNTER - const __DRImediaStreamCounterExtension *msc; -#endif - #endif /** diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 5d022557bb..4a7360c149 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -2038,22 +2038,6 @@ __glXSwapIntervalSGI(int interval) return GLX_BAD_VALUE; } -#ifdef __DRI_SWAP_CONTROL - if (gc->driContext) { - __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy, - gc->screen ); - __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(gc->currentDpy, - gc->currentDrawable, - NULL); - if (psc->swapControl != NULL && pdraw != NULL) { - psc->swapControl->setSwapInterval(pdraw->driDrawable, interval); - return 0; - } - else if (pdraw == NULL) { - return GLX_BAD_CONTEXT; - } - } -#endif psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen); #ifdef GLX_DIRECT_RENDERING @@ -2097,25 +2081,9 @@ __glXSwapIntervalSGI(int interval) static int __glXSwapIntervalMESA(unsigned int interval) { +#ifdef GLX_DIRECT_RENDERING GLXContext gc = __glXGetCurrentContext(); -#ifdef __DRI_SWAP_CONTROL - if (gc != NULL && gc->driContext) { - __GLXscreenConfigs *const psc = GetGLXScreenConfigs(gc->currentDpy, - gc->screen); - - if ((psc != NULL) && (psc->driScreen != NULL)) { - __GLXDRIdrawable *pdraw = - GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); - if (psc->swapControl != NULL && pdraw != NULL) { - psc->swapControl->setSwapInterval(pdraw->driDrawable, interval); - return 0; - } - } - } -#endif - -#ifdef GLX_DIRECT_RENDERING if (gc != NULL && gc->driContext) { __GLXscreenConfigs *psc; @@ -2123,8 +2091,7 @@ __glXSwapIntervalMESA(unsigned int interval) if (psc->driScreen && psc->driScreen->setSwapInterval) { __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); - psc->driScreen->setSwapInterval(pdraw, interval); - return 0; + return psc->driScreen->setSwapInterval(pdraw, interval); } } #endif @@ -2136,24 +2103,9 @@ __glXSwapIntervalMESA(unsigned int interval) static int __glXGetSwapIntervalMESA(void) { -#ifdef __DRI_SWAP_CONTROL +#ifdef GLX_DIRECT_RENDERING GLXContext gc = __glXGetCurrentContext(); - if (gc != NULL && gc->driContext) { - __GLXscreenConfigs *const psc = GetGLXScreenConfigs(gc->currentDpy, - gc->screen); - - if ((psc != NULL) && (psc->driScreen != NULL)) { - __GLXDRIdrawable *pdraw = - GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); - if (psc->swapControl != NULL && pdraw != NULL) { - return psc->swapControl->getSwapInterval(pdraw->driDrawable); - } - } - } -#endif - -#ifdef GLX_DIRECT_RENDERING if (gc != NULL && gc->driContext) { __GLXscreenConfigs *psc; @@ -2302,16 +2254,6 @@ __glXGetVideoSyncSGI(unsigned int *count) * FIXME: there should be a GLX encoding for this call. I can find no * FIXME: documentation for the GLX encoding. */ -#ifdef __DRI_MEDIA_STREAM_COUNTER - if ( psc->msc && psc->driScreen ) { - ret = (*psc->msc->getDrawableMSC)(psc->__driScreen, - pdraw->driDrawable, &msc); - *count = (unsigned) msc; - - return (ret == 0) ? 0 : GLX_BAD_CONTEXT; - } -#endif - #ifdef GLX_DIRECT_RENDERING if (psc->driScreen && psc->driScreen->getDrawableMSC) { ret = psc->driScreen->getDrawableMSC(psc, pdraw, &ust, &msc, &sbc); @@ -2350,15 +2292,6 @@ __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count) pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); #endif -#ifdef __DRI_MEDIA_STREAM_COUNTER - if (psc->msc != NULL && psc->driScreen ) { - ret = (*psc->msc->waitForMSC)(pdraw->driDrawable, 0, - divisor, remainder, &msc, &sbc); - *count = (unsigned) msc; - return (ret == 0) ? 0 : GLX_BAD_CONTEXT; - } -#endif - #ifdef GLX_DIRECT_RENDERING if (psc->driScreen && psc->driScreen->waitForMSC) { ret = psc->driScreen->waitForMSC(pdraw, 0, divisor, remainder, &ust, &msc, @@ -2543,18 +2476,7 @@ __glXGetSyncValuesOML(Display * dpy, GLXDrawable drawable, #ifdef GLX_DIRECT_RENDERING pdraw = GetGLXDRIDrawable(dpy, drawable, &i); -#endif psc = priv->screenConfigs[i]; - -#if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER) - if (pdraw && psc->sbc && psc->msc) - return ( (pdraw && psc->sbc && psc->msc) - && ((*psc->msc->getMSC)(psc->driScreen, msc) == 0) - && ((*psc->sbc->getSBC)(pdraw->driDrawable, sbc) == 0) - && (__glXGetUST(ust) == 0) ); -#endif - -#ifdef GLX_DIRECT_RENDERING if (pdraw && psc && psc->driScreen && psc->driScreen->getDrawableMSC) { ret = psc->driScreen->getDrawableMSC(psc, pdraw, ust, msc, sbc); return ret; @@ -2703,12 +2625,6 @@ __glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable, if (target_msc == 0 && divisor == 0 && remainder == 0) remainder = 1; -#ifdef __DRI_SWAP_BUFFER_COUNTER - if (psc->counters != NULL) - return (*psc->sbc->swapBuffersMSC)(pdraw->driDrawable, target_msc, - divisor, remainder); -#endif - #ifdef GLX_DIRECT_RENDERING if (psc->driScreen && psc->driScreen->swapBuffers) return (*psc->driScreen->swapBuffers)(pdraw, target_msc, divisor, @@ -2741,18 +2657,6 @@ __glXWaitForMscOML(Display * dpy, GLXDrawable drawable, if (divisor > 0 && remainder >= divisor) return False; -#ifdef __DRI_MEDIA_STREAM_COUNTER - if (pdraw != NULL && psc->msc != NULL) { - ret = (*psc->msc->waitForMSC) (pdraw->driDrawable, target_msc, - divisor, remainder, msc, sbc); - - /* __glXGetUST returns zero on success and non-zero on failure. - * This function returns True on success and False on failure. - */ - return ((ret == 0) && (__glXGetUST(ust) == 0)); - } -#endif - #ifdef GLX_DIRECT_RENDERING if (pdraw && psc->driScreen && psc->driScreen->waitForMSC) { ret = psc->driScreen->waitForMSC(pdraw, target_msc, divisor, remainder, @@ -2782,17 +2686,6 @@ __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable, */ if (target_sbc < 0) return False; -#ifdef __DRI_SWAP_BUFFER_COUNTER - if (pdraw != NULL && psc->sbc != NULL) { - ret = - (*psc->sbc->waitForSBC) (pdraw->driDrawable, target_sbc, msc, sbc); - - /* __glXGetUST returns zero on success and non-zero on failure. - * This function returns True on success and False on failure. - */ - return ((ret == 0) && (__glXGetUST(ust) == 0)); - } -#endif #ifdef GLX_DIRECT_RENDERING if (pdraw && psc->driScreen && psc->driScreen->waitForSBC) { -- cgit v1.2.3 From 70887d517290060a80c7f5dd8c0ea0c834c4d91e Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Mon, 19 Jul 2010 16:45:23 -0400 Subject: glx: Move __driScreen into the dri screen privates --- src/glx/dri2_glx.c | 22 +++++++++++----------- src/glx/dri_glx.c | 21 +++++++++++---------- src/glx/drisw_glx.c | 19 ++++++++++--------- src/glx/glxclient.h | 1 - 4 files changed, 32 insertions(+), 31 deletions(-) (limited to 'src/glx/drisw_glx.c') diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index 7d0a8603e0..3187fa16d9 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -78,7 +78,8 @@ struct dri2_display struct dri2_screen { __GLXscreenConfigs base; - __GLXDRIscreen driScreen; + __DRIscreen *driScreen; + __GLXDRIscreen vtable; const __DRIdri2Extension *dri2; const __DRIcoreExtension *core; @@ -161,7 +162,7 @@ dri2CreateContext(__GLXscreenConfigs *base, pcp->psc = &psc->base; pcp->driContext = - (*psc->dri2->createNewContext) (psc->base.__driScreen, + (*psc->dri2->createNewContext) (psc->driScreen, config->driConfig, shared, pcp); gc->__driContext = pcp->driContext; @@ -217,7 +218,7 @@ dri2CreateDrawable(__GLXscreenConfigs *base, XID xDrawable, pdraw->have_back = 0; if (psc->config) - psc->config->configQueryi(psc->base.__driScreen, + psc->config->configQueryi(psc->driScreen, "vblank_mode", &vblank_mode); switch (vblank_mode) { @@ -238,7 +239,7 @@ dri2CreateDrawable(__GLXscreenConfigs *base, XID xDrawable, pdp = (struct dri2_display *)dpyPriv->dri2Display;; /* Create a new drawable */ pdraw->base.driDrawable = - (*psc->dri2->createNewDrawable) (psc->base.__driScreen, + (*psc->dri2->createNewDrawable) (psc->driScreen, config->driConfig, pdraw); if (!pdraw->base.driDrawable) { @@ -400,9 +401,8 @@ dri2DestroyScreen(__GLXscreenConfigs *base) struct dri2_screen *psc = (struct dri2_screen *) base; /* Free the direct rendering per screen data */ - (*psc->core->destroyScreen) (psc->base.__driScreen); + (*psc->core->destroyScreen) (psc->driScreen); close(psc->fd); - base->__driScreen = NULL; Xfree(psc); } @@ -530,7 +530,7 @@ dri2SetSwapInterval(__GLXDRIdrawable *pdraw, int interval) struct dri2_screen *psc = (struct dri2_screen *) priv->base.psc; if (psc->config) - psc->config->configQueryi(psc->base.__driScreen, + psc->config->configQueryi(psc->driScreen, "vblank_mode", &vblank_mode); switch (vblank_mode) { @@ -737,18 +737,18 @@ dri2CreateScreen(int screen, __GLXdisplayPrivate * priv) /* If the server does not support the protocol for * DRI2GetBuffersWithFormat, don't supply that interface to the driver. */ - psc->base.__driScreen = + psc->driScreen = psc->dri2->createNewScreen(screen, psc->fd, (const __DRIextension **) &pdp->loader_extensions[0], &driver_configs, psc); - if (psc->base.__driScreen == NULL) { + if (psc->driScreen == NULL) { ErrorMessageF("failed to create dri screen\n"); goto handle_error; } - extensions = psc->core->getExtensions(psc->base.__driScreen); + extensions = psc->core->getExtensions(psc->driScreen); driBindCommonExtensions(&psc->base, extensions); dri2BindExtensions(psc, extensions); @@ -759,7 +759,7 @@ dri2CreateScreen(int screen, __GLXdisplayPrivate * priv) psc->base.driver_configs = driver_configs; - psp = &psc->driScreen; + psp = &psc->vtable; psc->base.driScreen = psp; psp->destroyScreen = dri2DestroyScreen; psp->createContext = dri2CreateContext; diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c index 42d5994b2e..373f9fb649 100644 --- a/src/glx/dri_glx.c +++ b/src/glx/dri_glx.c @@ -63,7 +63,8 @@ struct dri_screen { __GLXscreenConfigs base; - __GLXDRIscreen driScreen; + __DRIscreen *driScreen; + __GLXDRIscreen vtable; const __DRIlegacyExtension *legacy; const __DRIcoreExtension *core; const __DRIswapControlExtension *swapControl; @@ -551,7 +552,7 @@ driCreateContext(__GLXscreenConfigs *base, } pcp->driContext = - (*psc->legacy->createNewContext) (psc->base.__driScreen, + (*psc->legacy->createNewContext) (psc->driScreen, config->driConfig, renderType, shared, hwContext, pcp); if (pcp->driContext == NULL) { @@ -607,7 +608,7 @@ driCreateDrawable(__GLXscreenConfigs *base, /* Create a new drawable */ pdraw->driDrawable = - (*psc->legacy->createNewDrawable) (psc->base.__driScreen, + (*psc->legacy->createNewDrawable) (psc->driScreen, config->driConfig, hwDrawable, GLX_WINDOW_BIT, @@ -648,9 +649,9 @@ driDestroyScreen(__GLXscreenConfigs *base) struct dri_screen *psc = (struct dri_screen *) base; /* Free the direct rendering per screen data */ - if (psc->base.__driScreen) - (*psc->core->destroyScreen) (psc->base.__driScreen); - psc->base.__driScreen = NULL; + if (psc->driScreen) + (*psc->core->destroyScreen) (psc->driScreen); + psc->driScreen = NULL; if (psc->driver) dlclose(psc->driver); } @@ -820,19 +821,19 @@ driCreateScreen(int screen, __GLXdisplayPrivate *priv) } pdp = (struct dri_display *) priv->driDisplay; - psc->base.__driScreen = + psc->driScreen = CallCreateNewScreen(psc->base.dpy, screen, psc, pdp); - if (psc->base.__driScreen == NULL) { + if (psc->driScreen == NULL) { dlclose(psc->driver); Xfree(psc); return NULL; } - extensions = psc->core->getExtensions(psc->base.__driScreen); + extensions = psc->core->getExtensions(psc->driScreen); driBindExtensions(psc, extensions); driBindCommonExtensions(&psc->base, extensions); - psp = &psc->driScreen; + psp = &psc->vtable; psc->base.driScreen = psp; if (psc->base.driCopySubBuffer) psp->copySubBuffer = driCopySubBuffer; diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index d403b23537..e9a88e6db0 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -44,7 +44,8 @@ struct drisw_screen { __GLXscreenConfigs base; - __GLXDRIscreen driScreen; + __DRIscreen *driScreen; + __GLXDRIscreen vtable; const __DRIcoreExtension *core; const __DRIswrastExtension *swrast; void *driver; @@ -290,7 +291,7 @@ driCreateContext(__GLXscreenConfigs *base, pcp->psc = &psc->base; pcp->driContext = - (*psc->core->createNewContext) (psc->base.__driScreen, + (*psc->core->createNewContext) (psc->driScreen, config->driConfig, shared, pcp); if (pcp->driContext == NULL) { Xfree(pcp); @@ -344,7 +345,7 @@ driCreateDrawable(__GLXscreenConfigs *base, XID xDrawable, /* Create a new drawable */ pdraw->driDrawable = - (*swrast->createNewDrawable) (psc->base.__driScreen, + (*swrast->createNewDrawable) (psc->driScreen, config->driConfig, pdp); if (!pdraw->driDrawable) { @@ -380,8 +381,8 @@ driDestroyScreen(__GLXscreenConfigs *base) struct drisw_screen *psc = (struct drisw_screen *) base; /* Free the direct rendering per screen data */ - (*psc->core->destroyScreen) (psc->base.__driScreen); - psc->base.__driScreen = NULL; + (*psc->core->destroyScreen) (psc->driScreen); + psc->driScreen = NULL; if (psc->driver) dlclose(psc->driver); } @@ -439,15 +440,15 @@ driCreateScreen(int screen, __GLXdisplayPrivate *priv) goto handle_error; } - psc->base.__driScreen = + psc->driScreen = psc->swrast->createNewScreen(screen, loader_extensions, &driver_configs, psc); - if (psc->base.__driScreen == NULL) { + if (psc->driScreen == NULL) { ErrorMessageF("failed to create dri screen\n"); goto handle_error; } - extensions = psc->core->getExtensions(psc->base.__driScreen); + extensions = psc->core->getExtensions(psc->driScreen); driBindCommonExtensions(&psc->base, extensions); psc->base.configs = @@ -457,7 +458,7 @@ driCreateScreen(int screen, __GLXdisplayPrivate *priv) psc->base.driver_configs = driver_configs; - psp = &psc->driScreen; + psp = &psc->vtable; psc->base.driScreen = psp; psp->destroyScreen = driDestroyScreen; psp->createContext = driCreateContext; diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h index b865e24b36..d7af44470f 100644 --- a/src/glx/glxclient.h +++ b/src/glx/glxclient.h @@ -528,7 +528,6 @@ struct __GLXscreenConfigsRec /** * Per screen direct rendering interface functions and data. */ - __DRIscreen *__driScreen; __glxHashTable *drawHash; Display *dpy; int scr; -- cgit v1.2.3 From 271c3c3a90ccfd01da9d7ac7fa451518f4e6a27c Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Mon, 19 Jul 2010 18:11:03 -0400 Subject: glx: Move __DRIdrawable pointers to DRI drawable privates --- src/glx/dri2_glx.c | 48 ++++++++++++++++++++--------------- src/glx/dri_glx.c | 73 +++++++++++++++++++++++++++++++++-------------------- src/glx/drisw_glx.c | 28 ++++++++++---------- src/glx/glxclient.h | 1 - src/glx/glxcmds.c | 2 +- 5 files changed, 88 insertions(+), 64 deletions(-) (limited to 'src/glx/drisw_glx.c') diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index 3187fa16d9..27223fdaeb 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -101,6 +101,7 @@ struct dri2_context struct dri2_drawable { __GLXDRIdrawable base; + __DRIdrawable *driDrawable; __DRIbuffer buffers[5]; int bufferCount; int width, height; @@ -127,9 +128,11 @@ dri2BindContext(__GLXDRIcontext *context, { struct dri2_context *pcp = (struct dri2_context *) context; struct dri2_screen *psc = (struct dri2_screen *) pcp->psc; + struct dri2_drawable *pdr = (struct dri2_drawable *) draw; + struct dri2_drawable *prd = (struct dri2_drawable *) read; return (*psc->core->bindContext) (pcp->driContext, - draw->driDrawable, read->driDrawable); + pdr->driDrawable, prd->driDrawable); } static void @@ -179,18 +182,19 @@ dri2CreateContext(__GLXscreenConfigs *base, } static void -dri2DestroyDrawable(__GLXDRIdrawable *pdraw) +dri2DestroyDrawable(__GLXDRIdrawable *base) { - struct dri2_screen *psc = (struct dri2_screen *) pdraw->psc; + struct dri2_screen *psc = (struct dri2_screen *) base->psc; + struct dri2_drawable *pdraw = (struct dri2_drawable *) base; __GLXdisplayPrivate *dpyPriv; struct dri2_display *pdp; - dpyPriv = __glXInitialize(pdraw->psc->dpy); + dpyPriv = __glXInitialize(base->psc->dpy); pdp = (struct dri2_display *)dpyPriv->dri2Display; - __glxHashDelete(pdp->dri2Hash, pdraw->xDrawable); + __glxHashDelete(pdp->dri2Hash, pdraw->base.xDrawable); (*psc->core->destroyDrawable) (pdraw->driDrawable); - DRI2DestroyDrawable(psc->base.dpy, pdraw->xDrawable); + DRI2DestroyDrawable(psc->base.dpy, pdraw->base.xDrawable); Xfree(pdraw); } @@ -238,18 +242,18 @@ dri2CreateDrawable(__GLXscreenConfigs *base, XID xDrawable, dpyPriv = __glXInitialize(psc->base.dpy); pdp = (struct dri2_display *)dpyPriv->dri2Display;; /* Create a new drawable */ - pdraw->base.driDrawable = + pdraw->driDrawable = (*psc->dri2->createNewDrawable) (psc->driScreen, config->driConfig, pdraw); - if (!pdraw->base.driDrawable) { + if (!pdraw->driDrawable) { DRI2DestroyDrawable(psc->base.dpy, xDrawable); Xfree(pdraw); return NULL; } if (__glxHashInsert(pdp->dri2Hash, xDrawable, pdraw)) { - (*psc->core->destroyDrawable) (pdraw->base.driDrawable); + (*psc->core->destroyDrawable) (pdraw->driDrawable); DRI2DestroyDrawable(psc->base.dpy, xDrawable); Xfree(pdraw); return None; @@ -319,7 +323,7 @@ dri2CopySubBuffer(__GLXDRIdrawable *pdraw, int x, int y, int width, int height) #ifdef __DRI2_FLUSH if (psc->f) - (*psc->f->flush) (pdraw->driDrawable); + (*psc->f->flush) (priv->driDrawable); #endif region = XFixesCreateRegion(psc->base.dpy, &xrect, 1); @@ -349,7 +353,7 @@ dri2_copy_drawable(struct dri2_drawable *priv, int dest, int src) #ifdef __DRI2_FLUSH if (psc->f) - (*psc->f->flush) (priv->base.driDrawable); + (*psc->f->flush) (priv->driDrawable); #endif region = XFixesCreateRegion(psc->base.dpy, &xrect, 1); @@ -451,7 +455,7 @@ dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor, #ifdef __DRI2_FLUSH if (psc->f) - (*psc->f->flush)(pdraw->driDrawable); + (*psc->f->flush)(priv->driDrawable); #endif /* Old servers don't send invalidate events */ @@ -586,10 +590,11 @@ dri2InvalidateBuffers(Display *dpy, XID drawable) __GLXDRIdrawable *pdraw = dri2GetGlxDrawableFromXDrawableId(dpy, drawable); struct dri2_screen *psc = (struct dri2_screen *) pdraw->psc; + struct dri2_drawable *pdp = (struct dri2_drawable *) pdraw; #if __DRI2_FLUSH_VERSION >= 3 if (pdraw && psc->f) - psc->f->invalidate(pdraw->driDrawable); + psc->f->invalidate(pdp->driDrawable); #endif } @@ -599,11 +604,12 @@ dri2_bind_tex_image(Display * dpy, int buffer, const int *attrib_list) { GLXContext gc = __glXGetCurrentContext(); - __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL); - __GLXdisplayPrivate *dpyPriv = __glXInitialize(dpy); - struct dri2_display *pdp = - (struct dri2_display *) dpyPriv->dri2Display; - struct dri2_screen *psc = (struct dri2_screen *) pdraw->psc; + __GLXDRIdrawable *base = GetGLXDRIDrawable(dpy, drawable, NULL); + __GLXdisplayPrivate *dpyPriv = __glXInitialize(dpy); + struct dri2_drawable *pdraw = (struct dri2_drawable *) base; + struct dri2_display *pdp = + (struct dri2_display *) dpyPriv->dri2Display; + struct dri2_screen *psc = (struct dri2_screen *) base->psc; if (pdraw != NULL) { @@ -615,13 +621,13 @@ dri2_bind_tex_image(Display * dpy, if (psc->texBuffer->base.version >= 2 && psc->texBuffer->setTexBuffer2 != NULL) { (*psc->texBuffer->setTexBuffer2) (gc->__driContext, - pdraw->textureTarget, - pdraw->textureFormat, + pdraw->base.textureTarget, + pdraw->base.textureFormat, pdraw->driDrawable); } else { (*psc->texBuffer->setTexBuffer) (gc->__driContext, - pdraw->textureTarget, + pdraw->base.textureTarget, pdraw->driDrawable); } } diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c index 373f9fb649..d3facca843 100644 --- a/src/glx/dri_glx.c +++ b/src/glx/dri_glx.c @@ -82,6 +82,13 @@ struct dri_context __GLXscreenConfigs *psc; }; +struct dri_drawable +{ + __GLXDRIdrawable base; + + __DRIdrawable *driDrawable; +}; + /* * Given a display pointer and screen number, determine the name of * the DRI driver for the screen. (I.e. "r128", "tdfx", etc). @@ -506,9 +513,11 @@ driBindContext(__GLXDRIcontext *context, { struct dri_context *pcp = (struct dri_context *) context; struct dri_screen *psc = (struct dri_screen *) pcp->psc; + struct dri_drawable *pdr = (struct dri_drawable *) draw; + struct dri_drawable *prd = (struct dri_drawable *) read; return (*psc->core->bindContext) (pcp->driContext, - draw->driDrawable, read->driDrawable); + pdr->driDrawable, prd->driDrawable); } static void @@ -572,8 +581,9 @@ static void driDestroyDrawable(__GLXDRIdrawable * pdraw) { struct dri_screen *psc = (struct dri_screen *) pdraw->psc; + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; - (*psc->core->destroyDrawable) (pdraw->driDrawable); + (*psc->core->destroyDrawable) (pdp->driDrawable); XF86DRIDestroyDrawable(psc->base.dpy, psc->base.scr, pdraw->drawable); Xfree(pdraw); } @@ -583,46 +593,46 @@ driCreateDrawable(__GLXscreenConfigs *base, XID xDrawable, GLXDrawable drawable, const __GLcontextModes * modes) { - __GLXDRIdrawable *pdraw; drm_drawable_t hwDrawable; void *empty_attribute_list = NULL; __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes; struct dri_screen *psc = (struct dri_screen *) base; + struct dri_drawable *pdp; /* Old dri can't handle GLX 1.3+ drawable constructors. */ if (xDrawable != drawable) return NULL; - pdraw = Xmalloc(sizeof(*pdraw)); - if (!pdraw) + pdp = Xmalloc(sizeof *pdp); + if (!pdp) return NULL; - pdraw->drawable = drawable; - pdraw->psc = &psc->base; + pdp->base.drawable = drawable; + pdp->base.psc = &psc->base; if (!XF86DRICreateDrawable(psc->base.dpy, psc->base.scr, drawable, &hwDrawable)) { - Xfree(pdraw); + Xfree(pdp); return NULL; } /* Create a new drawable */ - pdraw->driDrawable = + pdp->driDrawable = (*psc->legacy->createNewDrawable) (psc->driScreen, config->driConfig, hwDrawable, GLX_WINDOW_BIT, - empty_attribute_list, pdraw); + empty_attribute_list, pdp); - if (!pdraw->driDrawable) { + if (!pdp->driDrawable) { XF86DRIDestroyDrawable(psc->base.dpy, psc->base.scr, drawable); - Xfree(pdraw); + Xfree(pdp); return NULL; } - pdraw->destroyDrawable = driDestroyDrawable; + pdp->base.destroyDrawable = driDestroyDrawable; - return pdraw; + return &pdp->base; } static int64_t @@ -630,8 +640,9 @@ driSwapBuffers(__GLXDRIdrawable * pdraw, int64_t unused1, int64_t unused2, int64_t unused3) { struct dri_screen *psc = (struct dri_screen *) pdraw->psc; + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; - (*psc->core->swapBuffers) (pdraw->driDrawable); + (*psc->core->swapBuffers) (pdp->driDrawable); return 0; } @@ -639,8 +650,10 @@ static void driCopySubBuffer(__GLXDRIdrawable * pdraw, int x, int y, int width, int height) { - (*pdraw->psc->driCopySubBuffer->copySubBuffer) (pdraw->driDrawable, - x, y, width, height); + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; + + (*pdp->base.psc->driCopySubBuffer->copySubBuffer) (pdp->driDrawable, + x, y, width, height); } static void @@ -668,10 +681,11 @@ driDrawableGetMSC(__GLXscreenConfigs *base, __GLXDRIdrawable *pdraw, int64_t *ust, int64_t *msc, int64_t *sbc) { struct dri_screen *psc = (struct dri_screen *) base; + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; - if (pdraw && psc->sbc && psc->msc) + if (pdp && psc->sbc && psc->msc) return ( (*psc->msc->getMSC)(psc->driScreen, msc) == 0 && - (*psc->sbc->getSBC)(pdraw->driDrawable, sbc) == 0 && + (*psc->sbc->getSBC)(pdp->driDrawable, sbc) == 0 && __glXGetUST(ust) == 0 ); } @@ -680,9 +694,10 @@ driWaitForMSC(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc) { struct dri_screen *psc = (struct dri_screen *) pdraw->psc; + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; - if (pdraw != NULL && psc->msc != NULL) { - ret = (*psc->msc->waitForMSC) (pdraw->driDrawable, target_msc, + if (pdp != NULL && psc->msc != NULL) { + ret = (*psc->msc->waitForMSC) (pdp->driDrawable, target_msc, divisor, remainder, msc, sbc); /* __glXGetUST returns zero on success and non-zero on failure. @@ -696,9 +711,11 @@ static int driWaitForSBC(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust, int64_t *msc, int64_t *sbc) { - if (pdraw != NULL && psc->sbc != NULL) { + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; + + if (pdp != NULL && psc->sbc != NULL) { ret = - (*psc->sbc->waitForSBC) (pdraw->driDrawable, target_sbc, msc, sbc); + (*psc->sbc->waitForSBC) (pdp->driDrawable, target_sbc, msc, sbc); /* __glXGetUST returns zero on success and non-zero on failure. * This function returns True on success and False on failure. @@ -706,8 +723,8 @@ driWaitForSBC(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust, return ((ret == 0) && (__glXGetUST(ust) == 0)); } - return DRI2WaitSBC(pdraw->psc->dpy, pdraw->xDrawable, target_sbc, ust, msc, - sbc); + return DRI2WaitSBC(pdp->base.psc->dpy, + pdp->base.xDrawable, target_sbc, ust, msc, sbc); } #endif @@ -716,13 +733,14 @@ static int driSetSwapInterval(__GLXDRIdrawable *pdraw, int interval) { GLXContext gc = __glXGetCurrentContext(); + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; struct dri_screen *psc; if (gc->driContext) { psc = (struct dri_screen *) pdraw->psc; if (psc->swapControl != NULL && pdraw != NULL) { - psc->swapControl->setSwapInterval(pdraw->driDrawable, interval); + psc->swapControl->setSwapInterval(pdp->driDrawable, interval); return 0; } } @@ -734,13 +752,14 @@ static int driGetSwapInterval(__GLXDRIdrawable *pdraw) { GLXContext gc = __glXGetCurrentContext(); + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; struct dri_screen *psc; if (gc != NULL && gc->driContext) { psc = (struct dri_screen *) pdraw->psc; if (psc->swapControl != NULL && pdraw != NULL) { - return psc->swapControl->getSwapInterval(pdraw->driDrawable); + return psc->swapControl->getSwapInterval(pdp->driDrawable); } } diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index e9a88e6db0..0ea846b691 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -58,6 +58,7 @@ struct drisw_drawable GC gc; GC swapgc; + __DRIdrawable *driDrawable; XVisualInfo *visinfo; XImage *ximage; }; @@ -253,9 +254,11 @@ driBindContext(__GLXDRIcontext * context, { struct drisw_context *pcp = (struct drisw_context *) context; struct drisw_screen *psc = (struct drisw_screen *) pcp->psc; + struct drisw_drawable *pdr = (struct drisw_drawable *) draw; + struct drisw_drawable *prd = (struct drisw_drawable *) read; return (*psc->core->bindContext) (pcp->driContext, - draw->driDrawable, read->driDrawable); + pdr->driDrawable, prd->driDrawable); } static void @@ -311,7 +314,7 @@ driDestroyDrawable(__GLXDRIdrawable * pdraw) struct drisw_drawable *pdp = (struct drisw_drawable *) pdraw; struct drisw_screen *psc = (struct drisw_screen *) pdp->base.psc; - (*psc->core->destroyDrawable) (pdraw->driDrawable); + (*psc->core->destroyDrawable) (pdp->driDrawable); XDestroyDrawable(pdp, pdraw->psc->dpy, pdraw->drawable); Xfree(pdp); @@ -321,7 +324,6 @@ static __GLXDRIdrawable * driCreateDrawable(__GLXscreenConfigs *base, XID xDrawable, GLXDrawable drawable, const __GLcontextModes * modes) { - __GLXDRIdrawable *pdraw; struct drisw_drawable *pdp; __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes; struct drisw_screen *psc = (struct drisw_screen *) base; @@ -336,27 +338,25 @@ driCreateDrawable(__GLXscreenConfigs *base, XID xDrawable, if (!pdp) return NULL; - pdraw = &(pdp->base); - pdraw->xDrawable = xDrawable; - pdraw->drawable = drawable; - pdraw->psc = &psc->base; + pdp->base.xDrawable = xDrawable; + pdp->base.drawable = drawable; + pdp->base.psc = &psc->base; XCreateDrawable(pdp, psc->base.dpy, xDrawable, modes->visualID); /* Create a new drawable */ - pdraw->driDrawable = - (*swrast->createNewDrawable) (psc->driScreen, - config->driConfig, pdp); + pdp->driDrawable = + (*swrast->createNewDrawable) (psc->driScreen, config->driConfig, pdp); - if (!pdraw->driDrawable) { + if (!pdp->driDrawable) { XDestroyDrawable(pdp, psc->base.dpy, xDrawable); Xfree(pdp); return NULL; } - pdraw->destroyDrawable = driDestroyDrawable; + pdp->base.destroyDrawable = driDestroyDrawable; - return pdraw; + return &pdp->base; } static int64_t @@ -370,7 +370,7 @@ driSwapBuffers(__GLXDRIdrawable * pdraw, (void) divisor; (void) remainder; - (*psc->core->swapBuffers) (pdraw->driDrawable); + (*psc->core->swapBuffers) (pdp->driDrawable); return 0; } diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h index 4ce99050b3..65dc26b3fc 100644 --- a/src/glx/glxclient.h +++ b/src/glx/glxclient.h @@ -173,7 +173,6 @@ struct __GLXDRIdrawableRec XID drawable; __GLXscreenConfigs *psc; GLenum textureTarget; - __DRIdrawable *driDrawable; GLenum textureFormat; /* EXT_texture_from_pixmap support */ unsigned long eventMask; }; diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index f51df7bca1..a75226a657 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -2481,7 +2481,7 @@ __glXGetMscRateOML(Display * dpy, GLXDrawable drawable, if (draw == NULL) return False; - return __driGetMscRateOML(draw->driDrawable, numerator, denominator, draw); + return __driGetMscRateOML(NULL, numerator, denominator, draw); #else (void) dpy; (void) drawable; -- cgit v1.2.3 From bab13969d8bf3ff9259524c3f4ab96d81485ccef Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Mon, 19 Jul 2010 22:12:22 -0400 Subject: glx: Move driver_configs to DRI screen privates --- src/glx/dri2_glx.c | 4 +++- src/glx/dri_common.c | 10 ++++++++++ src/glx/dri_common.h | 2 ++ src/glx/dri_glx.c | 4 +++- src/glx/drisw_glx.c | 5 ++++- src/glx/glxclient.h | 2 -- src/glx/glxext.c | 7 ------- 7 files changed, 22 insertions(+), 12 deletions(-) (limited to 'src/glx/drisw_glx.c') diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index 6ac03cf0cf..df7ad477ff 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -86,6 +86,7 @@ struct dri2_screen { const __DRI2flushExtension *f; const __DRI2configQueryExtension *config; const __DRItexBufferExtension *texBuffer; + const __DRIconfig **driver_configs; void *driver; int fd; @@ -428,6 +429,7 @@ dri2DestroyScreen(__GLXscreenConfigs *base) /* Free the direct rendering per screen data */ (*psc->core->destroyScreen) (psc->driScreen); + driDestroyConfigs(psc->driver_configs); close(psc->fd); Xfree(psc); } @@ -785,7 +787,7 @@ dri2CreateScreen(int screen, __GLXdisplayPrivate * priv) psc->base.visuals = driConvertConfigs(psc->core, psc->base.visuals, driver_configs); - psc->base.driver_configs = driver_configs; + psc->driver_configs = driver_configs; psp = &psc->vtable; psc->base.driScreen = psp; diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c index b1d9f32021..796654a65d 100644 --- a/src/glx/dri_common.c +++ b/src/glx/dri_common.c @@ -336,6 +336,16 @@ driConvertConfigs(const __DRIcoreExtension * core, return head.next; } +_X_HIDDEN void +driDestroyConfigs(const __DRIconfig **configs) +{ + int i; + + for (i = 0; configs[i]; i++) + free((__DRIconfig *) configs[i]); + free(configs); +} + /* Bind extensions common to DRI1 and DRI2 */ _X_HIDDEN void driBindCommonExtensions(__GLXscreenConfigs *psc, diff --git a/src/glx/dri_common.h b/src/glx/dri_common.h index 7ed7767c92..509ddab8ed 100644 --- a/src/glx/dri_common.h +++ b/src/glx/dri_common.h @@ -48,6 +48,8 @@ extern __GLcontextModes *driConvertConfigs(const __DRIcoreExtension * core, __GLcontextModes * modes, const __DRIconfig ** configs); +extern void driDestroyConfigs(const __DRIconfig **configs); + extern const __DRIsystemTimeExtension systemTimeExtension; extern void InfoMessageF(const char *f, ...); diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c index d3facca843..aba7b1b844 100644 --- a/src/glx/dri_glx.c +++ b/src/glx/dri_glx.c @@ -69,6 +69,7 @@ struct dri_screen const __DRIcoreExtension *core; const __DRIswapControlExtension *swapControl; const __DRImediaStreamCounterExtension *msc; + const __DRIconfig **driver_configs; void *driver; int fd; @@ -448,7 +449,7 @@ CallCreateNewScreen(Display *dpy, int scrn, struct dri_screen *psc, psc->base.visuals = driConvertConfigs(psc->core, psc->base.visuals, driver_configs); - psc->base.driver_configs = driver_configs; + psc->driver_configs = driver_configs; /* Visuals with depth != screen depth are subject to automatic compositing * in the X server, so DRI1 can't render to them properly. Mark them as @@ -664,6 +665,7 @@ driDestroyScreen(__GLXscreenConfigs *base) /* Free the direct rendering per screen data */ if (psc->driScreen) (*psc->core->destroyScreen) (psc->driScreen); + driDestroyConfigs(psc->driver_configs); psc->driScreen = NULL; if (psc->driver) dlclose(psc->driver); diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index 0ea846b691..94866269c4 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -48,6 +48,8 @@ struct drisw_screen __GLXDRIscreen vtable; const __DRIcoreExtension *core; const __DRIswrastExtension *swrast; + const __DRIconfig **driver_configs; + void *driver; }; @@ -382,6 +384,7 @@ driDestroyScreen(__GLXscreenConfigs *base) /* Free the direct rendering per screen data */ (*psc->core->destroyScreen) (psc->driScreen); + driDestroyConfigs(psc->driver_configs); psc->driScreen = NULL; if (psc->driver) dlclose(psc->driver); @@ -456,7 +459,7 @@ driCreateScreen(int screen, __GLXdisplayPrivate *priv) psc->base.visuals = driConvertConfigs(psc->core, psc->base.visuals, driver_configs); - psc->base.driver_configs = driver_configs; + psc->driver_configs = driver_configs; psp = &psc->vtable; psc->base.driScreen = psp; diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h index adfa3ce1b6..c6c02aee1e 100644 --- a/src/glx/glxclient.h +++ b/src/glx/glxclient.h @@ -534,8 +534,6 @@ struct __GLXscreenConfigsRec __GLXDRIscreen *driScreen; - const __DRIconfig **driver_configs; - #ifdef __DRI_COPY_SUB_BUFFER const __DRIcopySubBufferExtension *driCopySubBuffer; #endif diff --git a/src/glx/glxext.c b/src/glx/glxext.c index 65aacc5887..9c3c7a4840 100644 --- a/src/glx/glxext.c +++ b/src/glx/glxext.c @@ -260,13 +260,6 @@ FreeScreenConfigs(__GLXdisplayPrivate * priv) Xfree((char *) psc->serverGLXexts); #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) - if (psc->driver_configs) { - unsigned int j; - for (j = 0; psc->driver_configs[j]; j++) - free((__DRIconfig *) psc->driver_configs[j]); - free(psc->driver_configs); - psc->driver_configs = NULL; - } if (psc->driScreen) { psc->driScreen->destroyScreen(psc); psc->driScreen = NULL; -- cgit v1.2.3 From a7292f2920a28a190ca39ce530454a852ec36d59 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Mon, 19 Jul 2010 22:40:22 -0400 Subject: glx: Move DRI CopySubBuffer extension to DRI1 code We do this in the X server for DRI2. --- src/glx/dri2_glx.c | 2 +- src/glx/dri_common.c | 25 ------------------------- src/glx/dri_common.h | 3 --- src/glx/dri_glx.c | 17 +++++++++++++---- src/glx/drisw_glx.c | 1 - src/glx/glxclient.h | 5 ----- 6 files changed, 14 insertions(+), 39 deletions(-) (limited to 'src/glx/drisw_glx.c') diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index df7ad477ff..4fbe9496b1 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -675,6 +675,7 @@ dri2BindExtensions(struct dri2_screen *psc, const __DRIextension **extensions) __glXEnableDirectExtension(&psc->base, "GLX_SGI_video_sync"); __glXEnableDirectExtension(&psc->base, "GLX_SGI_swap_control"); __glXEnableDirectExtension(&psc->base, "GLX_MESA_swap_control"); + __glXEnableDirectExtension(&psc->base, "GLX_SGI_make_current_read"); /* FIXME: if DRI2 version supports it... */ __glXEnableDirectExtension(&psc->base, "INTEL_swap_event"); @@ -779,7 +780,6 @@ dri2CreateScreen(int screen, __GLXdisplayPrivate * priv) } extensions = psc->core->getExtensions(psc->driScreen); - driBindCommonExtensions(&psc->base, extensions); dri2BindExtensions(psc, extensions); psc->base.configs = diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c index 796654a65d..eb9f1e4b39 100644 --- a/src/glx/dri_common.c +++ b/src/glx/dri_common.c @@ -346,29 +346,4 @@ driDestroyConfigs(const __DRIconfig **configs) free(configs); } -/* Bind extensions common to DRI1 and DRI2 */ -_X_HIDDEN void -driBindCommonExtensions(__GLXscreenConfigs *psc, - const __DRIextension **extensions) -{ - int i; - - for (i = 0; extensions[i]; i++) { -#ifdef __DRI_COPY_SUB_BUFFER - if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) { - psc->driCopySubBuffer = (__DRIcopySubBufferExtension *) extensions[i]; - __glXEnableDirectExtension(psc, "GLX_MESA_copy_sub_buffer"); - } -#endif - -#ifdef __DRI_READ_DRAWABLE - if (strcmp(extensions[i]->name, __DRI_READ_DRAWABLE) == 0) { - __glXEnableDirectExtension(psc, "GLX_SGI_make_current_read"); - } -#endif - - /* Ignore unknown extensions */ - } -} - #endif /* GLX_DIRECT_RENDERING */ diff --git a/src/glx/dri_common.h b/src/glx/dri_common.h index 509ddab8ed..44104969e2 100644 --- a/src/glx/dri_common.h +++ b/src/glx/dri_common.h @@ -58,7 +58,4 @@ extern void ErrorMessageF(const char *f, ...); extern void *driOpenDriver(const char *driverName); -extern void driBindCommonExtensions(__GLXscreenConfigs * psc, - const __DRIextension **extensions); - #endif /* _DRI_COMMON_H */ diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c index aba7b1b844..369d07a27f 100644 --- a/src/glx/dri_glx.c +++ b/src/glx/dri_glx.c @@ -70,6 +70,7 @@ struct dri_screen const __DRIswapControlExtension *swapControl; const __DRImediaStreamCounterExtension *msc; const __DRIconfig **driver_configs; + const __DRIcopySubBufferExtension *driCopySubBuffer; void *driver; int fd; @@ -652,9 +653,10 @@ driCopySubBuffer(__GLXDRIdrawable * pdraw, int x, int y, int width, int height) { struct dri_drawable *pdp = (struct dri_drawable *) pdraw; + struct dri_screen *psc = (struct dri_screen *) pdp->base.psc; - (*pdp->base.psc->driCopySubBuffer->copySubBuffer) (pdp->driDrawable, - x, y, width, height); + (*psc->driCopySubBuffer->copySubBuffer) (pdp->driDrawable, + x, y, width, height); } static void @@ -788,6 +790,14 @@ driBindExtensions(struct dri_screen *psc, const __DRIextension **extensions) __glXEnableDirectExtension(&psc->base, "GLX_SGI_video_sync"); } + if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) { + psc->driCopySubBuffer = (__DRIcopySubBufferExtension *) extensions[i]; + __glXEnableDirectExtension(&psc->base, "GLX_MESA_copy_sub_buffer"); + } + + if (strcmp(extensions[i]->name, __DRI_READ_DRAWABLE) == 0) { + __glXEnableDirectExtension(&psc->base, "GLX_SGI_make_current_read"); + } /* Ignore unknown extensions */ } } @@ -852,11 +862,10 @@ driCreateScreen(int screen, __GLXdisplayPrivate *priv) extensions = psc->core->getExtensions(psc->driScreen); driBindExtensions(psc, extensions); - driBindCommonExtensions(&psc->base, extensions); psp = &psc->vtable; psc->base.driScreen = psp; - if (psc->base.driCopySubBuffer) + if (psc->driCopySubBuffer) psp->copySubBuffer = driCopySubBuffer; psp->destroyScreen = driDestroyScreen; diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index 94866269c4..441606106e 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -452,7 +452,6 @@ driCreateScreen(int screen, __GLXdisplayPrivate *priv) } extensions = psc->core->getExtensions(psc->driScreen); - driBindCommonExtensions(&psc->base, extensions); psc->base.configs = driConvertConfigs(psc->core, psc->base.configs, driver_configs); diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h index c6c02aee1e..31d2beb5d4 100644 --- a/src/glx/glxclient.h +++ b/src/glx/glxclient.h @@ -533,11 +533,6 @@ struct __GLXscreenConfigsRec int scr; __GLXDRIscreen *driScreen; - -#ifdef __DRI_COPY_SUB_BUFFER - const __DRIcopySubBufferExtension *driCopySubBuffer; -#endif - #endif /** -- cgit v1.2.3 From 31819830b66a49f1b62e09090cc65aefc657aeb8 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Thu, 22 Jul 2010 21:24:14 -0400 Subject: glx: Allocate the __GLXcontext in the DRI drivers --- src/glx/dri2_glx.c | 40 +++++++++++-------- src/glx/dri_glx.c | 43 +++++++++++--------- src/glx/drisw_glx.c | 30 ++++++++------ src/glx/glxclient.h | 31 ++++++--------- src/glx/glxcmds.c | 108 +++++++++++++++++++++++++++------------------------ src/glx/glxcurrent.c | 8 ++-- 6 files changed, 136 insertions(+), 124 deletions(-) (limited to 'src/glx/drisw_glx.c') diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index 6ce5ae6fc9..778607dd1c 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -94,9 +94,9 @@ struct dri2_screen { struct dri2_context { - __GLXDRIcontext base; + __GLXcontext base; + __GLXDRIcontext dri_vtable; __DRIcontext *driContext; - __GLXscreenConfigs *psc; }; struct dri2_drawable @@ -111,12 +111,13 @@ struct dri2_drawable int swap_interval; }; +static const struct glx_context_vtable dri2_context_vtable; + static void -dri2DestroyContext(__GLXDRIcontext *context, - __GLXscreenConfigs *base, Display *dpy) +dri2DestroyContext(__GLXcontext *context) { struct dri2_context *pcp = (struct dri2_context *) context; - struct dri2_screen *psc = (struct dri2_screen *) base; + struct dri2_screen *psc = (struct dri2_screen *) context->psc; (*psc->core->destroyContext) (pcp->driContext); @@ -124,11 +125,11 @@ dri2DestroyContext(__GLXDRIcontext *context, } static Bool -dri2BindContext(__GLXDRIcontext *context, +dri2BindContext(__GLXcontext *context, __GLXDRIdrawable *draw, __GLXDRIdrawable *read) { struct dri2_context *pcp = (struct dri2_context *) context; - struct dri2_screen *psc = (struct dri2_screen *) pcp->psc; + struct dri2_screen *psc = (struct dri2_screen *) pcp->base.psc; struct dri2_drawable *pdr = (struct dri2_drawable *) draw; struct dri2_drawable *prd = (struct dri2_drawable *) read; @@ -137,18 +138,18 @@ dri2BindContext(__GLXDRIcontext *context, } static void -dri2UnbindContext(__GLXDRIcontext *context) +dri2UnbindContext(__GLXcontext *context) { struct dri2_context *pcp = (struct dri2_context *) context; - struct dri2_screen *psc = (struct dri2_screen *) pcp->psc; + struct dri2_screen *psc = (struct dri2_screen *) pcp->base.psc; (*psc->core->unbindContext) (pcp->driContext); } -static __GLXDRIcontext * +static __GLXcontext * dri2CreateContext(__GLXscreenConfigs *base, const __GLcontextModes * mode, - GLXContext gc, GLXContext shareList, int renderType) + GLXContext shareList, int renderType) { struct dri2_context *pcp, *pcp_shared; struct dri2_screen *psc = (struct dri2_screen *) base; @@ -164,7 +165,12 @@ dri2CreateContext(__GLXscreenConfigs *base, if (pcp == NULL) return NULL; - pcp->psc = &psc->base; + memset(pcp, 0, sizeof *pcp); + if (!glx_context_init(&pcp->base, &psc->base, mode)) { + Xfree(pcp); + return NULL; + } + pcp->driContext = (*psc->dri2->createNewContext) (psc->driScreen, config->driConfig, shared, pcp); @@ -174,9 +180,11 @@ dri2CreateContext(__GLXscreenConfigs *base, return NULL; } - pcp->base.destroyContext = dri2DestroyContext; - pcp->base.bindContext = dri2BindContext; - pcp->base.unbindContext = dri2UnbindContext; + pcp->base.vtable = &dri2_context_vtable; + pcp->base.driContext = &pcp->dri_vtable; + pcp->dri_vtable.destroyContext = dri2DestroyContext; + pcp->dri_vtable.bindContext = dri2BindContext; + pcp->dri_vtable.unbindContext = dri2UnbindContext; return &pcp->base; } @@ -826,8 +834,6 @@ dri2CreateScreen(int screen, __GLXdisplayPrivate * priv) psp->copySubBuffer = dri2CopySubBuffer; __glXEnableDirectExtension(&psc->base, "GLX_MESA_copy_sub_buffer"); - psc->base.direct_context_vtable = &dri2_context_vtable; - Xfree(driverName); Xfree(deviceName); diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c index 369d07a27f..959fc7425a 100644 --- a/src/glx/dri_glx.c +++ b/src/glx/dri_glx.c @@ -78,7 +78,8 @@ struct dri_screen struct dri_context { - __GLXDRIcontext base; + __GLXcontext base; + __GLXDRIcontext dri_vtable; __DRIcontext *driContext; XID hwContextID; __GLXscreenConfigs *psc; @@ -91,6 +92,11 @@ struct dri_drawable __DRIdrawable *driDrawable; }; +static const struct glx_context_vtable dri_context_vtable = { + NULL, + NULL, +}; + /* * Given a display pointer and screen number, determine the name of * the DRI driver for the screen. (I.e. "r128", "tdfx", etc). @@ -497,11 +503,10 @@ CallCreateNewScreen(Display *dpy, int scrn, struct dri_screen *psc, } static void -driDestroyContext(__GLXDRIcontext * context, - __GLXscreenConfigs *base, Display * dpy) +driDestroyContext(__GLXcontext * context) { struct dri_context *pcp = (struct dri_context *) context; - struct dri_screen *psc = (struct dri_screen *) base; + struct dri_screen *psc = (struct dri_screen *) context->psc; (*psc->core->destroyContext) (pcp->driContext); @@ -510,7 +515,7 @@ driDestroyContext(__GLXDRIcontext * context, } static Bool -driBindContext(__GLXDRIcontext *context, +driBindContext(__GLXcontext *context, __GLXDRIdrawable *draw, __GLXDRIdrawable *read) { struct dri_context *pcp = (struct dri_context *) context; @@ -523,7 +528,7 @@ driBindContext(__GLXDRIcontext *context, } static void -driUnbindContext(__GLXDRIcontext * context) +driUnbindContext(__GLXcontext * context) { struct dri_context *pcp = (struct dri_context *) context; struct dri_screen *psc = (struct dri_screen *) pcp->psc; @@ -531,10 +536,10 @@ driUnbindContext(__GLXDRIcontext * context) (*psc->core->unbindContext) (pcp->driContext); } -static __GLXDRIcontext * +static __GLXcontext * driCreateContext(__GLXscreenConfigs *base, const __GLcontextModes * mode, - GLXContext gc, GLXContext shareList, int renderType) + GLXContext shareList, int renderType) { struct dri_context *pcp, *pcp_shared; struct dri_screen *psc = (struct dri_screen *) base; @@ -554,7 +559,12 @@ driCreateContext(__GLXscreenConfigs *base, if (pcp == NULL) return NULL; - pcp->psc = &psc->base; + memset(pcp, 0, sizeof *pcp); + if (!glx_context_init(&pcp->base, &psc->base, mode)) { + Xfree(pcp); + return NULL; + } + if (!XF86DRICreateContextWithConfig(psc->base.dpy, psc->base.scr, mode->visualID, &pcp->hwContextID, &hwContext)) { @@ -572,9 +582,11 @@ driCreateContext(__GLXscreenConfigs *base, return NULL; } - pcp->base.destroyContext = driDestroyContext; - pcp->base.bindContext = driBindContext; - pcp->base.unbindContext = driUnbindContext; + pcp->base.vtable = &dri_context_vtable; + pcp->base.driContext = &pcp->dri_vtable; + pcp->dri_vtable.destroyContext = driDestroyContext; + pcp->dri_vtable.bindContext = driBindContext; + pcp->dri_vtable.unbindContext = driUnbindContext; return &pcp->base; } @@ -673,11 +685,6 @@ driDestroyScreen(__GLXscreenConfigs *base) dlclose(psc->driver); } -static const struct glx_context_vtable dri_context_vtable = { - NULL, - NULL, -}; - #ifdef __DRI_SWAP_BUFFER_COUNTER static int @@ -884,8 +891,6 @@ driCreateScreen(int screen, __GLXdisplayPrivate *priv) psp->setSwapInterval = driSetSwapInterval; psp->getSwapInterval = driGetSwapInterval; - psc->base.direct_context_vtable = &dri_context_vtable; - return &psc->base; } diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index 441606106e..367aa6a6f2 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -35,7 +35,8 @@ struct drisw_display struct drisw_context { - __GLXDRIcontext base; + __GLXcontext base; + __GLXDRIcontext dri_vtable; __DRIcontext *driContext; __GLXscreenConfigs *psc; }; @@ -239,11 +240,10 @@ static const __DRIextension *loader_extensions[] = { */ static void -driDestroyContext(__GLXDRIcontext *context, - __GLXscreenConfigs *base, Display *dpy) +driDestroyContext(__GLXcontext *context) { struct drisw_context *pcp = (struct drisw_context *) context; - struct drisw_screen *psc = (struct drisw_screen *) base; + struct drisw_screen *psc = (struct drisw_screen *) context->psc; (*psc->core->destroyContext) (pcp->driContext); @@ -251,7 +251,7 @@ driDestroyContext(__GLXDRIcontext *context, } static Bool -driBindContext(__GLXDRIcontext * context, +driBindContext(__GLXcontext * context, __GLXDRIdrawable * draw, __GLXDRIdrawable * read) { struct drisw_context *pcp = (struct drisw_context *) context; @@ -264,7 +264,7 @@ driBindContext(__GLXDRIcontext * context, } static void -driUnbindContext(__GLXDRIcontext * context) +driUnbindContext(__GLXcontext * context) { struct drisw_context *pcp = (struct drisw_context *) context; struct drisw_screen *psc = (struct drisw_screen *) pcp->psc; @@ -272,10 +272,10 @@ driUnbindContext(__GLXDRIcontext * context) (*psc->core->unbindContext) (pcp->driContext); } -static __GLXDRIcontext * +static __GLXcontext * driCreateContext(__GLXscreenConfigs *base, const __GLcontextModes *mode, - GLXContext gc, GLXContext shareList, int renderType) + GLXContext shareList, int renderType) { struct drisw_context *pcp, *pcp_shared; __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode; @@ -294,7 +294,12 @@ driCreateContext(__GLXscreenConfigs *base, if (pcp == NULL) return NULL; - pcp->psc = &psc->base; + memset(pcp, 0, sizeof *pcp); + if (!glx_context_init(&pcp->base, &psc->base, mode)) { + Xfree(pcp); + return NULL; + } + pcp->driContext = (*psc->core->createNewContext) (psc->driScreen, config->driConfig, shared, pcp); @@ -303,9 +308,10 @@ driCreateContext(__GLXscreenConfigs *base, return NULL; } - pcp->base.destroyContext = driDestroyContext; - pcp->base.bindContext = driBindContext; - pcp->base.unbindContext = driUnbindContext; + pcp->base.driContext = &pcp->dri_vtable; + pcp->dri_vtable.destroyContext = driDestroyContext; + pcp->dri_vtable.bindContext = driBindContext; + pcp->dri_vtable.unbindContext = driUnbindContext; return &pcp->base; } diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h index 4f833057ff..dcb75d4959 100644 --- a/src/glx/glxclient.h +++ b/src/glx/glxclient.h @@ -126,10 +126,9 @@ struct __GLXDRIscreenRec { void (*destroyScreen)(__GLXscreenConfigs *psc); - __GLXDRIcontext *(*createContext)(__GLXscreenConfigs *psc, - const __GLcontextModes *mode, - GLXContext gc, - GLXContext shareList, int renderType); + __GLXcontext *(*createContext)(__GLXscreenConfigs *psc, + const __GLcontextModes *mode, + GLXContext shareList, int renderType); __GLXDRIdrawable *(*createDrawable)(__GLXscreenConfigs *psc, XID drawable, @@ -155,12 +154,10 @@ struct __GLXDRIscreenRec { struct __GLXDRIcontextRec { - void (*destroyContext) (__GLXDRIcontext * context, - __GLXscreenConfigs * psc, Display * dpy); - Bool(*bindContext) (__GLXDRIcontext * context, __GLXDRIdrawable * pdraw, - __GLXDRIdrawable * pread); - - void (*unbindContext) (__GLXDRIcontext * context); + void (*destroyContext) (__GLXcontext *context); + Bool(*bindContext) (__GLXcontext *context, __GLXDRIdrawable *pdraw, + __GLXDRIdrawable *pread); + void (*unbindContext) (__GLXcontext *context); }; struct __GLXDRIdrawableRec @@ -388,11 +385,6 @@ struct __GLXcontextRec GLubyte *extensions; /*@} */ - /** - * Record the dpy this context was created on for later freeing - */ - Display *createDpy; - /** * Maximum small render command size. This is the smaller of 64k and * the size of the above buffer. @@ -463,6 +455,10 @@ struct __GLXcontextRec const struct glx_context_vtable *vtable; }; +extern Bool +glx_context_init(__GLXcontext *gc, + __GLXscreenConfigs *psc, const __GLcontextModes *fbconfig); + #define __glXSetError(gc,code) \ if (!(gc)->error) { \ (gc)->error = code; \ @@ -515,11 +511,6 @@ struct __GLXscreenConfigsRec */ char *effectiveGLXexts; - /** - * Context vtable to use for direct contexts on this screen - */ - const struct glx_context_vtable *direct_context_vtable; - __GLXdisplayPrivate *display; #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index a9f6b17338..5eae5a914d 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -62,7 +62,7 @@ static const char __glXGLXClientVendorName[] = "Mesa Project and SGI"; static const char __glXGLXClientVersion[] = "1.4"; -static const struct glx_context_vtable glx_indirect_context_vtable; +static const struct glx_context_vtable indirect_context_vtable; #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) @@ -272,6 +272,7 @@ AllocateGLXContext(Display * dpy) } memset(gc, 0, sizeof(struct __GLXcontextRec)); + gc->vtable = &indirect_context_vtable; state = Xmalloc(sizeof(struct __GLXattributeRec)); if (state == NULL) { /* Out of memory */ @@ -325,7 +326,6 @@ AllocateGLXContext(Display * dpy) else { gc->limit = gc->buf + bufSize - __GLX_BUFFER_LIMIT_SIZE; } - gc->createDpy = dpy; gc->majorOpcode = opcode; /* @@ -350,6 +350,22 @@ AllocateGLXContext(Display * dpy) return gc; } +_X_HIDDEN Bool +glx_context_init(__GLXcontext *gc, + __GLXscreenConfigs *psc, const __GLcontextModes *fbconfig) +{ + gc->majorOpcode = __glXSetupForCommand(psc->display->dpy); + if (!gc->majorOpcode) + return GL_FALSE; + + gc->screen = psc->scr; + gc->psc = psc; + gc->mode = fbconfig; + gc->isDirect = GL_TRUE; + + return GL_TRUE; +} + /** * Create a new context. Exactly one of \c vis and \c fbconfig should be @@ -367,7 +383,7 @@ CreateContext(Display * dpy, int generic_id, Bool allowDirect, unsigned code, int renderType, int screen) { - GLXContext gc; + GLXContext gc = NULL; __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); #if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_APPLEGL) int errorcode; @@ -380,28 +396,18 @@ CreateContext(Display * dpy, int generic_id, if (generic_id == None) return NULL; - gc = AllocateGLXContext(dpy); - if (!gc) - return NULL; - #ifndef GLX_USE_APPLEGL /* TODO: darwin indirect */ #ifdef GLX_DIRECT_RENDERING if (allowDirect && psc->driScreen) { - gc->driContext = psc->driScreen->createContext(psc, fbconfig, gc, - shareList, renderType); - if (gc->driContext != NULL) { - gc->screen = screen; - gc->psc = psc; - gc->mode = fbconfig; - gc->isDirect = GL_TRUE; - } + gc = psc->driScreen->createContext(psc, fbconfig, + shareList, renderType); } #endif - if (gc->driContext != NULL) - gc->vtable = psc->direct_context_vtable; - else - gc->vtable = &glx_indirect_context_vtable; + if (!gc) + gc = AllocateGLXContext(dpy); + if (!gc) + return NULL; LockDisplay(dpy); switch (code) { @@ -570,54 +576,54 @@ DestroyContext(Display * dpy, GLXContext gc) return; } -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) /* Destroy the direct rendering context */ if (gc->driContext) { - (*gc->driContext->destroyContext) (gc->driContext, gc->psc, dpy); - gc->driContext = NULL; GarbageCollectDRIDrawables(gc->psc); + if (gc->extensions) + XFree((char *) gc->extensions); + (*gc->driContext->destroyContext) (gc); } + else #endif + { + __glXFreeVertexArrayState(gc); + __glXFreeContext(gc); + } + + if (!imported) { + /* + ** This dpy also created the server side part of the context. + ** Send the glXDestroyContext request. + */ + LockDisplay(dpy); + GetReq(GLXDestroyContext, req); + req->reqType = opcode; + req->glxCode = X_GLXDestroyContext; + req->context = xid; + UnlockDisplay(dpy); + SyncHandle(); + } - __glXFreeVertexArrayState(gc); #else - __glXLock(); -#endif /* GLX_USE_APPLEGL */ + __glXLock(); if (gc->currentDpy) { -#ifdef GLX_USE_APPLEGL /* * Set the Bool that indicates that we should destroy this GLX context * when the context is no longer current. */ gc->do_destroy = True; -#endif /* Have to free later cuz it's in use now */ __glXUnlock(); } else { /* Destroy the handle if not current to anybody */ __glXUnlock(); -#ifdef GLX_USE_APPLEGL if(gc->driContext) - apple_glx_destroy_context(&gc->driContext, dpy); -#endif + apple_glx_destroy_context(&gc->driContext, dpy); __glXFreeContext(gc); } -#ifndef GLX_USE_APPLEGL - if (!imported) { - /* - ** This dpy also created the server side part of the context. - ** Send the glXDestroyContext request. - */ - LockDisplay(dpy); - GetReq(GLXDestroyContext, req); - req->reqType = opcode; - req->glxCode = X_GLXDestroyContext; - req->context = xid; - UnlockDisplay(dpy); - SyncHandle(); - } #endif } @@ -2711,9 +2717,9 @@ __glXCopySubBufferMESA(Display * dpy, GLXDrawable drawable, * GLX_EXT_texture_from_pixmap */ static void -glx_indirect_bind_tex_image(Display * dpy, - GLXDrawable drawable, - int buffer, const int *attrib_list) +indirect_bind_tex_image(Display * dpy, + GLXDrawable drawable, + int buffer, const int *attrib_list) { xGLXVendorPrivateReq *req; GLXContext gc = __glXGetCurrentContext(); @@ -2764,7 +2770,7 @@ glx_indirect_bind_tex_image(Display * dpy, } static void -glx_indirect_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer) +indirect_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer) { xGLXVendorPrivateReq *req; GLXContext gc = __glXGetCurrentContext(); @@ -2793,9 +2799,9 @@ glx_indirect_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer) SyncHandle(); } -static const struct glx_context_vtable glx_indirect_context_vtable = { - glx_indirect_bind_tex_image, - glx_indirect_release_tex_image, +static const struct glx_context_vtable indirect_context_vtable = { + indirect_bind_tex_image, + indirect_release_tex_image, }; /*@{*/ diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c index 43469c371c..0bf61779c4 100644 --- a/src/glx/glxcurrent.c +++ b/src/glx/glxcurrent.c @@ -399,7 +399,7 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, } bindReturnValue = - (gc->driContext->bindContext) (gc->driContext, pdraw, pread); + (gc->driContext->bindContext) (gc, pdraw, pread); } else if (!gc && oldGC && oldGC->driContext) { bindReturnValue = True; @@ -441,7 +441,7 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, } #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) else if (oldGC->driContext && oldGC != gc) { - oldGC->driContext->unbindContext(oldGC->driContext); + oldGC->driContext->unbindContext(oldGC); } #endif @@ -488,9 +488,7 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) /* Destroy the old direct rendering context */ if (oldGC->driContext) { - oldGC->driContext->destroyContext(oldGC->driContext, - oldGC->psc, - oldGC->createDpy); + oldGC->driContext->destroyContext(oldGC); oldGC->driContext = NULL; } #endif -- cgit v1.2.3 From 7b7845a076c933e096ac511b4184141ba194449a Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Thu, 22 Jul 2010 22:24:00 -0400 Subject: glx: Move WaitGL, WaitX, UseXFont to context vtable functions --- src/glx/dri2_glx.c | 21 ++++---- src/glx/dri_glx.c | 5 +- src/glx/drisw_glx.c | 11 +++- src/glx/glxclient.h | 9 ++-- src/glx/glxcmds.c | 148 +++++++++++++++++++++++----------------------------- src/glx/xfont.c | 4 +- 6 files changed, 97 insertions(+), 101 deletions(-) (limited to 'src/glx/drisw_glx.c') diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index 778607dd1c..aa01203c61 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -394,22 +394,24 @@ dri2_copy_drawable(struct dri2_drawable *priv, int dest, int src) } static void -dri2WaitX(__GLXDRIdrawable *pdraw) +dri2_wait_x(__GLXcontext *gc) { - struct dri2_drawable *priv = (struct dri2_drawable *) pdraw; + struct dri2_drawable *priv = (struct dri2_drawable *) + GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); - if (!priv->have_fake_front) + if (priv == NULL || !priv->have_fake_front) return; dri2_copy_drawable(priv, DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft); } static void -dri2WaitGL(__GLXDRIdrawable * pdraw) +dri2_wait_gl(__GLXcontext *gc) { - struct dri2_drawable *priv = (struct dri2_drawable *) pdraw; + struct dri2_drawable *priv = (struct dri2_drawable *) + GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL); - if (!priv->have_fake_front) + if (priv == NULL || !priv->have_fake_front) return; dri2_copy_drawable(priv, DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft); @@ -426,7 +428,7 @@ dri2FlushFrontBuffer(__DRIdrawable *driDrawable, void *loaderPrivate) if (!pdp->invalidateAvailable) dri2InvalidateBuffers(priv->dpy, pdraw->base.drawable); - dri2WaitGL(loaderPrivate); + dri2_copy_drawable(pdraw, DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft); } @@ -672,6 +674,9 @@ dri2_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer) } static const struct glx_context_vtable dri2_context_vtable = { + dri2_wait_gl, + dri2_wait_x, + DRI_glXUseXFont, dri2_bind_tex_image, dri2_release_tex_image, }; @@ -804,8 +809,6 @@ dri2CreateScreen(int screen, __GLXdisplayPrivate * priv) psp->createContext = dri2CreateContext; psp->createDrawable = dri2CreateDrawable; psp->swapBuffers = dri2SwapBuffers; - psp->waitGL = dri2WaitGL; - psp->waitX = dri2WaitX; psp->getDrawableMSC = NULL; psp->waitForMSC = NULL; psp->waitForSBC = NULL; diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c index 959fc7425a..352d833fd7 100644 --- a/src/glx/dri_glx.c +++ b/src/glx/dri_glx.c @@ -95,6 +95,9 @@ struct dri_drawable static const struct glx_context_vtable dri_context_vtable = { NULL, NULL, + DRI_glXUseXFont, + NULL, + NULL, }; /* @@ -879,8 +882,6 @@ driCreateScreen(int screen, __GLXdisplayPrivate *priv) psp->createContext = driCreateContext; psp->createDrawable = driCreateDrawable; psp->swapBuffers = driSwapBuffers; - psp->waitX = NULL; - psp->waitGL = NULL; #ifdef __DRI_SWAP_BUFFER_COUNTER psp->getDrawableMSC = driDrawableGetMSC; diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index 367aa6a6f2..0ad7391457 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -272,6 +272,14 @@ driUnbindContext(__GLXcontext * context) (*psc->core->unbindContext) (pcp->driContext); } +static const struct glx_context_vtable drisw_context_vtable = { + NULL, + NULL, + DRI_glXUseXFont, + NULL, + NULL, +}; + static __GLXcontext * driCreateContext(__GLXscreenConfigs *base, const __GLcontextModes *mode, @@ -308,6 +316,7 @@ driCreateContext(__GLXscreenConfigs *base, return NULL; } + pcp->base.vtable = &drisw_context_vtable; pcp->base.driContext = &pcp->dri_vtable; pcp->dri_vtable.destroyContext = driDestroyContext; pcp->dri_vtable.bindContext = driBindContext; @@ -472,8 +481,6 @@ driCreateScreen(int screen, __GLXdisplayPrivate *priv) psp->createContext = driCreateContext; psp->createDrawable = driCreateDrawable; psp->swapBuffers = driSwapBuffers; - psp->waitX = NULL; - psp->waitGL = NULL; return &psc->base; diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h index dcb75d4959..581db97a6e 100644 --- a/src/glx/glxclient.h +++ b/src/glx/glxclient.h @@ -95,7 +95,8 @@ typedef struct _glapi_table __GLapi; #define containerOf(ptr, type, member) \ (type *)( (char *)ptr - offsetof(type,member) ) -extern void DRI_glXUseXFont(Font font, int first, int count, int listbase); +extern void DRI_glXUseXFont(GLXContext CC, + Font font, int first, int count, int listbase); #endif @@ -139,8 +140,6 @@ struct __GLXDRIscreenRec { int64_t divisor, int64_t remainder); void (*copySubBuffer)(__GLXDRIdrawable *pdraw, int x, int y, int width, int height); - void (*waitX)(__GLXDRIdrawable *pdraw); - void (*waitGL)(__GLXDRIdrawable *pdraw); int (*getDrawableMSC)(__GLXscreenConfigs *psc, __GLXDRIdrawable *pdraw, int64_t *ust, int64_t *msc, int64_t *sbc); int (*waitForMSC)(__GLXDRIdrawable *pdraw, int64_t target_msc, @@ -242,6 +241,10 @@ typedef struct __GLXattributeMachineRec } __GLXattributeMachine; struct glx_context_vtable { + void (*wait_gl)(__GLXcontext *ctx); + void (*wait_x)(__GLXcontext *ctx); + void (*use_x_font)(__GLXcontext *ctx, + Font font, int first, int count, int listBase); void (*bind_tex_image)(Display * dpy, GLXDrawable drawable, int buffer, const int *attrib_list); diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 5eae5a914d..eef2b621ba 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -672,42 +672,14 @@ glXQueryExtension(Display * dpy, int *errorBase, int *eventBase) return rv; } -/* -** Put a barrier in the token stream that forces the GL to finish its -** work before X can proceed. -*/ -PUBLIC void -glXWaitGL(void) +static void +indirect_wait_gl(__GLXcontext *gc) { -#ifndef GLX_USE_APPLEGL xGLXWaitGLReq *req; -#endif - GLXContext gc = __glXGetCurrentContext(); Display *dpy = gc->currentDpy; - if (!dpy) - return; - /* Flush any pending commands out */ __glXFlushRenderBuffer(gc, gc->pc); -#ifdef GLX_USE_APPLEGL - glFinish(); -#else -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) - if (gc->driContext) { - int screen; - __GLXDRIdrawable *pdraw = - GetGLXDRIDrawable(dpy, gc->currentDrawable, &screen); - - if (pdraw != NULL) { - __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); - glFlush(); - if (psc->driScreen->waitGL != NULL) - (*psc->driScreen->waitGL) (pdraw); - } - return; - } -#endif /* Send the glXWaitGL request */ LockDisplay(dpy); @@ -717,51 +689,30 @@ glXWaitGL(void) req->contextTag = gc->currentContextTag; UnlockDisplay(dpy); SyncHandle(); -#endif /* GLX_USE_APPLEGL */ } /* -** Put a barrier in the token stream that forces X to finish its -** work before GL can proceed. +** Put a barrier in the token stream that forces the GL to finish its +** work before X can proceed. */ PUBLIC void -glXWaitX(void) +glXWaitGL(void) { -#ifndef GLX_USE_APPLEGL - xGLXWaitXReq *req; -#endif GLXContext gc = __glXGetCurrentContext(); - Display *dpy = gc->currentDpy; - if (!dpy) - return; + if (gc && gc->vtable->use_x_font) + gc->vtable->wait_gl(gc); +} + +static void +indirect_wait_x(__GLXcontext *gc) +{ + xGLXWaitXReq *req; + Display *dpy = gc->currentDpy; /* Flush any pending commands out */ __glXFlushRenderBuffer(gc, gc->pc); -#ifdef GLX_USE_APPLEGL - apple_glx_waitx(dpy, gc->driContext); -#else -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) - if (gc->driContext) { - int screen; - __GLXDRIdrawable *pdraw = - GetGLXDRIDrawable(dpy, gc->currentDrawable, &screen); - - if (pdraw != NULL) { - __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); - if (psc->driScreen->waitX != NULL) - (*psc->driScreen->waitX) (pdraw); - } - else - XSync(dpy, False); - return; - } -#endif - - /* - ** Send the glXWaitX request. - */ LockDisplay(dpy); GetReq(GLXWaitX, req); req->reqType = gc->majorOpcode; @@ -769,32 +720,30 @@ glXWaitX(void) req->contextTag = gc->currentContextTag; UnlockDisplay(dpy); SyncHandle(); -#endif /* GLX_USE_APPLEGL */ } +/* +** Put a barrier in the token stream that forces X to finish its +** work before GL can proceed. +*/ PUBLIC void -glXUseXFont(Font font, int first, int count, int listBase) +glXWaitX(void) { -#ifndef GLX_USE_APPLEGL - xGLXUseXFontReq *req; -#endif GLXContext gc = __glXGetCurrentContext(); - Display *dpy = gc->currentDpy; - if (!dpy) - return; + if (gc && gc->vtable->use_x_font) + gc->vtable->wait_x(gc); +} + +static void +indirect_use_x_font(__GLXcontext *gc, + Font font, int first, int count, int listBase) +{ + xGLXUseXFontReq *req; + Display *dpy = gc->currentDpy; /* Flush any pending commands out */ - (void) __glXFlushRenderBuffer(gc, gc->pc); -#ifdef GLX_USE_APPLEGL - DRI_glXUseXFont(font, first, count, listBase); -#else -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) - if (gc->driContext) { - DRI_glXUseXFont(font, first, count, listBase); - return; - } -#endif + __glXFlushRenderBuffer(gc, gc->pc); /* Send the glXUseFont request */ LockDisplay(dpy); @@ -808,7 +757,39 @@ glXUseXFont(Font font, int first, int count, int listBase) req->listBase = listBase; UnlockDisplay(dpy); SyncHandle(); -#endif /* GLX_USE_APPLEGL */ +} + +#ifdef GLX_USE_APPLEGL + +static void +applegl_wait_gl(__GLXcontext *gc) +{ + glFinish(); +} + +static void +applegl_wait_x(__GLXcontext *gc) +{ + apple_glx_waitx(gc->dpy, gc->driContext); +} + +static const struct glx_context_vtable applegl_context_vtable = { + applegl_wait_gl, + applegl_wait_x, + DRI_glXUseXFont, + NULL, /* bind_tex_image, */ + NULL, /* release_tex_image, */ +}; + +#endif + +PUBLIC void +glXUseXFont(Font font, int first, int count, int listBase) +{ + GLXContext gc = __glXGetCurrentContext(); + + if (gc && gc->vtable->use_x_font) + gc->vtable->use_x_font(gc, font, first, count, listBase); } /************************************************************************/ @@ -2800,6 +2781,9 @@ indirect_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer) } static const struct glx_context_vtable indirect_context_vtable = { + indirect_wait_gl, + indirect_wait_x, + indirect_use_x_font, indirect_bind_tex_image, indirect_release_tex_image, }; diff --git a/src/glx/xfont.c b/src/glx/xfont.c index 797fd7a490..db3a570110 100644 --- a/src/glx/xfont.c +++ b/src/glx/xfont.c @@ -212,9 +212,8 @@ isvalid(XFontStruct * fs, int which) } _X_HIDDEN void -DRI_glXUseXFont(Font font, int first, int count, int listbase) +DRI_glXUseXFont(GLXContext CC, Font font, int first, int count, int listbase) { - GLXContext CC; Display *dpy; Window win; Pixmap pixmap; @@ -231,7 +230,6 @@ DRI_glXUseXFont(Font font, int first, int count, int listbase) int i; - CC = __glXGetCurrentContext(); dpy = CC->currentDpy; win = CC->currentDrawable; -- cgit v1.2.3 From c796bb0cc3fde409545bff320540ddf5c029e513 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Thu, 22 Jul 2010 23:45:18 -0400 Subject: glx: Move context destroy to context vtable --- src/glx/dri2_glx.c | 11 +++++- src/glx/dri_glx.c | 27 ++++++++----- src/glx/drisw_glx.c | 11 +++++- src/glx/glxclient.h | 10 +++-- src/glx/glxcmds.c | 104 ++++++++++++++++++--------------------------------- src/glx/glxcurrent.c | 23 +----------- src/glx/glxext.c | 2 +- 7 files changed, 83 insertions(+), 105 deletions(-) (limited to 'src/glx/drisw_glx.c') diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index ae5bf535af..02c0f9f24e 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -114,11 +114,18 @@ struct dri2_drawable static const struct glx_context_vtable dri2_context_vtable; static void -dri2DestroyContext(__GLXcontext *context) +dri2_destroy_context(__GLXcontext *context) { struct dri2_context *pcp = (struct dri2_context *) context; struct dri2_screen *psc = (struct dri2_screen *) context->psc; + glx_send_destroy_context(psc->base.dpy, context->xid); + + if (context->extensions) + XFree((char *) context->extensions); + + GarbageCollectDRIDrawables(context->psc); + (*psc->core->destroyContext) (pcp->driContext); Xfree(pcp); @@ -182,7 +189,6 @@ dri2CreateContext(__GLXscreenConfigs *base, pcp->base.vtable = &dri2_context_vtable; pcp->base.driContext = &pcp->dri_vtable; - pcp->dri_vtable.destroyContext = dri2DestroyContext; pcp->dri_vtable.bindContext = dri2BindContext; pcp->dri_vtable.unbindContext = dri2UnbindContext; @@ -675,6 +681,7 @@ dri2_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer) } static const struct glx_context_vtable dri2_context_vtable = { + dri2_destroy_context, dri2_wait_gl, dri2_wait_x, DRI_glXUseXFont, diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c index 352d833fd7..ff7ca5ef7d 100644 --- a/src/glx/dri_glx.c +++ b/src/glx/dri_glx.c @@ -92,13 +92,7 @@ struct dri_drawable __DRIdrawable *driDrawable; }; -static const struct glx_context_vtable dri_context_vtable = { - NULL, - NULL, - DRI_glXUseXFont, - NULL, - NULL, -}; +static const struct glx_context_vtable dri_context_vtable; /* * Given a display pointer and screen number, determine the name of @@ -506,11 +500,18 @@ CallCreateNewScreen(Display *dpy, int scrn, struct dri_screen *psc, } static void -driDestroyContext(__GLXcontext * context) +dri_destroy_context(__GLXcontext * context) { struct dri_context *pcp = (struct dri_context *) context; struct dri_screen *psc = (struct dri_screen *) context->psc; + glx_send_destroy_context(psc->base.dpy, context->xid); + + if (context->extensions) + XFree((char *) context->extensions); + + GarbageCollectDRIDrawables(context->psc); + (*psc->core->destroyContext) (pcp->driContext); XF86DRIDestroyContext(psc->base.dpy, psc->base.scr, pcp->hwContextID); @@ -539,6 +540,15 @@ driUnbindContext(__GLXcontext * context) (*psc->core->unbindContext) (pcp->driContext); } +static const struct glx_context_vtable dri_context_vtable = { + dri_destroy_context, + NULL, + NULL, + DRI_glXUseXFont, + NULL, + NULL, +}; + static __GLXcontext * driCreateContext(__GLXscreenConfigs *base, const __GLcontextModes * mode, @@ -587,7 +597,6 @@ driCreateContext(__GLXscreenConfigs *base, pcp->base.vtable = &dri_context_vtable; pcp->base.driContext = &pcp->dri_vtable; - pcp->dri_vtable.destroyContext = driDestroyContext; pcp->dri_vtable.bindContext = driBindContext; pcp->dri_vtable.unbindContext = driUnbindContext; diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index 0ad7391457..c971de2f76 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -240,11 +240,18 @@ static const __DRIextension *loader_extensions[] = { */ static void -driDestroyContext(__GLXcontext *context) +drisw_destroy_context(__GLXcontext *context) { struct drisw_context *pcp = (struct drisw_context *) context; struct drisw_screen *psc = (struct drisw_screen *) context->psc; + glx_send_destroy_context(psc->base.dpy, context->xid); + + if (context->extensions) + XFree((char *) context->extensions); + + GarbageCollectDRIDrawables(context->psc); + (*psc->core->destroyContext) (pcp->driContext); Xfree(pcp); @@ -273,6 +280,7 @@ driUnbindContext(__GLXcontext * context) } static const struct glx_context_vtable drisw_context_vtable = { + drisw_destroy_context, NULL, NULL, DRI_glXUseXFont, @@ -318,7 +326,6 @@ driCreateContext(__GLXscreenConfigs *base, pcp->base.vtable = &drisw_context_vtable; pcp->base.driContext = &pcp->dri_vtable; - pcp->dri_vtable.destroyContext = driDestroyContext; pcp->dri_vtable.bindContext = driBindContext; pcp->dri_vtable.unbindContext = driUnbindContext; diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h index 8112c01e7c..20c4529131 100644 --- a/src/glx/glxclient.h +++ b/src/glx/glxclient.h @@ -153,7 +153,6 @@ struct __GLXDRIscreenRec { struct __GLXDRIcontextRec { - void (*destroyContext) (__GLXcontext *context); Bool(*bindContext) (__GLXcontext *context, __GLXDRIdrawable *pdraw, __GLXDRIdrawable *pread); void (*unbindContext) (__GLXcontext *context); @@ -241,6 +240,7 @@ typedef struct __GLXattributeMachineRec } __GLXattributeMachine; struct glx_context_vtable { + void (*destroy)(__GLXcontext *ctx); void (*wait_gl)(__GLXcontext *ctx); void (*wait_x)(__GLXcontext *ctx); void (*use_x_font)(__GLXcontext *ctx, @@ -252,6 +252,9 @@ struct glx_context_vtable { }; +extern void +glx_send_destroy_context(Display *dpy, XID xid); + /** * GLX state that needs to be kept on the client. One of these records * exist for each context that has been made current by this client. @@ -660,8 +663,6 @@ extern __GLXcontext *__glXcurrentContext; extern void __glXSetCurrentContextNull(void); -extern void __glXFreeContext(__GLXcontext *); - /* ** Global lock for all threads in this address space using the GLX @@ -790,6 +791,9 @@ __glxGetMscRate(__GLXDRIdrawable *glxDraw, * glx_info->codes->first_event */ XExtDisplayInfo *__glXFindDisplay (Display *dpy); +extern void +GarbageCollectDRIDrawables(__GLXscreenConfigs *psc); + extern __GLXDRIdrawable * GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable); diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 8ee9a999e4..72ac3ecd7d 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -85,7 +85,7 @@ windowExistsErrorHandler(Display * dpy, XErrorEvent * xerr) * \param dpy Display to destroy drawables for * \param screen Screen number to destroy drawables for */ -static void +_X_HIDDEN void GarbageCollectDRIDrawables(__GLXscreenConfigs * sc) { XID draw; @@ -480,7 +480,7 @@ CreateContext(Display * dpy, int generic_id, shareList ? shareList->driContext : NULL, &errorcode, &x11error)) { __glXSendError(dpy, errorcode, 0, X_GLXCreateContext, x11error); - __glXFreeContext(gc); + gc->vtable->destroy(gc); return NULL; } @@ -524,8 +524,28 @@ glXCreateContext(Display * dpy, XVisualInfo * vis, } _X_HIDDEN void -__glXFreeContext(__GLXcontext * gc) +glx_send_destroy_context(Display *dpy, XID xid) { + CARD8 opcode = __glXSetupForCommand(dpy); + xGLXDestroyContextReq *req; + + LockDisplay(dpy); + GetReq(GLXDestroyContext, req); + req->reqType = opcode; + req->glxCode = X_GLXDestroyContext; + req->context = xid; + UnlockDisplay(dpy); + SyncHandle(); +} + +static void +indirect_destroy_context(__GLXcontext *gc) +{ + if (!gc->imported) + glx_send_destroy_context(gc->psc->dpy, gc->xid); + + __glXFreeVertexArrayState(gc); + if (gc->vendor) XFree((char *) gc->vendor); if (gc->renderer) @@ -538,7 +558,6 @@ __glXFreeContext(__GLXcontext * gc) XFree((char *) gc->buf); Xfree((char *) gc->client_state_private); XFree((char *) gc); - } /* @@ -547,81 +566,24 @@ __glXFreeContext(__GLXcontext * gc) static void DestroyContext(Display * dpy, GLXContext gc) { -#ifndef GLX_USE_APPLEGL /* TODO: darwin: indirect */ - xGLXDestroyContextReq *req; - GLXContextID xid; - CARD8 opcode; - GLboolean imported; - - opcode = __glXSetupForCommand(dpy); - if (!opcode || !gc) { + if (!gc) return; - } __glXLock(); - xid = gc->xid; - imported = gc->imported; - gc->xid = None; - if (gc->currentDpy) { /* This context is bound to some thread. According to the man page, * we should not actually delete the context until it's unbound. * Note that we set gc->xid = None above. In MakeContextCurrent() * we check for that and delete the context there. */ + gc->xid = None; __glXUnlock(); return; } + __glXUnlock(); -#if defined(GLX_DIRECT_RENDERING) - /* Destroy the direct rendering context */ - if (gc->driContext) { - GarbageCollectDRIDrawables(gc->psc); - if (gc->extensions) - XFree((char *) gc->extensions); - (*gc->driContext->destroyContext) (gc); - } - else -#endif - { - __glXFreeVertexArrayState(gc); - __glXFreeContext(gc); - } - - if (!imported) { - /* - ** This dpy also created the server side part of the context. - ** Send the glXDestroyContext request. - */ - LockDisplay(dpy); - GetReq(GLXDestroyContext, req); - req->reqType = opcode; - req->glxCode = X_GLXDestroyContext; - req->context = xid; - UnlockDisplay(dpy); - SyncHandle(); - } - -#else - - __glXLock(); - if (gc->currentDpy) { - /* - * Set the Bool that indicates that we should destroy this GLX context - * when the context is no longer current. - */ - gc->do_destroy = True; - /* Have to free later cuz it's in use now */ - __glXUnlock(); - } - else { - /* Destroy the handle if not current to anybody */ - __glXUnlock(); - if(gc->driContext) - apple_glx_destroy_context(&gc->driContext, dpy); - __glXFreeContext(gc); - } -#endif + if (gc->vtable->destroy) + gc->vtable->destroy(gc); } PUBLIC void @@ -758,6 +720,12 @@ indirect_use_x_font(__GLXcontext *gc, #ifdef GLX_USE_APPLEGL +static void +applegl_destroy_context(__GLXcontext *gc) +{ + apple_glx_destroy_context(&gc->driContext, gc->currentDpy); +} + static void applegl_wait_gl(__GLXcontext *gc) { @@ -771,6 +739,7 @@ applegl_wait_x(__GLXcontext *gc) } static const struct glx_context_vtable applegl_context_vtable = { + applegl_destroy_context, applegl_wait_gl, applegl_wait_x, DRI_glXUseXFont, @@ -1857,7 +1826,7 @@ glXImportContextEXT(Display * dpy, GLXContextID contextID) ctx->imported = GL_TRUE; if (Success != __glXQueryContextInfo(dpy, ctx)) { - __glXFreeContext(ctx); + ctx->vtable->destroy(ctx); ctx = NULL; } } @@ -2773,6 +2742,7 @@ indirect_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer) } static const struct glx_context_vtable indirect_context_vtable = { + indirect_destroy_context, indirect_wait_gl, indirect_wait_x, indirect_use_x_font, diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c index 0bf61779c4..e8649b6765 100644 --- a/src/glx/glxcurrent.c +++ b/src/glx/glxcurrent.c @@ -468,32 +468,13 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, oldGC->currentReadable = None; oldGC->currentContextTag = 0; oldGC->thread_id = 0; -#ifdef GLX_USE_APPLEGL - - /* - * At this point we should check if the context has been - * through glXDestroyContext, and redestroy it if so. - */ - if(oldGC->do_destroy) { - __glXUnlock(); - /* glXDestroyContext uses the same global lock. */ - glXDestroyContext(dpy, oldGC); - __glXLock(); -#else + if (oldGC->xid == None) { /* We are switching away from a context that was * previously destroyed, so we need to free the memory * for the old handle. */ -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) - /* Destroy the old direct rendering context */ - if (oldGC->driContext) { - oldGC->driContext->destroyContext(oldGC); - oldGC->driContext = NULL; - } -#endif - __glXFreeContext(oldGC); -#endif /* GLX_USE_APPLEGL */ + oldGC->vtable->destroy(oldGC); } } if (gc) { diff --git a/src/glx/glxext.c b/src/glx/glxext.c index 88e74c2a38..97149dff70 100644 --- a/src/glx/glxext.c +++ b/src/glx/glxext.c @@ -263,8 +263,8 @@ __glXCloseDisplay(Display * dpy, XExtCodes * codes) gc = __glXGetCurrentContext(); if (dpy == gc->currentDpy) { + gc->vtable->destroy(gc); __glXSetCurrentContextNull(); - __glXFreeContext(gc); } FreeScreenConfigs(priv); -- cgit v1.2.3 From 6ec39db726beead21d97bf64ddbe1f0b2d2d6ca1 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Fri, 23 Jul 2010 16:15:31 -0400 Subject: glx: Refactor and simplify context creation This lets us better separate context creation between the different backends. --- src/glx/dri2_glx.c | 11 +- src/glx/dri_glx.c | 12 +- src/glx/drisw_glx.c | 12 +- src/glx/glxclient.h | 11 ++ src/glx/glxcmds.c | 327 ++++++++++++++++++++++++---------------------------- src/glx/glxext.c | 17 +-- 6 files changed, 185 insertions(+), 205 deletions(-) (limited to 'src/glx/drisw_glx.c') diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index 02c0f9f24e..58f09ed86a 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -154,9 +154,9 @@ dri2UnbindContext(__GLXcontext *context) } static __GLXcontext * -dri2CreateContext(__GLXscreenConfigs *base, - const __GLcontextModes * mode, - GLXContext shareList, int renderType) +dri2_create_context(__GLXscreenConfigs *base, + const __GLcontextModes * mode, + GLXContext shareList, int renderType) { struct dri2_context *pcp, *pcp_shared; struct dri2_screen *psc = (struct dri2_screen *) base; @@ -718,6 +718,9 @@ dri2BindExtensions(struct dri2_screen *psc, const __DRIextension **extensions) } } +static const struct glx_screen_vtable dri2_screen_vtable = { + dri2_create_context +}; static __GLXscreenConfigs * dri2CreateScreen(int screen, __GLXdisplayPrivate * priv) @@ -811,10 +814,10 @@ dri2CreateScreen(int screen, __GLXdisplayPrivate * priv) psc->driver_configs = driver_configs; + psc->base.vtable = &dri2_screen_vtable; psp = &psc->vtable; psc->base.driScreen = psp; psp->destroyScreen = dri2DestroyScreen; - psp->createContext = dri2CreateContext; psp->createDrawable = dri2CreateDrawable; psp->swapBuffers = dri2SwapBuffers; psp->getDrawableMSC = NULL; diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c index ff7ca5ef7d..95cded792d 100644 --- a/src/glx/dri_glx.c +++ b/src/glx/dri_glx.c @@ -550,9 +550,9 @@ static const struct glx_context_vtable dri_context_vtable = { }; static __GLXcontext * -driCreateContext(__GLXscreenConfigs *base, - const __GLcontextModes * mode, - GLXContext shareList, int renderType) +dri_create_context(__GLXscreenConfigs *base, + const __GLcontextModes *mode, + GLXContext shareList, int renderType) { struct dri_context *pcp, *pcp_shared; struct dri_screen *psc = (struct dri_screen *) base; @@ -821,6 +821,10 @@ driBindExtensions(struct dri_screen *psc, const __DRIextension **extensions) } } +static const struct glx_screen_vtable dri_screen_vtable = { + dri_create_context +}; + static __GLXscreenConfigs * driCreateScreen(int screen, __GLXdisplayPrivate *priv) { @@ -882,13 +886,13 @@ driCreateScreen(int screen, __GLXdisplayPrivate *priv) extensions = psc->core->getExtensions(psc->driScreen); driBindExtensions(psc, extensions); + psc->base.vtable = &dri_screen_vtable; psp = &psc->vtable; psc->base.driScreen = psp; if (psc->driCopySubBuffer) psp->copySubBuffer = driCopySubBuffer; psp->destroyScreen = driDestroyScreen; - psp->createContext = driCreateContext; psp->createDrawable = driCreateDrawable; psp->swapBuffers = driSwapBuffers; diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index c971de2f76..4265f56412 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -289,9 +289,9 @@ static const struct glx_context_vtable drisw_context_vtable = { }; static __GLXcontext * -driCreateContext(__GLXscreenConfigs *base, - const __GLcontextModes *mode, - GLXContext shareList, int renderType) +drisw_create_context(__GLXscreenConfigs *base, + const __GLcontextModes *mode, + GLXContext shareList, int renderType) { struct drisw_context *pcp, *pcp_shared; __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode; @@ -426,6 +426,10 @@ driOpenSwrast(void) return driver; } +static const struct glx_screen_vtable drisw_screen_vtable = { + drisw_create_context +}; + static __GLXscreenConfigs * driCreateScreen(int screen, __GLXdisplayPrivate *priv) { @@ -482,10 +486,10 @@ driCreateScreen(int screen, __GLXdisplayPrivate *priv) psc->driver_configs = driver_configs; + psc->base.vtable = &drisw_screen_vtable; psp = &psc->vtable; psc->base.driScreen = psp; psp->destroyScreen = driDestroyScreen; - psp->createContext = driCreateContext; psp->createDrawable = driCreateDrawable; psp->swapBuffers = driSwapBuffers; diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h index 20c4529131..48b5501fe9 100644 --- a/src/glx/glxclient.h +++ b/src/glx/glxclient.h @@ -504,8 +504,16 @@ extern void __glFreeAttributeState(__GLXcontext *); * One of these records exists per screen of the display. It contains * a pointer to the config data for that screen (if the screen supports GL). */ +struct glx_screen_vtable { + __GLXcontext *(*create_context)(__GLXscreenConfigs *psc, + const __GLcontextModes *mode, + GLXContext shareList, int renderType); +}; + struct __GLXscreenConfigsRec { + const struct glx_screen_vtable *vtable; + /** * GLX extension string reported by the X-server. */ @@ -799,4 +807,7 @@ GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable); #endif +extern __GLXscreenConfigs * +indirect_create_screen(int screen, __GLXdisplayPrivate * priv); + #endif /* !__GLX_client_h__ */ diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 72ac3ecd7d..1ded6247ef 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -234,6 +234,55 @@ ValidateGLXFBConfig(Display * dpy, GLXFBConfig config) return NULL; } +#ifdef GLX_USE_APPLEGL + +static const struct glx_context_vtable applegl_context_vtable; + +static __GLcontext * +applegl_create_context(__GLXscreenConfigs *psc, + const __GLcontextModes *mode, + GLXContext shareList, int renderType) +{ + __GLXcontext *gc; + int errorcode; + bool x11error; + + /* TODO: Integrate this with apple_glx_create_context and make + * struct apple_glx_context inherit from __GLXcontext. */ + + gc = Xmalloc(sizeof *gc); + if (pcp == NULL) + return NULL; + + memset(gc, 0, sizeof *gc); + if (!glx_context_init(&gc->base, &psc->base, mode)) { + Xfree(gc); + return NULL; + } + + gc->vtable = &applegl_context_vtable; + gc->driContext = NULL; + gc->do_destroy = False; + + /* TODO: darwin: Integrate with above to do indirect */ + if(apple_glx_create_context(&gc->driContext, dpy, screen, fbconfig, + shareList ? shareList->driContext : NULL, + &errorcode, &x11error)) { + __glXSendError(dpy, errorcode, 0, X_GLXCreateContext, x11error); + gc->vtable->destroy(gc); + return NULL; + } + + gc->currentContextTag = -1; + gc->mode = fbconfig; + gc->isDirect = allowDirect; + gc->xid = 1; /* Just something not None, so we know when to destroy + * it in MakeContextCurrent. */ + + return gc; +} +#endif + /** * \todo It should be possible to move the allocate of \c client_state_private @@ -246,17 +295,16 @@ ValidateGLXFBConfig(Display * dpy, GLXFBConfig config) * does all the initialization (including the pixel pack / unpack). */ static GLXContext -AllocateGLXContext(Display * dpy) +indirect_create_context(__GLXscreenConfigs *psc, + const __GLcontextModes *mode, + GLXContext shareList, int renderType) { GLXContext gc; int bufSize; CARD8 opcode; __GLXattribute *state; - if (!dpy) - return NULL; - - opcode = __glXSetupForCommand(dpy); + opcode = __glXSetupForCommand(psc->dpy); if (!opcode) { return NULL; } @@ -269,6 +317,8 @@ AllocateGLXContext(Display * dpy) } memset(gc, 0, sizeof(struct __GLXcontextRec)); + glx_context_init(gc, psc, mode); + gc->isDirect = GL_FALSE; gc->vtable = &indirect_context_vtable; state = Xmalloc(sizeof(struct __GLXattributeRec)); if (state == NULL) { @@ -287,7 +337,7 @@ AllocateGLXContext(Display * dpy) ** packet for the GLXRenderReq header. */ - bufSize = (XMaxRequestSize(dpy) * 4) - sz_xGLXRenderReq; + bufSize = (XMaxRequestSize(psc->dpy) * 4) - sz_xGLXRenderReq; gc->buf = (GLubyte *) Xmalloc(bufSize); if (!gc->buf) { Xfree(gc->client_state_private); @@ -339,14 +389,31 @@ AllocateGLXContext(Display * dpy) } gc->maxSmallRenderCommandSize = bufSize; -#ifdef GLX_USE_APPLEGL - gc->driContext = NULL; - gc->do_destroy = False; -#endif return gc; } +struct glx_screen_vtable indirect_screen_vtable = { + indirect_create_context +}; + +_X_HIDDEN __GLXscreenConfigs * +indirect_create_screen(int screen, __GLXdisplayPrivate * priv) +{ + __GLXscreenConfigs *psc; + + psc = Xmalloc(sizeof *psc); + if (psc == NULL) + return NULL; + + memset(psc, 0, sizeof *psc); + glx_screen_init(psc, screen, priv); + psc->vtable = &indirect_screen_vtable; + + return psc; +} + + _X_HIDDEN Bool glx_context_init(__GLXcontext *gc, __GLXscreenConfigs *psc, const __GLcontextModes *fbconfig) @@ -382,27 +449,19 @@ CreateContext(Display * dpy, int generic_id, { GLXContext gc = NULL; __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); -#if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_APPLEGL) - int errorcode; - bool x11error; -#endif - + if (dpy == NULL) return NULL; if (generic_id == None) return NULL; -#ifndef GLX_USE_APPLEGL /* TODO: darwin indirect */ -#ifdef GLX_DIRECT_RENDERING - if (allowDirect && psc->driScreen) { - gc = psc->driScreen->createContext(psc, fbconfig, - shareList, renderType); - } -#endif - + gc = NULL; + if (allowDirect && psc->vtable->create_context) + gc = psc->vtable->create_context(psc, fbconfig, + shareList, renderType); if (!gc) - gc = AllocateGLXContext(dpy); + gc = indirect_create_context(psc, fbconfig, shareList, renderType); if (!gc) return NULL; @@ -469,26 +528,10 @@ CreateContext(Display * dpy, int generic_id, UnlockDisplay(dpy); SyncHandle(); -#endif gc->imported = GL_FALSE; gc->renderType = renderType; - /* TODO: darwin: Integrate with above to do indirect */ -#ifdef GLX_USE_APPLEGL - if(apple_glx_create_context(&gc->driContext, dpy, screen, fbconfig, - shareList ? shareList->driContext : NULL, - &errorcode, &x11error)) { - __glXSendError(dpy, errorcode, 0, X_GLXCreateContext, x11error); - gc->vtable->destroy(gc); - return NULL; - } - - gc->currentContextTag = -1; - gc->mode = fbconfig; - gc->isDirect = allowDirect; -#endif - return gc; } @@ -1633,122 +1676,103 @@ GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (), glXGetCurrentDisplay) #ifndef GLX_USE_APPLEGL -/** - * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests - * to the X-server. - * - * \param dpy Display where \c ctx was created. - * \param ctx Context to query. - * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid, - * or zero if the request failed due to internal problems (i.e., - * unable to allocate temporary memory, etc.) - * - * \note - * This function dynamically determines whether to use the EXT_import_context - * version of the protocol or the GLX 1.3 version of the protocol. - */ -static int __glXQueryContextInfo(Display * dpy, GLXContext ctx) +PUBLIC GLXContext +glXImportContextEXT(Display *dpy, GLXContextID contextID) { __GLXdisplayPrivate *priv = __glXInitialize(dpy); + __GLXscreenConfigs *psc; xGLXQueryContextReply reply; CARD8 opcode; - GLuint numValues; - int retval; + GLXContext ctx; + int propList[__GLX_MAX_CONTEXT_PROPS * 2], *pProp, nPropListBytes; + int i, renderType; + XID share; + __GLcontextModes *mode; + + if (contextID == None || __glXIsDirect(dpy, contextID)) + return NULL; - if (ctx == NULL) { - return GLX_BAD_CONTEXT; - } opcode = __glXSetupForCommand(dpy); - if (!opcode) { + if (!opcode) return 0; - } /* Send the glXQueryContextInfoEXT request */ LockDisplay(dpy); - if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) { + if (priv->majorVersion > 1 || priv->minorVersion >= 3) { xGLXQueryContextReq *req; GetReq(GLXQueryContext, req); req->reqType = opcode; req->glxCode = X_GLXQueryContext; - req->context = (unsigned int) (ctx->xid); + req->context = contextID; } else { xGLXVendorPrivateReq *vpreq; xGLXQueryContextInfoEXTReq *req; GetReqExtra(GLXVendorPrivate, - sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq, - vpreq); + sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq, + vpreq); req = (xGLXQueryContextInfoEXTReq *) vpreq; req->reqType = opcode; req->glxCode = X_GLXVendorPrivateWithReply; req->vendorCode = X_GLXvop_QueryContextInfoEXT; - req->context = (unsigned int) (ctx->xid); + req->context = contextID; } _XReply(dpy, (xReply *) & reply, 0, False); - numValues = reply.n; - if (numValues == 0) - retval = Success; - else if (numValues > __GLX_MAX_CONTEXT_PROPS) - retval = 0; - else { - int *propList, *pProp; - int nPropListBytes; - - nPropListBytes = numValues << 3; - propList = (int *) Xmalloc(nPropListBytes); - if (NULL == propList) { - retval = 0; - } - else { - unsigned i; - - _XRead(dpy, (char *) propList, nPropListBytes); - - /* Look up screen first so we can look up visuals/fbconfigs later */ - pProp = propList; - for (i = 0; i < numValues; i++, pProp += 2) - if (pProp[0] == GLX_SCREEN) { - ctx->screen = pProp[1]; - ctx->psc = GetGLXScreenConfigs(dpy, ctx->screen); - } - - pProp = propList; - for (i = 0; i < numValues; i++) { - switch (*pProp++) { - case GLX_SHARE_CONTEXT_EXT: - ctx->share_xid = *pProp++; - break; - case GLX_VISUAL_ID_EXT: - ctx->mode = - _gl_context_modes_find_visual(ctx->psc->visuals, *pProp++); - break; - case GLX_FBCONFIG_ID: - ctx->mode = - _gl_context_modes_find_fbconfig(ctx->psc->configs, - *pProp++); - break; - case GLX_RENDER_TYPE: - ctx->renderType = *pProp++; - break; - case GLX_SCREEN: - default: - pProp++; - continue; - } - } - Xfree((char *) propList); - retval = Success; - } - } + if (reply.n <= __GLX_MAX_CONTEXT_PROPS) + nPropListBytes = reply.n * 2 * sizeof propList[0]; + else + nPropListBytes = 0; + _XRead(dpy, (char *) propList, nPropListBytes); UnlockDisplay(dpy); SyncHandle(); - return retval; + + /* Look up screen first so we can look up visuals/fbconfigs later */ + psc = NULL; + for (i = 0, pProp = propList; i < reply.n; i++, pProp += 2) + if (pProp[0] == GLX_SCREEN) + psc = GetGLXScreenConfigs(dpy, pProp[1]); + if (psc == NULL) + return NULL; + + share = None; + mode = NULL; + renderType = 0; + pProp = propList; + + for (i = 0, pProp = propList; i < reply.n; i++, pProp += 2) + switch (pProp[0]) { + case GLX_SHARE_CONTEXT_EXT: + share = pProp[1]; + break; + case GLX_VISUAL_ID_EXT: + mode = _gl_context_modes_find_visual(psc->visuals, pProp[1]); + break; + case GLX_FBCONFIG_ID: + mode = _gl_context_modes_find_fbconfig(psc->configs, pProp[1]); + break; + case GLX_RENDER_TYPE: + renderType = pProp[1]; + break; + } + + if (mode == NULL) + return NULL; + + ctx = indirect_create_context(psc, mode, NULL, renderType); + if (ctx == NULL) + return NULL; + + ctx->xid = contextID; + ctx->imported = GL_TRUE; + ctx->share_xid = share; + + return ctx; } #endif @@ -1756,38 +1780,21 @@ static int __glXQueryContextInfo(Display * dpy, GLXContext ctx) PUBLIC int glXQueryContext(Display * dpy, GLXContext ctx, int attribute, int *value) { -#ifndef GLX_USE_APPLEGL - int retVal; - - /* get the information from the server if we don't have it already */ -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) - if (!ctx->driContext && (ctx->mode == NULL)) { -#else - if (ctx->mode == NULL) { -#endif - retVal = __glXQueryContextInfo(dpy, ctx); - if (Success != retVal) - return retVal; - } -#endif - switch (attribute) { -#ifndef GLX_USE_APPLEGL case GLX_SHARE_CONTEXT_EXT: - *value = (int) (ctx->share_xid); + *value = ctx->share_xid; break; case GLX_VISUAL_ID_EXT: *value = ctx->mode ? ctx->mode->visualID : None; break; -#endif case GLX_SCREEN: - *value = (int) (ctx->screen); + *value = ctx->screen; break; case GLX_FBCONFIG_ID: *value = ctx->mode ? ctx->mode->fbconfigID : None; break; case GLX_RENDER_TYPE: - *value = (int) (ctx->renderType); + *value = ctx->renderType; break; default: return GLX_BAD_ATTRIBUTE; @@ -1805,35 +1812,6 @@ PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx) return ctx->xid; } -PUBLIC GLXContext -glXImportContextEXT(Display * dpy, GLXContextID contextID) -{ -#ifdef GLX_USE_APPLEGL - return NULL; -#else - GLXContext ctx; - - if (contextID == None) { - return NULL; - } - if (__glXIsDirect(dpy, contextID)) { - return NULL; - } - - ctx = AllocateGLXContext(dpy); - if (NULL != ctx) { - ctx->xid = contextID; - ctx->imported = GL_TRUE; - - if (Success != __glXQueryContextInfo(dpy, ctx)) { - ctx->vtable->destroy(ctx); - ctx = NULL; - } - } - return ctx; -#endif -} - PUBLIC void glXFreeContextEXT(Display * dpy, GLXContext ctx) { @@ -1841,11 +1819,6 @@ glXFreeContextEXT(Display * dpy, GLXContext ctx) } - -/* - * GLX 1.3 functions - these are just stubs for now! - */ - PUBLIC GLXFBConfig * glXChooseFBConfig(Display * dpy, int screen, const int *attribList, int *nitems) diff --git a/src/glx/glxext.c b/src/glx/glxext.c index 324230f5e3..f9a5f7ce5d 100644 --- a/src/glx/glxext.c +++ b/src/glx/glxext.c @@ -738,21 +738,6 @@ glx_screen_init(__GLXscreenConfigs *psc, return GL_TRUE; } -static __GLXscreenConfigs * -createIndirectScreen(int screen, __GLXdisplayPrivate * priv) -{ - __GLXscreenConfigs *psc; - - psc = Xmalloc(sizeof *psc); - if (psc == NULL) - return NULL; - - memset(psc, 0, sizeof *psc); - glx_screen_init(psc, screen, priv); - - return psc; -} - /* ** Allocate the memory for the per screen configs for each screen. ** If that works then fetch the per screen configs data. @@ -789,7 +774,7 @@ AllocAndFetchScreenConfigs(Display * dpy, __GLXdisplayPrivate * priv) psc = (*priv->driswDisplay->createScreen) (i, priv); #endif if (psc == NULL) - psc = createIndirectScreen (i, priv); + psc = indirect_create_screen(i, priv); priv->screenConfigs[i] = psc; } SyncHandle(); -- cgit v1.2.3 From 6393a33944ec9983426cecd5f6c9f05ac089e1ae Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Fri, 23 Jul 2010 21:45:05 -0400 Subject: glx: zero out drawable structs after allocation --- src/glx/dri2_glx.c | 1 + src/glx/dri_glx.c | 1 + src/glx/drisw_glx.c | 1 + 3 files changed, 3 insertions(+) (limited to 'src/glx/drisw_glx.c') diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index 58f09ed86a..4a08f84de3 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -224,6 +224,7 @@ dri2CreateDrawable(__GLXscreenConfigs *base, XID xDrawable, if (!pdraw) return NULL; + memset(pdraw, 0, sizeof *pdraw); pdraw->base.destroyDrawable = dri2DestroyDrawable; pdraw->base.xDrawable = xDrawable; pdraw->base.drawable = drawable; diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c index 95cded792d..d0f680de63 100644 --- a/src/glx/dri_glx.c +++ b/src/glx/dri_glx.c @@ -633,6 +633,7 @@ driCreateDrawable(__GLXscreenConfigs *base, if (!pdp) return NULL; + memset(pdp, 0, sizeof *pdp); pdp->base.drawable = drawable; pdp->base.psc = &psc->base; diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index 4265f56412..852e56e484 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -362,6 +362,7 @@ driCreateDrawable(__GLXscreenConfigs *base, XID xDrawable, if (!pdp) return NULL; + memset(pdp, 0, sizeof *pdp); pdp->base.xDrawable = xDrawable; pdp->base.drawable = drawable; pdp->base.psc = &psc->base; -- cgit v1.2.3 From d77bb8e059ecfed9b714301fc31b093c6026c7bc Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Fri, 23 Jul 2010 22:05:21 -0400 Subject: glx: Don't destroy context with XID 0 We use XID 0 to indicate the context has already been destroyed, but it's currently bound. --- src/glx/dri2_glx.c | 3 ++- src/glx/dri_glx.c | 3 ++- src/glx/drisw_glx.c | 3 ++- src/glx/glxcmds.c | 4 +++- 4 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src/glx/drisw_glx.c') diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index 4a08f84de3..a94223b2a1 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -119,7 +119,8 @@ dri2_destroy_context(__GLXcontext *context) struct dri2_context *pcp = (struct dri2_context *) context; struct dri2_screen *psc = (struct dri2_screen *) context->psc; - glx_send_destroy_context(psc->base.dpy, context->xid); + if (context->xid) + glx_send_destroy_context(psc->base.dpy, context->xid); if (context->extensions) XFree((char *) context->extensions); diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c index d0f680de63..eaf8e3b7f2 100644 --- a/src/glx/dri_glx.c +++ b/src/glx/dri_glx.c @@ -505,7 +505,8 @@ dri_destroy_context(__GLXcontext * context) struct dri_context *pcp = (struct dri_context *) context; struct dri_screen *psc = (struct dri_screen *) context->psc; - glx_send_destroy_context(psc->base.dpy, context->xid); + if (context->xid) + glx_send_destroy_context(psc->base.dpy, context->xid); if (context->extensions) XFree((char *) context->extensions); diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index 852e56e484..11f88e9670 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -245,7 +245,8 @@ drisw_destroy_context(__GLXcontext *context) struct drisw_context *pcp = (struct drisw_context *) context; struct drisw_screen *psc = (struct drisw_screen *) context->psc; - glx_send_destroy_context(psc->base.dpy, context->xid); + if (context->xid) + glx_send_destroy_context(psc->base.dpy, context->xid); if (context->extensions) XFree((char *) context->extensions); diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 1ded6247ef..b92638c9c2 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -584,7 +584,7 @@ glx_send_destroy_context(Display *dpy, XID xid) static void indirect_destroy_context(__GLXcontext *gc) { - if (!gc->imported) + if (!gc->imported && gc->xid) glx_send_destroy_context(gc->psc->dpy, gc->xid); __glXFreeVertexArrayState(gc); @@ -619,6 +619,8 @@ DestroyContext(Display * dpy, GLXContext gc) * Note that we set gc->xid = None above. In MakeContextCurrent() * we check for that and delete the context there. */ + if (!gc->imported) + glx_send_destroy_context(dpy, gc->xid); gc->xid = None; __glXUnlock(); return; -- cgit v1.2.3 From 4d58b5b482d06ab8d4c4b2db33d0b48b7c82d064 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Sat, 24 Jul 2010 21:43:25 -0400 Subject: glx: Drop duplicate psc field in drisw context struct Causing a crash in drisw MakeCurrent. --- src/glx/drisw_glx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/glx/drisw_glx.c') diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index 11f88e9670..5f7185de4c 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -38,7 +38,7 @@ struct drisw_context __GLXcontext base; __GLXDRIcontext dri_vtable; __DRIcontext *driContext; - __GLXscreenConfigs *psc; + }; struct drisw_screen @@ -263,7 +263,7 @@ driBindContext(__GLXcontext * context, __GLXDRIdrawable * draw, __GLXDRIdrawable * read) { struct drisw_context *pcp = (struct drisw_context *) context; - struct drisw_screen *psc = (struct drisw_screen *) pcp->psc; + struct drisw_screen *psc = (struct drisw_screen *) pcp->base.psc; struct drisw_drawable *pdr = (struct drisw_drawable *) draw; struct drisw_drawable *prd = (struct drisw_drawable *) read; @@ -275,7 +275,7 @@ static void driUnbindContext(__GLXcontext * context) { struct drisw_context *pcp = (struct drisw_context *) context; - struct drisw_screen *psc = (struct drisw_screen *) pcp->psc; + struct drisw_screen *psc = (struct drisw_screen *) pcp->base.psc; (*psc->core->unbindContext) (pcp->driContext); } -- cgit v1.2.3