Rob Shearman : gdi32: Optimise StretchBlt for the case where no stretching is being done and the whole image is being set .

Alexandre Julliard julliard at winehq.org
Fri Feb 22 05:49:33 CST 2008


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

Author: Rob Shearman <rob at codeweavers.com>
Date:   Thu Feb 21 16:44:52 2008 +0000

gdi32: Optimise StretchBlt for the case where no stretching is being done and the whole image is being set.

In this case, we can just call SetDIBits which is likely to be a lot faster.

---

 dlls/gdi32/dib.c |  118 ++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 75 insertions(+), 43 deletions(-)

diff --git a/dlls/gdi32/dib.c b/dlls/gdi32/dib.c
index e8b3dc9..d53b8f2 100644
--- a/dlls/gdi32/dib.c
+++ b/dlls/gdi32/dib.c
@@ -205,13 +205,12 @@ INT WINAPI StretchDIBits(HDC hdc, INT xDst, INT yDst, INT widthDst,
     }
     else /* use StretchBlt */
     {
-        HBITMAP hBitmap, hOldBitmap;
-        HPALETTE hpal = NULL;
-        HDC hdcMem;
         LONG height;
         LONG width;
         WORD planes, bpp;
         DWORD compr, size;
+        HBITMAP hBitmap;
+        BOOL fastpath = FALSE;
 
         release_dc_ptr( dc );
 
@@ -227,51 +226,84 @@ INT WINAPI StretchDIBits(HDC hdc, INT xDst, INT yDst, INT widthDst,
             return 0;
         }
 
-	hdcMem = CreateCompatibleDC( hdc );
-        hBitmap = CreateCompatibleBitmap(hdc, width, height);
-        hOldBitmap = SelectObject( hdcMem, hBitmap );
-        if(wUsage == DIB_PAL_COLORS)
+        hBitmap = GetCurrentObject(hdc, OBJ_BITMAP);
+
+        if (xDst == 0 && yDst == 0 && xSrc == 0 && ySrc == 0 &&
+            widthDst == widthSrc && heightDst == heightSrc &&
+            info->bmiHeader.biCompression == BI_RGB &&
+            dwRop == SRCCOPY)
         {
-            hpal = GetCurrentObject(hdc, OBJ_PAL);
-            hpal = SelectPalette(hdcMem, hpal, FALSE);
+            BITMAPOBJ *bmp;
+            if ((bmp = (BITMAPOBJ *)GDI_GetObjPtr( hBitmap, BITMAP_MAGIC )))
+            {
+                if (bmp->bitmap.bmBitsPixel == bpp &&
+                    bmp->bitmap.bmWidth == widthSrc &&
+                    bmp->bitmap.bmHeight == heightSrc &&
+                    bmp->bitmap.bmPlanes == planes)
+                    fastpath = TRUE;
+                GDI_ReleaseObj( hBitmap );
+            }
         }
 
-	if (info->bmiHeader.biCompression == BI_RLE4 ||
-	    info->bmiHeader.biCompression == BI_RLE8) {
-
-	   /* when RLE compression is used, there may be some gaps (ie the DIB doesn't
-	    * contain all the rectangle described in bmiHeader, but only part of it.
-	    * This mean that those undescribed pixels must be left untouched.
-	    * So, we first copy on a memory bitmap the current content of the
-	    * destination rectangle, blit the DIB bits on top of it - hence leaving
-	    * the gaps untouched -, and blitting the rectangle back.
-	    * This insure that gaps are untouched on the destination rectangle
-	    * Not doing so leads to trashed images (the gaps contain what was on the
-	    * memory bitmap => generally black or garbage)
-	    * Unfortunately, RLE DIBs without gaps will be slowed down. But this is
-	    * another speed vs correctness issue. Anyway, if speed is needed, then the
-	    * pStretchDIBits function shall be implemented.
-	    * ericP (2000/09/09)
-	    */
-
-            /* copy existing bitmap from destination dc */
-            StretchBlt( hdcMem, xSrc, abs(height) - heightSrc - ySrc,
-                        widthSrc, heightSrc, hdc, xDst, yDst, widthDst, heightDst,
-                        dwRop );
+        if (fastpath)
+        {
+            /* fast path */
+            TRACE("using fast path\n");
+            heightSrc = SetDIBits( hdc, hBitmap, 0, height, bits, info, wUsage);
         }
+        else
+        {
+            /* slow path - need to use StretchBlt */
+            HBITMAP hOldBitmap;
+            HPALETTE hpal = NULL;
+            HDC hdcMem;
+
+            hdcMem = CreateCompatibleDC( hdc );
+            hBitmap = CreateCompatibleBitmap(hdc, width, height);
+            hOldBitmap = SelectObject( hdcMem, hBitmap );
+            if(wUsage == DIB_PAL_COLORS)
+            {
+                hpal = GetCurrentObject(hdc, OBJ_PAL);
+                hpal = SelectPalette(hdcMem, hpal, FALSE);
+            }
 
-        SetDIBits(hdcMem, hBitmap, 0, height, bits, info, wUsage);
-
-        /* Origin for DIBitmap may be bottom left (positive biHeight) or top
-           left (negative biHeight) */
-        StretchBlt( hdc, xDst, yDst, widthDst, heightDst,
-		    hdcMem, xSrc, abs(height) - heightSrc - ySrc,
-		    widthSrc, heightSrc, dwRop );
-        if(hpal)
-            SelectPalette(hdcMem, hpal, FALSE);
-	SelectObject( hdcMem, hOldBitmap );
-	DeleteDC( hdcMem );
-	DeleteObject( hBitmap );
+            if (info->bmiHeader.biCompression == BI_RLE4 ||
+	            info->bmiHeader.biCompression == BI_RLE8) {
+
+                /* when RLE compression is used, there may be some gaps (ie the DIB doesn't
+                 * contain all the rectangle described in bmiHeader, but only part of it.
+                 * This mean that those undescribed pixels must be left untouched.
+                 * So, we first copy on a memory bitmap the current content of the
+                 * destination rectangle, blit the DIB bits on top of it - hence leaving
+                 * the gaps untouched -, and blitting the rectangle back.
+                 * This insure that gaps are untouched on the destination rectangle
+                 * Not doing so leads to trashed images (the gaps contain what was on the
+                 * memory bitmap => generally black or garbage)
+                 * Unfortunately, RLE DIBs without gaps will be slowed down. But this is
+                 * another speed vs correctness issue. Anyway, if speed is needed, then the
+                 * pStretchDIBits function shall be implemented.
+                 * ericP (2000/09/09)
+                 */
+
+                /* copy existing bitmap from destination dc */
+                StretchBlt( hdcMem, xSrc, abs(height) - heightSrc - ySrc,
+                            widthSrc, heightSrc, hdc, xDst, yDst, widthDst, heightDst,
+                            dwRop );
+            }
+
+            SetDIBits(hdcMem, hBitmap, 0, height, bits, info, wUsage);
+
+            /* Origin for DIBitmap may be bottom left (positive biHeight) or top
+               left (negative biHeight) */
+            StretchBlt( hdc, xDst, yDst, widthDst, heightDst,
+                hdcMem, xSrc, abs(height) - heightSrc - ySrc,
+                widthSrc, heightSrc, dwRop );
+            if(hpal)
+                SelectPalette(hdcMem, hpal, FALSE);
+            SelectObject( hdcMem, hOldBitmap );
+            DeleteDC( hdcMem );
+            DeleteObject( hBitmap );
+        }
     }
     return heightSrc;
 }




More information about the wine-cvs mailing list