#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 void
+gradient_property_changed (pixman_image_t *image)
+{
+ 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]);
+
+ 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;
+ }
+}
pixman_bool_t
-_pixman_init_gradient (gradient_t *gradient,
- const pixman_gradient_stop_t *stops,
- int n_stops)
+_pixman_init_gradient (gradient_t * gradient,
+ const pixman_gradient_stop_t *stops,
+ int n_stops)
{
return_val_if_fail (n_stops > 0, FALSE);
- 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.class = SOURCE_IMAGE_CLASS_UNKNOWN;
+ gradient->common.property_changed = gradient_property_changed;
return TRUE;
}
+void
+_pixman_image_init (pixman_image_t *image)
+{
+ image_common_t *common = &image->common;
+
+ 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;
+}
+
+pixman_bool_t
+_pixman_image_fini (pixman_image_t *image)
+{
+ image_common_t *common = (image_common_t *)image;
+
+ common->ref_count--;
+
+ if (common->ref_count == 0)
+ {
+ if (image->common.destroy_func)
+ image->common.destroy_func (image, image->common.destroy_data);
+
+ pixman_region32_fini (&common->clip_region);
+
+ free (common->transform);
+ free (common->filter_params);
+
+ if (common->alpha_map)
+ pixman_image_unref ((pixman_image_t *)common->alpha_map);
+
+ 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);
+ }
+
+ /* 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);
+ }
+
+ if (image->type == BITS && image->bits.free_me)
+ free (image->bits.free_me);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
pixman_image_t *
_pixman_image_allocate (void)
{
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;
- }
+ _pixman_image_init (image);
return image;
}
-source_pict_class_t
-_pixman_image_classify (pixman_image_t *image,
- int x,
- int y,
- int width,
- int height)
+static void
+image_property_changed (pixman_image_t *image)
{
- if (image->common.classify)
- return image->common.classify (image, x, y, width, height);
- else
- return SOURCE_IMAGE_CLASS_UNKNOWN;
+ image->common.dirty = TRUE;
}
-#define READ_ACCESS(f) ((image->common.read_func)? f##_accessors : f)
-
-static void fbFetchSolid(bits_image_t * image, int x, int y, int width, uint32_t *buffer, uint32_t *mask, uint32_t maskBits)
+/* Ref Counting */
+PIXMAN_EXPORT pixman_image_t *
+pixman_image_ref (pixman_image_t *image)
{
- uint32_t color;
- uint32_t *end;
- fetchPixelProc32 fetch = READ_ACCESS(pixman_fetchPixelProcForPicture32)(image);
-
- color = fetch(image, 0, 0);
+ image->common.ref_count++;
- end = buffer + width;
- while (buffer < end)
- *(buffer++) = color;
+ return image;
}
-static void fbFetchSolid64(bits_image_t * image, int x, int y, int width, uint64_t *buffer, void *unused, uint32_t unused2)
+/* returns TRUE when the image is freed */
+PIXMAN_EXPORT pixman_bool_t
+pixman_image_unref (pixman_image_t *image)
{
- uint64_t color;
- uint64_t *end;
- fetchPixelProc64 fetch = READ_ACCESS(pixman_fetchPixelProcForPicture64)(image);
-
- color = fetch(image, 0, 0);
+ if (_pixman_image_fini (image))
+ {
+ free (image);
+ return TRUE;
+ }
- end = buffer + width;
- while (buffer < end)
- *(buffer++) = color;
+ return FALSE;
}
-static void fbFetch(bits_image_t * image, int x, int y, int width, uint32_t *buffer, uint32_t *mask, uint32_t maskBits)
+PIXMAN_EXPORT void
+pixman_image_set_destroy_function (pixman_image_t * image,
+ pixman_image_destroy_func_t func,
+ void * data)
{
- fetchProc32 fetch = READ_ACCESS(pixman_fetchProcForPicture32)(image);
+ image->common.destroy_func = func;
+ image->common.destroy_data = data;
+}
- fetch(image, x, y, width, buffer);
+PIXMAN_EXPORT void *
+pixman_image_get_destroy_data (pixman_image_t *image)
+{
+ return image->common.destroy_data;
}
-static void fbFetch64(bits_image_t * image, int x, int y, int width, uint64_t *buffer, void *unused, uint32_t unused2)
+void
+_pixman_image_reset_clip_region (pixman_image_t *image)
{
- fetchProc64 fetch = READ_ACCESS(pixman_fetchProcForPicture64)(image);
+ image->common.have_clip_region = FALSE;
+}
- fetch(image, x, y, width, buffer);
+/* 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)
+{
}
static void
-set_fetchers (pixman_image_t *image)
+compute_image_info (pixman_image_t *image)
{
- if (IS_SOURCE_IMAGE (image))
+ pixman_format_code_t code;
+ uint32_t flags = 0;
+
+ /* Transform */
+ if (!image->common.transform)
{
- image->common.get_scanline_64 = (scanFetchProc)pixmanFetchSourcePict64;
- image->common.get_scanline_32 = (scanFetchProc)pixmanFetchSourcePict;
+ flags |= (FAST_PATH_ID_TRANSFORM |
+ FAST_PATH_X_UNIT_POSITIVE |
+ FAST_PATH_Y_UNIT_ZERO |
+ FAST_PATH_AFFINE_TRANSFORM);
}
else
{
- bits_image_t *bits = (bits_image_t *)image;
+ flags |= FAST_PATH_HAS_TRANSFORM;
- if (bits->common.alpha_map)
+ if (image->common.transform->matrix[2][0] == 0 &&
+ image->common.transform->matrix[2][1] == 0 &&
+ image->common.transform->matrix[2][2] == pixman_fixed_1)
{
- image->common.get_scanline_64 =
- (scanFetchProc)READ_ACCESS(fbFetchExternalAlpha64);
- image->common.get_scanline_32 =
- (scanFetchProc)READ_ACCESS(fbFetchExternalAlpha);
- }
- else if ((bits->common.repeat != PIXMAN_REPEAT_NONE) &&
- bits->width == 1 &&
- bits->height == 1)
- {
- image->common.get_scanline_64 = (scanFetchProc)fbFetchSolid64;
- image->common.get_scanline_32 = (scanFetchProc)fbFetchSolid;
+ 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];
+
+ if (m01 == -1 && m10 == 1)
+ flags |= FAST_PATH_ROTATE_90_TRANSFORM;
+ else if (m01 == 1 && m10 == -1)
+ flags |= FAST_PATH_ROTATE_270_TRANSFORM;
+ }
}
- else if (!bits->common.transform &&
- bits->common.filter != PIXMAN_FILTER_CONVOLUTION &&
- bits->common.repeat != PIXMAN_REPEAT_PAD &&
- bits->common.repeat != PIXMAN_REPEAT_REFLECT)
+
+ if (image->common.transform->matrix[0][0] > 0)
+ flags |= FAST_PATH_X_UNIT_POSITIVE;
+
+ if (image->common.transform->matrix[1][0] == 0)
+ flags |= FAST_PATH_Y_UNIT_ZERO;
+ }
+
+ /* Filter */
+ switch (image->common.filter)
+ {
+ case PIXMAN_FILTER_NEAREST:
+ case PIXMAN_FILTER_FAST:
+ flags |= (FAST_PATH_NEAREST_FILTER | FAST_PATH_NO_CONVOLUTION_FILTER);
+ break;
+
+ case PIXMAN_FILTER_BILINEAR:
+ case PIXMAN_FILTER_GOOD:
+ case PIXMAN_FILTER_BEST:
+ flags |= (FAST_PATH_BILINEAR_FILTER | FAST_PATH_NO_CONVOLUTION_FILTER);
+
+ /* 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)
{
- image->common.get_scanline_64 = (scanFetchProc)fbFetch64;
- image->common.get_scanline_32 = (scanFetchProc)fbFetch;
+ flags |= FAST_PATH_NEAREST_FILTER;
}
- else
+ 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)
+ )
+ )
{
- image->common.get_scanline_64 = (scanFetchProc)READ_ACCESS(fbFetchTransformed64);
- image->common.get_scanline_32 = (scanFetchProc)READ_ACCESS(fbFetchTransformed);
+ /* 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;
-scanFetchProc
-_pixman_image_get_fetcher (pixman_image_t *image,
- int wide)
-{
- set_fetchers (image);
- if (wide)
- return image->common.get_scanline_64;
- else
- return image->common.get_scanline_32;
-}
+ case PIXMAN_FILTER_CONVOLUTION:
+ break;
+ 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;
-#define WRITE_ACCESS(f) ((image->common.write_func)? f##_accessors : f)
+ default:
+ flags |=
+ FAST_PATH_NO_REFLECT_REPEAT |
+ FAST_PATH_NO_PAD_REPEAT |
+ FAST_PATH_NO_NONE_REPEAT;
+ break;
+ }
-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;
+ /* Component alpha */
+ if (image->common.component_alpha)
+ flags |= FAST_PATH_COMPONENT_ALPHA;
+ else
+ flags |= FAST_PATH_UNIFIED_ALPHA;
- bits = image->bits;
- stride = image->rowstride;
- bits += y*stride;
- store((pixman_image_t *)image, bits, buffer, x, width, indexed);
-}
+ flags |= (FAST_PATH_NO_ACCESSORS | FAST_PATH_NARROW_FORMAT);
-static void
-fbStore64(bits_image_t * image, int x, int y, int width, uint64_t *buffer)
-{
- uint32_t *bits;
- int32_t stride;
- storeProc64 store = WRITE_ACCESS(pixman_storeProcForPicture64)(image);
- const pixman_indexed_t * indexed = image->indexed;
+ /* Type specific checks */
+ switch (image->type)
+ {
+ case SOLID:
+ code = PIXMAN_solid;
- bits = image->bits;
- stride = image->rowstride;
- bits += y*stride;
- store((pixman_image_t *)image, bits, buffer, x, width, indexed);
-}
+ if (image->solid.color.alpha == 0xffff)
+ flags |= FAST_PATH_IS_OPAQUE;
+ break;
-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;
+ case BITS:
+ if (image->bits.width == 1 &&
+ image->bits.height == 1 &&
+ image->common.repeat != PIXMAN_REPEAT_NONE)
+ {
+ code = PIXMAN_solid;
+ }
else
- return (scanStoreProc)fbStore;
- }
-}
-
-static void
-image_property_changed (pixman_image_t *image)
-{
-
-
- image->common.property_changed (image);
-}
+ {
+ code = image->bits.format;
+ flags |= FAST_PATH_BITS_IMAGE;
+ }
-/* Ref Counting */
-PIXMAN_EXPORT pixman_image_t *
-pixman_image_ref (pixman_image_t *image)
-{
- image->common.ref_count++;
+ 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;
- return image;
-}
+ if (image->common.repeat != PIXMAN_REPEAT_NONE)
+ flags |= FAST_PATH_IS_OPAQUE;
+ }
-/* returns TRUE when the image is freed */
-PIXMAN_EXPORT pixman_bool_t
-pixman_image_unref (pixman_image_t *image)
-{
- image_common_t *common = (image_common_t *)image;
+ if (image->bits.read_func || image->bits.write_func)
+ flags &= ~FAST_PATH_NO_ACCESSORS;
- common->ref_count--;
+ if (PIXMAN_FORMAT_IS_WIDE (image->bits.format))
+ flags &= ~FAST_PATH_NARROW_FORMAT;
+ break;
- if (common->ref_count == 0)
- {
- pixman_region32_fini (&common->clip_region);
- pixman_region32_fini (&common->full_region);
+ case RADIAL:
+ code = PIXMAN_unknown;
- if (common->transform)
- free (common->transform);
+ /*
+ * 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 (common->filter_params)
- free (common->filter_params);
+ if (image->radial.a >= 0)
+ break;
- if (common->alpha_map)
- pixman_image_unref ((pixman_image_t *)common->alpha_map);
+ /* Fall through */
-#if 0
- if (image->type == BITS && image->bits.indexed)
- free (image->bits.indexed);
-#endif
+ case CONICAL:
+ case LINEAR:
+ code = PIXMAN_unknown;
-#if 0
- memset (image, 0xaa, sizeof (pixman_image_t));
-#endif
- if (image->type == LINEAR || image->type == RADIAL || image->type == CONICAL)
+ if (image->common.repeat != PIXMAN_REPEAT_NONE)
{
- if (image->gradient.stops)
- free (image->gradient.stops);
- }
+ int i;
+ 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 && image->bits.free_me)
- free (image->bits.free_me);
+ default:
+ code = PIXMAN_unknown;
+ break;
+ }
- free (image);
+ /* Alpha map */
+ if (!image->common.alpha_map)
+ {
+ flags |= FAST_PATH_NO_ALPHA_MAP;
+ }
+ else
+ {
+ if (PIXMAN_FORMAT_IS_WIDE (image->common.alpha_map->format))
+ flags &= ~FAST_PATH_NARROW_FORMAT;
+ }
- return TRUE;
+ /* 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.
+ */
+ if (image->common.alpha_map ||
+ image->common.filter == PIXMAN_FILTER_CONVOLUTION ||
+ image->common.component_alpha)
+ {
+ flags &= ~(FAST_PATH_IS_OPAQUE | FAST_PATH_SAMPLES_OPAQUE);
}
- return FALSE;
+ image->common.flags = flags;
+ image->common.extended_format_code = code;
}
-/* Constructors */
-
void
-_pixman_image_reset_clip_region (pixman_image_t *image)
+_pixman_image_validate (pixman_image_t *image)
{
- pixman_region32_fini (&image->common.clip_region);
-
- if (image->type == BITS)
- {
- pixman_region32_init_rect (&image->common.clip_region, 0, 0,
- image->bits.width, image->bits.height);
- }
- else
+ if (image->common.dirty)
{
- pixman_region32_init (&image->common.clip_region);
+ 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;
}
+
+ 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)
{
- result = pixman_region32_copy (&common->clip_region, region);
+ if ((result = pixman_region32_copy (&common->clip_region, region)))
+ image->common.have_clip_region = TRUE;
}
else
{
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)
{
- result = 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
{
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_property_changed (image);
+ 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;
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)
{
result = FALSE;
+
goto out;
}
- memcpy(common->transform, transform, sizeof(pixman_transform_t));
+ memcpy (common->transform, transform, sizeof(pixman_transform_t));
+
+ result = TRUE;
out:
image_property_changed (image);
-
- return TRUE;
+
+ 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;
}
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);
}
* 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);
+ image_property_changed (image);
+ }
}
PIXMAN_EXPORT uint32_t *
return 0;
}
-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_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;
-
- case SOLID:
- if(Alpha(image->solid.color) != 0xff)
- return FALSE;
- break;
- }
+ _pixman_implementation_src_iter_init (
+ imp, &iter, image, 0, 0, 1, 1,
+ (uint8_t *)&result, ITER_NARROW);
- /* 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;
}