Bug 1167356 - Handle return value of DataSourceSurface::Map wherever possible. r=Bas

--HG--
extra : rebase_source : fe4fcb9c3a89e2573e6fde423ed8d96f31e00f14
This commit is contained in:
Andrew Comminos 2015-06-11 13:06:23 -04:00
parent 4a8e2edd09
commit 1013161996
9 changed files with 49 additions and 17 deletions

View File

@ -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);

View File

@ -177,7 +177,10 @@ public:
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 =

View File

@ -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<DrawTarget> dt =
Factory::CreateDrawTargetForData(BackendType::CAIRO,

View File

@ -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;
}

View File

@ -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);

View File

@ -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,

View File

@ -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);

View File

@ -484,9 +484,11 @@ imgFrame::Optimize()
}
DataSourceSurface::MappedSurface mapping;
DebugOnly<bool> 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<DrawTarget> target =
Factory::CreateDrawTargetForData(BackendType::CAIRO,
mapping.mData,
@ -910,9 +912,11 @@ imgFrame::Deoptimize()
}
DataSourceSurface::MappedSurface mapping;
DebugOnly<bool> 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<DrawTarget> target =
Factory::CreateDrawTargetForData(BackendType::CAIRO,
mapping.mData,

View File

@ -75,7 +75,9 @@ nsImageToPixbuf::SourceSurfaceToPixbuf(SourceSurface* aSurface,
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;