Bug 1350066 - Skip premult if src is missing color or alpha, and spew formats on reformat. - r=ethlin
MozReview-Commit-ID: JeoTq9EX9Rx
--- a/dom/canvas/TexUnpackBlob.cpp
+++ b/dom/canvas/TexUnpackBlob.cpp
@@ -286,16 +286,35 @@ TexUnpackBlob::TexUnpackBlob(const WebGL
, mSrcIsPremult(srcIsPremult)
, mNeedsExactUpload(false)
{
MOZ_ASSERT_IF(!IsTarget3D(target), mDepth == 1);
}
+static bool
+HasColorAndAlpha(const WebGLTexelFormat format)
+{
+ switch (format) {
+ case WebGLTexelFormat::RA8:
+ case WebGLTexelFormat::RA16F:
+ case WebGLTexelFormat::RA32F:
+ case WebGLTexelFormat::RGBA8:
+ case WebGLTexelFormat::RGBA5551:
+ case WebGLTexelFormat::RGBA4444:
+ case WebGLTexelFormat::RGBA16F:
+ case WebGLTexelFormat::RGBA32F:
+ case WebGLTexelFormat::BGRA8:
+ return true;
+ default:
+ return false;
+ }
+}
+
bool
TexUnpackBlob::ConvertIfNeeded(WebGLContext* webgl, const char* funcName,
const uint32_t rowLength, const uint32_t rowCount,
WebGLTexelFormat srcFormat,
const uint8_t* const srcBegin, const ptrdiff_t srcStride,
WebGLTexelFormat dstFormat, const ptrdiff_t dstStride,
const uint8_t** const out_begin,
UniqueBuffer* const out_anchoredBuffer) const
@@ -309,26 +328,28 @@ TexUnpackBlob::ConvertIfNeeded(WebGLCont
return true;
const auto& dstIsPremult = webgl->mPixelStore_PremultiplyAlpha;
const auto srcOrigin = (webgl->mPixelStore_FlipY ? gl::OriginPos::TopLeft
: gl::OriginPos::BottomLeft);
const auto dstOrigin = gl::OriginPos::BottomLeft;
if (srcFormat != dstFormat) {
- webgl->GeneratePerfWarning("%s: Conversion requires pixel reformatting.",
- funcName);
- } else if (mSrcIsPremult != dstIsPremult) {
+ webgl->GeneratePerfWarning("%s: Conversion requires pixel reformatting. (%u->%u)",
+ funcName, uint32_t(srcFormat),
+ uint32_t(dstFormat));
+ } else if (mSrcIsPremult != dstIsPremult && HasColorAndAlpha(srcFormat)) {
webgl->GeneratePerfWarning("%s: Conversion requires change in"
- "alpha-premultiplication.",
+ " alpha-premultiplication.",
funcName);
} else if (srcOrigin != dstOrigin) {
webgl->GeneratePerfWarning("%s: Conversion requires y-flip.", funcName);
} else if (srcStride != dstStride) {
- webgl->GeneratePerfWarning("%s: Conversion requires change in stride.", funcName);
+ webgl->GeneratePerfWarning("%s: Conversion requires change in stride. (%u->%u)",
+ funcName, uint32_t(srcStride), uint32_t(dstStride));
} else {
return true;
}
////
const auto dstTotalBytes = CheckedUint32(rowCount) * dstStride;
if (!dstTotalBytes.isValid()) {