Bug 629799, part 3: Ensure that SharedDIBWins are aligned well for alpha recovery. r=jimm
authorChris Jones <jones.chris.g@gmail.com>
Wed, 16 Feb 2011 16:43:30 -0600
changeset 62694 7e8fb5a646dae92615a816e856b8f403b5cd3a77
parent 62693 2be3da6a6531090be8a1c31ff643c54c726cdfa3
child 62695 663d27e9098c3e6a8af9f439b02e427305f4bd1a
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs629799
milestone2.0b12pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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;
 }