First import
[xorg_rtime.git] / xorg-server-1.4 / hw / kdrive / src / kshadow.c
blobea44812dbaa47a263ac67b79d7c434a705613ccb
1 /*
2 * Copyright © 1999 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Keith Packard makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
23 #ifdef HAVE_CONFIG_H
24 #include <kdrive-config.h>
25 #endif
26 #include "kdrive.h"
28 Bool
29 KdShadowFbAlloc (KdScreenInfo *screen, int fb, Bool rotate)
31 int paddedWidth;
32 void *buf;
33 int width = rotate ? screen->height : screen->width;
34 int height = rotate ? screen->width : screen->height;
35 int bpp = screen->fb[fb].bitsPerPixel;
37 /* use fb computation for width */
38 paddedWidth = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof (FbBits);
39 buf = xalloc (paddedWidth * height);
40 if (!buf)
41 return FALSE;
42 if (screen->fb[fb].shadow)
43 xfree (screen->fb[fb].frameBuffer);
44 screen->fb[fb].shadow = TRUE;
45 screen->fb[fb].frameBuffer = buf;
46 screen->fb[fb].byteStride = paddedWidth;
47 screen->fb[fb].pixelStride = paddedWidth * 8 / bpp;
48 return TRUE;
51 void
52 KdShadowFbFree (KdScreenInfo *screen, int fb)
54 if (screen->fb[fb].shadow)
56 xfree (screen->fb[fb].frameBuffer);
57 screen->fb[fb].frameBuffer = 0;
58 screen->fb[fb].shadow = FALSE;
62 Bool
63 KdShadowSet (ScreenPtr pScreen, int randr, ShadowUpdateProc update, ShadowWindowProc window)
65 KdScreenPriv(pScreen);
66 KdScreenInfo *screen = pScreenPriv->screen;
67 int fb;
69 shadowRemove (pScreen, pScreen->GetScreenPixmap(pScreen));
70 for (fb = 0; fb < KD_MAX_FB && screen->fb[fb].depth; fb++)
72 if (screen->fb[fb].shadow)
73 return shadowAdd (pScreen, pScreen->GetScreenPixmap(pScreen),
74 update, window, randr, 0);
76 return TRUE;
79 void
80 KdShadowUnset (ScreenPtr pScreen)
82 shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen));