1996-10-23 18:59:13 +02:00
|
|
|
/*
|
1998-01-18 19:01:49 +01:00
|
|
|
* X11DRV clipping functions
|
1996-10-23 18:59:13 +02:00
|
|
|
*
|
1998-01-18 19:01:49 +01:00
|
|
|
* Copyright 1998 Huw Davies
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1996-10-23 18:59:13 +02:00
|
|
|
*/
|
|
|
|
|
1999-02-04 12:11:01 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
1998-12-26 13:00:43 +01:00
|
|
|
#include "ts_xlib.h"
|
|
|
|
|
1996-10-23 18:59:13 +02:00
|
|
|
#include <stdio.h>
|
2000-04-25 21:55:35 +02:00
|
|
|
|
2000-11-05 03:05:07 +01:00
|
|
|
#include "gdi.h"
|
1996-10-23 18:59:13 +02:00
|
|
|
#include "x11drv.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1996-10-23 18:59:13 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
1996-10-23 18:59:13 +02:00
|
|
|
/***********************************************************************
|
2002-05-26 00:16:12 +02:00
|
|
|
* X11DRV_GetRegionData
|
1998-01-18 19:01:49 +01:00
|
|
|
*
|
2002-05-26 00:16:12 +02:00
|
|
|
* Calls GetRegionData on the given region and converts the rectangle
|
|
|
|
* array to XRectangle format. The returned buffer must be freed by
|
|
|
|
* caller using HeapFree(GetProcessHeap(),...).
|
|
|
|
* If hdc_lptodp is not 0, the rectangles are converted through LPtoDP.
|
1996-10-23 18:59:13 +02:00
|
|
|
*/
|
2002-05-26 00:16:12 +02:00
|
|
|
RGNDATA *X11DRV_GetRegionData( HRGN hrgn, HDC hdc_lptodp )
|
1996-10-23 18:59:13 +02:00
|
|
|
{
|
2002-05-26 00:16:12 +02:00
|
|
|
RGNDATA *data;
|
|
|
|
DWORD size;
|
|
|
|
int i;
|
|
|
|
RECT *rect, tmp;
|
|
|
|
XRectangle *xrect;
|
2002-03-28 23:22:05 +01:00
|
|
|
|
2002-05-26 00:16:12 +02:00
|
|
|
if (!(size = GetRegionData( hrgn, 0, NULL ))) return NULL;
|
|
|
|
if (sizeof(XRectangle) > sizeof(RECT))
|
1996-10-23 18:59:13 +02:00
|
|
|
{
|
2002-05-26 00:16:12 +02:00
|
|
|
/* add extra size for XRectangle array */
|
|
|
|
int count = (size - sizeof(RGNDATAHEADER)) / sizeof(RECT);
|
|
|
|
size += count * (sizeof(XRectangle) - sizeof(RECT));
|
1996-10-23 18:59:13 +02:00
|
|
|
}
|
2002-05-26 00:16:12 +02:00
|
|
|
if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL;
|
|
|
|
if (!GetRegionData( hrgn, size, data ))
|
1996-10-23 18:59:13 +02:00
|
|
|
{
|
2002-05-26 00:16:12 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, data );
|
|
|
|
return NULL;
|
|
|
|
}
|
1998-01-18 19:01:49 +01:00
|
|
|
|
2002-05-26 00:16:12 +02:00
|
|
|
rect = (RECT *)data->Buffer;
|
|
|
|
xrect = (XRectangle *)data->Buffer;
|
|
|
|
if (hdc_lptodp) /* map to device coordinates */
|
|
|
|
{
|
|
|
|
LPtoDP( hdc_lptodp, (POINT *)rect, data->rdh.nCount * 2 );
|
|
|
|
for (i = 0; i < data->rdh.nCount; i++)
|
|
|
|
{
|
|
|
|
if (rect[i].right < rect[i].left)
|
|
|
|
{
|
|
|
|
INT tmp = rect[i].right;
|
|
|
|
rect[i].right = rect[i].left;
|
|
|
|
rect[i].left = tmp;
|
|
|
|
}
|
|
|
|
if (rect[i].bottom < rect[i].top)
|
|
|
|
{
|
|
|
|
INT tmp = rect[i].bottom;
|
|
|
|
rect[i].bottom = rect[i].top;
|
|
|
|
rect[i].top = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-01-18 19:01:49 +01:00
|
|
|
|
2002-05-26 00:16:12 +02:00
|
|
|
if (sizeof(XRectangle) > sizeof(RECT))
|
|
|
|
{
|
|
|
|
/* need to start from the end */
|
|
|
|
for (i = data->rdh.nCount-1; i >=0; i--)
|
1998-01-18 19:01:49 +01:00
|
|
|
{
|
2002-05-26 00:16:12 +02:00
|
|
|
tmp = rect[i];
|
|
|
|
xrect[i].x = tmp.left;
|
|
|
|
xrect[i].y = tmp.top;
|
|
|
|
xrect[i].width = tmp.right - tmp.left;
|
|
|
|
xrect[i].height = tmp.bottom - tmp.top;
|
1998-01-18 19:01:49 +01:00
|
|
|
}
|
1996-10-23 18:59:13 +02:00
|
|
|
}
|
1998-01-18 19:01:49 +01:00
|
|
|
else
|
2002-05-26 00:16:12 +02:00
|
|
|
{
|
|
|
|
for (i = 0; i < data->rdh.nCount; i++)
|
|
|
|
{
|
|
|
|
tmp = rect[i];
|
|
|
|
xrect[i].x = tmp.left;
|
|
|
|
xrect[i].y = tmp.top;
|
|
|
|
xrect[i].width = tmp.right - tmp.left;
|
|
|
|
xrect[i].height = tmp.bottom - tmp.top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
1998-01-18 19:01:49 +01:00
|
|
|
|
|
|
|
|
2002-05-26 00:16:12 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_SetDeviceClipping
|
|
|
|
*/
|
|
|
|
void X11DRV_SetDeviceClipping( X11DRV_PDEVICE *physDev, HRGN hrgn )
|
|
|
|
{
|
|
|
|
RGNDATA *data;
|
1998-01-18 19:01:49 +01:00
|
|
|
|
2002-05-26 00:16:12 +02:00
|
|
|
if (!(data = X11DRV_GetRegionData( hrgn, 0 ))) return;
|
2002-06-11 00:52:47 +02:00
|
|
|
TSXSetClipRectangles( gdi_display, physDev->gc, physDev->org.x, physDev->org.y,
|
2002-05-26 00:16:12 +02:00
|
|
|
(XRectangle *)data->Buffer, data->rdh.nCount, YXBanded );
|
|
|
|
HeapFree( GetProcessHeap(), 0, data );
|
1996-10-23 18:59:13 +02:00
|
|
|
}
|
1999-02-04 12:11:01 +01:00
|
|
|
|
2001-06-04 23:55:17 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_SetDrawable
|
|
|
|
*
|
|
|
|
* Set the drawable, clipping mode and origin for a DC.
|
|
|
|
*/
|
2002-06-11 00:52:47 +02:00
|
|
|
void X11DRV_SetDrawable( HDC hdc, Drawable drawable, int mode, const POINT *org,
|
|
|
|
const POINT *drawable_org )
|
2001-06-04 23:55:17 +02:00
|
|
|
{
|
|
|
|
DC *dc = DC_GetDCPtr( hdc );
|
|
|
|
if (dc)
|
|
|
|
{
|
2002-03-28 23:22:05 +01:00
|
|
|
X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
|
2002-06-11 00:52:47 +02:00
|
|
|
|
|
|
|
physDev->org = *org;
|
2001-06-04 23:55:17 +02:00
|
|
|
physDev->drawable = drawable;
|
2002-06-11 00:52:47 +02:00
|
|
|
physDev->drawable_org = *drawable_org;
|
2001-06-04 23:55:17 +02:00
|
|
|
TSXSetSubwindowMode( gdi_display, physDev->gc, mode );
|
2002-01-29 04:07:21 +01:00
|
|
|
if(physDev->xrender)
|
2002-03-28 23:22:05 +01:00
|
|
|
X11DRV_XRender_UpdateDrawable( physDev );
|
2001-06-04 23:55:17 +02:00
|
|
|
GDI_ReleaseObj( hdc );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_StartGraphicsExposures
|
|
|
|
*
|
|
|
|
* Set the DC in graphics exposures mode
|
|
|
|
*/
|
|
|
|
void X11DRV_StartGraphicsExposures( HDC hdc )
|
|
|
|
{
|
|
|
|
DC *dc = DC_GetDCPtr( hdc );
|
|
|
|
if (dc)
|
|
|
|
{
|
2002-03-28 23:22:05 +01:00
|
|
|
X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
|
2001-06-04 23:55:17 +02:00
|
|
|
TSXSetGraphicsExposures( gdi_display, physDev->gc, True );
|
2001-06-11 22:24:57 +02:00
|
|
|
physDev->exposures = 0;
|
2001-06-04 23:55:17 +02:00
|
|
|
GDI_ReleaseObj( hdc );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_EndGraphicsExposures
|
|
|
|
*
|
|
|
|
* End the graphics exposures mode and process the events
|
|
|
|
*/
|
|
|
|
void X11DRV_EndGraphicsExposures( HDC hdc, HRGN hrgn )
|
|
|
|
{
|
|
|
|
HRGN tmp = 0;
|
|
|
|
DC *dc = DC_GetDCPtr( hdc );
|
|
|
|
|
|
|
|
if (dc)
|
|
|
|
{
|
|
|
|
XEvent event;
|
2002-03-28 23:22:05 +01:00
|
|
|
X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
|
2001-06-04 23:55:17 +02:00
|
|
|
|
|
|
|
SetRectRgn( hrgn, 0, 0, 0, 0 );
|
|
|
|
wine_tsx11_lock();
|
|
|
|
XSetGraphicsExposures( gdi_display, physDev->gc, False );
|
2001-06-11 22:24:57 +02:00
|
|
|
if (physDev->exposures)
|
2001-06-04 23:55:17 +02:00
|
|
|
{
|
2001-06-11 22:24:57 +02:00
|
|
|
XSync( gdi_display, False );
|
|
|
|
for (;;)
|
2001-06-04 23:55:17 +02:00
|
|
|
{
|
2001-06-11 22:24:57 +02:00
|
|
|
XWindowEvent( gdi_display, physDev->drawable, ~0, &event );
|
|
|
|
if (event.type == NoExpose) break;
|
|
|
|
if (event.type == GraphicsExpose)
|
|
|
|
{
|
2002-06-11 00:52:47 +02:00
|
|
|
int x = event.xgraphicsexpose.x - physDev->org.x;
|
|
|
|
int y = event.xgraphicsexpose.y - physDev->org.y;
|
2001-06-20 02:18:15 +02:00
|
|
|
|
2001-06-11 22:24:57 +02:00
|
|
|
TRACE( "got %d,%d %dx%d count %d\n",
|
2001-06-20 02:18:15 +02:00
|
|
|
x, y, event.xgraphicsexpose.width, event.xgraphicsexpose.height,
|
|
|
|
event.xgraphicsexpose.count );
|
2001-06-11 22:24:57 +02:00
|
|
|
|
|
|
|
if (!tmp) tmp = CreateRectRgn( 0, 0, 0, 0 );
|
2001-06-20 02:18:15 +02:00
|
|
|
SetRectRgn( tmp, x, y,
|
|
|
|
x + event.xgraphicsexpose.width,
|
|
|
|
y + event.xgraphicsexpose.height );
|
2001-06-11 22:24:57 +02:00
|
|
|
CombineRgn( hrgn, hrgn, tmp, RGN_OR );
|
|
|
|
if (!event.xgraphicsexpose.count) break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR( "got unexpected event %d\n", event.type );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tmp) DeleteObject( tmp );
|
2001-06-04 23:55:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
GDI_ReleaseObj( hdc );
|
|
|
|
}
|
|
|
|
}
|