Bug 1290831 - Clarify TexUnpackBlob::TexOrSubImage's fallibility and update callers. - r=cleu
MozReview-Commit-ID: EmkzXwek8JW
--- a/dom/canvas/TexUnpackBlob.cpp
+++ b/dom/canvas/TexUnpackBlob.cpp
@@ -485,17 +485,17 @@ TexUnpackBytes::TexOrSubImage(bool isSub
MOZ_ASSERT(webgl->mBoundPixelUnpackBuffer);
if (!isSubImage) {
// Alloc first to catch OOMs.
AssertUintParamCorrect(gl, LOCAL_GL_PIXEL_UNPACK_BUFFER, 0);
*out_error = DoTexOrSubImage(false, gl, target, level, dui, xOffset, yOffset,
zOffset, mWidth, mHeight, mDepth, nullptr);
if (*out_error)
- return false;
+ return true;
}
const ScopedLazyBind bindPBO(gl, LOCAL_GL_PIXEL_UNPACK_BUFFER,
webgl->mBoundPixelUnpackBuffer);
//////
// Make our sometimes-implicit values explicit. Also this keeps them constant when we
@@ -582,17 +582,17 @@ TexUnpackImage::TexOrSubImage(bool isSub
gl::GLContext* gl = webgl->GL();
gl->MakeCurrent();
if (needsRespec) {
*out_error = DoTexOrSubImage(isSubImage, gl, target.get(), level, dui, xOffset,
yOffset, zOffset, mWidth, mHeight, mDepth,
nullptr);
if (*out_error)
- return false;
+ return true;
}
do {
if (mDepth != 1)
break;
const bool isDstPremult = webgl->mPixelStore_PremultiplyAlpha;
if (mIsSrcPremult != isDstPremult)
@@ -645,17 +645,17 @@ TexUnpackImage::TexOrSubImage(bool isSub
if (surf) {
// WARNING: OSX can lose our MakeCurrent here.
dataSurf = surf->GetDataSurface();
}
if (!dataSurf) {
webgl->ErrorOutOfMemory("%s: GetAsSourceSurface or GetDataSurface failed after"
" blit failed for TexUnpackImage.",
funcName);
- return false;
+ return true;
}
const TexUnpackSurface surfBlob(webgl, target, mWidth, mHeight, mDepth, dataSurf,
mIsSrcPremult);
return surfBlob.TexOrSubImage(isSubImage, needsRespec, funcName, tex, target, level,
dui, xOffset, yOffset, zOffset, out_error);
}
@@ -746,18 +746,20 @@ TexUnpackSurface::TexOrSubImage(bool isS
if (!GetFormatForSurf(mSurf, &srcFormat, &srcBPP)) {
webgl->ErrorImplementationBug("%s: GetFormatForSurf failed for"
" WebGLTexelFormat::%u.",
funcName, uint32_t(mSurf->GetFormat()));
return false;
}
gfx::DataSourceSurface::ScopedMap map(mSurf, gfx::DataSourceSurface::MapType::READ);
- if (!map.IsMapped())
+ if (!map.IsMapped()) {
+ webgl->ErrorOutOfMemory("%s: Failed to map source surface for upload.", funcName);
return false;
+ }
const auto srcBytes = map.GetData();
const auto srcStride = map.GetStride();
// CPU conversion. (++numCopies)
webgl->GenerateWarning("%s: Incurred CPU-side conversion, which is very slow.",
funcName);
--- a/dom/canvas/TexUnpackBlob.h
+++ b/dom/canvas/TexUnpackBlob.h
@@ -69,16 +69,20 @@ protected:
const uint8_t** const out_bytes,
UniqueBuffer* const out_anchoredBuffer) const;
public:
virtual bool HasData() const { return true; }
virtual bool Validate(WebGLContext* webgl, const char* funcName,
const webgl::PackingInfo& pi) = 0;
+
+ // Returns false when we've generated a WebGL error.
+ // Returns true but with a non-zero *out_error if we still need to generate a WebGL
+ // error.
virtual bool TexOrSubImage(bool isSubImage, bool needsRespec, const char* funcName,
WebGLTexture* tex, TexImageTarget target, GLint level,
const webgl::DriverUnpackInfo* dui, GLint xOffset,
GLint yOffset, GLint zOffset,
GLenum* const out_error) const = 0;
};
class TexUnpackBytes final : public TexUnpackBlob
--- a/dom/canvas/WebGLTextureUpload.cpp
+++ b/dom/canvas/WebGLTextureUpload.cpp
@@ -1234,18 +1234,21 @@ WebGLTexture::TexImage(const char* funcN
imageInfo->mHeight != newImageInfo.mHeight ||
imageInfo->mDepth != newImageInfo.mDepth ||
imageInfo->mFormat != newImageInfo.mFormat);
const GLint xOffset = 0;
const GLint yOffset = 0;
const GLint zOffset = 0;
GLenum glError;
- blob->TexOrSubImage(isSubImage, needsRespec, funcName, this, target, level,
- driverUnpackInfo, xOffset, yOffset, zOffset, &glError);
+ if (!blob->TexOrSubImage(isSubImage, needsRespec, funcName, this, target, level,
+ driverUnpackInfo, xOffset, yOffset, zOffset, &glError))
+ {
+ return;
+ }
if (glError == LOCAL_GL_OUT_OF_MEMORY) {
mContext->ErrorOutOfMemory("%s: Driver ran out of memory during upload.",
funcName);
return;
}
if (glError) {
@@ -1319,18 +1322,21 @@ WebGLTexture::TexSubImage(const char* fu
{
return;
}
const bool isSubImage = true;
const bool needsRespec = false;
GLenum glError;
- blob->TexOrSubImage(isSubImage, needsRespec, funcName, this, target, level,
- driverUnpackInfo, xOffset, yOffset, zOffset, &glError);
+ if (!blob->TexOrSubImage(isSubImage, needsRespec, funcName, this, target, level,
+ driverUnpackInfo, xOffset, yOffset, zOffset, &glError))
+ {
+ return;
+ }
if (glError == LOCAL_GL_OUT_OF_MEMORY) {
mContext->ErrorOutOfMemory("%s: Driver ran out of memory during upload.",
funcName);
return;
}
if (glError) {