struct dri2_context
{
- __GLXDRIcontext base;
+ __GLXcontext base;
+ __GLXDRIcontext dri_vtable;
__DRIcontext *driContext;
- __GLXscreenConfigs *psc;
};
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);
}
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;
}
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;
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);
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;
}
psp->copySubBuffer = dri2CopySubBuffer;
__glXEnableDirectExtension(&psc->base, "GLX_MESA_copy_sub_buffer");
- psc->base.direct_context_vtable = &dri2_context_vtable;
-
Xfree(driverName);
Xfree(deviceName);
struct dri_context
{
- __GLXDRIcontext base;
+ __GLXcontext base;
+ __GLXDRIcontext dri_vtable;
__DRIcontext *driContext;
XID hwContextID;
__GLXscreenConfigs *psc;
__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).
}
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);
}
static Bool
-driBindContext(__GLXDRIcontext *context,
+driBindContext(__GLXcontext *context,
__GLXDRIdrawable *draw, __GLXDRIdrawable *read)
{
struct dri_context *pcp = (struct dri_context *) 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;
(*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;
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)) {
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;
}
dlclose(psc->driver);
}
-static const struct glx_context_vtable dri_context_vtable = {
- NULL,
- NULL,
-};
-
#ifdef __DRI_SWAP_BUFFER_COUNTER
static int
psp->setSwapInterval = driSetSwapInterval;
psp->getSwapInterval = driGetSwapInterval;
- psc->base.direct_context_vtable = &dri_context_vtable;
-
return &psc->base;
}
struct drisw_context
{
- __GLXDRIcontext base;
+ __GLXcontext base;
+ __GLXDRIcontext dri_vtable;
__DRIcontext *driContext;
__GLXscreenConfigs *psc;
};
*/
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);
}
static Bool
-driBindContext(__GLXDRIcontext * context,
+driBindContext(__GLXcontext * context,
__GLXDRIdrawable * draw, __GLXDRIdrawable * read)
{
struct drisw_context *pcp = (struct drisw_context *) 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;
(*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;
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);
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;
}
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,
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
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.
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; \
*/
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)
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)
}
memset(gc, 0, sizeof(struct __GLXcontextRec));
+ gc->vtable = &indirect_context_vtable;
state = Xmalloc(sizeof(struct __GLXattributeRec));
if (state == NULL) {
/* Out of memory */
else {
gc->limit = gc->buf + bufSize - __GLX_BUFFER_LIMIT_SIZE;
}
- gc->createDpy = dpy;
gc->majorOpcode = opcode;
/*
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
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;
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) {
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
}
* 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();
}
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();
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,
};
/*@{*/
}
bindReturnValue =
- (gc->driContext->bindContext) (gc->driContext, pdraw, pread);
+ (gc->driContext->bindContext) (gc, pdraw, pread);
}
else if (!gc && oldGC && oldGC->driContext) {
bindReturnValue = True;
}
#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
#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