[cairo-commit] cairo/src cairo-color.c, 1.13,
1.14 cairo-glitz-surface.c, 1.31, 1.32 cairo-gstate-private.h,
1.4, 1.5 cairo-gstate.c, 1.110, 1.111 cairo-pattern.c, 1.31,
1.32 cairo-pdf-surface.c, 1.28, 1.29 cairo-ps-surface.c, 1.31,
1.32 cairo-surface.c, 1.58, 1.59 cairo-xlib-surface.c, 1.58,
1.59 cairo.c, 1.77, 1.78 cairo.h, 1.98, 1.99 cairoint.h, 1.126,
1.127
Carl Worth
commit at pdx.freedesktop.org
Thu Apr 14 14:42:29 PDT 2005
- Previous message: [cairo-commit]
cairo/test Makefile.am, 1.34, 1.35 cairo-test.c, 1.18,
1.19 clip-twice.c, 1.3, 1.4 coverage.c, 1.6, 1.7 fill-rule.c,
1.4, 1.5 line-width.c, 1.3, 1.4 linear-gradient.c, 1.3,
1.4 pixman-rotate.c, 1.5, 1.6 set-source.c, 1.1,
1.2 text-rotate.c, 1.7, 1.8 trap-clip.c, 1.1, 1.2
- Next message: [cairo-commit] cairo ChangeLog,1.512,1.513 TODO,1.44,1.45
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: cworth
Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv4566/src
Modified Files:
cairo-color.c cairo-glitz-surface.c cairo-gstate-private.h
cairo-gstate.c cairo-pattern.c cairo-pdf-surface.c
cairo-ps-surface.c cairo-surface.c cairo-xlib-surface.c
cairo.c cairo.h cairoint.h
Log Message:
* src/cairo.h:
* src/cairo.c: Rename, add, and delete:
cairo_set_pattern -> cairo_set_source
cairo_get_pattern -> cairo_get_source
cairo_set_rgb_color -> cairo_set_source_rgb
-> cairo_set_source_rgba
cairo_set_alpha ->
cairo_get_alpha ->
Note that we'll likely want to add cairo_set_source_surface.
* src/cairo-color.c: Add _cairo_stock_color helper function.
Improve some interfaces:
_cairo_color_init _cairo_color_init_rgb
_cairo_color_set_rgb -> _cairo_color_init_rgba
_cairo_color_set_alpha _cairo_color_multiply_alpha
_cairo_color_get_rgb -> _cairo_color_get_rbga
_cairo_color_get_rgba_premultiplied
* src/cairoint.h: Add cairo_stock_t and some helper macros:
CAIRO_COLOR_WHITE
CAIRO_COLOR_BLACK
CAIRO_COLOR_TRANSPARENT
Fix cairo_pattern_t by eliminating pattern->alpha.
Fix cairo_solid_pattern_t to use cairo_color_t rather than three
doubles.
* src/cairo-glitz-surface.c:
(_cairo_glitz_pattern_acquire_surface),
(_cairo_glitz_pattern_acquire_surfaces),
(_cairo_glitz_surface_composite_trapezoids): Track removal of
pattern->alpha, simplifying the code considerably
* src/cairo-gstate-private.h:
* src/cairo-gstate.c: Track _cairo_color interface changes. Remove
gstate->alpha. Propagate down set_source renamings.
* src/cairo.h:
* src/cairo-pattern.c: Rename:
cairo_pattern_add_color_stop -> cairo_pattern_add_color_stop_rgba
and add:
cairo_pattern_add_color_stop_rgb
Remove pattern->alpha, simplifying the code considerably.
* src/cairo-pdf-surface.c:
* src/cairo-ps-surface.c: Track pattern and color interface
changes.
* src/cairo-surface.c: Add const where appropriate on
cairo_color_t*.
* src/cairo-xlib-surface.c: (_cairo_surface_is_xlib): Add private
type inspection predicate.
(cairo_xlib_surface_set_size): Add check for surface type
mismatch, (no useful error reporting yet, though).
* test/Makefile.am: Note coverage as en expected failure.
* test/cairo-test.c: (cairo_test_expect_failure): Improve line
wrap on expected failure messages.
* test/clip-twice.c:
* test/coverage.c:
* test/fill-rule.c:
* test/line-width.c:
* test/linear-gradient.c:
* test/pixman-rotate.c:
* test/set-source.c:
* test/text-rotate.c:
* test/trap-clip.c: Port all tests to new cairo_set_source
interfaces.
Index: cairo-color.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-color.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- cairo-color.c 22 Feb 2005 19:35:03 -0000 1.13
+++ cairo-color.c 14 Apr 2005 21:42:26 -0000 1.14
@@ -1,6 +1,7 @@
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2002 University of Southern California
+ * Copyright © 2005 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
@@ -36,62 +37,127 @@
#include "cairoint.h"
-static cairo_color_t const CAIRO_COLOR_WHITE = {
- 1.0, 1.0, 1.0, 1.0,
+static cairo_color_t const cairo_color_white = {
+ 1.0, 1.0, 1.0, 1.0,
0xffff, 0xffff, 0xffff, 0xffff
};
-static void
-_cairo_color_compute_shorts (cairo_color_t *color);
+static cairo_color_t const cairo_color_black = {
+ 0.0, 0.0, 0.0, 1.0,
+ 0x0, 0x0, 0x0, 0xffff
+};
+
+static cairo_color_t const cairo_color_transparent = {
+ 0.0, 0.0, 0.0, 0.0,
+ 0x0, 0x0, 0x0, 0x0
+};
+
+static cairo_color_t const cairo_color_magenta = {
+ 1.0, 0.0, 1.0, 1.0,
+ 0xffff, 0x0, 0xffff, 0xffff
+};
+
+const cairo_color_t *
+_cairo_stock_color (cairo_stock_t stock)
+{
+ switch (stock) {
+ case CAIRO_STOCK_WHITE:
+ return &cairo_color_white;
+ case CAIRO_STOCK_BLACK:
+ return &cairo_color_black;
+ case CAIRO_STOCK_TRANSPARENT:
+ return &cairo_color_transparent;
+ }
+
+ ASSERT_NOT_REACHED;
+
+ /* If the user can get here somehow, give a color that indicates a
+ * problem. */
+ return &cairo_color_magenta;
+}
void
_cairo_color_init (cairo_color_t *color)
{
- *color = CAIRO_COLOR_WHITE;
+ *color = cairo_color_white;
}
void
-_cairo_color_fini (cairo_color_t *color)
+_cairo_color_init_rgb (cairo_color_t *color,
+ double red, double green, double blue)
{
- /* Nothing to do here */
+ _cairo_color_init_rgba (color, red, green, blue, 1.0);
+}
+
+
+/* XXX: The calculation of:
+
+ channel * 0xffff
+
+ isn't really what we want since:
+
+ (1.0 - epsilon) * 0xffff = 0xfffe
+
+ In other words, given an input range of [0.0, 1.0], we have an
+ infinitely small range tha maps to the output value 0xffff,
+ (while having large, uniformly sized input ranges for all
+ other output values). This is undesirable, particularly when
+ we want to do optimizations for "opaque" colors specfied as
+ floating-point.
+*/
+static void
+_cairo_color_compute_shorts (cairo_color_t *color)
+{
+ color->red_short = color->red * color->alpha * 0xffff;
+ color->green_short = color->green * color->alpha * 0xffff;
+ color->blue_short = color->blue * color->alpha * 0xffff;
+ color->alpha_short = color->alpha * 0xffff;
}
void
-_cairo_color_set_rgb (cairo_color_t *color, double red, double green, double blue)
+_cairo_color_init_rgba (cairo_color_t *color,
+ double red, double green, double blue,
+ double alpha)
{
color->red = red;
color->green = green;
color->blue = blue;
+ color->alpha = alpha;
_cairo_color_compute_shorts (color);
}
void
-_cairo_color_get_rgb (const cairo_color_t *color,
- double *red, double *green, double *blue)
+_cairo_color_multiply_alpha (cairo_color_t *color,
+ double alpha)
{
- if (red)
- *red = color->red;
- if (green)
- *green = color->green;
- if (blue)
- *blue = color->blue;
+ color->alpha *= alpha;
+
+ _cairo_color_compute_shorts (color);
}
void
-_cairo_color_set_alpha (cairo_color_t *color, double alpha)
+_cairo_color_get_rgba (cairo_color_t *color,
+ double *red,
+ double *green,
+ double *blue,
+ double *alpha)
{
- color->alpha = alpha;
-
- _cairo_color_compute_shorts (color);
+ *red = color->red;
+ *green = color->green;
+ *blue = color->blue;
+ *alpha = color->alpha;
}
-static void
-_cairo_color_compute_shorts (cairo_color_t *color)
+void
+_cairo_color_get_rgba_premultiplied (cairo_color_t *color,
+ double *red,
+ double *green,
+ double *blue,
+ double *alpha)
{
- color->red_short = (color->red * color->alpha) * 0xffff;
- color->green_short = (color->green * color->alpha) * 0xffff;
- color->blue_short = (color->blue * color->alpha) * 0xffff;
- color->alpha_short = color->alpha * 0xffff;
+ *red = color->red * color->alpha;
+ *green = color->green * color->alpha;
+ *blue = color->blue * color->alpha;
+ *alpha = color->alpha;
}
-
Index: cairo-glitz-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-glitz-surface.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- cairo-glitz-surface.c 12 Apr 2005 14:12:08 -0000 1.31
+++ cairo-glitz-surface.c 14 Apr 2005 21:42:26 -0000 1.32
@@ -562,12 +562,12 @@
pattern->filter != CAIRO_FILTER_BEST)
break;
- alpha = (gradient->stops[0].color.alpha * pattern->alpha) * 0xffff;
+ alpha = (gradient->stops[0].color.alpha) * 0xffff;
for (i = 1; i < gradient->n_stops; i++)
{
unsigned short a;
- a = (gradient->stops[i].color.alpha * pattern->alpha) * 0xffff;
+ a = (gradient->stops[i].color.alpha) * 0xffff;
if (a != alpha)
break;
}
@@ -729,50 +729,30 @@
{
cairo_int_status_t status;
cairo_pattern_union_t tmp;
- cairo_bool_t src_opaque, mask_opaque;
- double src_alpha, mask_alpha;
- src_opaque = _cairo_pattern_is_opaque (src);
- mask_opaque = !mask || _cairo_pattern_is_opaque (mask);
-
- /* For surface patterns, we move any translucency from src->alpha
- * to mask->alpha so we can use the source unchanged. Otherwise we
- * move the translucency from mask->alpha to src->alpha so that
- * we can drop the mask if possible.
- */
- if (src->type == CAIRO_PATTERN_SURFACE)
- {
- if (mask) {
- mask_opaque = mask_opaque && src_opaque;
- mask_alpha = mask->alpha * src->alpha;
- } else {
- mask_opaque = src_opaque;
- mask_alpha = src->alpha;
- }
-
- src_alpha = 1.0;
- src_opaque = TRUE;
- }
- else
+ /* If src and mask are both solid, then the mask alpha can be
+ * combined into src and mask can be ignored. */
+
+ /* XXX: This optimization assumes that there is no color
+ * information in mask, so this will need to change when we
+ * support RENDER-style 4-channel masks. */
+
+ if (src->type == CAIRO_PATTERN_SOLID &&
+ mask->type == CAIRO_PATTERN_SOLID)
{
- if (mask)
- {
- src_opaque = mask_opaque && src_opaque;
- src_alpha = mask->alpha * src->alpha;
- /* FIXME: This needs changing when we support RENDER
- * style 4-channel masks.
- */
- if (mask->type == CAIRO_PATTERN_SOLID)
- mask = NULL;
- } else
- src_alpha = src->alpha;
+ cairo_color_t combined;
+ cairo_solid_pattern_t *src_solid = (cairo_solid_pattern_t *) src;
+ cairo_solid_pattern_t *mask_solid = (cairo_solid_pattern_t *) mask;
- mask_alpha = 1.0;
- mask_opaque = TRUE;
- }
+ combined = src_solid->color;
+ _cairo_color_multiply_alpha (&combined, mask_solid->color.alpha);
- _cairo_pattern_init_copy (&tmp.base, src);
- _cairo_pattern_set_alpha (&tmp.base, src_alpha);
+ _cairo_pattern_init_solid (&tmp.solid, &combined);
+
+ mask = NULL;
+ } else {
+ _cairo_pattern_init_copy (&tmp.base, src);
+ }
status = _cairo_glitz_pattern_acquire_surface (&tmp.base, dst,
src_x, src_y,
@@ -784,14 +764,9 @@
if (status)
return status;
- if (mask || !mask_opaque)
+ if (mask)
{
- if (mask)
- _cairo_pattern_init_copy (&tmp.base, mask);
- else
- _cairo_pattern_init_solid (&tmp.solid, 0.0, 0.0, 0.0);
-
- _cairo_pattern_set_alpha (&tmp.base, mask_alpha);
+ _cairo_pattern_init_copy (&tmp.base, mask);
status = _cairo_glitz_pattern_acquire_surface (&tmp.base, dst,
mask_x, mask_y,
@@ -1001,7 +976,6 @@
cairo_pattern_union_t tmp;
_cairo_pattern_init_copy (&tmp.base, pattern);
- _cairo_pattern_set_alpha (&tmp.base, 1.0);
status = _cairo_glitz_pattern_acquire_surface (&tmp.base, dst,
src_x, src_y,
@@ -1009,8 +983,6 @@
&src, &attributes);
_cairo_pattern_fini (&tmp.base);
-
- alpha = pattern->alpha * 0xffff;
}
else
{
@@ -1018,8 +990,8 @@
src_x, src_y,
width, height,
&src, &attributes);
- alpha = 0xffff;
}
+ alpha = 0xffff;
if (status)
return status;
@@ -1052,7 +1024,7 @@
return CAIRO_INT_STATUS_UNSUPPORTED;
}
- color.red = color.green = color.blue = color.alpha = alpha;
+ color.red = color.green = color.blue = color.alpha = 0xffff;
glitz_set_rectangle (mask->surface, &clear_black, 0, 0, 1, 1);
glitz_set_rectangle (mask->surface, &color, 1, 0, 1, 1);
@@ -1142,18 +1114,6 @@
pixman_add_trapezoids (image->pixman_image, -dst_x, -dst_y,
(pixman_trapezoid_t *) traps, n_traps);
- if (alpha != 0xffff)
- {
- pixman_color_t color;
-
- color.red = color.green = color.blue = color.alpha = alpha;
-
- pixman_fill_rectangle (PIXMAN_OPERATOR_IN,
- image->pixman_image,
- &color,
- 0, 0, width, height);
- }
-
mask = (cairo_glitz_surface_t *)
_cairo_surface_create_similar_scratch (&dst->base,
CAIRO_FORMAT_A8, 0,
Index: cairo-gstate-private.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-gstate-private.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cairo-gstate-private.h 7 Apr 2005 18:04:00 -0000 1.4
+++ cairo-gstate-private.h 14 Apr 2005 21:42:26 -0000 1.5
@@ -64,8 +64,7 @@
cairo_surface_t *surface;
- cairo_pattern_t *pattern;
- double alpha;
+ cairo_pattern_t *source;
cairo_clip_rec_t clip;
Index: cairo-gstate.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-gstate.c,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -d -r1.110 -r1.111
--- cairo-gstate.c 13 Apr 2005 18:23:43 -0000 1.110
+++ cairo-gstate.c 14 Apr 2005 21:42:26 -0000 1.111
@@ -1,6 +1,7 @@
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2002 University of Southern California
+ * Copyright © 2005 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
@@ -105,12 +106,10 @@
gstate->clip.region = NULL;
gstate->clip.surface = NULL;
-
- gstate->pattern = _cairo_pattern_create_solid (0.0, 0.0, 0.0);
- if (!gstate->pattern)
- return CAIRO_STATUS_NO_MEMORY;
- gstate->alpha = 1.0;
+ gstate->source = _cairo_pattern_create_solid (CAIRO_COLOR_BLACK);
+ if (!gstate->source)
+ return CAIRO_STATUS_NO_MEMORY;
_cairo_gstate_identity_matrix (gstate);
@@ -157,7 +156,7 @@
cairo_surface_reference (gstate->surface);
cairo_surface_reference (gstate->clip.surface);
- cairo_pattern_reference (gstate->pattern);
+ cairo_pattern_reference (gstate->source);
status = _cairo_path_fixed_init_copy (&gstate->path, &other->path);
if (status)
@@ -203,7 +202,7 @@
pixman_region_destroy (gstate->clip.region);
gstate->clip.region = NULL;
- cairo_pattern_destroy (gstate->pattern);
+ cairo_pattern_destroy (gstate->source);
_cairo_path_fixed_fini (&gstate->path);
@@ -262,7 +261,6 @@
_cairo_gstate_begin_group (cairo_gstate_t *gstate)
{
Pixmap pix;
- cairo_color_t clear;
unsigned int width, height;
gstate->parent_surface = gstate->surface;
@@ -283,12 +281,9 @@
_cairo_surface_set_drawableWH (gstate->surface, pix, width, height);
- _cairo_color_init (&clear);
- _cairo_color_set_alpha (&clear, 0);
-
status = _cairo_surface_fill_rectangle (gstate->surface,
CAIRO_OPERATOR_SRC,
- &clear,
+ &CAIRO_COLOR_TRANSPARENT,
0, 0,
_cairo_surface_get_width (gstate->surface),
_cairo_surface_get_height (gstate->surface));
@@ -313,7 +308,6 @@
_cairo_surface_init (&mask, gstate->dpy);
_cairo_color_init (&mask_color);
- _cairo_color_set_alpha (&mask_color, gstate->alpha);
_cairo_surface_set_solid_color (&mask, &mask_color);
@@ -383,29 +377,44 @@
}
cairo_status_t
-_cairo_gstate_set_pattern (cairo_gstate_t *gstate, cairo_pattern_t *pattern)
+_cairo_gstate_set_source (cairo_gstate_t *gstate,
+ cairo_pattern_t *source)
{
- if (pattern == NULL)
+ if (source == NULL)
return CAIRO_STATUS_NULL_POINTER;
- cairo_pattern_reference (pattern);
- cairo_pattern_destroy (gstate->pattern);
- gstate->pattern = pattern;
+ cairo_pattern_reference (source);
+ cairo_pattern_destroy (gstate->source);
+ gstate->source = source;
+
+ return CAIRO_STATUS_SUCCESS;
+}
+
+cairo_status_t
+_cairo_gstate_set_source_solid (cairo_gstate_t *gstate,
+ const cairo_color_t *color)
+{
+ cairo_status_t status;
+ cairo_pattern_t *source;
+
+ source = _cairo_pattern_create_solid (color);
+ if (!source)
+ return CAIRO_STATUS_NO_MEMORY;
+
+ status = _cairo_gstate_set_source (gstate, source);
+
+ cairo_pattern_destroy (source);
return CAIRO_STATUS_SUCCESS;
}
cairo_pattern_t *
-_cairo_gstate_get_pattern (cairo_gstate_t *gstate)
+_cairo_gstate_get_source (cairo_gstate_t *gstate)
{
if (gstate == NULL)
return NULL;
-/* XXX: Do we want this?
- cairo_pattern_reference (gstate->pattern);
-*/
-
- return gstate->pattern;
+ return gstate->source;
}
cairo_status_t
@@ -423,21 +432,9 @@
}
cairo_status_t
-_cairo_gstate_set_rgb_color (cairo_gstate_t *gstate, double red, double green, double blue)
-{
- cairo_pattern_destroy (gstate->pattern);
-
- gstate->pattern = _cairo_pattern_create_solid (red, green, blue);
- if (!gstate->pattern)
- return CAIRO_STATUS_NO_MEMORY;
-
- return CAIRO_STATUS_SUCCESS;
-}
-
-cairo_status_t
_cairo_gstate_get_rgb_color (cairo_gstate_t *gstate, double *red, double *green, double *blue)
{
- return _cairo_pattern_get_rgb (gstate->pattern, red, green, blue);
+ return _cairo_pattern_get_rgb (gstate->source, red, green, blue);
}
cairo_status_t
@@ -455,20 +452,6 @@
}
cairo_status_t
-_cairo_gstate_set_alpha (cairo_gstate_t *gstate, double alpha)
-{
- gstate->alpha = alpha;
-
- return CAIRO_STATUS_SUCCESS;
-}
-
-double
-_cairo_gstate_get_alpha (cairo_gstate_t *gstate)
-{
- return gstate->alpha;
-}
-
-cairo_status_t
_cairo_gstate_set_fill_rule (cairo_gstate_t *gstate, cairo_fill_rule_t fill_rule)
{
gstate->fill_rule = fill_rule;
@@ -1314,19 +1297,6 @@
_cairo_pattern_transform (pattern, &tmp_matrix);
}
-/* XXX: gstate->alpha will be going away before too long, and when it
- * does, it may make sense for this function to just disappear.
- */
-static void
-_cairo_gstate_pattern_init_copy (cairo_gstate_t *gstate,
- cairo_pattern_union_t *pattern,
- cairo_pattern_t *src)
-{
- _cairo_pattern_init_copy (&pattern->base, src);
- _cairo_gstate_pattern_transform (gstate, &pattern->base);
- _cairo_pattern_set_alpha (&pattern->base, gstate->alpha);
-}
-
cairo_status_t
_cairo_gstate_stroke (cairo_gstate_t *gstate)
{
@@ -1347,7 +1317,7 @@
}
_cairo_gstate_clip_and_composite_trapezoids (gstate,
- gstate->pattern,
+ gstate->source,
gstate->operator,
gstate->surface,
&traps);
@@ -1570,7 +1540,9 @@
return status;
}
- _cairo_gstate_pattern_init_copy (gstate, &pattern, src);
+ _cairo_pattern_init_copy (&pattern.base, src);
+ _cairo_gstate_pattern_transform (gstate, &pattern.base);
+
if (gstate->clip.surface)
_cairo_pattern_init_for_surface (&mask.surface, gstate->clip.surface);
@@ -1642,22 +1614,19 @@
cairo_surface_t *intermediate;
cairo_pattern_union_t pattern;
cairo_surface_pattern_t intermediate_pattern;
- cairo_color_t empty_color;
cairo_status_t status;
translate_traps (traps, -extents->x, -extents->y);
- _cairo_color_init (&empty_color);
- _cairo_color_set_alpha (&empty_color, 0.);
intermediate = _cairo_surface_create_similar_solid (gstate->clip.surface,
CAIRO_FORMAT_A8,
extents->width,
extents->height,
- &empty_color);
+ CAIRO_COLOR_TRANSPARENT);
if (intermediate == NULL)
return CAIRO_STATUS_NO_MEMORY;
- _cairo_pattern_init_solid (&pattern.solid, 1.0, 1.0, 1.0);
+ _cairo_pattern_init_solid (&pattern.solid, CAIRO_COLOR_WHITE);
status = _cairo_surface_composite_trapezoids (CAIRO_OPERATOR_ADD,
&pattern.base,
@@ -1691,7 +1660,8 @@
goto out;
_cairo_pattern_init_for_surface (&intermediate_pattern, intermediate);
- _cairo_gstate_pattern_init_copy (gstate, &pattern, src);
+ _cairo_pattern_init_copy (&pattern.base, src);
+ _cairo_gstate_pattern_transform (gstate, &pattern.base);
status = _cairo_surface_composite (operator,
&pattern.base,
@@ -1722,7 +1692,6 @@
cairo_surface_t *dst,
pixman_region16_t *region)
{
- cairo_color_t color;
int num_rects = pixman_region_num_rects (region);
pixman_box16_t *boxes = pixman_region_rects (region);
cairo_rectangle_t *rects;
@@ -1743,12 +1712,8 @@
rects[i].height = boxes[i].y2 - boxes[i].y1;
}
- _cairo_color_init (&color);
- _cairo_color_set_rgb (&color, src->red, src->green, src->blue);
- _cairo_color_set_alpha (&color, gstate->alpha);
-
status = _cairo_surface_fill_rectangles (dst, operator,
- &color, rects, num_rects);
+ &src->color, rects, num_rects);
free (rects);
@@ -1769,7 +1734,8 @@
cairo_pattern_union_t pattern;
cairo_status_t status;
- _cairo_gstate_pattern_init_copy (gstate, &pattern, src);
+ _cairo_pattern_init_copy (&pattern.base, src);
+ _cairo_gstate_pattern_transform (gstate, &pattern.base);
status = _cairo_surface_composite_trapezoids (gstate->operator,
&pattern.base, dst,
@@ -1876,7 +1842,7 @@
}
_cairo_gstate_clip_and_composite_trapezoids (gstate,
- gstate->pattern,
+ gstate->source,
gstate->operator,
gstate->surface,
&traps);
@@ -2040,7 +2006,6 @@
cairo_status_t status;
cairo_pattern_union_t pattern;
cairo_traps_t traps;
- cairo_color_t white_color;
cairo_box_t extents;
pixman_region16_t *region;
@@ -2096,8 +2061,6 @@
/* Otherwise represent the clip as a mask surface. */
- _cairo_color_init (&white_color);
-
if (gstate->clip.surface == NULL) {
_cairo_traps_extents (&traps, &extents);
_cairo_box_round_to_rectangle (&extents, &gstate->clip.rect);
@@ -2106,13 +2069,13 @@
CAIRO_FORMAT_A8,
gstate->clip.rect.width,
gstate->clip.rect.height,
- &white_color);
+ CAIRO_COLOR_WHITE);
if (gstate->clip.surface == NULL)
return CAIRO_STATUS_NO_MEMORY;
}
translate_traps (&traps, -gstate->clip.rect.x, -gstate->clip.rect.y);
- _cairo_pattern_init_solid (&pattern.solid, 1.0, 1.0, 1.0);
+ _cairo_pattern_init_solid (&pattern.solid, CAIRO_COLOR_WHITE);
status = _cairo_surface_composite_trapezoids (CAIRO_OPERATOR_IN,
&pattern.base,
@@ -2248,7 +2211,6 @@
pattern.base.extend = CAIRO_EXTEND_NONE;
_cairo_gstate_pattern_transform (gstate, &pattern.base);
- _cairo_pattern_set_alpha (&pattern.base, gstate->alpha);
pattern_extents.p1.x = _cairo_fixed_from_double (backend_x);
pattern_extents.p1.y = _cairo_fixed_from_double (backend_y);
@@ -2632,7 +2594,6 @@
{
cairo_surface_t *intermediate;
cairo_surface_pattern_t intermediate_pattern;
- cairo_color_t empty_color;
_cairo_rectangle_intersect (&extents, &gstate->clip.rect);
@@ -2642,13 +2603,11 @@
goto BAIL1;
}
- _cairo_color_init (&empty_color);
- _cairo_color_set_alpha (&empty_color, .0);
intermediate = _cairo_surface_create_similar_solid (gstate->clip.surface,
CAIRO_FORMAT_A8,
extents.width,
extents.height,
- &empty_color);
+ CAIRO_COLOR_TRANSPARENT);
if (intermediate == NULL) {
status = CAIRO_STATUS_NO_MEMORY;
goto BAIL1;
@@ -2661,7 +2620,7 @@
transformed_glyphs[i].y -= extents.y;
}
- _cairo_pattern_init_solid (&pattern.solid, 1.0, 1.0, 1.0);
+ _cairo_pattern_init_solid (&pattern.solid, CAIRO_COLOR_WHITE);
status = _cairo_scaled_font_show_glyphs (gstate->scaled_font,
CAIRO_OPERATOR_ADD,
@@ -2695,7 +2654,8 @@
goto BAIL2;
_cairo_pattern_init_for_surface (&intermediate_pattern, intermediate);
- _cairo_gstate_pattern_init_copy (gstate, &pattern, gstate->pattern);
+ _cairo_pattern_init_copy (&pattern.base, gstate->source);
+ _cairo_gstate_pattern_transform (gstate, &pattern.base);
status = _cairo_surface_composite (gstate->operator,
&pattern.base,
@@ -2715,7 +2675,8 @@
}
else
{
- _cairo_gstate_pattern_init_copy (gstate, &pattern, gstate->pattern);
+ _cairo_pattern_init_copy (&pattern.base, gstate->source);
+ _cairo_gstate_pattern_transform (gstate, &pattern.base);
status = _cairo_scaled_font_show_glyphs (gstate->scaled_font,
gstate->operator, &pattern.base,
Index: cairo-pattern.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-pattern.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- cairo-pattern.c 12 Apr 2005 16:14:14 -0000 1.31
+++ cairo-pattern.c 14 Apr 2005 21:42:26 -0000 1.32
@@ -1,6 +1,7 @@
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2004 David Reveman
+ * Copyright © 2005 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
@@ -56,7 +57,6 @@
pattern->ref_count = 1;
pattern->extend = CAIRO_EXTEND_DEFAULT;
pattern->filter = CAIRO_FILTER_DEFAULT;
- pattern->alpha = 1.0;
cairo_matrix_init_identity (&pattern->matrix);
}
@@ -150,15 +150,10 @@
void
_cairo_pattern_init_solid (cairo_solid_pattern_t *pattern,
- double red,
- double green,
- double blue)
+ const cairo_color_t *color)
{
_cairo_pattern_init (&pattern->base, CAIRO_PATTERN_SOLID);
-
- pattern->red = red;
- pattern->green = green;
- pattern->blue = blue;
+ pattern->color = *color;
}
void
@@ -209,7 +204,7 @@
}
cairo_pattern_t *
-_cairo_pattern_create_solid (double red, double green, double blue)
+_cairo_pattern_create_solid (const cairo_color_t *color)
{
cairo_solid_pattern_t *pattern;
@@ -217,7 +212,7 @@
if (pattern == NULL)
return NULL;
- _cairo_pattern_init_solid (pattern, red, green, blue);
+ _cairo_pattern_init_solid (pattern, color);
return &pattern->base;
}
@@ -296,11 +291,8 @@
static cairo_status_t
_cairo_pattern_add_color_stop (cairo_gradient_pattern_t *pattern,
- double offset,
- double red,
- double green,
- double blue,
- double alpha)
+ double offset,
+ cairo_color_t *color)
{
cairo_color_stop_t *stop;
@@ -316,22 +308,48 @@
stop = &pattern->stops[pattern->n_stops - 1];
stop->offset = _cairo_fixed_from_double (offset);
-
- _cairo_color_init (&stop->color);
- _cairo_color_set_rgb (&stop->color, red, green, blue);
- _cairo_color_set_alpha (&stop->color, alpha);
+ stop->color = *color;
return CAIRO_STATUS_SUCCESS;
}
cairo_status_t
-cairo_pattern_add_color_stop (cairo_pattern_t *pattern,
- double offset,
- double red,
- double green,
- double blue,
- double alpha)
+cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern,
+ double offset,
+ double red,
+ double green,
+ double blue)
{
+ cairo_color_t color;
+
+ if (pattern->type != CAIRO_PATTERN_LINEAR &&
+ pattern->type != CAIRO_PATTERN_RADIAL)
+ {
+ /* XXX: CAIRO_STATUS_INVALID_PATTERN? */
+ return CAIRO_STATUS_SUCCESS;
+ }
+
+ _cairo_restrict_value (&offset, 0.0, 1.0);
+ _cairo_restrict_value (&red, 0.0, 1.0);
+ _cairo_restrict_value (&green, 0.0, 1.0);
+ _cairo_restrict_value (&blue, 0.0, 1.0);
+
+ _cairo_color_init_rgb (&color, red, green, blue);
+ return _cairo_pattern_add_color_stop ((cairo_gradient_pattern_t *) pattern,
+ offset,
+ &color);
+}
+
+cairo_status_t
+cairo_pattern_add_color_stop_rgba (cairo_pattern_t *pattern,
+ double offset,
+ double red,
+ double green,
+ double blue,
+ double alpha)
+{
+ cairo_color_t color;
+
if (pattern->type != CAIRO_PATTERN_LINEAR &&
pattern->type != CAIRO_PATTERN_RADIAL)
{
@@ -345,11 +363,12 @@
_cairo_restrict_value (&blue, 0.0, 1.0);
_cairo_restrict_value (&alpha, 0.0, 1.0);
+ _cairo_color_init_rgba (&color, red, green, blue, alpha);
return _cairo_pattern_add_color_stop ((cairo_gradient_pattern_t *) pattern,
offset,
- red, green, blue,
- alpha);
+ &color);
}
+DEPRECATE (cairo_pattern_add_color_stop, cairo_pattern_add_color_stop_rgba);
cairo_status_t
cairo_pattern_set_matrix (cairo_pattern_t *pattern, cairo_matrix_t *matrix)
@@ -401,27 +420,20 @@
double *green,
double *blue)
{
-
if (pattern->type == CAIRO_PATTERN_SOLID)
{
+ double alpha_unused;
cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) pattern;
-
- *red = solid->red;
- *green = solid->green;
- *blue = solid->blue;
- } else
+
+ _cairo_color_get_rgba (&solid->color, red, green, blue, &alpha_unused);
+ } else {
*red = *green = *blue = 1.0;
+ }
return CAIRO_STATUS_SUCCESS;
}
void
-_cairo_pattern_set_alpha (cairo_pattern_t *pattern, double alpha)
-{
- pattern->alpha = alpha;
-}
-
-void
_cairo_pattern_transform (cairo_pattern_t *pattern,
cairo_matrix_t *ctm_inverse)
{
@@ -510,8 +522,7 @@
op->stops[i].color_char[0] = pattern->stops[i].color.red * 0xff;
op->stops[i].color_char[1] = pattern->stops[i].color.green * 0xff;
op->stops[i].color_char[2] = pattern->stops[i].color.blue * 0xff;
- op->stops[i].color_char[3] = pattern->stops[i].color.alpha *
- pattern->base.alpha * 0xff;
+ op->stops[i].color_char[3] = pattern->stops[i].color.alpha * 0xff;
op->stops[i].offset = pattern->stops[i].offset;
op->stops[i].id = i;
}
@@ -975,16 +986,10 @@
cairo_surface_t **out,
cairo_surface_attributes_t *attribs)
{
- cairo_color_t color;
-
- _cairo_color_init (&color);
- _cairo_color_set_rgb (&color, pattern->red, pattern->green, pattern->blue);
- _cairo_color_set_alpha (&color, pattern->base.alpha);
-
*out = _cairo_surface_create_similar_solid (dst,
CAIRO_FORMAT_ARGB32,
1, 1,
- &color);
+ &pattern->color);
if (*out == NULL)
return CAIRO_STATUS_NO_MEMORY;
@@ -1000,28 +1005,27 @@
/**
- * _cairo_pattern_is_opaque
- *
- * Convenience function to determine whether a pattern has an opaque
- * alpha value. This is done by testing whether the pattern's alpha
- * value when converted to a byte is 255, so if a backend actually
- * supported deep alpha channels this function might not do the right
- * thing.
+ * _cairo_pattern_is_opaque_solid
*
- * Note that for a gradient or surface pattern, the overall resulting
- * alpha for the pattern can be non-opaque even this function returns
- * %TRUE, since the resulting alpha is the multiplication of the
- * alpha of the gradient or surface with the pattern's alpha. In
- * the future, alpha will be moved from the base pattern to the
- * solid pattern subtype, at which point this function should
- * probably be renamed to _cairo_pattern_is_opaque_solid()
+ * Convenience function to determine whether a pattern is an opaque
+ * (alpha==1.0) solid color pattern. This is done by testing whether
+ * the pattern's alpha value when converted to a byte is 255, so if a
+ * backend actually supported deep alpha channels this function might
+ * not do the right thing.
*
- * Return value: %TRUE if the pattern is opaque
+ * Return value: %TRUE if the pattern is an opaque, solid color.
**/
cairo_bool_t
-_cairo_pattern_is_opaque (cairo_pattern_t *pattern)
+_cairo_pattern_is_opaque_solid (cairo_pattern_t *pattern)
{
- return (pattern->alpha >= ((double)0xff00 / (double)0xffff));
+ cairo_solid_pattern_t *solid;
+
+ if (pattern->type != CAIRO_PATTERN_SOLID)
+ return FALSE;
+
+ solid = (cairo_solid_pattern_t *) pattern;
+
+ return (solid->color.alpha >= ((double)0xff00 / (double)0xffff));
}
static cairo_int_status_t
@@ -1035,85 +1039,39 @@
cairo_surface_attributes_t *attr)
{
cairo_int_status_t status;
+ int tx, ty;
attr->acquired = FALSE;
-
- /* handle pattern opacity */
- if (!_cairo_pattern_is_opaque (&pattern->base))
+
+ if (_cairo_surface_is_image (dst))
{
- cairo_surface_pattern_t tmp;
- cairo_color_t color;
-
- _cairo_color_init (&color);
- _cairo_color_set_alpha (&color, pattern->base.alpha);
-
- *out = _cairo_surface_create_similar_solid (dst,
- CAIRO_FORMAT_ARGB32,
- width, height,
- &color);
- if (*out == NULL)
- return CAIRO_STATUS_NO_MEMORY;
-
- status = _cairo_pattern_init_copy (&tmp.base, &pattern->base);
- if (CAIRO_OK (status))
- {
- tmp.base.alpha = 1.0;
- status = _cairo_surface_composite (CAIRO_OPERATOR_IN,
- &tmp.base,
- NULL,
- *out,
- x, y, 0, 0, 0, 0,
- width, height);
-
- _cairo_pattern_fini (&tmp.base);
- }
-
- if (status) {
- cairo_surface_destroy (*out);
- return status;
- }
+ cairo_image_surface_t *image;
- attr->x_offset = -x;
- attr->y_offset = -y;
- attr->extend = CAIRO_EXTEND_NONE;
- attr->filter = CAIRO_FILTER_GOOD;
+ status = _cairo_surface_acquire_source_image (pattern->surface,
+ &image,
+ &attr->extra);
+ if (CAIRO_OK (status))
+ *out = &image->base;
+ attr->acquired = TRUE;
+ }
+ else
+ status = _cairo_surface_clone_similar (dst, pattern->surface, out);
+
+ attr->extend = pattern->base.extend;
+ attr->filter = pattern->base.filter;
+ if (_cairo_matrix_is_integer_translation (&pattern->base.matrix,
+ &tx, &ty))
+ {
cairo_matrix_init_identity (&attr->matrix);
+ attr->x_offset = tx;
+ attr->y_offset = ty;
+ attr->filter = CAIRO_FILTER_NEAREST;
}
else
{
- int tx, ty;
-
- if (_cairo_surface_is_image (dst))
- {
- cairo_image_surface_t *image;
-
- status = _cairo_surface_acquire_source_image (pattern->surface,
- &image,
- &attr->extra);
- if (CAIRO_OK (status))
- *out = &image->base;
-
- attr->acquired = TRUE;
- }
- else
- status = _cairo_surface_clone_similar (dst, pattern->surface, out);
-
- attr->extend = pattern->base.extend;
- attr->filter = pattern->base.filter;
- if (_cairo_matrix_is_integer_translation (&pattern->base.matrix,
- &tx, &ty))
- {
- cairo_matrix_init_identity (&attr->matrix);
- attr->x_offset = tx;
- attr->y_offset = ty;
- attr->filter = CAIRO_FILTER_NEAREST;
- }
- else
- {
- attr->matrix = pattern->base.matrix;
- attr->x_offset = attr->y_offset = 0;
- }
+ attr->matrix = pattern->base.matrix;
+ attr->x_offset = attr->y_offset = 0;
}
return status;
@@ -1162,22 +1120,15 @@
/* fast path for gradients with less than 2 color stops */
if (src->n_stops < 2)
{
+ const cairo_color_t *color;
cairo_solid_pattern_t solid;
if (src->n_stops)
- {
- _cairo_pattern_init_solid (&solid,
- src->stops->color.red,
- src->stops->color.green,
- src->stops->color.blue);
- _cairo_pattern_set_alpha (&solid.base,
- src->stops->color.alpha);
- }
+ color = &src->stops->color;
else
- {
- _cairo_pattern_init_solid (&solid, 0.0, 0.0, 0.0);
- _cairo_pattern_set_alpha (&solid.base, 0.0);
- }
+ color = CAIRO_COLOR_TRANSPARENT;
+
+ _cairo_pattern_init_solid (&solid, color);
return _cairo_pattern_acquire_surface_for_solid (&solid, dst,
x, y,
@@ -1242,71 +1193,44 @@
cairo_surface_attributes_t *mask_attributes)
{
cairo_int_status_t status;
-
cairo_pattern_union_t tmp;
- cairo_bool_t src_opaque, mask_opaque;
- double src_alpha, mask_alpha;
- src_opaque = _cairo_pattern_is_opaque (src);
- mask_opaque = !mask || _cairo_pattern_is_opaque (mask);
-
- /* For surface patterns, we move any translucency from src->alpha
- * to mask->alpha so we can use the source unchanged. Otherwise we
- * move the translucency from mask->alpha to src->alpha so that
- * we can drop the mask if possible.
- */
- if (src->type == CAIRO_PATTERN_SURFACE)
- {
- if (mask) {
- mask_opaque = mask_opaque && src_opaque;
- mask_alpha = mask->alpha * src->alpha;
- } else {
- mask_opaque = src_opaque;
- mask_alpha = src->alpha;
- }
-
- src_alpha = 1.0;
- src_opaque = TRUE;
- }
- else
+ /* If src and mask are both solid, then the mask alpha can be
+ * combined into src and mask can be ignored. */
+
+ /* XXX: This optimization assumes that there is no color
+ * information in mask, so this will need to change when we
+ * support RENDER-style 4-channel masks. */
+ if (src->type == CAIRO_PATTERN_SOLID &&
+ mask->type == CAIRO_PATTERN_SOLID)
{
- if (mask)
- {
- src_opaque = mask_opaque && src_opaque;
- src_alpha = mask->alpha * src->alpha;
- /* FIXME: This needs changing when we support RENDER
- * style 4-channel masks.
- */
- if (mask->type == CAIRO_PATTERN_SOLID)
- mask = NULL;
- } else
- src_alpha = src->alpha;
+ cairo_color_t combined;
+ cairo_solid_pattern_t *src_solid = (cairo_solid_pattern_t *) src;
+ cairo_solid_pattern_t *mask_solid = (cairo_solid_pattern_t *) mask;
- mask_alpha = 1.0;
- mask_opaque = TRUE;
+ combined = src_solid->color;
+ _cairo_color_multiply_alpha (&combined, mask_solid->color.alpha);
+
+ _cairo_pattern_init_solid (&tmp.solid, &combined);
+
+ mask = NULL;
+ } else {
+ _cairo_pattern_init_copy (&tmp.base, src);
}
- _cairo_pattern_init_copy (&tmp.base, src);
- _cairo_pattern_set_alpha (&tmp.base, src_alpha);
-
status = _cairo_pattern_acquire_surface (&tmp.base, dst,
src_x, src_y,
width, height,
src_out, src_attributes);
-
+
_cairo_pattern_fini (&tmp.base);
if (status)
return status;
- if (mask || !mask_opaque)
+ if (mask)
{
- if (mask)
- _cairo_pattern_init_copy (&tmp.base, mask);
- else
- _cairo_pattern_init_solid (&tmp.solid, 0.0, 0.0, 0.0);
-
- _cairo_pattern_set_alpha (&tmp.base, mask_alpha);
+ _cairo_pattern_init_copy (&tmp.base, mask);
status = _cairo_pattern_acquire_surface (&tmp.base, dst,
mask_x, mask_y,
Index: cairo-pdf-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-pdf-surface.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- cairo-pdf-surface.c 8 Apr 2005 20:14:17 -0000 1.28
+++ cairo-pdf-surface.c 14 Apr 2005 21:42:26 -0000 1.29
@@ -1378,13 +1378,13 @@
cairo_output_stream_t *output = document->output_stream;
unsigned int alpha;
- alpha = _cairo_pdf_surface_add_alpha (surface, pattern->base.alpha);
+ alpha = _cairo_pdf_surface_add_alpha (surface, pattern->color.alpha);
_cairo_pdf_surface_ensure_stream (surface);
_cairo_output_stream_printf (output,
"%f %f %f rg /a%d gs\r\n",
- pattern->red,
- pattern->green,
- pattern->blue,
+ pattern->color.red,
+ pattern->color.green,
+ pattern->color.blue,
alpha);
}
Index: cairo-ps-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-ps-surface.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- cairo-ps-surface.c 7 Apr 2005 21:25:00 -0000 1.31
+++ cairo-ps-surface.c 14 Apr 2005 21:42:26 -0000 1.32
@@ -146,14 +146,9 @@
static void
_cairo_ps_surface_erase (cairo_ps_surface_t *surface)
{
- cairo_color_t transparent;
-
- _cairo_color_init (&transparent);
- _cairo_color_set_rgb (&transparent, 0., 0., 0.);
- _cairo_color_set_alpha (&transparent, 0.);
_cairo_surface_fill_rectangle (&surface->image->base,
CAIRO_OPERATOR_SRC,
- &transparent,
+ CAIRO_COLOR_TRANSPARENT,
0, 0,
surface->image->width,
surface->image->height);
@@ -222,7 +217,7 @@
/* PostScript can not represent the alpha channel, so we blend the
current image over a white RGB surface to eliminate it. */
- _cairo_pattern_init_solid (&white_pattern, 1.0, 1.0, 1.0);
+ _cairo_pattern_init_solid (&white_pattern, CAIRO_COLOR_WHITE);
_cairo_surface_composite (CAIRO_OPERATOR_OVER_REVERSE,
&white_pattern.base,
Index: cairo-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-surface.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- cairo-surface.c 13 Apr 2005 21:51:59 -0000 1.58
+++ cairo-surface.c 14 Apr 2005 21:42:26 -0000 1.59
@@ -1,6 +1,7 @@
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2002 University of Southern California
+ * Copyright © 2005 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
@@ -77,24 +78,20 @@
int width,
int height)
{
- cairo_color_t empty;
-
if (other == NULL)
return NULL;
- _cairo_color_init (&empty);
- _cairo_color_set_rgb (&empty, 0., 0., 0.);
- _cairo_color_set_alpha (&empty, 0.);
-
- return _cairo_surface_create_similar_solid (other, format, width, height, &empty);
+ return _cairo_surface_create_similar_solid (other, format,
+ width, height,
+ CAIRO_COLOR_TRANSPARENT);
}
cairo_surface_t *
-_cairo_surface_create_similar_solid (cairo_surface_t *other,
- cairo_format_t format,
- int width,
- int height,
- cairo_color_t *color)
+_cairo_surface_create_similar_solid (cairo_surface_t *other,
+ cairo_format_t format,
+ int width,
+ int height,
+ const cairo_color_t *color)
{
cairo_status_t status;
cairo_surface_t *surface;
@@ -604,13 +601,13 @@
}
cairo_status_t
-_cairo_surface_fill_rectangle (cairo_surface_t *surface,
- cairo_operator_t operator,
- cairo_color_t *color,
- int x,
- int y,
- int width,
- int height)
+_cairo_surface_fill_rectangle (cairo_surface_t *surface,
+ cairo_operator_t operator,
+ const cairo_color_t *color,
+ int x,
+ int y,
+ int width,
+ int height)
{
cairo_rectangle_t rect;
Index: cairo-xlib-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-xlib-surface.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- cairo-xlib-surface.c 7 Apr 2005 21:25:00 -0000 1.58
+++ cairo-xlib-surface.c 14 Apr 2005 21:42:26 -0000 1.59
@@ -866,6 +866,20 @@
_cairo_xlib_surface_show_glyphs
};
+/**
+ * _cairo_surface_is_xlib:
+ * @surface: a #cairo_surface_t
+ *
+ * Checks if a surface is a #cairo_xlib_surface_t
+ *
+ * Return value: True if the surface is an xlib surface
+ **/
+static cairo_bool_t
+_cairo_surface_is_xlib (cairo_surface_t *surface)
+{
+ return surface->backend == &cairo_xlib_surface_backend;
+}
+
static cairo_surface_t *
_cairo_xlib_surface_create_internal (Display *dpy,
Drawable drawable,
@@ -1089,6 +1103,10 @@
{
cairo_xlib_surface_t *xlib_surface = (cairo_xlib_surface_t *)surface;
+ /* XXX: How do we want to handle this error case? */
+ if (! _cairo_surface_is_xlib (surface))
+ return;
+
xlib_surface->width = width;
xlib_surface->height = height;
}
Index: cairo.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.c,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- cairo.c 11 Apr 2005 18:30:28 -0000 1.77
+++ cairo.c 14 Apr 2005 21:42:26 -0000 1.78
@@ -1,6 +1,7 @@
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2002 University of Southern California
+ * Copyright © 2005 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
@@ -661,20 +662,25 @@
}
/**
- * cairo_set_rgb_color:
- * @cr: a #cairo_t
+ * cairo_set_source_rgb
+ * @cr: a cairo context
* @red: red component of color
* @green: green component of color
* @blue: blue component of color
*
- * Sets a constant color for filling and stroking. This replaces any
- * pattern set with cairo_set_pattern(). The color components are
- * floating point numbers in the range 0 to 1. If the values passed in
- * are outside that range, they will be clamped.
+ * Sets the source pattern within @cr to an opaque color. This opaque
+ * color will then be used for any subsequent drawing operation until
+ * a new source pattern is set.
+ *
+ * The color components are floating point numbers in the range 0 to
+ * 1. If the values passed in are outside that range, they will be
+ * clamped.
**/
void
-cairo_set_rgb_color (cairo_t *cr, double red, double green, double blue)
+cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue)
{
+ cairo_color_t color;
+
CAIRO_CHECK_SANITY (cr);
if (cr->status)
return;
@@ -683,52 +689,101 @@
_cairo_restrict_value (&green, 0.0, 1.0);
_cairo_restrict_value (&blue, 0.0, 1.0);
- cr->status = _cairo_gstate_set_rgb_color (cr->gstate, red, green, blue);
+ _cairo_color_init_rgb (&color, red, green, blue);
+
+ cr->status = _cairo_gstate_set_source_solid (cr->gstate, &color);
+
CAIRO_CHECK_SANITY (cr);
}
/**
- * cairo_set_pattern:
- * @cr: a #cairo_t
- * @pattern: a #cairo_pattern_t to be used as the source for
+ * cairo_set_source_rgba:
+ * @cr: a cairo context
+ * @red: red component of color
+ * @green: green component of color
+ * @blue: blue component of color
+ * @alpha: alpha component of color
+ *
+ * Sets the source pattern within @cr to a translucent color. This
+ * color will then be used for any subsequent drawing operation until
+ * a new source pattern is set.
+ *
+ * The color and alpha components are floating point numbers in the
+ * range 0 to 1. If the values passed in are outside that range, they
+ * will be clamped.
+ **/
+void
+cairo_set_source_rgba (cairo_t *cr,
+ double red, double green, double blue,
+ double alpha)
+{
+ cairo_color_t color;
+
+ CAIRO_CHECK_SANITY (cr);
+ if (cr->status)
+ return;
+
+ _cairo_restrict_value (&red, 0.0, 1.0);
+ _cairo_restrict_value (&green, 0.0, 1.0);
+ _cairo_restrict_value (&blue, 0.0, 1.0);
+ _cairo_restrict_value (&alpha, 0.0, 1.0);
+
+ _cairo_color_init_rgba (&color, red, green, blue, alpha);
+
+ cr->status = _cairo_gstate_set_source_solid (cr->gstate, &color);
+
+ CAIRO_CHECK_SANITY (cr);
+}
+DEPRECATE(cairo_set_rgb_color, cairo_set_source_rgb);
+
+/**
+ * cairo_set_source
+ * @cr: a cairo context
+ * @source: a #cairo_pattern_t to be used as the source for
* subsequent drawing operations.
*
- * Sets the source pattern within @cr to @pattern. This pattern will
- * then be used for any subsequent drawing operation until a new
- * pattern is set.
+ * Sets the source pattern within @cr to @source. This pattern
+ * will then be used for any subsequent drawing operation until a new
+ * source pattern is set.
*
* XXX: I'd also like to direct the reader's attention to some
* (not-yet-written) section on cairo's imaging model. How would I do
* that if such a section existed? (cworth).
**/
void
-cairo_set_pattern (cairo_t *cr, cairo_pattern_t *pattern)
+cairo_set_source (cairo_t *cr, cairo_pattern_t *source)
{
CAIRO_CHECK_SANITY (cr);
if (cr->status)
return;
- cr->status = _cairo_gstate_set_pattern (cr->gstate, pattern);
+ cr->status = _cairo_gstate_set_source (cr->gstate, source);
CAIRO_CHECK_SANITY (cr);
}
+DEPRECATE(cairo_set_pattern, cairo_set_source);
/**
- * cairo_get_pattern:
- * @cr: a #cairo_t
+ * cairo_get_source:
+ * @cr: a cairo context
*
- * Gets the current source pattern for a #cairo_t.
+ * Gets the current source pattern for @cr.
*
* Return value: the current source pattern. This object is owned by
* cairo. To keep a reference to it, you must call
* cairo_pattern_reference().
**/
cairo_pattern_t *
-cairo_get_pattern (cairo_t *cr)
+cairo_get_source (cairo_t *cr)
{
CAIRO_CHECK_SANITY (cr);
- return _cairo_gstate_get_pattern (cr->gstate);
+ /* XXX: We'll want to do something like this:
+ if (cr->status)
+ return cairo_pattern_nil;
+ */
+
+ return _cairo_gstate_get_source (cr->gstate);
}
-DEPRECATE(cairo_current_pattern, cairo_get_pattern);
+DEPRECATE(cairo_current_pattern, cairo_get_source);
/**
* cairo_set_tolerance:
@@ -757,30 +812,6 @@
}
/**
- * cairo_set_alpha:
- * @cr: a #cairo_t
- * @alpha: the alpha value. 0 is transparent, 1 fully opaque.
- * if the value is outside the range 0 to 1, it will be
- * clamped to that range.
- *
- * Sets an overall alpha value used for stroking and filling. This
- * value is multiplied with any alpha value coming from a gradient or
- * image pattern.
- **/
-void
-cairo_set_alpha (cairo_t *cr, double alpha)
-{
- CAIRO_CHECK_SANITY (cr);
- if (cr->status)
- return;
-
- _cairo_restrict_value (&alpha, 0.0, 1.0);
-
- cr->status = _cairo_gstate_set_alpha (cr->gstate, alpha);
- CAIRO_CHECK_SANITY (cr);
-}
-
-/**
* cairo_set_fill_rule:
* @cr: a #cairo_t
* @fill_rule: a fill rule, specified as a #cairo_fill_rule_t
@@ -1891,8 +1922,8 @@
* operations, (in the case of an alternate source pattern being set
* by cairo_set_pattern()).
*
- * WARNING: This function is scheduled to be removed as part of the
- * upcoming API Shakeup.
+ * WARNING: This function is deprecated and scheduled to be removed as
+ * part of the upcoming API Shakeup.
**/
void
cairo_get_rgb_color (cairo_t *cr, double *red, double *green, double *blue)
@@ -1904,25 +1935,6 @@
DEPRECATE (cairo_current_rgb_color, cairo_get_rgb_color);
/**
- * cairo_get_alpha:
- * @cr: a cairo context
- *
- * Gets the current alpha value, as set by cairo_set_alpha().
- *
- * Return value: the current alpha value.
- *
- * WARNING: This function is scheduled to be removed as part of the
- * upcoming API Shakeup.
- **/
-double
-cairo_get_alpha (cairo_t *cr)
-{
- CAIRO_CHECK_SANITY (cr);
- return _cairo_gstate_get_alpha (cr->gstate);
-}
-DEPRECATE (cairo_current_alpha, cairo_get_alpha);
-
-/**
* cairo_get_tolerance:
* @cr: a cairo context
*
Index: cairo.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.h,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- cairo.h 11 Apr 2005 16:18:51 -0000 1.98
+++ cairo.h 14 Apr 2005 21:42:27 -0000 1.99
@@ -1,6 +1,7 @@
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2002 University of Southern California
+ * Copyright © 2005 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
@@ -237,31 +238,21 @@
void
cairo_set_operator (cairo_t *cr, cairo_operator_t op);
-/* XXX: Probably want to bite the bullet and expose a cairo_color_t object */
-
-/* XXX: I've been trying to come up with a sane way to specify:
-
- cairo_set_color (cairo_t *cr, cairo_color_t *color);
-
- Keith wants to be able to support super-luminescent colors,
- (premultiplied colors with R/G/B greater than alpha). The current
- API does not allow that. Adding a premulitplied RGBA cairo_color_t
- would do the trick.
-
- One problem though is that alpha is currently orthogonal to
- color. For example, show_surface uses gstate->alpha but ignores the
- color. So, it doesn't seem be right to have cairo_set_color modify
- the behavior of cairo_show_surface.
-*/
+void
+cairo_set_source (cairo_t *cr, cairo_pattern_t *pattern);
+/* XXX: NYI:
void
-cairo_set_rgb_color (cairo_t *cr, double red, double green, double blue);
+cairo_set_source_surface (cairo_t *cr, cairo_surface_t *surface);
+*/
void
-cairo_set_pattern (cairo_t *cr, cairo_pattern_t *pattern);
+cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue);
void
-cairo_set_alpha (cairo_t *cr, double alpha);
+cairo_set_source_rgba (cairo_t *cr,
+ double red, double green, double blue,
+ double alpha);
/* XXX: Currently, the tolerance value is specified by the user in
terms of device-space units. If I'm not mistaken, this is the only
@@ -698,8 +689,9 @@
void
cairo_get_rgb_color (cairo_t *cr, double *red, double *green, double *blue);
+
cairo_pattern_t *
-cairo_get_pattern (cairo_t *cr);
+cairo_get_source (cairo_t *cr);
double
cairo_get_alpha (cairo_t *cr);
@@ -977,11 +969,16 @@
cairo_pattern_destroy (cairo_pattern_t *pattern);
cairo_status_t
-cairo_pattern_add_color_stop (cairo_pattern_t *pattern,
- double offset,
- double red, double green, double blue,
- double alpha);
-
+cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern,
+ double offset,
+ double red, double green, double blue);
+
+cairo_status_t
+cairo_pattern_add_color_stop_rgba (cairo_pattern_t *pattern,
+ double offset,
+ double red, double green, double blue,
+ double alpha);
+
cairo_status_t
cairo_pattern_set_matrix (cairo_pattern_t *pattern, cairo_matrix_t *matrix);
@@ -1127,6 +1124,10 @@
#define cairo_default_matrix cairo_default_matrix_DEPRECATED_BY_cairo_identity_matrix
#define cairo_matrix_set_affine cairo_matrix_set_affine_DEPRECTATED_BY_cairo_matrix_init
#define cairo_matrix_set_identity cairo_matrix_set_identity_DEPRECATED_BY_cairo_matrix_init_identity
+#define cairo_pattern_add_color_stop cairo_pattern_add_color_stop_DEPRECATED_BY_cairo_pattern_add_color_stop_rgba
+#define cairo_set_rgb_color cairo_set_rgb_color_DEPRECATED_BY_cairo_set_source_rgb
+#define cairo_set_pattern cairo_set_pattern_DEPRECATED_BY_cairo_set_source
+#define cairo_set_alpha cairo_set_alpha_DEPRECATED_BY_cairo_set_source_rgba
#else /* CAIRO_API_SHAKEUP_FLAG_DAY */
@@ -1162,6 +1163,10 @@
#define cairo_default_matrix cairo_identity_matrix
#define cairo_matrix_set_affine cairo_matrix_init
#define cairo_matrix_set_identity cairo_matrix_init_identity
+#define cairo_pattern_add_color_stop cairo_pattern_add_color_stop_rgba
+#define cairo_set_rgb_color cairo_set_source_rgb
+#define cairo_set_pattern cairo_set_source
+#define cairo_set_alpha cairo_set_alpha_DEPRECATED_BY_cairo_set_source_rgba
#endif /* CAIRO_API_SHAKEUP_FLAG_DAY */
Index: cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -d -r1.126 -r1.127
--- cairoint.h 13 Apr 2005 18:23:43 -0000 1.126
+++ cairoint.h 14 Apr 2005 21:42:27 -0000 1.127
@@ -1,6 +1,7 @@
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2002 University of Southern California
+ * Copyright © 2005 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
@@ -723,6 +724,12 @@
unsigned short alpha_short;
};
+typedef enum {
+ CAIRO_STOCK_WHITE,
+ CAIRO_STOCK_BLACK,
+ CAIRO_STOCK_TRANSPARENT
+} cairo_stock_t;
+
#define CAIRO_EXTEND_DEFAULT CAIRO_EXTEND_NONE
#define CAIRO_FILTER_DEFAULT CAIRO_FILTER_BEST
@@ -744,13 +751,11 @@
cairo_matrix_t matrix;
cairo_filter_t filter;
cairo_extend_t extend;
- double alpha;
};
typedef struct _cairo_solid_pattern {
cairo_pattern_t base;
-
- double red, green, blue;
+ cairo_color_t color;
} cairo_solid_pattern_t;
typedef struct _cairo_surface_pattern {
@@ -924,10 +929,14 @@
_cairo_gstate_get_target_surface (cairo_gstate_t *gstate);
cairo_private cairo_status_t
-_cairo_gstate_set_pattern (cairo_gstate_t *gstate, cairo_pattern_t *pattern);
+_cairo_gstate_set_source (cairo_gstate_t *gstate, cairo_pattern_t *source);
+
+cairo_status_t
+_cairo_gstate_set_source_solid (cairo_gstate_t *gstate,
+ const cairo_color_t *color);
cairo_private cairo_pattern_t *
-_cairo_gstate_get_pattern (cairo_gstate_t *gstate);
+_cairo_gstate_get_source (cairo_gstate_t *gstate);
cairo_private cairo_status_t
_cairo_gstate_set_operator (cairo_gstate_t *gstate, cairo_operator_t operator);
@@ -936,9 +945,6 @@
_cairo_gstate_get_operator (cairo_gstate_t *gstate);
cairo_private cairo_status_t
-_cairo_gstate_set_rgb_color (cairo_gstate_t *gstate, double red, double green, double blue);
-
-cairo_private cairo_status_t
_cairo_gstate_get_rgb_color (cairo_gstate_t *gstate,
double *red,
double *green,
@@ -951,12 +957,6 @@
_cairo_gstate_get_tolerance (cairo_gstate_t *gstate);
cairo_private cairo_status_t
-_cairo_gstate_set_alpha (cairo_gstate_t *gstate, double alpha);
-
-cairo_private double
-_cairo_gstate_get_alpha (cairo_gstate_t *gstate);
-
-cairo_private cairo_status_t
_cairo_gstate_set_fill_rule (cairo_gstate_t *gstate, cairo_fill_rule_t fill_rule);
cairo_private cairo_fill_rule_t
@@ -1184,21 +1184,42 @@
/* cairo_color.c */
+cairo_private const cairo_color_t *
+_cairo_stock_color (cairo_stock_t stock);
+
+#define CAIRO_COLOR_WHITE _cairo_stock_color (CAIRO_STOCK_WHITE)
+#define CAIRO_COLOR_BLACK _cairo_stock_color (CAIRO_STOCK_BLACK)
+#define CAIRO_COLOR_TRANSPARENT _cairo_stock_color (CAIRO_STOCK_TRANSPARENT)
+
cairo_private void
_cairo_color_init (cairo_color_t *color);
cairo_private void
-_cairo_color_fini (cairo_color_t *color);
+_cairo_color_init_rgb (cairo_color_t *color,
+ double red, double green, double blue);
cairo_private void
-_cairo_color_set_rgb (cairo_color_t *color, double red, double green, double blue);
+_cairo_color_init_rgba (cairo_color_t *color,
+ double red, double green, double blue,
+ double alpha);
cairo_private void
-_cairo_color_get_rgb (const cairo_color_t *color,
- double *red, double *green, double *blue);
+_cairo_color_multiply_alpha (cairo_color_t *color,
+ double alpha);
cairo_private void
-_cairo_color_set_alpha (cairo_color_t *color, double alpha);
+_cairo_color_get_rgba (cairo_color_t *color,
+ double *red,
+ double *green,
+ double *blue,
+ double *alpha);
+
+cairo_private void
+_cairo_color_get_rgba_premultiplied (cairo_color_t *color,
+ double *red,
+ double *green,
+ double *blue,
+ double *alpha);
/* cairo-font.c */
@@ -1375,24 +1396,24 @@
int height);
cairo_private cairo_surface_t *
-_cairo_surface_create_similar_solid (cairo_surface_t *other,
- cairo_format_t format,
- int width,
- int height,
- cairo_color_t *color);
+_cairo_surface_create_similar_solid (cairo_surface_t *other,
+ cairo_format_t format,
+ int width,
+ int height,
+ const cairo_color_t *color);
cairo_private void
_cairo_surface_init (cairo_surface_t *surface,
const cairo_surface_backend_t *backend);
cairo_private cairo_status_t
-_cairo_surface_fill_rectangle (cairo_surface_t *surface,
- cairo_operator_t operator,
- cairo_color_t *color,
- int x,
- int y,
- int width,
- int height);
+_cairo_surface_fill_rectangle (cairo_surface_t *surface,
+ cairo_operator_t operator,
+ const cairo_color_t *color,
+ int x,
+ int y,
+ int width,
+ int height);
cairo_private cairo_status_t
_cairo_surface_composite (cairo_operator_t operator,
@@ -1649,7 +1670,7 @@
cairo_private void
_cairo_pattern_init_solid (cairo_solid_pattern_t *pattern,
- double red, double green, double blue);
+ const cairo_color_t *color);
cairo_private void
_cairo_pattern_init_for_surface (cairo_surface_pattern_t *pattern,
@@ -1668,21 +1689,18 @@
_cairo_pattern_fini (cairo_pattern_t *pattern);
cairo_private cairo_pattern_t *
-_cairo_pattern_create_solid (double red, double green, double blue);
+_cairo_pattern_create_solid (const cairo_color_t *color);
cairo_private cairo_status_t
_cairo_pattern_get_rgb (cairo_pattern_t *pattern,
double *red, double *green, double *blue);
cairo_private void
-_cairo_pattern_set_alpha (cairo_pattern_t *pattern, double alpha);
-
-cairo_private void
_cairo_pattern_transform (cairo_pattern_t *pattern,
cairo_matrix_t *ctm_inverse);
cairo_private cairo_bool_t
-_cairo_pattern_is_opaque (cairo_pattern_t *pattern);
+_cairo_pattern_is_opaque_solid (cairo_pattern_t *pattern);
cairo_private cairo_int_status_t
_cairo_pattern_acquire_surface (cairo_pattern_t *pattern,
- Previous message: [cairo-commit]
cairo/test Makefile.am, 1.34, 1.35 cairo-test.c, 1.18,
1.19 clip-twice.c, 1.3, 1.4 coverage.c, 1.6, 1.7 fill-rule.c,
1.4, 1.5 line-width.c, 1.3, 1.4 linear-gradient.c, 1.3,
1.4 pixman-rotate.c, 1.5, 1.6 set-source.c, 1.1,
1.2 text-rotate.c, 1.7, 1.8 trap-clip.c, 1.1, 1.2
- Next message: [cairo-commit] cairo ChangeLog,1.512,1.513 TODO,1.44,1.45
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the cairo-commit
mailing list