103b705cfSriastradh/* 203b705cfSriastradh * Copyright © 1998 Keith Packard 303b705cfSriastradh * Copyright © 2012 Intel Corporation 403b705cfSriastradh * 503b705cfSriastradh * Permission to use, copy, modify, distribute, and sell this software and its 603b705cfSriastradh * documentation for any purpose is hereby granted without fee, provided that 703b705cfSriastradh * the above copyright notice appear in all copies and that both that 803b705cfSriastradh * copyright notice and this permission notice appear in supporting 903b705cfSriastradh * documentation, and that the name of Keith Packard not be used in 1003b705cfSriastradh * advertising or publicity pertaining to distribution of the software without 1103b705cfSriastradh * specific, written prior permission. Keith Packard makes no 1203b705cfSriastradh * representations about the suitability of this software for any purpose. It 1303b705cfSriastradh * is provided "as is" without express or implied warranty. 1403b705cfSriastradh * 1503b705cfSriastradh * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 1603b705cfSriastradh * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 1703b705cfSriastradh * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR 1803b705cfSriastradh * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 1903b705cfSriastradh * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 2003b705cfSriastradh * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 2103b705cfSriastradh * PERFORMANCE OF THIS SOFTWARE. 2203b705cfSriastradh */ 2303b705cfSriastradh 2403b705cfSriastradh#include "fb.h" 2503b705cfSriastradh#include "fbclip.h" 2603b705cfSriastradh 2703b705cfSriastradhinline static void 2803b705cfSriastradhfbFillSpan(DrawablePtr drawable, GCPtr gc, const BoxRec *b, void *data) 2903b705cfSriastradh{ 3003b705cfSriastradh DBG(("%s (%d,%d)+%d\n", __FUNCTION__, b->x1, b->y1, b->x2-b->x1)); 3103b705cfSriastradh fbFill(drawable, gc, b->x1, b->y1, b->x2 - b->x1, 1); 3203b705cfSriastradh} 3303b705cfSriastradh 3403b705cfSriastradhvoid 3503b705cfSriastradhfbFillSpans(DrawablePtr drawable, GCPtr gc, 3603b705cfSriastradh int n, DDXPointPtr pt, int *width, int fSorted) 3703b705cfSriastradh{ 3803b705cfSriastradh DBG(("%s x %d\n", __FUNCTION__, n)); 3903b705cfSriastradh while (n--) { 4003b705cfSriastradh BoxRec box; 4103b705cfSriastradh 4203b705cfSriastradh *(DDXPointPtr)&box = *pt++; 4303b705cfSriastradh box.x2 = box.x1 + *width++; 4403b705cfSriastradh box.y2 = box.y1 + 1; 4503b705cfSriastradh 4603b705cfSriastradh /* XXX fSorted */ 4703b705cfSriastradh fbDrawableRun(drawable, gc, &box, fbFillSpan, NULL); 4803b705cfSriastradh } 4903b705cfSriastradh} 5003b705cfSriastradh 5103b705cfSriastradhstruct fbSetSpan { 5203b705cfSriastradh char *src; 5303b705cfSriastradh DDXPointRec pt; 5403b705cfSriastradh FbStride stride; 5503b705cfSriastradh FbBits *dst; 5603b705cfSriastradh int dx, dy; 5703b705cfSriastradh}; 5803b705cfSriastradh 5903b705cfSriastradhinline static void 6003b705cfSriastradhfbSetSpan(DrawablePtr drawable, GCPtr gc, const BoxRec *b, void *_data) 6103b705cfSriastradh{ 6203b705cfSriastradh struct fbSetSpan *data = _data; 6303b705cfSriastradh int xoff, bpp; 6403b705cfSriastradh 6503b705cfSriastradh xoff = (int) (((long)data->src) & (FB_MASK >> 3)); 6603b705cfSriastradh bpp = drawable->bitsPerPixel; 6703b705cfSriastradh 6803b705cfSriastradh fbBlt((FbBits *)(data->src - xoff), 0, 6903b705cfSriastradh (b->x1 - data->pt.x) * bpp + (xoff << 3), 7003b705cfSriastradh data->dst + (b->y1 + data->dy) * data->stride, data->stride, 7103b705cfSriastradh (b->x1 + data->dx) * bpp, 7203b705cfSriastradh (b->x2 - b->x1) * bpp, 1, 7303b705cfSriastradh gc->alu, fb_gc(gc)->pm, bpp, 7403b705cfSriastradh FALSE, FALSE); 7503b705cfSriastradh} 7603b705cfSriastradh 7703b705cfSriastradhvoid 7803b705cfSriastradhfbSetSpans(DrawablePtr drawable, GCPtr gc, 7903b705cfSriastradh char *src, DDXPointPtr pt, int *width, int n, int fSorted) 8003b705cfSriastradh{ 8103b705cfSriastradh struct fbSetSpan data; 8203b705cfSriastradh PixmapPtr pixmap; 8303b705cfSriastradh 8403b705cfSriastradh DBG(("%s x %d\n", __FUNCTION__, n)); 8503b705cfSriastradh 8603b705cfSriastradh fbGetDrawablePixmap(drawable, pixmap, data.dx, data.dy); 8703b705cfSriastradh data.dst = pixmap->devPrivate.ptr; 8803b705cfSriastradh data.stride = pixmap->devKind / sizeof(FbStip); 8903b705cfSriastradh 9003b705cfSriastradh data.src = src; 9103b705cfSriastradh while (n--) { 9203b705cfSriastradh BoxRec box; 9303b705cfSriastradh 9403b705cfSriastradh *(DDXPointPtr)&box = data.pt = *pt; 9503b705cfSriastradh box.x2 = box.x1 + *width; 9603b705cfSriastradh box.y2 = box.y1 + 1; 9703b705cfSriastradh 9803b705cfSriastradh fbDrawableRun(drawable, gc, &box, fbSetSpan, &data); 9903b705cfSriastradh 10003b705cfSriastradh data.src += PixmapBytePad(*width, drawable->depth); 10103b705cfSriastradh width++; 10203b705cfSriastradh pt++; 10303b705cfSriastradh } 10403b705cfSriastradh} 10503b705cfSriastradh 10603b705cfSriastradhvoid 10703b705cfSriastradhfbGetSpans(DrawablePtr drawable, int wMax, 10803b705cfSriastradh DDXPointPtr pt, int *width, int n, char *dst) 10903b705cfSriastradh{ 11003b705cfSriastradh FbBits *src, *d; 11103b705cfSriastradh FbStride srcStride; 11203b705cfSriastradh int srcBpp; 11303b705cfSriastradh int srcXoff, srcYoff; 11403b705cfSriastradh int xoff; 11503b705cfSriastradh 11603b705cfSriastradh fbGetDrawable(drawable, src, srcStride, srcBpp, srcXoff, srcYoff); 11703b705cfSriastradh 11803b705cfSriastradh DBG(("%s x %d\n", __FUNCTION__, n)); 11903b705cfSriastradh while (n--) { 12003b705cfSriastradh xoff = (int) (((long) dst) & (FB_MASK >> 3)); 12103b705cfSriastradh d = (FbBits *) (dst - xoff); 12203b705cfSriastradh fbBlt(src + (pt->y + srcYoff) * srcStride, srcStride, 12303b705cfSriastradh (pt->x + srcXoff) * srcBpp, 12403b705cfSriastradh d, 1, xoff << 3, *width * srcBpp, 12503b705cfSriastradh 1, GXcopy, FB_ALLONES, srcBpp, 12603b705cfSriastradh FALSE, FALSE); 12703b705cfSriastradh dst += PixmapBytePad(*width, drawable->depth); 12803b705cfSriastradh pt++; 12903b705cfSriastradh width++; 13003b705cfSriastradh } 13103b705cfSriastradh} 132