📄 cfbmskbits.h
字号:
/************************************************************Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA. All Rights ReservedPermission to use, copy, modify, and distribute thissoftware and its documentation for any purpose and withoutfee is hereby granted, provided that the above copyright no-tice appear in all copies and that both that copyright no-tice and this permission notice appear in supporting docu-mentation, and that the names of Sun or X Consortiumnot be used in advertising or publicity pertaining to distribution of the software without specific prior written permission. Sun and X Consortium make no representations about the suitability of this software for any purpose. It is provided "as is" without any express or implied warranty.SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI-ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA ORPROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OROTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITHTHE USE OR PERFORMANCE OF THIS SOFTWARE.********************************************************//* $XConsortium: cfbmskbits.h,v 4.25 94/04/17 20:28:55 dpw Exp $ *//* $XFree86: xc/programs/Xserver/cfb/cfbmskbits.h,v 3.3.2.1 1997/05/27 06:28:09 dawes Exp $ *//* Optimizations for PSZ == 32 added by Kyle Marvin (marvin@vitec.com) */#include "X.h"#include "Xmd.h"#include "servermd.h"#ifdef XFREE86#define NO_COMPILER_H_EXTRAS#include "compiler.h"#endif/* * ========================================================================== * Converted from mfb to support memory-mapped color framebuffer by smarks@sun, * April-May 1987. * * The way I did the conversion was to consider each longword as an * array of four bytes instead of an array of 32 one-bit pixels. So * getbits() and putbits() retain much the same calling sequence, but * they move bytes around instead of bits. Of course, this entails the * removal of all of the one-bit-pixel dependencies from the other * files, but the major bit-hacking stuff should be covered here. * * I've created some new macros that make it easier to understand what's * going on in the pixel calculations, and that make it easier to change the * pixel size. * * name explanation * ---- ----------- * PSZ pixel size (in bits) * PGSZ pixel group size (in bits) * PGSZB pixel group size (in bytes) * PGSZBMSK mask with lowest PGSZB bits set to 1 * PPW pixels per word (pixels per pixel group) * PPWMSK mask with lowest PPW bits set to 1 * PLST index of last pixel in a word (should be PPW-1) * PIM pixel index mask (index within a pixel group) * PWSH pixel-to-word shift (should be log2(PPW)) * PMSK mask with lowest PSZ bits set to 1 * * * Here are some sample values. In the notation cfbA,B: A is PSZ, and * B is PGSZB. All the other values are derived from these * two. This table does not show all combinations! * * name cfb8,4 cfb24,4 cfb32,4 cfb8,8 cfb24,8 cfb32,8 * ---- ------ ------- ------ ------ ------ ------- * PSZ 8 24 32 8 24 32 * PGSZ 32 32 32 64 64 64 * PGSZB 4 4 4 8 8 8 * PGSZBMSK 0xF 0xF? 0xF 0xFF 0xFF 0xFF * PPW 4 1 1 8 2 2 * PPWMSK 0xF 0x1 0x1 0xFF 0x3? 0x3 * PLST 3 0 0 7 1 1 * PIM 0x3 0x0 0x0 0x7 0x1? 0x1 * PWSH 2 0 0 3 1 1 * PMSK 0xFF 0xFFFFFF 0xFFFFFFFF 0xFF 0xFFFFFF 0xFFFFFFFF * * * I have also added a new macro, PFILL, that takes one pixel and * replicates it throughout a word. This macro definition is dependent * upon pixel and word size; it doesn't use macros like PPW and so * forth. Examples: for monochrome, PFILL(1) => 0xffffffff, PFILL(0) => * 0x00000000. For 8-bit color, PFILL(0x5d) => 0x5d5d5d5d. This macro * is used primarily for replicating a plane mask into a word. * * Color framebuffers operations also support the notion of a plane * mask. This mask determines which planes of the framebuffer can be * altered; the others are left unchanged. I have added another * parameter to the putbits and putbitsrop macros that is the plane * mask. * ========================================================================== *//* * PSZ needs to be defined before we get here. Usually it comes from a * -DPSZ=foo on the compilation command line. */#ifndef PSZ#define PSZ 8#endif/* * PixelGroup is the data type used to operate on groups of pixels. * We typedef it here to unsigned long with the assumption that you * want to manipulate as many pixels at a time as you can. If unsigned * long is not appropriate for your server, define it to something else * before including this file. In this case you will also have to define * PGSZB to the size in bytes of PixelGroup. */#ifndef PixelGrouptypedef unsigned long PixelGroup;#ifdef LONG64#define PGSZB 8#else#define PGSZB 4#endif /* LONG64 */#endif /* PixelGroup */#define PGSZ (PGSZB << 3)#define PPW (PGSZ/PSZ)#define PLST (PPW-1)#define PIM PLST#define PMSK (((PixelGroup)1 << PSZ) - 1)#define PPWMSK (((PixelGroup)1 << PPW) - 1) /* instead of BITMSK */#define PGSZBMSK (((PixelGroup)1 << PGSZB) - 1)/* set PWSH = log2(PPW) using brute force */#if PPW == 1#define PWSH 0#else#if PPW == 2#define PWSH 1#else#if PPW == 4#define PWSH 2#else#if PPW == 8#define PWSH 3#else#if PPW == 16#define PWSH 4#endif /* PPW == 16 */#endif /* PPW == 8 */#endif /* PPW == 4 */#endif /* PPW == 2 */#endif /* PPW == 1 *//* Defining PIXEL_ADDR means that individual pixels are addressable by this * machine (as type PixelType). A possible CFB architecture which supported * 8-bits-per-pixel on a non byte-addressable machine would not have this * defined. * * Defining FOUR_BIT_CODE means that cfb knows how to stipple on this machine; * eventually, stippling code for 16 and 32 bit devices should be written * which would allow them to also use FOUR_BIT_CODE. There isn't that * much to do in those cases, but it would make them quite a bit faster. */#if PSZ == 8#define PIXEL_ADDRtypedef CARD8 PixelType;#define FOUR_BIT_CODE#endif#if PSZ == 16#define PIXEL_ADDRtypedef CARD16 PixelType;#endif#if PSZ == 24#undef PMSK#define PMSK 0xFFFFFF/*#undef PIM#define PIM 3*/#define PIXEL_ADDRtypedef CARD32 PixelType;#endif#if PSZ == 32#undef PMSK#define PMSK 0xFFFFFFFF#define PIXEL_ADDRtypedef CARD32 PixelType;#endif/* the following notes use the following conventions:SCREEN LEFT SCREEN RIGHTin this file and maskbits.c, left and right refer to screen coordinates,NOT bit numbering in registers.cfbstarttab[n] pixels[0,n-1] = 0's pixels[n,PPW-1] = 1'scfbendtab[n] = pixels[0,n-1] = 1's pixels[n,PPW-1] = 0'scfbstartpartial[], cfbendpartial[] these are used as accelerators for doing putbits and masking outbits that are all contained between longword boudaries. the extra256 bytes of data seems a small price to pay -- code is smaller,and narrow things (e.g. window borders) go faster.the names may seem misleading; they are derived not from which endof the word the bits are turned on, but at which end of a scanlinethe table tends to be used.look at the tables and macros to understand boundary conditions.(careful readers will note that starttab[n] = ~endtab[n] for n != 0)-----------------------------------------------------------------------these two macros depend on the screen's bit ordering.in both of them x is a screen position. they are used tocombine bits collected from multiple longwords into asingle destination longword, and to unpack a singlesource longword into multiple destinations.SCRLEFT(dst, x) takes dst[x, PPW] and moves them to dst[0, PPW-x] the contents of the rest of dst are 0 ONLY IF dst is UNSIGNED. is cast as an unsigned. this is a right shift on the VAX, left shift on Sun and pc-rt.SCRRIGHT(dst, x) takes dst[0,x] and moves them to dst[PPW-x, PPW] the contents of the rest of dst are 0 ONLY IF dst is UNSIGNED. this is a left shift on the VAX, right shift on Sun and pc-rt.the remaining macros are cpu-independent; all bit order dependenciesare built into the tables and the two macros above.maskbits(x, w, startmask, endmask, nlw) for a span of width w starting at position x, returnsa mask for ragged pixels at start, mask for ragged pixels at end,and the number of whole longwords between the ends.maskpartialbits(x, w, mask) works like maskbits(), except all the pixels are in the same longword (i.e. (x&0xPIM + w) <= PPW)mask32bits(x, w, startmask, endmask, nlw) as maskbits, but does not calculate nlw. it is used by cfbGlyphBlt to put down glyphs <= PPW bits wide.getbits(psrc, x, w, dst) starting at position x in psrc (x < PPW), collect w pixels and put them in the screen left portion of dst. psrc is a longword pointer. this may span longword boundaries. it special-cases fetching all w bits from one longword. +--------+--------+ +--------+ | | m |n| | ==> | m |n| | +--------+--------+ +--------+ x x+w 0 w psrc psrc+1 dst m = PPW - x n = w - m implementation: get m pixels, move to screen-left of dst, zeroing rest of dst; get n pixels from next word, move screen-right by m, zeroing lower m pixels of word. OR the two things together.putbits(src, x, w, pdst, planemask) starting at position x in pdst, put down the screen-leftmost w bits of src. pdst is a longword pointer. this may span longword boundaries. it special-cases putting all w bits into the same longword. +--------+ +--------+--------+ | m |n| | ==> | | m |n| | +--------+ +--------+--------+ 0 w x x+w dst pdst pdst+1 m = PPW - x n = w - m implementation: get m pixels, shift screen-right by x, zero screen-leftmost x pixels; zero rightmost m bits of *pdst and OR in stuff from before the semicolon. shift src screen-left by m, zero bits n-32; zero leftmost n pixels of *(pdst+1) and OR in the stuff from before the semicolon.putbitsrop(src, x, w, pdst, planemask, ROP) like putbits but calls DoRop with the rasterop ROP (see cfb.h for DoRop)getleftbits(psrc, w, dst) get the leftmost w (w<=PPW) bits from *psrc and put them in dst. this is used by the cfbGlyphBlt code for glyphs <=PPW bits wide.*/#if (BITMAP_BIT_ORDER == MSBFirst)#define BitRight(lw,n) ((lw) >> (n))#define BitLeft(lw,n) ((lw) << (n))#else /* (BITMAP_BIT_ORDER == LSBFirst) */#define BitRight(lw,n) ((lw) << (n))#define BitLeft(lw,n) ((lw) >> (n))#endif /* (BITMAP_BIT_ORDER == MSBFirst) */#define SCRLEFT(lw, n) BitLeft (lw, (n) * PSZ)#define SCRRIGHT(lw, n) BitRight(lw, (n) * PSZ)/* * Note that the shift direction is independent of the byte ordering of the * machine. The following is portable code. */#if PPW == 16#define PFILL(p) ( ((p)&PMSK) | \ ((p)&PMSK) << PSZ | \ ((p)&PMSK) << 2*PSZ | \ ((p)&PMSK) << 3*PSZ | \ ((p)&PMSK) << 4*PSZ | \ ((p)&PMSK) << 5*PSZ | \ ((p)&PMSK) << 6*PSZ | \ ((p)&PMSK) << 7*PSZ | \ ((p)&PMSK) << 8*PSZ | \ ((p)&PMSK) << 9*PSZ | \ ((p)&PMSK) << 10*PSZ | \ ((p)&PMSK) << 11*PSZ | \ ((p)&PMSK) << 12*PSZ | \ ((p)&PMSK) << 13*PSZ | \ ((p)&PMSK) << 14*PSZ | \ ((p)&PMSK) << 15*PSZ ) #define PFILL2(p, pf) { \ pf = (p) & PMSK; \ pf |= (pf << PSZ); \ pf |= (pf << 2*PSZ); \ pf |= (pf << 4*PSZ); \ pf |= (pf << 8*PSZ); \}#endif /* PPW == 16 */#if PPW == 8#define PFILL(p) ( ((p)&PMSK) | \ ((p)&PMSK) << PSZ | \ ((p)&PMSK) << 2*PSZ | \ ((p)&PMSK) << 3*PSZ | \ ((p)&PMSK) << 4*PSZ | \ ((p)&PMSK) << 5*PSZ | \ ((p)&PMSK) << 6*PSZ | \ ((p)&PMSK) << 7*PSZ )#define PFILL2(p, pf) { \ pf = (p) & PMSK; \ pf |= (pf << PSZ); \ pf |= (pf << 2*PSZ); \ pf |= (pf << 4*PSZ); \}#endif#if PPW == 4#define PFILL(p) ( ((p)&PMSK) | \ ((p)&PMSK) << PSZ | \ ((p)&PMSK) << 2*PSZ | \ ((p)&PMSK) << 3*PSZ )#define PFILL2(p, pf) { \ pf = (p) & PMSK; \ pf |= (pf << PSZ); \ pf |= (pf << 2*PSZ); \}#endif#if PPW == 2#define PFILL(p) ( ((p)&PMSK) | \ ((p)&PMSK) << PSZ )#define PFILL2(p, pf) { \ pf = (p) & PMSK; \ pf |= (pf << PSZ); \}#endif#if PPW == 1#define PFILL(p) (p)#define PFILL2(p,pf) (pf = (p))#endif/* * Reduced raster op - using precomputed values, perform the above * in three instructions */#define DoRRop(dst, and, xor) (((dst) & (and)) ^ (xor))#define DoMaskRRop(dst, and, xor, mask) \ (((dst) & ((and) | ~(mask))) ^ (xor & mask))#if PSZ != 32 || PPW != 1# if (PSZ == 24 && PPW == 1)#define maskbits(x, w, startmask, endmask, nlw) {\ startmask = cfbstarttab[(x)&3]; \ endmask = cfbendtab[((x)+(w)) & 3]; \ nlw = ((((x)+(w))*3)>>2) - (((x)*3 +3)>>2); \}#define mask32bits(x, w, startmask, endmask) \ startmask = cfbstarttab[(x)&3]; \ endmask = cfbendtab[((x)+(w)) & 3];#define maskpartialbits(x, w, mask) \ mask = cfbstartpartial[(x) & 3] & cfbendpartial[((x)+(w)) & 3];#define maskbits24(x, w, startmask, endmask, nlw) \ startmask = cfbstarttab24[(x) & 3]; \ endmask = cfbendtab24[((x)+(w)) & 3]; \ if (startmask){ \ nlw = (((w) - (4 - ((x) & 3))) >> 2); \ } else { \ nlw = (w) >> 2; \ }#define getbits24(psrc, dst, index) {\ register int idx; \ switch(idx = ((index)&3)<<1){ \ case 0: \ dst = (*(psrc) &cfbmask[idx]); \ break; \ case 6: \ dst = BitLeft((*(psrc) &cfbmask[idx]), cfb24Shift[idx]); \ break; \ default: \ dst = BitLeft((*(psrc) &cfbmask[idx]), cfb24Shift[idx]) | \ BitRight(((*((psrc)+1)) &cfbmask[idx+1]), cfb24Shift[idx+1]); \ }; \}#define putbits24(src, x, w, pdst, planemask, index) {\ register PixelGroup dstpixel; \ register unsigned int idx; \ switch(idx = ((index)&3)<<1){ \ case 0: \ dstpixel = (*(pdst) &cfbmask[idx]); \ break; \ case 6: \ dstpixel = BitLeft((*(pdst) &cfbmask[idx]), cfb24Shift[idx]); \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -