135c4bbdfSmrg/* 235c4bbdfSmrg * Copyright © 2013 Geert Uytterhoeven 335c4bbdfSmrg * 435c4bbdfSmrg * Permission is hereby granted, free of charge, to any person obtaining a 535c4bbdfSmrg * copy of this software and associated documentation files (the "Software"), 635c4bbdfSmrg * to deal in the Software without restriction, including without limitation 735c4bbdfSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 835c4bbdfSmrg * and/or sell copies of the Software, and to permit persons to whom the 935c4bbdfSmrg * Software is furnished to do so, subject to the following conditions: 1035c4bbdfSmrg * 1135c4bbdfSmrg * The above copyright notice and this permission notice (including the next 1235c4bbdfSmrg * paragraph) shall be included in all copies or substantial portions of the 1335c4bbdfSmrg * Software. 1435c4bbdfSmrg * 1535c4bbdfSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1635c4bbdfSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1735c4bbdfSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1835c4bbdfSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1935c4bbdfSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2035c4bbdfSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 2135c4bbdfSmrg * DEALINGS IN THE SOFTWARE. 2235c4bbdfSmrg * 2335c4bbdfSmrg * Based on shpacked.c, which is Copyright © 2000 Keith Packard 2435c4bbdfSmrg */ 2535c4bbdfSmrg 2635c4bbdfSmrg#ifdef HAVE_DIX_CONFIG_H 2735c4bbdfSmrg#include <dix-config.h> 2835c4bbdfSmrg#endif 2935c4bbdfSmrg 3035c4bbdfSmrg#include <stdlib.h> 3135c4bbdfSmrg 3235c4bbdfSmrg#include <X11/X.h> 3335c4bbdfSmrg#include "scrnintstr.h" 3435c4bbdfSmrg#include "windowstr.h" 3535c4bbdfSmrg#include <X11/fonts/font.h> 3635c4bbdfSmrg#include "dixfontstr.h" 3735c4bbdfSmrg#include <X11/fonts/fontstruct.h> 3835c4bbdfSmrg#include "mi.h" 3935c4bbdfSmrg#include "regionstr.h" 4035c4bbdfSmrg#include "globals.h" 4135c4bbdfSmrg#include "gcstruct.h" 4235c4bbdfSmrg#include "shadow.h" 4335c4bbdfSmrg#include "fb.h" 4435c4bbdfSmrg#include "c2p_core.h" 4535c4bbdfSmrg 4635c4bbdfSmrg 4735c4bbdfSmrg /* 4835c4bbdfSmrg * Perform a full C2P step on 32 8-bit pixels, stored in 8 32-bit words 4935c4bbdfSmrg * containing 5035c4bbdfSmrg * - 32 8-bit chunky pixels on input 5135c4bbdfSmrg * - permutated planar data (1 plane per 32-bit word) on output 5235c4bbdfSmrg */ 5335c4bbdfSmrg 5435c4bbdfSmrgstatic void c2p_32x8(CARD32 d[8]) 5535c4bbdfSmrg{ 5635c4bbdfSmrg transp8(d, 16, 4); 5735c4bbdfSmrg transp8(d, 8, 2); 5835c4bbdfSmrg transp8(d, 4, 1); 5935c4bbdfSmrg transp8(d, 2, 4); 6035c4bbdfSmrg transp8(d, 1, 2); 6135c4bbdfSmrg} 6235c4bbdfSmrg 6335c4bbdfSmrg 6435c4bbdfSmrg /* 6535c4bbdfSmrg * Store a full block of permutated planar data after c2p conversion 6635c4bbdfSmrg */ 6735c4bbdfSmrg 6835c4bbdfSmrgstatic inline void store_afb8(void *dst, unsigned int stride, 6935c4bbdfSmrg const CARD32 d[8]) 7035c4bbdfSmrg{ 7135c4bbdfSmrg CARD8 *p = dst; 7235c4bbdfSmrg 7335c4bbdfSmrg *(CARD32 *)p = d[7]; p += stride; 7435c4bbdfSmrg *(CARD32 *)p = d[5]; p += stride; 7535c4bbdfSmrg *(CARD32 *)p = d[3]; p += stride; 7635c4bbdfSmrg *(CARD32 *)p = d[1]; p += stride; 7735c4bbdfSmrg *(CARD32 *)p = d[6]; p += stride; 7835c4bbdfSmrg *(CARD32 *)p = d[4]; p += stride; 7935c4bbdfSmrg *(CARD32 *)p = d[2]; p += stride; 8035c4bbdfSmrg *(CARD32 *)p = d[0]; p += stride; 8135c4bbdfSmrg} 8235c4bbdfSmrg 8335c4bbdfSmrg 8435c4bbdfSmrgvoid 8535c4bbdfSmrgshadowUpdateAfb8(ScreenPtr pScreen, shadowBufPtr pBuf) 8635c4bbdfSmrg{ 871b5d61b8Smrg RegionPtr damage = DamageRegion(pBuf->pDamage); 8835c4bbdfSmrg PixmapPtr pShadow = pBuf->pPixmap; 8935c4bbdfSmrg int nbox = RegionNumRects(damage); 9035c4bbdfSmrg BoxPtr pbox = RegionRects(damage); 9135c4bbdfSmrg FbBits *shaBase; 9235c4bbdfSmrg CARD32 *shaLine, *sha; 9335c4bbdfSmrg FbStride shaStride; 9435c4bbdfSmrg int scrLine; 9535c4bbdfSmrg _X_UNUSED int shaBpp, shaXoff, shaYoff; 9635c4bbdfSmrg int x, y, w, h; 9735c4bbdfSmrg int i, n; 9835c4bbdfSmrg CARD32 *win; 9935c4bbdfSmrg CARD32 off, winStride; 10035c4bbdfSmrg union { 10135c4bbdfSmrg CARD8 bytes[32]; 10235c4bbdfSmrg CARD32 words[8]; 10335c4bbdfSmrg } d; 10435c4bbdfSmrg 10535c4bbdfSmrg fbGetDrawable(&pShadow->drawable, shaBase, shaStride, shaBpp, shaXoff, 10635c4bbdfSmrg shaYoff); 10735c4bbdfSmrg if (sizeof(FbBits) != sizeof(CARD32)) 10835c4bbdfSmrg shaStride = shaStride * sizeof(FbBits) / sizeof(CARD32); 10935c4bbdfSmrg 11035c4bbdfSmrg while (nbox--) { 11135c4bbdfSmrg x = pbox->x1; 11235c4bbdfSmrg y = pbox->y1; 11335c4bbdfSmrg w = pbox->x2 - pbox->x1; 11435c4bbdfSmrg h = pbox->y2 - pbox->y1; 11535c4bbdfSmrg 11635c4bbdfSmrg scrLine = x & -32; 11735c4bbdfSmrg shaLine = (CARD32 *)shaBase + y * shaStride + scrLine / sizeof(CARD32); 11835c4bbdfSmrg 11935c4bbdfSmrg off = scrLine / 8; /* byte offset in bitplane scanline */ 12035c4bbdfSmrg n = ((x & 31) + w + 31) / 32; /* number of c2p units in scanline */ 12135c4bbdfSmrg 12235c4bbdfSmrg while (h--) { 12335c4bbdfSmrg sha = shaLine; 12435c4bbdfSmrg win = (CARD32 *) (*pBuf->window) (pScreen, 12535c4bbdfSmrg y, 12635c4bbdfSmrg off, 12735c4bbdfSmrg SHADOW_WINDOW_WRITE, 12835c4bbdfSmrg &winStride, 12935c4bbdfSmrg pBuf->closure); 13035c4bbdfSmrg if (!win) 13135c4bbdfSmrg return; 13235c4bbdfSmrg for (i = 0; i < n; i++) { 13335c4bbdfSmrg memcpy(d.bytes, sha, sizeof(d.bytes)); 13435c4bbdfSmrg c2p_32x8(d.words); 13535c4bbdfSmrg store_afb8(win++, winStride, d.words); 13635c4bbdfSmrg sha += sizeof(d.bytes) / sizeof(*sha); 13735c4bbdfSmrg } 13835c4bbdfSmrg shaLine += shaStride; 13935c4bbdfSmrg y++; 14035c4bbdfSmrg } 14135c4bbdfSmrg pbox++; 14235c4bbdfSmrg } 14335c4bbdfSmrg} 144