Back to index

lightning-sunbird  0.9+nobinonly
fbtrap.c
Go to the documentation of this file.
00001 /*
00002  * $Id: fbtrap.c,v 1.3.4.1 2005/09/27 23:09:03 vladimir%pobox.com Exp $
00003  *
00004  * Copyright © 2004 Keith Packard
00005  *
00006  * Permission to use, copy, modify, distribute, and sell this software and its
00007  * documentation for any purpose is hereby granted without fee, provided that
00008  * the above copyright notice appear in all copies and that both that
00009  * copyright notice and this permission notice appear in supporting
00010  * documentation, and that the name of Keith Packard not be used in
00011  * advertising or publicity pertaining to distribution of the software without
00012  * specific, written prior permission.  Keith Packard makes no
00013  * representations about the suitability of this software for any purpose.  It
00014  * is provided "as is" without express or implied warranty.
00015  *
00016  * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00017  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
00018  * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
00019  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
00020  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
00021  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00022  * PERFORMANCE OF THIS SOFTWARE.
00023  */
00024 
00025 #include "pixman-xserver-compat.h"
00026 
00027 #ifdef RENDER
00028 
00029 /* XXX: Haven't added addTraps to libpixman yet. */
00030 #if 0
00031 void
00032 fbAddTraps (PicturePtr      pPicture,
00033            INT16     x_off,
00034            INT16     y_off,
00035            int              ntrap,
00036            xTrap     *traps)
00037 {
00038     FbBits    *buf;
00039     int              bpp;
00040     int              width;
00041     int              stride;
00042     int              height;
00043     int              pxoff, pyoff;
00044 
00045     xFixed    x_off_fixed;
00046     xFixed    y_off_fixed;
00047     RenderEdge  l, r;
00048     xFixed    t, b;
00049     
00050     fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff);
00051 
00052     width = pPicture->pDrawable->width;
00053     height = pPicture->pDrawable->height;
00054     x_off += pxoff;
00055     y_off += pyoff;
00056     
00057     x_off_fixed = IntToxFixed(y_off);
00058     y_off_fixed = IntToxFixed(y_off);
00059 
00060     while (ntrap--)
00061     {
00062        t = traps->top.y + y_off_fixed;
00063        if (t < 0)
00064            t = 0;
00065        t = RenderSampleCeilY (t, bpp);
00066     
00067        b = traps->bot.y + y_off_fixed;
00068        if (xFixedToInt (b) >= height)
00069            b = IntToxFixed (height) - 1;
00070        b = RenderSampleFloorY (b, bpp);
00071        
00072        if (b >= t)
00073        {
00074            /* initialize edge walkers */
00075            RenderEdgeInit (&l, bpp, t,
00076                          traps->top.l + x_off_fixed,
00077                          traps->top.y + y_off_fixed,
00078                          traps->bot.l + x_off_fixed,
00079                          traps->bot.y + y_off_fixed);
00080        
00081            RenderEdgeInit (&r, bpp, t,
00082                          traps->top.r + x_off_fixed,
00083                          traps->top.y + y_off_fixed,
00084                          traps->bot.r + x_off_fixed,
00085                          traps->bot.y + y_off_fixed);
00086            
00087            fbRasterizeEdges (buf, bpp, width, stride, &l, &r, t, b);
00088        }
00089        traps++;
00090     }
00091 }
00092 #endif
00093 
00094 void
00095 fbRasterizeTrapezoid (PicturePtr    pPicture,
00096                     const xTrapezoid  *trap,
00097                     int         x_off,
00098                     int         y_off)
00099 {
00100     FbBits    *buf;
00101     int              bpp;
00102     int              width;
00103     int              stride;
00104     int              height;
00105     int              pxoff, pyoff;
00106 
00107     xFixed    x_off_fixed;
00108     xFixed    y_off_fixed;
00109     RenderEdge       l, r;
00110     xFixed    t, b;
00111     
00112     fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff);
00113 
00114     width = pPicture->pDrawable->width;
00115     height = pPicture->pDrawable->height;
00116     x_off += pxoff;
00117     y_off += pyoff;
00118     
00119     x_off_fixed = IntToxFixed(x_off);
00120     y_off_fixed = IntToxFixed(y_off);
00121     t = trap->top + y_off_fixed;
00122     if (t < 0)
00123        t = 0;
00124     t = RenderSampleCeilY (t, bpp);
00125 
00126     b = trap->bottom + y_off_fixed;
00127     if (xFixedToInt (b) >= height)
00128        b = IntToxFixed (height) - 1;
00129     b = RenderSampleFloorY (b, bpp);
00130     
00131     if (b >= t)
00132     {
00133        /* initialize edge walkers */
00134        RenderLineFixedEdgeInit (&l, bpp, t, &trap->left, x_off, y_off);
00135        RenderLineFixedEdgeInit (&r, bpp, t, &trap->right, x_off, y_off);
00136        
00137        fbRasterizeEdges (buf, bpp, width, stride, &l, &r, t, b);
00138     }
00139 }
00140 
00141 /* XXX: Haven't add addTriangles to libpixman yet. */
00142 #if 0
00143 static int
00144 _GreaterY (xPointFixed *a, xPointFixed *b)
00145 {
00146     if (a->y == b->y)
00147        return a->x > b->x;
00148     return a->y > b->y;
00149 }
00150 
00151 /*
00152  * Note that the definition of this function is a bit odd because
00153  * of the X coordinate space (y increasing downwards).
00154  */
00155 static int
00156 _Clockwise (xPointFixed *ref, xPointFixed *a, xPointFixed *b)
00157 {
00158     xPointFixed      ad, bd;
00159 
00160     ad.x = a->x - ref->x;
00161     ad.y = a->y - ref->y;
00162     bd.x = b->x - ref->x;
00163     bd.y = b->y - ref->y;
00164 
00165     return ((xFixed_32_32) bd.y * ad.x - (xFixed_32_32) ad.y * bd.x) < 0;
00166 }
00167 
00168 /* FIXME -- this could be made more efficient */
00169 void
00170 fbAddTriangles (PicturePtr  pPicture,
00171               INT16      x_off,
00172               INT16      y_off,
00173               int        ntri,
00174               xTriangle   *tris)
00175 {
00176     xPointFixed          *top, *left, *right, *tmp;
00177     xTrapezoid           trap;
00178 
00179     for (; ntri; ntri--, tris++)
00180     {
00181        top = &tris->p1;
00182        left = &tris->p2;
00183        right = &tris->p3;
00184        if (_GreaterY (top, left)) {
00185            tmp = left; left = top; top = tmp;
00186        }
00187        if (_GreaterY (top, right)) {
00188            tmp = right; right = top; top = tmp;
00189        }
00190        if (_Clockwise (top, right, left)) {
00191            tmp = right; right = left; left = tmp;
00192        }
00193        
00194        /*
00195         * Two cases:
00196         *
00197         *          +               +
00198         *         / \             / \
00199         *        /   \           /   \
00200         *       /     +         +     \
00201         *      /    --           --    \
00202         *     /   --               --   \
00203         *    / ---                   --- \
00204         *   +--                         --+
00205         */
00206        
00207        trap.top = top->y;
00208        trap.left.p1 = *top;
00209        trap.left.p2 = *left;
00210        trap.right.p1 = *top;
00211        trap.right.p2 = *right;
00212        if (right->y < left->y)
00213            trap.bottom = right->y;
00214        else
00215            trap.bottom = left->y;
00216        fbRasterizeTrapezoid (pPicture, &trap, x_off, y_off);
00217        if (right->y < left->y)
00218        {
00219            trap.top = right->y;
00220            trap.bottom = left->y;
00221            trap.right.p1 = *right;
00222            trap.right.p2 = *left;
00223        }
00224        else
00225        {
00226            trap.top = left->y;
00227            trap.bottom = right->y;
00228            trap.left.p1 = *left;
00229            trap.left.p2 = *right;
00230        }
00231        fbRasterizeTrapezoid (pPicture, &trap, x_off, y_off);
00232     }
00233 }
00234 #endif
00235 
00236 #endif /* RENDER */