Release 980413
[wine] / graphics / x11drv / clipping.c
1 /*
2  * X11DRV clipping functions
3  *
4  * Copyright 1998 Huw Davies
5  */
6
7 #include <stdio.h>
8 #include "dc.h"
9 #include "x11drv.h"
10 #include "region.h"
11 #include "debug.h"
12 #include "heap.h"
13
14 /***********************************************************************
15  *           X11DRV_SetDeviceClipping
16  *           Copy RECT32s to a temporary buffer of XRectangles and call
17  *           TSXSetClipRectangles().
18  *
19  *           Could write using GetRegionData but this would be slower.
20  */
21 void X11DRV_SetDeviceClipping( DC * dc )
22 {
23     XRectangle *pXrect;
24     RGNOBJ *obj = (RGNOBJ *) GDI_GetObjPtr(dc->w.hGCClipRgn, REGION_MAGIC);
25     if (!obj)
26     {
27         fprintf( stderr, "X11DRV_SetDeviceClipping: Rgn is 0. Please report this.\n");
28         exit(1);
29     }
30     
31     if (obj->rgn->numRects > 0)
32     {
33         XRectangle *pXr;
34         RECT32 *pRect = obj->rgn->rects;
35         RECT32 *pEndRect = obj->rgn->rects + obj->rgn->numRects;
36
37         pXrect = HeapAlloc( GetProcessHeap(), 0, 
38                             sizeof(*pXrect) * obj->rgn->numRects );
39         if(!pXrect)
40         {
41             fprintf(stderr, "X11DRV_SetDeviceClipping() can't alloc buffer\n");
42             return;
43         }
44
45         for(pXr = pXrect; pRect < pEndRect; pRect++, pXr++)
46         {
47             pXr->x = pRect->left;
48             pXr->y = pRect->top;
49             pXr->width = pRect->right - pRect->left;
50             pXr->height = pRect->bottom - pRect->top;
51         }
52     }
53     else
54         pXrect = NULL;
55
56     TSXSetClipRectangles( display, dc->u.x.gc, dc->w.DCOrgX, dc->w.DCOrgY, 
57                 pXrect, obj->rgn->numRects, YXBanded );
58
59     if(pXrect)
60         HeapFree( GetProcessHeap(), 0, pXrect );
61
62     GDI_HEAP_UNLOCK( dc->w.hGCClipRgn );
63 }