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 16 4-bit pixels, stored in 2 32-bit words
49      *  containing
50      *    - 16 4-bit chunky pixels on input
51      *    - permutated planar data (2 planes per 32-bit word) on output
52      */
53 
c2p_16x4(CARD32 d[2])54 static void c2p_16x4(CARD32 d[2])
55 {
56     transp2(d, 8);
57     transp2(d, 2);
58     transp2x(d, 1);
59     transp2(d, 16);
60     transp2(d, 4);
61     transp2(d, 1);
62 }
63 
64 
65     /*
66      *  Store a full block of iplan2p4 data after c2p conversion
67      */
68 
store_iplan2p4(void * dst,const CARD32 d[2])69 static inline void store_iplan2p4(void *dst, const CARD32 d[2])
70 {
71     CARD32 *p = dst;
72 
73     *p++ = d[0];
74     *p++ = d[1];
75 }
76 
77 
78 void
shadowUpdateIplan2p4(ScreenPtr pScreen,shadowBufPtr pBuf)79 shadowUpdateIplan2p4(ScreenPtr pScreen, shadowBufPtr pBuf)
80 {
81     RegionPtr damage = DamageRegion(pBuf->pDamage);
82     PixmapPtr pShadow = pBuf->pPixmap;
83     int nbox = RegionNumRects(damage);
84     BoxPtr pbox = RegionRects(damage);
85     FbBits *shaBase;
86     CARD16 *shaLine, *sha;
87     FbStride shaStride;
88     int scrLine;
89     _X_UNUSED int shaBpp, shaXoff, shaYoff;
90     int x, y, w, h;
91     int i, n;
92     CARD16 *win;
93     _X_UNUSED CARD32 winSize;
94     union {
95         CARD8 bytes[8];
96         CARD32 words[2];
97     } d;
98 
99     fbGetDrawable(&pShadow->drawable, shaBase, shaStride, shaBpp, shaXoff,
100                   shaYoff);
101     shaStride *= sizeof(FbBits) / sizeof(CARD16);
102 
103     while (nbox--) {
104         x = pbox->x1;
105         y = pbox->y1;
106         w = pbox->x2 - pbox->x1;
107         h = pbox->y2 - pbox->y1;
108 
109         scrLine = (x & -16) / 2;
110         shaLine = (CARD16 *)shaBase + y * shaStride + scrLine / sizeof(CARD16);
111 
112         n = ((x & 15) + w + 15) / 16;   /* number of c2p units in scanline */
113 
114         while (h--) {
115             sha = shaLine;
116             win = (CARD16 *) (*pBuf->window) (pScreen,
117                                               y,
118                                               scrLine,
119                                               SHADOW_WINDOW_WRITE,
120                                               &winSize,
121                                               pBuf->closure);
122             if (!win)
123                 return;
124             for (i = 0; i < n; i++) {
125                 memcpy(d.bytes, sha, sizeof(d.bytes));
126                 c2p_16x4(d.words);
127                 store_iplan2p4(win, d.words);
128                 sha += sizeof(d.bytes) / sizeof(*sha);
129                 win += sizeof(d.bytes) / sizeof(*win);
130             }
131             shaLine += shaStride;
132             y++;
133         }
134         pbox++;
135     }
136 }
137