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