home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mfb / mfb.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-10  |  10.9 KB  |  343 lines

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