fbarc.c revision 35c4bbdf
105b261ecSmrg/* 205b261ecSmrg * Copyright © 1998 Keith Packard 305b261ecSmrg * 405b261ecSmrg * Permission to use, copy, modify, distribute, and sell this software and its 505b261ecSmrg * documentation for any purpose is hereby granted without fee, provided that 605b261ecSmrg * the above copyright notice appear in all copies and that both that 705b261ecSmrg * copyright notice and this permission notice appear in supporting 805b261ecSmrg * documentation, and that the name of Keith Packard not be used in 905b261ecSmrg * advertising or publicity pertaining to distribution of the software without 1005b261ecSmrg * specific, written prior permission. Keith Packard makes no 1105b261ecSmrg * representations about the suitability of this software for any purpose. It 1205b261ecSmrg * is provided "as is" without express or implied warranty. 1305b261ecSmrg * 1405b261ecSmrg * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 1505b261ecSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 1605b261ecSmrg * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR 1705b261ecSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 1805b261ecSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 1905b261ecSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 2005b261ecSmrg * PERFORMANCE OF THIS SOFTWARE. 2105b261ecSmrg */ 2205b261ecSmrg 2305b261ecSmrg#ifdef HAVE_DIX_CONFIG_H 2405b261ecSmrg#include <dix-config.h> 2505b261ecSmrg#endif 2605b261ecSmrg 2705b261ecSmrg#include "fb.h" 2805b261ecSmrg#include "mizerarc.h" 2905b261ecSmrg#include <limits.h> 3005b261ecSmrg 3135c4bbdfSmrgtypedef void (*FbArc) (FbBits * dst, 3235c4bbdfSmrg FbStride dstStride, 3335c4bbdfSmrg int dstBpp, 3435c4bbdfSmrg xArc * arc, int dx, int dy, FbBits and, FbBits xor); 3505b261ecSmrg 3605b261ecSmrgvoid 3735c4bbdfSmrgfbPolyArc(DrawablePtr pDrawable, GCPtr pGC, int narcs, xArc * parcs) 3805b261ecSmrg{ 3935c4bbdfSmrg FbArc arc; 4035c4bbdfSmrg 4135c4bbdfSmrg if (pGC->lineWidth == 0) { 4235c4bbdfSmrg arc = 0; 4335c4bbdfSmrg if (pGC->lineStyle == LineSolid && pGC->fillStyle == FillSolid) { 4435c4bbdfSmrg switch (pDrawable->bitsPerPixel) { 4535c4bbdfSmrg case 8: 4635c4bbdfSmrg arc = fbArc8; 4735c4bbdfSmrg break; 4835c4bbdfSmrg case 16: 4935c4bbdfSmrg arc = fbArc16; 5035c4bbdfSmrg break; 5135c4bbdfSmrg case 24: 5235c4bbdfSmrg arc = fbArc24; 5335c4bbdfSmrg break; 5435c4bbdfSmrg case 32: 5535c4bbdfSmrg arc = fbArc32; 5635c4bbdfSmrg break; 5735c4bbdfSmrg } 5835c4bbdfSmrg } 5935c4bbdfSmrg if (arc) { 6035c4bbdfSmrg FbGCPrivPtr pPriv = fbGetGCPrivate(pGC); 6135c4bbdfSmrg FbBits *dst; 6235c4bbdfSmrg FbStride dstStride; 6335c4bbdfSmrg int dstBpp; 6435c4bbdfSmrg int dstXoff, dstYoff; 6535c4bbdfSmrg BoxRec box; 6635c4bbdfSmrg int x2, y2; 6735c4bbdfSmrg RegionPtr cclip; 6835c4bbdfSmrg 694642e01fSmrg#ifdef FB_ACCESS_WRAPPER 7035c4bbdfSmrg int wrapped = 1; 714642e01fSmrg#endif 7235c4bbdfSmrg 7335c4bbdfSmrg cclip = fbGetCompositeClip(pGC); 7435c4bbdfSmrg fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff); 7535c4bbdfSmrg while (narcs--) { 7635c4bbdfSmrg if (miCanZeroArc(parcs)) { 7735c4bbdfSmrg box.x1 = parcs->x + pDrawable->x; 7835c4bbdfSmrg box.y1 = parcs->y + pDrawable->y; 7935c4bbdfSmrg /* 8035c4bbdfSmrg * Because box.x2 and box.y2 get truncated to 16 bits, and the 8135c4bbdfSmrg * RECT_IN_REGION test treats the resulting number as a signed 8235c4bbdfSmrg * integer, the RECT_IN_REGION test alone can go the wrong way. 8335c4bbdfSmrg * This can result in a server crash because the rendering 8435c4bbdfSmrg * routines in this file deal directly with cpu addresses 8535c4bbdfSmrg * of pixels to be stored, and do not clip or otherwise check 8635c4bbdfSmrg * that all such addresses are within their respective pixmaps. 8735c4bbdfSmrg * So we only allow the RECT_IN_REGION test to be used for 8835c4bbdfSmrg * values that can be expressed correctly in a signed short. 8935c4bbdfSmrg */ 9035c4bbdfSmrg x2 = box.x1 + (int) parcs->width + 1; 9135c4bbdfSmrg box.x2 = x2; 9235c4bbdfSmrg y2 = box.y1 + (int) parcs->height + 1; 9335c4bbdfSmrg box.y2 = y2; 9435c4bbdfSmrg if ((x2 <= SHRT_MAX) && (y2 <= SHRT_MAX) && 9535c4bbdfSmrg (RegionContainsRect(cclip, &box) == rgnIN)) { 964642e01fSmrg#ifdef FB_ACCESS_WRAPPER 9735c4bbdfSmrg if (!wrapped) { 9835c4bbdfSmrg fbPrepareAccess(pDrawable); 9935c4bbdfSmrg wrapped = 1; 10035c4bbdfSmrg } 1014642e01fSmrg#endif 10235c4bbdfSmrg (*arc) (dst, dstStride, dstBpp, 10335c4bbdfSmrg parcs, pDrawable->x + dstXoff, 10435c4bbdfSmrg pDrawable->y + dstYoff, pPriv->and, pPriv->xor); 10535c4bbdfSmrg } 10635c4bbdfSmrg else { 1074642e01fSmrg#ifdef FB_ACCESS_WRAPPER 10835c4bbdfSmrg if (wrapped) { 10935c4bbdfSmrg fbFinishAccess(pDrawable); 11035c4bbdfSmrg wrapped = 0; 11135c4bbdfSmrg } 1124642e01fSmrg#endif 11335c4bbdfSmrg miZeroPolyArc(pDrawable, pGC, 1, parcs); 11435c4bbdfSmrg } 11535c4bbdfSmrg } 11635c4bbdfSmrg else { 1174642e01fSmrg#ifdef FB_ACCESS_WRAPPER 11835c4bbdfSmrg if (wrapped) { 11935c4bbdfSmrg fbFinishAccess(pDrawable); 12035c4bbdfSmrg wrapped = 0; 12135c4bbdfSmrg } 1224642e01fSmrg#endif 12335c4bbdfSmrg miPolyArc(pDrawable, pGC, 1, parcs); 12435c4bbdfSmrg } 12535c4bbdfSmrg parcs++; 12635c4bbdfSmrg } 1274642e01fSmrg#ifdef FB_ACCESS_WRAPPER 12835c4bbdfSmrg if (wrapped) { 12935c4bbdfSmrg fbFinishAccess(pDrawable); 13035c4bbdfSmrg wrapped = 0; 13135c4bbdfSmrg } 13205b261ecSmrg#endif 13335c4bbdfSmrg } 13435c4bbdfSmrg else 13535c4bbdfSmrg miZeroPolyArc(pDrawable, pGC, narcs, parcs); 13605b261ecSmrg } 13705b261ecSmrg else 13835c4bbdfSmrg miPolyArc(pDrawable, pGC, narcs, parcs); 13905b261ecSmrg} 140