]> git.saurik.com Git - wxWidgets.git/commitdiff
use StretchDIBits() if we're drawing a DIB and not a DDB in Blit()
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 24 Mar 2003 23:10:41 +0000 (23:10 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 24 Mar 2003 23:10:41 +0000 (23:10 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19789 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/dc.cpp

index 64e2dda0db9d0318d34d99ec4a23aa401558a74c..e36e35dfc86b902334f0724ae70a7bb7cf7f0bbd 100644 (file)
@@ -1828,13 +1828,14 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest,
     if (!GetHDC()) return FALSE;
 #endif
 
+    const wxBitmap& bmpSrc = source->m_selectedBitmap;
+
     wxMask *mask = NULL;
     if ( useMask )
     {
-        const wxBitmap& bmp = source->m_selectedBitmap;
-        mask = bmp.GetMask();
+        mask = bmpSrc.GetMask();
 
-        if ( !(bmp.Ok() && mask && mask->GetMaskBitmap()) )
+        if ( !(bmpSrc.Ok() && mask && mask->GetMaskBitmap()) )
         {
             // don't give assert here because this would break existing
             // programs - just silently ignore useMask parameter
@@ -1998,36 +1999,79 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest,
     }
     else // no mask, just BitBlt() it
     {
-        // use StretchBlt() if available
-        if ( ::GetDeviceCaps(GetHdc(), RASTERCAPS) & RC_STRETCHBLT )
+        // if we already have a DIB, draw it using StretchDIBits(), otherwise
+        // use StretchBlt() if available and finally fall back to BitBlt()
+        const int caps = ::GetDeviceCaps(GetHdc(), RASTERCAPS);
+        if ( bmpSrc.Ok() && (caps & RC_STRETCHDIB) )
         {
-            StretchBltModeChanger changeMode(GetHdc(), COLORONCOLOR);
+            DIBSECTION ds;
+            wxZeroMemory(ds);
 
-            success = ::StretchBlt
-                        (
-                            GetHdc(),
-                            xdest, ydest, width, height,
-                            GetHdcOf(*source),
-                            xsrc, ysrc, width, height,
-                            dwRop
-                        ) != 0;
+            if ( ::GetObject(GetHbitmapOf(bmpSrc),
+                             sizeof(ds),
+                             &ds) == sizeof(ds) )
+            {
+                StretchBltModeChanger changeMode(GetHdc(), COLORONCOLOR);
+
+                if ( ::StretchDIBits(GetHdc(),
+                                     xdest, ydest,
+                                     width, height,
+                                     0, 0,
+                                     width, height,
+                                     ds.dsBm.bmBits,
+                                     (LPBITMAPINFO)&ds.dsBmih,
+                                     DIB_RGB_COLORS,
+                                     SRCCOPY
+                                     ) == (int)GDI_ERROR )
+                {
+                    wxLogLastError(wxT("StretchDIBits"));
+                }
+                else
+                {
+                    success = TRUE;
+                }
+            }
         }
-        else
+
+        if ( !success && (caps & RC_STRETCHBLT) )
         {
-            success = ::BitBlt
-                        (
-                            GetHdc(),
-                            xdest, ydest,
-                            (int)width, (int)height,
-                            GetHdcOf(*source),
-                            xsrc, ysrc,
-                            dwRop
-                        ) != 0;
+            StretchBltModeChanger changeMode(GetHdc(), COLORONCOLOR);
+
+            if ( !::StretchBlt
+                    (
+                        GetHdc(),
+                        xdest, ydest, width, height,
+                        GetHdcOf(*source),
+                        xsrc, ysrc, width, height,
+                        dwRop
+                    ) )
+            {
+                wxLogLastError(_T("StretchBlt"));
+            }
+            else
+            {
+                success = TRUE;
+            }
         }
 
         if ( !success )
         {
-            wxLogLastError(wxT("BitBlt/StretchBlt"));
+            if ( !::BitBlt
+                    (
+                        GetHdc(),
+                        xdest, ydest,
+                        (int)width, (int)height,
+                        GetHdcOf(*source),
+                        xsrc, ysrc,
+                        dwRop
+                    ) )
+            {
+                wxLogLastError(_T("BitBlt"));
+            }
+            else
+            {
+                success = TRUE;
+            }
         }
     }