Bug 1167356 - Handle return value of DataSourceSurface::Map wherever possible. r=Bas, a=abillings
CLOSED TREE
--- a/gfx/2d/SourceSurfaceD2D1.cpp
+++ b/gfx/2d/SourceSurfaceD2D1.cpp
@@ -1,15 +1,16 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "SourceSurfaceD2D1.h"
#include "DrawTargetD2D1.h"
+#include "Logging.h"
#include "Tools.h"
namespace mozilla {
namespace gfx {
SourceSurfaceD2D1::SourceSurfaceD2D1(ID2D1Image *aImage, ID2D1DeviceContext *aDC,
SurfaceFormat aFormat, const IntSize &aSize,
DrawTargetD2D1 *aDT)
@@ -151,17 +152,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 = true;
return true;
}
void
@@ -184,14 +188,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/GLScreenBuffer.cpp
+++ b/gfx/gl/GLScreenBuffer.cpp
@@ -478,17 +478,20 @@ GLScreenBuffer::CreateRead(SharedSurface
return ReadBuffer::Create(gl, caps, formats, surf);
}
void
GLScreenBuffer::Readback(SharedSurface_GL* src, DataSourceSurface* dest)
{
MOZ_ASSERT(src && dest);
DataSourceSurface::MappedSurface ms;
- dest->Map(DataSourceSurface::MapType::READ, &ms);
+ if (!dest->Map(DataSourceSurface::MapType::READ, &ms)) {
+ NS_ERROR("Failed to map surface for reading.");
+ return;
+ }
nsRefPtr<gfxImageSurface> wrappedDest =
new gfxImageSurface(ms.mData,
ThebesIntSize(dest->GetSize()),
ms.mStride,
SurfaceFormatToImageFormat(dest->GetFormat()));
DeprecatedReadback(src, wrappedDest);
dest->Unmap();
}
--- a/gfx/gl/SharedSurfaceGL.cpp
+++ b/gfx/gl/SharedSurfaceGL.cpp
@@ -321,17 +321,20 @@ SharedSurface_Basic::~SharedSurface_Basi
void
SharedSurface_Basic::Fence()
{
mGL->MakeCurrent();
ScopedBindFramebuffer autoFB(mGL, mFB);
DataSourceSurface::MappedSurface map;
- mData->Map(DataSourceSurface::MapType::WRITE, &map);
+ if (!mData->Map(DataSourceSurface::MapType::WRITE, &map)) {
+ NS_ERROR("Failed to map surface for writing.");
+ return;
+ }
nsRefPtr<gfxImageSurface> wrappedData =
new gfxImageSurface(map.mData,
ThebesIntSize(mData->GetSize()),
map.mStride,
SurfaceFormatToImageFormat(mData->GetFormat()));
ReadPixelsIntoImageSurface(mGL, wrappedData);
mData->Unmap();
}
--- a/gfx/layers/YCbCrImageDataSerializer.cpp
+++ b/gfx/layers/YCbCrImageDataSerializer.cpp
@@ -273,17 +273,19 @@ YCbCrImageDataSerializer::CopyData(const
TemporaryRef<DataSourceSurface>
YCbCrImageDataDeserializer::ToDataSourceSurface()
{
RefPtr<DataSourceSurface> result =
Factory::CreateDataSourceSurface(GetYSize(), gfx::SurfaceFormat::B8G8R8X8);
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/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -1341,17 +1341,21 @@ CompositorOGL::CopyToTarget(DrawTarget *
// to GL_COLOR_ATTACHMENT0 attachment point.
mGLContext->fReadBuffer(LOCAL_GL_BACK);
}
RefPtr<DataSourceSurface> source =
Factory::CreateDataSourceSurface(rect.Size(), gfx::SurfaceFormat::B8G8R8A8);
DataSourceSurface::MappedSurface map;
- source->Map(DataSourceSurface::MapType::WRITE, &map);
+ if (!source->Map(DataSourceSurface::MapType::WRITE, &map)) {
+ NS_ERROR("Failed to map surface for writing!");
+ return;
+ }
+
// XXX we should do this properly one day without using the gfxImageSurface
nsRefPtr<gfxImageSurface> surf =
new gfxImageSurface(map.mData,
gfxIntSize(width, height),
map.mStride,
gfxImageFormat::ARGB32);
ReadPixelsIntoImageSurface(mGLContext, surf);
source->Unmap();
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -657,18 +657,20 @@ CopySurface(gfxASurface* aSurface)
RefPtr<DataSourceSurface> data =
Factory::CreateDataSourceSurface(ToIntSize(size),
ImageFormatToSurfaceFormat(format));
if (!data) {
return nullptr;
}
DataSourceSurface::MappedSurface map;
- DebugOnly<bool> result = data->Map(DataSourceSurface::WRITE, &map);
- MOZ_ASSERT(result, "Should always succeed mapping raw data surfaces!");
+ if (!data->Map(DataSourceSurface::WRITE, &map)) {
+ NS_ERROR("Failed to map surface for reading!");
+ return nullptr;
+ }
nsRefPtr<gfxImageSurface> image = new gfxImageSurface(map.mData, size, map.mStride, format);
nsRefPtr<gfxContext> ctx = new gfxContext(image);
ctx->SetSource(aSurface);
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
ctx->Paint();
--- 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;