From 101316199629532508a83c130893c1e88c8a9c40 Mon Sep 17 00:00:00 2001 From: Andrew Comminos Date: Thu, 11 Jun 2015 13:06:23 -0400 Subject: [PATCH] Bug 1167356 - Handle return value of DataSourceSurface::Map wherever possible. r=Bas --HG-- extra : rebase_source : fe4fcb9c3a89e2573e6fde423ed8d96f31e00f14 --- dom/base/nsContentUtils.cpp | 4 +++- gfx/2d/DrawTargetTiled.h | 5 ++++- gfx/2d/FilterNodeSoftware.cpp | 5 ++++- gfx/2d/SourceSurfaceD2D1.cpp | 10 ++++++++-- gfx/gl/GLReadTexImageHelper.cpp | 12 +++++++++--- gfx/layers/YCbCrImageDataSerializer.cpp | 4 +++- gfx/layers/d3d11/TextureD3D11.cpp | 6 +++++- image/imgFrame.cpp | 16 ++++++++++------ widget/gtk/nsImageToPixbuf.cpp | 4 +++- 9 files changed, 49 insertions(+), 17 deletions(-) diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index aaf2cb9e1669..3ffecd6be645 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -7431,7 +7431,9 @@ nsContentUtils::GetSurfaceData(mozilla::gfx::DataSourceSurface* aSurface, size_t* aLength, int32_t* aStride) { mozilla::gfx::DataSourceSurface::MappedSurface map; - aSurface->Map(mozilla::gfx::DataSourceSurface::MapType::READ, &map); + if (NS_WARN_IF(!aSurface->Map(mozilla::gfx::DataSourceSurface::MapType::READ, &map))) { + return nullptr; + } mozilla::gfx::IntSize size = aSurface->GetSize(); mozilla::CheckedInt32 requiredBytes = mozilla::CheckedInt32(map.mStride) * mozilla::CheckedInt32(size.height); diff --git a/gfx/2d/DrawTargetTiled.h b/gfx/2d/DrawTargetTiled.h index be020c2ca927..934237632ce1 100644 --- a/gfx/2d/DrawTargetTiled.h +++ b/gfx/2d/DrawTargetTiled.h @@ -177,7 +177,10 @@ public: RefPtr 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 dt = diff --git a/gfx/2d/FilterNodeSoftware.cpp b/gfx/2d/FilterNodeSoftware.cpp index cccc540aab0b..e3df239483ef 100644 --- a/gfx/2d/FilterNodeSoftware.cpp +++ b/gfx/2d/FilterNodeSoftware.cpp @@ -1095,7 +1095,10 @@ FilterNodeTransformSoftware::Render(const IntRect& aRect) } 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 dt = Factory::CreateDrawTargetForData(BackendType::CAIRO, diff --git a/gfx/2d/SourceSurfaceD2D1.cpp b/gfx/2d/SourceSurfaceD2D1.cpp index bd79d918c495..1f26d26b756c 100644 --- a/gfx/2d/SourceSurfaceD2D1.cpp +++ b/gfx/2d/SourceSurfaceD2D1.cpp @@ -182,7 +182,10 @@ DataSourceSurfaceD2D1::Map(MapType aMapType, MappedSurface *aMappedSurface) } 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; @@ -215,7 +218,10 @@ DataSourceSurfaceD2D1::EnsureMapped() 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; } diff --git a/gfx/gl/GLReadTexImageHelper.cpp b/gfx/gl/GLReadTexImageHelper.cpp index 2b72cc139f75..48705a5949c7 100644 --- a/gfx/gl/GLReadTexImageHelper.cpp +++ b/gfx/gl/GLReadTexImageHelper.cpp @@ -217,7 +217,10 @@ 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; @@ -288,8 +291,11 @@ CopyDataSourceSurface(DataSourceSurface* aSource, 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); diff --git a/gfx/layers/YCbCrImageDataSerializer.cpp b/gfx/layers/YCbCrImageDataSerializer.cpp index af32e0552777..7553bb126a31 100644 --- a/gfx/layers/YCbCrImageDataSerializer.cpp +++ b/gfx/layers/YCbCrImageDataSerializer.cpp @@ -287,7 +287,9 @@ YCbCrImageDataDeserializer::ToDataSourceSurface() } 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, diff --git a/gfx/layers/d3d11/TextureD3D11.cpp b/gfx/layers/d3d11/TextureD3D11.cpp index 366215d1ea23..a1baca00bad5 100644 --- a/gfx/layers/d3d11/TextureD3D11.cpp +++ b/gfx/layers/d3d11/TextureD3D11.cpp @@ -851,7 +851,11 @@ DataTextureSourceD3D11::Update(DataSourceSurface* aSurface, } 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); diff --git a/image/imgFrame.cpp b/image/imgFrame.cpp index 4504a7c43f76..2b033e748851 100644 --- a/image/imgFrame.cpp +++ b/image/imgFrame.cpp @@ -484,9 +484,11 @@ imgFrame::Optimize() } DataSourceSurface::MappedSurface mapping; - DebugOnly success = - surf->Map(DataSourceSurface::MapType::WRITE, &mapping); - NS_ASSERTION(success, "Failed to map surface"); + if (!surf->Map(DataSourceSurface::MapType::WRITE, &mapping)) { + gfxCriticalError() << "imgFrame::Optimize failed to map surface"; + return NS_ERROR_FAILURE; + } + RefPtr target = Factory::CreateDrawTargetForData(BackendType::CAIRO, mapping.mData, @@ -910,9 +912,11 @@ imgFrame::Deoptimize() } DataSourceSurface::MappedSurface mapping; - DebugOnly success = - surf->Map(DataSourceSurface::MapType::WRITE, &mapping); - NS_ASSERTION(success, "Failed to map surface"); + if (!surf->Map(DataSourceSurface::MapType::WRITE, &mapping)) { + gfxCriticalError() << "imgFrame::Deoptimize failed to map surface"; + return NS_ERROR_FAILURE; + } + RefPtr target = Factory::CreateDrawTargetForData(BackendType::CAIRO, mapping.mData, diff --git a/widget/gtk/nsImageToPixbuf.cpp b/widget/gtk/nsImageToPixbuf.cpp index ca05b3b8a49e..a83a570d3d82 100644 --- a/widget/gtk/nsImageToPixbuf.cpp +++ b/widget/gtk/nsImageToPixbuf.cpp @@ -75,7 +75,9 @@ nsImageToPixbuf::SourceSurfaceToPixbuf(SourceSurface* aSurface, RefPtr 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;