GCOps.c revision 05b261ec
105b261ecSmrg/*
205b261ecSmrg
305b261ecSmrgCopyright 1993 by Davor Matic
405b261ecSmrg
505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software
605b261ecSmrgand its documentation for any purpose is hereby granted without fee,
705b261ecSmrgprovided that the above copyright notice appear in all copies and that
805b261ecSmrgboth that copyright notice and this permission notice appear in
905b261ecSmrgsupporting documentation.  Davor Matic makes no representations about
1005b261ecSmrgthe suitability of this software for any purpose.  It is provided "as
1105b261ecSmrgis" without express or implied warranty.
1205b261ecSmrg
1305b261ecSmrg*/
1405b261ecSmrg
1505b261ecSmrg#ifdef HAVE_XNEST_CONFIG_H
1605b261ecSmrg#include <xnest-config.h>
1705b261ecSmrg#endif
1805b261ecSmrg
1905b261ecSmrg#include <X11/X.h>
2005b261ecSmrg#include <X11/Xproto.h>
2105b261ecSmrg#include "regionstr.h"
2205b261ecSmrg#include <X11/fonts/fontstruct.h>
2305b261ecSmrg#include "gcstruct.h"
2405b261ecSmrg#include "scrnintstr.h"
2505b261ecSmrg#include "windowstr.h"
2605b261ecSmrg#include "pixmapstr.h"
2705b261ecSmrg#include "region.h"
2805b261ecSmrg#include "servermd.h"
2905b261ecSmrg
3005b261ecSmrg#include "Xnest.h"
3105b261ecSmrg
3205b261ecSmrg#include "Display.h"
3305b261ecSmrg#include "Screen.h"
3405b261ecSmrg#include "XNGC.h"
3505b261ecSmrg#include "XNFont.h"
3605b261ecSmrg#include "GCOps.h"
3705b261ecSmrg#include "Drawable.h"
3805b261ecSmrg#include "Visual.h"
3905b261ecSmrg
4005b261ecSmrgvoid
4105b261ecSmrgxnestFillSpans(DrawablePtr pDrawable, GCPtr pGC, int nSpans, xPoint *pPoints,
4205b261ecSmrg	       int *pWidths, int fSorted)
4305b261ecSmrg{
4405b261ecSmrg  ErrorF("xnest warning: function xnestFillSpans not implemented\n");
4505b261ecSmrg}
4605b261ecSmrg
4705b261ecSmrgvoid
4805b261ecSmrgxnestSetSpans(DrawablePtr pDrawable, GCPtr pGC, char *pSrc,
4905b261ecSmrg	      xPoint *pPoints, int *pWidths, int nSpans, int fSorted)
5005b261ecSmrg{
5105b261ecSmrg  ErrorF("xnest warning: function xnestSetSpans not implemented\n");
5205b261ecSmrg}
5305b261ecSmrg
5405b261ecSmrgvoid
5505b261ecSmrgxnestGetSpans(DrawablePtr pDrawable, int maxWidth, DDXPointPtr pPoints,
5605b261ecSmrg	      int *pWidths, int nSpans, char *pBuffer)
5705b261ecSmrg{
5805b261ecSmrg  ErrorF("xnest warning: function xnestGetSpans not implemented\n");
5905b261ecSmrg}
6005b261ecSmrg
6105b261ecSmrgvoid
6205b261ecSmrgxnestQueryBestSize(int class, unsigned short *pWidth, unsigned short *pHeight,
6305b261ecSmrg		   ScreenPtr pScreen)
6405b261ecSmrg{
6505b261ecSmrg  unsigned int width, height;
6605b261ecSmrg
6705b261ecSmrg  width = *pWidth;
6805b261ecSmrg  height = *pHeight;
6905b261ecSmrg
7005b261ecSmrg  XQueryBestSize(xnestDisplay, class,
7105b261ecSmrg		 xnestDefaultWindows[pScreen->myNum],
7205b261ecSmrg		 width, height, &width, &height);
7305b261ecSmrg
7405b261ecSmrg  *pWidth = width;
7505b261ecSmrg  *pHeight = height;
7605b261ecSmrg}
7705b261ecSmrg
7805b261ecSmrgvoid
7905b261ecSmrgxnestPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
8005b261ecSmrg	      int w, int h, int leftPad, int format, char *pImage)
8105b261ecSmrg{
8205b261ecSmrg  XImage *ximage;
8305b261ecSmrg
8405b261ecSmrg  ximage = XCreateImage(xnestDisplay, xnestDefaultVisual(pDrawable->pScreen),
8505b261ecSmrg			depth, format, leftPad, (char *)pImage,
8605b261ecSmrg			w, h, BitmapPad(xnestDisplay),
8705b261ecSmrg			(format == ZPixmap) ?
8805b261ecSmrg			   PixmapBytePad(w, depth) : BitmapBytePad(w+leftPad));
8905b261ecSmrg
9005b261ecSmrg  if (ximage) {
9105b261ecSmrg      XPutImage(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
9205b261ecSmrg		ximage, 0, 0, x, y, w, h);
9305b261ecSmrg      XFree(ximage);
9405b261ecSmrg  }
9505b261ecSmrg}
9605b261ecSmrg
9705b261ecSmrgvoid
9805b261ecSmrgxnestGetImage(DrawablePtr pDrawable, int x, int y, int w, int h,
9905b261ecSmrg	      unsigned int format, unsigned long planeMask,
10005b261ecSmrg	      char *pImage)
10105b261ecSmrg{
10205b261ecSmrg  XImage *ximage;
10305b261ecSmrg  int length;
10405b261ecSmrg
10505b261ecSmrg  ximage = XGetImage(xnestDisplay, xnestDrawable(pDrawable),
10605b261ecSmrg                     x, y, w, h, planeMask, format);
10705b261ecSmrg
10805b261ecSmrg  if (ximage) {
10905b261ecSmrg      length = ximage->bytes_per_line * ximage->height;
11005b261ecSmrg
11105b261ecSmrg      memmove(pImage, ximage->data, length);
11205b261ecSmrg
11305b261ecSmrg      XDestroyImage(ximage);
11405b261ecSmrg  }
11505b261ecSmrg}
11605b261ecSmrg
11705b261ecSmrgstatic Bool
11805b261ecSmrgxnestBitBlitPredicate(Display *display, XEvent *event, char *args)
11905b261ecSmrg{
12005b261ecSmrg  return (event->type == GraphicsExpose || event->type == NoExpose);
12105b261ecSmrg}
12205b261ecSmrg
12305b261ecSmrgstatic RegionPtr
12405b261ecSmrgxnestBitBlitHelper(GCPtr pGC)
12505b261ecSmrg{
12605b261ecSmrg  if (!pGC->graphicsExposures)
12705b261ecSmrg    return NullRegion;
12805b261ecSmrg  else {
12905b261ecSmrg    XEvent event;
13005b261ecSmrg    RegionPtr pReg, pTmpReg;
13105b261ecSmrg    BoxRec Box;
13205b261ecSmrg    Bool pending, overlap;
13305b261ecSmrg
13405b261ecSmrg    pReg = REGION_CREATE(pGC->pScreen, NULL, 1);
13505b261ecSmrg    pTmpReg = REGION_CREATE(pGC->pScreen, NULL, 1);
13605b261ecSmrg    if(!pReg || !pTmpReg) return NullRegion;
13705b261ecSmrg
13805b261ecSmrg    pending = True;
13905b261ecSmrg    while (pending) {
14005b261ecSmrg      XIfEvent(xnestDisplay, &event, xnestBitBlitPredicate, NULL);
14105b261ecSmrg
14205b261ecSmrg      switch (event.type) {
14305b261ecSmrg      case NoExpose:
14405b261ecSmrg	pending = False;
14505b261ecSmrg	break;
14605b261ecSmrg
14705b261ecSmrg      case GraphicsExpose:
14805b261ecSmrg	Box.x1 = event.xgraphicsexpose.x;
14905b261ecSmrg	Box.y1 = event.xgraphicsexpose.y;
15005b261ecSmrg	Box.x2 = event.xgraphicsexpose.x + event.xgraphicsexpose.width;
15105b261ecSmrg	Box.y2 = event.xgraphicsexpose.y + event.xgraphicsexpose.height;
15205b261ecSmrg	REGION_RESET(pGC->pScreen, pTmpReg, &Box);
15305b261ecSmrg	REGION_APPEND(pGC->pScreen, pReg, pTmpReg);
15405b261ecSmrg	pending = event.xgraphicsexpose.count;
15505b261ecSmrg	break;
15605b261ecSmrg      }
15705b261ecSmrg    }
15805b261ecSmrg
15905b261ecSmrg    REGION_DESTROY(pGC->pScreen, pTmpReg);
16005b261ecSmrg    REGION_VALIDATE(pGC->pScreen, pReg, &overlap);
16105b261ecSmrg    return(pReg);
16205b261ecSmrg  }
16305b261ecSmrg}
16405b261ecSmrg
16505b261ecSmrgRegionPtr
16605b261ecSmrgxnestCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
16705b261ecSmrg	      GCPtr pGC, int srcx, int srcy, int width, int height,
16805b261ecSmrg	      int dstx, int dsty)
16905b261ecSmrg{
17005b261ecSmrg  XCopyArea(xnestDisplay,
17105b261ecSmrg	    xnestDrawable(pSrcDrawable), xnestDrawable(pDstDrawable),
17205b261ecSmrg	    xnestGC(pGC), srcx, srcy, width, height, dstx, dsty);
17305b261ecSmrg
17405b261ecSmrg  return xnestBitBlitHelper(pGC);
17505b261ecSmrg}
17605b261ecSmrg
17705b261ecSmrgRegionPtr
17805b261ecSmrgxnestCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
17905b261ecSmrg	       GCPtr pGC, int srcx, int srcy, int width, int height,
18005b261ecSmrg	       int dstx, int dsty, unsigned long plane)
18105b261ecSmrg{
18205b261ecSmrg  XCopyPlane(xnestDisplay,
18305b261ecSmrg	     xnestDrawable(pSrcDrawable), xnestDrawable(pDstDrawable),
18405b261ecSmrg	     xnestGC(pGC), srcx, srcy, width, height, dstx, dsty, plane);
18505b261ecSmrg
18605b261ecSmrg  return xnestBitBlitHelper(pGC);
18705b261ecSmrg}
18805b261ecSmrg
18905b261ecSmrgvoid
19005b261ecSmrgxnestPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode, int nPoints,
19105b261ecSmrg	       DDXPointPtr pPoints)
19205b261ecSmrg{
19305b261ecSmrg  XDrawPoints(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
19405b261ecSmrg              (XPoint *)pPoints, nPoints, mode);
19505b261ecSmrg}
19605b261ecSmrg
19705b261ecSmrgvoid
19805b261ecSmrgxnestPolylines(DrawablePtr pDrawable, GCPtr pGC, int mode, int nPoints,
19905b261ecSmrg	       DDXPointPtr pPoints)
20005b261ecSmrg{
20105b261ecSmrg  XDrawLines(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
20205b261ecSmrg              (XPoint *)pPoints, nPoints, mode);
20305b261ecSmrg}
20405b261ecSmrg
20505b261ecSmrgvoid
20605b261ecSmrgxnestPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nSegments,
20705b261ecSmrg		 xSegment *pSegments)
20805b261ecSmrg{
20905b261ecSmrg  XDrawSegments(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
21005b261ecSmrg                (XSegment *)pSegments, nSegments);
21105b261ecSmrg}
21205b261ecSmrg
21305b261ecSmrgvoid
21405b261ecSmrgxnestPolyRectangle(DrawablePtr pDrawable, GCPtr pGC, int nRectangles,
21505b261ecSmrg		   xRectangle *pRectangles)
21605b261ecSmrg{
21705b261ecSmrg  XDrawRectangles(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
21805b261ecSmrg                  (XRectangle *)pRectangles, nRectangles);
21905b261ecSmrg}
22005b261ecSmrg
22105b261ecSmrgvoid
22205b261ecSmrgxnestPolyArc(DrawablePtr pDrawable, GCPtr pGC, int nArcs, xArc *pArcs)
22305b261ecSmrg{
22405b261ecSmrg  XDrawArcs(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
22505b261ecSmrg            (XArc *)pArcs, nArcs);
22605b261ecSmrg}
22705b261ecSmrg
22805b261ecSmrgvoid
22905b261ecSmrgxnestFillPolygon(DrawablePtr pDrawable, GCPtr pGC, int shape, int mode,
23005b261ecSmrg		 int nPoints, DDXPointPtr pPoints)
23105b261ecSmrg{
23205b261ecSmrg  XFillPolygon(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
23305b261ecSmrg               (XPoint *)pPoints, nPoints, shape, mode);
23405b261ecSmrg}
23505b261ecSmrg
23605b261ecSmrgvoid
23705b261ecSmrgxnestPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nRectangles,
23805b261ecSmrg		  xRectangle *pRectangles)
23905b261ecSmrg{
24005b261ecSmrg  XFillRectangles(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
24105b261ecSmrg                  (XRectangle *)pRectangles, nRectangles);
24205b261ecSmrg}
24305b261ecSmrg
24405b261ecSmrgvoid
24505b261ecSmrgxnestPolyFillArc(DrawablePtr pDrawable, GCPtr pGC, int nArcs, xArc *pArcs)
24605b261ecSmrg{
24705b261ecSmrg  XFillArcs(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
24805b261ecSmrg            (XArc *)pArcs, nArcs);
24905b261ecSmrg}
25005b261ecSmrg
25105b261ecSmrgint
25205b261ecSmrgxnestPolyText8(DrawablePtr pDrawable, GCPtr pGC, int x, int y, int count,
25305b261ecSmrg	       char *string)
25405b261ecSmrg{
25505b261ecSmrg  int width;
25605b261ecSmrg
25705b261ecSmrg  XDrawString(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
25805b261ecSmrg              x, y, string, count);
25905b261ecSmrg
26005b261ecSmrg  width = XTextWidth(xnestFontStruct(pGC->font), string, count);
26105b261ecSmrg
26205b261ecSmrg  return width + x;
26305b261ecSmrg}
26405b261ecSmrg
26505b261ecSmrgint
26605b261ecSmrgxnestPolyText16(DrawablePtr pDrawable, GCPtr pGC, int x, int y, int count,
26705b261ecSmrg		unsigned short *string)
26805b261ecSmrg{
26905b261ecSmrg  int width;
27005b261ecSmrg
27105b261ecSmrg  XDrawString16(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
27205b261ecSmrg                x, y, (XChar2b *)string, count);
27305b261ecSmrg
27405b261ecSmrg  width = XTextWidth16(xnestFontStruct(pGC->font), (XChar2b *)string, count);
27505b261ecSmrg
27605b261ecSmrg  return width + x;
27705b261ecSmrg}
27805b261ecSmrg
27905b261ecSmrgvoid
28005b261ecSmrgxnestImageText8(DrawablePtr pDrawable, GCPtr pGC, int x, int y, int count,
28105b261ecSmrg		char *string)
28205b261ecSmrg{
28305b261ecSmrg  XDrawImageString(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
28405b261ecSmrg                   x, y, string, count);
28505b261ecSmrg}
28605b261ecSmrg
28705b261ecSmrgvoid
28805b261ecSmrgxnestImageText16(DrawablePtr pDrawable, GCPtr pGC, int x, int y, int count,
28905b261ecSmrg		 unsigned short *string)
29005b261ecSmrg{
29105b261ecSmrg  XDrawImageString16(xnestDisplay, xnestDrawable(pDrawable), xnestGC(pGC),
29205b261ecSmrg                     x, y, (XChar2b *)string, count);
29305b261ecSmrg}
29405b261ecSmrg
29505b261ecSmrgvoid
29605b261ecSmrgxnestImageGlyphBlt(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
29705b261ecSmrg		   unsigned int nGlyphs, CharInfoPtr *pCharInfo,
29805b261ecSmrg		   pointer pGlyphBase)
29905b261ecSmrg{
30005b261ecSmrg  ErrorF("xnest warning: function xnestImageGlyphBlt not implemented\n");
30105b261ecSmrg}
30205b261ecSmrg
30305b261ecSmrgvoid
30405b261ecSmrgxnestPolyGlyphBlt(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
30505b261ecSmrg		  unsigned int nGlyphs, CharInfoPtr *pCharInfo,
30605b261ecSmrg		  pointer pGlyphBase)
30705b261ecSmrg{
30805b261ecSmrg  ErrorF("xnest warning: function xnestPolyGlyphBlt not implemented\n");
30905b261ecSmrg}
31005b261ecSmrg
31105b261ecSmrgvoid
31205b261ecSmrgxnestPushPixels(GCPtr pGC, PixmapPtr pBitmap, DrawablePtr pDst,
31305b261ecSmrg		int width, int height, int x, int y)
31405b261ecSmrg{
31505b261ecSmrg  /* only works for solid bitmaps */
31605b261ecSmrg  if (pGC->fillStyle == FillSolid)
31705b261ecSmrg  {
31805b261ecSmrg    XSetStipple (xnestDisplay, xnestGC(pGC), xnestPixmap(pBitmap));
31905b261ecSmrg    XSetTSOrigin (xnestDisplay, xnestGC(pGC), x, y);
32005b261ecSmrg    XSetFillStyle (xnestDisplay, xnestGC(pGC), FillStippled);
32105b261ecSmrg    XFillRectangle (xnestDisplay, xnestDrawable(pDst),
32205b261ecSmrg		    xnestGC(pGC), x, y, width, height);
32305b261ecSmrg    XSetFillStyle (xnestDisplay, xnestGC(pGC), FillSolid);
32405b261ecSmrg  }
32505b261ecSmrg  else
32605b261ecSmrg    ErrorF("xnest warning: function xnestPushPixels not implemented\n");
32705b261ecSmrg}
328