Bug 943392 - Let MemoryTextureClient use a fallible allocation. r=BenWa a=lsblakk
authorEdwin Flores <eflores@mozilla.com>
Mon, 16 Dec 2013 10:52:07 +1300
changeset 167705 4b567544791ea870ca4aca1761143a896079176a
parent 167704 90af7e816b88e1ba2087177429c3a8c97a1e5296
child 167706 d551dd374cfc2a40df0c412a5905f6f1208239d9
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBenWa, lsblakk
bugs943392
milestone27.0
Bug 943392 - Let MemoryTextureClient use a fallible allocation. r=BenWa a=lsblakk
gfx/layers/client/TextureClient.cpp
gfx/layers/ipc/SharedRGBImage.cpp
--- a/gfx/layers/client/TextureClient.cpp
+++ b/gfx/layers/client/TextureClient.cpp
@@ -208,17 +208,22 @@ MemoryTextureClient::ToSurfaceDescriptor
                                         GetFormat());
   return true;
 }
 
 bool
 MemoryTextureClient::Allocate(uint32_t aSize)
 {
   MOZ_ASSERT(!mBuffer);
-  mBuffer = new uint8_t[aSize];
+  static const fallible_t fallible = fallible_t();
+  mBuffer = new(fallible) uint8_t[aSize];
+  if (!mBuffer) {
+    NS_WARNING("Failed to allocate buffer");
+    return false;
+  }
   mBufSize = aSize;
   return true;
 }
 
 MemoryTextureClient::MemoryTextureClient(CompositableClient* aCompositable,
                                          gfx::SurfaceFormat aFormat,
                                          TextureFlags aFlags)
   : BufferTextureClient(aCompositable, aFormat, aFlags)
--- a/gfx/layers/ipc/SharedRGBImage.cpp
+++ b/gfx/layers/ipc/SharedRGBImage.cpp
@@ -78,18 +78,21 @@ CreateSharedRGBImage(ImageContainer *aIm
 
     if (!rgbImageDep->AllocateBuffer(aSize, aImageFormat)) {
       NS_WARNING("Failed to allocate shared memory for DeprecatedSharedRGBImage");
       return nullptr;
     }
     return rgbImageDep.forget();
   }
   nsRefPtr<SharedRGBImage> rgbImage = static_cast<SharedRGBImage*>(image.get());
-  rgbImage->Allocate(gfx::ToIntSize(aSize),
-                     gfx::ImageFormatToSurfaceFormat(aImageFormat));
+  if (!rgbImage->Allocate(gfx::ToIntSize(aSize),
+                          gfx::ImageFormatToSurfaceFormat(aImageFormat))) {
+    NS_WARNING("Failed to allocate a shared image");
+    return nullptr;
+  }
   return image.forget();
 }
 
 uint8_t *
 DeprecatedSharedRGBImage::GetBuffer()
 {
   return mShmem->get<uint8_t>();
 }