[cairo-commit] gtkcairo/gtkcairo gdkcairo.c,1.7,1.8

David Reveman commit at pdx.freedesktop.org
Fri Nov 12 03:47:48 PST 2004


Committed by: davidr

Update of /cvs/cairo/gtkcairo/gtkcairo
In directory gabe:/tmp/cvs-serv23528/gtkcairo

Modified Files:
	gdkcairo.c 
Log Message:
Better glitz backend support

Index: gdkcairo.c
===================================================================
RCS file: /cvs/cairo/gtkcairo/gtkcairo/gdkcairo.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- gdkcairo.c	11 Nov 2004 09:05:22 -0000	1.7
+++ gdkcairo.c	12 Nov 2004 11:47:46 -0000	1.8
@@ -136,56 +136,92 @@
         #endif
         #ifdef USE_GL
         case GDKCAIRO_BACKEND_GL: {
-	        Display *dpy = gdk_x11_get_default_xdisplay ();
-	        int screen = gdk_x11_get_default_screen ();
+	    Display *dpy = gdk_x11_get_default_xdisplay ();
+	    int screen = gdk_x11_get_default_screen ();
             XVisualInfo *vinfo;
-	        glitz_format_t *onscreen_format;
-		glitz_format_t templ;
-		unsigned long mask;
+	    glitz_drawable_format_t *dformat;
+	    glitz_drawable_format_t templ;
+	    unsigned long mask;
+	    char *GTKCAIRO_GL_DOUBLEBUFFER;
+	    char *GTKCAIRO_GL_SAMPLES;
 
-		templ.doublebuffer = 1;
-		mask = GLITZ_FORMAT_DOUBLEBUFFER_MASK;
+	    GTKCAIRO_GL_DOUBLEBUFFER = getenv ("GTKCAIRO_GL_DOUBLEBUFFER");
+	    GTKCAIRO_GL_SAMPLES = getenv ("GTKCAIRO_GL_SAMPLES");
 
-		templ.draw.onscreen = 1;
-		mask |= GLITZ_FORMAT_DRAW_ONSCREEN_MASK;
+	    templ.types.window = 1;
+	    mask = GLITZ_FORMAT_WINDOW_MASK;
 
-		templ.multisample.samples = 4;
-		mask |= GLITZ_FORMAT_MULTISAMPLE_SAMPLES_MASK;
+	    if (GTKCAIRO_GL_DOUBLEBUFFER) {
+		if (atoi (GTKCAIRO_GL_DOUBLEBUFFER))
+		    templ.doublebuffer = 1;
+		else
+		    templ.doublebuffer = 0;
+		    
+		mask |= GLITZ_FORMAT_DOUBLEBUFFER_MASK;
+	    }
 
-	        onscreen_format =
-		    glitz_glx_find_format (dpy, screen, mask, &templ, 0);
-	        if (!onscreen_format) {
-		    mask &= ~GLITZ_FORMAT_MULTISAMPLE_SAMPLES_MASK;
+	    if (GTKCAIRO_GL_SAMPLES) {
+		templ.samples = atoi (GTKCAIRO_GL_SAMPLES);
+
+		/* less than 1 sample is not possible */
+		if (templ.samples < 1)
+		    templ.samples = 1;
+		    
+		mask |= GLITZ_FORMAT_SAMPLES_MASK;
+	    }
+	    
+	    dformat =
+		glitz_glx_find_drawable_format (dpy, screen, mask, &templ, 0);
+	    
+	    if (dformat) {
+		glitz_drawable_t *drawable;
+		glitz_format_t *format;
+		XID xid;
 		
-		    onscreen_format =
-			glitz_glx_find_format (dpy, screen, mask, &templ, 0);
-		}
+		vinfo = glitz_glx_get_visual_info_from_format (dpy, screen,
+							       dformat);
+		gtk_widget_set_double_buffered (widget, FALSE);
+		attributes.visual = gdkx_visual_get (vinfo->visualid);
+		attributes.colormap =
+		    gdk_colormap_new (attributes.visual, TRUE);
 		
-	        /*  XSetWindowAttributes xswa;*/
+		attributes_mask =
+		    GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+		
+		widget->window =
+		    gdk_window_new (gtk_widget_get_parent_window (widget),
+				    &attributes, attributes_mask);
 
-	        if (onscreen_format) {
-              vinfo = glitz_glx_get_visual_info_from_format (dpy, screen, onscreen_format);
-              gtk_widget_set_double_buffered (widget, FALSE);
-              attributes.visual = gdkx_visual_get (vinfo->visualid);
-              attributes.colormap = gdk_colormap_new (attributes.visual, TRUE);
+		xid = gdk_x11_drawable_get_xid (widget->window);
 
-		      attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+		drawable =
+		    glitz_glx_create_drawable_for_window (dpy, screen,
+							  dformat, xid,
+							  attributes.width,
+							  attributes.height);
+		format = glitz_find_standard_format (drawable,
+						     GLITZ_STANDARD_ARGB32);
+		self->glitz_surface =
+		    glitz_surface_create (drawable,
+					  format,
+					  attributes.width,
+					  attributes.height);
 
-		      widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
-			                                   &attributes, attributes_mask);
-                self->glitz_surface =
-                glitz_glx_surface_create_for_window (dpy, screen,
-						     onscreen_format,
-						     gdk_x11_drawable_get_xid (widget->window),
-						     attributes.width,
-						     attributes.height);
+		glitz_surface_attach (self->glitz_surface,
+				      drawable,
+				      (dformat->doublebuffer) ?
+				      GLITZ_DRAWABLE_BUFFER_BACK_COLOR:
+				      GLITZ_DRAWABLE_BUFFER_FRONT_COLOR,
+				      0, 0);
 
-              cairo_set_target_glitz (self->cr, self->glitz_surface);
+		glitz_drawable_destroy (drawable);
+					  
+		cairo_set_target_glitz (self->cr, self->glitz_surface);
             } else {
-            g_error ("could not find a usable GL visual\n");
-            self->backend = GDKCAIRO_BACKEND_XLIB;
-            goto retry;
-             }
+		g_warning ("could not find a usable GL visual\n");
+		self->backend = GDKCAIRO_BACKEND_XLIB;
+		goto retry;
+	    }
             }
             break;
         #endif
@@ -217,18 +253,29 @@
            case GDKCAIRO_BACKEND_GL:
             if (self->glitz_surface) {
 		glitz_format_t *format;
+		glitz_drawable_t *drawable;
+		glitz_drawable_format_t *dformat;
 
 		format = glitz_surface_get_format (self->glitz_surface);
+		drawable = glitz_surface_get_drawable (self->glitz_surface);
+		dformat = glitz_drawable_get_format (drawable);
 		
 		glitz_surface_destroy (self->glitz_surface);
-		
+
+		glitz_drawable_update_size (drawable, width, height);
+
 		self->glitz_surface =
-		    glitz_glx_surface_create_for_window (gdk_x11_get_default_xdisplay (),
-							 gdk_x11_get_default_screen (),
-							 format,
-							 gdk_x11_drawable_get_xid (self->widget->window),
-							 width,
-							 height);
+		    glitz_surface_create (drawable, format, width, height);
+
+		glitz_surface_attach (self->glitz_surface,
+				      drawable,
+				      (dformat->doublebuffer) ?
+				      GLITZ_DRAWABLE_BUFFER_BACK_COLOR:
+				      GLITZ_DRAWABLE_BUFFER_FRONT_COLOR,
+				      0, 0);
+		
+		glitz_drawable_destroy (drawable);
+		
 		cairo_set_target_glitz (self->cr, self->glitz_surface);
             }
 	    
@@ -253,6 +300,8 @@
     switch (self->backend) {
         #ifdef USE_GL
         case GDKCAIRO_BACKEND_GL:{
+	    glitz_drawable_t *drawable;
+	    glitz_drawable_format_t *dformat;
 
             cairo_rectangle (self->cr, 0, 0, widget->allocation.width, widget->allocation.height);
             cairo_set_rgb_color (self->cr, 0.7, 0.7, 0.7);  /* FIXME: use color from style */
@@ -260,9 +309,16 @@
               &(self->widget->style->bg[GTK_STATE_NORMAL]) );
             cairo_fill      (self->cr);
 
-	        g_signal_emit_by_name (self->widget, "paint", self->cr);
-            glitz_surface_swap_buffers (self->glitz_surface);
-            XSync (gdk_x11_get_default_xdisplay (), 0);
+	    g_signal_emit_by_name (self->widget, "paint", self->cr);
+
+	    drawable = glitz_surface_get_drawable (self->glitz_surface);
+	    dformat = glitz_drawable_get_format (drawable);
+
+	    if (!dformat->doublebuffer) {
+		glitz_surface_flush (self->glitz_surface);
+		glitz_drawable_flush (drawable);
+	    } else
+		glitz_drawable_swap_buffers (drawable);
         }break;
         #endif
         #ifdef CAIRO_HAS_XLIB_SURFACE




More information about the cairo-commit mailing list