f78b12e570284aa8291f4ca1add24937fd107403vboxsync/*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync *
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * Copyright © 2000 Keith Packard
f78b12e570284aa8291f4ca1add24937fd107403vboxsync *
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * Permission to use, copy, modify, distribute, and sell this software and its
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * documentation for any purpose is hereby granted without fee, provided that
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * the above copyright notice appear in all copies and that both that
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * copyright notice and this permission notice appear in supporting
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * documentation, and that the name of Keith Packard not be used in
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * advertising or publicity pertaining to distribution of the software without
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * specific, written prior permission. Keith Packard makes no
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * representations about the suitability of this software for any purpose. It
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * is provided "as is" without express or implied warranty.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync *
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * PERFORMANCE OF THIS SOFTWARE.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * Thanks to Daniel Chemko <dchemko@intrinsyc.com> for making the 90 and 180
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * orientations work.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#ifdef HAVE_DIX_CONFIG_H
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include <dix-config.h>
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include <stdlib.h>
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include <X11/X.h>
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "scrnintstr.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "windowstr.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include <X11/fonts/font.h>
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "dixfontstr.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include <X11/fonts/fontstruct.h>
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "mi.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "regionstr.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "globals.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "gcstruct.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "shadow.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "fb.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define DANDEBUG 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#if ROTATE == 270
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SCRLEFT(x,y,w,h) (pScreen->height - ((y) + (h)))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SCRY(x,y,w,h) (x)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SCRWIDTH(x,y,w,h) (h)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define FIRSTSHA(x,y,w,h) (((y) + (h) - 1) * shaStride + (x))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define STEPDOWN(x,y,w,h) ((w)--)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define NEXTY(x,y,w,h) ((x)++)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SHASTEPX(stride) -(stride)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SHASTEPY(stride) (1)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#elif ROTATE == 90
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SCRLEFT(x,y,w,h) (y)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SCRY(x,y,w,h) (pScreen->width - ((x) + (w)) - 1)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SCRWIDTH(x,y,w,h) (h)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define FIRSTSHA(x,y,w,h) ((y) * shaStride + (x + w - 1))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define STEPDOWN(x,y,w,h) ((w)--)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define NEXTY(x,y,w,h) ((void)(x))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SHASTEPX(stride) (stride)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SHASTEPY(stride) (-1)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#elif ROTATE == 180
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SCRLEFT(x,y,w,h) (pScreen->width - ((x) + (w)))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SCRY(x,y,w,h) (pScreen->height - ((y) + (h)) - 1)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SCRWIDTH(x,y,w,h) (w)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define FIRSTSHA(x,y,w,h) ((y + h - 1) * shaStride + (x + w - 1))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define STEPDOWN(x,y,w,h) ((h)--)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define NEXTY(x,y,w,h) ((void)(y))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SHASTEPX(stride) (-1)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SHASTEPY(stride) -(stride)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#else
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SCRLEFT(x,y,w,h) (x)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SCRY(x,y,w,h) (y)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SCRWIDTH(x,y,w,h) (w)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define FIRSTSHA(x,y,w,h) ((y) * shaStride + (x))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define STEPDOWN(x,y,w,h) ((h)--)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define NEXTY(x,y,w,h) ((y)++)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SHASTEPX(stride) (1)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SHASTEPY(stride) (stride)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncvoid
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncFUNC (ScreenPtr pScreen,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync shadowBufPtr pBuf)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync{
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RegionPtr damage = shadowDamage (pBuf);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync PixmapPtr pShadow = pBuf->pPixmap;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync int nbox = RegionNumRects (damage);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync BoxPtr pbox = RegionRects (damage);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync FbBits *shaBits;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync Data *shaBase, *shaLine, *sha;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync FbStride shaStride;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync int scrBase, scrLine, scr;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync int shaBpp;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync _X_UNUSED int shaXoff, shaYoff;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync int x, y, w, h, width;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync int i;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync Data *winBase = NULL, *win;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync CARD32 winSize;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync fbGetDrawable (&pShadow->drawable, shaBits, shaStride, shaBpp, shaXoff, shaYoff);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync shaBase = (Data *) shaBits;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync shaStride = shaStride * sizeof (FbBits) / sizeof (Data);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#if (DANDEBUG > 1)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ErrorF ("-> Entering Shadow Update:\r\n |- Origins: pShadow=%x, pScreen=%x, damage=%x\r\n |- Metrics: shaStride=%d, shaBase=%x, shaBpp=%d\r\n | \n", pShadow, pScreen, damage, shaStride, shaBase, shaBpp);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync while (nbox--)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync x = pbox->x1;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync y = pbox->y1;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync w = (pbox->x2 - pbox->x1);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync h = pbox->y2 - pbox->y1;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#if (DANDEBUG > 2)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ErrorF (" |-> Redrawing box - Metrics: X=%d, Y=%d, Width=%d, Height=%d\n", x, y, w, h);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync scrLine = SCRLEFT(x,y,w,h);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync shaLine = shaBase + FIRSTSHA(x,y,w,h);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync while (STEPDOWN(x,y,w,h))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync winSize = 0;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync scrBase = 0;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync width = SCRWIDTH(x,y,w,h);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync scr = scrLine;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync sha = shaLine;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#if (DANDEBUG > 3)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ErrorF (" | |-> StepDown - Metrics: width=%d, scr=%x, sha=%x\n", width, scr, sha);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync while (width)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* how much remains in this window */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync i = scrBase + winSize - scr;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (i <= 0 || scr < scrBase)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync winBase = (Data *) (*pBuf->window) (pScreen,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync SCRY(x,y,w,h),
f78b12e570284aa8291f4ca1add24937fd107403vboxsync scr * sizeof (Data),
f78b12e570284aa8291f4ca1add24937fd107403vboxsync SHADOW_WINDOW_WRITE,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync &winSize,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync pBuf->closure);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if(!winBase)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync scrBase = scr;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync winSize /= sizeof (Data);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync i = winSize;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#if(DANDEBUG > 4)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ErrorF (" | | |-> Starting New Line - Metrics: winBase=%x, scrBase=%x, winSize=%d\r\n | | | Xstride=%d, Ystride=%d, w=%d h=%d\n", winBase, scrBase, winSize, SHASTEPX(shaStride), SHASTEPY(shaStride), w, h);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync win = winBase + (scr - scrBase);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (i > width)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync i = width;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync width -= i;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync scr += i;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#if(DANDEBUG > 5)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ErrorF (" | | |-> Writing Line - Metrics: win=%x, sha=%x\n", win, sha);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync while (i--)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#if(DANDEBUG > 6)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ErrorF (" | | |-> Writing Pixel - Metrics: win=%x, sha=%d, remaining=%d\n", win, sha, i);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync *win++ = *sha;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync sha += SHASTEPX(shaStride);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync } /* i */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync } /* width */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync shaLine += SHASTEPY(shaStride);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync NEXTY(x,y,w,h);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync } /* STEPDOWN */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync pbox++;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync } /* nbox */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync}