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