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