1 /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */ 2 /*********************************************************** 3 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, 4 and the Massachusetts Institute of Technology, Cambridge, Massachusetts. 5 6 All Rights Reserved 7 8 Permission to use, copy, modify, and distribute this software and its 9 documentation for any purpose and without fee is hereby granted, 10 provided that the above copyright notice appear in all copies and that 11 both that copyright notice and this permission notice appear in 12 supporting documentation, and that the names of Digital or MIT not be 13 used in advertising or publicity pertaining to distribution of the 14 software without specific, written prior permission. 15 16 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 17 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 18 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 19 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 20 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 21 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 22 SOFTWARE. 23 24 ******************************************************************/ 25 /* $XFree86: mit/server/ddx/mfb/mfb.h,v 1.3 1993/03/27 09:00:33 dawes Exp $ */ 26 /* $XConsortium: mfb.h,v 5.15 91/04/10 11:43:42 keith Exp $ */ 27 /* Monochrome Frame Buffer definitions 28 written by drewry, september 1986 29 */ 30 #include "misc.h" 31 #include "mfbcustom.h" 32 #include "mfbmap.h" 33 #include "pixmap.h" 34 #include "region.h" 35 #include "gc.h" 36 #include "colormap.h" 37 #include "miscstruct.h" 38 #include "mibstore.h" 39 40 extern int InverseAlu[]; 41 42 extern Bool mfbScreenInit(); 43 extern Bool mfbCloseScreen(); 44 extern Bool mfbCreateDefColormap(); 45 extern void mfbQueryBestSize(); 46 extern Bool mfbCreateWindow(); 47 extern Bool mfbPositionWindow(); 48 extern Bool mfbChangeWindowAttributes(); 49 extern Bool mfbMapWindow(); 50 extern Bool mfbUnmapWindow(); 51 extern Bool mfbDestroyWindow(); 52 53 extern Bool mfbRealizeFont(); 54 extern Bool mfbUnrealizeFont(); 55 extern Bool mfbScreenSaver(); 56 extern Bool mfbCreateGC(); 57 extern int mfbReduceRop(); 58 59 extern void mfbValidateGC(), mfbChangeGC(), mfbCopyGC(); 60 extern void mfbDestroyGC(); 61 extern void mfbChangeClip(), mfbDestroyClip(), mfbCopyClip(); 62 63 extern PixmapPtr mfbCreatePixmap(); 64 extern Bool mfbDestroyPixmap(); 65 66 extern void mfbCopyWindow(); 67 68 extern void mfbSaveAreas(); 69 extern void mfbRestoreAreas(); 70 71 /* window painter */ 72 extern void mfbPaintWindow(); 73 74 /* rectangle painters */ 75 extern void mfbSolidWhiteArea(); 76 extern void mfbStippleWhiteArea(); 77 extern void mfbSolidBlackArea(); 78 extern void mfbStippleBlackArea(); 79 extern void mfbSolidInvertArea(); 80 extern void mfbStippleInvertArea(); 81 extern void mfbTileArea32(); 82 83 extern void mfbPolyFillRect(); 84 extern RegionPtr mfbCopyArea(); 85 extern void mfbPolyPoint(); 86 extern RegionPtr mfbCopyPlane(); 87 extern void mfbPolyFillArcSolid(); 88 89 extern void mfbSetSpans(); 90 extern void mfbGetSpans(); 91 extern void mfbWhiteSolidFS(); 92 extern void mfbBlackSolidFS(); 93 extern void mfbInvertSolidFS(); 94 extern void mfbWhiteStippleFS(); 95 extern void mfbBlackStippleFS(); 96 extern void mfbInvertStippleFS(); 97 extern void mfbTileFS(); 98 extern void mfbUnnaturalTileFS(); 99 extern void mfbUnnaturalStippleFS(); 100 101 extern void mfbGetImage(); 102 extern void mfbPutImage(); 103 104 extern void mfbLineSS(); /* solid single-pixel wide line */ 105 /* calls mfb{Bres|Horz|Vert}S() */ 106 extern void mfbLineSD(); 107 extern void mfbSegmentSS(); 108 extern void mfbSegmentSD(); 109 extern void mfbZeroPolyArcSS(); 110 extern void mfbImageText8(); 111 extern void mfbImageText16(); 112 extern int mfbPolyText16(); 113 extern int mfbPolyText8(); 114 extern PixmapPtr mfbCopyPixmap(); 115 extern RegionPtr mfbPixmapToRegion(); 116 extern void mfbSolidPP(); 117 extern void mfbPushPixels(); 118 119 /* text for glyphs <= 32 bits wide */ 120 extern void mfbImageGlyphBltWhite(); 121 extern void mfbImageGlyphBltBlack(); 122 extern void mfbPolyGlyphBltWhite(); 123 extern void mfbPolyGlyphBltBlack(); 124 extern void mfbPolyGlyphBltInvert(); 125 126 /* text for terminal emulator fonts */ 127 extern void mfbTEGlyphBltWhite(); /* fg = 1, bg = 0 */ 128 extern void mfbTEGlyphBltBlack(); /* fg = 0, bg = 1 */ 129 130 extern int mfbListInstalledColormaps(); 131 extern void mfbInstallColormap(); 132 extern void mfbUninstallColormap(); 133 extern Bool mfbCreateColormap(); 134 extern void mfbDestroyColormap(); 135 extern void mfbResolveColor(); 136 137 extern void mfbCopyGCDest(); 138 139 extern void mfbCopyRotatePixmap(); 140 extern void mfbYRotatePixmap(); 141 extern void mfbXRotatePixmap(); 142 extern void mfbPadPixmap(); 143 144 /* 145 private filed of pixmap 146 pixmap.devPrivate = (unsigned int *)pointer_to_bits 147 pixmap.devKind = width_of_pixmap_in_bytes 148 149 private field of screen 150 a pixmap, for which we allocate storage. devPrivate is a pointer to 151 the bits in the hardware framebuffer. note that devKind can be poked to 152 make the code work for framebuffers that are wider than their 153 displayable screen (e.g. the early vsII, which displayed 960 pixels 154 across, but was 1024 in the hardware.) 155 156 private field of GC 157 Freeing pCompositeClip is done based on the value of 158 freeCompClip; if freeCompClip is not carefully maintained, we will end 159 up losing storage or freeing something that isn't ours. 160 */ 161 162 typedef struct { 163 unsigned char rop; /* reduction of rasterop to 1 of 3 */ 164 unsigned char ropOpStip; /* rop for opaque stipple */ 165 unsigned char ropFillArea; /* == alu, rop, or ropOpStip */ 166 unsigned fExpose:1; /* callexposure handling ? */ 167 unsigned freeCompClip:1; 168 PixmapPtr pRotatedPixmap; /* tile/stipple rotated to align */ 169 RegionPtr pCompositeClip; /* free this based on freeCompClip 170 flag rather than NULLness */ 171 void (* FillArea)(); /* fills regions; look at the code */ 172 } mfbPrivGC; 173 typedef mfbPrivGC *mfbPrivGCPtr; 174 175 extern int mfbGCPrivateIndex; /* index into GC private array */ 176 extern int mfbWindowPrivateIndex; /* index into Window private array */ 177 178 /* private field of window */ 179 typedef struct { 180 unsigned char fastBorder; /* non-zero if border tile is 32 bits wide */ 181 unsigned char fastBackground; 182 unsigned short unused; /* pad for alignment with Sun compiler */ 183 DDXPointRec oldRotate; 184 PixmapPtr pRotatedBackground; 185 PixmapPtr pRotatedBorder; 186 } mfbPrivWin; 187 188 /* Common macros for extracting drawing information */ 189 190 #define mfbGetTypedWidth(pDrawable,type) (\ 191 (((pDrawable)->type == DRAWABLE_WINDOW) ? \ 192 (int) (((PixmapPtr)((pDrawable)->pScreen->devPrivate))->devKind) : \ 193 (int)(((PixmapPtr)pDrawable)->devKind)) / sizeof (type)) 194 195 #define mfbGetByteWidth(pDrawable) cbGetTypedWidth(pDrawable, char) 196 197 #define mfbGetLongWidth(pDrawable) cbGetTypedWidth(pDrawable, long) 198 199 #define mfbGetTypedWidthAndPointer(pDrawable, width, pointer, wtype, ptype) {\ 200 PixmapPtr _pPix; \ 201 if ((pDrawable)->type == DRAWABLE_WINDOW) \ 202 _pPix = (PixmapPtr) (pDrawable)->pScreen->devPrivate; \ 203 else \ 204 _pPix = (PixmapPtr) (pDrawable); \ 205 (pointer) = (ptype *) _pPix->devPrivate.ptr; \ 206 (width) = ((int) _pPix->devKind) / sizeof (wtype); \ 207 } 208 209 #define mfbGetByteWidthAndPointer(pDrawable, width, pointer) \ 210 mfbGetTypedWidthAndPointer(pDrawable, width, pointer, char, char) 211 212 #define mfbGetLongWidthAndPointer(pDrawable, width, pointer) \ 213 mfbGetTypedWidthAndPointer(pDrawable, width, pointer, unsigned long, unsigned long) 214 215 #define mfbGetWindowTypedWidthAndPointer(pWin, width, pointer, wtype, ptype) {\ 216 PixmapPtr _pPix = (PixmapPtr) (pWin)->drawable.pScreen->devPrivate; \ 217 (pointer) = (ptype *) _pPix->devPrivate.ptr; \ 218 (width) = ((int) _pPix->devKind) / sizeof (wtype); \ 219 } 220 221 #define mfbGetWindowLongWidthAndPointer(pWin, width, pointer) \ 222 mfbGetWindowTypedWidthAndPointer(pWin, width, pointer, unsigned long, unsigned long) 223 224 #define mfbGetWindowByteWidthAndPointer(pWin, width, pointer) \ 225 mfbGetWindowTypedWidthAndPointer(pWin, width, pointer, char, char) 226 227 /* precomputed information about each glyph for GlyphBlt code. 228 this saves recalculating the per glyph information for each 229 box. 230 */ 231 typedef struct _pos{ 232 int xpos; /* xposition of glyph's origin */ 233 int xchar; /* x position mod 32 */ 234 int leftEdge; 235 int rightEdge; 236 int topEdge; 237 int bottomEdge; 238 unsigned int *pdstBase; /* longword with character origin */ 239 int widthGlyph; /* width in bytes of this glyph */ 240 } TEXTPOS; 241 242 /* reduced raster ops for mfb */ 243 #define RROP_BLACK GXclear 244 #define RROP_WHITE GXset 245 #define RROP_NOP GXnoop 246 #define RROP_INVERT GXinvert 247 248 /* out of clip region codes */ 249 #define OUT_LEFT 0x08 250 #define OUT_RIGHT 0x04 251 #define OUT_ABOVE 0x02 252 #define OUT_BELOW 0x01 253 254 /* major axis for bresenham's line */ 255 #define X_AXIS 0 256 #define Y_AXIS 1 257 258 /* macros for mfbbitblt.c, mfbfillsp.c 259 these let the code do one switch on the rop per call, rather 260 than a switch on the rop per item (span or rectangle.) 261 */ 262 263 #define fnCLEAR(src, dst) (0) 264 #define fnAND(src, dst) (src & dst) 265 #define fnANDREVERSE(src, dst) (src & ~dst) 266 #define fnCOPY(src, dst) (src) 267 #define fnANDINVERTED(src, dst) (~src & dst) 268 #define fnNOOP(src, dst) (dst) 269 #define fnXOR(src, dst) (src ^ dst) 270 #define fnOR(src, dst) (src | dst) 271 #define fnNOR(src, dst) (~(src | dst)) 272 #define fnEQUIV(src, dst) (~src ^ dst) 273 #define fnINVERT(src, dst) (~dst) 274 #define fnORREVERSE(src, dst) (src | ~dst) 275 #define fnCOPYINVERTED(src, dst)(~src) 276 #define fnORINVERTED(src, dst) (~src | dst) 277 #define fnNAND(src, dst) (~(src & dst)) 278 #define fnSET(src, dst) (~0) 279 280 /* Using a "switch" statement is much faster in most cases 281 * since the compiler can do a look-up table or multi-way branch 282 * instruction, depending on the architecture. The result on 283 * A Sun 3/50 is at least 2.5 times faster, assuming a uniform 284 * distribution of RasterOp operation types. 285 * 286 * However, doing some profiling on a running system reveals 287 * GXcopy is the operation over 99.5% of the time and 288 * GXxor is the next most frequent (about .4%), so we make special 289 * checks for those first. 290 * 291 * Note that this requires a change to the "calling sequence" 292 * since we can't engineer a "switch" statement to have an lvalue. 293 */ 294 #define DoRop(result, alu, src, dst) \ 295 { \ 296 if (alu == GXcopy) \ 297 result = fnCOPY (src, dst); \ 298 else if (alu == GXxor) \ 299 result = fnXOR (src, dst); \ 300 else \ 301 switch (alu) \ 302 { \ 303 case GXclear: \ 304 result = fnCLEAR (src, dst); \ 305 break; \ 306 case GXand: \ 307 result = fnAND (src, dst); \ 308 break; \ 309 case GXandReverse: \ 310 result = fnANDREVERSE (src, dst); \ 311 break; \ 312 case GXandInverted: \ 313 result = fnANDINVERTED (src, dst); \ 314 break; \ 315 case GXnoop: \ 316 result = fnNOOP (src, dst); \ 317 break; \ 318 case GXor: \ 319 result = fnOR (src, dst); \ 320 break; \ 321 case GXnor: \ 322 result = fnNOR (src, dst); \ 323 break; \ 324 case GXequiv: \ 325 result = fnEQUIV (src, dst); \ 326 break; \ 327 case GXinvert: \ 328 result = fnINVERT (src, dst); \ 329 break; \ 330 case GXorReverse: \ 331 result = fnORREVERSE (src, dst); \ 332 break; \ 333 case GXcopyInverted: \ 334 result = fnCOPYINVERTED (src, dst); \ 335 break; \ 336 case GXorInverted: \ 337 result = fnORINVERTED (src, dst); \ 338 break; \ 339 case GXnand: \ 340 result = fnNAND (src, dst); \ 341 break; \ 342 case GXset: \ 343 result = fnSET (src, dst); \ 344 break; \ 345 } \ 346 } 347