From fa6dd84904faa04a367d997058e283b64034ad7b Mon Sep 17 00:00:00 2001 From: "paper%animecity.nu" Date: Mon, 7 Mar 2005 02:35:47 +0000 Subject: [PATCH] Bug 284978: Create DDB surface. If failed, try DIB. r=ere, sr=bz --- gfx/src/windows/nsDrawingSurfaceWin.cpp | 30 +++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/gfx/src/windows/nsDrawingSurfaceWin.cpp b/gfx/src/windows/nsDrawingSurfaceWin.cpp index dcaed7d845ff..ec4c5c687564 100644 --- a/gfx/src/windows/nsDrawingSurfaceWin.cpp +++ b/gfx/src/windows/nsDrawingSurfaceWin.cpp @@ -431,11 +431,15 @@ NS_IMETHODIMP nsDrawingSurfaceWin :: Init(HDC aDC, PRUint32 aWidth, if (nsnull == mSurface) #endif { - HBITMAP tbits; + HBITMAP tbits = nsnull; if (aWidth > 0 && aHeight > 0) { - if (aFlags & NS_CREATEDRAWINGSURFACE_FOR_PIXEL_ACCESS) + if ((aFlags & NS_CREATEDRAWINGSURFACE_FOR_PIXEL_ACCESS) == 0) + tbits = ::CreateCompatibleBitmap(aDC, aWidth, aHeight); + + // Create a DIB if we need Pixel Access, or if DDB creation failed + if (nsnull == tbits) { void *bits; BITMAPINFO *binfo; @@ -449,21 +453,19 @@ NS_IMETHODIMP nsDrawingSurfaceWin :: Init(HDC aDC, PRUint32 aWidth, binfo = CreateBitmapInfo(aWidth, aHeight, depth); - if (nsnull != binfo) - mSelectedBitmap = tbits = ::CreateDIBSection(aDC, binfo, DIB_RGB_COLORS, &bits, NULL, 0); + if (nsnull == binfo) + return NS_ERROR_FAILURE; + + mSelectedBitmap = tbits = ::CreateDIBSection(aDC, binfo, DIB_RGB_COLORS, &bits, NULL, 0); if (NULL == mSelectedBitmap) - tbits = ::CreateCompatibleBitmap(aDC, aWidth, aHeight); - else - { - mBitmapInfo = binfo; - mDIBits = (PRUint8 *)bits; - mBitmap.bmWidthBytes = RASWIDTH(aWidth, depth); - mBitmap.bmBitsPixel = depth; - } + return NS_ERROR_FAILURE; + + mBitmapInfo = binfo; + mDIBits = (PRUint8 *)bits; + mBitmap.bmWidthBytes = RASWIDTH(aWidth, depth); + mBitmap.bmBitsPixel = depth; } - else - tbits = ::CreateCompatibleBitmap(aDC, aWidth, aHeight); } else {