Bug 943392 - Let MemoryTextureClient use a fallible allocation. r=BenWa
authorNicolas Silva <nical@mozilla.com>
Fri, 06 Dec 2013 16:30:50 +0100
changeset 174855 0cfd889611f88bde647725fa13d0ba102c72e2a2
parent 174854 b76e788fa2171a90855b5c7a6b4c8a9752bb5a46
child 174856 11e0720cbd281b93aba81f7863fac831e3b99882
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBenWa
bugs943392
milestone28.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 943392 - Let MemoryTextureClient use a fallible allocation. r=BenWa
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;
+  }
   GfxMemoryImageReporter::DidAlloc(mBuffer);
   mBufSize = aSize;
   return true;
 }
 
 MemoryTextureClient::MemoryTextureClient(CompositableClient* aCompositable,
                                          gfx::SurfaceFormat aFormat,
                                          TextureFlags aFlags)
--- a/gfx/layers/ipc/SharedRGBImage.cpp
+++ b/gfx/layers/ipc/SharedRGBImage.cpp
@@ -79,18 +79,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>();
 }