glx: Split tfp functions out to context vtable

This introduces a new per-context vtable, which lets us clean up all the
#ifdef's a bit and move the DRI2 specific implementation into dri2_glx.c.
This commit is contained in:
Kristian Høgsberg
2010-05-21 10:36:56 -04:00
parent 4db0c76019
commit 643b2af020
4 changed files with 99 additions and 40 deletions
+36
View File
@@ -563,6 +563,40 @@ dri2InvalidateBuffers(Display *dpy, XID drawable)
#endif
}
static void
dri2_bind_tex_image(Display * dpy,
GLXDrawable drawable,
int buffer, const int *attrib_list)
{
GLXContext gc = __glXGetCurrentContext();
__GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);
if (pdraw != NULL) {
if (pdraw->psc->texBuffer->base.version >= 2 &&
pdraw->psc->texBuffer->setTexBuffer2 != NULL) {
(*pdraw->psc->texBuffer->setTexBuffer2) (gc->__driContext,
pdraw->textureTarget,
pdraw->textureFormat,
pdraw->driDrawable);
}
else {
(*pdraw->psc->texBuffer->setTexBuffer) (gc->__driContext,
pdraw->textureTarget,
pdraw->driDrawable);
}
}
}
static void
dri2_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer)
{
}
static const struct glx_context_vtable dri2_context_vtable = {
dri2_bind_tex_image,
dri2_release_tex_image,
};
static __GLXDRIscreen *
dri2CreateScreen(__GLXscreenConfigs * psc, int screen,
__GLXdisplayPrivate * priv)
@@ -683,6 +717,8 @@ dri2CreateScreen(__GLXscreenConfigs * psc, int screen,
psp->copySubBuffer = dri2CopySubBuffer;
__glXEnableDirectExtension(psc, "GLX_MESA_copy_sub_buffer");
psc->direct_context_vtable = &dri2_context_vtable;
Xfree(driverName);
Xfree(deviceName);
+7
View File
@@ -634,6 +634,11 @@ driDestroyScreen(__GLXscreenConfigs * psc)
dlclose(psc->driver);
}
static const struct glx_context_vtable dri_context_vtable = {
NULL,
NULL,
};
static __GLXDRIscreen *
driCreateScreen(__GLXscreenConfigs * psc, int screen,
__GLXdisplayPrivate * priv)
@@ -700,6 +705,8 @@ driCreateScreen(__GLXscreenConfigs * psc, int screen,
psp->waitX = NULL;
psp->waitGL = NULL;
psc->direct_context_vtable = &dri_context_vtable;
return psp;
}
+15
View File
@@ -249,6 +249,14 @@ typedef struct __GLXattributeMachineRec
__GLXattribute **stackPointer;
} __GLXattributeMachine;
struct glx_context_vtable {
void (*bind_tex_image)(Display * dpy,
GLXDrawable drawable,
int buffer, const int *attrib_list);
void (*release_tex_image)(Display * dpy, GLXDrawable drawable, int buffer);
};
/**
* 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.
@@ -457,6 +465,8 @@ struct __GLXcontextRec
unsigned long thread_id;
char gl_extension_bits[__GL_EXT_BYTES];
const struct glx_context_vtable *vtable;
};
#define __glXSetError(gc,code) \
@@ -511,6 +521,11 @@ struct __GLXscreenConfigsRec
*/
char *effectiveGLXexts;
/**
* Context vtable to use for direct contexts on this screen
*/
const struct glx_context_vtable *direct_context_vtable;
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
/**
* Per screen direct rendering interface functions and data.
+41 -40
View File
@@ -62,9 +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;
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
@@ -378,13 +376,10 @@ CreateContext(Display * dpy, int generic_id,
unsigned code, int renderType, int screen)
{
GLXContext gc;
#ifdef GLX_DIRECT_RENDERING
#ifdef GLX_USE_APPLEGL
__GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen);
#if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_APPLEGL)
int errorcode;
bool x11error;
#else
__GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen);
#endif
#endif
if (dpy == NULL)
@@ -411,6 +406,11 @@ CreateContext(Display * dpy, int generic_id,
}
#endif
if (gc->driContext != NULL)
gc->vtable = psc->direct_context_vtable;
else
gc->vtable = &glx_indirect_context_vtable;
LockDisplay(dpy);
switch (code) {
case X_GLXCreateContext: {
@@ -2997,10 +2997,10 @@ __glXCopySubBufferMESA(Display * dpy, GLXDrawable drawable,
/**
* GLX_EXT_texture_from_pixmap
*/
/*@{*/
static void
__glXBindTexImageEXT(Display * dpy,
GLXDrawable drawable, int buffer, const int *attrib_list)
glx_indirect_bind_tex_image(Display * dpy,
GLXDrawable drawable,
int buffer, const int *attrib_list)
{
xGLXVendorPrivateReq *req;
GLXContext gc = __glXGetCurrentContext();
@@ -3011,37 +3011,12 @@ __glXBindTexImageEXT(Display * dpy,
CARD8 opcode;
unsigned int i;
if (gc == NULL)
return;
i = 0;
if (attrib_list) {
while (attrib_list[i * 2] != None)
i++;
}
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
if (gc->driContext) {
__GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);
if (pdraw != NULL) {
if (pdraw->psc->texBuffer->base.version >= 2 &&
pdraw->psc->texBuffer->setTexBuffer2 != NULL) {
(*pdraw->psc->texBuffer->setTexBuffer2) (gc->__driContext,
pdraw->textureTarget,
pdraw->textureFormat,
pdraw->driDrawable);
}
else {
(*pdraw->psc->texBuffer->setTexBuffer) (gc->__driContext,
pdraw->textureTarget,
pdraw->driDrawable);
}
}
return;
}
#endif
opcode = __glXSetupForCommand(dpy);
if (!opcode)
return;
@@ -3076,7 +3051,7 @@ __glXBindTexImageEXT(Display * dpy,
}
static void
__glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer)
glx_indirect_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer)
{
xGLXVendorPrivateReq *req;
GLXContext gc = __glXGetCurrentContext();
@@ -3084,9 +3059,6 @@ __glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer)
INT32 *buffer_ptr;
CARD8 opcode;
if ((gc == NULL) || GC_IS_DIRECT(gc))
return;
opcode = __glXSetupForCommand(dpy);
if (!opcode)
return;
@@ -3108,6 +3080,35 @@ __glXReleaseTexImageEXT(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 void
__glXBindTexImageEXT(Display * dpy,
GLXDrawable drawable, int buffer, const int *attrib_list)
{
GLXContext gc = __glXGetCurrentContext();
if (gc == NULL || gc->vtable->bind_tex_image == NULL)
return;
gc->vtable->bind_tex_image(dpy, drawable, buffer, attrib_list);
}
static void
__glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer)
{
GLXContext gc = __glXGetCurrentContext();
if (gc == NULL || gc->vtable->release_tex_image == NULL)
return;
gc->vtable->release_tex_image(dpy, drawable, buffer);
}
/*@}*/
#endif /* GLX_USE_APPLEGL */