Skip to content

Commit

Permalink
Bug 1167356 - Handle return value of DataSourceSurface::Map wherever …
Browse files Browse the repository at this point in the history
…possible. r=Bas
  • Loading branch information
acomminos committed Jun 11, 2015
1 parent 3395347 commit b6eba9b
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 17 deletions.
4 changes: 3 additions & 1 deletion dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion gfx/2d/DrawTargetTiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ class SnapshotTiled : public SourceSurface
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 =
Expand Down
5 changes: 4 additions & 1 deletion gfx/2d/FilterNodeSoftware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions gfx/2d/SourceSurfaceD2D1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
12 changes: 9 additions & 3 deletions gfx/gl/GLReadTexImageHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion gfx/layers/YCbCrImageDataSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion gfx/layers/d3d11/TextureD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 10 additions & 6 deletions image/imgFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion widget/gtk/nsImageToPixbuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b6eba9b

Please sign in to comment.