[WIN32K]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Mon, 7 Mar 2011 22:00:19 +0000 (22:00 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Mon, 7 Mar 2011 22:00:19 +0000 (22:00 +0000)
clip the destination rect against the bounds of the destination and source surface. Fixes a crash of gdi32_winetest bitmap that occurs as soon as IntCreateCompatibleBitmap is fixed. Other Eng* code needs to be checked as well.

svn path=/trunk/; revision=50998

reactos/subsystems/win32/win32k/eng/copybits.c

index 1200c1c..0bec04a 100644 (file)
@@ -49,12 +49,28 @@ EngCopyBits(SURFOBJ *psoDest,
     BLTINFO   BltInfo;
     SURFACE *psurfDest;
     SURFACE *psurfSource;
     BLTINFO   BltInfo;
     SURFACE *psurfDest;
     SURFACE *psurfSource;
+    RECTL rclDest = *DestRect;
+    POINTL ptlSrc = *SourcePoint;
 
     ASSERT(psoDest != NULL && psoSource != NULL && DestRect != NULL && SourcePoint != NULL);
 
     psurfSource = CONTAINING_RECORD(psoSource, SURFACE, SurfObj);
     psurfDest = CONTAINING_RECORD(psoDest, SURFACE, SurfObj);
 
 
     ASSERT(psoDest != NULL && psoSource != NULL && DestRect != NULL && SourcePoint != NULL);
 
     psurfSource = CONTAINING_RECORD(psoSource, SURFACE, SurfObj);
     psurfDest = CONTAINING_RECORD(psoDest, SURFACE, SurfObj);
 
+    /* Clip dest rect against source surface size / source point */
+    if (psoSource->sizlBitmap.cx - ptlSrc.x < rclDest.right - rclDest.left)
+        rclDest.right = rclDest.left + psoSource->sizlBitmap.cx - ptlSrc.x;
+    if (psoSource->sizlBitmap.cy - ptlSrc.y < rclDest.bottom - rclDest.top)
+        rclDest.bottom = rclDest.top + psoSource->sizlBitmap.cy - ptlSrc.y;
+
+    /* Clip dest rect against target surface size */
+    if (rclDest.right > psoDest->sizlBitmap.cx)
+        rclDest.right = psoDest->sizlBitmap.cx;
+    if (rclDest.bottom > psoDest->sizlBitmap.cy)
+        rclDest.bottom = psoDest->sizlBitmap.cy;
+    if (RECTL_bIsEmptyRect(&rclDest)) return TRUE;
+    DestRect = &rclDest;
+    
     // FIXME: Don't punt to the driver's DrvCopyBits immediately. Instead,
     //        mark the copy block function to be DrvCopyBits instead of the
     //        GDI's copy bit function so as to remove clipping from the
     // FIXME: Don't punt to the driver's DrvCopyBits immediately. Instead,
     //        mark the copy block function to be DrvCopyBits instead of the
     //        GDI's copy bit function so as to remove clipping from the