[Xcb] GLX patches

Jeremy Kolb jkolb at brandeis.edu
Fri May 6 10:53:34 PDT 2005


Okay, here are my patches for making indirect glx work with XCB.  The 
first one for glX_proto_send.py adds support for generating the XCB code 
to handle the single requests (not vendor or render requests).

The second one for glxext.c uses XCB to send Render/RenderLarge using XCB.

All of the C code is surrounded with #ifdef/#else/#endif (symbol is 
USE_XCB).

In order to build this correctly after applying the patches you'll need 
to edit the linux-dri config file and add -DUSE_XCB to DEFINES and -lXCB 
to GL_LIB_DEPS, also change your paths to include the "Xlibs --with-xcb" 
and XCB.


Jeremy
-------------- next part --------------
Index: glX_proto_send.py
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/glapi/glX_proto_send.py,v
retrieving revision 1.24
diff -u -d -r1.24 glX_proto_send.py
--- glX_proto_send.py	18 Apr 2005 19:42:23 -0000	1.24
+++ glX_proto_send.py	6 May 2005 17:50:08 -0000
@@ -120,6 +120,12 @@
 		print '#include "glxclient.h"'
 		print '#include "indirect_size.h"'
 		print '#include <GL/glxproto.h>'
+		print '#ifdef USE_XCB'
+		print '#include <X11/xcl.h>'
+		print '#include <X11/XCB/xcb.h>'
+		print '#include <X11/XCB/glx.h>'
+		print '#endif /* USE_XCB */'
+		
 		print ''
 		print '#define __GLX_PAD(n) (((n) + 3) & ~3)'
 		print ''
@@ -411,10 +417,57 @@
 
 	def printSingleFunction(self, f):
 		self.common_func_print_header(f)
-
+		
 		if self.debug:
 			print '        printf( "Enter %%s...\\n", "gl%s" );' % (f.name)
+		if f.glx_vendorpriv == 0 and f.opcode_name()[-3:] != "ARB" and f.opcode_name()[-2:] != "NV":
+
+			# XCB specific:
+			print '#ifdef USE_XCB'
+			if self.debug:
+				print '        printf("\\tUsing XCB.\\n");'
+			print '        XCBConnection *c = XCBConnectionOfDisplay(dpy);'
+			print '        (void) __glXFlushRenderBuffer(gc, gc->pc);'
+			xcb_name = 'XCBGlx%s' % (f.opcode_name().rsplit("_", 1)[1]);
+			iparams=[]
+			for p in f.fn_parameters:
+				if p.is_output == 0:
+					iparams.append(p.name)
+
+			if f.image and f.image.is_output:
+				if f.image.img_format != "GL_COLOR_INDEX" or f.image.img_type != "GL_BITMAP":
+					iparams.append("state->storePack.swapEndian")
+				else:
+					iparams.append("0")
+					
+				# Hardcode this in.  lsb_first param (apparently always GL_FALSE)
+				# also present in GetPolygonStipple, but taken care of above.
+				if xcb_name == "XCBGlxReadPixels": iparams.append("0")
+			    
+			xcb_request = '%s(%s)' % (xcb_name, ", ".join(["c", "gc->currentContextTag"] + iparams))
 
+			if f.needs_reply():
+				print '        %sRep *reply = %sReply(c, %s, NULL);' % (xcb_name, xcb_name, xcb_request)
+				if f.output and f.reply_always_array:
+					print '        %s = (%s *)%sData(reply);' % (f.output.name, f.output.p_type.name, xcb_name)
+				elif f.output and not f.reply_always_array:
+					if not f.image:
+						print '        if (%sDataLength(reply) == 0)' % (xcb_name)
+						print '            %s = (%s *) &reply->datum;' % (f.output.name, f.output.p_type.name)
+						print '        else'
+						print '            %s = (%s *)%sData(reply);' % (f.output.name, f.output.p_type.name, xcb_name)
+					else:
+						print '        %s = (%s *)%sData(reply);' % (f.output.name, f.output.p_type.name, xcb_name)
+
+
+				if f.fn_return_type != 'void':
+					print '        retval = reply->ret_val;'
+				print '        free(reply);'
+			else:
+				print '        ' + xcb_request + ';'
+			print '#else'
+			# End of XCB specific.
+		
 		if f.fn_parameters != []:
 			pc_decl = "GLubyte const * pc ="
 		else:
@@ -472,11 +525,13 @@
 			# that don't already require a reply from the server.
 			print '        __indirect_glFinish();'
 
+		print '        UnlockDisplay(dpy); SyncHandle();'
+		
+		if f.glx_vendorpriv == 0 and f.opcode_name()[-3:] != "ARB" and f.opcode_name()[-2:] != "NV":
+			print '#endif /* USE_XCB */'
+			
 		if self.debug:
 			print '        printf( "Exit %%s.\\n", "gl%s" );' % (f.name)
-
-
-		print '        UnlockDisplay(dpy); SyncHandle();'
 		print '    }'
 		print '    %s' % f.return_string()
 		print '}'
@@ -678,7 +733,7 @@
 		# regular.  Since they are so regular and there are so many
 		# of them, special case them with generic functions.  On
 		# x86, this saves about 26KB in the libGL.so binary.
-
+		
 		if f.variable_length_parameter() == None and len(f.fn_parameters) == 1:
 			p = f.fn_parameters[0]
 			if p.is_pointer:
-------------- next part --------------
Index: glxext.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/glx/x11/glxext.c,v
retrieving revision 1.8
diff -u -d -r1.8 glxext.c
--- glxext.c	18 Apr 2005 16:59:53 -0000	1.8
+++ glxext.c	6 May 2005 06:07:33 -0000
@@ -68,6 +68,12 @@
 #include "dri_glx.h"
 #endif
 
+#ifdef USE_XCB
+#include <X11/xcl.h>
+#include <X11/XCB/xcb.h>
+#include <X11/XCB/glx.h>
+#endif
+
 #include <assert.h>
 
 #ifdef DEBUG
@@ -1047,7 +1053,7 @@
 	    fb_req->glxCode = X_GLXGetFBConfigs;
 	    fb_req->screen = i;
 	    break;
-	    
+	   
 	    case 2:
 	    GetReqExtra(GLXVendorPrivateWithReply,
 			sz_xGLXGetFBConfigsSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq);
@@ -1349,10 +1355,17 @@
 GLubyte *__glXFlushRenderBuffer(__GLXcontext *ctx, GLubyte *pc)
 {
     Display * const dpy = ctx->currentDpy;
+#ifdef USE_XCB
+    XCBConnection *c = XCBConnectionOfDisplay(dpy);
+#else
     xGLXRenderReq *req;
+#endif /* USE_XCB */
     const GLint size = pc - ctx->buf;
 
     if ( (dpy != NULL) && (size > 0) ) {
+#ifdef USE_XCB
+	XCBGlxRender(c, ctx->currentContextTag, size, (char *)ctx->buf);
+#else
 	/* Send the entire buffer as an X request */
 	LockDisplay(dpy);
 	GetReq(GLXRender,req); 
@@ -1363,6 +1376,7 @@
 	_XSend(dpy, (char *)ctx->buf, size);
 	UnlockDisplay(dpy);
 	SyncHandle();
+#endif
     }
 
     /* Reset pointer and return it */
@@ -1392,8 +1406,12 @@
 			 const GLvoid * data, GLint dataLen)
 {
     Display *dpy = gc->currentDpy;
+#ifdef USE_XCB
+    XCBConnection *c = XCBConnectionOfDisplay(dpy);
+    XCBGlxRenderLarge(c, gc->currentContextTag, requestNumber, totalRequests, dataLen, data);
+#else
     xGLXRenderLargeReq *req;
-
+    
     if ( requestNumber == 1 ) {
 	LockDisplay(dpy);
     }
@@ -1412,6 +1430,7 @@
 	UnlockDisplay(dpy);
 	SyncHandle();
     }
+#endif /* USE_XCB */
 }
 
 


More information about the xcb mailing list