xserver

xserver with xephyr scale patch
git clone https://git.neptards.moe/u3shit/xserver.git
Log | Files | Refs | README | LICENSE

fbarc.c (5054B)


      1 /*
      2  * Copyright © 1998 Keith Packard
      3  *
      4  * Permission to use, copy, modify, distribute, and sell this software and its
      5  * documentation for any purpose is hereby granted without fee, provided that
      6  * the above copyright notice appear in all copies and that both that
      7  * copyright notice and this permission notice appear in supporting
      8  * documentation, and that the name of Keith Packard not be used in
      9  * advertising or publicity pertaining to distribution of the software without
     10  * specific, written prior permission.  Keith Packard makes no
     11  * representations about the suitability of this software for any purpose.  It
     12  * is provided "as is" without express or implied warranty.
     13  *
     14  * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
     15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
     16  * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
     17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
     18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
     19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
     20  * PERFORMANCE OF THIS SOFTWARE.
     21  */
     22 
     23 #ifdef HAVE_DIX_CONFIG_H
     24 #include <dix-config.h>
     25 #endif
     26 
     27 #include "fb.h"
     28 #include "mizerarc.h"
     29 #include <limits.h>
     30 
     31 typedef void (*FbArc) (FbBits * dst,
     32                        FbStride dstStride,
     33                        int dstBpp,
     34                        xArc * arc, int dx, int dy, FbBits and, FbBits xor);
     35 
     36 void
     37 fbPolyArc(DrawablePtr pDrawable, GCPtr pGC, int narcs, xArc * parcs)
     38 {
     39     FbArc arc;
     40 
     41     if (pGC->lineWidth == 0) {
     42         arc = 0;
     43         if (pGC->lineStyle == LineSolid && pGC->fillStyle == FillSolid) {
     44             switch (pDrawable->bitsPerPixel) {
     45             case 8:
     46                 arc = fbArc8;
     47                 break;
     48             case 16:
     49                 arc = fbArc16;
     50                 break;
     51             case 32:
     52                 arc = fbArc32;
     53                 break;
     54             }
     55         }
     56         if (arc) {
     57             FbGCPrivPtr pPriv = fbGetGCPrivate(pGC);
     58             FbBits *dst;
     59             FbStride dstStride;
     60             int dstBpp;
     61             int dstXoff, dstYoff;
     62             BoxRec box;
     63             int x2, y2;
     64             RegionPtr cclip;
     65 
     66 #ifdef FB_ACCESS_WRAPPER
     67             int wrapped = 1;
     68 #endif
     69 
     70             cclip = fbGetCompositeClip(pGC);
     71             fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
     72             while (narcs--) {
     73                 if (miCanZeroArc(parcs)) {
     74                     box.x1 = parcs->x + pDrawable->x;
     75                     box.y1 = parcs->y + pDrawable->y;
     76                     /*
     77                      * Because box.x2 and box.y2 get truncated to 16 bits, and the
     78                      * RECT_IN_REGION test treats the resulting number as a signed
     79                      * integer, the RECT_IN_REGION test alone can go the wrong way.
     80                      * This can result in a server crash because the rendering
     81                      * routines in this file deal directly with cpu addresses
     82                      * of pixels to be stored, and do not clip or otherwise check
     83                      * that all such addresses are within their respective pixmaps.
     84                      * So we only allow the RECT_IN_REGION test to be used for
     85                      * values that can be expressed correctly in a signed short.
     86                      */
     87                     x2 = box.x1 + (int) parcs->width + 1;
     88                     box.x2 = x2;
     89                     y2 = box.y1 + (int) parcs->height + 1;
     90                     box.y2 = y2;
     91                     if ((x2 <= SHRT_MAX) && (y2 <= SHRT_MAX) &&
     92                         (RegionContainsRect(cclip, &box) == rgnIN)) {
     93 #ifdef FB_ACCESS_WRAPPER
     94                         if (!wrapped) {
     95                             fbPrepareAccess(pDrawable);
     96                             wrapped = 1;
     97                         }
     98 #endif
     99                         (*arc) (dst, dstStride, dstBpp,
    100                                 parcs, pDrawable->x + dstXoff,
    101                                 pDrawable->y + dstYoff, pPriv->and, pPriv->xor);
    102                     }
    103                     else {
    104 #ifdef FB_ACCESS_WRAPPER
    105                         if (wrapped) {
    106                             fbFinishAccess(pDrawable);
    107                             wrapped = 0;
    108                         }
    109 #endif
    110                         miZeroPolyArc(pDrawable, pGC, 1, parcs);
    111                     }
    112                 }
    113                 else {
    114 #ifdef FB_ACCESS_WRAPPER
    115                     if (wrapped) {
    116                         fbFinishAccess(pDrawable);
    117                         wrapped = 0;
    118                     }
    119 #endif
    120                     miPolyArc(pDrawable, pGC, 1, parcs);
    121                 }
    122                 parcs++;
    123             }
    124 #ifdef FB_ACCESS_WRAPPER
    125             if (wrapped) {
    126                 fbFinishAccess(pDrawable);
    127                 wrapped = 0;
    128             }
    129 #endif
    130         }
    131         else
    132             miZeroPolyArc(pDrawable, pGC, narcs, parcs);
    133     }
    134     else
    135         miPolyArc(pDrawable, pGC, narcs, parcs);
    136 }