Bug 1285676 - Use actual bit depths for depth and stencil. - r=ethlin draft
authorJeff Gilbert <jgilbert@mozilla.com>
Fri, 08 Jul 2016 14:57:18 -0700
changeset 385657 607f4275b71b551ed5bd345ef0f5223e73eade75
parent 385656 87b61f63b037683e48e00bd35e0be626b0a01cf3
child 385658 f9ce96600efbb976c48740c690cb842395c356f0
push id22570
push userbmo:jgilbert@mozilla.com
push dateFri, 08 Jul 2016 22:48:58 +0000
reviewersethlin
bugs1285676
milestone50.0a1
Bug 1285676 - Use actual bit depths for depth and stencil. - r=ethlin MozReview-Commit-ID: FX3Ev3noJ6U
dom/canvas/WebGLContext.cpp
dom/canvas/WebGLFormats.cpp
dom/canvas/WebGLFormats.h
dom/canvas/WebGLFramebuffer.cpp
dom/canvas/WebGLRenderbuffer.cpp
dom/canvas/WebGLTexture.cpp
dom/canvas/WebGLTextureUpload.cpp
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -2100,29 +2100,29 @@ ZeroTexImageWithClear(WebGLContext* webg
     ScopedFramebuffer scopedFB(gl);
     ScopedBindFramebuffer scopedBindFB(gl, scopedFB.FB());
 
     const auto format = usage->format;
 
     GLenum attachPoint = 0;
     GLbitfield clearBits = 0;
 
-    if (format->isColorFormat) {
+    if (format->IsColorFormat()) {
         attachPoint = LOCAL_GL_COLOR_ATTACHMENT0;
         clearBits = LOCAL_GL_COLOR_BUFFER_BIT;
     }
 
-    if (format->hasDepth) {
+    if (format->d) {
         attachPoint = LOCAL_GL_DEPTH_ATTACHMENT;
         clearBits |= LOCAL_GL_DEPTH_BUFFER_BIT;
     }
 
-    if (format->hasStencil) {
-        attachPoint = (format->hasDepth ? LOCAL_GL_DEPTH_STENCIL_ATTACHMENT
-                                        : LOCAL_GL_STENCIL_ATTACHMENT);
+    if (format->s) {
+        attachPoint = (format->d ? LOCAL_GL_DEPTH_STENCIL_ATTACHMENT
+                                 : LOCAL_GL_STENCIL_ATTACHMENT);
         clearBits |= LOCAL_GL_STENCIL_BUFFER_BIT;
     }
 
     MOZ_RELEASE_ASSERT(attachPoint && clearBits, "GFX: No bits cleared.");
 
     {
         gl::GLContext::LocalErrorScope errorScope(*gl);
         gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, attachPoint, target.get(), tex,
--- a/dom/canvas/WebGLFormats.cpp
+++ b/dom/canvas/WebGLFormats.cpp
@@ -124,67 +124,77 @@ InitCompressedFormatInfo()
 //////////////////////////////////////////////////////////////////////////////////////////
 
 static void
 AddFormatInfo(EffectiveFormat format, const char* name, GLenum sizedFormat,
               uint8_t bytesPerPixel, uint8_t r, uint8_t g, uint8_t b, uint8_t a,
               uint8_t d, uint8_t s, UnsizedFormat unsizedFormat, bool isSRGB,
               ComponentType componentType)
 {
+    switch (unsizedFormat) {
+    case UnsizedFormat::R:
+        MOZ_ASSERT(r && !g && !b && !a && !d && !s);
+        break;
+
+    case UnsizedFormat::RG:
+        MOZ_ASSERT(r && g && !b && !a && !d && !s);
+        break;
+
+    case UnsizedFormat::RGB:
+        MOZ_ASSERT(r && g && b && !a && !d && !s);
+        break;
+
+    case UnsizedFormat::RGBA:
+        MOZ_ASSERT(r && g && b && a && !d && !s);
+        break;
+
+    case UnsizedFormat::L:
+        MOZ_ASSERT(r && !g && !b && !a && !d && !s);
+        break;
+
+    case UnsizedFormat::A:
+        MOZ_ASSERT(!r && !g && !b && a && !d && !s);
+        break;
+
+    case UnsizedFormat::LA:
+        MOZ_ASSERT(r && !g && !b && a && !d && !s);
+        break;
+
+    case UnsizedFormat::D:
+        MOZ_ASSERT(!r && !g && !b && !a && d && !s);
+        break;
+
+    case UnsizedFormat::S:
+        MOZ_ASSERT(!r && !g && !b && !a && !d && s);
+        break;
+
+    case UnsizedFormat::DS:
+        MOZ_ASSERT(!r && !g && !b && !a && d && s);
+        break;
+    }
+
+    const CompressedFormatInfo* compressedFormatInfo = GetCompressedFormatInfo(format);
+    MOZ_ASSERT(!bytesPerPixel == bool(compressedFormatInfo));
+
 #ifdef DEBUG
     uint8_t totalBits = r + g + b + a + d + s;
     if (format == EffectiveFormat::RGB9_E5) {
         totalBits = 9 + 9 + 9 + 5;
     }
-    MOZ_ASSERT(totalBits == bytesPerPixel*8);
+
+    if (compressedFormatInfo) {
+        MOZ_ASSERT(totalBits);
+        MOZ_ASSERT(!bytesPerPixel);
+    } else {
+        MOZ_ASSERT(totalBits == bytesPerPixel*8);
+    }
 #endif
 
-    bool isColorFormat = false;
-    bool hasAlpha = false;
-    bool hasDepth = false;
-    bool hasStencil = false;
-
-    switch (unsizedFormat) {
-    case UnsizedFormat::L:
-    case UnsizedFormat::R:
-    case UnsizedFormat::RG:
-    case UnsizedFormat::RGB:
-        isColorFormat = true;
-        break;
-
-    case UnsizedFormat::A: // Alpha is a 'color format' since it's 'color-attachable'.
-    case UnsizedFormat::LA:
-    case UnsizedFormat::RGBA:
-        isColorFormat = true;
-        hasAlpha = true;
-        break;
-
-    case UnsizedFormat::D:
-        hasDepth = true;
-        break;
-
-    case UnsizedFormat::S:
-        hasStencil = true;
-        break;
-
-    case UnsizedFormat::DS:
-        hasDepth = true;
-        hasStencil = true;
-        break;
-
-    default:
-        MOZ_CRASH("GFX: Missing UnsizedFormat case.");
-    }
-
-    const CompressedFormatInfo* compressedFormatInfo = GetCompressedFormatInfo(format);
-    MOZ_ASSERT(!bytesPerPixel == bool(compressedFormatInfo));
-
     const FormatInfo info = { format, name, sizedFormat, unsizedFormat, componentType,
-                              bytesPerPixel, r,g,b,a, isColorFormat, isSRGB, hasAlpha,
-                              hasDepth, hasStencil, compressedFormatInfo };
+                              isSRGB, compressedFormatInfo, bytesPerPixel, r,g,b,a,d,s };
     AlwaysInsert(gFormatInfoMap, format, info);
 }
 
 static void
 InitFormatInfo()
 {
 #define FOO(x) EffectiveFormat::x, #x, LOCAL_GL_ ## x
 
@@ -253,46 +263,46 @@ InitFormatInfo()
     AddFormatInfo(FOO(DEPTH24_STENCIL8  ), 4, 0,0,0,0, 24,8, UnsizedFormat::DS, false, ComponentType::Special);
     AddFormatInfo(FOO(DEPTH32F_STENCIL8 ), 5, 0,0,0,0, 32,8, UnsizedFormat::DS, false, ComponentType::Special);
 
     // GLES 3.0.4, p205-206, "Required Renderbuffer Formats"
     AddFormatInfo(FOO(STENCIL_INDEX8), 1, 0,0,0,0, 0,8, UnsizedFormat::S, false, ComponentType::UInt);
 
     // GLES 3.0.4, p147, table 3.19
     // GLES 3.0.4  p286+  $C.1 "ETC Compressed Texture Image Formats"
-    AddFormatInfo(FOO(COMPRESSED_RGB8_ETC2                     ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
-    AddFormatInfo(FOO(COMPRESSED_SRGB8_ETC2                    ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , true , ComponentType::NormUInt);
-    AddFormatInfo(FOO(COMPRESSED_RGBA8_ETC2_EAC                ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
-    AddFormatInfo(FOO(COMPRESSED_SRGB8_ALPHA8_ETC2_EAC         ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, true , ComponentType::NormUInt);
-    AddFormatInfo(FOO(COMPRESSED_R11_EAC                       ), 0, 0,0,0,0, 0,0, UnsizedFormat::R   , false, ComponentType::NormUInt);
-    AddFormatInfo(FOO(COMPRESSED_RG11_EAC                      ), 0, 0,0,0,0, 0,0, UnsizedFormat::RG  , false, ComponentType::NormUInt);
-    AddFormatInfo(FOO(COMPRESSED_SIGNED_R11_EAC                ), 0, 0,0,0,0, 0,0, UnsizedFormat::R   , false, ComponentType::NormInt );
-    AddFormatInfo(FOO(COMPRESSED_SIGNED_RG11_EAC               ), 0, 0,0,0,0, 0,0, UnsizedFormat::RG  , false, ComponentType::NormInt );
-    AddFormatInfo(FOO(COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
-    AddFormatInfo(FOO(COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, true , ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_RGB8_ETC2                     ), 0, 1,1,1,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_SRGB8_ETC2                    ), 0, 1,1,1,0, 0,0, UnsizedFormat::RGB , true , ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_RGBA8_ETC2_EAC                ), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_SRGB8_ALPHA8_ETC2_EAC         ), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, true , ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_R11_EAC                       ), 0, 1,0,0,0, 0,0, UnsizedFormat::R   , false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_RG11_EAC                      ), 0, 1,1,0,0, 0,0, UnsizedFormat::RG  , false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_SIGNED_R11_EAC                ), 0, 1,0,0,0, 0,0, UnsizedFormat::R   , false, ComponentType::NormInt );
+    AddFormatInfo(FOO(COMPRESSED_SIGNED_RG11_EAC               ), 0, 1,1,0,0, 0,0, UnsizedFormat::RG  , false, ComponentType::NormInt );
+    AddFormatInfo(FOO(COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 ), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, true , ComponentType::NormUInt);
 
     // AMD_compressed_ATC_texture
-    AddFormatInfo(FOO(ATC_RGB_AMD                    ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
-    AddFormatInfo(FOO(ATC_RGBA_EXPLICIT_ALPHA_AMD    ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
-    AddFormatInfo(FOO(ATC_RGBA_INTERPOLATED_ALPHA_AMD), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(ATC_RGB_AMD                    ), 0, 1,1,1,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(ATC_RGBA_EXPLICIT_ALPHA_AMD    ), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(ATC_RGBA_INTERPOLATED_ALPHA_AMD), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
 
     // EXT_texture_compression_s3tc
-    AddFormatInfo(FOO(COMPRESSED_RGB_S3TC_DXT1_EXT ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
-    AddFormatInfo(FOO(COMPRESSED_RGBA_S3TC_DXT1_EXT), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
-    AddFormatInfo(FOO(COMPRESSED_RGBA_S3TC_DXT3_EXT), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
-    AddFormatInfo(FOO(COMPRESSED_RGBA_S3TC_DXT5_EXT), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_RGB_S3TC_DXT1_EXT ), 0, 1,1,1,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_RGBA_S3TC_DXT1_EXT), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_RGBA_S3TC_DXT3_EXT), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_RGBA_S3TC_DXT5_EXT), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
 
     // IMG_texture_compression_pvrtc
-    AddFormatInfo(FOO(COMPRESSED_RGB_PVRTC_4BPPV1 ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
-    AddFormatInfo(FOO(COMPRESSED_RGBA_PVRTC_4BPPV1), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
-    AddFormatInfo(FOO(COMPRESSED_RGB_PVRTC_2BPPV1 ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
-    AddFormatInfo(FOO(COMPRESSED_RGBA_PVRTC_2BPPV1), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_RGB_PVRTC_4BPPV1 ), 0, 1,1,1,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_RGBA_PVRTC_4BPPV1), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_RGB_PVRTC_2BPPV1 ), 0, 1,1,1,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(COMPRESSED_RGBA_PVRTC_2BPPV1), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
 
     // OES_compressed_ETC1_RGB8_texture
-    AddFormatInfo(FOO(ETC1_RGB8_OES), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB, false, ComponentType::NormUInt);
+    AddFormatInfo(FOO(ETC1_RGB8_OES), 0, 1,1,1,0, 0,0, UnsizedFormat::RGB, false, ComponentType::NormUInt);
 
 #undef FOO
 
     // 'Virtual' effective formats have no sizedFormat.
 #define FOO(x) EffectiveFormat::x, #x, 0
 
     // GLES 3.0.4, p128, table 3.12.
     AddFormatInfo(FOO(Luminance8Alpha8), 2, 8,0,0,8, 0,0, UnsizedFormat::LA, false, ComponentType::NormUInt);
@@ -634,17 +644,17 @@ AddUnsizedFormats(FormatUsageAuthority* 
 
 void
 FormatUsageInfo::SetRenderable()
 {
     this->isRenderable = true;
 
 #ifdef DEBUG
     const auto format = this->format;
-    if (format->isColorFormat) {
+    if (format->IsColorFormat()) {
         const auto& map = format->copyDecayFormats;
         const auto itr = map.find(format->unsizedFormat);
         MOZ_ASSERT(itr != map.end(), "Renderable formats must be in copyDecayFormats.");
         MOZ_ASSERT(itr->second == format);
     }
 #endif
 }
 
--- a/dom/canvas/WebGLFormats.h
+++ b/dom/canvas/WebGLFormats.h
@@ -193,32 +193,41 @@ struct CompressedFormatInfo
 
 struct FormatInfo
 {
     const EffectiveFormat effectiveFormat;
     const char* const name;
     const GLenum sizedFormat;
     const UnsizedFormat unsizedFormat;
     const ComponentType componentType;
-    const uint8_t estimatedBytesPerPixel; // 0 iff `!!compression`. Only use this for
+    const bool isSRGB;
+
+    const CompressedFormatInfo* const compression;
+
+    const uint8_t estimatedBytesPerPixel; // 0 iff bool(compression).
+
+    // In bits. Iff bool(compression), active channels are 1.
     const uint8_t r;
     const uint8_t g;
     const uint8_t b;
     const uint8_t a;
-    const bool isColorFormat;             // memory usage estimation. Use
-    const bool isSRGB;                    // BytesPerPixel(packingFormat, packingType) for
-    const bool hasAlpha;                  // calculating pack/unpack byte count.
-    const bool hasDepth;
-    const bool hasStencil;
+    const uint8_t d;
+    const uint8_t s;
 
-    const CompressedFormatInfo* const compression;
+    //////
 
     std::map<UnsizedFormat, const FormatInfo*> copyDecayFormats;
 
     const FormatInfo* GetCopyDecayFormat(UnsizedFormat) const;
+
+    bool IsColorFormat() const {
+         // Alpha is a 'color format' since it's 'color-attachable'.
+        return bool(compression) ||
+               bool(r | g | b | a);
+    }
 };
 
 struct PackingInfo
 {
     GLenum format;
     GLenum type;
 
     bool operator <(const PackingInfo& x) const
--- a/dom/canvas/WebGLFramebuffer.cpp
+++ b/dom/canvas/WebGLFramebuffer.cpp
@@ -78,17 +78,17 @@ WebGLFBAttachPoint::Samples() const
         return mRenderbufferPtr->Samples();
 
     return 0;
 }
 
 bool
 WebGLFBAttachPoint::HasAlpha() const
 {
-    return Format()->format->hasAlpha;
+    return Format()->format->a;
 }
 
 const webgl::FormatUsageInfo*
 WebGLFramebuffer::GetFormatForAttachment(const WebGLFBAttachPoint& attachment) const
 {
     MOZ_ASSERT(attachment.IsDefined());
     MOZ_ASSERT(attachment.Texture() || attachment.Renderbuffer());
 
@@ -97,17 +97,17 @@ WebGLFramebuffer::GetFormatForAttachment
 
 bool
 WebGLFBAttachPoint::IsReadableFloat() const
 {
     auto formatUsage = Format();
     MOZ_ASSERT(formatUsage);
 
     auto format = formatUsage->format;
-    if (!format->isColorFormat)
+    if (!format->IsColorFormat())
         return false;
 
     return format->componentType == webgl::ComponentType::Float;
 }
 
 void
 WebGLFBAttachPoint::Clear()
 {
@@ -289,50 +289,50 @@ WebGLFBAttachPoint::IsComplete(WebGLCont
     }
 
     const auto format = formatUsage->format;
 
     bool hasRequiredBits;
 
     switch (mAttachmentPoint) {
     case LOCAL_GL_DEPTH_ATTACHMENT:
-        hasRequiredBits = format->hasDepth;
+        hasRequiredBits = format->d;
         break;
 
     case LOCAL_GL_STENCIL_ATTACHMENT:
-        hasRequiredBits = format->hasStencil;
+        hasRequiredBits = format->s;
         break;
 
     case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
         MOZ_ASSERT(!webgl->IsWebGL2());
-        hasRequiredBits = (format->hasDepth && format->hasStencil);
+        hasRequiredBits = (format->d && format->s);
         break;
 
     default:
         MOZ_ASSERT(mAttachmentPoint >= LOCAL_GL_COLOR_ATTACHMENT0);
-        hasRequiredBits = format->isColorFormat;
+        hasRequiredBits = format->IsColorFormat();
         break;
     }
 
     if (!hasRequiredBits) {
         AttachmentName(out_info);
         out_info->AppendLiteral("'s format is missing required color/depth/stencil bits");
         return false;
     }
 
     if (!webgl->IsWebGL2()) {
         bool hasSurplusPlanes = false;
 
         switch (mAttachmentPoint) {
         case LOCAL_GL_DEPTH_ATTACHMENT:
-            hasSurplusPlanes = format->hasStencil;
+            hasSurplusPlanes = format->s;
             break;
 
         case LOCAL_GL_STENCIL_ATTACHMENT:
-            hasSurplusPlanes = format->hasDepth;
+            hasSurplusPlanes = format->d;
             break;
         }
 
         if (hasSurplusPlanes) {
             AttachmentName(out_info);
             out_info->AppendLiteral("'s format has depth or stencil bits when it"
                                     " shouldn't");
             return false;
--- a/dom/canvas/WebGLRenderbuffer.cpp
+++ b/dom/canvas/WebGLRenderbuffer.cpp
@@ -253,17 +253,17 @@ WebGLRenderbuffer::GetRenderbufferParame
 {
     gl::GLContext* gl = mContext->gl;
 
     switch (pname.get()) {
     case LOCAL_GL_RENDERBUFFER_STENCIL_SIZE:
         if (!mFormat)
             return 0;
 
-        if (!mFormat->format->hasStencil)
+        if (!mFormat->format->s)
             return 0;
 
         return 8;
 
     case LOCAL_GL_RENDERBUFFER_SAMPLES:
     case LOCAL_GL_RENDERBUFFER_WIDTH:
     case LOCAL_GL_RENDERBUFFER_HEIGHT:
     case LOCAL_GL_RENDERBUFFER_RED_SIZE:
--- a/dom/canvas/WebGLTexture.cpp
+++ b/dom/canvas/WebGLTexture.cpp
@@ -338,17 +338,17 @@ WebGLTexture::IsComplete(uint32_t texUni
         auto format = formatUsage->format;
 
         // "* The effective internal format specified for the texture arrays is a sized
         //    internal color format that is not texture-filterable, and either the
         //    magnification filter is not NEAREST or the minification filter is neither
         //    NEAREST nor NEAREST_MIPMAP_NEAREST."
         // Since all (GLES3) unsized color formats are filterable just like their sized
         // equivalents, we don't have to care whether its sized or not.
-        if (format->isColorFormat && !formatUsage->isFilterable) {
+        if (format->IsColorFormat() && !formatUsage->isFilterable) {
             *out_reason = "Because minification or magnification filtering is not NEAREST"
                           " or NEAREST_MIPMAP_NEAREST, and the texture's format is a"
                           " color format, its format must be \"texture-filterable\".";
             return false;
         }
 
         // "* The effective internal format specified for the texture arrays is a sized
         //    internal depth or depth and stencil format, the value of
@@ -358,17 +358,17 @@ WebGLTexture::IsComplete(uint32_t texUni
         // [1]: This sounds suspect, but is explicitly noted in the change log for GLES
         //      3.0.1:
         //      "* Clarify that a texture is incomplete if it has a depth component, no
         //         shadow comparison, and linear filtering (also Bug 9481)."
         // As of OES_packed_depth_stencil rev #3, the sample code explicitly samples from
         // a DEPTH_STENCIL_OES texture with a min-filter of LINEAR. Therefore we relax
         // this restriction if WEBGL_depth_texture is enabled.
         if (!mContext->IsExtensionEnabled(WebGLExtensionID::WEBGL_depth_texture)) {
-            if (format->hasDepth && mTexCompareMode != LOCAL_GL_NONE) {
+            if (format->d && mTexCompareMode != LOCAL_GL_NONE) {
                 *out_reason = "A depth or depth-stencil format with TEXTURE_COMPARE_MODE"
                               " of NONE must have minification or magnification filtering"
                               " of NEAREST or NEAREST_MIPMAP_NEAREST.";
                 return false;
             }
         }
     }
 
@@ -481,19 +481,19 @@ WebGLTexture::GetFakeBlackType(const cha
 
     if (!hasUninitializedData) {
         *out_fakeBlack = FakeBlackType::None;
         return true;
     }
 
     if (!hasInitializedData) {
         const auto format = ImageInfoAtFace(0, mBaseMipmapLevel).mFormat->format;
-        if (format->isColorFormat) {
-            *out_fakeBlack = (format->hasAlpha ? FakeBlackType::RGBA0000
-                                               : FakeBlackType::RGBA0001);
+        if (format->IsColorFormat()) {
+            *out_fakeBlack = (format->a ? FakeBlackType::RGBA0000
+                                        : FakeBlackType::RGBA0001);
             return true;
         }
 
         mContext->GenerateWarning("%s: Active texture %u for target 0x%04x is"
                                   " uninitialized, and will be (perhaps slowly) cleared"
                                   " by the implementation.",
                                   funcName, texUnit, mTarget.get());
     } else {
@@ -731,17 +731,17 @@ WebGLTexture::GenerateMipmap(TexTarget t
 
     auto format = baseImageInfo.mFormat->format;
     if (format->compression) {
         mContext->ErrorInvalidOperation("generateMipmap: Texture data at base level is"
                                         " compressed.");
         return;
     }
 
-    if (format->hasDepth) {
+    if (format->d) {
         mContext->ErrorInvalidOperation("generateMipmap: Depth textures are not"
                                         " supported.");
         return;
     }
 
     // OpenGL ES 3.0.4 p160:
     // If the level base array was not specified with an unsized internal format from
     // table 3.3 or a sized internal format that is both color-renderable and
--- a/dom/canvas/WebGLTextureUpload.cpp
+++ b/dom/canvas/WebGLTextureUpload.cpp
@@ -1256,17 +1256,17 @@ WebGLTexture::TexImage(const char* funcN
 
     ////////////////////////////////////
     // Check that source and dest info are compatible
     auto dstFormat = dstUsage->format;
 
     if (!ValidateTargetForFormat(funcName, mContext, target, dstFormat))
         return;
 
-    if (!mContext->IsWebGL2() && dstFormat->hasDepth) {
+    if (!mContext->IsWebGL2() && dstFormat->d) {
         if (target != LOCAL_GL_TEXTURE_2D ||
             blob->mHasData ||
             level != 0)
         {
             mContext->ErrorInvalidOperation("%s: With format %s, this function may only"
                                             " be called with target=TEXTURE_2D,"
                                             " data=null, and level=0.",
                                             funcName, dstFormat->name);
@@ -1340,17 +1340,17 @@ WebGLTexture::TexSubImage(const char* fu
     auto dstFormat = dstUsage->format;
 
     if (dstFormat->compression) {
         mContext->ErrorInvalidEnum("%s: Specified TexImage must not be compressed.",
                                    funcName);
         return;
     }
 
-    if (!mContext->IsWebGL2() && dstFormat->hasDepth) {
+    if (!mContext->IsWebGL2() && dstFormat->d) {
         mContext->ErrorInvalidOperation("%s: Function may not be called on a texture of"
                                         " format %s.",
                                         funcName, dstFormat->name);
         return;
     }
 
     ////////////////////////////////////
     // Get source info
@@ -1990,17 +1990,17 @@ WebGLTexture::CopyTexImage2D(TexImageTar
     if (!dstUsage)
         return;
 
     const auto dstFormat = dstUsage->format;
 
     if (!ValidateTargetForFormat(funcName, mContext, target, dstFormat))
         return;
 
-    if (!mContext->IsWebGL2() && dstFormat->hasDepth) {
+    if (!mContext->IsWebGL2() && dstFormat->d) {
         mContext->ErrorInvalidOperation("%s: Function may not be called with format %s.",
                                         funcName, dstFormat->name);
         return;
     }
 
     if (!ValidateCopyTexImageFormats(mContext, funcName, srcFormat, dstFormat))
         return;
 
@@ -2090,17 +2090,17 @@ WebGLTexture::CopyTexSubImage(const char
         return;
     }
     MOZ_ASSERT(imageInfo);
 
     auto dstUsage = imageInfo->mFormat;
     MOZ_ASSERT(dstUsage);
     auto dstFormat = dstUsage->format;
 
-    if (!mContext->IsWebGL2() && dstFormat->hasDepth) {
+    if (!mContext->IsWebGL2() && dstFormat->d) {
         mContext->ErrorInvalidOperation("%s: Function may not be called on a texture of"
                                         " format %s.",
                                         funcName, dstFormat->name);
         return;
     }
 
     ////////////////////////////////////
     // Get source info