Moved DC origin into device-specific structure.
[wine/multimedia.git] / graphics / x11drv / clipping.c
blobdaabf3d61f573566913d04bb9d88114fd1927099
1 /*
2 * X11DRV clipping functions
4 * Copyright 1998 Huw Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include "ts_xlib.h"
25 #include <stdio.h>
27 #include "gdi.h"
28 #include "x11drv.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
33 /***********************************************************************
34 * X11DRV_GetRegionData
36 * Calls GetRegionData on the given region and converts the rectangle
37 * array to XRectangle format. The returned buffer must be freed by
38 * caller using HeapFree(GetProcessHeap(),...).
39 * If hdc_lptodp is not 0, the rectangles are converted through LPtoDP.
41 RGNDATA *X11DRV_GetRegionData( HRGN hrgn, HDC hdc_lptodp )
43 RGNDATA *data;
44 DWORD size;
45 int i;
46 RECT *rect, tmp;
47 XRectangle *xrect;
49 if (!(size = GetRegionData( hrgn, 0, NULL ))) return NULL;
50 if (sizeof(XRectangle) > sizeof(RECT))
52 /* add extra size for XRectangle array */
53 int count = (size - sizeof(RGNDATAHEADER)) / sizeof(RECT);
54 size += count * (sizeof(XRectangle) - sizeof(RECT));
56 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL;
57 if (!GetRegionData( hrgn, size, data ))
59 HeapFree( GetProcessHeap(), 0, data );
60 return NULL;
63 rect = (RECT *)data->Buffer;
64 xrect = (XRectangle *)data->Buffer;
65 if (hdc_lptodp) /* map to device coordinates */
67 LPtoDP( hdc_lptodp, (POINT *)rect, data->rdh.nCount * 2 );
68 for (i = 0; i < data->rdh.nCount; i++)
70 if (rect[i].right < rect[i].left)
72 INT tmp = rect[i].right;
73 rect[i].right = rect[i].left;
74 rect[i].left = tmp;
76 if (rect[i].bottom < rect[i].top)
78 INT tmp = rect[i].bottom;
79 rect[i].bottom = rect[i].top;
80 rect[i].top = tmp;
85 if (sizeof(XRectangle) > sizeof(RECT))
87 /* need to start from the end */
88 for (i = data->rdh.nCount-1; i >=0; i--)
90 tmp = rect[i];
91 xrect[i].x = tmp.left;
92 xrect[i].y = tmp.top;
93 xrect[i].width = tmp.right - tmp.left;
94 xrect[i].height = tmp.bottom - tmp.top;
97 else
99 for (i = 0; i < data->rdh.nCount; i++)
101 tmp = rect[i];
102 xrect[i].x = tmp.left;
103 xrect[i].y = tmp.top;
104 xrect[i].width = tmp.right - tmp.left;
105 xrect[i].height = tmp.bottom - tmp.top;
108 return data;
112 /***********************************************************************
113 * X11DRV_SetDeviceClipping
115 void X11DRV_SetDeviceClipping( X11DRV_PDEVICE *physDev, HRGN hrgn )
117 RGNDATA *data;
119 if (!(data = X11DRV_GetRegionData( hrgn, 0 ))) return;
120 TSXSetClipRectangles( gdi_display, physDev->gc, physDev->org.x, physDev->org.y,
121 (XRectangle *)data->Buffer, data->rdh.nCount, YXBanded );
122 HeapFree( GetProcessHeap(), 0, data );
126 /***********************************************************************
127 * X11DRV_SetDrawable
129 * Set the drawable, clipping mode and origin for a DC.
131 void X11DRV_SetDrawable( HDC hdc, Drawable drawable, int mode, const POINT *org,
132 const POINT *drawable_org )
134 DC *dc = DC_GetDCPtr( hdc );
135 if (dc)
137 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
139 physDev->org = *org;
140 physDev->drawable = drawable;
141 physDev->drawable_org = *drawable_org;
142 TSXSetSubwindowMode( gdi_display, physDev->gc, mode );
143 if(physDev->xrender)
144 X11DRV_XRender_UpdateDrawable( physDev );
145 GDI_ReleaseObj( hdc );
150 /***********************************************************************
151 * X11DRV_StartGraphicsExposures
153 * Set the DC in graphics exposures mode
155 void X11DRV_StartGraphicsExposures( HDC hdc )
157 DC *dc = DC_GetDCPtr( hdc );
158 if (dc)
160 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
161 TSXSetGraphicsExposures( gdi_display, physDev->gc, True );
162 physDev->exposures = 0;
163 GDI_ReleaseObj( hdc );
168 /***********************************************************************
169 * X11DRV_EndGraphicsExposures
171 * End the graphics exposures mode and process the events
173 void X11DRV_EndGraphicsExposures( HDC hdc, HRGN hrgn )
175 HRGN tmp = 0;
176 DC *dc = DC_GetDCPtr( hdc );
178 if (dc)
180 XEvent event;
181 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
183 SetRectRgn( hrgn, 0, 0, 0, 0 );
184 wine_tsx11_lock();
185 XSetGraphicsExposures( gdi_display, physDev->gc, False );
186 if (physDev->exposures)
188 XSync( gdi_display, False );
189 for (;;)
191 XWindowEvent( gdi_display, physDev->drawable, ~0, &event );
192 if (event.type == NoExpose) break;
193 if (event.type == GraphicsExpose)
195 int x = event.xgraphicsexpose.x - physDev->org.x;
196 int y = event.xgraphicsexpose.y - physDev->org.y;
198 TRACE( "got %d,%d %dx%d count %d\n",
199 x, y, event.xgraphicsexpose.width, event.xgraphicsexpose.height,
200 event.xgraphicsexpose.count );
202 if (!tmp) tmp = CreateRectRgn( 0, 0, 0, 0 );
203 SetRectRgn( tmp, x, y,
204 x + event.xgraphicsexpose.width,
205 y + event.xgraphicsexpose.height );
206 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
207 if (!event.xgraphicsexpose.count) break;
209 else
211 ERR( "got unexpected event %d\n", event.type );
212 break;
214 if (tmp) DeleteObject( tmp );
217 wine_tsx11_unlock();
218 GDI_ReleaseObj( hdc );