467d5d
From 3ef4be8129f78afd5566a9e5d0fb901449dcb771 Mon Sep 17 00:00:00 2001
467d5d
From: Ian Romanick <ian.d.romanick@intel.com>
467d5d
Date: Tue, 29 Sep 2009 16:43:43 -0700
467d5d
Subject: [PATCH] GLX: Enable GLX 1.4 on DRI2
467d5d
467d5d
this squashes 4 commits
467d5d
(cherry picked from commit ad5c0d9efa47476ed5cf75c82265c73919e468b4)
467d5d
(cherry picked from commit cb54cf1b3e8c4109541cfb698542c00f2473e731)
467d5d
(cherry picked from commit 4c6bfa2c09ae2b0cffdf9211a6dfbcaefe0366b5)
467d5d
(cherry picked from commit 9bf2ff4faf730913de3073f346646a8727be41d4)
467d5d
---
467d5d
 glx/glxcmds.c                      |   12 ++++++++----
467d5d
 glx/glxdri2.c                      |   12 ++++++++++++
467d5d
 glx/glxext.c                       |    8 +++++++-
467d5d
 glx/glxscreens.c                   |   15 ++++++++++++---
467d5d
 glx/glxscreens.h                   |   11 +++++++++++
467d5d
 glx/glxserver.h                    |    3 +++
467d5d
 glx/indirect_texture_compression.c |    4 ++--
467d5d
 include/protocol-versions.h        |    2 +-
467d5d
 8 files changed, 56 insertions(+), 11 deletions(-)
467d5d
467d5d
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
467d5d
index b1061a8..ba4c123 100644
467d5d
--- a/glx/glxcmds.c
467d5d
+++ b/glx/glxcmds.c
467d5d
@@ -50,7 +50,6 @@
467d5d
 #include "indirect_dispatch.h"
467d5d
 #include "indirect_table.h"
467d5d
 #include "indirect_util.h"
467d5d
-#include "protocol-versions.h"
467d5d
 
467d5d
 static int
467d5d
 validGlxScreen(ClientPtr client, int screen, __GLXscreen **pGlxScreen, int *err)
467d5d
@@ -739,8 +738,8 @@ int __glXDisp_QueryVersion(__GLXclientState *cl, GLbyte *pc)
467d5d
     ** client if it wants to work with older clients; however, in this
467d5d
     ** implementation the server just returns its version number.
467d5d
     */
467d5d
-    reply.majorVersion = SERVER_GLX_MAJOR_VERSION;
467d5d
-    reply.minorVersion = SERVER_GLX_MINOR_VERSION;
467d5d
+    reply.majorVersion = glxMajorVersion;
467d5d
+    reply.minorVersion = glxMinorVersion;
467d5d
     reply.length = 0;
467d5d
     reply.type = X_Reply;
467d5d
     reply.sequenceNumber = client->sequence;
467d5d
@@ -2360,6 +2359,7 @@ int __glXDisp_QueryServerString(__GLXclientState *cl, GLbyte *pc)
467d5d
     char *buf;
467d5d
     __GLXscreen *pGlxScreen;
467d5d
     int err;
467d5d
+    char ver_str[16];
467d5d
 
467d5d
     if (!validGlxScreen(client, req->screen, &pGlxScreen, &err))
467d5d
 	return err;
467d5d
@@ -2369,7 +2369,11 @@ int __glXDisp_QueryServerString(__GLXclientState *cl, GLbyte *pc)
467d5d
 	    ptr = pGlxScreen->GLXvendor;
467d5d
 	    break;
467d5d
 	case GLX_VERSION:
467d5d
-	    ptr = pGlxScreen->GLXversion;
467d5d
+	    /* Return to the server version rather than the screen version
467d5d
+	     * to prevent confusion when they do not match.
467d5d
+	     */
467d5d
+	    snprintf(ver_str, 16, "%d.%d", glxMajorVersion, glxMinorVersion);
467d5d
+	    ptr = ver_str;
467d5d
 	    break;
467d5d
 	case GLX_EXTENSIONS:
467d5d
 	    ptr = pGlxScreen->GLXextensions;
467d5d
diff --git a/glx/glxdri2.c b/glx/glxdri2.c
467d5d
index ed7fb4c..ed7dc80 100644
467d5d
--- a/glx/glxdri2.c
467d5d
+++ b/glx/glxdri2.c
467d5d
@@ -685,6 +685,18 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
467d5d
 				       screen->base.GLXextensions);
467d5d
     }
467d5d
 
467d5d
+    /* We're going to assume (perhaps incorrectly?) that all DRI2-enabled
467d5d
+     * drivers support the required extensions for GLX 1.4.  The extensions
467d5d
+     * we're assuming are:
467d5d
+     *
467d5d
+     *    - GLX_SGI_make_current_read (1.3)
467d5d
+     *    - GLX_SGIX_fbconfig (1.3)
467d5d
+     *    - GLX_SGIX_pbuffer (1.3)
467d5d
+     *    - GLX_ARB_multisample (1.4)
467d5d
+     */
467d5d
+    screen->base.GLXmajor = 1;
467d5d
+    screen->base.GLXminor = 4;
467d5d
+
467d5d
     screen->enterVT = pScrn->EnterVT;
467d5d
     pScrn->EnterVT = glxDRIEnterVT; 
467d5d
     screen->leaveVT = pScrn->LeaveVT;
467d5d
diff --git a/glx/glxext.c b/glx/glxext.c
467d5d
index 19d70d4..9f9c0ed 100644
467d5d
--- a/glx/glxext.c
467d5d
+++ b/glx/glxext.c
467d5d
@@ -360,12 +360,18 @@ void GlxExtensionInit(void)
467d5d
 	pScreen = screenInfo.screens[i];
467d5d
 
467d5d
 	for (p = __glXProviderStack; p != NULL; p = p->next) {
467d5d
-	    if (p->screenProbe(pScreen) != NULL) {
467d5d
+	    __GLXscreen *glxScreen;
467d5d
+
467d5d
+	    glxScreen = p->screenProbe(pScreen);
467d5d
+	    if (glxScreen != NULL) {
467d5d
+	        if (glxScreen->GLXminor < glxMinorVersion)
467d5d
+		    glxMinorVersion = glxScreen->GLXminor;
467d5d
 		LogMessage(X_INFO,
467d5d
 			   "GLX: Initialized %s GL provider for screen %d\n",
467d5d
 			   p->name, i);
467d5d
 		break;
467d5d
 	    }
467d5d
+
467d5d
 	}
467d5d
 
467d5d
 	if (!p)
467d5d
diff --git a/glx/glxscreens.c b/glx/glxscreens.c
467d5d
index 7d29d31..674e2c6 100644
467d5d
--- a/glx/glxscreens.c
467d5d
+++ b/glx/glxscreens.c
467d5d
@@ -42,6 +42,7 @@
467d5d
 #include "glxserver.h"
467d5d
 #include "glxutil.h"
467d5d
 #include "glxext.h"
467d5d
+#include "protocol-versions.h"
467d5d
 
467d5d
 static int glxScreenPrivateKeyIndex;
467d5d
 static DevPrivateKey glxScreenPrivateKey = &glxScreenPrivateKeyIndex;
467d5d
@@ -162,7 +163,8 @@ static const char GLServerExtensions[] =
467d5d
 ** supported across all screens in a multi-screen system.
467d5d
 */
467d5d
 static char GLXServerVendorName[] = "SGI";
467d5d
-static char GLXServerVersion[] = "1.2";
467d5d
+unsigned glxMajorVersion = SERVER_GLX_MAJOR_VERSION;
467d5d
+unsigned glxMinorVersion = SERVER_GLX_MINOR_VERSION;
467d5d
 static char GLXServerExtensions[] =
467d5d
 			"GLX_ARB_multisample "
467d5d
 			"GLX_EXT_visual_info "
467d5d
@@ -378,9 +380,17 @@ void __glXScreenInit(__GLXscreen *pGlxScreen, ScreenPtr pScreen)
467d5d
     pGlxScreen->pScreen       = pScreen;
467d5d
     pGlxScreen->GLextensions  = xstrdup(GLServerExtensions);
467d5d
     pGlxScreen->GLXvendor     = xstrdup(GLXServerVendorName);
467d5d
-    pGlxScreen->GLXversion    = xstrdup(GLXServerVersion);
467d5d
     pGlxScreen->GLXextensions = xstrdup(GLXServerExtensions);
467d5d
 
467d5d
+    /* All GLX providers must support all of the functionality required for at
467d5d
+     * least GLX 1.2.  If the provider supports a higher version, the GLXminor
467d5d
+     * version can be changed in the provider's screen-probe routine.  For
467d5d
+     * most providers, the screen-probe routine is the caller of this
467d5d
+     * function.
467d5d
+     */
467d5d
+    pGlxScreen->GLXmajor      = 1;
467d5d
+    pGlxScreen->GLXminor      = 2;
467d5d
+
467d5d
     pGlxScreen->CloseScreen = pScreen->CloseScreen;
467d5d
     pScreen->CloseScreen = glxCloseScreen;
467d5d
     pGlxScreen->DestroyWindow = pScreen->DestroyWindow;
467d5d
@@ -454,7 +464,6 @@ void __glXScreenInit(__GLXscreen *pGlxScreen, ScreenPtr pScreen)
467d5d
 void __glXScreenDestroy(__GLXscreen *screen)
467d5d
 {
467d5d
     xfree(screen->GLXvendor);
467d5d
-    xfree(screen->GLXversion);
467d5d
     xfree(screen->GLXextensions);
467d5d
     xfree(screen->GLextensions);
467d5d
 }
467d5d
diff --git a/glx/glxscreens.h b/glx/glxscreens.h
467d5d
index 3c1bdd4..bff4363 100644
467d5d
--- a/glx/glxscreens.h
467d5d
+++ b/glx/glxscreens.h
467d5d
@@ -161,6 +161,17 @@ struct __GLXscreen {
467d5d
     char *GLXversion;
467d5d
     char *GLXextensions;
467d5d
 
467d5d
+    /**
467d5d
+     * \name GLX version supported by this screen.
467d5d
+     *
467d5d
+     * Since the GLX version advertised by the server is for the whole server,
467d5d
+     * the GLX protocol code uses the minimum version supported on all screens.
467d5d
+     */
467d5d
+    /*@{*/
467d5d
+    unsigned GLXmajor;
467d5d
+    unsigned GLXminor;
467d5d
+    /*@}*/
467d5d
+
467d5d
     Bool (*CloseScreen)(int index, ScreenPtr pScreen);
467d5d
     Bool (*DestroyWindow)(WindowPtr pWindow);
467d5d
 };
467d5d
diff --git a/glx/glxserver.h b/glx/glxserver.h
467d5d
index 4aa8c2e..80f1b28 100644
467d5d
--- a/glx/glxserver.h
467d5d
+++ b/glx/glxserver.h
467d5d
@@ -248,4 +248,7 @@ extern int __glXImageSize(GLenum format, GLenum type,
467d5d
     GLint imageHeight, GLint rowLength, GLint skipImages, GLint skipRows,
467d5d
     GLint alignment);
467d5d
 
467d5d
+extern unsigned glxMajorVersion;
467d5d
+extern unsigned glxMinorVersion;
467d5d
+
467d5d
 #endif /* !__GLX_server_h__ */
467d5d
diff --git a/glx/indirect_texture_compression.c b/glx/indirect_texture_compression.c
467d5d
index 25c6eb3..5f44d7b 100644
467d5d
--- a/glx/indirect_texture_compression.c
467d5d
+++ b/glx/indirect_texture_compression.c
467d5d
@@ -52,7 +52,7 @@ int __glXDisp_GetCompressedTexImageARB(struct __GLXclientStateRec *cl, GLbyte *p
467d5d
 	const GLenum target = *(GLenum *)(pc + 0);
467d5d
 	const GLint  level  = *(GLint  *)(pc + 4);
467d5d
 	GLint compsize = 0;
467d5d
-	char *answer, answerBuffer[200];
467d5d
+	char *answer = NULL, answerBuffer[200];
467d5d
 
467d5d
 	CALL_GetTexLevelParameteriv(GET_DISPATCH(), (target, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compsize));
467d5d
 
467d5d
@@ -92,7 +92,7 @@ int __glXDispSwap_GetCompressedTexImageARB(struct __GLXclientStateRec *cl, GLbyt
467d5d
 	const GLenum target = (GLenum) bswap_32( *(int *)(pc + 0) );
467d5d
 	const GLint  level =  (GLint ) bswap_32( *(int *)(pc + 4) );
467d5d
 	GLint compsize = 0;
467d5d
-	char *answer, answerBuffer[200];
467d5d
+	char *answer = NULL, answerBuffer[200];
467d5d
 
467d5d
 	CALL_GetTexLevelParameteriv(GET_DISPATCH(), (target, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compsize));
467d5d
 
467d5d
diff --git a/include/protocol-versions.h b/include/protocol-versions.h
467d5d
index da9770c..d688c66 100644
467d5d
--- a/include/protocol-versions.h
467d5d
+++ b/include/protocol-versions.h
467d5d
@@ -61,7 +61,7 @@
467d5d
 
467d5d
 /* GLX */
467d5d
 #define SERVER_GLX_MAJOR_VERSION		1
467d5d
-#define SERVER_GLX_MINOR_VERSION		2
467d5d
+#define SERVER_GLX_MINOR_VERSION		4
467d5d
 
467d5d
 /* Xinerama */
467d5d
 #define SERVER_PANORAMIX_MAJOR_VERSION          1
467d5d
-- 
467d5d
1.6.5.rc2
467d5d