[cairo-commit] src/cairo-color.c src/cairo-gl-surface.c src/cairo-gstate.c src/cairoint.h src/cairo-pattern.c src/drm
Chris Wilson
ickle at kemper.freedesktop.org
Thu May 13 01:53:39 PDT 2010
src/cairo-color.c | 30 ++++++++++++++++++++++++++++++
src/cairo-gl-surface.c | 4 ++--
src/cairo-gstate.c | 4 ++--
src/cairo-pattern.c | 6 +++---
src/cairoint.h | 4 ++++
src/drm/cairo-drm-intel.c | 2 +-
6 files changed, 42 insertions(+), 8 deletions(-)
New commits:
commit dfa2544f158930b002df74e676f3ef7aeeee1bd4
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Thu May 13 09:52:39 2010 +0100
color: Special case comparing color stops.
color stops are not premultiplied so we need to handle them carefully
when comparing. The next step will be to make cairo_color_stop_t a
unique type to prevent this mistake again.
diff --git a/src/cairo-color.c b/src/cairo-color.c
index 1df82bb..d6c6c3d 100644
--- a/src/cairo-color.c
+++ b/src/cairo-color.c
@@ -174,3 +174,33 @@ _cairo_color_equal (const cairo_color_t *color_a,
color_a->blue_short == color_b->blue_short &&
color_a->alpha_short == color_b->alpha_short;
}
+
+cairo_bool_t
+_cairo_color_stop_equal (const cairo_color_t *color_a,
+ const cairo_color_t *color_b)
+{
+ uint16_t a, b;
+
+ if (color_a == color_b)
+ return TRUE;
+
+ if (color_a->alpha_short != color_b->alpha_short)
+ return FALSE;
+
+ a = _cairo_color_double_to_short (color_a->red * color_a->alpha);
+ b = _cairo_color_double_to_short (color_b->red * color_b->alpha);
+ if (a != b)
+ return FALSE;
+
+ a = _cairo_color_double_to_short (color_a->green * color_a->alpha);
+ b = _cairo_color_double_to_short (color_b->green * color_b->alpha);
+ if (a != b)
+ return FALSE;
+
+ a = _cairo_color_double_to_short (color_a->blue * color_a->alpha);
+ b = _cairo_color_double_to_short (color_b->blue * color_b->alpha);
+ if (a != b)
+ return FALSE;
+
+ return TRUE;
+}
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index 82a3981..27fc02c 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -1253,8 +1253,8 @@ _cairo_gl_gradient_operand_init(cairo_gl_context_t *ctx,
* Happens more often than you would believe.
*/
for (i = 1; i < gradient->n_stops; i++) {
- if (! _cairo_color_equal (&gradient->stops[0].color,
- &gradient->stops[i].color))
+ if (! _cairo_color_stop_equal (&gradient->stops[0].color,
+ &gradient->stops[i].color))
{
break;
}
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index 78aab50..c3f63db 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -887,8 +887,8 @@ _cairo_gstate_copy_pattern (cairo_pattern_t *pattern,
* Happens more often than you would believe.
*/
for (i = 1; i < src->n_stops; i++) {
- if (! _cairo_color_equal (&src->stops[0].color,
- &src->stops[i].color))
+ if (! _cairo_color_stop_equal (&src->stops[0].color,
+ &src->stops[i].color))
{
break;
}
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index 8504527..2fea11a 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -2294,8 +2294,8 @@ _cairo_pattern_acquire_surface (const cairo_pattern_t *pattern,
* Happens more often than you would believe.
*/
for (i = 1; i < src->n_stops; i++) {
- if (! _cairo_color_equal (&src->stops[0].color,
- &src->stops[i].color))
+ if (! _cairo_color_stop_equal (&src->stops[0].color,
+ &src->stops[i].color))
{
break;
}
@@ -2767,7 +2767,7 @@ _cairo_gradient_color_stops_equal (const cairo_gradient_pattern_t *a,
for (n = 0; n < a->n_stops; n++) {
if (a->stops[n].offset != b->stops[n].offset)
return FALSE;
- if (! _cairo_color_equal (&a->stops[n].color, &b->stops[n].color))
+ if (! _cairo_color_stop_equal (&a->stops[n].color, &b->stops[n].color))
return FALSE;
}
diff --git a/src/cairoint.h b/src/cairoint.h
index 5cf0bcf..6fe3702 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1309,6 +1309,10 @@ cairo_private cairo_bool_t
_cairo_color_equal (const cairo_color_t *color_a,
const cairo_color_t *color_b) cairo_pure;
+cairo_private cairo_bool_t
+_cairo_color_stop_equal (const cairo_color_t *color_a,
+ const cairo_color_t *color_b) cairo_pure;
+
/* cairo-font-face.c */
extern const cairo_private cairo_font_face_t _cairo_font_face_nil;
diff --git a/src/drm/cairo-drm-intel.c b/src/drm/cairo-drm-intel.c
index 4d69f8a..032647c 100644
--- a/src/drm/cairo-drm-intel.c
+++ b/src/drm/cairo-drm-intel.c
@@ -1421,7 +1421,7 @@ _gradient_color_stops_equal (const cairo_gradient_pattern_t *a,
return FALSE;
}
- if (! _cairo_color_equal (&a->stops[n].color, &b->stops[n].color))
+ if (! _cairo_color_stop_equal (&a->stops[n].color, &b->stops[n].color))
return FALSE;
}
More information about the cairo-commit
mailing list