Re: Visbits changes have broken many things

Brian Paul <[email protected]> Mon, 31 Jan 2005 16:27:59 -0700
Newsgroups gmane.comp.graphics.chromium.devel
Message-ID <[email protected]>
Brian Paul wrote:
> Mike Houston wrote:

> Perhaps we should try to recreate the GLX context with a new visual if 
> the initial context's visual doesn't match the CRUT window's visual. I 
> think that might work.  I'll look into it.

OK, here's a patch to do that.  Apply after the previous patch.

-Brian
glx2.patch (text/plain, 2 KB)
Index: renderspu_glx.c
===================================================================
RCS file: /cvsroot/chromium/cr/spu/render/renderspu_glx.c,v
retrieving revision 1.55
diff -u -r1.55 renderspu_glx.c
--- renderspu_glx.c	29 Jan 2005 12:54:54 -0000	1.55
+++ renderspu_glx.c	31 Jan 2005 23:24:21 -0000
@@ -940,6 +940,37 @@
 }
 
 
+/**
+ * Recreate the GLX context for ContextInfo.  The new context will use the
+ * visual specified by newVisualID.
+ */
+static void
+renderspu_RecreateContext( ContextInfo *context, int newVisualID )
+{
+	XVisualInfo templateVis, *vis;
+	long templateFlags;
+	int screen = 0, count;
+
+	templateFlags = VisualScreenMask | VisualClassMask;
+	templateVis.screen = screen;
+	templateVis.visualid = newVisualID;
+	vis = XGetVisualInfo(context->visual->dpy, templateFlags, &templateVis, &count);
+	CRASSERT(vis);
+	if (!vis)
+		return;
+
+	/* destroy old context */
+	render_spu.ws.glXDestroyContext(context->visual->dpy, context->context);
+
+	/* create new context */
+	context->context = render_spu.ws.glXCreateContext(context->visual->dpy,
+																										vis, NULL,
+																										render_spu.try_direct);
+	CRASSERT(context->context);
+	XFree(vis);
+}
+
+
 void
 renderspu_SystemDestroyContext( ContextInfo *context )
 {
@@ -1084,8 +1115,20 @@
 										"0x%x because of different X visuals (0x%x != 0x%x)!",
 										context->id, (int) nativeWindow,
 										vid, (int) context->visual->visual->visualid);
+#if 0
+					/* Bind to the regular (non-CRUT) window instead */
+					render_spu.ws.glXMakeCurrent(window->visual->dpy,
+																			 window->window, context->context );
+#else
+					crWarning("Render SPU: Trying to recreate GLX context to match.");
+					renderspu_RecreateContext(context, vid);
+					/* fall-through into old else clause... */
+#endif
 				}
-				else {
+#if 0
+				else
+#endif
+				{
 					/* OK, this should work */
 					window->nativeWindow = (Window) nativeWindow;
 					b = render_spu.ws.glXMakeCurrent( window->visual->dpy,