--- fb2/fbcompose.c 2005-08-01 15:51:42.810620080 -0400 +++ iccompose.c 2005-08-01 15:52:15.904589032 -0400 @@ -26,15 +26,54 @@ #ifdef HAVE_CONFIG_H #include #endif -#include "fb.h" +#include +#include "pixman-xserver-compat.h" +#include "fbpict.h" #ifdef RENDER -#include "picturestr.h" -#include "mipict.h" -#include "fbpict.h" +#include "pixregionint.h" + +// #define PIXMAN_CONVOLUTION +// #define PIXMAN_GRADIENTS +// #define PIXMAN_INDEXED_FORMATS +#define miIndexedPtr FbIndexedPtr +#define miIndexToEnt24 FbIndexToEnt24 +#define miIndexToEntY24 FbIndexToEntY24 + +#define MAX_FIXED_48_16 ((xFixed_48_16) 0x7fffffff) +#define MIN_FIXED_48_16 (-((xFixed_48_16) 1 << 31)) + +static Bool +PictureTransformPoint3d (pixman_transform_t *transform, + PictVector *vector) +{ + PictVector result; + int i, j; + xFixed_32_32 partial; + xFixed_48_16 v; + + for (j = 0; j < 3; j++) + { + v = 0; + for (i = 0; i < 3; i++) + { + partial = ((xFixed_48_16) transform->matrix[j][i] * + (xFixed_48_16) vector->vector[i]); + v += partial >> 16; + } + if (v > MAX_FIXED_48_16 || v < MIN_FIXED_48_16) + return FALSE; + result.vector[j] = (xFixed) v; + } + if (!result.vector[2]) + return FALSE; + *vector = result; + return TRUE; +} -#define mod(a,b) ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-a) % (b)) + +// #define mod(a,b) ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-a) % (b)) #define SCANLINE_BUFFER_LENGTH 2048 @@ -509,7 +548,7 @@ static fetchProc fetchProcForPicture (PicturePtr pict) { - switch(pict->format) { + switch(pict->format_code) { case PICT_a8r8g8b8: return fbFetch_a8r8g8b8; case PICT_x8r8g8b8: return fbFetch_x8r8g8b8; case PICT_a8b8g8r8: return fbFetch_a8b8g8r8; @@ -528,9 +567,9 @@ case PICT_a1b5g5r5: return fbFetch_a1b5g5r5; case PICT_x1b5g5r5: return fbFetch_x1b5g5r5; case PICT_a4r4g4b4: return fbFetch_a4r4g4b4; - case PICT_x4r4g4b4: return fbFetch_x4r4g4b4; - case PICT_a4b4g4r4: return fbFetch_a4b4g4r4; - case PICT_x4b4g4r4: return fbFetch_x4b4g4r4; +// case PICT_x4r4g4b4: return fbFetch_x4r4g4b4; +// case PICT_a4b4g4r4: return fbFetch_a4b4g4r4; +// case PICT_x4b4g4r4: return fbFetch_x4b4g4r4; /* 8bpp formats */ case PICT_a8: return fbFetch_a8; @@ -937,7 +976,7 @@ static fetchPixelProc fetchPixelProcForPicture (PicturePtr pict) { - switch(pict->format) { + switch(pict->format_code) { case PICT_a8r8g8b8: return fbFetchPixel_a8r8g8b8; case PICT_x8r8g8b8: return fbFetchPixel_x8r8g8b8; case PICT_a8b8g8r8: return fbFetchPixel_a8b8g8r8; @@ -956,9 +995,9 @@ case PICT_a1b5g5r5: return fbFetchPixel_a1b5g5r5; case PICT_x1b5g5r5: return fbFetchPixel_x1b5g5r5; case PICT_a4r4g4b4: return fbFetchPixel_a4r4g4b4; - case PICT_x4r4g4b4: return fbFetchPixel_x4r4g4b4; - case PICT_a4b4g4r4: return fbFetchPixel_a4b4g4r4; - case PICT_x4b4g4r4: return fbFetchPixel_x4b4g4r4; +// case PICT_x4r4g4b4: return fbFetchPixel_x4r4g4b4; +// case PICT_a4b4g4r4: return fbFetchPixel_a4b4g4r4; +// case PICT_x4b4g4r4: return fbFetchPixel_x4b4g4r4; /* 8bpp formats */ case PICT_a8: return fbFetchPixel_a8; @@ -1374,7 +1413,7 @@ static storeProc storeProcForPicture (PicturePtr pict) { - switch(pict->format) { + switch(pict->format_code) { case PICT_a8r8g8b8: return fbStore_a8r8g8b8; case PICT_x8r8g8b8: return fbStore_x8r8g8b8; case PICT_a8b8g8r8: return fbStore_a8b8g8r8; @@ -1393,9 +1432,9 @@ case PICT_a1b5g5r5: return fbStore_a1b5g5r5; case PICT_x1b5g5r5: return fbStore_x1b5g5r5; case PICT_a4r4g4b4: return fbStore_a4r4g4b4; - case PICT_x4r4g4b4: return fbStore_x4r4g4b4; - case PICT_a4b4g4r4: return fbStore_a4b4g4r4; - case PICT_x4b4g4r4: return fbStore_x4b4g4r4; +// case PICT_x4r4g4b4: return fbStore_x4r4g4b4; +// case PICT_a4b4g4r4: return fbStore_a4b4g4r4; +// case PICT_x4b4g4r4: return fbStore_x4b4g4r4; /* 8bpp formats */ case PICT_a8: return fbStore_a8; @@ -2604,7 +2643,11 @@ CARD32 color; CARD32 *end; fetchPixelProc fetch = fetchPixelProcForPicture(pict); +#ifdef PIXMAN_INDEXED_FORMATS miIndexedPtr indexed = (miIndexedPtr) pict->pFormat->index.devPrivate; +#else + miIndexedPtr indexed = 0; +#endif fbGetDrawable (pict->pDrawable, bits, stride, bpp, xoff, yoff); bits += yoff*stride + (xoff*bpp >> FB_SHIFT); @@ -2623,7 +2666,11 @@ int bpp; int xoff, yoff; fetchProc fetch = fetchProcForPicture(pict); +#ifdef PIXMAN_INDEXED_FORMATS miIndexedPtr indexed = (miIndexedPtr) pict->pFormat->index.devPrivate; +#else + miIndexedPtr indexed = 0; +#endif fbGetDrawable (pict->pDrawable, bits, stride, bpp, xoff, yoff); x += xoff; @@ -2634,11 +2681,10 @@ fetch(bits, x, width, buffer, indexed); } -#define MOD(a,b) ((a) < 0 ? ((b) - ((-(a) - 1) % (b))) - 1 : (a) % (b)) #define DIV(a,b) ((((a) < 0) == ((b) < 0)) ? (a) / (b) :\ ((a) - (b) + 1 - (((b) < 0) << 1)) / (b)) - +#ifdef PIXMAN_GRADIENTS static CARD32 gradientPixel(const SourcePictPtr pGradient, xFixed_48_16 pos, unsigned int spread) { int ipos = (pos * PICT_GRADIENT_STOPTABLE_SIZE - 1) >> 16; @@ -2848,7 +2894,7 @@ } } } - +#endif /* PIXMAN_GRADIENTS */ static void fbFetchTransformed(PicturePtr pict, int x, int y, int width, CARD32 *buffer) @@ -2862,7 +2908,11 @@ PictVector unit; int i; BoxRec box; +#ifdef PIXMAN_INDEXED_FORMATS miIndexedPtr indexed = (miIndexedPtr) pict->pFormat->index.devPrivate; +#else + miIndexedPtr indexed = 0; +#endif fetch = fetchPixelProcForPicture(pict); @@ -2887,10 +2937,10 @@ unit.vector[2] = 0; } - if (pict->filter == PictFilterNearest) + if (pict->filter == PIXMAN_FILTER_NEAREST || pict->filter == PIXMAN_FILTER_FAST) { if (pict->repeat == RepeatNormal) { - if (REGION_NUM_RECTS(pict->pCompositeClip) == 1) { + if (PIXREGION_NUM_RECTS(pict->pCompositeClip) == 1) { box = pict->pCompositeClip->extents; for (i = 0; i < width; ++i) { if (!v.vector[2]) { @@ -2911,7 +2961,7 @@ } else { y = MOD(DIV(v.vector[1],v.vector[2]), pict->pDrawable->height); x = MOD(DIV(v.vector[0],v.vector[2]), pict->pDrawable->width); - if (POINT_IN_REGION (0, pict->pCompositeClip, x, y, &box)) + if (pixman_region_contains_point (pict->pCompositeClip, x, y, &box)) buffer[i] = fetch(bits + (y + pict->pDrawable->y)*stride, x + pict->pDrawable->x, indexed); else buffer[i] = 0; @@ -2922,7 +2972,7 @@ } } } else { - if (REGION_NUM_RECTS(pict->pCompositeClip) == 1) { + if (PIXREGION_NUM_RECTS(pict->pCompositeClip) == 1) { box = pict->pCompositeClip->extents; for (i = 0; i < width; ++i) { if (!v.vector[2]) { @@ -2944,7 +2994,7 @@ } else { y = DIV(v.vector[1],v.vector[2]); x = DIV(v.vector[0],v.vector[2]); - if (POINT_IN_REGION (0, pict->pCompositeClip, x, y, &box)) + if (pixman_region_contains_point (pict->pCompositeClip, x, y, &box)) buffer[i] = fetch(bits + (y + pict->pDrawable->y)*stride, x + pict->pDrawable->x, indexed); else buffer[i] = 0; @@ -2955,9 +3005,9 @@ } } } - } else if (pict->filter == PictFilterBilinear) { + } else if (pict->filter == PIXMAN_FILTER_BILINEAR || pict->filter == PIXMAN_FILTER_GOOD || pict->filter == PIXMAN_FILTER_BEST) { if (pict->repeat == RepeatNormal) { - if (REGION_NUM_RECTS(pict->pCompositeClip) == 1) { + if (PIXREGION_NUM_RECTS(pict->pCompositeClip) == 1) { box = pict->pCompositeClip->extents; for (i = 0; i < width; ++i) { if (!v.vector[2]) { @@ -3031,14 +3081,14 @@ b = bits + (y1 + pict->pDrawable->y)*stride; - tl = POINT_IN_REGION(0, pict->pCompositeClip, x1, y1, &box) + tl = pixman_region_contains_point(pict->pCompositeClip, x1, y1, &box) ? fetch(b, x1 + pict->pDrawable->x, indexed) : 0; - tr = POINT_IN_REGION(0, pict->pCompositeClip, x2, y1, &box) + tr = pixman_region_contains_point(pict->pCompositeClip, x2, y1, &box) ? fetch(b, x2 + pict->pDrawable->x, indexed) : 0; b = bits + (y2 + pict->pDrawable->y)*stride; - bl = POINT_IN_REGION(0, pict->pCompositeClip, x1, y2, &box) + bl = pixman_region_contains_point(pict->pCompositeClip, x1, y2, &box) ? fetch(b, x1 + pict->pDrawable->x, indexed) : 0; - br = POINT_IN_REGION(0, pict->pCompositeClip, x2, y2, &box) + br = pixman_region_contains_point(pict->pCompositeClip, x2, y2, &box) ? fetch(b, x2 + pict->pDrawable->x, indexed) : 0; FbByteAddMul_256(tl, idistx, tr, distx); @@ -3052,7 +3102,7 @@ } } } else { - if (REGION_NUM_RECTS(pict->pCompositeClip) == 1) { + if (PIXREGION_NUM_RECTS(pict->pCompositeClip) == 1) { box = pict->pCompositeClip->extents; for (i = 0; i < width; ++i) { if (!v.vector[2]) { @@ -3124,14 +3174,14 @@ b = bits + (y1 + pict->pDrawable->y)*stride; x_off = x1 + pict->pDrawable->x; - tl = POINT_IN_REGION(0, pict->pCompositeClip, x1, y1, &box) + tl = pixman_region_contains_point(pict->pCompositeClip, x1, y1, &box) ? fetch(b, x_off, indexed) : 0; - tr = POINT_IN_REGION(0, pict->pCompositeClip, x2, y1, &box) + tr = pixman_region_contains_point(pict->pCompositeClip, x2, y1, &box) ? fetch(b, x_off + 1, indexed) : 0; b += stride; - bl = POINT_IN_REGION(0, pict->pCompositeClip, x1, y2, &box) + bl = pixman_region_contains_point(pict->pCompositeClip, x1, y2, &box) ? fetch(b, x_off, indexed) : 0; - br = POINT_IN_REGION(0, pict->pCompositeClip, x2, y2, &box) + br = pixman_region_contains_point(pict->pCompositeClip, x2, y2, &box) ? fetch(b, x_off + 1, indexed) : 0; FbByteAddMul_256(tl, idistx, tr, distx); @@ -3145,6 +3195,7 @@ } } } +#ifdef PIXMAN_CONVOLUTION } else if (pict->filter == PictFilterConvolution) { xFixed *params = pict->filter_params; INT32 cwidth = xFixedToInt(params[0]); @@ -3174,7 +3225,7 @@ for (x = x1; x < x2; x++) { if (*p) { int tx = (pict->repeat == RepeatNormal) ? MOD (x, pict->pDrawable->width) : x; - if (POINT_IN_REGION (0, pict->pCompositeClip, tx, ty, &box)) { + if (pixman_region_contains_point (pict->pCompositeClip, tx, ty, &box)) { FbBits *b = bits + (ty + pict->pDrawable->y)*stride; CARD32 c = fetch(b, tx + pict->pDrawable->x, indexed); @@ -3202,6 +3253,7 @@ v.vector[1] += unit.vector[1]; v.vector[2] += unit.vector[2]; } +#endif } } @@ -3241,7 +3293,11 @@ int bpp; int xoff, yoff; storeProc store = storeProcForPicture(pict); +#ifdef PIXMAN_INDEXED_FORMATS miIndexedPtr indexed = (miIndexedPtr) pict->pFormat->index.devPrivate; +#else + miIndexedPtr indexed = 0; +#endif fbGetDrawable (pict->pDrawable, bits, stride, bpp, xoff, yoff); x += xoff; @@ -3260,7 +3316,11 @@ int ax, ay; storeProc store; storeProc astore; +#ifdef PIXMAN_INDEXED_FORMATS miIndexedPtr indexed = (miIndexedPtr) pict->pFormat->index.devPrivate; +#else + miIndexedPtr indexed = 0; +#endif miIndexedPtr aindexed; if (!pict->alphaMap) { @@ -3270,7 +3330,11 @@ store = storeProcForPicture(pict); astore = storeProcForPicture(pict->alphaMap); +#ifdef PIXMAN_INDEXED_FORMATS aindexed = (miIndexedPtr) pict->alphaMap->pFormat->index.devPrivate; +#else + aindexed = 0; +#endif ax = x; ay = y; @@ -3302,32 +3366,46 @@ scanStoreProc store; scanFetchProc fetchSrc = 0, fetchMask = 0, fetchDest = 0; - if (data->op == PictOpClear) + if (data->op == PIXMAN_OPERATOR_CLEAR) fetchSrc = 0; else if (!data->src->pDrawable) { +#ifdef PIXMAN_GRADIENTS if (data->src->pSourcePict) fetchSrc = fbFetchSourcePict; +#endif } else if (data->src->alphaMap) fetchSrc = fbFetchExternalAlpha; else if (data->src->repeat == RepeatNormal && data->src->pDrawable->width == 1 && data->src->pDrawable->height == 1) fetchSrc = fbFetchSolid; +#ifdef PIXMAN_CONVOLUTION else if (!data->src->transform && data->src->filter != PictFilterConvolution) fetchSrc = fbFetch; +#else + else if (!data->src->transform) + fetchSrc = fbFetch; +#endif else fetchSrc = fbFetchTransformed; - if (data->mask && data->op != PictOpClear) { + if (data->mask && data->op != PIXMAN_OPERATOR_CLEAR) { if (!data->mask->pDrawable) { +#ifdef PIXMAN_GRADIENTS if (data->mask->pSourcePict) fetchMask = fbFetchSourcePict; +#endif } else if (data->mask->alphaMap) fetchMask = fbFetchExternalAlpha; else if (data->mask->repeat == RepeatNormal && data->mask->pDrawable->width == 1 && data->mask->pDrawable->height == 1) fetchMask = fbFetchSolid; +#ifdef PIXMAN_CONVOLUTION else if (!data->mask->transform && data->mask->filter != PictFilterConvolution) fetchMask = fbFetch; +#else + else if (!data->mask->transform) + fetchMask = fbFetch; +#endif else fetchMask = fbFetchTransformed; } else { @@ -3341,10 +3419,10 @@ fetchDest = fbFetch; store = fbStore; } - if (data->op == PictOpClear || data->op == PictOpSrc) + if (data->op == PIXMAN_OPERATOR_CLEAR || data->op == PIXMAN_OPERATOR_SRC) fetchDest = 0; - if (fetchSrc && fetchMask && data->mask && data->mask->componentAlpha && PICT_FORMAT_RGB(data->mask->format)) { + if (fetchSrc && fetchMask && data->mask && data->mask->componentAlpha && PICT_FORMAT_RGB(data->mask->format_code)) { CARD32 *mask_buffer = dest_buffer + data->width; CombineFuncC compose = composeFunctions.combineC[data->op]; if (!compose) @@ -3408,7 +3486,7 @@ } void -fbCompositeGeneral (CARD8 op, +pixman_compositeGeneral (pixman_operator_t op, PicturePtr pSrc, PicturePtr pMask, PicturePtr pDst, @@ -3421,7 +3499,7 @@ CARD16 width, CARD16 height) { - RegionRec region; + pixman_region16_t *region; int n; BoxPtr pbox; Bool srcRepeat = FALSE; @@ -3439,10 +3517,13 @@ maskRepeat = pMask->repeat == RepeatNormal && !pMask->transform && (pMask->pDrawable->width != 1 || pMask->pDrawable->height != 1); - if (op == PictOpOver && !pMask && !pSrc->transform && !PICT_FORMAT_A(pSrc->format) && !pSrc->alphaMap) - op = PictOpSrc; + if (op == PIXMAN_OPERATOR_OVER && !pMask && !pSrc->transform && !PICT_FORMAT_A(pSrc->format_code) && !pSrc->alphaMap) + op = PIXMAN_OPERATOR_SRC; + + region = pixman_region_create(); + pixman_region_union_rect (region, region, xDst, yDst, width, height); - if (!miComputeCompositeRegion (®ion, + if (!FbComputeCompositeRegion (region, pSrc, pMask, pDst, @@ -3463,8 +3544,8 @@ if (width > SCANLINE_BUFFER_LENGTH) scanline_buffer = (CARD32 *) malloc(width * 3 * sizeof(CARD32)); - n = REGION_NUM_RECTS (®ion); - pbox = REGION_RECTS (®ion); + n = pixman_region_num_rects (region); + pbox = pixman_region_rects (region); while (n--) { h = pbox->y2 - pbox->y1; @@ -3480,13 +3561,13 @@ compose_data.xDest = pbox->x1; if (maskRepeat) { - compose_data.yMask = mod (compose_data.yMask, pMask->pDrawable->height); + compose_data.yMask = MOD (compose_data.yMask, pMask->pDrawable->height); if (compose_data.height > pMask->pDrawable->height - compose_data.yMask) compose_data.height = pMask->pDrawable->height - compose_data.yMask; } if (srcRepeat) { - compose_data.ySrc = mod (compose_data.ySrc, pSrc->pDrawable->height); + compose_data.ySrc = MOD (compose_data.ySrc, pSrc->pDrawable->height); if (compose_data.height > pSrc->pDrawable->height - compose_data.ySrc) compose_data.height = pSrc->pDrawable->height - compose_data.ySrc; } @@ -3495,13 +3576,13 @@ compose_data.width = w; if (maskRepeat) { - compose_data.xMask = mod (compose_data.xMask, pMask->pDrawable->width); + compose_data.xMask = MOD (compose_data.xMask, pMask->pDrawable->width); if (compose_data.width > pMask->pDrawable->width - compose_data.xMask) compose_data.width = pMask->pDrawable->width - compose_data.xMask; } if (srcRepeat) { - compose_data.xSrc = mod (compose_data.xSrc, pSrc->pDrawable->width); + compose_data.xSrc = MOD (compose_data.xSrc, pSrc->pDrawable->width); if (compose_data.width > pSrc->pDrawable->width - compose_data.xSrc) compose_data.width = pSrc->pDrawable->width - compose_data.xSrc; } @@ -3518,7 +3599,7 @@ } pbox++; } - REGION_UNINIT (pDst->pDrawable->pScreen, ®ion); + pixman_region_destroy (region); if (scanline_buffer != _scanline_buffer) free(scanline_buffer);