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

Alexandre Julliard julliard at winehq.org
Tue Dec 6 15:46:18 CST 2011


Module: wine
Branch: master
Commit: 1e2dd7cad83a5e1de5fbb71709e9a69510f4a83f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=1e2dd7cad83a5e1de5fbb71709e9a69510f4a83f

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Dec  6 12:57:30 2011 +0100

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

---

 dlls/gdi32/bitblt.c      |   12 +++---------
 dlls/gdi32/clipping.c    |   19 ++++++++++++++++++-
 dlls/gdi32/dib.c         |   18 +++++++-----------
 dlls/gdi32/font.c        |    4 +---
 dlls/gdi32/gdi_private.h |    2 +-
 5 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/dlls/gdi32/bitblt.c b/dlls/gdi32/bitblt.c
index a7c4918..bfb56a6 100644
--- a/dlls/gdi32/bitblt.c
+++ b/dlls/gdi32/bitblt.c
@@ -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);
diff --git a/dlls/gdi32/clipping.c b/dlls/gdi32/clipping.c
index 70e0e32..53ad56b 100644
--- a/dlls/gdi32/clipping.c
+++ b/dlls/gdi32/clipping.c
@@ -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 );
@@ -74,6 +74,23 @@ int get_clip_box( DC *dc, RECT *rect )
 }
 
 /***********************************************************************
+ *           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
  *
  * Update the GC clip region when the ClipRgn or VisRgn have changed.
diff --git a/dlls/gdi32/dib.c b/dlls/gdi32/dib.c
index bc9564a..0b8bb76 100644
--- a/dlls/gdi32/dib.c
+++ b/dlls/gdi32/dib.c
@@ -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 );
diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index a785283..0d308b0 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -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;
diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h
index fe879ac..c01c2f5 100644
--- a/dlls/gdi32/gdi_private.h
+++ b/dlls/gdi32/gdi_private.h
@@ -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) */




More information about the wine-cvs mailing list