diff options
Diffstat (limited to 'render/mitri.c')
-rw-r--r-- | render/mitri.c | 274 |
1 files changed, 55 insertions, 219 deletions
diff --git a/render/mitri.c b/render/mitri.c index b0526256d..5d5df1c61 100644 --- a/render/mitri.c +++ b/render/mitri.c @@ -65,82 +65,6 @@ miTriangleBounds (int ntri, xTriangle *tris, BoxPtr bounds) } void -miRasterizeTriangle (PicturePtr pPicture, - xTriangle *tri, - int x_off, - int y_off) -{ - ScreenPtr pScreen = pPicture->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - xPointFixed *top, *left, *right, *t; - xTrapezoid trap[2]; - - top = &tri->p1; - left = &tri->p2; - right = &tri->p3; - if (left->y < top->y) { - t = left; left = top; top = t; - } - if (right->y < top->y) { - t = right; right = top; top = t; - } - if (right->x < left->x) { - t = right; right = left; left = t; - } - - /* - * Two cases: - * - * + + - * / \ / \ - * / \ / \ - * / + + \ - * / -- -- \ - * / -- -- \ - * / --- --- \ - * +-- --+ - */ - - trap[0].top = top->y; - - trap[0].left.p1.x = top->x; - trap[0].left.p1.y = trap[0].top; - trap[0].left.p2.x = left->x; - trap[0].left.p2.y = left->y; - - trap[0].right.p1 = trap[0].left.p1; - trap[0].right.p2.x = right->x; - trap[0].right.p2.y = right->y; - - if (right->y < left->y) - { - trap[0].bottom = trap[0].right.p2.y; - - trap[1].top = trap[0].bottom; - trap[1].bottom = trap[0].left.p2.y; - - trap[1].left = trap[0].left; - trap[1].right.p1 = trap[0].right.p2; - trap[1].right.p2 = trap[0].left.p2; - } - else - { - trap[0].bottom = trap[0].left.p2.y; - - trap[1].top = trap[0].bottom; - trap[1].bottom = trap[0].right.p2.y; - - trap[1].right = trap[0].right; - trap[1].left.p1 = trap[0].left.p2; - trap[1].left.p2 = trap[0].right.p2; - } - if (trap[0].top != trap[0].bottom) - (*ps->RasterizeTrapezoid) (pPicture, &trap[0], x_off, y_off); - if (trap[1].top != trap[1].bottom) - (*ps->RasterizeTrapezoid) (pPicture, &trap[1], x_off, y_off); -} - -void miTriangles (CARD8 op, PicturePtr pSrc, PicturePtr pDst, @@ -151,16 +75,25 @@ miTriangles (CARD8 op, xTriangle *tris) { ScreenPtr pScreen = pDst->pDrawable->pScreen; - BoxRec bounds; - PicturePtr pPicture = 0; - INT16 xDst, yDst; - INT16 xRel, yRel; - - xDst = tris[0].p1.x >> 16; - yDst = tris[0].p1.y >> 16; + PictureScreenPtr ps = GetPictureScreen(pScreen); - if (maskFormat) + /* + * Check for solid alpha add + */ + if (op == PictOpAdd && miIsSolidAlpha (pSrc)) { + (*ps->AddTriangles) (pDst, 0, 0, ntri, tris); + } + else if (maskFormat) + { + BoxRec bounds; + PicturePtr pPicture; + INT16 xDst, yDst; + INT16 xRel, yRel; + + xDst = tris[0].p1.x >> 16; + yDst = tris[0].p1.y >> 16; + miTriangleBounds (ntri, tris, &bounds); if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1) return; @@ -169,34 +102,8 @@ miTriangles (CARD8 op, bounds.y2 - bounds.y1); if (!pPicture) return; - } - for (; ntri; ntri--, tris++) - { - if (!maskFormat) - { - miTriangleBounds (1, tris, &bounds); - if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1) - continue; - pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - if (!pPicture) - break; - } - miRasterizeTriangle (pPicture, tris, -bounds.x1, -bounds.y1); - if (!maskFormat) - { - xRel = bounds.x1 + xSrc - xDst; - yRel = bounds.y1 + ySrc - yDst; - CompositePicture (op, pSrc, pPicture, pDst, - xRel, yRel, 0, 0, bounds.x1, bounds.y1, - bounds.x2 - bounds.x1, bounds.y2 - bounds.y1); - FreePicture (pPicture, 0); - } - /* XXX adjust xSrc and ySrc */ - } - if (maskFormat) - { + (*ps->AddTriangles) (pPicture, -bounds.x1, -bounds.y1, ntri, tris); + xRel = bounds.x1 + xSrc - xDst; yRel = bounds.y1 + ySrc - yDst; CompositePicture (op, pSrc, pPicture, pDst, @@ -204,6 +111,16 @@ miTriangles (CARD8 op, bounds.x2 - bounds.x1, bounds.y2 - bounds.y1); FreePicture (pPicture, 0); } + else + { + if (pDst->polyEdge == PolyEdgeSharp) + maskFormat = PictureMatchFormat (pScreen, 1, PICT_a1); + else + maskFormat = PictureMatchFormat (pScreen, 8, PICT_a8); + + for (; ntri; ntri--, tris++) + miTriangles (op, pSrc, pDst, maskFormat, xSrc, ySrc, 1, tris); + } } void @@ -217,64 +134,24 @@ miTriStrip (CARD8 op, xPointFixed *points) { ScreenPtr pScreen = pDst->pDrawable->pScreen; - xTriangle tri; - BoxRec bounds; - PicturePtr pPicture = 0; - INT16 xDst, yDst; - INT16 xRel, yRel; - - xDst = points[0].x >> 16; - yDst = points[0].y >> 16; + PictureScreenPtr ps = GetPictureScreen(pScreen); + xTriangle *tris, *tri; + int ntri; if (npoint < 3) return; - if (maskFormat) - { - miPointFixedBounds (npoint, points, &bounds); - if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1) - return; - pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - if (!pPicture) - return; - } - for (; npoint >= 3; npoint--, points++) - { - tri.p1 = points[0]; - tri.p2 = points[1]; - tri.p3 = points[2]; - if (!maskFormat) - { - miTriangleBounds (1, &tri, &bounds); - if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1) - continue; - pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - if (!pPicture) - continue; - } - miRasterizeTriangle (pPicture, &tri, -bounds.x1, -bounds.y1); - if (!maskFormat) - { - xRel = bounds.x1 + xSrc - xDst; - yRel = bounds.y1 + ySrc - yDst; - CompositePicture (op, pSrc, pPicture, pDst, - xRel, yRel, 0, 0, bounds.x1, bounds.y1, - bounds.x2 - bounds.x1, bounds.y2 - bounds.y1); - FreePicture (pPicture, 0); - } - } - if (maskFormat) + ntri = npoint - 2; + tris = ALLOCATE_LOCAL (ntri & sizeof (xTriangle)); + if (!tris) + return; + for (tri = tris; npoint >= 3; npoint--, points++, tri++) { - xRel = bounds.x1 + xSrc - xDst; - yRel = bounds.y1 + ySrc - yDst; - CompositePicture (op, pSrc, pPicture, pDst, - xRel, yRel, 0, 0, bounds.x1, bounds.y1, - bounds.x2 - bounds.x1, bounds.y2 - bounds.y1); - FreePicture (pPicture, 0); + tri->p1 = points[0]; + tri->p2 = points[1]; + tri->p3 = points[2]; } + (*ps->Triangles) (op, pSrc, pDst, maskFormat, xSrc, ySrc, ntri, tris); + DEALLOCATE_LOCAL (tris); } void @@ -288,65 +165,24 @@ miTriFan (CARD8 op, xPointFixed *points) { ScreenPtr pScreen = pDst->pDrawable->pScreen; - xTriangle tri; - BoxRec bounds; - PicturePtr pPicture = 0; + PictureScreenPtr ps = GetPictureScreen(pScreen); + xTriangle *tris, *tri; xPointFixed *first; - INT16 xDst, yDst; - INT16 xRel, yRel; - - xDst = points[0].x >> 16; - yDst = points[0].y >> 16; + int ntri; if (npoint < 3) return; - if (maskFormat) - { - miPointFixedBounds (npoint, points, &bounds); - if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1) - return; - pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - if (!pPicture) - return; - } + ntri = npoint - 2; + tris = ALLOCATE_LOCAL (ntri & sizeof (xTriangle)); + if (!tris) + return; first = points++; - npoint--; - for (; npoint >= 2; npoint--, points++) + for (tri = tris; npoint >= 3; npoint--, points++, tri++) { - tri.p1 = *first; - tri.p2 = points[0]; - tri.p3 = points[1]; - if (!maskFormat) - { - miTriangleBounds (1, &tri, &bounds); - if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1) - continue; - pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat, - bounds.x2 - bounds.x1, - bounds.y2 - bounds.y1); - if (!pPicture) - continue; - } - miRasterizeTriangle (pPicture, &tri, -bounds.x1, -bounds.y1); - if (!maskFormat) - { - xRel = bounds.x1 + xSrc - xDst; - yRel = bounds.y1 + ySrc - yDst; - CompositePicture (op, pSrc, pPicture, pDst, - xRel, yRel, 0, 0, bounds.x1, bounds.y1, - bounds.x2 - bounds.x1, bounds.y2 - bounds.y1); - FreePicture (pPicture, 0); - } - } - if (maskFormat) - { - xRel = bounds.x1 + xSrc - xDst; - yRel = bounds.y1 + ySrc - yDst; - CompositePicture (op, pSrc, pPicture, pDst, - xRel, yRel, 0, 0, bounds.x1, bounds.y1, - bounds.x2 - bounds.x1, bounds.y2 - bounds.y1); - FreePicture (pPicture, 0); + tri->p1 = *first; + tri->p2 = points[0]; + tri->p3 = points[1]; } + (*ps->Triangles) (op, pSrc, pDst, maskFormat, xSrc, ySrc, ntri, tris); + DEALLOCATE_LOCAL (tris); } |