Bug 1167356 - Handle return value of DataSourceSurface::Map wherever possible. r=Bas, a=lizzard
authorAndrew Comminos <acomminos@mozilla.com>
Tue, 16 Jun 2015 15:42:18 -0400
changeset 267734 c7499d2cdf329b2cc0f806d3b9b598fde9bd549e
parent 267733 1fe9f73c9e297e5f18b7df2c14c59365337eb63b
child 267735 dde4eeaaa7ad22a0c55cc0f11a927aca2b790b57
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas, lizzard
bugs1167356
milestone39.0
Bug 1167356 - Handle return value of DataSourceSurface::Map wherever possible. r=Bas, a=lizzard
gfx/2d/DrawTargetTiled.h
gfx/2d/FilterNodeSoftware.cpp
gfx/2d/SourceSurfaceD2D1.cpp
gfx/gl/GLReadTexImageHelper.cpp
gfx/layers/YCbCrImageDataSerializer.cpp
gfx/layers/d3d11/TextureD3D11.cpp
widget/gtk/nsImageToPixbuf.cpp
--- a/gfx/2d/DrawTargetTiled.h
+++ b/gfx/2d/DrawTargetTiled.h
@@ -172,17 +172,20 @@ public:
   }
   virtual SurfaceFormat GetFormat() const { return mSnapshots[0]->GetFormat(); }
 
   virtual TemporaryRef<DataSourceSurface> GetDataSurface()
   {
     RefPtr<DataSourceSurface> surf = Factory::CreateDataSourceSurface(GetSize(), GetFormat());
 
     DataSourceSurface::MappedSurface mappedSurf;
-    surf->Map(DataSourceSurface::MapType::WRITE, &mappedSurf);
+    if (!surf->Map(DataSourceSurface::MapType::WRITE, &mappedSurf)) {
+      gfxCriticalError() << "DrawTargetTiled::GetDataSurface failed to map surface";
+      return nullptr;
+    }
 
     {
       RefPtr<DrawTarget> dt =
         Factory::CreateDrawTargetForData(BackendType::CAIRO, mappedSurf.mData,
         GetSize(), mappedSurf.mStride, GetFormat());
 
       if (!dt) {
         gfxWarning() << "DrawTargetTiled::GetDataSurface failed in CreateDrawTargetForData";
--- a/gfx/2d/FilterNodeSoftware.cpp
+++ b/gfx/2d/FilterNodeSoftware.cpp
@@ -1090,17 +1090,20 @@ FilterNodeTransformSoftware::Render(cons
   RefPtr<DataSourceSurface> surf =
     Factory::CreateDataSourceSurface(aRect.Size(), input->GetFormat(), true);
 
   if (!surf) {
     return nullptr;
   }
 
   DataSourceSurface::MappedSurface mapping;
-  surf->Map(DataSourceSurface::MapType::WRITE, &mapping);
+  if (!surf->Map(DataSourceSurface::MapType::WRITE, &mapping)) {
+    gfxCriticalError() << "FilterNodeTransformSoftware::Render failed to map surface";
+    return nullptr;
+  }
 
   RefPtr<DrawTarget> dt =
     Factory::CreateDrawTargetForData(BackendType::CAIRO,
                                      mapping.mData,
                                      surf->GetSize(),
                                      mapping.mStride,
                                      surf->GetFormat());
   if (!dt) {
--- a/gfx/2d/SourceSurfaceD2D1.cpp
+++ b/gfx/2d/SourceSurfaceD2D1.cpp
@@ -177,17 +177,20 @@ DataSourceSurfaceD2D1::Map(MapType aMapT
   D2D1_MAP_OPTIONS options;
   if (aMapType == MapType::READ) {
     options = D2D1_MAP_OPTIONS_READ;
   } else {
     MOZ_CRASH("No support for Write maps on D2D1 DataSourceSurfaces yet!");
   }
 
   D2D1_MAPPED_RECT map;
-  mBitmap->Map(D2D1_MAP_OPTIONS_READ, &map);
+  if (FAILED(mBitmap->Map(D2D1_MAP_OPTIONS_READ, &map))) {
+    gfxCriticalError() << "Failed to map bitmap.";
+    return false;
+  }
   aMappedSurface->mData = map.bits;
   aMappedSurface->mStride = map.pitch;
 
   mIsMapped = !!aMappedSurface->mData;
   return mIsMapped;
 }
 
 void
@@ -210,14 +213,17 @@ DataSourceSurfaceD2D1::Stride()
 void
 DataSourceSurfaceD2D1::EnsureMapped()
 {
   // Do not use GetData() after having used Map!
   MOZ_ASSERT(!mIsMapped);
   if (mMapped) {
     return;
   }
-  mBitmap->Map(D2D1_MAP_OPTIONS_READ, &mMap);
+  if (FAILED(mBitmap->Map(D2D1_MAP_OPTIONS_READ, &mMap))) {
+    gfxCriticalError() << "Failed to map bitmap.";
+    return;
+  }
   mMapped = true;
 }
 
 }
 }
--- a/gfx/gl/GLReadTexImageHelper.cpp
+++ b/gfx/gl/GLReadTexImageHelper.cpp
@@ -212,17 +212,20 @@ GetActualReadFormats(GLContext* gl,
         return true;
     }
 }
 
 static void
 SwapRAndBComponents(DataSourceSurface* surf)
 {
     DataSourceSurface::MappedSurface map;
-    MOZ_ALWAYS_TRUE( surf->Map(DataSourceSurface::MapType::READ_WRITE, &map) );
+    if (!surf->Map(DataSourceSurface::MapType::READ_WRITE, &map)) {
+        MOZ_ASSERT(false, "SwapRAndBComponents: Failed to map surface.");
+        return;
+    }
     MOZ_ASSERT(map.mStride >= 0);
 
     const size_t rowBytes = surf->GetSize().width*4;
     const size_t rowHole = map.mStride - rowBytes;
 
     uint8_t* row = map.mData;
     if (!row) {
         MOZ_ASSERT(false, "SwapRAndBComponents: Failed to get data from"
@@ -283,18 +286,21 @@ CopyDataSourceSurface(DataSourceSurface*
     const bool destHasAlpha = aDest->GetFormat() == SurfaceFormat::R8G8B8A8 ||
                               aDest->GetFormat() == SurfaceFormat::B8G8R8A8;
     const bool needsAlphaMask = !srcHasAlpha && destHasAlpha;
 
     const bool needsConvertTo16Bits = aDest->GetFormat() == SurfaceFormat::R5G6B5;
 
     DataSourceSurface::MappedSurface srcMap;
     DataSourceSurface::MappedSurface destMap;
-    MOZ_ALWAYS_TRUE( aSource->Map(DataSourceSurface::MapType::READ, &srcMap) );
-    MOZ_ALWAYS_TRUE( aDest->Map(DataSourceSurface::MapType::WRITE, &destMap) );
+    if (!aSource->Map(DataSourceSurface::MapType::READ, &srcMap) ||
+        !aDest->Map(DataSourceSurface::MapType::WRITE, &destMap)) {
+        MOZ_ASSERT(false, "CopyDataSourceSurface: Failed to map surface.");
+        return;
+    }
     MOZ_ASSERT(srcMap.mStride >= 0);
     MOZ_ASSERT(destMap.mStride >= 0);
 
     const size_t srcBPP = BytesPerPixel(aSource->GetFormat());
     const size_t srcRowBytes = aSource->GetSize().width * srcBPP;
     const size_t srcRowHole = srcMap.mStride - srcRowBytes;
 
     const size_t destBPP = BytesPerPixel(aDest->GetFormat());
--- a/gfx/layers/YCbCrImageDataSerializer.cpp
+++ b/gfx/layers/YCbCrImageDataSerializer.cpp
@@ -282,17 +282,19 @@ YCbCrImageDataDeserializer::ToDataSource
 {
   RefPtr<DataSourceSurface> result =
     Factory::CreateDataSourceSurface(GetYSize(), gfx::SurfaceFormat::B8G8R8X8);
   if (NS_WARN_IF(!result)) {
     return nullptr;
   }
 
   DataSourceSurface::MappedSurface map;
-  result->Map(DataSourceSurface::MapType::WRITE, &map);
+  if (NS_WARN_IF(!result->Map(DataSourceSurface::MapType::WRITE, &map))) {
+    return nullptr;
+  }
 
   gfx::ConvertYCbCrToRGB32(GetYData(), GetCbData(), GetCrData(),
                            map.mData,
                            0, 0, //pic x and y
                            GetYSize().width, GetYSize().height,
                            GetYStride(), GetCbCrStride(),
                            map.mStride,
                            gfx::YV12);
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -797,17 +797,21 @@ DataTextureSourceD3D11::Update(DataSourc
       mIsTiled = false;
       if (FAILED(hr) || !mTexture) {
         Reset();
         return false;
       }
     }
 
     DataSourceSurface::MappedSurface map;
-    aSurface->Map(DataSourceSurface::MapType::READ, &map);
+    if (!aSurface->Map(DataSourceSurface::MapType::READ, &map)) {
+      gfxCriticalError() << "Failed to map surface.";
+      Reset();
+      return false;
+    }
 
     if (aDestRegion) {
       nsIntRegionRectIterator iter(*aDestRegion);
       const nsIntRect *iterRect;
       while ((iterRect = iter.Next())) {
         D3D11_BOX box;
         box.front = 0;
         box.back = 1;
--- a/widget/gtk/nsImageToPixbuf.cpp
+++ b/widget/gtk/nsImageToPixbuf.cpp
@@ -70,17 +70,19 @@ nsImageToPixbuf::SourceSurfaceToPixbuf(S
     if (!pixbuf)
         return nullptr;
 
     uint32_t destStride = gdk_pixbuf_get_rowstride (pixbuf);
     guchar* destPixels = gdk_pixbuf_get_pixels (pixbuf);
 
     RefPtr<DataSourceSurface> dataSurface = aSurface->GetDataSurface();
     DataSourceSurface::MappedSurface map;
-    dataSurface->Map(DataSourceSurface::MapType::READ, &map);
+    if (!dataSurface->Map(DataSourceSurface::MapType::READ, &map))
+        return nullptr;
+
     uint8_t* srcData = map.mData;
     int32_t srcStride = map.mStride;
 
     SurfaceFormat format = dataSurface->GetFormat();
 
     for (int32_t row = 0; row < aHeight; ++row) {
         for (int32_t col = 0; col < aWidth; ++col) {
             guchar* destPixel = destPixels + row * destStride + 4 * col;