home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / cfb / cfbwindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-12  |  6.8 KB  |  264 lines

  1. /***********************************************************
  2. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. #include "X.h"
  26. #include "scrnintstr.h"
  27. #include "windowstr.h"
  28. #include "cfb.h"
  29. #include "mistruct.h"
  30. #include "regionstr.h"
  31. #include "cfbmskbits.h"
  32.  
  33. extern WindowPtr *WindowTable;
  34.  
  35. Bool
  36. cfbCreateWindow(pWin)
  37.     WindowPtr pWin;
  38. {
  39.     cfbPrivWin *pPrivWin;
  40.  
  41.     pPrivWin = (cfbPrivWin *)(pWin->devPrivates[cfbWindowPrivateIndex].ptr);
  42.     pPrivWin->pRotatedBorder = NullPixmap;
  43.     pPrivWin->pRotatedBackground = NullPixmap;
  44.     pPrivWin->fastBackground = FALSE;
  45.     pPrivWin->fastBorder = FALSE;
  46.  
  47.     return TRUE;
  48. }
  49.  
  50. Bool
  51. cfbDestroyWindow(pWin)
  52.     WindowPtr pWin;
  53. {
  54.     cfbPrivWin *pPrivWin;
  55.  
  56.     pPrivWin = (cfbPrivWin *)(pWin->devPrivates[cfbWindowPrivateIndex].ptr);
  57.  
  58.     if (pPrivWin->pRotatedBorder)
  59.     cfbDestroyPixmap(pPrivWin->pRotatedBorder);
  60.     if (pPrivWin->pRotatedBackground)
  61.     cfbDestroyPixmap(pPrivWin->pRotatedBackground);
  62.     return(TRUE);
  63. }
  64.  
  65. /*ARGSUSED*/
  66. Bool
  67. cfbMapWindow(pWindow)
  68.     WindowPtr pWindow;
  69. {
  70.     return(TRUE);
  71. }
  72.  
  73. /* (x, y) is the upper left corner of the window on the screen 
  74.    do we really need to pass this?  (is it a;ready in pWin->absCorner?)
  75.    we only do the rotation for pixmaps that are 32 bits wide (padded
  76. or otherwise.)
  77.    cfbChangeWindowAttributes() has already put a copy of the pixmap
  78. in pPrivWin->pRotated*
  79. */
  80. /*ARGSUSED*/
  81. Bool
  82. cfbPositionWindow(pWin, x, y)
  83.     WindowPtr pWin;
  84.     int x, y;
  85. {
  86.     cfbPrivWin *pPrivWin;
  87.     int setxy = 0;
  88.  
  89.     pPrivWin = (cfbPrivWin *)(pWin->devPrivates[cfbWindowPrivateIndex].ptr);
  90.     if (pWin->backgroundState == BackgroundPixmap && pPrivWin->fastBackground)
  91.     {
  92.     cfbXRotatePixmap(pPrivWin->pRotatedBackground,
  93.               pWin->drawable.x - pPrivWin->oldRotate.x);
  94.     cfbYRotatePixmap(pPrivWin->pRotatedBackground,
  95.               pWin->drawable.y - pPrivWin->oldRotate.y);
  96.     setxy = 1;
  97.     }
  98.  
  99.     if (!pWin->borderIsPixel &&    pPrivWin->fastBorder)
  100.     {
  101.     cfbXRotatePixmap(pPrivWin->pRotatedBorder,
  102.               pWin->drawable.x - pPrivWin->oldRotate.x);
  103.     cfbYRotatePixmap(pPrivWin->pRotatedBorder,
  104.               pWin->drawable.y - pPrivWin->oldRotate.y);
  105.     setxy = 1;
  106.     }
  107.     if (setxy)
  108.     {
  109.     pPrivWin->oldRotate.x = pWin->drawable.x;
  110.     pPrivWin->oldRotate.y = pWin->drawable.y;
  111.     }
  112.     return (TRUE);
  113. }
  114.  
  115. /*ARGSUSED*/
  116. Bool
  117. cfbUnmapWindow(pWindow)
  118.     WindowPtr pWindow;
  119. {
  120.     return (TRUE);
  121. }
  122.  
  123. /* UNCLEAN!
  124.    this code calls the bitblt helper code directly.
  125.  
  126.    cfbCopyWindow copies only the parts of the destination that are
  127. visible in the source.
  128. */
  129.  
  130.  
  131. void 
  132. cfbCopyWindow(pWin, ptOldOrg, prgnSrc)
  133.     WindowPtr pWin;
  134.     DDXPointRec ptOldOrg;
  135.     RegionPtr prgnSrc;
  136. {
  137.     DDXPointPtr pptSrc;
  138.     register DDXPointPtr ppt;
  139.     RegionPtr prgnDst;
  140.     register BoxPtr pbox;
  141.     register int dx, dy;
  142.     register int i, nbox;
  143.     WindowPtr pwinRoot;
  144.  
  145.     pwinRoot = WindowTable[pWin->drawable.pScreen->myNum];
  146.  
  147.     prgnDst = (* pWin->drawable.pScreen->RegionCreate)(NULL, 1);
  148.  
  149.     dx = ptOldOrg.x - pWin->drawable.x;
  150.     dy = ptOldOrg.y - pWin->drawable.y;
  151.     (* pWin->drawable.pScreen->TranslateRegion)(prgnSrc, -dx, -dy);
  152.     (* pWin->drawable.pScreen->Intersect)(prgnDst, &pWin->borderClip, prgnSrc);
  153.  
  154.     pbox = REGION_RECTS(prgnDst);
  155.     nbox = REGION_NUM_RECTS(prgnDst);
  156.     if(!(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec))))
  157.     return;
  158.     ppt = pptSrc;
  159.  
  160.     for (i = nbox; --i >= 0; ppt++, pbox++)
  161.     {
  162.     ppt->x = pbox->x1 + dx;
  163.     ppt->y = pbox->y1 + dy;
  164.     }
  165.  
  166.     cfbDoBitbltCopy((DrawablePtr)pwinRoot, (DrawablePtr)pwinRoot,
  167.         GXcopy, prgnDst, pptSrc, ~0L);
  168.     DEALLOCATE_LOCAL(pptSrc);
  169.     (* pWin->drawable.pScreen->RegionDestroy)(prgnDst);
  170. }
  171.  
  172.  
  173.  
  174. /* swap in correct PaintWindow* routine.  If we can use a fast output
  175. routine (i.e. the pixmap is paddable to 32 bits), also pre-rotate a copy
  176. of it in devPrivates[cfbWindowPrivateIndex].ptr.
  177. */
  178. Bool
  179. cfbChangeWindowAttributes(pWin, mask)
  180.     WindowPtr pWin;
  181.     unsigned long mask;
  182. {
  183.     register unsigned long index;
  184.     register cfbPrivWin *pPrivWin;
  185.     int width;
  186.  
  187.     pPrivWin = (cfbPrivWin *)(pWin->devPrivates[cfbWindowPrivateIndex].ptr);
  188.     while(mask)
  189.     {
  190.     index = lowbit (mask);
  191.     mask &= ~index;
  192.     switch(index)
  193.     {
  194.       case CWBackPixmap:
  195.           if (pWin->backgroundState == None)
  196.           {
  197.           pPrivWin->fastBackground = FALSE;
  198.           }
  199.           else if (pWin->backgroundState == ParentRelative)
  200.           {
  201.           pPrivWin->fastBackground = FALSE;
  202.           }
  203.           else if (((width = (pWin->background.pixmap->drawable.width * PSZ)) <= 32) &&
  204.                !(width & (width - 1)))
  205.           {
  206.           cfbCopyRotatePixmap(pWin->background.pixmap,
  207.                       &pPrivWin->pRotatedBackground,
  208.                       pWin->drawable.x,
  209.                       pWin->drawable.y);
  210.           if (pPrivWin->pRotatedBackground)
  211.           {
  212.               pPrivWin->fastBackground = TRUE;
  213.               pPrivWin->oldRotate.x = pWin->drawable.x;
  214.               pPrivWin->oldRotate.y = pWin->drawable.y;
  215.           }
  216.           else
  217.           {
  218.               pPrivWin->fastBackground = FALSE;
  219.           }
  220.           }
  221.           else
  222.           {
  223.           pPrivWin->fastBackground = FALSE;
  224.           }
  225.           break;
  226.  
  227.       case CWBackPixel:
  228.           pPrivWin->fastBackground = FALSE;
  229.           break;
  230.  
  231.       case CWBorderPixmap:
  232.           if (((width = (pWin->border.pixmap->drawable.width * PSZ)) <= 32) &&
  233.           !(width & (width - 1)))
  234.           {
  235.           cfbCopyRotatePixmap(pWin->border.pixmap,
  236.                       &pPrivWin->pRotatedBorder,
  237.                       pWin->drawable.x,
  238.                       pWin->drawable.y);
  239.           if (pPrivWin->pRotatedBorder)
  240.           {
  241.               pPrivWin->fastBorder = TRUE;
  242.               pPrivWin->oldRotate.x = pWin->drawable.x;
  243.               pPrivWin->oldRotate.y = pWin->drawable.y;
  244.           }
  245.           else
  246.           {
  247.               pPrivWin->fastBorder = FALSE;
  248.           }
  249.           }
  250.           else
  251.           {
  252.           pPrivWin->fastBorder = FALSE;
  253.           }
  254.           break;
  255.         case CWBorderPixel:
  256.           pPrivWin->fastBorder = FALSE;
  257.           break;
  258.  
  259.     }
  260.     }
  261.     return (TRUE);
  262. }
  263.  
  264.