Bug 1499580 - Check enum in CompressedTexSubImage. r=kvark
authorJeff Gilbert <jgilbert@mozilla.com>
Wed, 17 Oct 2018 19:13:14 +0000
changeset 490150 c29585c36177f6c1fa00049c519f89b12bd779e3
parent 490149 b94a2aa50ef2a049dace3fb54fbaf825c6503a25
child 490151 a58c07d9a7fa325c65fb00b7a6b2b8cc25a7af1d
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewerskvark
bugs1499580
milestone64.0a1
Bug 1499580 - Check enum in CompressedTexSubImage. r=kvark Also skip some redundent `compression` checks. Differential Revision: https://phabricator.services.mozilla.com/D8938
dom/canvas/WebGLTextureUpload.cpp
--- a/dom/canvas/WebGLTextureUpload.cpp
+++ b/dom/canvas/WebGLTextureUpload.cpp
@@ -1299,21 +1299,16 @@ WebGLTexture::TexSubImage(TexImageTarget
     {
         return;
     }
     MOZ_ASSERT(imageInfo);
 
     auto dstUsage = imageInfo->mFormat;
     auto dstFormat = dstUsage->format;
 
-    if (dstFormat->compression) {
-        mContext->ErrorInvalidEnum("Specified TexImage must not be compressed.");
-        return;
-    }
-
     if (!mContext->IsWebGL2() && dstFormat->d) {
         mContext->ErrorInvalidOperation("Function may not be called on a texture of"
                                         " format %s.",
                                         dstFormat->name);
         return;
     }
 
     ////////////////////////////////////
@@ -1417,27 +1412,21 @@ WebGLTexture::CompressedTexImage(TexImag
     if (!ValidateTexImageSpecification(target, level, blob->mWidth,
                                        blob->mHeight, blob->mDepth, &imageInfo))
     {
         return;
     }
     MOZ_ASSERT(imageInfo);
 
     auto usage = mContext->mFormatUsage->GetSizedTexUsage(internalFormat);
-    if (!usage) {
-        mContext->ErrorInvalidEnum("Invalid internalFormat: 0x%04x",
-                                   internalFormat);
+    if (!usage || !usage->format->compression) {
+        mContext->ErrorInvalidEnumArg("internalFormat", internalFormat);
         return;
     }
-
     auto format = usage->format;
-    if (!format->compression) {
-        mContext->ErrorInvalidEnum("Specified internalFormat must be compressed.");
-        return;
-    }
 
     if (!ValidateTargetForFormat(mContext, target, format))
         return;
 
     ////////////////////////////////////
     // Get source info
 
     if (!ValidateCompressedTexUnpack(mContext, blob->mWidth, blob->mHeight,
@@ -1535,21 +1524,20 @@ WebGLTexture::CompressedTexSubImage(TexI
 
     auto dstUsage = imageInfo->mFormat;
     auto dstFormat = dstUsage->format;
 
     ////////////////////////////////////
     // Get source info
 
     auto srcUsage = mContext->mFormatUsage->GetSizedTexUsage(sizedUnpackFormat);
-    if (!srcUsage->format->compression) {
-        mContext->ErrorInvalidEnum("Specified format must be compressed.");
+    if (!srcUsage || !srcUsage->format->compression) {
+        mContext->ErrorInvalidEnumArg("sizedUnpackFormat", sizedUnpackFormat);
         return;
     }
-
     if (srcUsage != dstUsage) {
         mContext->ErrorInvalidOperation("`format` must match the format of the"
                                         " existing texture image.");
         return;
     }
 
     auto format = srcUsage->format;
     MOZ_ASSERT(format == dstFormat);