105b261ecSmrg/*
235c4bbdfSmrg * Copyright © 1999 Keith Packard
305b261ecSmrg *
405b261ecSmrg * Permission to use, copy, modify, distribute, and sell this software and its
505b261ecSmrg * documentation for any purpose is hereby granted without fee, provided that
605b261ecSmrg * the above copyright notice appear in all copies and that both that
705b261ecSmrg * copyright notice and this permission notice appear in supporting
805b261ecSmrg * documentation, and that the name of Keith Packard not be used in
905b261ecSmrg * advertising or publicity pertaining to distribution of the software without
1005b261ecSmrg * specific, written prior permission.  Keith Packard makes no
1105b261ecSmrg * representations about the suitability of this software for any purpose.  It
1205b261ecSmrg * is provided "as is" without express or implied warranty.
1305b261ecSmrg *
1405b261ecSmrg * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1505b261ecSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1605b261ecSmrg * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1705b261ecSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1805b261ecSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1905b261ecSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2005b261ecSmrg * PERFORMANCE OF THIS SOFTWARE.
2105b261ecSmrg */
2205b261ecSmrg
231b5d61b8Smrg#ifdef HAVE_DIX_CONFIG_H
241b5d61b8Smrg#include <dix-config.h>
2505b261ecSmrg#endif
2605b261ecSmrg#include "kdrive.h"
2705b261ecSmrg
2805b261ecSmrgBool
2935c4bbdfSmrgKdShadowFbAlloc(KdScreenInfo * screen, Bool rotate)
3005b261ecSmrg{
3135c4bbdfSmrg    int paddedWidth;
3235c4bbdfSmrg    void *buf;
3335c4bbdfSmrg    int width = rotate ? screen->height : screen->width;
3435c4bbdfSmrg    int height = rotate ? screen->width : screen->height;
3535c4bbdfSmrg    int bpp = screen->fb.bitsPerPixel;
3605b261ecSmrg
3705b261ecSmrg    /* use fb computation for width */
3835c4bbdfSmrg    paddedWidth = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof(FbBits);
3935c4bbdfSmrg    buf = xallocarray(paddedWidth, height);
4005b261ecSmrg    if (!buf)
4135c4bbdfSmrg        return FALSE;
426747b715Smrg    if (screen->fb.shadow)
4335c4bbdfSmrg        free(screen->fb.frameBuffer);
446747b715Smrg    screen->fb.shadow = TRUE;
456747b715Smrg    screen->fb.frameBuffer = buf;
466747b715Smrg    screen->fb.byteStride = paddedWidth;
476747b715Smrg    screen->fb.pixelStride = paddedWidth * 8 / bpp;
4805b261ecSmrg    return TRUE;
4905b261ecSmrg}
5005b261ecSmrg
5105b261ecSmrgvoid
5235c4bbdfSmrgKdShadowFbFree(KdScreenInfo * screen)
5305b261ecSmrg{
5435c4bbdfSmrg    if (screen->fb.shadow) {
5535c4bbdfSmrg        free(screen->fb.frameBuffer);
5635c4bbdfSmrg        screen->fb.frameBuffer = 0;
5735c4bbdfSmrg        screen->fb.shadow = FALSE;
5805b261ecSmrg    }
5905b261ecSmrg}
6005b261ecSmrg
6105b261ecSmrgBool
6235c4bbdfSmrgKdShadowSet(ScreenPtr pScreen, int randr, ShadowUpdateProc update,
6335c4bbdfSmrg            ShadowWindowProc window)
6405b261ecSmrg{
6505b261ecSmrg    KdScreenPriv(pScreen);
6605b261ecSmrg    KdScreenInfo *screen = pScreenPriv->screen;
6705b261ecSmrg
6835c4bbdfSmrg    shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen));
6935c4bbdfSmrg    if (screen->fb.shadow) {
7035c4bbdfSmrg        return shadowAdd(pScreen, pScreen->GetScreenPixmap(pScreen),
7135c4bbdfSmrg                         update, window, randr, 0);
7205b261ecSmrg    }
7305b261ecSmrg    return TRUE;
7405b261ecSmrg}
7505b261ecSmrg
7605b261ecSmrgvoid
7735c4bbdfSmrgKdShadowUnset(ScreenPtr pScreen)
7805b261ecSmrg{
7905b261ecSmrg    shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen));
8005b261ecSmrg}
81