xref: /OK3568_Linux_fs/external/xserver/miext/shadow/shafb8.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *  Copyright © 2013 Geert Uytterhoeven
3  *
4  *  Permission is hereby granted, free of charge, to any person obtaining a
5  *  copy of this software and associated documentation files (the "Software"),
6  *  to deal in the Software without restriction, including without limitation
7  *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  *  and/or sell copies of the Software, and to permit persons to whom the
9  *  Software is furnished to do so, subject to the following conditions:
10  *
11  *  The above copyright notice and this permission notice (including the next
12  *  paragraph) shall be included in all copies or substantial portions of the
13  *  Software.
14  *
15  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  *  DEALINGS IN THE SOFTWARE.
22  *
23  *  Based on shpacked.c, which is Copyright © 2000 Keith Packard
24  */
25 
26 #ifdef HAVE_DIX_CONFIG_H
27 #include <dix-config.h>
28 #endif
29 
30 #include <stdlib.h>
31 
32 #include    <X11/X.h>
33 #include    "scrnintstr.h"
34 #include    "windowstr.h"
35 #include    <X11/fonts/font.h>
36 #include    "dixfontstr.h"
37 #include    <X11/fonts/fontstruct.h>
38 #include    "mi.h"
39 #include    "regionstr.h"
40 #include    "globals.h"
41 #include    "gcstruct.h"
42 #include    "shadow.h"
43 #include    "fb.h"
44 #include    "c2p_core.h"
45 
46 
47     /*
48      *  Perform a full C2P step on 32 8-bit pixels, stored in 8 32-bit words
49      *  containing
50      *    - 32 8-bit chunky pixels on input
51      *    - permutated planar data (1 plane per 32-bit word) on output
52      */
53 
c2p_32x8(CARD32 d[8])54 static void c2p_32x8(CARD32 d[8])
55 {
56     transp8(d, 16, 4);
57     transp8(d, 8, 2);
58     transp8(d, 4, 1);
59     transp8(d, 2, 4);
60     transp8(d, 1, 2);
61 }
62 
63 
64     /*
65      *  Store a full block of permutated planar data after c2p conversion
66      */
67 
store_afb8(void * dst,unsigned int stride,const CARD32 d[8])68 static inline void store_afb8(void *dst, unsigned int stride,
69                               const CARD32 d[8])
70 {
71     CARD8 *p = dst;
72 
73     *(CARD32 *)p = d[7]; p += stride;
74     *(CARD32 *)p = d[5]; p += stride;
75     *(CARD32 *)p = d[3]; p += stride;
76     *(CARD32 *)p = d[1]; p += stride;
77     *(CARD32 *)p = d[6]; p += stride;
78     *(CARD32 *)p = d[4]; p += stride;
79     *(CARD32 *)p = d[2]; p += stride;
80     *(CARD32 *)p = d[0]; p += stride;
81 }
82 
83 
84 void
shadowUpdateAfb8(ScreenPtr pScreen,shadowBufPtr pBuf)85 shadowUpdateAfb8(ScreenPtr pScreen, shadowBufPtr pBuf)
86 {
87     RegionPtr damage = DamageRegion(pBuf->pDamage);
88     PixmapPtr pShadow = pBuf->pPixmap;
89     int nbox = RegionNumRects(damage);
90     BoxPtr pbox = RegionRects(damage);
91     FbBits *shaBase;
92     CARD32 *shaLine, *sha;
93     FbStride shaStride;
94     int scrLine;
95     _X_UNUSED int shaBpp, shaXoff, shaYoff;
96     int x, y, w, h;
97     int i, n;
98     CARD32 *win;
99     CARD32 off, winStride;
100     union {
101         CARD8 bytes[32];
102         CARD32 words[8];
103     } d;
104 
105     fbGetDrawable(&pShadow->drawable, shaBase, shaStride, shaBpp, shaXoff,
106                   shaYoff);
107     if (sizeof(FbBits) != sizeof(CARD32))
108         shaStride = shaStride * sizeof(FbBits) / sizeof(CARD32);
109 
110     while (nbox--) {
111         x = pbox->x1;
112         y = pbox->y1;
113         w = pbox->x2 - pbox->x1;
114         h = pbox->y2 - pbox->y1;
115 
116         scrLine = x & -32;
117         shaLine = (CARD32 *)shaBase + y * shaStride + scrLine / sizeof(CARD32);
118 
119         off = scrLine / 8;              /* byte offset in bitplane scanline */
120         n = ((x & 31) + w + 31) / 32;   /* number of c2p units in scanline */
121 
122         while (h--) {
123             sha = shaLine;
124             win = (CARD32 *) (*pBuf->window) (pScreen,
125                                               y,
126                                               off,
127                                               SHADOW_WINDOW_WRITE,
128                                               &winStride,
129                                               pBuf->closure);
130             if (!win)
131                 return;
132             for (i = 0; i < n; i++) {
133                 memcpy(d.bytes, sha, sizeof(d.bytes));
134                 c2p_32x8(d.words);
135                 store_afb8(win++, winStride, d.words);
136                 sha += sizeof(d.bytes) / sizeof(*sha);
137             }
138             shaLine += shaStride;
139             y++;
140         }
141         pbox++;
142     }
143 }
144