[cairo-commit] gtkcairo/gtkcairo gtkcairo.c,1.5,1.6 gtkcairo.h,1.4,1.5

OEyvind Kolaas commit at pdx.freedesktop.org
Mon Aug 15 11:12:59 PDT 2005


Committed by: pippin

Update of /cvs/cairo/gtkcairo/gtkcairo
In directory pdx:/tmp/cvs-serv2020/gtkcairo

Modified Files:
	gtkcairo.c gtkcairo.h 
Log Message:
Initial checkin of glx aware cairo code


Index: gtkcairo.c
===================================================================
RCS file: /cvs/cairo/gtkcairo/gtkcairo/gtkcairo.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** gtkcairo.c	14 Feb 2004 17:04:58 -0000	1.5
--- gtkcairo.c	15 Feb 2004 17:46:28 -0000	1.6
***************
*** 107,111 ****
  static void
  gtk_cairo_init (GtkCairo *gtkcairo)
! {
  	gtkcairo->cairo = cairo_create ();
  }
--- 107,118 ----
  static void
  gtk_cairo_init (GtkCairo *gtkcairo)
! {      
! #ifdef CAIRO_HAS_GLX_SURFACE
!     gtkcairo->glx = 1;
!     gtkcairo->surface = NULL;
! #endif
! #ifndef CAIRO_HAS_GLX_SURFACE
!     gtkcairo->glx = 0;
! #endif    
  	gtkcairo->cairo = cairo_create ();
  }
***************
*** 114,118 ****
  gtk_cairo_new (void)
  {
! 	GtkWidget *gtkcairo;
  	
  	gtkcairo = GTK_WIDGET (g_object_new (GTK_TYPE_CAIRO, NULL));
--- 121,125 ----
  gtk_cairo_new (void)
  {
! 	GtkWidget *gtkcairo;    
  	
  	gtkcairo = GTK_WIDGET (g_object_new (GTK_TYPE_CAIRO, NULL));
***************
*** 160,173 ****
  	attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
  	attributes.visual = gtk_widget_get_visual (widget);
! 	attributes.colormap = gtk_widget_get_colormap (widget);
! 	
! 	attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
! 	widget->window = gdk_window_new (widget->parent->window,
! 			&attributes, attributes_mask);
! 	
! 	gdk_window_set_user_data (widget->window, widget);
  	gtk_style_attach (widget->style, widget->window);
- 	
  	gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
  }
  
--- 167,216 ----
  	attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
  	attributes.visual = gtk_widget_get_visual (widget);
! 
! #ifdef CAIRO_HAS_GLX_SURFACE
!     if (gtkcairo->glx ) {
!        XSetWindowAttributes xswa;
!        XVisualInfo *vinfo;
! 
!        vinfo = cairo_glx_find_best_visual_info (
!                gdk_x11_get_default_xdisplay (),
!                gdk_x11_get_default_screen (), 0);
! 
!        if (vinfo) {
!             gtk_widget_set_double_buffered (widget, FALSE);
!             attributes.visual = gdkx_visual_get (vinfo->visualid);
!             attributes.colormap = gdk_colormap_new (attributes.visual, TRUE);
! 
!     	    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);
! 
!             gtkcairo->surface =
!               cairo_glx_surface_create_for_window (gdk_x11_get_default_xdisplay (),
!                                  DefaultScreen (gdk_x11_get_default_xdisplay ()),
!                                 0, gdk_x11_drawable_get_xid (widget->window));
! 
!             cairo_set_target_surface (gtkcairo->cairo, gtkcairo->surface); 
!        } else {
!             fprintf (stderr, "could not find a usable GLX visual\n");
!             gtkcairo->glx = 0;
!        }
!     }
!         
!     if (!gtkcairo->glx){
! #endif
! 	    attributes.colormap = gtk_widget_get_colormap (widget);
! 
! 	    attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
! 	    widget->window = gdk_window_new (widget->parent->window,
! 			    &attributes, attributes_mask);
! #ifdef CAIRO_HAS_GLX_SURFACE
!     }
! #endif
!     
  	gtk_style_attach (widget->style, widget->window);
  	gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+ 	gdk_window_set_user_data (widget->window, widget);
  }
  
***************
*** 176,189 ****
                           GtkAllocation *allocation)
  {
  	g_return_if_fail (widget != NULL);
  	g_return_if_fail (GTK_IS_CAIRO (widget));
  	g_return_if_fail (allocation != NULL);
  
  	widget->allocation = *allocation;
  
  	if (GTK_WIDGET_REALIZED (widget)) {
! 		gdk_window_move_resize (widget->window,
! 					allocation->x, allocation->y,
! 					allocation->width, allocation->height);
  	}
  }
--- 219,240 ----
                           GtkAllocation *allocation)
  {
+     GtkCairo *gtkcairo;
  	g_return_if_fail (widget != NULL);
  	g_return_if_fail (GTK_IS_CAIRO (widget));
  	g_return_if_fail (allocation != NULL);
  
+ 	gtkcairo = GTK_CAIRO (widget);
+ 
  	widget->allocation = *allocation;
  
  	if (GTK_WIDGET_REALIZED (widget)) {
! 		    gdk_window_move_resize (widget->window,
! 					    allocation->x, allocation->y,
! 					    allocation->width, allocation->height);
! #ifdef CAIRO_HAS_GLX_SURFACE
!             if (gtkcairo->glx && gtkcairo->surface) {
!                 cairo_gl_surface_realize (gtkcairo->surface);
!             } 
! #endif            
  	}
  }
***************
*** 194,199 ****
  {
  	GtkCairo *gtkcairo;
- 	GdkDrawable *gdkdrawable;
- 	gint x_off, y_off;
  
  	g_return_val_if_fail (widget != NULL, FALSE);
--- 245,248 ----
***************
*** 203,228 ****
  	gtkcairo = GTK_CAIRO (widget);
  
! 	/* Ignore GTK+ and use Cairo for drawing. */
! 	gdk_window_get_internal_paint_info (widget->window,
! 			&gdkdrawable, &x_off, &y_off);
  
! 	/* XXX  X11-specific: */
! 	cairo_set_target_drawable (gtkcairo->cairo,
! 			gdk_x11_drawable_get_xdisplay (gdkdrawable),
! 			gdk_x11_drawable_get_xid (gdkdrawable));
! 	/* XXX  :X11-specific */
  
! 	/* counter offset of expose */
! 	if (x_off || y_off) {
! 		cairo_save (gtkcairo->cairo);
! 		cairo_translate (gtkcairo->cairo, -x_off, -y_off);
! 	}
  
! 	g_signal_emit_by_name (gtkcairo, "redraw", gtkcairo->cairo);
  
! 	if (x_off || y_off) {
! 		cairo_restore (gtkcairo->cairo);
! 	}
! 	
  	return FALSE;
  }
--- 252,289 ----
  	gtkcairo = GTK_CAIRO (widget);
  
! #ifdef CAIRO_HAS_GLX_SURFACE
!     if (gtkcairo->glx) {
!         cairo_rectangle (gtkcairo->cairo, 0, 0, widget->allocation.width, widget->allocation.height);
!         cairo_set_rgb_color(gtkcairo->cairo, 0.7, 0.7, 0.7);
!         cairo_fill (gtkcairo->cairo);    
  
! 	    g_signal_emit_by_name (gtkcairo, "redraw", gtkcairo->cairo);
!         cairo_copy_page (gtkcairo->cairo);
!     } else {
! #endif
!         GdkDrawable *gdkdrawable;
!         gint x_off, y_off;
  
! 	    gdk_window_get_internal_paint_info (widget->window,
! 			    &gdkdrawable, &x_off, &y_off);
  
! 	    cairo_set_target_drawable (gtkcairo->cairo,
! 			    gdk_x11_drawable_get_xdisplay (gdkdrawable),
! 			    gdk_x11_drawable_get_xid (gdkdrawable));
  
! 	    /* counter offset of expose */
! 	    if (x_off || y_off) {
! 		    cairo_save (gtkcairo->cairo);
! 		    cairo_translate (gtkcairo->cairo, -x_off, -y_off);
! 	    }
! 
! 	    g_signal_emit_by_name (gtkcairo, "redraw", gtkcairo->cairo);
! 
! 	    if (x_off || y_off) {
! 		    cairo_restore (gtkcairo->cairo);
! 	    }
! #ifdef CAIRO_HAS_GLX_SURFACE
!     }
! #endif    
  	return FALSE;
  }

Index: gtkcairo.h
===================================================================
RCS file: /cvs/cairo/gtkcairo/gtkcairo/gtkcairo.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** gtkcairo.h	14 Feb 2004 17:04:58 -0000	1.4
--- gtkcairo.h	15 Feb 2004 17:46:28 -0000	1.5
***************
*** 51,55 ****
--- 51,63 ----
  {
  	GtkWidget widget;
+ 
+ /* all fields are private */
  	cairo_t *cairo;
+     
+     int glx;
+ #ifdef CAIRO_HAS_GLX_SURFACE
+     cairo_surface_t *surface;
+ #endif
+     
  };
  





More information about the cairo-commit mailing list