Bug 1350066 - Skip premult if src is missing color or alpha, and spew formats on reformat. - r=ethlin draft
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 23 Mar 2017 13:44:16 -0700
changeset 503922 d2fe0d35a5da3105d71e7c79dce1df0701909647
parent 503825 439ee2e4fc4ed4a82102608639d9751e376d5536
child 503923 b22f82c45211494cde2a2787025847f295e2acbf
push id50710
push userbmo:jgilbert@mozilla.com
push dateThu, 23 Mar 2017 20:48:17 +0000
reviewersethlin
bugs1350066
milestone55.0a1
Bug 1350066 - Skip premult if src is missing color or alpha, and spew formats on reformat. - r=ethlin MozReview-Commit-ID: JeoTq9EX9Rx
dom/canvas/TexUnpackBlob.cpp
--- 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()) {