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 31typedef void (*FbArc) (FbBits *dst, 32 FbStride dstStride, 33 int dstBpp, 34 xArc *arc, 35 int dx, 36 int dy, 37 FbBits and, 38 FbBits xor); 39 40void 41fbPolyArc (DrawablePtr pDrawable, 42 GCPtr pGC, 43 int narcs, 44 xArc *parcs) 45{ 46 FbArc arc; 47 48 if (pGC->lineWidth == 0) 49 { 50#ifndef FBNOPIXADDR 51 arc = 0; 52 if (pGC->lineStyle == LineSolid && pGC->fillStyle == FillSolid) 53 { 54 switch (pDrawable->bitsPerPixel) 55 { 56 case 8: arc = fbArc8; break; 57 case 16: arc = fbArc16; break; 58#ifdef FB_24BIT 59 case 24: arc = fbArc24; break; 60#endif 61 case 32: arc = fbArc32; break; 62 } 63 } 64 if (arc) 65 { 66 FbGCPrivPtr pPriv = fbGetGCPrivate (pGC); 67 FbBits *dst; 68 FbStride dstStride; 69 int dstBpp; 70 int dstXoff, dstYoff; 71 BoxRec box; 72 int x2, y2; 73 RegionPtr cclip; 74 int wrapped = 0; 75 76 cclip = fbGetCompositeClip (pGC); 77 fbGetDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff); 78#ifdef FB_ACCESS_WRAPPER 79 wrapped = 1; 80#else 81 wrapped = 0; 82#endif 83 while (narcs--) 84 { 85 if (miCanZeroArc (parcs)) 86 { 87 box.x1 = parcs->x + pDrawable->x; 88 box.y1 = parcs->y + pDrawable->y; 89 /* 90 * Because box.x2 and box.y2 get truncated to 16 bits, and the 91 * RECT_IN_REGION test treats the resulting number as a signed 92 * integer, the RECT_IN_REGION test alone can go the wrong way. 93 * This can result in a server crash because the rendering 94 * routines in this file deal directly with cpu addresses 95 * of pixels to be stored, and do not clip or otherwise check 96 * that all such addresses are within their respective pixmaps. 97 * So we only allow the RECT_IN_REGION test to be used for 98 * values that can be expressed correctly in a signed short. 99 */ 100 x2 = box.x1 + (int)parcs->width + 1; 101 box.x2 = x2; 102 y2 = box.y1 + (int)parcs->height + 1; 103 box.y2 = y2; 104 if ( (x2 <= SHRT_MAX) && (y2 <= SHRT_MAX) && 105 (RegionContainsRect(cclip, &box) == rgnIN) ) { 106#ifdef FB_ACCESS_WRAPPER 107 if (!wrapped) { 108 fbPrepareAccess (pDrawable); 109 wrapped = 1; 110 } 111#endif 112 (*arc) (dst, dstStride, dstBpp, 113 parcs, pDrawable->x + dstXoff, pDrawable->y + dstYoff, 114 pPriv->and, pPriv->xor); 115 } else { 116#ifdef FB_ACCESS_WRAPPER 117 if (wrapped) { 118 fbFinishAccess (pDrawable); 119 wrapped = 0; 120 } 121#endif 122 miZeroPolyArc(pDrawable, pGC, 1, parcs); 123 } 124 } 125 else { 126#ifdef FB_ACCESS_WRAPPER 127 if (wrapped) { 128 fbFinishAccess (pDrawable); 129 wrapped = 0; 130 } 131#endif 132 miPolyArc(pDrawable, pGC, 1, parcs); 133 } 134 parcs++; 135 } 136#ifdef FB_ACCESS_WRAPPER 137 if (wrapped) { 138 fbFinishAccess (pDrawable); 139 wrapped = 0; 140 } 141#endif 142 } 143 else 144#endif 145 miZeroPolyArc (pDrawable, pGC, narcs, parcs); 146 } 147 else 148 miPolyArc (pDrawable, pGC, narcs, parcs); 149} 150