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 <stdlib.h> 2503b705cfSriastradh 2603b705cfSriastradh#include "fb.h" 2703b705cfSriastradh#include <mi.h> 2803b705cfSriastradh 2903b705cfSriastradhvoid 3003b705cfSriastradhfbCopyNtoN(DrawablePtr src_drawable, DrawablePtr dst_drawable, GCPtr gc, 3103b705cfSriastradh BoxPtr box, int nbox, 3203b705cfSriastradh int dx, int dy, 3303b705cfSriastradh Bool reverse, Bool upsidedown, Pixel bitplane, 3403b705cfSriastradh void *closure) 3503b705cfSriastradh{ 3603b705cfSriastradh CARD8 alu = gc ? gc->alu : GXcopy; 3703b705cfSriastradh FbBits pm = gc ? fb_gc(gc)->pm : FB_ALLONES; 3803b705cfSriastradh FbBits *src, *dst; 3903b705cfSriastradh FbStride srcStride, dstStride; 4003b705cfSriastradh int dstBpp, srcBpp; 4103b705cfSriastradh int srcXoff, srcYoff; 4203b705cfSriastradh int dstXoff, dstYoff; 4303b705cfSriastradh 4403b705cfSriastradh fbGetDrawable(src_drawable, src, srcStride, srcBpp, srcXoff, srcYoff); 4503b705cfSriastradh fbGetDrawable(dst_drawable, dst, dstStride, dstBpp, dstXoff, dstYoff); 4603b705cfSriastradh 4703b705cfSriastradh src += (dy + srcYoff) * srcStride; 4803b705cfSriastradh srcXoff += dx; 4903b705cfSriastradh dst += dstYoff * dstStride; 5003b705cfSriastradh do { 5103b705cfSriastradh fbBlt(src + box->y1 * srcStride, srcStride, 5203b705cfSriastradh (box->x1 + srcXoff) * srcBpp, 5303b705cfSriastradh dst + box->y1 * dstStride, dstStride, 5403b705cfSriastradh (box->x1 + dstXoff) * dstBpp, 5503b705cfSriastradh (box->x2 - box->x1) * dstBpp, 5603b705cfSriastradh (box->y2 - box->y1), 5703b705cfSriastradh alu, pm, dstBpp, reverse, upsidedown); 5803b705cfSriastradh } while (box++, --nbox); 5903b705cfSriastradh} 6003b705cfSriastradh 6103b705cfSriastradhvoid 6203b705cfSriastradhfbCopy1toN(DrawablePtr src_drawable, DrawablePtr dst_drawable, GCPtr gc, 6303b705cfSriastradh BoxPtr box, int nbox, 6403b705cfSriastradh int dx, int dy, 6503b705cfSriastradh Bool reverse, Bool upsidedown, Pixel bitplane, 6603b705cfSriastradh void *closure) 6703b705cfSriastradh{ 6803b705cfSriastradh FbGCPrivPtr pgc = fb_gc(gc); 6903b705cfSriastradh FbBits *src; 7003b705cfSriastradh FbStride srcStride; 7103b705cfSriastradh int srcBpp; 7203b705cfSriastradh int srcXoff, srcYoff; 7303b705cfSriastradh FbBits *dst; 7403b705cfSriastradh FbStride dstStride; 7503b705cfSriastradh int dstBpp; 7603b705cfSriastradh int dstXoff, dstYoff; 7703b705cfSriastradh 7803b705cfSriastradh fbGetDrawable(src_drawable, src, srcStride, srcBpp, srcXoff, srcYoff); 7903b705cfSriastradh fbGetDrawable(dst_drawable, dst, dstStride, dstBpp, dstXoff, dstYoff); 8003b705cfSriastradh 8103b705cfSriastradh while (nbox--) { 8203b705cfSriastradh if (dstBpp == 1) { 8303b705cfSriastradh fbBlt(src + (box->y1 + dy + srcYoff) * srcStride, 8403b705cfSriastradh srcStride, 8503b705cfSriastradh (box->x1 + dx + srcXoff) * srcBpp, 8603b705cfSriastradh dst + (box->y1 + dstYoff) * dstStride, 8703b705cfSriastradh dstStride, 8803b705cfSriastradh (box->x1 + dstXoff) * dstBpp, 8903b705cfSriastradh (box->x2 - box->x1) * dstBpp, 9003b705cfSriastradh (box->y2 - box->y1), 9103b705cfSriastradh FbOpaqueStipple1Rop(gc->alu, 9203b705cfSriastradh gc->fgPixel, gc->bgPixel), 9303b705cfSriastradh pgc->pm, dstBpp, reverse, upsidedown); 9403b705cfSriastradh } else { 9503b705cfSriastradh fbBltOne((FbStip *) (src + (box->y1 + dy + srcYoff) * srcStride), 9603b705cfSriastradh srcStride * (FB_UNIT / FB_STIP_UNIT), 9703b705cfSriastradh (box->x1 + dx + srcXoff), 9803b705cfSriastradh dst + (box->y1 + dstYoff) * dstStride, 9903b705cfSriastradh dstStride, 10003b705cfSriastradh (box->x1 + dstXoff) * dstBpp, 10103b705cfSriastradh dstBpp, 10203b705cfSriastradh (box->x2 - box->x1) * dstBpp, 10303b705cfSriastradh (box->y2 - box->y1), 10403b705cfSriastradh pgc->and, pgc->xor, pgc->bgand, pgc->bgxor); 10503b705cfSriastradh } 10603b705cfSriastradh box++; 10703b705cfSriastradh } 10803b705cfSriastradh} 10903b705cfSriastradh 11003b705cfSriastradhvoid 11103b705cfSriastradhfbCopyNto1(DrawablePtr src_drawable, DrawablePtr dst_drawable, GCPtr gc, 11203b705cfSriastradh BoxPtr box, int nbox, 11303b705cfSriastradh int dx, int dy, 11403b705cfSriastradh Bool reverse, Bool upsidedown, Pixel bitplane, void *closure) 11503b705cfSriastradh{ 11603b705cfSriastradh FbGCPrivPtr pgc = fb_gc(gc); 11703b705cfSriastradh 11803b705cfSriastradh while (nbox--) { 11903b705cfSriastradh if (dst_drawable->bitsPerPixel == 1) { 12003b705cfSriastradh FbBits *src; 12103b705cfSriastradh FbStride srcStride; 12203b705cfSriastradh int srcBpp; 12303b705cfSriastradh int srcXoff, srcYoff; 12403b705cfSriastradh 12503b705cfSriastradh FbStip *dst; 12603b705cfSriastradh FbStride dstStride; 12703b705cfSriastradh int dstBpp; 12803b705cfSriastradh int dstXoff, dstYoff; 12903b705cfSriastradh 13003b705cfSriastradh fbGetDrawable(src_drawable, src, 13103b705cfSriastradh srcStride, srcBpp, srcXoff, srcYoff); 13203b705cfSriastradh fbGetStipDrawable(dst_drawable, 13303b705cfSriastradh dst, dstStride, dstBpp, dstXoff, dstYoff); 13403b705cfSriastradh fbBltPlane(src + (box->y1 + dy + srcYoff) * srcStride, srcStride, 13503b705cfSriastradh (box->x1 + dx + srcXoff) * srcBpp, srcBpp, 13603b705cfSriastradh dst + (box->y1 + dstYoff) * dstStride, dstStride, 13703b705cfSriastradh (box->x1 + dstXoff) * dstBpp, 13803b705cfSriastradh (box->x2 - box->x1) * srcBpp, (box->y2 - box->y1), 13903b705cfSriastradh (FbStip) pgc->and, (FbStip) pgc->xor, 14003b705cfSriastradh (FbStip) pgc->bgand, (FbStip) pgc->bgxor, bitplane); 14103b705cfSriastradh } else { 14203b705cfSriastradh FbBits *src; 14303b705cfSriastradh FbStride srcStride; 14403b705cfSriastradh int srcBpp; 14503b705cfSriastradh int srcXoff, srcYoff; 14603b705cfSriastradh 14703b705cfSriastradh FbBits *dst; 14803b705cfSriastradh FbStride dstStride; 14903b705cfSriastradh int dstBpp; 15003b705cfSriastradh int dstXoff, dstYoff; 15103b705cfSriastradh 15203b705cfSriastradh FbStip *tmp; 15303b705cfSriastradh FbStride tmpStride; 15403b705cfSriastradh int width, height; 15503b705cfSriastradh 15603b705cfSriastradh width = box->x2 - box->x1; 15703b705cfSriastradh height = box->y2 - box->y1; 15803b705cfSriastradh 15903b705cfSriastradh tmpStride = ((width + FB_STIP_MASK) >> FB_STIP_SHIFT); 16003b705cfSriastradh tmp = malloc(tmpStride * height * sizeof(FbStip)); 16103b705cfSriastradh if (!tmp) 16203b705cfSriastradh return; 16303b705cfSriastradh 16403b705cfSriastradh fbGetDrawable(src_drawable, src, 16503b705cfSriastradh srcStride, srcBpp, srcXoff, srcYoff); 16603b705cfSriastradh fbGetDrawable(dst_drawable, dst, 16703b705cfSriastradh dstStride, dstBpp, dstXoff, dstYoff); 16803b705cfSriastradh 16903b705cfSriastradh fbBltPlane(src + (box->y1 + dy + srcYoff) * srcStride, 17003b705cfSriastradh srcStride, 17103b705cfSriastradh (box->x1 + dx + srcXoff) * srcBpp, 17203b705cfSriastradh srcBpp, 17303b705cfSriastradh tmp, 17403b705cfSriastradh tmpStride, 17503b705cfSriastradh 0, 17603b705cfSriastradh width * srcBpp, 17703b705cfSriastradh height, 17803b705cfSriastradh fbAndStip(GXcopy, FB_ALLONES, FB_ALLONES), 17903b705cfSriastradh fbXorStip(GXcopy, FB_ALLONES, FB_ALLONES), 18003b705cfSriastradh fbAndStip(GXcopy, 0, FB_ALLONES), 18103b705cfSriastradh fbXorStip(GXcopy, 0, FB_ALLONES), bitplane); 18203b705cfSriastradh fbBltOne(tmp, 18303b705cfSriastradh tmpStride, 18403b705cfSriastradh 0, 18503b705cfSriastradh dst + (box->y1 + dstYoff) * dstStride, 18603b705cfSriastradh dstStride, 18703b705cfSriastradh (box->x1 + dstXoff) * dstBpp, 18803b705cfSriastradh dstBpp, 18903b705cfSriastradh width * dstBpp, 19003b705cfSriastradh height, 19103b705cfSriastradh pgc->and, pgc->xor, pgc->bgand, pgc->bgxor); 19203b705cfSriastradh free(tmp); 19303b705cfSriastradh } 19403b705cfSriastradh box++; 19503b705cfSriastradh } 19603b705cfSriastradh} 19703b705cfSriastradh 19803b705cfSriastradhRegionPtr 19903b705cfSriastradhfbCopyArea(DrawablePtr src, DrawablePtr dst, GCPtr gc, 20003b705cfSriastradh int sx, int sy, 20103b705cfSriastradh int width, int height, 20203b705cfSriastradh int dx, int dy) 20303b705cfSriastradh{ 20403b705cfSriastradh return miDoCopy(src, dst, gc, sx, sy, width, height, dx, dy, 20503b705cfSriastradh fbCopyNtoN, 0, 0); 20603b705cfSriastradh} 20703b705cfSriastradh 20803b705cfSriastradhRegionPtr 20903b705cfSriastradhfbCopyPlane(DrawablePtr src, DrawablePtr dst, GCPtr gc, 21003b705cfSriastradh int sx, int sy, 21103b705cfSriastradh int width, int height, 21203b705cfSriastradh int dx, int dy, 21303b705cfSriastradh unsigned long bitplane) 21403b705cfSriastradh{ 21503b705cfSriastradh if (src->bitsPerPixel > 1) 21603b705cfSriastradh return miDoCopy(src, dst, gc, sx, sy, width, height, dx, dy, 21703b705cfSriastradh fbCopyNto1, (Pixel) bitplane, 0); 21803b705cfSriastradh else if (bitplane & 1) 21903b705cfSriastradh return miDoCopy(src, dst, gc, sx, sy, width, height, dx, dy, 22003b705cfSriastradh fbCopy1toN, (Pixel) bitplane, 0); 22103b705cfSriastradh else 22203b705cfSriastradh return miHandleExposures(src, dst, gc, 22303b705cfSriastradh sx, sy, width, height, dx, dy, 22403b705cfSriastradh bitplane); 22503b705cfSriastradh} 226