gdi32: Add a helper function to clip a rectangle to the DC visible rect.

oldstable
Alexandre Julliard 2011-12-06 12:57:30 +01:00
parent 3284d17ec2
commit 1e2dd7cad8
5 changed files with 30 additions and 25 deletions

View File

@ -104,7 +104,7 @@ BOOL intersect_vis_rectangles( struct bitblt_coords *dst, struct bitblt_coords *
static BOOL get_vis_rectangles( DC *dc_dst, struct bitblt_coords *dst,
DC *dc_src, struct bitblt_coords *src )
{
RECT rect, clip;
RECT rect;
/* get the destination visible rectangle */
@ -124,10 +124,7 @@ static BOOL get_vis_rectangles( DC *dc_dst, struct bitblt_coords *dst,
}
get_bounding_rect( &rect, dst->x, dst->y, dst->width, dst->height );
if (get_clip_box( dc_dst, &clip ))
intersect_rect( &dst->visrect, &rect, &clip );
else
dst->visrect = rect;
clip_visrect( dc_dst, &dst->visrect, &rect );
/* get the source visible rectangle */
@ -408,7 +405,6 @@ BOOL nulldrv_GradientFill( PHYSDEV dev, TRIVERTEX *vert_array, ULONG nvert,
struct gdi_image_bits bits;
unsigned int i;
POINT *pts;
RECT clip;
BOOL ret = TRUE;
DWORD err;
HRGN rgn;
@ -437,9 +433,7 @@ BOOL nulldrv_GradientFill( PHYSDEV dev, TRIVERTEX *vert_array, ULONG nvert,
dst.y = dst.visrect.top;
dst.width = dst.visrect.right - dst.visrect.left;
dst.height = dst.visrect.bottom - dst.visrect.top;
if (get_clip_box( dc, &clip )) intersect_rect( &dst.visrect, &dst.visrect, &clip );
if (is_rect_empty( &dst.visrect )) goto done;
if (!clip_visrect( dc, &dst.visrect, &dst.visrect )) goto done;
/* query the bitmap format */
info->bmiHeader.biSize = sizeof(info->bmiHeader);

View File

@ -57,7 +57,7 @@ static inline RECT get_clip_rect( DC * dc, int left, int top, int right, int bot
*
* Get the clipping rectangle in device coordinates.
*/
int get_clip_box( DC *dc, RECT *rect )
static int get_clip_box( DC *dc, RECT *rect )
{
int ret = ERROR;
HRGN rgn, clip = get_clip_region( dc );
@ -73,6 +73,23 @@ int get_clip_box( DC *dc, RECT *rect )
return ret;
}
/***********************************************************************
* clip_visrect
*
* Clip a rectangle to the DC visible rect.
*/
BOOL clip_visrect( DC *dc, RECT *dst, const RECT *src )
{
RECT clip;
if (!get_clip_box( dc, &clip ))
{
*dst = *src;
return !is_rect_empty( dst );
}
return intersect_rect( dst, src, &clip );
}
/***********************************************************************
* CLIPPING_UpdateGCRegion
*

View File

@ -403,7 +403,7 @@ INT nulldrv_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst, INT he
INT ret = 0;
INT height = abs( src_info->bmiHeader.biHeight );
BOOL top_down = src_info->bmiHeader.biHeight < 0, non_stretch_from_origin = FALSE;
RECT rect, clip_rect;
RECT rect;
TRACE("%d %d %d %d <- %d %d %d %d rop %08x\n", xDst, yDst, widthDst, heightDst,
xSrc, ySrc, widthSrc, heightSrc, rop);
@ -487,11 +487,7 @@ INT nulldrv_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst, INT he
get_bounding_rect( &rect, dst.x, dst.y, dst.width, dst.height );
if (get_clip_box( dc, &clip_rect ))
intersect_rect( &dst.visrect, &rect, &clip_rect );
else
dst.visrect = rect;
if (is_rect_empty( &dst.visrect )) goto done;
if (!clip_visrect( dc, &dst.visrect, &rect )) goto done;
if (!intersect_vis_rectangles( &dst, &src )) goto done;
@ -796,11 +792,11 @@ INT nulldrv_SetDIBitsToDevice( PHYSDEV dev, INT x_dst, INT y_dst, DWORD cx, DWOR
dst.height = cy;
if (GetLayout( dev->hdc ) & LAYOUT_RTL) dst.x -= cx - 1;
dst.visrect.left = dst.x;
dst.visrect.top = dst.y;
dst.visrect.right = dst.x + cx;
dst.visrect.bottom = dst.y + cy;
if (get_clip_box( dc, &rect )) intersect_rect( &dst.visrect, &dst.visrect, &rect );
rect.left = dst.x;
rect.top = dst.y;
rect.right = dst.x + cx;
rect.bottom = dst.y + cy;
if (!clip_visrect( dc, &dst.visrect, &rect )) goto done;
offset_rect( &src.visrect, dst.x - src.x, dst.y - src.y );
intersect_rect( &rect, &src.visrect, &dst.visrect );

View File

@ -1863,13 +1863,11 @@ BOOL nulldrv_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags, const RECT *rect
struct gdi_image_bits bits;
struct bitblt_coords src, dst;
PHYSDEV dst_dev;
RECT clip;
dst_dev = GET_DC_PHYSDEV( dc, pPutImage );
src.visrect = get_total_extents( dev->hdc, x, y, flags, aa_flags, str, count, dx );
if (flags & ETO_CLIPPED) intersect_rect( &src.visrect, &src.visrect, rect );
if (get_clip_box( dc, &clip )) intersect_rect( &src.visrect, &src.visrect, &clip );
if (is_rect_empty( &src.visrect )) return TRUE;
if (!clip_visrect( dc, &src.visrect, &src.visrect )) return TRUE;
/* FIXME: check for ETO_OPAQUE and avoid GetImage */
src.x = src.visrect.left;

View File

@ -212,7 +212,7 @@ extern DWORD stretch_bits( const BITMAPINFO *src_info, struct bitblt_coords *src
extern BOOL get_brush_bitmap_info( HBRUSH handle, BITMAPINFO *info, void **bits, UINT *usage ) DECLSPEC_HIDDEN;
/* clipping.c */
extern int get_clip_box( DC *dc, RECT *rect ) DECLSPEC_HIDDEN;
extern BOOL clip_visrect( DC *dc, RECT *dst, const RECT *src ) DECLSPEC_HIDDEN;
extern void CLIPPING_UpdateGCRegion( DC * dc ) DECLSPEC_HIDDEN;
/* Return the total clip region (if any) */