Bug 980415 - Fix multiple points in the codebase where we fail to call DataSourceSurface::Unmap(). r=Bas

This commit is contained in:
Jonathan Watt 2014-03-07 13:21:38 +00:00
parent 95ed84029a
commit f5b9b89e8c
5 changed files with 31 additions and 19 deletions

View File

@ -766,17 +766,10 @@ WriteBitmap(nsIFile* aFile, imgIContainer* aImage)
thebesImageSurface->CopyToB8G8R8A8DataSourceSurface();
NS_ENSURE_TRUE(dataSurface, NS_ERROR_FAILURE);
DataSourceSurface::MappedSurface map;
dataSurface->Map(DataSourceSurface::MapType::READ, &map);
if (!map.mData) {
return NS_ERROR_FAILURE;
}
int32_t width = dataSurface->GetSize().width;
int32_t height = dataSurface->GetSize().height;
int32_t bytesPerPixel = 4 * sizeof(uint8_t);
uint32_t bytesPerRow = bytesPerPixel * width;
uint32_t length = map.mStride * height;
// initialize these bitmap structs which we will later
// serialize directly to the head of the bitmap file
@ -805,6 +798,11 @@ WriteBitmap(nsIFile* aFile, imgIContainer* aImage)
rv = NS_NewLocalFileOutputStream(getter_AddRefs(stream), aFile);
NS_ENSURE_SUCCESS(rv, rv);
DataSourceSurface::MappedSurface map;
if (!dataSurface->Map(DataSourceSurface::MapType::READ, &map)) {
return NS_ERROR_FAILURE;
}
// write the bitmap headers and rgb pixel data to the file
rv = NS_ERROR_FAILURE;
if (stream) {
@ -815,7 +813,7 @@ WriteBitmap(nsIFile* aFile, imgIContainer* aImage)
if (written == sizeof(BITMAPINFOHEADER)) {
// write out the image data backwards because the desktop won't
// show bitmaps with negative heights for top-to-bottom
uint32_t i = length;
uint32_t i = map.mStride * height;
do {
i -= map.mStride;
stream->Write(((const char*)map.mData) + i, bytesPerRow, &written);
@ -832,6 +830,8 @@ WriteBitmap(nsIFile* aFile, imgIContainer* aImage)
stream->Close();
}
dataSurface->Unmap();
return rv;
}

View File

@ -490,6 +490,7 @@ GLScreenBuffer::Readback(SharedSurface_GL* src, DataSourceSurface* dest)
ms.mStride,
SurfaceFormatToImageFormat(dest->GetFormat()));
DeprecatedReadback(src, wrappedDest);
dest->Unmap();
}
void

View File

@ -353,7 +353,9 @@ GrallocImage::GetAsSourceSurface()
surface->Unmap();
return surface;
} else if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP) {
}
if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP) {
uint32_t uvOffset = height * width;
ConvertYVU420SPToRGB565(buffer, width,
buffer + uvOffset, width,
@ -362,12 +364,15 @@ GrallocImage::GetAsSourceSurface()
surface->Unmap();
return surface;
} else if (format == HAL_PIXEL_FORMAT_YV12) {
}
if (format == HAL_PIXEL_FORMAT_YV12) {
gfx::ConvertYCbCrToRGB(mData,
surface->GetFormat(),
mSize,
surface->GetData(),
surface->Stride());
surface->Unmap();
return surface;
}
@ -376,6 +381,7 @@ GrallocImage::GetAsSourceSurface()
if (!colorConverter.isValid()) {
NS_WARNING("Invalid color conversion");
surface->Unmap();
return nullptr;
}

View File

@ -134,9 +134,9 @@ static nsresult EncodeImageData(DataSourceSurface* aDataSurface,
return NS_IMAGELIB_ERROR_NO_ENCODER;
DataSourceSurface::MappedSurface map;
aDataSurface->Map(DataSourceSurface::MapType::READ, &map);
if (!map.mData)
if (!aDataSurface->Map(DataSourceSurface::MapType::READ, &map)) {
return NS_ERROR_FAILURE;
}
IntSize size = aDataSurface->GetSize();
uint32_t dataLength = map.mStride * size.height;
@ -149,7 +149,7 @@ static nsresult EncodeImageData(DataSourceSurface* aDataSurface,
map.mStride,
imgIEncoder::INPUT_FORMAT_HOSTARGB,
aOutputOptions);
aDataSurface->Unmap();
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(encoder, aStream);
@ -204,9 +204,9 @@ NS_IMETHODIMP imgTools::EncodeScaledImage(imgIContainer *aContainer,
Factory::CreateDataSourceSurface(IntSize(aScaledWidth, aScaledHeight),
SurfaceFormat::B8G8R8A8);
DataSourceSurface::MappedSurface map;
dataSurface->Map(DataSourceSurface::MapType::WRITE, &map);
if (!map.mData)
if (!dataSurface->Map(DataSourceSurface::MapType::WRITE, &map)) {
return NS_ERROR_FAILURE;
}
RefPtr<DrawTarget> dt =
Factory::CreateDrawTargetForData(BackendType::CAIRO,
@ -220,6 +220,8 @@ NS_IMETHODIMP imgTools::EncodeScaledImage(imgIContainer *aContainer,
DrawSurfaceOptions(),
DrawOptions(1.0f, CompositionOp::OP_SOURCE));
dataSurface->Unmap();
return EncodeImageData(dataSurface, aMimeType, aOutputOptions, aStream);
}
@ -267,9 +269,9 @@ NS_IMETHODIMP imgTools::EncodeCroppedImage(imgIContainer *aContainer,
Factory::CreateDataSourceSurface(IntSize(aWidth, aHeight),
SurfaceFormat::B8G8R8A8);
DataSourceSurface::MappedSurface map;
dataSurface->Map(DataSourceSurface::MapType::WRITE, &map);
if (!map.mData)
if (!dataSurface->Map(DataSourceSurface::MapType::WRITE, &map)) {
return NS_ERROR_FAILURE;
}
RefPtr<DrawTarget> dt =
Factory::CreateDrawTargetForData(BackendType::CAIRO,
@ -281,6 +283,8 @@ NS_IMETHODIMP imgTools::EncodeCroppedImage(imgIContainer *aContainer,
IntRect(aOffsetX, aOffsetY, aWidth, aHeight),
IntPoint(0, 0));
dataSurface->Unmap();
return EncodeImageData(dataSurface, aMimeType, aOutputOptions, aStream);
}

View File

@ -197,8 +197,7 @@ nsClipboard::SetNativeClipboardData( nsITransferable *aTransferable,
continue;
DataSourceSurface::MappedSurface map;
dataSurface->Map(DataSourceSurface::MapType::READ, &map);
if (!map.mData)
if (!dataSurface->Map(DataSourceSurface::MapType::READ, &map))
continue;
QImage qImage(map.mData,
@ -207,6 +206,8 @@ nsClipboard::SetNativeClipboardData( nsITransferable *aTransferable,
map.mStride,
_moz2dformat_to_qformat(dataSurface->GetFormat()));
dataSurface->Unmap();
// Add image to the mimeData
mimeData->setImageData(qImage);
imageAdded = true;