[cairo-commit] cairo/src cairo_surface.c,1.14,1.15 cairo_xlib_surface.c,1.5,1.6 cairoint.h,1.31,1.32

Carl Worth commit at pdx.freedesktop.org
Mon Oct 27 18:40:57 PST 2003


Committed by: cworth

Update of /cvs/cairo/cairo/src
In directory pdx:/tmp/cvs-serv20545/src

Modified Files:
	cairo_surface.c cairo_xlib_surface.c cairoint.h 
Log Message:
Cleanup of surface->backend interface. Better type-safety and
more consistent return-value handling.

Index: cairo_surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_surface.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** cairo_surface.c	23 Oct 2003 14:47:29 -0000	1.14
--- cairo_surface.c	28 Oct 2003 02:40:55 -0000	1.15
***************
*** 344,349 ****
  			  unsigned int		height)
  {
!     if (dst->backend->composite
! 	&& (dst->backend->composite (operator, src, mask, dst, src_x, src_y, mask_x, mask_y, dst_x, dst_y, width, height) >= 0))
  	return;
  
--- 344,356 ----
  			  unsigned int		height)
  {
!     cairo_int_status_t status;
! 
!     status = dst->backend->composite (operator,
! 				      src, mask, dst,
! 				      src_x, src_y,
! 				      mask_x, mask_y,
! 				      dst_x, dst_y,
! 				      width, height);
!     if (status == CAIRO_STATUS_SUCCESS)
  	return;
  
***************
*** 391,394 ****
--- 398,402 ----
  				int			num_rects)
  {
+     cairo_int_status_t status;
      IcColor ic_color;
  
***************
*** 396,401 ****
  	return;
  
!     if (surface->backend->fill_rectangles
! 	&& (surface->backend->fill_rectangles (surface, operator, color, rects, num_rects) >= 0))
  	return;
  
--- 404,412 ----
  	return;
  
!     status = surface->backend->fill_rectangles (surface,
! 						operator,
! 						color,
! 						rects, num_rects);
!     if (status == CAIRO_STATUS_SUCCESS)
  	return;
  
***************
*** 423,428 ****
  				     int			num_traps)
  {
!     if (dst->backend->composite_trapezoids
! 	&& (dst->backend->composite_trapezoids (operator, src, dst, xSrc, ySrc, traps, num_traps) >= 0))
  	return;
  
--- 434,444 ----
  				     int			num_traps)
  {
!     cairo_int_status_t status;
! 
!     status = dst->backend->composite_trapezoids (operator,
! 						 src, dst,
! 						 xSrc, ySrc,
! 						 traps, num_traps);
!     if (status == CAIRO_STATUS_SUCCESS)
  	return;
  

Index: cairo_xlib_surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_xlib_surface.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** cairo_xlib_surface.c	24 Oct 2003 18:01:37 -0000	1.5
--- cairo_xlib_surface.c	28 Oct 2003 02:40:55 -0000	1.6
***************
*** 67,71 ****
      Picture picture;
      XImage *ximage;
! } cairo_xlib_surface;
  
  #define CAIRO_SURFACE_RENDER_AT_LEAST(surface, major, minor)	\
--- 67,71 ----
      Picture picture;
      XImage *ximage;
! } cairo_xlib_surface_t;
  
  #define CAIRO_SURFACE_RENDER_AT_LEAST(surface, major, minor)	\
***************
*** 105,118 ****
  }
  
! static cairo_xlib_surface *
! _cairo_xlib_surface_create_similar (cairo_xlib_surface	*other,
  				    cairo_format_t	format,
  				    int			width,
  				    int			height)
  {
!     Display *dpy = other->dpy;
      int scr;
      Pixmap pix;
!     cairo_xlib_surface *surface;
  
      /* XXX: There's a pretty lame heuristic here. This assumes that
--- 105,119 ----
  }
  
! static cairo_surface_t *
! _cairo_xlib_surface_create_similar (void		*abstract_src,
  				    cairo_format_t	format,
  				    int			width,
  				    int			height)
  {
!     cairo_xlib_surface_t *src = abstract_src;
!     Display *dpy = src->dpy;
      int scr;
      Pixmap pix;
!     cairo_xlib_surface_t *surface;
  
      /* XXX: There's a pretty lame heuristic here. This assumes that
***************
*** 122,128 ****
       * supported. */
      if (!dpy
! 	|| (!CAIRO_SURFACE_RENDER_HAS_COMPOSITE (other)
  	    && format == CAIRO_FORMAT_ARGB32))
! 	return 0;
  
      scr = DefaultScreen (dpy);
--- 123,129 ----
       * supported. */
      if (!dpy
! 	|| (!CAIRO_SURFACE_RENDER_HAS_COMPOSITE (src)
  	    && format == CAIRO_FORMAT_ARGB32))
! 	return NULL;
  
      scr = DefaultScreen (dpy);
***************
*** 132,145 ****
  			 _CAIRO_FORMAT_DEPTH (format));
  
!     surface = (cairo_xlib_surface *)
  	cairo_xlib_surface_create (dpy, pix, NULL, format, DefaultColormap (dpy, scr));
      surface->owns_pixmap = 1;
  
!     return surface;
  }
  
  static void
! _cairo_xlib_surface_destroy (cairo_xlib_surface *surface)
  {
      if (surface->picture)
  	XRenderFreePicture (surface->dpy, surface->picture);
--- 133,147 ----
  			 _CAIRO_FORMAT_DEPTH (format));
  
!     surface = (cairo_xlib_surface_t *)
  	cairo_xlib_surface_create (dpy, pix, NULL, format, DefaultColormap (dpy, scr));
      surface->owns_pixmap = 1;
  
!     return &surface->base;
  }
  
  static void
! _cairo_xlib_surface_destroy (void *abstract_surface)
  {
+     cairo_xlib_surface_t *surface = abstract_surface;
      if (surface->picture)
  	XRenderFreePicture (surface->dpy, surface->picture);
***************
*** 152,157 ****
  
  static void
! _cairo_xlib_surface_pull_image (cairo_xlib_surface *surface)
  {
      Window root_ignore;
      int x_ignore, y_ignore, bwidth_ignore, depth_ignore;
--- 154,160 ----
  
  static void
! _cairo_xlib_surface_pull_image (void *abstract_surface)
  {
+     cairo_xlib_surface_t *surface = abstract_surface;
      Window root_ignore;
      int x_ignore, y_ignore, bwidth_ignore, depth_ignore;
***************
*** 192,196 ****
  
  static void
! _cairo_xlib_surface_ensure_gc (cairo_xlib_surface *surface)
  {
      if (surface->gc)
--- 195,199 ----
  
  static void
! _cairo_xlib_surface_ensure_gc (cairo_xlib_surface_t *surface)
  {
      if (surface->gc)
***************
*** 201,206 ****
  
  static void
! _cairo_xlib_surface_push_image (cairo_xlib_surface *surface)
  {
      if (surface == NULL)
  	return;
--- 204,210 ----
  
  static void
! _cairo_xlib_surface_push_image (void *abstract_surface)
  {
+     cairo_xlib_surface_t *surface = abstract_surface;
      if (surface == NULL)
  	return;
***************
*** 224,229 ****
  
  static cairo_status_t
! _cairo_xlib_surface_set_matrix (cairo_xlib_surface *surface)
  {
      if (!surface->picture)
  	return CAIRO_STATUS_SUCCESS;
--- 228,234 ----
  
  static cairo_status_t
! _cairo_xlib_surface_set_matrix (void *abstract_surface)
  {
+     cairo_xlib_surface_t *surface = abstract_surface;
      if (!surface->picture)
  	return CAIRO_STATUS_SUCCESS;
***************
*** 263,268 ****
  
  static cairo_status_t
! _cairo_xlib_surface_set_filter (cairo_xlib_surface *surface, cairo_filter_t filter)
  {
      if (!surface->picture)
  	return CAIRO_STATUS_SUCCESS;
--- 268,274 ----
  
  static cairo_status_t
! _cairo_xlib_surface_set_filter (void *abstract_surface, cairo_filter_t filter)
  {
+     cairo_xlib_surface_t *surface = abstract_surface;
      if (!surface->picture)
  	return CAIRO_STATUS_SUCCESS;
***************
*** 275,280 ****
  
  static cairo_status_t
! _cairo_xlib_surface_set_repeat (cairo_xlib_surface *surface, int repeat)
  {
      unsigned long mask;
      XRenderPictureAttributes pa;
--- 281,287 ----
  
  static cairo_status_t
! _cairo_xlib_surface_set_repeat (void *abstract_surface, int repeat)
  {
+     cairo_xlib_surface_t *surface = abstract_surface;
      unsigned long mask;
      XRenderPictureAttributes pa;
***************
*** 292,296 ****
  
  static cairo_status_t
! _cairo_xlib_surface_put_image (cairo_xlib_surface	*surface,
  			      char			*data,
  			      int			width,
--- 299,303 ----
  
  static cairo_status_t
! _cairo_xlib_surface_put_image (cairo_xlib_surface_t	*surface,
  			      char			*data,
  			      int			width,
***************
*** 333,348 ****
  }
  
! static cairo_xlib_surface *
! _cairo_xlib_surface_clone_from (cairo_surface_t *src, cairo_xlib_surface *tmpl, 
                                  cairo_format_t fmt, int depth)
  {
      cairo_matrix_t matrix;
!     cairo_xlib_surface *src_on_server;
  
      _cairo_surface_pull_image (src);
  
!     src_on_server = _cairo_xlib_surface_create_similar (tmpl, fmt,
! 							IcImageGetWidth (src->icimage),
! 							IcImageGetHeight (src->icimage));
      if (src_on_server == NULL)
  	return NULL;
--- 340,356 ----
  }
  
! static cairo_xlib_surface_t *
! _cairo_xlib_surface_clone_from (cairo_surface_t *src, cairo_xlib_surface_t *tmpl, 
                                  cairo_format_t fmt, int depth)
  {
      cairo_matrix_t matrix;
!     cairo_xlib_surface_t *src_on_server;
  
      _cairo_surface_pull_image (src);
  
!     src_on_server = (cairo_xlib_surface_t *)
! 	_cairo_xlib_surface_create_similar (tmpl, fmt,
! 					    IcImageGetWidth (src->icimage),
! 					    IcImageGetHeight (src->icimage));
      if (src_on_server == NULL)
  	return NULL;
***************
*** 359,367 ****
  }
  
! static int
  _cairo_xlib_surface_composite (cairo_operator_t		operator,
! 			       cairo_xlib_surface	*src,
! 			       cairo_xlib_surface	*mask,
! 			       cairo_xlib_surface	*dst,
  			       int			src_x,
  			       int			src_y,
--- 367,375 ----
  }
  
! static cairo_int_status_t
  _cairo_xlib_surface_composite (cairo_operator_t		operator,
! 			       cairo_surface_t		*generic_src,
! 			       cairo_surface_t		*generic_mask,
! 			       void			*abstract_dst,
  			       int			src_x,
  			       int			src_y,
***************
*** 373,388 ****
  			       unsigned int		height)
  {
      if (!CAIRO_SURFACE_RENDER_HAS_COMPOSITE (dst))
! 	return -1;
  
!     if (src->base.backend != dst->base.backend || src->dpy != dst->dpy) {
! 	src = _cairo_xlib_surface_clone_from (&src->base, dst, CAIRO_FORMAT_ARGB32, 32);
  	if (!src)
! 	    return -1;
      }
!     if (mask && (mask->base.backend != dst->base.backend || mask->dpy != dst->dpy)) {
! 	mask = _cairo_xlib_surface_clone_from (&mask->base, dst, CAIRO_FORMAT_A8, 8);
  	if (!mask)
! 	    return -1;
      }
  
--- 381,400 ----
  			       unsigned int		height)
  {
+     cairo_xlib_surface_t *dst = abstract_dst;
+     cairo_xlib_surface_t *src = (cairo_xlib_surface_t *) generic_src;
+     cairo_xlib_surface_t *mask = (cairo_xlib_surface_t *) generic_mask;
+ 
      if (!CAIRO_SURFACE_RENDER_HAS_COMPOSITE (dst))
! 	return CAIRO_INT_STATUS_UNSUPPORTED;
  
!     if (generic_src->backend != dst->base.backend || src->dpy != dst->dpy) {
! 	src = _cairo_xlib_surface_clone_from (generic_src, dst, CAIRO_FORMAT_ARGB32, 32);
  	if (!src)
! 	    return CAIRO_INT_STATUS_UNSUPPORTED;
      }
!     if (generic_mask && (generic_mask->backend != dst->base.backend || mask->dpy != dst->dpy)) {
! 	mask = _cairo_xlib_surface_clone_from (generic_mask, dst, CAIRO_FORMAT_A8, 8);
  	if (!mask)
! 	    return CAIRO_INT_STATUS_UNSUPPORTED;
      }
  
***************
*** 396,404 ****
  		      width, height);
  
!     return 0;
  }
  
! static int
! _cairo_xlib_surface_fill_rectangles (cairo_xlib_surface		*surface,
  				     cairo_operator_t		operator,
  				     const cairo_color_t	*color,
--- 408,416 ----
  		      width, height);
  
!     return CAIRO_STATUS_SUCCESS;
  }
  
! static cairo_int_status_t
! _cairo_xlib_surface_fill_rectangles (void			*abstract_surface,
  				     cairo_operator_t		operator,
  				     const cairo_color_t	*color,
***************
*** 406,413 ****
  				     int			num_rects)
  {
      XRenderColor render_color;
  
      if (!CAIRO_SURFACE_RENDER_HAS_FILL_RECTANGLE (surface))
! 	return -1;
  
      render_color.red   = color->red_short;
--- 418,426 ----
  				     int			num_rects)
  {
+     cairo_xlib_surface_t *surface = abstract_surface;
      XRenderColor render_color;
  
      if (!CAIRO_SURFACE_RENDER_HAS_FILL_RECTANGLE (surface))
! 	return CAIRO_INT_STATUS_UNSUPPORTED;
  
      render_color.red   = color->red_short;
***************
*** 420,430 ****
  			   &render_color, (XRectangle *) rects, num_rects);
  
!     return 0;
  }
  
! static int
  _cairo_xlib_surface_composite_trapezoids (cairo_operator_t	operator,
! 					  cairo_xlib_surface	*src,
! 					  cairo_xlib_surface	*dst,
  					  int			xSrc,
  					  int			ySrc,
--- 433,443 ----
  			   &render_color, (XRectangle *) rects, num_rects);
  
!     return CAIRO_STATUS_SUCCESS;
  }
  
! static cairo_int_status_t
  _cairo_xlib_surface_composite_trapezoids (cairo_operator_t	operator,
! 					  cairo_surface_t	*generic_src,
! 					  void			*abstract_dst,
  					  int			xSrc,
  					  int			ySrc,
***************
*** 432,442 ****
  					  int			num_traps)
  {
      if (!CAIRO_SURFACE_RENDER_HAS_TRAPEZOIDS (dst))
! 	return -1;
  
!     if (src->base.backend != dst->base.backend || src->dpy != dst->dpy) {
! 	src = _cairo_xlib_surface_clone_from (&src->base, dst, CAIRO_FORMAT_ARGB32, 32);
  	if (!src)
! 	    return -1;
      }
  
--- 445,457 ----
  					  int			num_traps)
  {
+     cairo_xlib_surface_t *dst = abstract_dst;
+     cairo_xlib_surface_t *src = (cairo_xlib_surface_t *) generic_src;
      if (!CAIRO_SURFACE_RENDER_HAS_TRAPEZOIDS (dst))
! 	return CAIRO_INT_STATUS_UNSUPPORTED;
  
!     if (generic_src->backend != dst->base.backend || src->dpy != dst->dpy) {
! 	src = _cairo_xlib_surface_clone_from (generic_src, dst, CAIRO_FORMAT_ARGB32, 32);
  	if (!src)
! 	    return CAIRO_INT_STATUS_UNSUPPORTED;
      }
  
***************
*** 446,450 ****
  				xSrc, ySrc, (XTrapezoid *) traps, num_traps);
  
!     return 0;
  }
  
--- 461,465 ----
  				xSrc, ySrc, (XTrapezoid *) traps, num_traps);
  
!     return CAIRO_STATUS_SUCCESS;
  }
  
***************
*** 452,465 ****
  
  static const struct cairo_surface_backend cairo_xlib_surface_backend = {
!     create_similar:		(void *) _cairo_xlib_surface_create_similar,
!     destroy:			(void *) _cairo_xlib_surface_destroy,
!     pull_image:			(void *) _cairo_xlib_surface_pull_image,
!     push_image:			(void *) _cairo_xlib_surface_push_image,
!     set_matrix:			(void *) _cairo_xlib_surface_set_matrix,
!     set_filter:			(void *) _cairo_xlib_surface_set_filter,
!     set_repeat:			(void *) _cairo_xlib_surface_set_repeat,
!     composite:			(void *) _cairo_xlib_surface_composite,
!     fill_rectangles:		(void *) _cairo_xlib_surface_fill_rectangles,
!     composite_trapezoids:	(void *) _cairo_xlib_surface_composite_trapezoids,
  };
  
--- 467,480 ----
  
  static const struct cairo_surface_backend cairo_xlib_surface_backend = {
!     _cairo_xlib_surface_create_similar,
!     _cairo_xlib_surface_destroy,
!     _cairo_xlib_surface_pull_image,
!     _cairo_xlib_surface_push_image,
!     _cairo_xlib_surface_set_matrix,
!     _cairo_xlib_surface_set_filter,
!     _cairo_xlib_surface_set_repeat,
!     _cairo_xlib_surface_composite,
!     _cairo_xlib_surface_fill_rectangles,
!     _cairo_xlib_surface_composite_trapezoids,
  };
  
***************
*** 471,477 ****
  			   Colormap		colormap)
  {
!     cairo_xlib_surface *surface;
  
!     surface = malloc (sizeof (cairo_xlib_surface));
      if (surface == NULL)
  	return NULL;
--- 486,492 ----
  			   Colormap		colormap)
  {
!     cairo_xlib_surface_t *surface;
  
!     surface = malloc (sizeof (cairo_xlib_surface_t));
      if (surface == NULL)
  	return NULL;

Index: cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** cairoint.h	24 Oct 2003 17:01:34 -0000	1.31
--- cairoint.h	28 Oct 2003 02:40:55 -0000	1.32
***************
*** 130,133 ****
--- 130,134 ----
  typedef enum cairo_int_status {
      CAIRO_INT_STATUS_DEGENERATE = 1000,
+     CAIRO_INT_STATUS_UNSUPPORTED
  } cairo_int_status_t;
  
***************
*** 283,321 ****
  
  struct cairo_surface_backend {
!     cairo_surface_t *(*create_similar) (cairo_surface_t	*surface,
! 					cairo_format_t	format,
! 					int		width,
! 					int		height);
!     void (*destroy) (cairo_surface_t *surface);
!     void (*pull_image) (cairo_surface_t *surface);
!     void (*push_image) (cairo_surface_t *surface);
!     cairo_status_t (*set_matrix) (cairo_surface_t *surface);
!     cairo_status_t (*set_filter) (cairo_surface_t *surface, cairo_filter_t filter);
!     cairo_status_t (*set_repeat) (cairo_surface_t *surface, int repeat);
!     int (*composite) (cairo_operator_t	operator,
! 		      cairo_surface_t	*src,
! 		      cairo_surface_t	*mask,
! 		      cairo_surface_t	*dst,
! 		      int		src_x,
! 		      int		src_y,
! 		      int		mask_x,
! 		      int		mask_y,
! 		      int		dst_x,
! 		      int		dst_y,
! 		      unsigned int	width,
! 		      unsigned int	height);
!     int (*fill_rectangles) (cairo_surface_t	*surface,
! 			    cairo_operator_t	operator,
! 			    const cairo_color_t	*color,
! 			    cairo_rectangle_t	*rects,
! 			    int			num_rects);
!     int (*composite_trapezoids) (cairo_operator_t	operator,
  				 cairo_surface_t	*src,
! 				 cairo_surface_t	*dst,
  				 int			xSrc,
  				 int			ySrc,
  				 cairo_trapezoid_t	*traps,
  				 int			num_traps);
- 
  };
  
--- 284,344 ----
  
  struct cairo_surface_backend {
!     cairo_surface_t *
!     (*create_similar)		(void			*surface,
! 				 cairo_format_t		format,
! 				 int			width,
! 				 int			height);
! 
!     void
!     (*destroy)			(void			*surface);
! 
!     void
!     (*pull_image)		(void			*surface);
! 
!     void
!     (*push_image)		(void			*surface);
! 
!     cairo_status_t
!     (*set_matrix)		(void			*surface);
! 
!     cairo_status_t
!     (*set_filter)		(void			*surface,
! 				 cairo_filter_t		filter);
! 
!     cairo_status_t
!     (*set_repeat)		(void			*surface,
! 				 int			 repeat);
! 
!     /* XXX: dst should be the first argument for consistency */
!     cairo_int_status_t
!     (*composite)		(cairo_operator_t	operator,
! 				 cairo_surface_t       	*src,
! 				 cairo_surface_t	*mask,
! 				 void			*dst,
! 				 int			src_x,
! 				 int			src_y,
! 				 int			mask_x,
! 				 int			mask_y,
! 				 int			dst_x,
! 				 int			dst_y,
! 				 unsigned int		width,
! 				 unsigned int		height);
! 
!     cairo_int_status_t
!     (*fill_rectangles)		(void			*surface,
! 				 cairo_operator_t	operator,
! 				 const cairo_color_t	*color,
! 				 cairo_rectangle_t	*rects,
! 				 int			num_rects);
! 
!     /* XXX: dst should be the first argument for consistency */
!     cairo_int_status_t
!     (*composite_trapezoids)	(cairo_operator_t	operator,
  				 cairo_surface_t	*src,
! 				 void			*dst,
  				 int			xSrc,
  				 int			ySrc,
  				 cairo_trapezoid_t	*traps,
  				 int			num_traps);
  };
  





More information about the cairo-commit mailing list