summaryrefslogtreecommitdiff
path: root/src/glx/dri2_glx.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/glx/dri2_glx.c')
-rw-r--r--src/glx/dri2_glx.c110
1 files changed, 65 insertions, 45 deletions
diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index 2f12387860..ff48c79c27 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -76,7 +76,7 @@ struct dri2_display
};
struct dri2_screen {
- __GLXscreenConfigs base;
+ struct glx_screen base;
__DRIscreen *driScreen;
__GLXDRIscreen vtable;
@@ -94,8 +94,7 @@ struct dri2_screen {
struct dri2_context
{
- __GLXcontext base;
- __GLXDRIcontext dri_vtable;
+ struct glx_context base;
__DRIcontext *driContext;
};
@@ -114,31 +113,47 @@ struct dri2_drawable
static const struct glx_context_vtable dri2_context_vtable;
static void
-dri2DestroyContext(__GLXcontext *context)
+dri2_destroy_context(struct glx_context *context)
{
struct dri2_context *pcp = (struct dri2_context *) context;
struct dri2_screen *psc = (struct dri2_screen *) context->psc;
+ if (context->xid)
+ 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);
}
static Bool
-dri2BindContext(__GLXcontext *context,
- __GLXDRIdrawable *draw, __GLXDRIdrawable *read)
+dri2_bind_context(struct glx_context *context, struct glx_context *old,
+ GLXDrawable draw, GLXDrawable read)
{
struct dri2_context *pcp = (struct dri2_context *) context;
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;
+ struct dri2_drawable *pdraw, *pread;
+
+ pdraw = (struct dri2_drawable *) driFetchDrawable(context, draw);
+ pread = (struct dri2_drawable *) driFetchDrawable(context, read);
+
+ if (pdraw == NULL || pread == NULL)
+ return GLXBadDrawable;
- return (*psc->core->bindContext) (pcp->driContext,
- pdr->driDrawable, prd->driDrawable);
+ if ((*psc->core->bindContext) (pcp->driContext,
+ pdraw->driDrawable, pread->driDrawable))
+ return Success;
+
+ return GLXBadContext;
}
static void
-dri2UnbindContext(__GLXcontext *context)
+dri2_unbind_context(struct glx_context *context, struct glx_context *new)
{
struct dri2_context *pcp = (struct dri2_context *) context;
struct dri2_screen *psc = (struct dri2_screen *) pcp->base.psc;
@@ -146,18 +161,18 @@ dri2UnbindContext(__GLXcontext *context)
(*psc->core->unbindContext) (pcp->driContext);
}
-static __GLXcontext *
-dri2CreateContext(__GLXscreenConfigs *base,
- const __GLcontextModes * mode,
- GLXContext shareList, int renderType)
+static struct glx_context *
+dri2_create_context(struct glx_screen *base,
+ struct glx_config *config_base,
+ struct glx_context *shareList, int renderType)
{
struct dri2_context *pcp, *pcp_shared;
struct dri2_screen *psc = (struct dri2_screen *) base;
- __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode;
+ __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base;
__DRIcontext *shared = NULL;
if (shareList) {
- pcp_shared = (struct dri2_context *) shareList->driContext;
+ pcp_shared = (struct dri2_context *) shareList;
shared = pcp_shared->driContext;
}
@@ -166,7 +181,7 @@ dri2CreateContext(__GLXscreenConfigs *base,
return NULL;
memset(pcp, 0, sizeof *pcp);
- if (!glx_context_init(&pcp->base, &psc->base, mode)) {
+ if (!glx_context_init(&pcp->base, &psc->base, &config->base)) {
Xfree(pcp);
return NULL;
}
@@ -181,10 +196,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;
return &pcp->base;
}
@@ -194,7 +205,7 @@ dri2DestroyDrawable(__GLXDRIdrawable *base)
{
struct dri2_screen *psc = (struct dri2_screen *) base->psc;
struct dri2_drawable *pdraw = (struct dri2_drawable *) base;
- __GLXdisplayPrivate *dpyPriv = psc->base.display;
+ struct glx_display *dpyPriv = psc->base.display;
struct dri2_display *pdp = (struct dri2_display *)dpyPriv->dri2Display;
__glxHashDelete(pdp->dri2Hash, pdraw->base.xDrawable);
@@ -204,13 +215,13 @@ dri2DestroyDrawable(__GLXDRIdrawable *base)
}
static __GLXDRIdrawable *
-dri2CreateDrawable(__GLXscreenConfigs *base, XID xDrawable,
- GLXDrawable drawable, const __GLcontextModes * modes)
+dri2CreateDrawable(struct glx_screen *base, XID xDrawable,
+ GLXDrawable drawable, struct glx_config *config_base)
{
struct dri2_drawable *pdraw;
struct dri2_screen *psc = (struct dri2_screen *) base;
- __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes;
- __GLXdisplayPrivate *dpyPriv;
+ __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base;
+ struct glx_display *dpyPriv;
struct dri2_display *pdp;
GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
@@ -218,6 +229,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;
@@ -280,7 +292,7 @@ dri2CreateDrawable(__GLXscreenConfigs *base, XID xDrawable,
#ifdef X_DRI2GetMSC
static int
-dri2DrawableGetMSC(__GLXscreenConfigs *psc, __GLXDRIdrawable *pdraw,
+dri2DrawableGetMSC(struct glx_screen *psc, __GLXDRIdrawable *pdraw,
int64_t *ust, int64_t *msc, int64_t *sbc)
{
CARD64 dri2_ust, dri2_msc, dri2_sbc;
@@ -394,7 +406,7 @@ dri2_copy_drawable(struct dri2_drawable *priv, int dest, int src)
}
static void
-dri2_wait_x(__GLXcontext *gc)
+dri2_wait_x(struct glx_context *gc)
{
struct dri2_drawable *priv = (struct dri2_drawable *)
GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
@@ -406,7 +418,7 @@ dri2_wait_x(__GLXcontext *gc)
}
static void
-dri2_wait_gl(__GLXcontext *gc)
+dri2_wait_gl(struct glx_context *gc)
{
struct dri2_drawable *priv = (struct dri2_drawable *)
GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
@@ -421,19 +433,20 @@ static void
dri2FlushFrontBuffer(__DRIdrawable *driDrawable, void *loaderPrivate)
{
struct dri2_drawable *pdraw = loaderPrivate;
- __GLXdisplayPrivate *priv = __glXInitialize(pdraw->base.psc->dpy);
+ struct glx_display *priv = __glXInitialize(pdraw->base.psc->dpy);
struct dri2_display *pdp = (struct dri2_display *)priv->dri2Display;
+ struct glx_context *gc = __glXGetCurrentContext();
/* Old servers don't send invalidate events */
if (!pdp->invalidateAvailable)
- dri2InvalidateBuffers(priv->dpy, pdraw->base.drawable);
+ dri2InvalidateBuffers(priv->dpy, pdraw->base.xDrawable);
- dri2_copy_drawable(pdraw, DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
+ dri2_wait_gl(gc);
}
static void
-dri2DestroyScreen(__GLXscreenConfigs *base)
+dri2DestroyScreen(struct glx_screen *base)
{
struct dri2_screen *psc = (struct dri2_screen *) base;
@@ -481,11 +494,11 @@ dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
int64_t remainder)
{
struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
- __GLXdisplayPrivate *dpyPriv = __glXInitialize(priv->base.psc->dpy);
+ struct glx_display *dpyPriv = __glXInitialize(priv->base.psc->dpy);
struct dri2_screen *psc = (struct dri2_screen *) priv->base.psc;
struct dri2_display *pdp =
(struct dri2_display *)dpyPriv->dri2Display;
- CARD64 ret;
+ CARD64 ret = 0;
#ifdef __DRI2_FLUSH
if (psc->f)
@@ -494,7 +507,7 @@ dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
/* Old servers don't send invalidate events */
if (!pdp->invalidateAvailable)
- dri2InvalidateBuffers(dpyPriv->dpy, pdraw->drawable);
+ dri2InvalidateBuffers(dpyPriv->dpy, pdraw->xDrawable);
/* Old servers can't handle swapbuffers */
if (!pdp->swapAvailable) {
@@ -637,16 +650,17 @@ dri2_bind_tex_image(Display * dpy,
GLXDrawable drawable,
int buffer, const int *attrib_list)
{
- GLXContext gc = __glXGetCurrentContext();
+ struct glx_context *gc = __glXGetCurrentContext();
+ struct dri2_context *pcp = (struct dri2_context *) gc;
__GLXDRIdrawable *base = GetGLXDRIDrawable(dpy, drawable);
- __GLXdisplayPrivate *dpyPriv = __glXInitialize(dpy);
+ struct glx_display *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;
- struct dri2_context *pcp = (struct dri2_context *) gc->driContext;
+ struct dri2_screen *psc;
if (pdraw != NULL) {
+ psc = (struct dri2_screen *) base->psc;
#if __DRI2_FLUSH_VERSION >= 3
if (!pdp->invalidateAvailable && psc->f)
@@ -674,6 +688,9 @@ dri2_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer)
}
static const struct glx_context_vtable dri2_context_vtable = {
+ dri2_destroy_context,
+ dri2_bind_context,
+ dri2_unbind_context,
dri2_wait_gl,
dri2_wait_x,
DRI_glXUseXFont,
@@ -710,9 +727,12 @@ 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)
+static struct glx_screen *
+dri2CreateScreen(int screen, struct glx_display * priv)
{
const __DRIconfig **driver_configs;
const __DRIextension **extensions;
@@ -803,10 +823,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;
@@ -863,7 +883,7 @@ dri2DestroyDisplay(__GLXDRIdisplay * dpy)
_X_HIDDEN __GLXDRIdrawable *
dri2GetGlxDrawableFromXDrawableId(Display *dpy, XID id)
{
- __GLXdisplayPrivate *d = __glXInitialize(dpy);
+ struct glx_display *d = __glXInitialize(dpy);
struct dri2_display *pdp = (struct dri2_display *) d->dri2Display;
__GLXDRIdrawable *pdraw;