glx: Split tfp functions out to context vtable
authorKristian Høgsberg <krh@bitplanet.net>
Fri, 21 May 2010 14:36:56 +0000 (10:36 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Sat, 22 May 2010 03:24:37 +0000 (23:24 -0400)
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.

src/glx/dri2_glx.c
src/glx/dri_glx.c
src/glx/glxclient.h
src/glx/glxcmds.c

index 45959915b4b40c69259e182cf6242d9a27ff9294..ba546a6bc1ceb5e280d9e50836fb33b788907e13 100644 (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);
 
index 74afa60301d6123879da9b1177b51e78be1669fd..12a2cf3af24585a177ed47db66121bcd017b0de9 100644 (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;
 }
 
index 57d254ea9873f54fe3ecae6e5ef0cb979d7c6735..78c5f33d4d57089be807857d1b2c7b9527d9653c 100644 (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.
index 34fbecf95634d75b8f786033d7cba3302a48f300..16c4eef6ba8fdd92bc46d9d450f9617b02034750 100644 (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 */