diff options
author | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-10-12 18:07:29 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-10-21 04:13:36 -0400 |
commit | 2d9cb563b415e90cef898de03de7ed9c6f091db1 (patch) | |
tree | d5f9c4fa657a7e28eee3fcce403afea40511d113 | |
parent | af803be17b4ea5f53db9af57b6c6ef06db99ebbd (diff) |
Add new pixman_image_create_bits_no_clear() API
When pixman_image_create_bits() function is given NULL for bits, it
will allocate a new buffer and initialize it to zero. However, in some
cases, only a small region of the image is actually used; in that case
it is wasteful to touch all of the memory.
The new pixman_image_create_bits_no_clear() works exactly like
_create_bits() except that it doesn't initialize any newly allocated
memory.
-rw-r--r-- | pixman/pixman-bits-image.c | 54 | ||||
-rw-r--r-- | pixman/pixman-fast-path.c | 3 | ||||
-rw-r--r-- | pixman/pixman-private.h | 3 | ||||
-rw-r--r-- | pixman/pixman.h | 5 |
4 files changed, 52 insertions, 13 deletions
diff --git a/pixman/pixman-bits-image.c b/pixman/pixman-bits-image.c index 029093d..085dd16 100644 --- a/pixman/pixman-bits-image.c +++ b/pixman/pixman-bits-image.c @@ -1388,7 +1388,8 @@ static uint32_t * create_bits (pixman_format_code_t format, int width, int height, - int * rowstride_bytes) + int * rowstride_bytes, + pixman_bool_t clear) { int stride; size_t buf_size; @@ -1420,7 +1421,10 @@ create_bits (pixman_format_code_t format, if (rowstride_bytes) *rowstride_bytes = stride; - return calloc (buf_size, 1); + if (clear) + return calloc (buf_size, 1); + else + return malloc (buf_size); } pixman_bool_t @@ -1429,7 +1433,8 @@ _pixman_bits_image_init (pixman_image_t * image, int width, int height, uint32_t * bits, - int rowstride) + int rowstride, + pixman_bool_t clear) { uint32_t *free_me = NULL; @@ -1437,7 +1442,7 @@ _pixman_bits_image_init (pixman_image_t * image, { int rowstride_bytes; - free_me = bits = create_bits (format, width, height, &rowstride_bytes); + free_me = bits = create_bits (format, width, height, &rowstride_bytes, clear); if (!bits) return FALSE; @@ -1465,12 +1470,13 @@ _pixman_bits_image_init (pixman_image_t * 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) +static pixman_image_t * +create_bits_image_internal (pixman_format_code_t format, + int width, + int height, + uint32_t * bits, + int rowstride_bytes, + pixman_bool_t clear) { pixman_image_t *image; @@ -1487,7 +1493,8 @@ pixman_image_create_bits (pixman_format_code_t format, return NULL; if (!_pixman_bits_image_init (image, format, width, height, bits, - rowstride_bytes / (int) sizeof (uint32_t))) + rowstride_bytes / (int) sizeof (uint32_t), + clear)) { free (image); return NULL; @@ -1495,3 +1502,28 @@ pixman_image_create_bits (pixman_format_code_t format, return image; } + +/* If bits is NULL, a buffer will be allocated and initialized to 0 */ +PIXMAN_EXPORT pixman_image_t * +pixman_image_create_bits (pixman_format_code_t format, + int width, + int height, + uint32_t * bits, + int rowstride_bytes) +{ + return create_bits_image_internal ( + format, width, height, bits, rowstride_bytes, TRUE); +} + + +/* If bits is NULL, a buffer will be allocated and _not_ initialized */ +PIXMAN_EXPORT pixman_image_t * +pixman_image_create_bits_no_clear (pixman_format_code_t format, + int width, + int height, + uint32_t * bits, + int rowstride_bytes) +{ + return create_bits_image_internal ( + format, width, height, bits, rowstride_bytes, FALSE); +} diff --git a/pixman/pixman-fast-path.c b/pixman/pixman-fast-path.c index a12c6cf..d95cb4d 100644 --- a/pixman/pixman-fast-path.c +++ b/pixman/pixman-fast-path.c @@ -1296,7 +1296,8 @@ fast_composite_tiled_repeat (pixman_implementation_t *imp, /* 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); + src_width, 1, &extended_src[0], src_stride, + FALSE); _pixman_image_validate (&extended_src_image); info2.src_image = &extended_src_image; diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h index dd03a93..c0a6bc0 100644 --- a/pixman/pixman-private.h +++ b/pixman/pixman-private.h @@ -283,7 +283,8 @@ _pixman_bits_image_init (pixman_image_t * image, int width, int height, uint32_t * bits, - int rowstride); + int rowstride, + pixman_bool_t clear); pixman_bool_t _pixman_image_fini (pixman_image_t *image); diff --git a/pixman/pixman.h b/pixman/pixman.h index 1dc167a..c8723cf 100644 --- a/pixman/pixman.h +++ b/pixman/pixman.h @@ -757,6 +757,11 @@ pixman_image_t *pixman_image_create_bits (pixman_format_code_t int height, uint32_t *bits, int rowstride_bytes); +pixman_image_t *pixman_image_create_bits_no_clear (pixman_format_code_t format, + int width, + int height, + uint32_t * bits, + int rowstride_bytes); /* Destructor */ pixman_image_t *pixman_image_ref (pixman_image_t *image); |