Bug 1097411 - Extend error reporting. r=jgilbert
authorDan Glastonbury <dglastonbury@mozilla.com>
Mon, 27 Oct 2014 09:35:02 +1000
changeset 241357 5fdc1acbc53fd5b5cea00229184b9ec981419f34
parent 241356 26112e1b5c61b382bfc61dc68065e1946a99313d
child 241358 86048e13f7d75c58396959651aa5cbffa52896f9
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1097411
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1097411 - Extend error reporting. r=jgilbert
dom/canvas/WebGL2ContextTextures.cpp
dom/canvas/WebGLContext.h
dom/canvas/WebGLContextUtils.cpp
--- a/dom/canvas/WebGL2ContextTextures.cpp
+++ b/dom/canvas/WebGL2ContextTextures.cpp
@@ -68,25 +68,22 @@ WebGL2Context::ValidateSizedInternalForm
     case LOCAL_GL_DEPTH_COMPONENT16:
     case LOCAL_GL_DEPTH_COMPONENT24:
     case LOCAL_GL_DEPTH_COMPONENT32F:
     case LOCAL_GL_DEPTH24_STENCIL8:
     case LOCAL_GL_DEPTH32F_STENCIL8:
         return true;
     }
 
-    if (IsCompressedTextureFormat(internalformat)) {
+    if (IsCompressedTextureFormat(internalformat))
         return true;
-    }
 
-    const char* name = EnumName(internalformat);
-    if (name && name[0] != '[')
-        ErrorInvalidEnum("%s: invalid internal format %s", info, name);
-    else
-        ErrorInvalidEnum("%s: invalid internal format 0x%04X", info, internalformat);
+    nsCString name;
+    EnumName(internalformat, &name);
+    ErrorInvalidEnum("%s: invalid internal format %s", info, name.get());
 
     return false;
 }
 
 /** Validates parameters to texStorage{2D,3D} */
 bool
 WebGL2Context::ValidateTexStorage(GLenum target, GLsizei levels, GLenum internalformat,
                                       GLsizei width, GLsizei height, GLsizei depth,
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -237,17 +237,21 @@ public:
 
     const char *ErrorName(GLenum error);
 
     /**
      * Return displayable name for GLenum.
      * This version is like gl::GLenumToStr but with out the GL_ prefix to
      * keep consistency with how errors are reported from WebGL.
      */
-    static const char *EnumName(GLenum glenum);
+
+    // Returns nullptr if glenum is unknown.
+    static const char* EnumName(GLenum glenum);
+    // Returns hex formatted version of glenum if glenum is unknown.
+    static void EnumName(GLenum glenum, nsACString* out_name);
 
     bool IsCompressedTextureFormat(GLenum format);
     bool IsTextureFormatCompressed(TexInternalFormat format);
 
     void DummyFramebufferOperation(const char *info);
 
     WebGLTexture* activeBoundTextureForTarget(const TexTarget texTarget) const {
         switch (texTarget.get()) {
--- a/dom/canvas/WebGLContextUtils.cpp
+++ b/dom/canvas/WebGLContextUtils.cpp
@@ -9,16 +9,17 @@
 
 #include "GLContext.h"
 #include "jsapi.h"
 #include "mozilla/Preferences.h"
 #include "nsIDOMDataContainerEvent.h"
 #include "nsIDOMEvent.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIVariant.h"
+#include "nsPrintfCString.h"
 #include "nsServiceManagerUtils.h"
 #include "prprf.h"
 #include "WebGLBuffer.h"
 #include "WebGLExtensions.h"
 #include "WebGLFramebuffer.h"
 #include "WebGLProgram.h"
 #include "WebGLTexture.h"
 #include "WebGLVertexArray.h"
@@ -500,17 +501,20 @@ WebGLContext::ErrorInvalidEnum(const cha
     va_end(va);
 
     return SynthesizeGLError(LOCAL_GL_INVALID_ENUM);
 }
 
 void
 WebGLContext::ErrorInvalidEnumInfo(const char *info, GLenum enumvalue)
 {
-    return ErrorInvalidEnum("%s: invalid enum value 0x%x", info, enumvalue);
+    nsCString name;
+    EnumName(enumvalue, &name);
+
+    return ErrorInvalidEnum("%s: invalid enum value %s", info, name.get());
 }
 
 void
 WebGLContext::ErrorInvalidOperation(const char *fmt, ...)
 {
     va_list va;
     va_start(va, fmt);
     GenerateWarning(fmt, va);
@@ -569,16 +573,17 @@ WebGLContext::ErrorName(GLenum error)
         case LOCAL_GL_NO_ERROR:
             return "NO_ERROR";
         default:
             MOZ_ASSERT(false);
             return "[unknown WebGL error!]";
     }
 }
 
+// This version is 'fallible' and will return NULL if glenum is not recognized.
 const char*
 WebGLContext::EnumName(GLenum glenum)
 {
     switch (glenum) {
 #define XX(x) case LOCAL_GL_##x: return #x
         XX(ALPHA);
         XX(ATC_RGB);
         XX(ATC_RGBA_EXPLICIT_ALPHA);
@@ -620,20 +625,299 @@ WebGLContext::EnumName(GLenum glenum)
         XX(TEXTURE_CUBE_MAP_POSITIVE_Z);
         XX(UNSIGNED_BYTE);
         XX(UNSIGNED_INT);
         XX(UNSIGNED_INT_24_8);
         XX(UNSIGNED_SHORT);
         XX(UNSIGNED_SHORT_4_4_4_4);
         XX(UNSIGNED_SHORT_5_5_5_1);
         XX(UNSIGNED_SHORT_5_6_5);
+        XX(READ_BUFFER);
+        XX(UNPACK_ROW_LENGTH);
+        XX(UNPACK_SKIP_ROWS);
+        XX(UNPACK_SKIP_PIXELS);
+        XX(PACK_ROW_LENGTH);
+        XX(PACK_SKIP_ROWS);
+        XX(PACK_SKIP_PIXELS);
+        XX(COLOR);
+        XX(DEPTH);
+        XX(STENCIL);
+        XX(RED);
+        XX(RGB8);
+        XX(RGBA8);
+        XX(RGB10_A2);
+        XX(TEXTURE_BINDING_3D);
+        XX(UNPACK_SKIP_IMAGES);
+        XX(UNPACK_IMAGE_HEIGHT);
+        XX(TEXTURE_WRAP_R);
+        XX(MAX_3D_TEXTURE_SIZE);
+        XX(UNSIGNED_INT_2_10_10_10_REV);
+        XX(MAX_ELEMENTS_VERTICES);
+        XX(MAX_ELEMENTS_INDICES);
+        XX(TEXTURE_MIN_LOD);
+        XX(TEXTURE_MAX_LOD);
+        XX(TEXTURE_BASE_LEVEL);
+        XX(TEXTURE_MAX_LEVEL);
+        XX(MIN);
+        XX(MAX);
+        XX(DEPTH_COMPONENT24);
+        XX(MAX_TEXTURE_LOD_BIAS);
+        XX(TEXTURE_COMPARE_MODE);
+        XX(TEXTURE_COMPARE_FUNC);
+        XX(CURRENT_QUERY);
+        XX(QUERY_RESULT);
+        XX(QUERY_RESULT_AVAILABLE);
+        XX(STREAM_READ);
+        XX(STREAM_COPY);
+        XX(STATIC_READ);
+        XX(STATIC_COPY);
+        XX(DYNAMIC_READ);
+        XX(DYNAMIC_COPY);
+        XX(MAX_DRAW_BUFFERS);
+        XX(DRAW_BUFFER0);
+        XX(DRAW_BUFFER1);
+        XX(DRAW_BUFFER2);
+        XX(DRAW_BUFFER3);
+        XX(DRAW_BUFFER4);
+        XX(DRAW_BUFFER5);
+        XX(DRAW_BUFFER6);
+        XX(DRAW_BUFFER7);
+        XX(DRAW_BUFFER8);
+        XX(DRAW_BUFFER9);
+        XX(DRAW_BUFFER10);
+        XX(DRAW_BUFFER11);
+        XX(DRAW_BUFFER12);
+        XX(DRAW_BUFFER13);
+        XX(DRAW_BUFFER14);
+        XX(DRAW_BUFFER15);
+        XX(MAX_FRAGMENT_UNIFORM_COMPONENTS);
+        XX(MAX_VERTEX_UNIFORM_COMPONENTS);
+        XX(SAMPLER_3D);
+        XX(SAMPLER_2D_SHADOW);
+        XX(FRAGMENT_SHADER_DERIVATIVE_HINT);
+        XX(PIXEL_PACK_BUFFER);
+        XX(PIXEL_UNPACK_BUFFER);
+        XX(PIXEL_PACK_BUFFER_BINDING);
+        XX(PIXEL_UNPACK_BUFFER_BINDING);
+        XX(FLOAT_MAT2x3);
+        XX(FLOAT_MAT2x4);
+        XX(FLOAT_MAT3x2);
+        XX(FLOAT_MAT3x4);
+        XX(FLOAT_MAT4x2);
+        XX(FLOAT_MAT4x3);
+        XX(SRGB8);
+        XX(SRGB8_ALPHA8);
+        XX(COMPARE_REF_TO_TEXTURE);
+        XX(VERTEX_ATTRIB_ARRAY_INTEGER);
+        XX(MAX_ARRAY_TEXTURE_LAYERS);
+        XX(MIN_PROGRAM_TEXEL_OFFSET);
+        XX(MAX_PROGRAM_TEXEL_OFFSET);
+        XX(MAX_VARYING_COMPONENTS);
+        XX(TEXTURE_2D_ARRAY);
+        XX(TEXTURE_BINDING_2D_ARRAY);
+        XX(R11F_G11F_B10F);
+        XX(UNSIGNED_INT_10F_11F_11F_REV);
+        XX(RGB9_E5);
+        XX(UNSIGNED_INT_5_9_9_9_REV);
+        XX(TRANSFORM_FEEDBACK_BUFFER_MODE);
+        XX(MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS);
+        XX(TRANSFORM_FEEDBACK_VARYINGS);
+        XX(TRANSFORM_FEEDBACK_BUFFER_START);
+        XX(TRANSFORM_FEEDBACK_BUFFER_SIZE);
+        XX(TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
+        XX(RASTERIZER_DISCARD);
+        XX(MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS);
+        XX(MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS);
+        XX(INTERLEAVED_ATTRIBS);
+        XX(SEPARATE_ATTRIBS);
+        XX(TRANSFORM_FEEDBACK_BUFFER);
+        XX(TRANSFORM_FEEDBACK_BUFFER_BINDING);
+        XX(RGBA32UI);
+        XX(RGB32UI);
+        XX(RGBA16UI);
+        XX(RGB16UI);
+        XX(RGBA8UI);
+        XX(RGB8UI);
+        XX(RGBA32I);
+        XX(RGB32I);
+        XX(RGBA16I);
+        XX(RGB16I);
+        XX(RGBA8I);
+        XX(RGB8I);
+        XX(RED_INTEGER);
+        XX(RGB_INTEGER);
+        XX(RGBA_INTEGER);
+        XX(SAMPLER_2D_ARRAY);
+        XX(SAMPLER_2D_ARRAY_SHADOW);
+        XX(SAMPLER_CUBE_SHADOW);
+        XX(UNSIGNED_INT_VEC2);
+        XX(UNSIGNED_INT_VEC3);
+        XX(UNSIGNED_INT_VEC4);
+        XX(INT_SAMPLER_2D);
+        XX(INT_SAMPLER_3D);
+        XX(INT_SAMPLER_CUBE);
+        XX(INT_SAMPLER_2D_ARRAY);
+        XX(UNSIGNED_INT_SAMPLER_2D);
+        XX(UNSIGNED_INT_SAMPLER_3D);
+        XX(UNSIGNED_INT_SAMPLER_CUBE);
+        XX(UNSIGNED_INT_SAMPLER_2D_ARRAY);
+        XX(DEPTH_COMPONENT32F);
+        XX(DEPTH32F_STENCIL8);
+        XX(FLOAT_32_UNSIGNED_INT_24_8_REV);
+        XX(FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING);
+        XX(FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE);
+        XX(FRAMEBUFFER_ATTACHMENT_RED_SIZE);
+        XX(FRAMEBUFFER_ATTACHMENT_GREEN_SIZE);
+        XX(FRAMEBUFFER_ATTACHMENT_BLUE_SIZE);
+        XX(FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE);
+        XX(FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE);
+        XX(FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE);
+        XX(FRAMEBUFFER_DEFAULT);
+        XX(DEPTH_STENCIL_ATTACHMENT);
+        XX(UNSIGNED_NORMALIZED);
+        XX(DRAW_FRAMEBUFFER_BINDING);
+        XX(READ_FRAMEBUFFER);
+        XX(DRAW_FRAMEBUFFER);
+        XX(READ_FRAMEBUFFER_BINDING);
+        XX(RENDERBUFFER_SAMPLES);
+        XX(FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER);
+        XX(MAX_COLOR_ATTACHMENTS);
+        XX(COLOR_ATTACHMENT1);
+        XX(COLOR_ATTACHMENT2);
+        XX(COLOR_ATTACHMENT3);
+        XX(COLOR_ATTACHMENT4);
+        XX(COLOR_ATTACHMENT5);
+        XX(COLOR_ATTACHMENT6);
+        XX(COLOR_ATTACHMENT7);
+        XX(COLOR_ATTACHMENT8);
+        XX(COLOR_ATTACHMENT9);
+        XX(COLOR_ATTACHMENT10);
+        XX(COLOR_ATTACHMENT11);
+        XX(COLOR_ATTACHMENT12);
+        XX(COLOR_ATTACHMENT13);
+        XX(COLOR_ATTACHMENT14);
+        XX(COLOR_ATTACHMENT15);
+        XX(FRAMEBUFFER_INCOMPLETE_MULTISAMPLE);
+        XX(MAX_SAMPLES);
+        XX(RG);
+        XX(RG_INTEGER);
+        XX(R8);
+        XX(RG8);
+        XX(R16F);
+        XX(R32F);
+        XX(RG16F);
+        XX(RG32F);
+        XX(R8I);
+        XX(R8UI);
+        XX(R16I);
+        XX(R16UI);
+        XX(R32I);
+        XX(R32UI);
+        XX(RG8I);
+        XX(RG8UI);
+        XX(RG16I);
+        XX(RG16UI);
+        XX(RG32I);
+        XX(RG32UI);
+        XX(VERTEX_ARRAY_BINDING);
+        XX(R8_SNORM);
+        XX(RG8_SNORM);
+        XX(RGB8_SNORM);
+        XX(RGBA8_SNORM);
+        XX(SIGNED_NORMALIZED);
+        XX(PRIMITIVE_RESTART_FIXED_INDEX);
+        XX(COPY_READ_BUFFER);
+        XX(COPY_WRITE_BUFFER);
+        XX(UNIFORM_BUFFER);
+        XX(UNIFORM_BUFFER_BINDING);
+        XX(UNIFORM_BUFFER_START);
+        XX(UNIFORM_BUFFER_SIZE);
+        XX(MAX_VERTEX_UNIFORM_BLOCKS);
+        XX(MAX_FRAGMENT_UNIFORM_BLOCKS);
+        XX(MAX_COMBINED_UNIFORM_BLOCKS);
+        XX(MAX_UNIFORM_BUFFER_BINDINGS);
+        XX(MAX_UNIFORM_BLOCK_SIZE);
+        XX(MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS);
+        XX(MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS);
+        XX(UNIFORM_BUFFER_OFFSET_ALIGNMENT);
+        XX(ACTIVE_UNIFORM_BLOCKS);
+        XX(UNIFORM_TYPE);
+        XX(UNIFORM_SIZE);
+        XX(UNIFORM_BLOCK_INDEX);
+        XX(UNIFORM_OFFSET);
+        XX(UNIFORM_ARRAY_STRIDE);
+        XX(UNIFORM_MATRIX_STRIDE);
+        XX(UNIFORM_IS_ROW_MAJOR);
+        XX(UNIFORM_BLOCK_BINDING);
+        XX(UNIFORM_BLOCK_DATA_SIZE);
+        XX(UNIFORM_BLOCK_ACTIVE_UNIFORMS);
+        XX(UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES);
+        XX(UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER);
+        XX(UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER);
+        XX(MAX_VERTEX_OUTPUT_COMPONENTS);
+        XX(MAX_FRAGMENT_INPUT_COMPONENTS);
+        XX(MAX_SERVER_WAIT_TIMEOUT);
+        XX(OBJECT_TYPE);
+        XX(SYNC_CONDITION);
+        XX(SYNC_STATUS);
+        XX(SYNC_FLAGS);
+        XX(SYNC_FENCE);
+        XX(SYNC_GPU_COMMANDS_COMPLETE);
+        XX(UNSIGNALED);
+        XX(SIGNALED);
+        XX(ALREADY_SIGNALED);
+        XX(TIMEOUT_EXPIRED);
+        XX(CONDITION_SATISFIED);
+        XX(WAIT_FAILED);
+        XX(VERTEX_ATTRIB_ARRAY_DIVISOR);
+        XX(ANY_SAMPLES_PASSED);
+        XX(ANY_SAMPLES_PASSED_CONSERVATIVE);
+        XX(SAMPLER_BINDING);
+        XX(RGB10_A2UI);
+        XX(TEXTURE_SWIZZLE_R);
+        XX(TEXTURE_SWIZZLE_G);
+        XX(TEXTURE_SWIZZLE_B);
+        XX(TEXTURE_SWIZZLE_A);
+        XX(GREEN);
+        XX(BLUE);
+        XX(INT_2_10_10_10_REV);
+        XX(TRANSFORM_FEEDBACK);
+        XX(TRANSFORM_FEEDBACK_PAUSED);
+        XX(TRANSFORM_FEEDBACK_ACTIVE);
+        XX(TRANSFORM_FEEDBACK_BINDING);
+        XX(COMPRESSED_R11_EAC);
+        XX(COMPRESSED_SIGNED_R11_EAC);
+        XX(COMPRESSED_RG11_EAC);
+        XX(COMPRESSED_SIGNED_RG11_EAC);
+        XX(COMPRESSED_RGB8_ETC2);
+        XX(COMPRESSED_SRGB8_ETC2);
+        XX(COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2);
+        XX(COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2);
+        XX(COMPRESSED_RGBA8_ETC2_EAC);
+        XX(COMPRESSED_SRGB8_ALPHA8_ETC2_EAC);
+        XX(TEXTURE_IMMUTABLE_FORMAT);
+        XX(MAX_ELEMENT_INDEX);
+        XX(NUM_SAMPLE_COUNTS);
+        XX(TEXTURE_IMMUTABLE_LEVELS);
 #undef XX
     }
 
-    return "[Unknown enum name]";
+    return nullptr;
+}
+
+void
+WebGLContext::EnumName(GLenum glenum, nsACString* out_name)
+{
+    const char* name = EnumName(glenum);
+    if (name) {
+        *out_name = nsDependentCString(name);
+    } else {
+        nsPrintfCString enumAsHex("<enum 0x%04x>", glenum);
+        *out_name = enumAsHex;
+    }
 }
 
 bool
 WebGLContext::IsCompressedTextureFormat(GLenum format)
 {
     switch (format) {
         case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
         case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: