[cairo-commit] libpixman/src icint.h,1.35,1.36 fbedge.c,1.2,1.3
Billy Biggs
commit at pdx.freedesktop.org
Mon Aug 1 18:01:26 PDT 2005
- Previous message: [cairo-commit] libpixman ChangeLog,1.93,1.94
- Next message: [cairo-commit] cairo-demo/gameoflife ChangeLog, 1.2, 1.3 Makefile,
1.5, 1.6 cgolwin.cpp, 1.7, 1.8 cgolwin.h, 1.3, 1.4 ctk.cpp, 1.2, 1.3
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: vektor
Update of /cvs/cairo/libpixman/src
In directory gabe:/tmp/cvs-serv17379/src
Modified Files:
icint.h fbedge.c
Log Message:
* src/fbedge.c: (clip255), (add_saturate_8),
(fbRasterizeEdges8): Optimize spans where the same value is
being added to multiple pixels. This improves the speed of
rasterizing wide trapezoids.
* src/icint.h: Add an INLINE macro that matches the one from
fbpict.h in xserver/fb.
Index: icint.h
===================================================================
RCS file: /cvs/cairo/libpixman/src/icint.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- icint.h 27 Jul 2005 21:11:59 -0000 1.35
+++ icint.h 2 Aug 2005 01:01:24 -0000 1.36
@@ -39,6 +39,12 @@
#define __inline
#endif
+#if defined(__GNUC__)
+#define INLINE __inline__
+#else
+#define INLINE
+#endif
+
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
Index: fbedge.c
===================================================================
RCS file: /cvs/cairo/libpixman/src/fbedge.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- fbedge.c 21 Jan 2005 18:26:28 -0000 1.2
+++ fbedge.c 2 Aug 2005 01:01:24 -0000 1.3
@@ -22,36 +22,12 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
+#include <string.h>
#include "pixman-xserver-compat.h"
#ifdef RENDER
/*
- * 8 bit alpha
- */
-
-#define N_BITS 8
-#define rasterizeEdges fbRasterizeEdges8
-
-#define DefineAlpha(line,x) \
- CARD8 *__ap = (CARD8 *) line + (x)
-
-#define StepAlpha __ap++
-
-#define AddAlpha(a) { \
- CARD16 __a = a + *__ap; \
- *__ap = ((CARD8) ((__a) | (0 - ((__a) >> 8)))); \
-}
-
-#include "fbedgeimp.h"
-
-#undef AddAlpha
-#undef StepAlpha
-#undef DefineAlpha
-#undef rasterizeEdges
-#undef N_BITS
-
-/*
* 4 bit alpha
*/
@@ -100,6 +76,208 @@
#undef rasterizeEdges
#undef N_BITS
+/*
+ * 8 bit alpha
+ */
+
+static INLINE CARD8
+clip255 (int x)
+{
+ if (x > 255) return 255;
+ return x;
+}
+
+static INLINE void
+add_saturate_8 (CARD8 *buf, int value, int length)
+{
+ while (length--)
+ {
+ *buf = clip255 (*buf + value);
+ buf++;
+ }
+}
+
+/*
+ * We want to detect the case where we add the same value to a long
+ * span of pixels. The triangles on the end are filled in while we
+ * count how many sub-pixel scanlines contribute to the middle section.
+ *
+ * +--------------------------+
+ * fill_height =| \ /
+ * +------------------+
+ * |================|
+ * fill_start fill_end
+ */
+static void
+fbRasterizeEdges8 (FbBits *buf,
+ int width,
+ int stride,
+ RenderEdge *l,
+ RenderEdge *r,
+ xFixed t,
+ xFixed b)
+{
+ xFixed y = t;
+ FbBits *line;
+ int fill_start = -1, fill_end = -1;
+ int fill_size = 0;
+
+ line = buf + xFixedToInt (y) * stride;
+
+ for (;;)
+ {
+ CARD8 *ap = (CARD8 *) line;
+ xFixed lx, rx;
+ int lxi, rxi;
+
+ /* clip X */
+ lx = l->x;
+ if (lx < 0)
+ lx = 0;
+ rx = r->x;
+ if (xFixedToInt (rx) >= width)
+ rx = IntToxFixed (width);
+
+ /* Skip empty (or backwards) sections */
+ if (rx > lx)
+ {
+ int lxs, rxs;
+
+ /* Find pixel bounds for span. */
+ lxi = xFixedToInt (lx);
+ rxi = xFixedToInt (rx);
+
+ /* Sample coverage for edge pixels */
+ lxs = RenderSamplesX (lx, 8);
+ rxs = RenderSamplesX (rx, 8);
+
+ /* Add coverage across row */
+ if (lxi == rxi)
+ {
+ ap[lxi] = clip255 (ap[lxi] + rxs - lxs);
+ }
+ else
+ {
+ ap[lxi] = clip255 (ap[lxi] + N_X_FRAC(8) - lxs);
+
+ /* Move forward so that lxi/rxi is the pixel span */
+ lxi++;
+
+ /* Don't bother trying to optimize the fill unless
+ * the span is longer than 4 pixels. */
+ if (rxi - lxi > 4)
+ {
+ if (fill_start < 0)
+ {
+ fill_start = lxi;
+ fill_end = rxi;
+ fill_size++;
+ }
+ else
+ {
+ if (lxi >= fill_end || rxi < fill_start)
+ {
+ /* We're beyond what we saved, just fill it */
+ add_saturate_8 (ap + fill_start,
+ fill_size * N_X_FRAC(8),
+ fill_end - fill_start);
+ fill_start = lxi;
+ fill_end = rxi;
+ fill_size = 1;
+ }
+ else
+ {
+ /* Update fill_start */
+ if (lxi > fill_start)
+ {
+ add_saturate_8 (ap + fill_start,
+ fill_size * N_X_FRAC(8),
+ lxi - fill_start);
+ fill_start = lxi;
+ }
+ else if (lxi < fill_start)
+ {
+ add_saturate_8 (ap + lxi, N_X_FRAC(8),
+ fill_start - lxi);
+ }
+
+ /* Update fill_end */
+ if (rxi < fill_end)
+ {
+ add_saturate_8 (ap + rxi,
+ fill_size * N_X_FRAC(8),
+ fill_end - rxi);
+ fill_end = rxi;
+ }
+ else if (fill_end < rxi)
+ {
+ add_saturate_8 (ap + fill_end,
+ N_X_FRAC(8),
+ rxi - fill_end);
+ }
+ fill_size++;
+ }
+ }
+ }
+ else
+ {
+ add_saturate_8 (ap + lxi, N_X_FRAC(8), rxi - lxi);
+ }
+
+ /* Do not add in a 0 alpha here. This check is
+ * necessary to avoid a buffer overrun, (when rx
+ * is exactly on a pixel boundary). */
+ if (rxs)
+ ap[rxi] = clip255 (ap[rxi] + rxs);
+ }
+ }
+
+ if (y == b) {
+ /* We're done, make sure we clean up any remaining fill. */
+ if (fill_start != fill_end) {
+ if (fill_size == N_Y_FRAC(8))
+ {
+ memset (ap + fill_start, 0xff, fill_end - fill_start);
+ }
+ else
+ {
+ add_saturate_8 (ap + fill_start, fill_size * N_X_FRAC(8),
+ fill_end - fill_start);
+ }
+ }
+ break;
+ }
+
+ if (xFixedFrac (y) != Y_FRAC_LAST(8))
+ {
+ RenderEdgeStepSmall (l);
+ RenderEdgeStepSmall (r);
+ y += STEP_Y_SMALL(8);
+ }
+ else
+ {
+ RenderEdgeStepBig (l);
+ RenderEdgeStepBig (r);
+ y += STEP_Y_BIG(8);
+ if (fill_start != fill_end)
+ {
+ if (fill_size == N_Y_FRAC(8))
+ {
+ memset (ap + fill_start, 0xff, fill_end - fill_start);
+ }
+ else
+ {
+ add_saturate_8 (ap + fill_start, fill_size * N_X_FRAC(8),
+ fill_end - fill_start);
+ }
+ fill_start = fill_end = -1;
+ fill_size = 0;
+ }
+ line += stride;
+ }
+ }
+}
+
void
fbRasterizeEdges (FbBits *buf,
int bpp,
- Previous message: [cairo-commit] libpixman ChangeLog,1.93,1.94
- Next message: [cairo-commit] cairo-demo/gameoflife ChangeLog, 1.2, 1.3 Makefile,
1.5, 1.6 cgolwin.cpp, 1.7, 1.8 cgolwin.h, 1.3, 1.4 ctk.cpp, 1.2, 1.3
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the cairo-commit
mailing list