Bug 1023194 - Fix stride calculation on 16 bit images. r=seth, a=2.0+
authorMichael Wu <mwu@mozilla.com>
Tue, 10 Jun 2014 15:44:04 -0400
changeset 207025 4b9df2be31dd206f694c974a2b2fb5bec8a872ba
parent 207024 ae67b93afc271fe921071e61fe903d55d7102321
child 207026 55a22e2c66eddeb29481c1859eaae72fa2985a9f
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersseth, 2
bugs1023194
milestone32.0a2
Bug 1023194 - Fix stride calculation on 16 bit images. r=seth, a=2.0+
image/src/imgFrame.cpp
--- a/image/src/imgFrame.cpp
+++ b/image/src/imgFrame.cpp
@@ -31,41 +31,48 @@ using namespace mozilla::image;
 static UserDataKey kVolatileBuffer;
 
 static void
 VolatileBufferRelease(void *vbuf)
 {
   delete static_cast<VolatileBufferPtr<unsigned char>*>(vbuf);
 }
 
+static int32_t
+VolatileSurfaceStride(const IntSize& size, SurfaceFormat format)
+{
+  // Stride must be a multiple of four or cairo will complain.
+  return (size.width * BytesPerPixel(format) + 0x3) & ~0x3;
+}
+
 static TemporaryRef<DataSourceSurface>
 CreateLockedSurface(VolatileBuffer *vbuf,
                     const IntSize& size,
                     SurfaceFormat format)
 {
   VolatileBufferPtr<unsigned char> *vbufptr =
     new VolatileBufferPtr<unsigned char>(vbuf);
   MOZ_ASSERT(!vbufptr->WasBufferPurged(), "Expected image data!");
 
-  int32_t stride = size.width * BytesPerPixel(format);
+  int32_t stride = VolatileSurfaceStride(size, format);
   RefPtr<DataSourceSurface> surf =
     Factory::CreateWrappingDataSourceSurface(*vbufptr, stride, size, format);
   if (!surf) {
     delete vbufptr;
     return nullptr;
   }
 
   surf->AddUserData(&kVolatileBuffer, vbufptr, VolatileBufferRelease);
   return surf;
 }
 
 static TemporaryRef<VolatileBuffer>
 AllocateBufferForImage(const IntSize& size, SurfaceFormat format)
 {
-  int32_t stride = size.width * BytesPerPixel(format);
+  int32_t stride = VolatileSurfaceStride(size, format);
   RefPtr<VolatileBuffer> buf = new VolatileBuffer();
   if (buf->Init(stride * size.height,
                 1 << gfxAlphaRecovery::GoodAlignmentLog2()))
     return buf;
 
   return nullptr;
 }