1/*
2 *
3 * Copyright © 2000 Keith Packard
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of Keith Packard not be used in
10 * advertising or publicity pertaining to distribution of the software without
11 * specific, written prior permission.  Keith Packard makes no
12 * representations about the suitability of this software for any purpose.  It
13 * is provided "as is" without express or implied warranty.
14 *
15 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 * PERFORMANCE OF THIS SOFTWARE.
22 */
23
24#ifdef HAVE_DIX_CONFIG_H
25#include <dix-config.h>
26#endif
27
28#include <stdlib.h>
29
30#include    <X11/X.h>
31#include    "scrnintstr.h"
32#include    "windowstr.h"
33#include    <X11/fonts/font.h>
34#include    "dixfontstr.h"
35#include    <X11/fonts/fontstruct.h>
36#include    "mi.h"
37#include    "regionstr.h"
38#include    "globals.h"
39#include    "gcstruct.h"
40#include    "shadow.h"
41#include    "fb.h"
42
43/*
44 * Expose 8bpp depth 4
45 */
46
47/*
48 *  32->8 conversion:
49 *
50 *      7 6 5 4 3 2 1 0
51 *      A B C D E F G H
52 *
53 *      3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
54 *      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
55 * m1   D x x x x x x x C x x x x x x x B x x x x x x x A x x x x x x x     sha[0] << (7-(p))
56 * m2   x x x x H x x x x x x x G x x x x x x x F x x x x x x x E x x x     sha[1] << (3-(p))
57 * m3   D               C               B               A                   m1 & 0x80808080
58 * m4           H               G               F               E           m2 & 0x08080808
59 * m5   D       H       C       G       B       F       A       E	    m3 | m4
60 * m6                     D       H       C       G       B       F         m5 >> 9
61 * m7   D       H       C D     G H     B C     F G     A B     E F         m5 | m6
62 * m8                                       D       H       C D     G H     m7 >> 18
63 * m9   D       H       C D     G H     B C D   F G H   A B C D E F G H     m7 | m8
64 */
65
66#define PL_SHIFT    8
67#define PL_UNIT	    (1 << PL_SHIFT)
68#define PL_MASK	    (PL_UNIT - 1)
69
70#if 0
71#define GetBits(p,o,d) { \
72    CARD32	m1,m2,m3,m4,m5,m6,m7,m8; \
73    m1 = sha[o] << (7 - (p)); \
74    m2 = sha[(o)+1] << (3 - (p)); \
75    m3 = m1 & 0x80808080; \
76    m4 = m2 & 0x08080808; \
77    m5 = m3 | m4; \
78    m6 = m5 >> 9; \
79    m7 = m5 | m6; \
80    m8 = m7 >> 18; \
81    d = m7 | m8; \
82}
83#else
84#define GetBits(p,o,d) { \
85    CARD32	m5,m7; \
86    m5 = ((sha[o] << (7 - (p))) & 0x80808080) | ((sha[(o)+1] << (3 - (p))) & 0x08080808); \
87    m7 = m5 | (m5 >> 9); \
88    d = m7 | (m7 >> 18); \
89}
90#endif
91
92void
93shadowUpdatePlanar4x8 (ScreenPtr	pScreen,
94		       shadowBufPtr	pBuf)
95{
96    RegionPtr	damage = shadowDamage (pBuf);
97    PixmapPtr	pShadow = pBuf->pPixmap;
98    int		nbox = RegionNumRects (damage);
99    BoxPtr	pbox = RegionRects (damage);
100    CARD32	*shaBase, *shaLine, *sha;
101    CARD8	s1, s2, s3, s4;
102    FbStride	shaStride;
103    int		scrBase, scrLine, scr;
104    int		shaBpp;
105    int		shaXoff, shaYoff;   /* XXX assumed to be zero */
106    int		x, y, w, h, width;
107    int         i;
108    CARD32	*winBase = NULL, *win;
109    CARD32	winSize;
110    int		plane;
111
112    fbGetStipDrawable (&pShadow->drawable, shaBase, shaStride, shaBpp, shaXoff, shaYoff);
113    while (nbox--)
114    {
115	x = pbox->x1 * shaBpp;
116	y = pbox->y1;
117	w = (pbox->x2 - pbox->x1) * shaBpp;
118	h = pbox->y2 - pbox->y1;
119
120	w = (w + (x & PL_MASK) + PL_MASK) >> PL_SHIFT;
121	x &= ~PL_MASK;
122
123	scrLine = (x >> PL_SHIFT);
124	shaLine = shaBase + y * shaStride + (x >> FB_SHIFT);
125
126	while (h--)
127	{
128	    for (plane = 0; plane < 4; plane++)
129	    {
130		width = w;
131		scr = scrLine;
132		sha = shaLine;
133		winSize = 0;
134		scrBase = 0;
135		while (width) {
136		    /* how much remains in this window */
137		    i = scrBase + winSize - scr;
138		    if (i <= 0 || scr < scrBase)
139		    {
140			winBase = (CARD32 *) (*pBuf->window) (pScreen,
141							      y,
142							      (scr << 4) | (plane),
143							      SHADOW_WINDOW_WRITE,
144							      &winSize,
145							      pBuf->closure);
146			if(!winBase)
147			    return;
148			winSize >>= 2;
149			scrBase = scr;
150			i = winSize;
151		    }
152		    win = winBase + (scr - scrBase);
153		    if (i > width)
154		    i = width;
155		    width -= i;
156		    scr += i;
157
158		    while (i--)
159		    {
160			GetBits(plane,0,s1);
161			GetBits(plane,2,s2);
162			GetBits(plane,4,s3);
163			GetBits(plane,6,s4);
164			*win++ = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24);
165			sha += 8;
166		    }
167		}
168	    }
169	    shaLine += shaStride;
170	    y++;
171	}
172	pbox++;
173    }
174}
175
176