1 From c29c9fa826b7112156fd6150b5f1564227935c05 Mon Sep 17 00:00:00 2001
2 From: Siarhei Siamashka <siarhei.siamashka@nokia.com>
3 Date: Thu, 22 Oct 2009 05:27:33 +0300
4 Subject: [PATCH 3/6] Generic C implementation of pixman_blt with overlapping support
6 Uses memcpy/memmove functions to copy pixels, can handle the
7 case when both source and destination areas are in the same
8 image (this is useful for scrolling).
10 It is assumed that copying direction is only important when
11 using the same image for both source and destination (and
12 src_stride == dst_stride). Copying direction is undefined
13 for the images with different source and destination stride
14 which happen to be in the overlapped areas (but this is an
15 unrealistic case anyway).
17 pixman/pixman-general.c | 21 ++++++++++++++++++---
18 pixman/pixman-private.h | 43 +++++++++++++++++++++++++++++++++++++++++++
19 2 files changed, 61 insertions(+), 3 deletions(-)
21 diff --git a/pixman/pixman-general.c b/pixman/pixman-general.c
22 index c96a3f9..d71a299 100644
23 --- a/pixman/pixman-general.c
24 +++ b/pixman/pixman-general.c
25 @@ -300,9 +300,24 @@ general_blt (pixman_implementation_t *imp,
29 - /* We can't blit unless we have sse2 or mmx */
32 + uint8_t *dst_bytes = (uint8_t *)dst_bits;
33 + uint8_t *src_bytes = (uint8_t *)src_bits;
36 + if (src_bpp != dst_bpp || src_bpp & 7)
43 + pixman_blt_helper (src_bytes + src_y * src_stride + src_x * bpp,
44 + dst_bytes + dst_y * dst_stride + dst_x * bpp,
53 diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h
54 index 5000f91..8c5d4fd 100644
55 --- a/pixman/pixman-private.h
56 +++ b/pixman/pixman-private.h
64 #include "pixman-compiler.h"
65 @@ -794,4 +795,46 @@ void pixman_timer_register (pixman_timer_t *timer);
67 #endif /* PIXMAN_TIMERS */
69 +/* a helper function, can blit 8-bit images with src/dst overlapping support */
71 +pixman_blt_helper (uint8_t *src_bytes,
79 + * The second part of this check is not strictly needed, but it prevents
80 + * unnecessary upside-down processing of areas which belong to different
81 + * images. Upside-down processing can be slower with fixed-distance-ahead
82 + * prefetch and perceived as having more tearing.
84 + if (src_bytes < dst_bytes + width &&
85 + src_bytes + src_stride * height > dst_bytes)
87 + src_bytes += src_stride * height - src_stride;
88 + dst_bytes += dst_stride * height - dst_stride;
89 + dst_stride = -dst_stride;
90 + src_stride = -src_stride;
91 + /* Horizontal scrolling to the left needs memmove */
92 + if (src_bytes + width > dst_bytes)
94 + while (--height >= 0)
96 + memmove (dst_bytes, src_bytes, width);
97 + dst_bytes += dst_stride;
98 + src_bytes += src_stride;
103 + while (--height >= 0)
105 + memcpy (dst_bytes, src_bytes, width);
106 + dst_bytes += dst_stride;
107 + src_bytes += src_stride;
111 #endif /* PIXMAN_PRIVATE_H */