Bug 629799, part 3: Ensure that SharedDIBWins are aligned well for alpha recovery. r=jimm
authorChris Jones <jones.chris.g@gmail.com>
Tue, 08 Feb 2011 18:44:12 -0600
changeset 62196 66459fa063f3b9dfb09557c3e1fcd982117159d7
parent 62195 e9279a68304de8dc6f9419ea236ff49cebee7942
child 62197 0903dd13cb784449bcfd706587d001964530f3cc
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersjimm
bugs629799
milestone2.0b12pre
Bug 629799, part 3: Ensure that SharedDIBWins are aligned well for alpha recovery. r=jimm
gfx/ipc/SharedDIBWin.cpp
--- a/gfx/ipc/SharedDIBWin.cpp
+++ b/gfx/ipc/SharedDIBWin.cpp
@@ -32,23 +32,27 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "SharedDIBWin.h"
+#include "gfxAlphaRecovery.h"
 #include "nsMathUtils.h"
 #include "nsDebug.h"
 
 namespace mozilla {
 namespace gfx {
 
 static const PRUint32 kBytesPerPixel = 4;
+static const PRUint32 kByteAlign = 1 << gfxAlphaRecovery::GoodAlignmentLog2();
+static const PRUint32 kHeaderBytes =
+  (sizeof(BITMAPV4HEADER) + kByteAlign - 1) & ~(kByteAlign - 1);
 
 SharedDIBWin::SharedDIBWin() :
     mSharedHdc(nsnull)
   , mSharedBmp(nsnull)
   , mOldObj(nsnull)
 {
 }
 
@@ -135,33 +139,33 @@ SharedDIBWin::SetupBitmapHeader(PRUint32
   aHeader->bV4V4Compression = BI_BITFIELDS;
   aHeader->bV4RedMask       = 0x00FF0000;
   aHeader->bV4GreenMask     = 0x0000FF00;
   aHeader->bV4BlueMask      = 0x000000FF;
 
   if (aTransparent)
     aHeader->bV4AlphaMask     = 0xFF000000;
 
-  return (sizeof(BITMAPV4HEADER) + (-aHeader->bV4Height * aHeader->bV4Width * kBytesPerPixel));
+  return (kHeaderBytes + (-aHeader->bV4Height * aHeader->bV4Width * kBytesPerPixel));
 }
 
 nsresult
 SharedDIBWin::SetupSurface(HDC aHdc, BITMAPV4HEADER *aHdr)
 {
   mSharedHdc = ::CreateCompatibleDC(aHdc);
 
   if (!mSharedHdc)
     return NS_ERROR_FAILURE;
 
   mSharedBmp = ::CreateDIBSection(mSharedHdc,
                                   (BITMAPINFO*)aHdr,
                                   DIB_RGB_COLORS,
                                   &mBitmapBits,
                                   mShMem->handle(),
-                                  (unsigned long)sizeof(BITMAPV4HEADER));
+                                  kHeaderBytes);
   if (!mSharedBmp)
     return NS_ERROR_FAILURE;
 
   mOldObj = SelectObject(mSharedHdc, mSharedBmp);
 
   return NS_OK;
 }