shafb4.c revision 01260a01
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 4-bit pixels, stored in 4 32-bit words 49 * containing 50 * - 32 4-bit chunky pixels on input 51 * - permutated planar data (1 plane per 32-bit word) on output 52 */ 53 54static void c2p_32x4(CARD32 d[4]) 55{ 56 transp4(d, 16, 2); 57 transp4(d, 8, 1); 58 transp4(d, 4, 2); 59 transp4(d, 2, 1); 60 transp4(d, 1, 2); 61} 62 63 64 /* 65 * Store a full block of permutated planar data after c2p conversion 66 */ 67 68static inline void store_afb4(void *dst, unsigned int stride, 69 const CARD32 d[4]) 70{ 71 CARD8 *p = dst; 72 73 *(CARD32 *)p = d[3]; p += stride; 74 *(CARD32 *)p = d[1]; p += stride; 75 *(CARD32 *)p = d[2]; p += stride; 76 *(CARD32 *)p = d[0]; p += stride; 77} 78 79 80void 81shadowUpdateAfb4(ScreenPtr pScreen, shadowBufPtr pBuf) 82{ 83 RegionPtr damage = DamageRegion(pBuf->pDamage); 84 PixmapPtr pShadow = pBuf->pPixmap; 85 int nbox = RegionNumRects(damage); 86 BoxPtr pbox = RegionRects(damage); 87 FbBits *shaBase; 88 CARD32 *shaLine, *sha; 89 FbStride shaStride; 90 int scrLine; 91 _X_UNUSED int shaBpp, shaXoff, shaYoff; 92 int x, y, w, h; 93 int i, n; 94 CARD32 *win; 95 CARD32 off, winStride; 96 union { 97 CARD8 bytes[16]; 98 CARD32 words[4]; 99 } d; 100 101 fbGetDrawable(&pShadow->drawable, shaBase, shaStride, shaBpp, shaXoff, 102 shaYoff); 103 if (sizeof(FbBits) != sizeof(CARD32)) 104 shaStride = shaStride * sizeof(FbBits) / sizeof(CARD32); 105 106 while (nbox--) { 107 x = pbox->x1; 108 y = pbox->y1; 109 w = pbox->x2 - pbox->x1; 110 h = pbox->y2 - pbox->y1; 111 112 scrLine = (x & -32) / 2; 113 shaLine = (CARD32 *)shaBase + y * shaStride + scrLine / sizeof(CARD32); 114 115 off = scrLine / 4; /* byte offset in bitplane scanline */ 116 n = ((x & 31) + w + 31) / 32; /* number of c2p units in scanline */ 117 118 while (h--) { 119 sha = shaLine; 120 win = (CARD32 *) (*pBuf->window) (pScreen, 121 y, 122 off, 123 SHADOW_WINDOW_WRITE, 124 &winStride, 125 pBuf->closure); 126 if (!win) 127 return; 128 for (i = 0; i < n; i++) { 129 memcpy(d.bytes, sha, sizeof(d.bytes)); 130 c2p_32x4(d.words); 131 store_afb4(win++, winStride, d.words); 132 sha += sizeof(d.bytes) / sizeof(*sha); 133 } 134 shaLine += shaStride; 135 y++; 136 } 137 pbox++; 138 } 139} 140 141 /* 142 * Like above, except input is 8-bit chunky pixels (upper 4 bits zero) 143 */ 144void 145shadowUpdateAfb4x8(ScreenPtr pScreen, shadowBufPtr pBuf) 146{ 147 RegionPtr damage = DamageRegion(pBuf->pDamage); 148 PixmapPtr pShadow = pBuf->pPixmap; 149 int nbox = RegionNumRects(damage); 150 BoxPtr pbox = RegionRects(damage); 151 FbBits *shaBase; 152 CARD32 *shaLine, *sha; 153 FbStride shaStride; 154 int scrLine; 155 _X_UNUSED int shaBpp, shaXoff, shaYoff; 156 int x, y, w, h; 157 int i, n; 158 CARD32 *win; 159 CARD32 off, winStride; 160 CARD32 dwords[4]; 161 162 fbGetDrawable(&pShadow->drawable, shaBase, shaStride, shaBpp, shaXoff, 163 shaYoff); 164 if (sizeof(FbBits) != sizeof(CARD32)) 165 shaStride = shaStride * sizeof(FbBits) / sizeof(CARD32); 166 167 while (nbox--) { 168 x = pbox->x1; 169 y = pbox->y1; 170 w = pbox->x2 - pbox->x1; 171 h = pbox->y2 - pbox->y1; 172 173 scrLine = x & -32; 174 shaLine = (CARD32 *)shaBase + y * shaStride + scrLine / sizeof(CARD32); 175 176 off = scrLine / 8; /* byte offset in bitplane scanline */ 177 n = ((x & 31) + w + 31) / 32; /* number of c2p units in scanline */ 178 179 while (h--) { 180 sha = shaLine; 181 win = (CARD32 *) (*pBuf->window) (pScreen, 182 y, 183 off, 184 SHADOW_WINDOW_WRITE, 185 &winStride, 186 pBuf->closure); 187 if (!win) 188 return; 189 for (i = 0; i < n; i++) { 190 dwords[0] = (sha[0] << 4) | sha[1]; 191 dwords[2] = (sha[2] << 4) | sha[3]; 192 dwords[1] = (sha[4] << 4) | sha[5]; 193 dwords[3] = (sha[6] << 4) | sha[7]; 194 transp4(dwords, 16, 1); 195 transp4(dwords, 8, 2); 196 transp4(dwords, 2, 1); 197 transp4(dwords, 1, 2); 198 store_afb4(win++, winStride, dwords); 199 sha += 8; 200 } 201 shaLine += shaStride; 202 y++; 203 } 204 pbox++; 205 } 206} 207