pixman: Branch 'master' - 6 commits
Taekyun Kim
podain at kemper.freedesktop.org
Sun Oct 9 20:23:50 PDT 2011
pixman/pixman-bits-image.c | 74 +++++++++++-------
pixman/pixman-fast-path.c | 178 +++++++++++++++++++++++++++++++++++++++++++++
pixman/pixman-image.c | 111 +++++++++++++++-------------
pixman/pixman-private.h | 29 +++++++
pixman/pixman-utils.c | 112 ++++++++++++++++++++++++++++
pixman/pixman.c | 123 +------------------------------
6 files changed, 435 insertions(+), 192 deletions(-)
New commits:
commit a43946a51fbbdc76be1af9bc25fe7c5c2a6314bb
Author: Taekyun Kim <tkq.kim at samsung.com>
Date: Thu Sep 22 18:42:38 2011 +0900
Simple repeat: Extend too short source scanlines into temporary buffer
Too short scanlines can cause repeat handling overhead and optimized
pixman composite functions usually process a bunch of pixels in a
single loop iteration it might be beneficial to pre-extend source
scanlines. The temporary buffers will usually reside in cache, so
accessing them should be quite efficient.
diff --git a/pixman/pixman-fast-path.c b/pixman/pixman-fast-path.c
index 89c973a..038dcf7 100644
--- a/pixman/pixman-fast-path.c
+++ b/pixman/pixman-fast-path.c
@@ -1191,6 +1191,8 @@ FAST_NEAREST (8888_565_none, 8888, 0565, uint32_t, uint16_t, OVER, NONE)
FAST_NEAREST (8888_565_pad, 8888, 0565, uint32_t, uint16_t, OVER, PAD)
FAST_NEAREST (8888_565_normal, 8888, 0565, uint32_t, uint16_t, OVER, NORMAL)
+#define REPEAT_MIN_WIDTH 32
+
static void
fast_composite_tiled_repeat (pixman_implementation_t *imp,
pixman_composite_info_t *info)
@@ -1224,27 +1226,111 @@ fast_composite_tiled_repeat (pixman_implementation_t *imp,
int32_t sx, sy;
int32_t width_remain;
int32_t num_pixels;
+ int32_t src_width;
+ int32_t i, j;
+ pixman_image_t extended_src_image;
+ uint32_t extended_src[REPEAT_MIN_WIDTH * 2];
+ pixman_bool_t need_src_extension;
+ uint32_t *src_line;
+ int32_t src_stride;
+ int32_t src_bpp;
pixman_composite_info_t info2 = *info;
+ src_bpp = PIXMAN_FORMAT_BPP (src_image->bits.format);
+
+ if (src_image->bits.width < REPEAT_MIN_WIDTH &&
+ (src_bpp == 32 || src_bpp == 16 || src_bpp == 8))
+ {
+ sx = src_x;
+ sx = MOD (sx, src_image->bits.width);
+ sx += width;
+ src_width = 0;
+
+ while (src_width < REPEAT_MIN_WIDTH && src_width <= sx)
+ src_width += src_image->bits.width;
+
+ src_stride = (src_width * (src_bpp >> 3) + 3) / (int) sizeof (uint32_t);
+
+ /* Initialize/validate stack-allocated temporary image */
+ _pixman_bits_image_init (&extended_src_image, src_image->bits.format,
+ src_width, 1, &extended_src[0], src_stride);
+ _pixman_image_validate (&extended_src_image);
+
+ info2.src_image = &extended_src_image;
+ need_src_extension = TRUE;
+ }
+ else
+ {
+ src_width = src_image->bits.width;
+ need_src_extension = FALSE;
+ }
+
sx = src_x;
sy = src_y;
while (--height >= 0)
{
- sx = MOD (sx, src_image->bits.width);
+ sx = MOD (sx, src_width);
sy = MOD (sy, src_image->bits.height);
+ if (need_src_extension)
+ {
+ if (src_bpp == 32)
+ {
+ PIXMAN_IMAGE_GET_LINE (src_image, 0, sy, uint32_t, src_stride, src_line, 1);
+
+ for (i = 0; i < src_width; )
+ {
+ for (j = 0; j < src_image->bits.width; j++, i++)
+ extended_src[i] = src_line[j];
+ }
+ }
+ else if (src_bpp == 16)
+ {
+ uint16_t *src_line_16;
+
+ PIXMAN_IMAGE_GET_LINE (src_image, 0, sy, uint16_t, src_stride,
+ src_line_16, 1);
+ src_line = (uint32_t*)src_line_16;
+
+ for (i = 0; i < src_width; )
+ {
+ for (j = 0; j < src_image->bits.width; j++, i++)
+ ((uint16_t*)extended_src)[i] = ((uint16_t*)src_line)[j];
+ }
+ }
+ else if (src_bpp == 8)
+ {
+ uint8_t *src_line_8;
+
+ PIXMAN_IMAGE_GET_LINE (src_image, 0, sy, uint8_t, src_stride,
+ src_line_8, 1);
+ src_line = (uint32_t*)src_line_8;
+
+ for (i = 0; i < src_width; )
+ {
+ for (j = 0; j < src_image->bits.width; j++, i++)
+ ((uint8_t*)extended_src)[i] = ((uint8_t*)src_line)[j];
+ }
+ }
+
+ info2.src_y = 0;
+ }
+ else
+ {
+ info2.src_y = sy;
+ }
+
width_remain = width;
while (width_remain > 0)
{
- num_pixels = src_image->bits.width - sx;
+ num_pixels = src_width - sx;
if (num_pixels > width_remain)
num_pixels = width_remain;
info2.src_x = sx;
- info2.src_y = sy;
info2.width = num_pixels;
info2.height = 1;
@@ -1263,6 +1349,9 @@ fast_composite_tiled_repeat (pixman_implementation_t *imp,
info2.dest_x = info->dest_x;
info2.dest_y++;
}
+
+ if (need_src_extension)
+ _pixman_image_fini (&extended_src_image);
}
else
{
commit eaff774a3f8af6651a245711b9ab8af3211eeb10
Author: Taekyun Kim <tkq.kim at samsung.com>
Date: Mon Aug 29 21:44:36 2011 +0900
Simple repeat fast path
We can implement simple repeat by stitching existing fast path
functions. First lookup COVER_CLIP function for given input and
then stitch horizontally using the function.
diff --git a/pixman/pixman-fast-path.c b/pixman/pixman-fast-path.c
index 033efd7..89c973a 100644
--- a/pixman/pixman-fast-path.c
+++ b/pixman/pixman-fast-path.c
@@ -1191,6 +1191,85 @@ FAST_NEAREST (8888_565_none, 8888, 0565, uint32_t, uint16_t, OVER, NONE)
FAST_NEAREST (8888_565_pad, 8888, 0565, uint32_t, uint16_t, OVER, PAD)
FAST_NEAREST (8888_565_normal, 8888, 0565, uint32_t, uint16_t, OVER, NORMAL)
+static void
+fast_composite_tiled_repeat (pixman_implementation_t *imp,
+ pixman_composite_info_t *info)
+{
+ PIXMAN_COMPOSITE_ARGS (info);
+ pixman_composite_func_t func;
+ pixman_format_code_t mask_format;
+ uint32_t src_flags, mask_flags;
+
+ src_flags = (info->src_flags & ~FAST_PATH_NORMAL_REPEAT) |
+ FAST_PATH_SAMPLES_COVER_CLIP_NEAREST;
+
+ if (mask_image)
+ {
+ mask_format = mask_image->common.extended_format_code;
+ mask_flags = info->mask_flags;
+ }
+ else
+ {
+ mask_format = PIXMAN_null;
+ mask_flags = FAST_PATH_IS_OPAQUE;
+ }
+
+ if (_pixman_lookup_composite_function (
+ imp->toplevel, info->op,
+ src_image->common.extended_format_code, src_flags,
+ mask_format, mask_flags,
+ dest_image->common.extended_format_code, info->dest_flags,
+ &imp, &func))
+ {
+ int32_t sx, sy;
+ int32_t width_remain;
+ int32_t num_pixels;
+ pixman_composite_info_t info2 = *info;
+
+ sx = src_x;
+ sy = src_y;
+
+ while (--height >= 0)
+ {
+ sx = MOD (sx, src_image->bits.width);
+ sy = MOD (sy, src_image->bits.height);
+
+ width_remain = width;
+
+ while (width_remain > 0)
+ {
+ num_pixels = src_image->bits.width - sx;
+
+ if (num_pixels > width_remain)
+ num_pixels = width_remain;
+
+ info2.src_x = sx;
+ info2.src_y = sy;
+ info2.width = num_pixels;
+ info2.height = 1;
+
+ func (imp, &info2);
+
+ width_remain -= num_pixels;
+ info2.mask_x += num_pixels;
+ info2.dest_x += num_pixels;
+ sx = 0;
+ }
+
+ sx = src_x;
+ sy++;
+ info2.mask_x = info->mask_x;
+ info2.mask_y++;
+ info2.dest_x = info->dest_x;
+ info2.dest_y++;
+ }
+ }
+ else
+ {
+ _pixman_log_error (FUNC, "Didn't find a suitable function ");
+ }
+}
+
/* Use more unrolling for src_0565_0565 because it is typically CPU bound */
static force_inline void
scaled_nearest_scanline_565_565_SRC (uint16_t * dst,
@@ -1787,6 +1866,16 @@ static const pixman_fast_path_t c_fast_paths[] =
SIMPLE_ROTATE_FAST_PATH (SRC, r5g6b5, r5g6b5, 565),
SIMPLE_ROTATE_FAST_PATH (SRC, a8, a8, 8),
+ /* Simple repeat fast path entry. */
+ { PIXMAN_OP_any,
+ PIXMAN_any,
+ (FAST_PATH_STANDARD_FLAGS | FAST_PATH_ID_TRANSFORM | FAST_PATH_BITS_IMAGE |
+ FAST_PATH_NORMAL_REPEAT),
+ PIXMAN_any, 0,
+ PIXMAN_any, FAST_PATH_STD_DEST_FLAGS,
+ fast_composite_tiled_repeat
+ },
+
{ PIXMAN_OP_NONE },
};
commit a258e33fcb6cf08a2ef76e374cb92a12c9adb171
Author: Taekyun Kim <tkq.kim at samsung.com>
Date: Thu Sep 22 16:33:02 2011 +0900
Move _pixman_lookup_composite_function() to pixman-utils.c
diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h
index c315220..cbd48f3 100644
--- a/pixman/pixman-private.h
+++ b/pixman/pixman-private.h
@@ -730,6 +730,17 @@ pixman_contract (uint32_t * dst,
const uint64_t *src,
int width);
+pixman_bool_t
+_pixman_lookup_composite_function (pixman_implementation_t *toplevel,
+ pixman_op_t op,
+ pixman_format_code_t src_format,
+ uint32_t src_flags,
+ pixman_format_code_t mask_format,
+ uint32_t mask_flags,
+ pixman_format_code_t dest_format,
+ uint32_t dest_flags,
+ pixman_implementation_t **out_imp,
+ pixman_composite_func_t *out_func);
/* Region Helpers */
pixman_bool_t
diff --git a/pixman/pixman-utils.c b/pixman/pixman-utils.c
index 768ca1b..d2af51a 100644
--- a/pixman/pixman-utils.c
+++ b/pixman/pixman-utils.c
@@ -30,6 +30,118 @@
#include "pixman-private.h"
+#define N_CACHED_FAST_PATHS 8
+
+typedef struct
+{
+ struct
+ {
+ pixman_implementation_t * imp;
+ pixman_fast_path_t fast_path;
+ } cache [N_CACHED_FAST_PATHS];
+} cache_t;
+
+PIXMAN_DEFINE_THREAD_LOCAL (cache_t, fast_path_cache);
+
+pixman_bool_t
+_pixman_lookup_composite_function (pixman_implementation_t *toplevel,
+ pixman_op_t op,
+ pixman_format_code_t src_format,
+ uint32_t src_flags,
+ pixman_format_code_t mask_format,
+ uint32_t mask_flags,
+ pixman_format_code_t dest_format,
+ uint32_t dest_flags,
+ pixman_implementation_t **out_imp,
+ pixman_composite_func_t *out_func)
+{
+ pixman_implementation_t *imp;
+ cache_t *cache;
+ int i;
+
+ /* Check cache for fast paths */
+ cache = PIXMAN_GET_THREAD_LOCAL (fast_path_cache);
+
+ for (i = 0; i < N_CACHED_FAST_PATHS; ++i)
+ {
+ const pixman_fast_path_t *info = &(cache->cache[i].fast_path);
+
+ /* Note that we check for equality here, not whether
+ * the cached fast path matches. This is to prevent
+ * us from selecting an overly general fast path
+ * when a more specific one would work.
+ */
+ if (info->op == op &&
+ info->src_format == src_format &&
+ info->mask_format == mask_format &&
+ info->dest_format == dest_format &&
+ info->src_flags == src_flags &&
+ info->mask_flags == mask_flags &&
+ info->dest_flags == dest_flags &&
+ info->func)
+ {
+ *out_imp = cache->cache[i].imp;
+ *out_func = cache->cache[i].fast_path.func;
+
+ goto update_cache;
+ }
+ }
+
+ for (imp = toplevel; imp != NULL; imp = imp->delegate)
+ {
+ const pixman_fast_path_t *info = imp->fast_paths;
+
+ while (info->op != PIXMAN_OP_NONE)
+ {
+ if ((info->op == op || info->op == PIXMAN_OP_any) &&
+ /* Formats */
+ ((info->src_format == src_format) ||
+ (info->src_format == PIXMAN_any)) &&
+ ((info->mask_format == mask_format) ||
+ (info->mask_format == PIXMAN_any)) &&
+ ((info->dest_format == dest_format) ||
+ (info->dest_format == PIXMAN_any)) &&
+ /* Flags */
+ (info->src_flags & src_flags) == info->src_flags &&
+ (info->mask_flags & mask_flags) == info->mask_flags &&
+ (info->dest_flags & dest_flags) == info->dest_flags)
+ {
+ *out_imp = imp;
+ *out_func = info->func;
+
+ /* Set i to the last spot in the cache so that the
+ * move-to-front code below will work
+ */
+ i = N_CACHED_FAST_PATHS - 1;
+
+ goto update_cache;
+ }
+
+ ++info;
+ }
+ }
+ return FALSE;
+
+update_cache:
+ if (i)
+ {
+ while (i--)
+ cache->cache[i + 1] = cache->cache[i];
+
+ cache->cache[0].imp = *out_imp;
+ cache->cache[0].fast_path.op = op;
+ cache->cache[0].fast_path.src_format = src_format;
+ cache->cache[0].fast_path.src_flags = src_flags;
+ cache->cache[0].fast_path.mask_format = mask_format;
+ cache->cache[0].fast_path.mask_flags = mask_flags;
+ cache->cache[0].fast_path.dest_format = dest_format;
+ cache->cache[0].fast_path.dest_flags = dest_flags;
+ cache->cache[0].fast_path.func = *out_func;
+ }
+
+ return TRUE;
+}
+
pixman_bool_t
_pixman_multiply_overflows_size (size_t a, size_t b)
{
diff --git a/pixman/pixman.c b/pixman/pixman.c
index 8ff78e9..8fb5356 100644
--- a/pixman/pixman.c
+++ b/pixman/pixman.c
@@ -335,117 +335,6 @@ pixman_compute_composite_region32 (pixman_region32_t * region,
return TRUE;
}
-#define N_CACHED_FAST_PATHS 8
-
-typedef struct
-{
- struct
- {
- pixman_implementation_t * imp;
- pixman_fast_path_t fast_path;
- } cache [N_CACHED_FAST_PATHS];
-} cache_t;
-
-PIXMAN_DEFINE_THREAD_LOCAL (cache_t, fast_path_cache);
-
-static force_inline pixman_bool_t
-lookup_composite_function (pixman_op_t op,
- pixman_format_code_t src_format,
- uint32_t src_flags,
- pixman_format_code_t mask_format,
- uint32_t mask_flags,
- pixman_format_code_t dest_format,
- uint32_t dest_flags,
- pixman_implementation_t **out_imp,
- pixman_composite_func_t *out_func)
-{
- pixman_implementation_t *imp;
- cache_t *cache;
- int i;
-
- /* Check cache for fast paths */
- cache = PIXMAN_GET_THREAD_LOCAL (fast_path_cache);
-
- for (i = 0; i < N_CACHED_FAST_PATHS; ++i)
- {
- const pixman_fast_path_t *info = &(cache->cache[i].fast_path);
-
- /* Note that we check for equality here, not whether
- * the cached fast path matches. This is to prevent
- * us from selecting an overly general fast path
- * when a more specific one would work.
- */
- if (info->op == op &&
- info->src_format == src_format &&
- info->mask_format == mask_format &&
- info->dest_format == dest_format &&
- info->src_flags == src_flags &&
- info->mask_flags == mask_flags &&
- info->dest_flags == dest_flags &&
- info->func)
- {
- *out_imp = cache->cache[i].imp;
- *out_func = cache->cache[i].fast_path.func;
-
- goto update_cache;
- }
- }
-
- for (imp = get_implementation (); imp != NULL; imp = imp->delegate)
- {
- const pixman_fast_path_t *info = imp->fast_paths;
-
- while (info->op != PIXMAN_OP_NONE)
- {
- if ((info->op == op || info->op == PIXMAN_OP_any) &&
- /* Formats */
- ((info->src_format == src_format) ||
- (info->src_format == PIXMAN_any)) &&
- ((info->mask_format == mask_format) ||
- (info->mask_format == PIXMAN_any)) &&
- ((info->dest_format == dest_format) ||
- (info->dest_format == PIXMAN_any)) &&
- /* Flags */
- (info->src_flags & src_flags) == info->src_flags &&
- (info->mask_flags & mask_flags) == info->mask_flags &&
- (info->dest_flags & dest_flags) == info->dest_flags)
- {
- *out_imp = imp;
- *out_func = info->func;
-
- /* Set i to the last spot in the cache so that the
- * move-to-front code below will work
- */
- i = N_CACHED_FAST_PATHS - 1;
-
- goto update_cache;
- }
-
- ++info;
- }
- }
- return FALSE;
-
-update_cache:
- if (i)
- {
- while (i--)
- cache->cache[i + 1] = cache->cache[i];
-
- cache->cache[0].imp = *out_imp;
- cache->cache[0].fast_path.op = op;
- cache->cache[0].fast_path.src_format = src_format;
- cache->cache[0].fast_path.src_flags = src_flags;
- cache->cache[0].fast_path.mask_format = mask_format;
- cache->cache[0].fast_path.mask_flags = mask_flags;
- cache->cache[0].fast_path.dest_format = dest_format;
- cache->cache[0].fast_path.dest_flags = dest_flags;
- cache->cache[0].fast_path.func = *out_func;
- }
-
- return TRUE;
-}
-
typedef struct
{
pixman_fixed_48_16_t x1;
@@ -790,11 +679,10 @@ pixman_image_composite32 (pixman_op_t op,
*/
op = optimize_operator (op, src_flags, mask_flags, dest_flags);
- if (lookup_composite_function (op,
- src_format, src_flags,
- mask_format, mask_flags,
- dest_format, dest_flags,
- &imp, &func))
+ if (_pixman_lookup_composite_function (
+ get_implementation (), op,
+ src_format, src_flags, mask_format, mask_flags, dest_format, dest_flags,
+ &imp, &func))
{
pixman_composite_info_t info;
const pixman_box32_t *pbox;
commit fc62785aabbe890b656c9cbaa57f2e65e74bbcc2
Author: Søren Sandmann Pedersen <ssp at redhat.com>
Date: Mon Jun 27 21:17:04 2011 +0000
Add src, mask, and dest flags to the composite args struct.
These flags are useful in the various compositing routines, and the
flags stored in the image structs are missing some bits of information
that can only be computed when pixman_image_composite() is called.
diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h
index 741fa7e..c315220 100644
--- a/pixman/pixman-private.h
+++ b/pixman/pixman-private.h
@@ -373,6 +373,10 @@ typedef struct
int32_t dest_y;
int32_t width;
int32_t height;
+
+ uint32_t src_flags;
+ uint32_t mask_flags;
+ uint32_t dest_flags;
} pixman_composite_info_t;
#define PIXMAN_COMPOSITE_ARGS(info) \
diff --git a/pixman/pixman.c b/pixman/pixman.c
index 87f5a93..8ff78e9 100644
--- a/pixman/pixman.c
+++ b/pixman/pixman.c
@@ -804,6 +804,9 @@ pixman_image_composite32 (pixman_op_t op,
info.src_image = src;
info.mask_image = mask;
info.dest_image = dest;
+ info.src_flags = src_flags;
+ info.mask_flags = mask_flags;
+ info.dest_flags = dest_flags;
pbox = pixman_region32_rectangles (®ion, &n);
commit fa6523d13ae9b7986bb890df5ad66e8599bc3ed8
Author: Taekyun Kim <tkq.kim at samsung.com>
Date: Thu Sep 22 16:26:55 2011 +0900
Add new fast path flag FAST_PATH_BITS_IMAGE
This fast path flag indicate that type of the image is bits image.
diff --git a/pixman/pixman-image.c b/pixman/pixman-image.c
index d22698c..afe587f 100644
--- a/pixman/pixman-image.c
+++ b/pixman/pixman-image.c
@@ -375,6 +375,7 @@ compute_image_info (pixman_image_t *image)
else
{
code = image->bits.format;
+ flags |= FAST_PATH_BITS_IMAGE;
}
if (!PIXMAN_FORMAT_A (image->bits.format) &&
diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h
index 69971ea..741fa7e 100644
--- a/pixman/pixman-private.h
+++ b/pixman/pixman-private.h
@@ -631,6 +631,7 @@ _pixman_iter_get_scanline_noop (pixman_iter_t *iter, const uint32_t *mask);
#define FAST_PATH_ROTATE_270_TRANSFORM (1 << 22)
#define FAST_PATH_SAMPLES_COVER_CLIP_NEAREST (1 << 23)
#define FAST_PATH_SAMPLES_COVER_CLIP_BILINEAR (1 << 24)
+#define FAST_PATH_BITS_IMAGE (1 << 25)
#define FAST_PATH_PAD_REPEAT \
(FAST_PATH_NO_NONE_REPEAT | \
commit 7272e2fcd2ff8e546cef19929cd370ae2f946135
Author: Taekyun Kim <tkq.kim at samsung.com>
Date: Thu Sep 22 16:20:03 2011 +0900
init/fini functions for pixman_image_t
pixman_image_t itself can be on stack or heap. So segregating
init/fini from create/unref can be useful when we want to use
pixman_image_t on stack or other memory.
diff --git a/pixman/pixman-bits-image.c b/pixman/pixman-bits-image.c
index f382c65..99c0dfe 100644
--- a/pixman/pixman-bits-image.c
+++ b/pixman/pixman-bits-image.c
@@ -1437,40 +1437,30 @@ create_bits (pixman_format_code_t format,
return calloc (buf_size, 1);
}
-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_bool_t
+_pixman_bits_image_init (pixman_image_t * image,
+ pixman_format_code_t format,
+ int width,
+ int height,
+ uint32_t * bits,
+ int rowstride)
{
- pixman_image_t *image;
uint32_t *free_me = NULL;
- /* must be a whole number of uint32_t's
- */
- return_val_if_fail (
- bits == NULL || (rowstride_bytes % sizeof (uint32_t)) == 0, NULL);
-
- return_val_if_fail (PIXMAN_FORMAT_BPP (format) >= PIXMAN_FORMAT_DEPTH (format), NULL);
-
if (!bits && width && height)
{
- free_me = bits = create_bits (format, width, height, &rowstride_bytes);
- if (!bits)
- return NULL;
- }
+ int rowstride_bytes;
- image = _pixman_image_allocate ();
+ free_me = bits = create_bits (format, width, height, &rowstride_bytes);
- if (!image)
- {
- if (free_me)
- free (free_me);
+ if (!bits)
+ return FALSE;
- return NULL;
+ rowstride = rowstride_bytes / (int) sizeof (uint32_t);
}
+ _pixman_image_init (image);
+
image->type = BITS;
image->bits.format = format;
image->bits.width = width;
@@ -1479,15 +1469,43 @@ pixman_image_create_bits (pixman_format_code_t format,
image->bits.free_me = free_me;
image->bits.read_func = NULL;
image->bits.write_func = NULL;
-
- /* The rowstride is stored in number of uint32_t */
- image->bits.rowstride = rowstride_bytes / (int) sizeof (uint32_t);
-
+ image->bits.rowstride = rowstride;
image->bits.indexed = NULL;
image->common.property_changed = bits_image_property_changed;
_pixman_image_reset_clip_region (image);
+ return TRUE;
+}
+
+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;
+
+ /* must be a whole number of uint32_t's
+ */
+ return_val_if_fail (
+ bits == NULL || (rowstride_bytes % sizeof (uint32_t)) == 0, NULL);
+
+ return_val_if_fail (PIXMAN_FORMAT_BPP (format) >= PIXMAN_FORMAT_DEPTH (format), NULL);
+
+ image = _pixman_image_allocate ();
+
+ if (!image)
+ return NULL;
+
+ if (!_pixman_bits_image_init (image, format, width, height, bits,
+ rowstride_bytes / (int) sizeof (uint32_t)))
+ {
+ free (image);
+ return NULL;
+ }
+
return image;
}
diff --git a/pixman/pixman-image.c b/pixman/pixman-image.c
index a3bb9b6..d22698c 100644
--- a/pixman/pixman-image.c
+++ b/pixman/pixman-image.c
@@ -49,56 +49,33 @@ _pixman_init_gradient (gradient_t * gradient,
return TRUE;
}
-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->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;
- }
-
- return image;
-}
-
-static void
-image_property_changed (pixman_image_t *image)
-{
- image->common.dirty = TRUE;
-}
-
-/* Ref Counting */
-PIXMAN_EXPORT pixman_image_t *
-pixman_image_ref (pixman_image_t *image)
+void
+_pixman_image_init (pixman_image_t *image)
{
- image->common.ref_count++;
-
- return 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;
}
-/* returns TRUE when the image is freed */
-PIXMAN_EXPORT pixman_bool_t
-pixman_image_unref (pixman_image_t *image)
+pixman_bool_t
+_pixman_image_fini (pixman_image_t *image)
{
image_common_t *common = (image_common_t *)image;
@@ -131,8 +108,45 @@ pixman_image_unref (pixman_image_t *image)
if (image->type == BITS && image->bits.free_me)
free (image->bits.free_me);
- free (image);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+pixman_image_t *
+_pixman_image_allocate (void)
+{
+ pixman_image_t *image = malloc (sizeof (pixman_image_t));
+
+ if (image)
+ _pixman_image_init (image);
+
+ return image;
+}
+
+static void
+image_property_changed (pixman_image_t *image)
+{
+ image->common.dirty = TRUE;
+}
+
+/* Ref Counting */
+PIXMAN_EXPORT pixman_image_t *
+pixman_image_ref (pixman_image_t *image)
+{
+ image->common.ref_count++;
+
+ return image;
+}
+
+/* returns TRUE when the image is freed */
+PIXMAN_EXPORT pixman_bool_t
+pixman_image_unref (pixman_image_t *image)
+{
+ if (_pixman_image_fini (image))
+ {
+ free (image);
return TRUE;
}
diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h
index 4d645fe..69971ea 100644
--- a/pixman/pixman-private.h
+++ b/pixman/pixman-private.h
@@ -250,6 +250,19 @@ _pixman_radial_gradient_iter_init (pixman_image_t *image, pixman_iter_t *iter);
void
_pixman_conical_gradient_iter_init (pixman_image_t *image, pixman_iter_t *iter);
+void
+_pixman_image_init (pixman_image_t *image);
+
+pixman_bool_t
+_pixman_bits_image_init (pixman_image_t * image,
+ pixman_format_code_t format,
+ int width,
+ int height,
+ uint32_t * bits,
+ int rowstride);
+pixman_bool_t
+_pixman_image_fini (pixman_image_t *image);
+
pixman_image_t *
_pixman_image_allocate (void);
More information about the xorg-commit
mailing list