diff --git a/mozilla/gfx/src/windows/nsImageWin.cpp b/mozilla/gfx/src/windows/nsImageWin.cpp index bcd61c210e1..eea1f487a5a 100644 --- a/mozilla/gfx/src/windows/nsImageWin.cpp +++ b/mozilla/gfx/src/windows/nsImageWin.cpp @@ -62,6 +62,8 @@ nsImageWin :: nsImageWin() mNaturalWidth = 0; mNaturalHeight = 0; + mIsLocked = PR_FALSE; + mDIBTemp = PR_FALSE; //CleanUp(PR_TRUE); CleanUpDDB(); @@ -1078,7 +1080,7 @@ UINT palType; if (mImageBits != nsnull) { delete [] mImageBits; mImageBits = nsnull; - } + } } } @@ -1194,30 +1196,40 @@ PRInt16 numPaletteColors; NS_IMETHODIMP nsImageWin::LockImagePixels(PRBool aMaskPixels) { - /* - if (!mHBitmap) - return NS_ERROR_NOT_INITIALIZED; - - ... and do Windows locking of image pixels here, if necessary -*/ + /* if (!mHBitmap) return NS_ERROR_NOT_INITIALIZED; + ... and do Windows locking of image pixels here, if necessary */ + + mIsLocked = PR_TRUE; + return NS_OK; } /** --------------------------------------------------- - * Unlock the pixels + * Unlock the pixels, optimize this nsImageWin */ NS_IMETHODIMP nsImageWin::UnlockImagePixels(PRBool aMaskPixels) { - /* - if (!mHBitmap) + mIsLocked = PR_FALSE; + // if memory was allocated temporarily by GetBits, it can now be deleted safely + if (mDIBTemp == PR_TRUE) { + // get rid of this memory + if (mImageBits != nsnull) { + delete [] mImageBits; + mImageBits = nsnull; + } + + mDIBTemp = PR_FALSE; + } + + /* if (!mHBitmap) return NS_ERROR_NOT_INITIALIZED; if (aMaskPixels && !mAlphamHBitmap) return NS_ERROR_NOT_INITIALIZED; - ... and do Windows unlocking of image pixels here, if necessary - */ + ... and do Windows unlocking of image pixels here, if necessary */ + return NS_OK; } /** --------------------------------------------------- @@ -1268,7 +1280,8 @@ nsRect destRect; /** * Get a pointer to the bits for the pixelmap. Will convert to DIB if - * only stored in optimized HBITMAP form. + * only stored in optimized HBITMAP form. Using this routine will + * set the mDIBTemp flag to true so the next unlock will destroy this memory * * @return address of the DIB pixel array */ @@ -1276,8 +1289,11 @@ nsRect destRect; PRUint8* nsImageWin::GetBits() { - if ( !mImageBits ) + // if mImageBits did not exist.. then + if ( !mImageBits ) { ConvertDDBtoDIB(GetWidth(), GetHeight()); + mDIBTemp = PR_TRUE; // only set to true if the DIB is being created here as temporary + } return mImageBits; diff --git a/mozilla/gfx/src/windows/nsImageWin.h b/mozilla/gfx/src/windows/nsImageWin.h index a072b054dec..3de88402205 100644 --- a/mozilla/gfx/src/windows/nsImageWin.h +++ b/mozilla/gfx/src/windows/nsImageWin.h @@ -246,13 +246,15 @@ private: PRBool mIsOptimized; // Did we convert our DIB to a HBITMAP nsColorMap* mColorMap; // Redundant with mColorTable, but necessary - PRInt32 mDecodedX1; //Keeps track of what part of image - PRInt32 mDecodedY1; // has been decoded. + PRInt32 mDecodedX1; //Keeps track of what part of image + PRInt32 mDecodedY1; // has been decoded. PRInt32 mDecodedX2; - PRInt32 mDecodedY2; + PRInt32 mDecodedY2; + PRBool mIsLocked; // variable to keep track of the locking + PRBool mDIBTemp; // boolean to let us know if DIB was created as temp - PRInt32 mNaturalWidth; - PRInt32 mNaturalHeight; + PRInt32 mNaturalWidth; + PRInt32 mNaturalHeight; // alpha layer members PRUint8 *mAlphaBits; // alpha layer if we made one @@ -260,13 +262,12 @@ private: PRInt16 mARowBytes; // number of bytes per row in the image for tha alpha PRInt16 mAlphaWidth; // alpha layer width PRInt16 mAlphaHeight; // alpha layer height - //nsPoint mLocation; // alpha mask location PRInt8 mImageCache; // place to save off the old image for fast animation PRInt16 mAlphaLevel; // an alpha level every pixel uses HBITMAP mHBitmap; // the GDI bitmaps LPBITMAPINFOHEADER mBHead; // BITMAPINFOHEADER - static ALPHABLENDPROC gAlphaBlend; // AlphaBlend function pointer + static ALPHABLENDPROC gAlphaBlend; // AlphaBlend function pointer };