shplanar.c revision 1b5d61b8
105b261ecSmrg/*
205b261ecSmrg *
305b261ecSmrg * Copyright © 2000 Keith Packard
405b261ecSmrg *
505b261ecSmrg * Permission to use, copy, modify, distribute, and sell this software and its
605b261ecSmrg * documentation for any purpose is hereby granted without fee, provided that
705b261ecSmrg * the above copyright notice appear in all copies and that both that
805b261ecSmrg * copyright notice and this permission notice appear in supporting
905b261ecSmrg * documentation, and that the name of Keith Packard not be used in
1005b261ecSmrg * advertising or publicity pertaining to distribution of the software without
1105b261ecSmrg * specific, written prior permission.  Keith Packard makes no
1205b261ecSmrg * representations about the suitability of this software for any purpose.  It
1305b261ecSmrg * is provided "as is" without express or implied warranty.
1405b261ecSmrg *
1505b261ecSmrg * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1605b261ecSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1705b261ecSmrg * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1805b261ecSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1905b261ecSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
2005b261ecSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2105b261ecSmrg * PERFORMANCE OF THIS SOFTWARE.
2205b261ecSmrg */
2305b261ecSmrg
2405b261ecSmrg#ifdef HAVE_DIX_CONFIG_H
2505b261ecSmrg#include <dix-config.h>
2605b261ecSmrg#endif
2705b261ecSmrg
2805b261ecSmrg#include <stdlib.h>
2905b261ecSmrg
3005b261ecSmrg#include    <X11/X.h>
3105b261ecSmrg#include    "scrnintstr.h"
3205b261ecSmrg#include    "windowstr.h"
3305b261ecSmrg#include    <X11/fonts/font.h>
3405b261ecSmrg#include    "dixfontstr.h"
3505b261ecSmrg#include    <X11/fonts/fontstruct.h>
3605b261ecSmrg#include    "mi.h"
3705b261ecSmrg#include    "regionstr.h"
3805b261ecSmrg#include    "globals.h"
3905b261ecSmrg#include    "gcstruct.h"
4005b261ecSmrg#include    "shadow.h"
4105b261ecSmrg#include    "fb.h"
4205b261ecSmrg
4305b261ecSmrg/*
4405b261ecSmrg * 32 4-bit pixels per write
4505b261ecSmrg */
4605b261ecSmrg
4735c4bbdfSmrg#define PL_SHIFT    7
4805b261ecSmrg#define PL_UNIT	    (1 << PL_SHIFT)
4905b261ecSmrg#define PL_MASK	    (PL_UNIT - 1)
5005b261ecSmrg
5105b261ecSmrg/*
5205b261ecSmrg *  32->8 conversion:
5305b261ecSmrg *
5405b261ecSmrg *      7 6 5 4 3 2 1 0
5505b261ecSmrg *      A B C D E F G H
5605b261ecSmrg *
5705b261ecSmrg *      3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
5805b261ecSmrg *      1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
5905b261ecSmrg * m    . . . H . . . G . . . F . . . E . . . D . . . C . . . B . . . A
6005b261ecSmrg * m1   G . . . F . . . E . . . D . . . C . . . B . . . A . . . . . . .	    m << (7 - (p))
6105b261ecSmrg * m2   . H . . . G . . . F . . . E . . . D . . . C . . . B . . . A . .	    (m >> (p)) << 2
6205b261ecSmrg * m3   G               E               C               A                   m1 & 0x80808080
6305b261ecSmrg * m4     H               F               D               B                 m2 & 0x40404040
6405b261ecSmrg * m5   G H             E F             C D             A B                 m3 | m4
6505b261ecSmrg * m6   G H             E F             C D     G H     A B     E F         m5 | (m5 >> 20)
6605b261ecSmrg * m7   G H             E F             C D     G H     A B C D E F G H     m6 | (m6 >> 10)
6705b261ecSmrg */
6805b261ecSmrg
6905b261ecSmrg#if 0
7005b261ecSmrg#define GetBits(p,o,d) {\
7105b261ecSmrg    m = sha[o]; \
7205b261ecSmrg    m1 = m << (7 - (p)); \
7305b261ecSmrg    m2 = (m >> (p)) << 2; \
7405b261ecSmrg    m3 = m1 & 0x80808080; \
7505b261ecSmrg    m4 = m2 & 0x40404040; \
7605b261ecSmrg    m5 = m3 | m4; \
7705b261ecSmrg    m6 = m5 | (m5 >> 20); \
7805b261ecSmrg    d = m6 | (m6 >> 10); \
7905b261ecSmrg}
8005b261ecSmrg#else
8105b261ecSmrg#define GetBits(p,o,d) {\
8205b261ecSmrg    m = sha[o]; \
8305b261ecSmrg    m5 = ((m << (7 - (p))) & 0x80808080) | (((m >> (p)) << 2) & 0x40404040); \
8405b261ecSmrg    m6 = m5 | (m5 >> 20); \
8505b261ecSmrg    d = m6 | (m6 >> 10); \
8605b261ecSmrg}
8705b261ecSmrg#endif
8805b261ecSmrg
8905b261ecSmrgvoid
9035c4bbdfSmrgshadowUpdatePlanar4(ScreenPtr pScreen, shadowBufPtr pBuf)
9105b261ecSmrg{
921b5d61b8Smrg    RegionPtr damage = DamageRegion(pBuf->pDamage);
9335c4bbdfSmrg    PixmapPtr pShadow = pBuf->pPixmap;
9435c4bbdfSmrg    int nbox = RegionNumRects(damage);
9535c4bbdfSmrg    BoxPtr pbox = RegionRects(damage);
9635c4bbdfSmrg    CARD32 *shaBase, *shaLine, *sha;
9735c4bbdfSmrg    FbStride shaStride;
9835c4bbdfSmrg    int scrBase, scrLine, scr;
9935c4bbdfSmrg    int shaBpp;
10035c4bbdfSmrg    _X_UNUSED int shaXoff, shaYoff;
10135c4bbdfSmrg    int x, y, w, h, width;
10235c4bbdfSmrg    int i;
10335c4bbdfSmrg    CARD32 *winBase = NULL, *win;
10435c4bbdfSmrg    CARD32 winSize;
10535c4bbdfSmrg    int plane;
10635c4bbdfSmrg    CARD32 m, m5, m6;
10735c4bbdfSmrg    CARD8 s1, s2, s3, s4;
10805b261ecSmrg
10935c4bbdfSmrg    fbGetStipDrawable(&pShadow->drawable, shaBase, shaStride, shaBpp, shaXoff,
11035c4bbdfSmrg                      shaYoff);
11135c4bbdfSmrg    while (nbox--) {
11235c4bbdfSmrg        x = (pbox->x1) * shaBpp;
11335c4bbdfSmrg        y = (pbox->y1);
11435c4bbdfSmrg        w = (pbox->x2 - pbox->x1) * shaBpp;
11535c4bbdfSmrg        h = pbox->y2 - pbox->y1;
11605b261ecSmrg
11735c4bbdfSmrg        w = (w + (x & PL_MASK) + PL_MASK) >> PL_SHIFT;
11835c4bbdfSmrg        x &= ~PL_MASK;
11935c4bbdfSmrg
12035c4bbdfSmrg        scrLine = (x >> PL_SHIFT);
12135c4bbdfSmrg        shaLine = shaBase + y * shaStride + (x >> FB_SHIFT);
12235c4bbdfSmrg
12335c4bbdfSmrg        while (h--) {
12435c4bbdfSmrg            for (plane = 0; plane < 4; plane++) {
12535c4bbdfSmrg                width = w;
12635c4bbdfSmrg                scr = scrLine;
12735c4bbdfSmrg                sha = shaLine;
12835c4bbdfSmrg                winSize = 0;
12935c4bbdfSmrg                scrBase = 0;
13035c4bbdfSmrg                while (width) {
13135c4bbdfSmrg                    /* how much remains in this window */
13235c4bbdfSmrg                    i = scrBase + winSize - scr;
13335c4bbdfSmrg                    if (i <= 0 || scr < scrBase) {
13435c4bbdfSmrg                        winBase = (CARD32 *) (*pBuf->window) (pScreen,
13535c4bbdfSmrg                                                              y,
13635c4bbdfSmrg                                                              (scr << 4) |
13735c4bbdfSmrg                                                              (plane),
13835c4bbdfSmrg                                                              SHADOW_WINDOW_WRITE,
13935c4bbdfSmrg                                                              &winSize,
14035c4bbdfSmrg                                                              pBuf->closure);
14135c4bbdfSmrg                        if (!winBase)
14235c4bbdfSmrg                            return;
14335c4bbdfSmrg                        winSize >>= 2;
14435c4bbdfSmrg                        scrBase = scr;
14535c4bbdfSmrg                        i = winSize;
14635c4bbdfSmrg                    }
14735c4bbdfSmrg                    win = winBase + (scr - scrBase);
14835c4bbdfSmrg                    if (i > width)
14935c4bbdfSmrg                        i = width;
15035c4bbdfSmrg                    width -= i;
15135c4bbdfSmrg                    scr += i;
15235c4bbdfSmrg
15335c4bbdfSmrg                    while (i--) {
15435c4bbdfSmrg                        GetBits(plane, 0, s1);
15535c4bbdfSmrg                        GetBits(plane, 1, s2);
15635c4bbdfSmrg                        GetBits(plane, 2, s3);
15735c4bbdfSmrg                        GetBits(plane, 3, s4);
15835c4bbdfSmrg                        *win++ = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24);
15935c4bbdfSmrg                        sha += 4;
16035c4bbdfSmrg                    }
16135c4bbdfSmrg                }
16235c4bbdfSmrg            }
16335c4bbdfSmrg            shaLine += shaStride;
16435c4bbdfSmrg            y++;
16535c4bbdfSmrg        }
16635c4bbdfSmrg        pbox++;
16705b261ecSmrg    }
16805b261ecSmrg}
169