diff --git a/ChangeLog b/ChangeLog index 14188fddb6..16b3dac9a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-05-07 Owen Taylor + + * gdk/gdkpixbuf-render.c gdk/gdkpixbuf.h (gdk_pixbuf_set_as_cairo_source): + Change prototype to match cairo_set_source_surface(). + + * gdk/gdkdraw.c gdk/gdkgc.c gdk/gdkpixbuf-render.c gdk/gdkwindow.c + gtk/gtkhsv.c tests/testcairo.c. + 2005-05-06 Federico Mena Quintero Merged from gtk-2-6: diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 14188fddb6..16b3dac9a9 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +2005-05-07 Owen Taylor + + * gdk/gdkpixbuf-render.c gdk/gdkpixbuf.h (gdk_pixbuf_set_as_cairo_source): + Change prototype to match cairo_set_source_surface(). + + * gdk/gdkdraw.c gdk/gdkgc.c gdk/gdkpixbuf-render.c gdk/gdkwindow.c + gtk/gtkhsv.c tests/testcairo.c. + 2005-05-06 Federico Mena Quintero Merged from gtk-2-6: diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 14188fddb6..16b3dac9a9 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +2005-05-07 Owen Taylor + + * gdk/gdkpixbuf-render.c gdk/gdkpixbuf.h (gdk_pixbuf_set_as_cairo_source): + Change prototype to match cairo_set_source_surface(). + + * gdk/gdkdraw.c gdk/gdkgc.c gdk/gdkpixbuf-render.c gdk/gdkwindow.c + gtk/gtkhsv.c tests/testcairo.c. + 2005-05-06 Federico Mena Quintero Merged from gtk-2-6: diff --git a/gdk/gdkdraw.c b/gdk/gdkdraw.c index ca0950d2c4..3269668b19 100644 --- a/gdk/gdkdraw.c +++ b/gdk/gdkdraw.c @@ -884,16 +884,16 @@ real_draw_glyphs (GdkDrawable *drawable, if (matrix) { - cairo_matrix_t *cairo_matrix; + cairo_matrix_t cairo_matrix; - cairo_matrix = cairo_matrix_create (); - cairo_matrix_set_affine (cairo_matrix, - matrix->xx, matrix->yx, - matrix->xy, matrix->yy, - matrix->x0, matrix->y0); + cairo_matrix.xx = matrix->xx; + cairo_matrix.yx = matrix->yx; + cairo_matrix.xy = matrix->xy; + cairo_matrix.yy = matrix->yy; + cairo_matrix.x0 = matrix->x0; + cairo_matrix.y0 = matrix->y0; - cairo_set_matrix (cr, cairo_matrix); - cairo_matrix_destroy (cairo_matrix); + cairo_set_matrix (cr, &cairo_matrix); } cairo_move_to (cr, x, y); @@ -1304,11 +1304,9 @@ gdk_drawable_create_cairo_context (GdkDrawable *drawable) g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL); - cr = cairo_create (); - surface = _gdk_drawable_ref_cairo_surface (drawable); - if (surface) - cairo_set_target_surface (cr, surface); + cr = cairo_create (surface); + cairo_surface_destroy (surface); return cr; } diff --git a/gdk/gdkgc.c b/gdk/gdkgc.c index 50179d4110..8c386938cc 100644 --- a/gdk/gdkgc.c +++ b/gdk/gdkgc.c @@ -1044,14 +1044,13 @@ make_stipple_tile_surface (cairo_t *cr, alpha_surface = _gdk_drawable_ref_cairo_surface (stipple); - surface = cairo_surface_create_similar (cairo_get_target_surface (cr), + surface = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_FORMAT_ARGB32, width, height); - tmp_cr = cairo_create (); - cairo_set_target_surface (tmp_cr, surface); + tmp_cr = cairo_create (surface); - cairo_set_operator (tmp_cr, CAIRO_OPERATOR_SRC); + cairo_set_operator (tmp_cr, CAIRO_OPERATOR_SOURCE); if (background) gdk_cairo_set_source_color (tmp_cr, background); diff --git a/gdk/gdkpixbuf-render.c b/gdk/gdkpixbuf-render.c index 6e3891f758..d8eda5eb69 100644 --- a/gdk/gdkpixbuf-render.c +++ b/gdk/gdkpixbuf-render.c @@ -333,14 +333,18 @@ gdk_pixbuf_render_pixmap_and_mask_for_colormap (GdkPixbuf *pixbuf, * gdk_pixbuf_set_as_cairo_source: * @pixbuf: a #GdkPixbuf * @cr: a #Cairo context + * @pixbuf_x: X coordinate of location to place upper left corner of @pixbuf + * @pixbuf_y: Y coordinate of location to place upper left corner of @pixbuf * * Sets the given pixbuf as the source pattern for the Cairo context. * The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned - * so that the origin of @pixbuf is at the current point. + * so that the origin of @pixbuf is @pixbuf_x, @pixbuf_y **/ void gdk_pixbuf_set_as_cairo_source (GdkPixbuf *pixbuf, - cairo_t *cr) + cairo_t *cr, + double pixbuf_x, + double pixbuf_y) { gint width = gdk_pixbuf_get_width (pixbuf); gint height = gdk_pixbuf_get_height (pixbuf); @@ -350,10 +354,7 @@ gdk_pixbuf_set_as_cairo_source (GdkPixbuf *pixbuf, guchar *cairo_pixels; cairo_format_t format; cairo_surface_t *surface; - cairo_pattern_t *pattern; static const cairo_user_data_key_t key; - cairo_matrix_t *matrix; - double x, y; int j; if (n_channels == 3) @@ -424,17 +425,7 @@ gdk_pixbuf_set_as_cairo_source (GdkPixbuf *pixbuf, cairo_pixels += 4 * width; } - pattern = cairo_pattern_create_for_surface (surface); - cairo_surface_destroy (surface); - - cairo_current_point (cr, &x, &y); - matrix = cairo_matrix_create (); - cairo_matrix_translate (matrix, -x, -y); - cairo_pattern_set_matrix (pattern, matrix); - cairo_matrix_destroy (matrix); - - cairo_set_source (cr, pattern); - cairo_pattern_destroy (pattern); + cairo_set_source_surface (cr, surface, pixbuf_x, pixbuf_y); } #define __GDK_PIXBUF_RENDER_C__ diff --git a/gdk/gdkpixbuf.h b/gdk/gdkpixbuf.h index 04f00a7eef..aa5b4acba2 100644 --- a/gdk/gdkpixbuf.h +++ b/gdk/gdkpixbuf.h @@ -81,7 +81,9 @@ GdkPixbuf *gdk_pixbuf_get_from_image (GdkPixbuf *dest, int height); void gdk_pixbuf_set_as_cairo_source (GdkPixbuf *pixbuf, - cairo_t *cr); + cairo_t *cr, + double pixbuf_x, + double pixbuf_y); G_END_DECLS diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c index 145e275194..87280a5052 100644 --- a/gdk/gdkwindow.c +++ b/gdk/gdkwindow.c @@ -1748,10 +1748,9 @@ gdk_window_set_bg_pattern (GdkWindow *window, if (x_offset != 0 || y_offset) { - cairo_matrix_t *matrix = cairo_matrix_create (); - cairo_matrix_translate (matrix, x_offset, y_offset); - cairo_pattern_set_matrix (pattern, matrix); - cairo_matrix_destroy (matrix); + cairo_matrix_t matrix; + cairo_matrix_init_translate (&matrix, x_offset, y_offset); + cairo_pattern_set_matrix (pattern, &matrix); } cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); @@ -1795,8 +1794,7 @@ gdk_window_clear_backing_rect (GdkWindow *window, if (GDK_WINDOW_DESTROYED (window)) return; - cr = cairo_create (); - cairo_set_target_surface (cr, paint->surface); + cr = cairo_create (paint->surface); gdk_window_set_bg_pattern (window, cr, 0, 0); diff --git a/gtk/gtkhsv.c b/gtk/gtkhsv.c index 36908b707f..20ca50c63c 100644 --- a/gtk/gtkhsv.c +++ b/gtk/gtkhsv.c @@ -917,26 +917,6 @@ gtk_hsv_motion (GtkWidget *widget, /* Redrawing */ -static void -set_source_surface (cairo_t *cr, - cairo_surface_t *surface) -{ - cairo_pattern_t *pattern; - cairo_matrix_t *matrix; - double x, y; - - pattern = cairo_pattern_create_for_surface (surface); - - cairo_current_point (cr, &x, &y); - matrix = cairo_matrix_create (); - cairo_matrix_translate (matrix, -x, -y); - cairo_pattern_set_matrix (pattern, matrix); - cairo_matrix_destroy (matrix); - - cairo_set_source (cr, pattern); - cairo_pattern_destroy (pattern); -} - /* Paints the hue ring */ static void paint_ring (GtkHSV *hsv, @@ -1018,8 +998,7 @@ paint_ring (GtkHSV *hsv, /* Now draw the value marker onto the source image, so that it * will get properly clipped at the edges of the ring */ - source_cr = cairo_create (); - cairo_set_target_surface (source_cr, source); + source_cr = cairo_create (source); r = priv->h; g = 1.0; @@ -1042,8 +1021,7 @@ paint_ring (GtkHSV *hsv, cairo_save (cr); - cairo_move_to (cr, x, y); - set_source_surface (cr, source); + cairo_set_source_surface (cr, source, x, y); cairo_surface_destroy (source); cairo_set_line_width (cr, priv->ring_width); @@ -1220,8 +1198,7 @@ paint_triangle (GtkHSV *hsv, /* Draw a triangle with the image as a source */ - cairo_move_to (cr, x, y); - set_source_surface (cr, source); + cairo_set_source_surface (cr, source, x, y); cairo_surface_destroy (source); cairo_move_to (cr, x1, y1); diff --git a/tests/testcairo.c b/tests/testcairo.c index 141bb8517f..06257cd9af 100644 --- a/tests/testcairo.c +++ b/tests/testcairo.c @@ -29,10 +29,7 @@ oval_path (cairo_t *cr, double xc, double yc, double xr, double yr) { - cairo_matrix_t *matrix; - - matrix = cairo_matrix_create (); - cairo_current_matrix (cr, matrix); + cairo_save (cr); cairo_translate (cr, xc, yc); cairo_scale (cr, 1.0, yr / xr); @@ -43,8 +40,7 @@ oval_path (cairo_t *cr, 0, 2 * G_PI); cairo_close_path (cr); - cairo_set_matrix (cr, matrix); - cairo_matrix_destroy (matrix); + cairo_restore (cr); } /* Create a path that is a circular oval with radii xr, yr at xc, @@ -125,25 +121,26 @@ draw (cairo_t *cr, int height) { cairo_surface_t *overlay, *punch, *circles; + cairo_t *overlay_cr, *punch_cr, *circles_cr; /* Fill the background */ double radius = 0.5 * (width < height ? width : height) - 10; double xc = width / 2.; double yc = height / 2.; - overlay = cairo_surface_create_similar (cairo_current_target_surface (cr), + overlay = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_FORMAT_ARGB32, width, height); if (overlay == NULL) return; - punch = cairo_surface_create_similar (cairo_current_target_surface (cr), + punch = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_FORMAT_A8, width, height); if (punch == NULL) return; - circles = cairo_surface_create_similar (cairo_current_target_surface (cr), + circles = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_FORMAT_ARGB32, width, height); if (circles == NULL) @@ -151,47 +148,39 @@ draw (cairo_t *cr, fill_checks (cr, 0, 0, width, height); - cairo_save (cr); - cairo_set_target_surface (cr, overlay); - cairo_identity_matrix (cr); - /* Draw a black circle on the overlay */ - cairo_set_source_rgb (cr, 0., 0., 0.); - oval_path (cr, xc, yc, radius, radius); - cairo_fill (cr); - - cairo_save (cr); - cairo_set_target_surface (cr, punch); + overlay_cr = cairo_create (overlay); + cairo_set_source_rgb (overlay_cr, 0., 0., 0.); + oval_path (overlay_cr, xc, yc, radius, radius); + cairo_fill (overlay_cr); /* Draw 3 circles to the punch surface, then cut * that out of the main circle in the overlay */ - draw_3circles (cr, xc, yc, radius, 1.0); + punch_cr = cairo_create (punch); + draw_3circles (punch_cr, xc, yc, radius, 1.0); + cairo_destroy (punch_cr); - cairo_restore (cr); - - cairo_set_operator (cr, CAIRO_OPERATOR_OUT_REVERSE); - cairo_set_source_surface (cr, punch, 0, 0); - cairo_paint (cr); + cairo_set_operator (overlay_cr, CAIRO_OPERATOR_DEST_OUT); + cairo_set_source_surface (overlay_cr, punch, 0, 0); + cairo_paint (overlay_cr); /* Now draw the 3 circles in a subgroup again * at half intensity, and use OperatorAdd to join up * without seams. */ - cairo_save (cr); - cairo_set_target_surface (cr, circles); + circles_cr = cairo_create (circles); + + cairo_set_operator (circles_cr, CAIRO_OPERATOR_OVER); + draw_3circles (circles_cr, xc, yc, radius, 0.5); + cairo_destroy (circles_cr); - cairo_set_operator (cr, CAIRO_OPERATOR_OVER); - draw_3circles (cr, xc, yc, radius, 0.5); + cairo_set_operator (overlay_cr, CAIRO_OPERATOR_ADD); + cairo_set_source_surface (overlay_cr, circles, 0, 0); + cairo_paint (overlay_cr); - cairo_restore (cr); - - cairo_set_operator (cr, CAIRO_OPERATOR_ADD); - cairo_set_source_surface (cr, circles, 0, 0); - cairo_paint (cr); - - cairo_restore (cr); + cairo_destroy (overlay_cr); cairo_set_source_surface (cr, overlay, 0, 0); cairo_paint (cr);