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