#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <assert.h>
#include "pixman-private.h"
-#define Alpha(x) ((x) >> 24)
+static const pixman_color_t transparent_black = { 0, 0, 0, 0 };
-static source_pict_class_t
-SourcePictureClassify (pixman_image_t *image,
- int x,
- int y,
- int width,
- int height)
+static void
+gradient_property_changed (pixman_image_t *image)
{
- source_image_t *pict = &image->source;
-
- pict->class = SOURCE_IMAGE_CLASS_UNKNOWN;
-
- if (pict->common.type == SOLID)
- {
- pict->class = SOURCE_IMAGE_CLASS_HORIZONTAL;
- }
- else if (pict->common.type == LINEAR)
- {
- linear_gradient_t *linear = (linear_gradient_t *)pict;
- pixman_vector_t v;
- pixman_fixed_32_32_t l;
- pixman_fixed_48_16_t dx, dy, a, b, off;
- pixman_fixed_48_16_t factors[4];
- int i;
-
- dx = linear->p2.x - linear->p1.x;
- dy = linear->p2.y - linear->p1.y;
- l = dx * dx + dy * dy;
- if (l)
- {
- a = (dx << 32) / l;
- b = (dy << 32) / l;
- }
- else
- {
- a = b = 0;
- }
-
- off = (-a * linear->p1.x
- -b * linear->p1.y) >> 16;
-
- for (i = 0; i < 3; i++)
- {
- v.vector[0] = pixman_int_to_fixed ((i % 2) * (width - 1) + x);
- v.vector[1] = pixman_int_to_fixed ((i / 2) * (height - 1) + y);
- v.vector[2] = pixman_fixed_1;
+ gradient_t *gradient = &image->gradient;
+ int n = gradient->n_stops;
+ pixman_gradient_stop_t *stops = gradient->stops;
+ pixman_gradient_stop_t *begin = &(gradient->stops[-1]);
+ pixman_gradient_stop_t *end = &(gradient->stops[n]);
- if (pict->common.transform)
- {
- if (!pixman_transform_point_3d (pict->common.transform, &v))
- {
- pict->class = SOURCE_IMAGE_CLASS_UNKNOWN;
- goto out;
- }
- }
-
- factors[i] = ((a * v.vector[0] + b * v.vector[1]) >> 16) + off;
- }
-
- if (factors[2] == factors[0])
- pict->class = SOURCE_IMAGE_CLASS_HORIZONTAL;
- else if (factors[1] == factors[0])
- pict->class = SOURCE_IMAGE_CLASS_VERTICAL;
+ switch (gradient->common.repeat)
+ {
+ default:
+ case PIXMAN_REPEAT_NONE:
+ begin->x = INT32_MIN;
+ begin->color = transparent_black;
+ end->x = INT32_MAX;
+ end->color = transparent_black;
+ break;
+
+ case PIXMAN_REPEAT_NORMAL:
+ begin->x = stops[n - 1].x - pixman_fixed_1;
+ begin->color = stops[n - 1].color;
+ end->x = stops[0].x + pixman_fixed_1;
+ end->color = stops[0].color;
+ break;
+
+ case PIXMAN_REPEAT_REFLECT:
+ begin->x = - stops[0].x;
+ begin->color = stops[0].color;
+ end->x = pixman_int_to_fixed (2) - stops[n - 1].x;
+ end->color = stops[n - 1].color;
+ break;
+
+ case PIXMAN_REPEAT_PAD:
+ begin->x = INT32_MIN;
+ begin->color = stops[0].color;
+ end->x = INT32_MAX;
+ end->color = stops[n - 1].color;
+ break;
}
-
-out:
- return pict->class;
}
-static void
-init_source_image (source_image_t *image)
-{
- image->class = SOURCE_IMAGE_CLASS_UNKNOWN;
- image->common.classify = SourcePictureClassify;
-}
-
-static pixman_bool_t
-init_gradient (gradient_t *gradient,
- const pixman_gradient_stop_t *stops,
- int n_stops)
+pixman_bool_t
+_pixman_init_gradient (gradient_t * gradient,
+ const pixman_gradient_stop_t *stops,
+ int n_stops)
{
return_val_if_fail (n_stops > 0, FALSE);
- init_source_image (&gradient->common);
-
- gradient->stops = pixman_malloc_ab (n_stops, sizeof (pixman_gradient_stop_t));
+ /* We allocate two extra stops, one before the beginning of the stop list,
+ * and one after the end. These stops are initialized to whatever color
+ * would be used for positions outside the range of the stop list.
+ *
+ * This saves a bit of computation in the gradient walker.
+ *
+ * The pointer we store in the gradient_t struct still points to the
+ * first user-supplied struct, so when freeing, we will have to
+ * subtract one.
+ */
+ gradient->stops =
+ pixman_malloc_ab (n_stops + 2, sizeof (pixman_gradient_stop_t));
if (!gradient->stops)
return FALSE;
+ gradient->stops += 1;
memcpy (gradient->stops, stops, n_stops * sizeof (pixman_gradient_stop_t));
-
gradient->n_stops = n_stops;
- gradient->stop_range = 0xffff;
- gradient->color_table = NULL;
- gradient->color_table_size = 0;
+ gradient->common.property_changed = gradient_property_changed;
return TRUE;
}
-static uint32_t
-color_to_uint32 (const pixman_color_t *color)
-{
- return
- (color->alpha >> 8 << 24) |
- (color->red >> 8 << 16) |
- (color->green & 0xff00) |
- (color->blue >> 8);
-}
-
-static pixman_image_t *
-allocate_image (void)
+void
+_pixman_image_init (pixman_image_t *image)
{
- pixman_image_t *image = malloc (sizeof (pixman_image_t));
-
- if (image)
- {
- image_common_t *common = &image->common;
-
- pixman_region32_init (&common->full_region);
- pixman_region32_init (&common->clip_region);
- common->src_clip = &common->full_region;
- common->has_client_clip = FALSE;
- common->transform = NULL;
- common->repeat = PIXMAN_REPEAT_NONE;
- common->filter = PIXMAN_FILTER_NEAREST;
- common->filter_params = NULL;
- common->n_filter_params = 0;
- common->alpha_map = NULL;
- common->component_alpha = FALSE;
- common->ref_count = 1;
- common->read_func = NULL;
- common->write_func = NULL;
- common->classify = NULL;
- }
+ image_common_t *common = &image->common;
- return image;
+ pixman_region32_init (&common->clip_region);
+
+ common->alpha_count = 0;
+ common->have_clip_region = FALSE;
+ common->clip_sources = FALSE;
+ common->transform = NULL;
+ common->repeat = PIXMAN_REPEAT_NONE;
+ common->filter = PIXMAN_FILTER_NEAREST;
+ common->filter_params = NULL;
+ common->n_filter_params = 0;
+ common->alpha_map = NULL;
+ common->component_alpha = FALSE;
+ common->ref_count = 1;
+ common->property_changed = NULL;
+ common->client_clip = FALSE;
+ common->destroy_func = NULL;
+ common->destroy_data = NULL;
+ common->dirty = TRUE;
}
-source_pict_class_t
-_pixman_image_classify (pixman_image_t *image,
- int x,
- int y,
- int width,
- int height)
+pixman_bool_t
+_pixman_image_fini (pixman_image_t *image)
{
- if (image->common.classify)
- return image->common.classify (image, x, y, width, height);
- else
- return SOURCE_IMAGE_CLASS_UNKNOWN;
-}
-
-#define READ_ACCESS(f) ((image->common.read_func)? f##_accessors : f)
+ image_common_t *common = (image_common_t *)image;
-static void fbFetchSolid(bits_image_t * image, int x, int y, int width, uint32_t *buffer, uint32_t *mask, uint32_t maskBits)
-{
- uint32_t color;
- uint32_t *end;
- fetchPixelProc32 fetch = READ_ACCESS(pixman_fetchPixelProcForPicture32)(image);
+ common->ref_count--;
- color = fetch(image, 0, 0);
+ if (common->ref_count == 0)
+ {
+ if (image->common.destroy_func)
+ image->common.destroy_func (image, image->common.destroy_data);
- end = buffer + width;
- while (buffer < end)
- *(buffer++) = color;
-}
+ pixman_region32_fini (&common->clip_region);
-static void fbFetchSolid64(bits_image_t * image, int x, int y, int width, uint64_t *buffer, void *unused, uint32_t unused2)
-{
- uint64_t color;
- uint64_t *end;
- fetchPixelProc64 fetch = READ_ACCESS(pixman_fetchPixelProcForPicture64)(image);
+ free (common->transform);
+ free (common->filter_params);
- color = fetch(image, 0, 0);
+ if (common->alpha_map)
+ pixman_image_unref ((pixman_image_t *)common->alpha_map);
- end = buffer + width;
- while (buffer < end)
- *(buffer++) = color;
-}
+ if (image->type == LINEAR ||
+ image->type == RADIAL ||
+ image->type == CONICAL)
+ {
+ if (image->gradient.stops)
+ {
+ /* See _pixman_init_gradient() for an explanation of the - 1 */
+ free (image->gradient.stops - 1);
+ }
-static void fbFetch(bits_image_t * image, int x, int y, int width, uint32_t *buffer, uint32_t *mask, uint32_t maskBits)
-{
- fetchProc32 fetch = READ_ACCESS(pixman_fetchProcForPicture32)(image);
+ /* This will trigger if someone adds a property_changed
+ * method to the linear/radial/conical gradient overwriting
+ * the general one.
+ */
+ assert (
+ image->common.property_changed == gradient_property_changed);
+ }
- fetch(image, x, y, width, buffer);
-}
+ if (image->type == BITS && image->bits.free_me)
+ free (image->bits.free_me);
-static void fbFetch64(bits_image_t * image, int x, int y, int width, uint64_t *buffer, void *unused, uint32_t unused2)
-{
- fetchProc64 fetch = READ_ACCESS(pixman_fetchProcForPicture64)(image);
+ return TRUE;
+ }
- fetch(image, x, y, width, buffer);
+ return FALSE;
}
-scanFetchProc
-_pixman_image_get_fetcher (pixman_image_t *image,
- int wide)
+pixman_image_t *
+_pixman_image_allocate (void)
{
- if (IS_SOURCE_IMAGE (image))
- {
- if (wide)
- return (scanFetchProc)pixmanFetchSourcePict64;
- else
- return (scanFetchProc)pixmanFetchSourcePict;
- }
- else
- {
- bits_image_t *bits = (bits_image_t *)image;
-
- if (bits->common.alpha_map)
- {
- if (wide)
- return (scanFetchProc)READ_ACCESS(fbFetchExternalAlpha64);
- else
- return (scanFetchProc)READ_ACCESS(fbFetchExternalAlpha);
- }
- else if ((bits->common.repeat != PIXMAN_REPEAT_NONE) &&
- bits->width == 1 &&
- bits->height == 1)
- {
- if (wide)
- return (scanFetchProc)fbFetchSolid64;
- else
- return (scanFetchProc)fbFetchSolid;
- }
- else if (!bits->common.transform && bits->common.filter != PIXMAN_FILTER_CONVOLUTION
- && bits->common.repeat != PIXMAN_REPEAT_PAD && bits->common.repeat != PIXMAN_REPEAT_REFLECT)
- {
- if (wide)
- return (scanFetchProc)fbFetch64;
- else
- return (scanFetchProc)fbFetch;
- }
- else
- {
- if (wide)
- return (scanFetchProc)READ_ACCESS(fbFetchTransformed64);
- else
- return (scanFetchProc)READ_ACCESS(fbFetchTransformed);
- }
- }
-}
+ pixman_image_t *image = malloc (sizeof (pixman_image_t));
-#define WRITE_ACCESS(f) ((image->common.write_func)? f##_accessors : f)
+ if (image)
+ _pixman_image_init (image);
-static void
-fbStore(bits_image_t * image, int x, int y, int width, uint32_t *buffer)
-{
- uint32_t *bits;
- int32_t stride;
- storeProc32 store = WRITE_ACCESS(pixman_storeProcForPicture32)(image);
- const pixman_indexed_t * indexed = image->indexed;
-
- bits = image->bits;
- stride = image->rowstride;
- bits += y*stride;
- store((pixman_image_t *)image, bits, buffer, x, width, indexed);
+ return image;
}
static void
-fbStore64(bits_image_t * image, int x, int y, int width, uint64_t *buffer)
+image_property_changed (pixman_image_t *image)
{
- uint32_t *bits;
- int32_t stride;
- storeProc64 store = WRITE_ACCESS(pixman_storeProcForPicture64)(image);
- const pixman_indexed_t * indexed = image->indexed;
-
- bits = image->bits;
- stride = image->rowstride;
- bits += y*stride;
- store((pixman_image_t *)image, bits, buffer, x, width, indexed);
-}
-
-scanStoreProc
-_pixman_image_get_storer (pixman_image_t *image,
- int wide)
-{
- if (image->common.alpha_map)
- {
- if (wide)
- return (scanStoreProc)WRITE_ACCESS(fbStoreExternalAlpha64);
- else
- return (scanStoreProc)WRITE_ACCESS(fbStoreExternalAlpha);
- }
- else
- {
- if (wide)
- return (scanStoreProc)fbStore64;
- else
- return (scanStoreProc)fbStore;
- }
+ image->common.dirty = TRUE;
}
/* Ref Counting */
PIXMAN_EXPORT pixman_bool_t
pixman_image_unref (pixman_image_t *image)
{
- image_common_t *common = (image_common_t *)image;
-
- common->ref_count--;
-
- if (common->ref_count == 0)
+ if (_pixman_image_fini (image))
{
- pixman_region32_fini (&common->clip_region);
- pixman_region32_fini (&common->full_region);
-
- if (common->transform)
- free (common->transform);
-
- if (common->filter_params)
- free (common->filter_params);
-
- if (common->alpha_map)
- pixman_image_unref ((pixman_image_t *)common->alpha_map);
-
-#if 0
- if (image->type == BITS && image->bits.indexed)
- free (image->bits.indexed);
-#endif
-
-#if 0
- memset (image, 0xaa, sizeof (pixman_image_t));
-#endif
- if (image->type == LINEAR || image->type == RADIAL || image->type == CONICAL)
- {
- if (image->gradient.stops)
- free (image->gradient.stops);
- }
-
-
- if (image->type == BITS && image->bits.free_me)
- free (image->bits.free_me);
-
free (image);
-
return TRUE;
}
return FALSE;
}
-/* Constructors */
-PIXMAN_EXPORT pixman_image_t *
-pixman_image_create_solid_fill (pixman_color_t *color)
+PIXMAN_EXPORT void
+pixman_image_set_destroy_function (pixman_image_t * image,
+ pixman_image_destroy_func_t func,
+ void * data)
{
- pixman_image_t *img = allocate_image();
- if (!img)
- return NULL;
-
- init_source_image (&img->solid.common);
-
- img->type = SOLID;
- img->solid.color = color_to_uint32 (color);
-
- return img;
+ image->common.destroy_func = func;
+ image->common.destroy_data = data;
}
-PIXMAN_EXPORT pixman_image_t *
-pixman_image_create_linear_gradient (pixman_point_fixed_t *p1,
- pixman_point_fixed_t *p2,
- const pixman_gradient_stop_t *stops,
- int n_stops)
+PIXMAN_EXPORT void *
+pixman_image_get_destroy_data (pixman_image_t *image)
{
- pixman_image_t *image;
- linear_gradient_t *linear;
-
- return_val_if_fail (n_stops >= 2, NULL);
+ return image->common.destroy_data;
+}
- image = allocate_image();
+void
+_pixman_image_reset_clip_region (pixman_image_t *image)
+{
+ image->common.have_clip_region = FALSE;
+}
- if (!image)
- return NULL;
+/* Executive Summary: This function is a no-op that only exists
+ * for historical reasons.
+ *
+ * There used to be a bug in the X server where it would rely on
+ * out-of-bounds accesses when it was asked to composite with a
+ * window as the source. It would create a pixman image pointing
+ * to some bogus position in memory, but then set a clip region
+ * to the position where the actual bits were.
+ *
+ * Due to a bug in old versions of pixman, where it would not clip
+ * against the image bounds when a clip region was set, this would
+ * actually work. So when the pixman bug was fixed, a workaround was
+ * added to allow certain out-of-bound accesses. This function disabled
+ * those workarounds.
+ *
+ * Since 0.21.2, pixman doesn't do these workarounds anymore, so now
+ * this function is a no-op.
+ */
+PIXMAN_EXPORT void
+pixman_disable_out_of_bounds_workaround (void)
+{
+}
- linear = &image->linear;
+static void
+compute_image_info (pixman_image_t *image)
+{
+ pixman_format_code_t code;
+ uint32_t flags = 0;
- if (!init_gradient (&linear->common, stops, n_stops))
+ /* Transform */
+ if (!image->common.transform)
{
- free (image);
- return NULL;
+ flags |= (FAST_PATH_ID_TRANSFORM |
+ FAST_PATH_X_UNIT_POSITIVE |
+ FAST_PATH_Y_UNIT_ZERO |
+ FAST_PATH_AFFINE_TRANSFORM);
}
+ else
+ {
+ flags |= FAST_PATH_HAS_TRANSFORM;
- linear->p1 = *p1;
- linear->p2 = *p2;
-
- image->type = LINEAR;
-
- return image;
-}
+ if (image->common.transform->matrix[2][0] == 0 &&
+ image->common.transform->matrix[2][1] == 0 &&
+ image->common.transform->matrix[2][2] == pixman_fixed_1)
+ {
+ flags |= FAST_PATH_AFFINE_TRANSFORM;
+ if (image->common.transform->matrix[0][1] == 0 &&
+ image->common.transform->matrix[1][0] == 0)
+ {
+ if (image->common.transform->matrix[0][0] == -pixman_fixed_1 &&
+ image->common.transform->matrix[1][1] == -pixman_fixed_1)
+ {
+ flags |= FAST_PATH_ROTATE_180_TRANSFORM;
+ }
+ flags |= FAST_PATH_SCALE_TRANSFORM;
+ }
+ else if (image->common.transform->matrix[0][0] == 0 &&
+ image->common.transform->matrix[1][1] == 0)
+ {
+ pixman_fixed_t m01 = image->common.transform->matrix[0][1];
+ pixman_fixed_t m10 = image->common.transform->matrix[1][0];
-PIXMAN_EXPORT pixman_image_t *
-pixman_image_create_radial_gradient (pixman_point_fixed_t *inner,
- pixman_point_fixed_t *outer,
- pixman_fixed_t inner_radius,
- pixman_fixed_t outer_radius,
- const pixman_gradient_stop_t *stops,
- int n_stops)
-{
- pixman_image_t *image;
- radial_gradient_t *radial;
+ if (m01 == -1 && m10 == 1)
+ flags |= FAST_PATH_ROTATE_90_TRANSFORM;
+ else if (m01 == 1 && m10 == -1)
+ flags |= FAST_PATH_ROTATE_270_TRANSFORM;
+ }
+ }
- return_val_if_fail (n_stops >= 2, NULL);
+ if (image->common.transform->matrix[0][0] > 0)
+ flags |= FAST_PATH_X_UNIT_POSITIVE;
- image = allocate_image();
+ if (image->common.transform->matrix[1][0] == 0)
+ flags |= FAST_PATH_Y_UNIT_ZERO;
+ }
- if (!image)
- return NULL;
+ /* Filter */
+ switch (image->common.filter)
+ {
+ case PIXMAN_FILTER_NEAREST:
+ case PIXMAN_FILTER_FAST:
+ flags |= (FAST_PATH_NEAREST_FILTER | FAST_PATH_NO_CONVOLUTION_FILTER);
+ break;
- radial = &image->radial;
+ case PIXMAN_FILTER_BILINEAR:
+ case PIXMAN_FILTER_GOOD:
+ case PIXMAN_FILTER_BEST:
+ flags |= (FAST_PATH_BILINEAR_FILTER | FAST_PATH_NO_CONVOLUTION_FILTER);
- if (!init_gradient (&radial->common, stops, n_stops))
- {
- free (image);
- return NULL;
- }
+ /* Here we have a chance to optimize BILINEAR filter to NEAREST if
+ * they are equivalent for the currently used transformation matrix.
+ */
+ if (flags & FAST_PATH_ID_TRANSFORM)
+ {
+ flags |= FAST_PATH_NEAREST_FILTER;
+ }
+ else if (
+ /* affine and integer translation components in matrix ... */
+ ((flags & FAST_PATH_AFFINE_TRANSFORM) &&
+ !pixman_fixed_frac (image->common.transform->matrix[0][2] |
+ image->common.transform->matrix[1][2])) &&
+ (
+ /* ... combined with a simple rotation */
+ (flags & (FAST_PATH_ROTATE_90_TRANSFORM |
+ FAST_PATH_ROTATE_180_TRANSFORM |
+ FAST_PATH_ROTATE_270_TRANSFORM)) ||
+ /* ... or combined with a simple non-rotated translation */
+ (image->common.transform->matrix[0][0] == pixman_fixed_1 &&
+ image->common.transform->matrix[1][1] == pixman_fixed_1 &&
+ image->common.transform->matrix[0][1] == 0 &&
+ image->common.transform->matrix[1][0] == 0)
+ )
+ )
+ {
+ /* FIXME: there are some affine-test failures, showing that
+ * handling of BILINEAR and NEAREST filter is not quite
+ * equivalent when getting close to 32K for the translation
+ * components of the matrix. That's likely some bug, but for
+ * now just skip BILINEAR->NEAREST optimization in this case.
+ */
+ pixman_fixed_t magic_limit = pixman_int_to_fixed (30000);
+ if (image->common.transform->matrix[0][2] <= magic_limit &&
+ image->common.transform->matrix[1][2] <= magic_limit &&
+ image->common.transform->matrix[0][2] >= -magic_limit &&
+ image->common.transform->matrix[1][2] >= -magic_limit)
+ {
+ flags |= FAST_PATH_NEAREST_FILTER;
+ }
+ }
+ break;
- image->type = RADIAL;
-
- radial->c1.x = inner->x;
- radial->c1.y = inner->y;
- radial->c1.radius = inner_radius;
- radial->c2.x = outer->x;
- radial->c2.y = outer->y;
- radial->c2.radius = outer_radius;
- radial->cdx = pixman_fixed_to_double (radial->c2.x - radial->c1.x);
- radial->cdy = pixman_fixed_to_double (radial->c2.y - radial->c1.y);
- radial->dr = pixman_fixed_to_double (radial->c2.radius - radial->c1.radius);
- radial->A = (radial->cdx * radial->cdx
- + radial->cdy * radial->cdy
- - radial->dr * radial->dr);
+ case PIXMAN_FILTER_CONVOLUTION:
+ break;
- return image;
-}
+ default:
+ flags |= FAST_PATH_NO_CONVOLUTION_FILTER;
+ break;
+ }
+
+ /* Repeat mode */
+ switch (image->common.repeat)
+ {
+ case PIXMAN_REPEAT_NONE:
+ flags |=
+ FAST_PATH_NO_REFLECT_REPEAT |
+ FAST_PATH_NO_PAD_REPEAT |
+ FAST_PATH_NO_NORMAL_REPEAT;
+ break;
+
+ case PIXMAN_REPEAT_REFLECT:
+ flags |=
+ FAST_PATH_NO_PAD_REPEAT |
+ FAST_PATH_NO_NONE_REPEAT |
+ FAST_PATH_NO_NORMAL_REPEAT;
+ break;
+
+ case PIXMAN_REPEAT_PAD:
+ flags |=
+ FAST_PATH_NO_REFLECT_REPEAT |
+ FAST_PATH_NO_NONE_REPEAT |
+ FAST_PATH_NO_NORMAL_REPEAT;
+ break;
-PIXMAN_EXPORT pixman_image_t *
-pixman_image_create_conical_gradient (pixman_point_fixed_t *center,
- pixman_fixed_t angle,
- const pixman_gradient_stop_t *stops,
- int n_stops)
-{
- pixman_image_t *image = allocate_image();
- conical_gradient_t *conical;
+ default:
+ flags |=
+ FAST_PATH_NO_REFLECT_REPEAT |
+ FAST_PATH_NO_PAD_REPEAT |
+ FAST_PATH_NO_NONE_REPEAT;
+ break;
+ }
- if (!image)
- return NULL;
+ /* Component alpha */
+ if (image->common.component_alpha)
+ flags |= FAST_PATH_COMPONENT_ALPHA;
+ else
+ flags |= FAST_PATH_UNIFIED_ALPHA;
- conical = &image->conical;
+ flags |= (FAST_PATH_NO_ACCESSORS | FAST_PATH_NARROW_FORMAT);
- if (!init_gradient (&conical->common, stops, n_stops))
+ /* Type specific checks */
+ switch (image->type)
{
- free (image);
- return NULL;
- }
+ case SOLID:
+ code = PIXMAN_solid;
- image->type = CONICAL;
- conical->center = *center;
- conical->angle = angle;
+ if (image->solid.color.alpha == 0xffff)
+ flags |= FAST_PATH_IS_OPAQUE;
+ break;
- return image;
-}
+ case BITS:
+ if (image->bits.width == 1 &&
+ image->bits.height == 1 &&
+ image->common.repeat != PIXMAN_REPEAT_NONE)
+ {
+ code = PIXMAN_solid;
+ }
+ else
+ {
+ code = image->bits.format;
+ flags |= FAST_PATH_BITS_IMAGE;
+ }
-static uint32_t *
-create_bits (pixman_format_code_t format,
- int width,
- int height,
- int *rowstride_bytes)
-{
- int stride;
- int buf_size;
- int bpp;
+ if (!PIXMAN_FORMAT_A (image->bits.format) &&
+ PIXMAN_FORMAT_TYPE (image->bits.format) != PIXMAN_TYPE_GRAY &&
+ PIXMAN_FORMAT_TYPE (image->bits.format) != PIXMAN_TYPE_COLOR)
+ {
+ flags |= FAST_PATH_SAMPLES_OPAQUE;
- /* what follows is a long-winded way, avoiding any possibility of integer
- * overflows, of saying:
- * stride = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof (uint32_t);
- */
+ if (image->common.repeat != PIXMAN_REPEAT_NONE)
+ flags |= FAST_PATH_IS_OPAQUE;
+ }
- bpp = PIXMAN_FORMAT_BPP (format);
- if (pixman_multiply_overflows_int (width, bpp))
- return NULL;
+ if (image->bits.read_func || image->bits.write_func)
+ flags &= ~FAST_PATH_NO_ACCESSORS;
- stride = width * bpp;
- if (pixman_addition_overflows_int (stride, FB_MASK))
- return NULL;
+ if (PIXMAN_FORMAT_IS_WIDE (image->bits.format))
+ flags &= ~FAST_PATH_NARROW_FORMAT;
+ break;
- stride += FB_MASK;
- stride >>= FB_SHIFT;
+ case RADIAL:
+ code = PIXMAN_unknown;
-#if FB_SHIFT < 2
- if (pixman_multiply_overflows_int (stride, sizeof (uint32_t)))
- return NULL;
-#endif
- stride *= sizeof (uint32_t);
+ /*
+ * As explained in pixman-radial-gradient.c, every point of
+ * the plane has a valid associated radius (and thus will be
+ * colored) if and only if a is negative (i.e. one of the two
+ * circles contains the other one).
+ */
- if (pixman_multiply_overflows_int (height, stride))
- return NULL;
+ if (image->radial.a >= 0)
+ break;
- buf_size = height * stride;
+ /* Fall through */
- if (rowstride_bytes)
- *rowstride_bytes = stride;
+ case CONICAL:
+ case LINEAR:
+ code = PIXMAN_unknown;
- return calloc (buf_size, 1);
-}
+ if (image->common.repeat != PIXMAN_REPEAT_NONE)
+ {
+ int i;
-static void
-reset_clip_region (pixman_image_t *image)
-{
- pixman_region32_fini (&image->common.clip_region);
+ flags |= FAST_PATH_IS_OPAQUE;
+ for (i = 0; i < image->gradient.n_stops; ++i)
+ {
+ if (image->gradient.stops[i].color.alpha != 0xffff)
+ {
+ flags &= ~FAST_PATH_IS_OPAQUE;
+ break;
+ }
+ }
+ }
+ break;
- if (image->type == BITS)
+ default:
+ code = PIXMAN_unknown;
+ break;
+ }
+
+ /* Alpha map */
+ if (!image->common.alpha_map)
{
- pixman_region32_init_rect (&image->common.clip_region, 0, 0,
- image->bits.width, image->bits.height);
+ flags |= FAST_PATH_NO_ALPHA_MAP;
}
else
{
- pixman_region32_init (&image->common.clip_region);
+ if (PIXMAN_FORMAT_IS_WIDE (image->common.alpha_map->format))
+ flags &= ~FAST_PATH_NARROW_FORMAT;
}
-}
-PIXMAN_EXPORT pixman_image_t *
-pixman_image_create_bits (pixman_format_code_t format,
- int width,
- int height,
- uint32_t *bits,
- int rowstride_bytes)
-{
- pixman_image_t *image;
- uint32_t *free_me = NULL;
-
- /* must be a whole number of uint32_t's
+ /* Both alpha maps and convolution filters can introduce
+ * non-opaqueness in otherwise opaque images. Also
+ * an image with component alpha turned on is only opaque
+ * if all channels are opaque, so we simply turn it off
+ * unconditionally for those images.
*/
- return_val_if_fail (bits == NULL ||
- (rowstride_bytes % sizeof (uint32_t)) == 0, NULL);
-
- if (!bits && width && height)
+ if (image->common.alpha_map ||
+ image->common.filter == PIXMAN_FILTER_CONVOLUTION ||
+ image->common.component_alpha)
{
- free_me = bits = create_bits (format, width, height, &rowstride_bytes);
- if (!bits)
- return NULL;
+ flags &= ~(FAST_PATH_IS_OPAQUE | FAST_PATH_SAMPLES_OPAQUE);
}
- image = allocate_image();
+ image->common.flags = flags;
+ image->common.extended_format_code = code;
+}
- if (!image) {
- if (free_me)
- free (free_me);
- return NULL;
+void
+_pixman_image_validate (pixman_image_t *image)
+{
+ if (image->common.dirty)
+ {
+ compute_image_info (image);
+
+ /* It is important that property_changed is
+ * called *after* compute_image_info() because
+ * property_changed() can make use of the flags
+ * to set up accessors etc.
+ */
+ if (image->common.property_changed)
+ image->common.property_changed (image);
+
+ image->common.dirty = FALSE;
}
-
- image->type = BITS;
- image->bits.format = format;
- image->bits.width = width;
- image->bits.height = height;
- image->bits.bits = bits;
- image->bits.free_me = free_me;
-
- image->bits.rowstride = rowstride_bytes / (int) sizeof (uint32_t); /* we store it in number
- * of uint32_t's
- */
- image->bits.indexed = NULL;
-
- pixman_region32_fini (&image->common.full_region);
- pixman_region32_init_rect (&image->common.full_region, 0, 0,
- image->bits.width, image->bits.height);
-
- reset_clip_region (image);
- return image;
+
+ if (image->common.alpha_map)
+ _pixman_image_validate ((pixman_image_t *)image->common.alpha_map);
}
PIXMAN_EXPORT pixman_bool_t
-pixman_image_set_clip_region32 (pixman_image_t *image,
- pixman_region32_t *region)
+pixman_image_set_clip_region32 (pixman_image_t * image,
+ pixman_region32_t *region)
{
image_common_t *common = (image_common_t *)image;
+ pixman_bool_t result;
if (region)
{
- return pixman_region32_copy (&common->clip_region, region);
+ if ((result = pixman_region32_copy (&common->clip_region, region)))
+ image->common.have_clip_region = TRUE;
}
else
{
- reset_clip_region (image);
+ _pixman_image_reset_clip_region (image);
- return TRUE;
+ result = TRUE;
}
-}
+ image_property_changed (image);
+
+ return result;
+}
PIXMAN_EXPORT pixman_bool_t
-pixman_image_set_clip_region (pixman_image_t *image,
- pixman_region16_t *region)
+pixman_image_set_clip_region (pixman_image_t * image,
+ pixman_region16_t *region)
{
image_common_t *common = (image_common_t *)image;
+ pixman_bool_t result;
if (region)
{
- return pixman_region32_copy_from_region16 (&common->clip_region, region);
+ if ((result = pixman_region32_copy_from_region16 (&common->clip_region, region)))
+ image->common.have_clip_region = TRUE;
}
else
{
- reset_clip_region (image);
+ _pixman_image_reset_clip_region (image);
- return TRUE;
+ result = TRUE;
}
+
+ image_property_changed (image);
+
+ return result;
}
-/* Sets whether the clip region includes a clip region set by the client
- */
PIXMAN_EXPORT void
pixman_image_set_has_client_clip (pixman_image_t *image,
- pixman_bool_t client_clip)
+ pixman_bool_t client_clip)
{
- image->common.has_client_clip = client_clip;
+ image->common.client_clip = client_clip;
}
PIXMAN_EXPORT pixman_bool_t
-pixman_image_set_transform (pixman_image_t *image,
- const pixman_transform_t *transform)
+pixman_image_set_transform (pixman_image_t * image,
+ const pixman_transform_t *transform)
{
static const pixman_transform_t id =
{
{ { pixman_fixed_1, 0, 0 },
{ 0, pixman_fixed_1, 0 },
- { 0, 0, pixman_fixed_1 }
- }
+ { 0, 0, pixman_fixed_1 } }
};
image_common_t *common = (image_common_t *)image;
+ pixman_bool_t result;
if (common->transform == transform)
return TRUE;
- if (memcmp (&id, transform, sizeof (pixman_transform_t)) == 0)
+ if (!transform || memcmp (&id, transform, sizeof (pixman_transform_t)) == 0)
{
- free(common->transform);
+ free (common->transform);
common->transform = NULL;
+ result = TRUE;
+
+ goto out;
+ }
+
+ if (common->transform &&
+ memcmp (common->transform, transform, sizeof (pixman_transform_t)) == 0)
+ {
return TRUE;
}
if (common->transform == NULL)
common->transform = malloc (sizeof (pixman_transform_t));
+
if (common->transform == NULL)
- return FALSE;
+ {
+ result = FALSE;
- memcpy(common->transform, transform, sizeof(pixman_transform_t));
+ goto out;
+ }
- return TRUE;
+ memcpy (common->transform, transform, sizeof(pixman_transform_t));
+
+ result = TRUE;
+
+out:
+ image_property_changed (image);
+
+ return result;
}
PIXMAN_EXPORT void
-pixman_image_set_repeat (pixman_image_t *image,
- pixman_repeat_t repeat)
+pixman_image_set_repeat (pixman_image_t *image,
+ pixman_repeat_t repeat)
{
+ if (image->common.repeat == repeat)
+ return;
+
image->common.repeat = repeat;
+
+ image_property_changed (image);
}
PIXMAN_EXPORT pixman_bool_t
-pixman_image_set_filter (pixman_image_t *image,
- pixman_filter_t filter,
- const pixman_fixed_t *params,
- int n_params)
+pixman_image_set_filter (pixman_image_t * image,
+ pixman_filter_t filter,
+ const pixman_fixed_t *params,
+ int n_params)
{
image_common_t *common = (image_common_t *)image;
pixman_fixed_t *new_params;
return FALSE;
memcpy (new_params,
- params, n_params * sizeof (pixman_fixed_t));
+ params, n_params * sizeof (pixman_fixed_t));
}
common->filter = filter;
common->filter_params = new_params;
common->n_filter_params = n_params;
+
+ image_property_changed (image);
return TRUE;
}
PIXMAN_EXPORT void
-pixman_image_set_source_clipping (pixman_image_t *image,
- pixman_bool_t source_clipping)
+pixman_image_set_source_clipping (pixman_image_t *image,
+ pixman_bool_t clip_sources)
{
- image_common_t *common = &image->common;
+ if (image->common.clip_sources == clip_sources)
+ return;
- if (source_clipping)
- common->src_clip = &common->clip_region;
- else
- common->src_clip = &common->full_region;
+ image->common.clip_sources = clip_sources;
+
+ image_property_changed (image);
}
/* Unlike all the other property setters, this function does not
* way, way too expensive.
*/
PIXMAN_EXPORT void
-pixman_image_set_indexed (pixman_image_t *image,
- const pixman_indexed_t *indexed)
+pixman_image_set_indexed (pixman_image_t * image,
+ const pixman_indexed_t *indexed)
{
bits_image_t *bits = (bits_image_t *)image;
+ if (bits->indexed == indexed)
+ return;
+
bits->indexed = indexed;
+
+ image_property_changed (image);
}
PIXMAN_EXPORT void
pixman_image_set_alpha_map (pixman_image_t *image,
- pixman_image_t *alpha_map,
- int16_t x,
- int16_t y)
+ pixman_image_t *alpha_map,
+ int16_t x,
+ int16_t y)
{
image_common_t *common = (image_common_t *)image;
return_if_fail (!alpha_map || alpha_map->type == BITS);
+ if (alpha_map && common->alpha_count > 0)
+ {
+ /* If this image is being used as an alpha map itself,
+ * then you can't give it an alpha map of its own.
+ */
+ return;
+ }
+
+ if (alpha_map && alpha_map->common.alpha_map)
+ {
+ /* If the image has an alpha map of its own,
+ * then it can't be used as an alpha map itself
+ */
+ return;
+ }
+
if (common->alpha_map != (bits_image_t *)alpha_map)
{
if (common->alpha_map)
+ {
+ common->alpha_map->common.alpha_count--;
+
pixman_image_unref ((pixman_image_t *)common->alpha_map);
+ }
if (alpha_map)
+ {
common->alpha_map = (bits_image_t *)pixman_image_ref (alpha_map);
+
+ common->alpha_map->common.alpha_count++;
+ }
else
+ {
common->alpha_map = NULL;
+ }
}
- common->alpha_origin.x = x;
- common->alpha_origin.y = y;
+ common->alpha_origin_x = x;
+ common->alpha_origin_y = y;
+
+ image_property_changed (image);
}
PIXMAN_EXPORT void
-pixman_image_set_component_alpha (pixman_image_t *image,
- pixman_bool_t component_alpha)
+pixman_image_set_component_alpha (pixman_image_t *image,
+ pixman_bool_t component_alpha)
{
+ if (image->common.component_alpha == component_alpha)
+ return;
+
image->common.component_alpha = component_alpha;
+
+ image_property_changed (image);
}
+PIXMAN_EXPORT pixman_bool_t
+pixman_image_get_component_alpha (pixman_image_t *image)
+{
+ return image->common.component_alpha;
+}
PIXMAN_EXPORT void
-pixman_image_set_accessors (pixman_image_t *image,
- pixman_read_memory_func_t read_func,
- pixman_write_memory_func_t write_func)
+pixman_image_set_accessors (pixman_image_t * image,
+ pixman_read_memory_func_t read_func,
+ pixman_write_memory_func_t write_func)
{
return_if_fail (image != NULL);
- image->common.read_func = read_func;
- image->common.write_func = write_func;
+ if (image->type == BITS)
+ {
+ image->bits.read_func = read_func;
+ image->bits.write_func = write_func;
+
+ image_property_changed (image);
+ }
}
PIXMAN_EXPORT uint32_t *
return 0;
}
-static pixman_bool_t
-color_to_pixel (pixman_color_t *color,
- uint32_t *pixel,
- pixman_format_code_t format)
-{
- uint32_t c = color_to_uint32 (color);
-
- if (!(format == PIXMAN_a8r8g8b8 ||
- format == PIXMAN_x8r8g8b8 ||
- format == PIXMAN_a8b8g8r8 ||
- format == PIXMAN_x8b8g8r8 ||
- format == PIXMAN_b8g8r8a8 ||
- format == PIXMAN_b8g8r8x8 ||
- format == PIXMAN_r5g6b5 ||
- format == PIXMAN_b5g6r5 ||
- format == PIXMAN_a8))
- {
- return FALSE;
- }
-
- if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_ABGR)
- {
- c = ((c & 0xff000000) >> 0) |
- ((c & 0x00ff0000) >> 16) |
- ((c & 0x0000ff00) >> 0) |
- ((c & 0x000000ff) << 16);
- }
- if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_BGRA)
- {
- c = ((c & 0xff000000) >> 24) |
- ((c & 0x00ff0000) >> 8) |
- ((c & 0x0000ff00) << 8) |
- ((c & 0x000000ff) << 24);
- }
-
- if (format == PIXMAN_a8)
- c = c >> 24;
- else if (format == PIXMAN_r5g6b5 ||
- format == PIXMAN_b5g6r5)
- c = cvt8888to0565 (c);
-
-#if 0
- printf ("color: %x %x %x %x\n", color->alpha, color->red, color->green, color->blue);
- printf ("pixel: %x\n", c);
-#endif
-
- *pixel = c;
- return TRUE;
-}
-
-PIXMAN_EXPORT pixman_bool_t
-pixman_image_fill_rectangles (pixman_op_t op,
- pixman_image_t *dest,
- pixman_color_t *color,
- int n_rects,
- const pixman_rectangle16_t *rects)
-{
- pixman_image_t *solid;
- pixman_color_t c;
- int i;
-
- if (color->alpha == 0xffff)
- {
- if (op == PIXMAN_OP_OVER)
- op = PIXMAN_OP_SRC;
- }
-
- if (op == PIXMAN_OP_CLEAR)
- {
- c.red = 0;
- c.green = 0;
- c.blue = 0;
- c.alpha = 0;
-
- color = &c;
-
- op = PIXMAN_OP_SRC;
- }
-
- if (op == PIXMAN_OP_SRC)
- {
- uint32_t pixel;
-
- if (color_to_pixel (color, &pixel, dest->bits.format))
- {
- for (i = 0; i < n_rects; ++i)
- {
- pixman_region32_t fill_region;
- int n_boxes, j;
- pixman_box32_t *boxes;
-
- pixman_region32_init_rect (&fill_region, rects[i].x, rects[i].y, rects[i].width, rects[i].height);
- if (!pixman_region32_intersect (&fill_region,
- &fill_region,
- &dest->common.clip_region))
- return FALSE;
-
-
- boxes = pixman_region32_rectangles (&fill_region, &n_boxes);
- for (j = 0; j < n_boxes; ++j)
- {
- const pixman_box32_t *box = &(boxes[j]);
- pixman_fill (dest->bits.bits, dest->bits.rowstride, PIXMAN_FORMAT_BPP (dest->bits.format),
- box->x1, box->y1, box->x2 - box->x1, box->y2 - box->y1,
- pixel);
- }
-
- pixman_region32_fini (&fill_region);
- }
- return TRUE;
- }
- }
-
- solid = pixman_image_create_solid_fill (color);
- if (!solid)
- return FALSE;
-
- for (i = 0; i < n_rects; ++i)
- {
- const pixman_rectangle16_t *rect = &(rects[i]);
-
- pixman_image_composite (op, solid, NULL, dest,
- 0, 0, 0, 0,
- rect->x, rect->y,
- rect->width, rect->height);
- }
-
- pixman_image_unref (solid);
-
- return TRUE;
-}
-
-pixman_bool_t
-pixman_image_can_get_solid (pixman_image_t *image)
+PIXMAN_EXPORT pixman_format_code_t
+pixman_image_get_format (pixman_image_t *image)
{
- if (image->type == SOLID)
- return TRUE;
-
- if (image->type != BITS ||
- image->bits.width != 1 ||
- image->bits.height != 1)
- {
- return FALSE;
- }
-
- if (image->common.repeat != PIXMAN_REPEAT_NORMAL)
- return FALSE;
+ if (image->type == BITS)
+ return image->bits.format;
- switch (image->bits.format)
- {
- case PIXMAN_a8r8g8b8:
- case PIXMAN_x8r8g8b8:
- case PIXMAN_a8b8g8r8:
- case PIXMAN_x8b8g8r8:
- case PIXMAN_b8g8r8a8:
- case PIXMAN_b8g8r8x8:
- case PIXMAN_r8g8b8:
- case PIXMAN_b8g8r8:
- case PIXMAN_r5g6b5:
- case PIXMAN_b5g6r5:
- return TRUE;
- default:
- return FALSE;
- }
+ return 0;
}
-pixman_bool_t
-pixman_image_is_opaque(pixman_image_t *image)
+uint32_t
+_pixman_image_get_solid (pixman_implementation_t *imp,
+ pixman_image_t * image,
+ pixman_format_code_t format)
{
- int i = 0;
- int gradientNumberOfColors = 0;
-
- if(image->common.alpha_map)
- return FALSE;
-
- switch(image->type)
- {
- case BITS:
- if(PIXMAN_FORMAT_A(image->bits.format))
- return FALSE;
- break;
+ uint32_t result;
+ pixman_iter_t iter;
- case LINEAR:
- case CONICAL:
- case RADIAL:
- gradientNumberOfColors = image->gradient.n_stops;
- i=0;
- while(i<gradientNumberOfColors)
- {
- if(image->gradient.stops[i].color.alpha != 0xffff)
- return FALSE;
- i++;
- }
- break;
+ _pixman_implementation_src_iter_init (
+ imp, &iter, image, 0, 0, 1, 1,
+ (uint8_t *)&result, ITER_NARROW);
- case SOLID:
- if(Alpha(image->solid.color) != 0xff)
- return FALSE;
- break;
- }
-
- /* Convolution filters can introduce translucency if the sum of the weights
- is lower than 1. */
- if (image->common.filter == PIXMAN_FILTER_CONVOLUTION)
- return FALSE;
+ result = *iter.get_scanline (&iter, NULL);
- if (image->common.repeat == PIXMAN_REPEAT_NONE)
+ /* If necessary, convert RGB <--> BGR. */
+ if (PIXMAN_FORMAT_TYPE (format) != PIXMAN_TYPE_ARGB)
{
- if (image->common.filter != PIXMAN_FILTER_NEAREST)
- return FALSE;
-
- if (image->common.transform)
- return FALSE;
-
- /* Gradients do not necessarily cover the entire compositing area */
- if (image->type == LINEAR || image->type == CONICAL || image->type == RADIAL)
- return FALSE;
+ result = (((result & 0xff000000) >> 0) |
+ ((result & 0x00ff0000) >> 16) |
+ ((result & 0x0000ff00) >> 0) |
+ ((result & 0x000000ff) << 16));
}
- return TRUE;
+ return result;
}