Bug 746344 - gfxImageSurface should allow allocation without memset. r=jmuizelaar a=jpr
authorBenoit Girard <b56girard@gmail.com>
Tue, 17 Apr 2012 17:55:11 -0400
changeset 91923 9cc11bafbb2944ebbe0179caef4cc6044e4176a8
parent 91922 26679372aaf4590ea453bb2c2705544d79271b15
child 91924 6a6c9764a3a2050bd4c715d9983b27c453f57bb7
push id8463
push userb56girard@gmail.com
push dateWed, 18 Apr 2012 20:30:06 +0000
treeherdermozilla-inbound@9cc11bafbb29 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmuizelaar, jpr
bugs746344
milestone14.0a1
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 746344 - gfxImageSurface should allow allocation without memset. r=jmuizelaar a=jpr
gfx/thebes/gfxImageSurface.cpp
gfx/thebes/gfxImageSurface.h
--- a/gfx/thebes/gfxImageSurface.cpp
+++ b/gfx/thebes/gfxImageSurface.cpp
@@ -118,33 +118,34 @@ TryAllocAlignedBytes(size_t aSize)
                               aSize) ?
              nsnull : ptr;
 #else
     // Oh well, hope that luck is with us in the allocator
     return moz_malloc(aSize);
 #endif
 }
 
-gfxImageSurface::gfxImageSurface(const gfxIntSize& size, gfxImageFormat format) :
+gfxImageSurface::gfxImageSurface(const gfxIntSize& size, gfxImageFormat format, bool aClear) :
     mSize(size), mOwnsData(false), mData(nsnull), mFormat(format)
 {
     mStride = ComputeStride();
 
     if (!CheckSurfaceSize(size))
         MakeInvalid();
 
     // if we have a zero-sized surface, just leave mData nsnull
     if (mSize.height * mStride > 0) {
 
         // This can fail to allocate memory aligned as we requested,
         // or it can fail to allocate any memory at all.
         mData = (unsigned char *) TryAllocAlignedBytes(mSize.height * mStride);
         if (!mData)
             return;
-        memset(mData, 0, mSize.height * mStride);
+        if (aClear)
+            memset(mData, 0, mSize.height * mStride);
     }
 
     mOwnsData = true;
 
     cairo_surface_t *surface =
         cairo_image_surface_create_for_data((unsigned char*)mData,
                                             (cairo_format_t)format,
                                             mSize.width,
--- a/gfx/thebes/gfxImageSurface.h
+++ b/gfx/thebes/gfxImageSurface.h
@@ -66,17 +66,17 @@ public:
 
     /**
      * Construct an image surface.
      * @param aSize The size of the buffer
      * @param format Format of the data
      *
      * @see gfxImageFormat
      */
-    gfxImageSurface(const gfxIntSize& size, gfxImageFormat format);
+    gfxImageSurface(const gfxIntSize& size, gfxImageFormat format, bool aClear = true);
     gfxImageSurface(cairo_surface_t *csurf);
 
     virtual ~gfxImageSurface();
 
     // ImageSurface methods
     gfxImageFormat Format() const { return mFormat; }
 
     virtual const gfxIntSize GetSize() const { return mSize; }