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