+2010-06-11 Zhenyao Mo <zmo@google.com>
+
+ Reviewed by Dimitri Glazkov.
+
+ drawElements/drawArrays should validate input parameters according to GLES2 spec
+ https://bugs.webkit.org/show_bug.cgi?id=38700
+
+ * fast/canvas/webgl/draw-arrays-out-of-bounds-expected.txt: Copied from LayoutTests/fast/canvas/webgl/drawArraysOutOfBounds-expected.txt, and fix a few test cases.
+ * fast/canvas/webgl/draw-arrays-out-of-bounds.html: Copied from LayoutTests/fast/canvas/webgl/drawArraysOutOfBounds.html, and fix a few test cases.
+ * fast/canvas/webgl/draw-elements-out-of-bounds-expected.txt: Copied from LayoutTests/fast/canvas/webgl/drawElementssOutOfBounds-expected.txt, and fix a few test cases.
+ * fast/canvas/webgl/draw-elements-out-of-bounds.html: Copied from LayoutTests/fast/canvas/webgl/drawElementssOutOfBounds.html, and fix a few test cases.
+ * fast/canvas/webgl/drawArraysOutOfBounds-expected.txt: Removed.
+ * fast/canvas/webgl/drawArraysOutOfBounds.html: Removed.
+ * fast/canvas/webgl/drawElementssOutOfBounds-expected.txt: Removed.
+ * fast/canvas/webgl/drawElementssOutOfBounds.html: Removed.
+ * fast/canvas/webgl/resources/webgl-test.js: Add helper functions for easy test of gl function errors.
+ (getGLErrorAsString):
+ (shouldGenerateGLError):
+
2010-06-11 Luiz Agostini <luiz.agostini@openbossa.org>, Kenneth Rohde Christiansen <kenneth@webkit.org>
Reviewed by Antti Koivisto.
--- /dev/null
+Test of drawArrays with out-of-bounds parameters
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Test empty buffer
+PASS context.drawArrays(context.TRIANGLES, 0, 10000) generated expected GL error: INVALID_OPERATION.
+PASS context.drawArrays(context.TRIANGLES, 0, -1) generated expected GL error: INVALID_VALUE.
+PASS context.drawArrays(context.TRIANGLES, -1, 0) generated expected GL error: INVALID_VALUE.
+PASS context.drawArrays(context.TRIANGLES, 0, 0) generated expected GL error: NO_ERROR.
+PASS context.drawArrays(context.TRIANGLES, 100, 0) generated expected GL error: NO_ERROR.
+
+Test buffer with 3 float vectors
+PASS context.checkFramebufferStatus(context.FRAMEBUFFER) is context.FRAMEBUFFER_COMPLETE
+PASS context.drawArrays(context.TRIANGLES, 0, 3) is undefined
+PASS context.drawArrays(context.TRIANGLES, 0, 3) generated expected GL error: NO_ERROR.
+PASS context.drawArrays(0x0009, 0, 3) generated expected GL error: INVALID_ENUM.
+PASS context.drawArrays(context.TRIANGLES, 3, 2) generated expected GL error: INVALID_OPERATION.
+PASS context.drawArrays(context.TRIANGLES, 0, 10000) generated expected GL error: INVALID_OPERATION.
+PASS context.drawArrays(context.TRIANGLES, 0, -1) generated expected GL error: INVALID_VALUE.
+PASS context.drawArrays(context.TRIANGLES, -1, 0) generated expected GL error: INVALID_VALUE.
+PASS context.drawArrays(context.TRIANGLES, 0, 0) generated expected GL error: NO_ERROR.
+PASS context.drawArrays(context.TRIANGLES, 100, 0) generated expected GL error: NO_ERROR.
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
--- /dev/null
+<html>
+<head>
+<link rel="stylesheet" href="../../js/resources/js-test-style.css"/>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script src="resources/webgl-test.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+
+<script>
+description("Test of drawArrays with out-of-bounds parameters");
+
+var context = create3DContext();
+var program = loadStandardProgram(context);
+
+context.useProgram(program);
+var vertexObject = context.createBuffer();
+context.bindBuffer(context.ARRAY_BUFFER, vertexObject);
+context.enableVertexAttribArray(0);
+
+debug("Test empty buffer")
+context.bufferData(context.ARRAY_BUFFER, new WebGLFloatArray([ ]), context.STATIC_DRAW);
+context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
+shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 10000)");
+shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 0, -1)");
+shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -1, 0)");
+shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 0, 0)");
+shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 100, 0)");
+
+debug("")
+debug("Test buffer with 3 float vectors")
+context.bufferData(context.ARRAY_BUFFER, new WebGLFloatArray([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), context.STATIC_DRAW);
+context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
+shouldBe("context.checkFramebufferStatus(context.FRAMEBUFFER)", "context.FRAMEBUFFER_COMPLETE");
+shouldBe("context.drawArrays(context.TRIANGLES, 0, 3)", "undefined");
+shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 0, 3)");
+shouldGenerateGLError(context, context.INVALID_ENUM, "context.drawArrays(0x0009, 0, 3)"); // GL_POLYGON
+shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 3, 2)");
+shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawArrays(context.TRIANGLES, 0, 10000)");
+shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, 0, -1)");
+shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawArrays(context.TRIANGLES, -1, 0)");
+shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 0, 0)");
+shouldGenerateGLError(context, context.NO_ERROR, "context.drawArrays(context.TRIANGLES, 100, 0)");
+
+debug("")
+successfullyParsed = true;
+</script>
+
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
--- /dev/null
+Test of drawElements with out-of-bounds parameters
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Test empty index buffer
+PASS context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0) generated expected GL error: INVALID_OPERATION.
+PASS context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0) generated expected GL error: INVALID_OPERATION.
+PASS context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 0) generated expected GL error: INVALID_VALUE.
+PASS context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, 0) generated expected GL error: INVALID_OPERATION.
+PASS context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1) generated expected GL error: INVALID_VALUE.
+PASS context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, 0) generated expected GL error: NO_ERROR.
+
+Test buffer with 3 byte indexes
+PASS context.checkFramebufferStatus(context.FRAMEBUFFER) is context.FRAMEBUFFER_COMPLETE
+PASS context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0) is undefined
+PASS context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0) generated expected GL error: NO_ERROR.
+PASS context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_INT, 0) generated expected GL error: INVALID_ENUM.
+PASS context.drawElements(0x0009, 3, context.UNSIGNED_BYTE, 0) generated expected GL error: INVALID_ENUM.
+PASS context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 2) generated expected GL error: INVALID_OPERATION.
+PASS context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0) generated expected GL error: INVALID_OPERATION.
+PASS context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 0) generated expected GL error: INVALID_VALUE.
+PASS context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1) generated expected GL error: INVALID_VALUE.
+PASS context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 1) generated expected GL error: INVALID_VALUE.
+PASS context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, 4) generated expected GL error: NO_ERROR.
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
--- /dev/null
+<html>
+<head>
+<link rel="stylesheet" href="../../js/resources/js-test-style.css"/>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script src="resources/webgl-test.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+
+<script>
+description("Test of drawElements with out-of-bounds parameters");
+
+var context = create3DContext();
+var program = loadStandardProgram(context);
+
+context.useProgram(program);
+var vertexObject = context.createBuffer();
+context.enableVertexAttribArray(0);
+context.bindBuffer(context.ARRAY_BUFFER, vertexObject);
+context.bufferData(context.ARRAY_BUFFER, new WebGLFloatArray([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), context.STATIC_DRAW);
+context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
+
+var indexObject = context.createBuffer();
+
+debug("Test empty index buffer")
+context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject);
+context.bufferData(context.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedByteArray([ ]), context.STATIC_DRAW);
+shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)");
+shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0)");
+shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 0)");
+shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, 0)");
+shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1)");
+shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, 0)");
+
+debug("")
+debug("Test buffer with 3 byte indexes")
+context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject);
+context.bufferData(context.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedByteArray([ 0, 1, 2 ]), context.STATIC_DRAW);
+shouldBe("context.checkFramebufferStatus(context.FRAMEBUFFER)", "context.FRAMEBUFFER_COMPLETE");
+shouldBe("context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)", "undefined");
+shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)");
+shouldGenerateGLError(context, context.INVALID_ENUM, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_INT, 0)");
+shouldGenerateGLError(context, context.INVALID_ENUM, "context.drawElements(0x0009, 3, context.UNSIGNED_BYTE, 0)"); // GL_POLYGON
+shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 2)");
+shouldGenerateGLError(context, context.INVALID_OPERATION, "context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0)");
+shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 0)");
+shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1)");
+shouldGenerateGLError(context, context.INVALID_VALUE, "context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 1)");
+shouldGenerateGLError(context, context.NO_ERROR, "context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, 4)");
+
+debug("")
+successfullyParsed = true;
+</script>
+
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
+++ /dev/null
-Test of drawArrays with out-of-bounds parameters
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-Test empty buffer
-PASS context.drawArrays(context.TRIANGLES, 0, 1) threw exception GL error 1282 in drawArrays.
-PASS context.drawArrays(context.TRIANGLES, 0, 10000) threw exception GL error 1282 in drawArrays.
-PASS context.drawArrays(context.TRIANGLES, 0, 10000000000000) threw exception GL error 1282 in drawArrays.
-PASS context.drawArrays(context.TRIANGLES, 0, -1) threw exception GL error 1282 in drawArrays.
-PASS context.drawArrays(context.TRIANGLES, 1, 0) threw exception GL error 1282 in drawArrays.
-PASS context.drawArrays(context.TRIANGLES, -1, 0) threw exception GL error 1282 in drawArrays.
-PASS context.drawArrays(context.TRIANGLES, 1, -1) threw exception GL error 1282 in drawArrays.
-PASS context.drawArrays(context.TRIANGLES, -1, 1) threw exception GL error 1282 in drawArrays.
-
-Test buffer with 3 float vectors
-PASS context.checkFramebufferStatus(context.FRAMEBUFFER) is context.FRAMEBUFFER_COMPLETE
-PASS context.drawArrays(context.TRIANGLES, 0, 3) is undefined
-PASS context.drawArrays(context.TRIANGLES, 3, 2) threw exception GL error 1282 in drawArrays.
-PASS context.drawArrays(context.TRIANGLES, 0, 10000) threw exception GL error 1282 in drawArrays.
-PASS context.drawArrays(context.TRIANGLES, 0, 10000000000000) threw exception GL error 1282 in drawArrays.
-PASS context.drawArrays(context.TRIANGLES, 0, -1) threw exception GL error 1282 in drawArrays.
-PASS context.drawArrays(context.TRIANGLES, -1, 0) threw exception GL error 1282 in drawArrays.
-PASS context.drawArrays(context.TRIANGLES, 1, -1) threw exception GL error 1282 in drawArrays.
-PASS context.drawArrays(context.TRIANGLES, -1, 1) threw exception GL error 1282 in drawArrays.
-
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
+++ /dev/null
-<html>
-<head>
-<link rel="stylesheet" href="../../js/resources/js-test-style.css"/>
-<script src="../../js/resources/js-test-pre.js"></script>
-<script src="resources/webgl-test.js"></script>
-</head>
-<body>
-<div id="description"></div>
-<div id="console"></div>
-
-<script>
-description("Test of drawArrays with out-of-bounds parameters");
-
-var context = create3DDebugContext();
-var program = loadStandardProgram(context);
-
-context.useProgram(program);
-var vertexObject = context.createBuffer();
-context.bindBuffer(context.ARRAY_BUFFER, vertexObject);
-context.enableVertexAttribArray(0);
-
-debug("Test empty buffer")
-context.bufferData(context.ARRAY_BUFFER, new WebGLFloatArray([ ]), context.STATIC_DRAW);
-context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
-shouldThrow("context.drawArrays(context.TRIANGLES, 0, 1)");
-shouldThrow("context.drawArrays(context.TRIANGLES, 0, 10000)");
-shouldThrow("context.drawArrays(context.TRIANGLES, 0, 10000000000000)");
-shouldThrow("context.drawArrays(context.TRIANGLES, 0, -1)");
-shouldThrow("context.drawArrays(context.TRIANGLES, 1, 0)");
-shouldThrow("context.drawArrays(context.TRIANGLES, -1, 0)");
-shouldThrow("context.drawArrays(context.TRIANGLES, 1, -1)");
-shouldThrow("context.drawArrays(context.TRIANGLES, -1, 1)");
-
-debug("")
-debug("Test buffer with 3 float vectors")
-context.bufferData(context.ARRAY_BUFFER, new WebGLFloatArray([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), context.STATIC_DRAW);
-context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
-shouldBe("context.checkFramebufferStatus(context.FRAMEBUFFER)", "context.FRAMEBUFFER_COMPLETE");
-shouldBe("context.drawArrays(context.TRIANGLES, 0, 3)", "undefined");
-shouldThrow("context.drawArrays(context.TRIANGLES, 3, 2)");
-shouldThrow("context.drawArrays(context.TRIANGLES, 0, 10000)");
-shouldThrow("context.drawArrays(context.TRIANGLES, 0, 10000000000000)");
-shouldThrow("context.drawArrays(context.TRIANGLES, 0, -1)");
-shouldThrow("context.drawArrays(context.TRIANGLES, -1, 0)");
-shouldThrow("context.drawArrays(context.TRIANGLES, 1, -1)");
-shouldThrow("context.drawArrays(context.TRIANGLES, -1, 1)");
-
-debug("")
-successfullyParsed = true;
-</script>
-
-<script src="../../js/resources/js-test-post.js"></script>
-</body>
-</html>
+++ /dev/null
-Test of drawElements with out-of-bounds parameters
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-Test empty index buffer
-PASS context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0) threw exception GL error 1282 in drawElements.
-PASS context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0) threw exception GL error 1282 in drawElements.
-PASS context.drawElements(context.TRIANGLES, 10000000000000, context.UNSIGNED_BYTE, 0) threw exception GL error 1282 in drawElements.
-PASS context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, 0) threw exception GL error 1282 in drawElements.
-PASS context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1) threw exception GL error 1282 in drawElements.
-PASS context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 1) threw exception GL error 1282 in drawElements.
-PASS context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, -1) threw exception GL error 1282 in drawElements.
-
-Test buffer with 3 byte indexes
-PASS context.checkFramebufferStatus(context.FRAMEBUFFER) is context.FRAMEBUFFER_COMPLETE
-PASS context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0) is undefined
-PASS context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 2) threw exception GL error 1282 in drawElements.
-PASS context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0) threw exception GL error 1282 in drawElements.
-PASS context.drawElements(context.TRIANGLES, 10000000000000, context.UNSIGNED_BYTE, 0) threw exception GL error 1282 in drawElements.
-PASS context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1) threw exception GL error 1282 in drawElements.
-PASS context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 1) threw exception GL error 1282 in drawElements.
-PASS context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, -1) threw exception GL error 1282 in drawElements.
-
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
+++ /dev/null
-<html>
-<head>
-<link rel="stylesheet" href="../../js/resources/js-test-style.css"/>
-<script src="../../js/resources/js-test-pre.js"></script>
-<script src="resources/webgl-test.js"></script>
-</head>
-<body>
-<div id="description"></div>
-<div id="console"></div>
-
-<script>
-description("Test of drawElements with out-of-bounds parameters");
-
-var context = create3DDebugContext();
-var program = loadStandardProgram(context);
-
-context.useProgram(program);
-var vertexObject = context.createBuffer();
-context.enableVertexAttribArray(0);
-context.bindBuffer(context.ARRAY_BUFFER, vertexObject);
-context.bufferData(context.ARRAY_BUFFER, new WebGLFloatArray([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), context.STATIC_DRAW);
-context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
-
-var indexObject = context.createBuffer();
-
-debug("Test empty index buffer")
-context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject);
-context.bufferData(context.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedByteArray([ ]), context.STATIC_DRAW);
-shouldThrow("context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)");
-shouldThrow("context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0)");
-shouldThrow("context.drawElements(context.TRIANGLES, 10000000000000, context.UNSIGNED_BYTE, 0)");
-shouldThrow("context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, 0)");
-shouldThrow("context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1)");
-shouldThrow("context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 1)");
-shouldThrow("context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, -1)");
-
-debug("")
-debug("Test buffer with 3 byte indexes")
-context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexObject);
-context.bufferData(context.ELEMENT_ARRAY_BUFFER, new WebGLUnsignedByteArray([ 0, 1, 2 ]), context.STATIC_DRAW);
-shouldBe("context.checkFramebufferStatus(context.FRAMEBUFFER)", "context.FRAMEBUFFER_COMPLETE");
-shouldBe("context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 0)", "undefined");
-shouldThrow("context.drawElements(context.TRIANGLES, 3, context.UNSIGNED_BYTE, 2)");
-shouldThrow("context.drawElements(context.TRIANGLES, 10000, context.UNSIGNED_BYTE, 0)");
-shouldThrow("context.drawElements(context.TRIANGLES, 10000000000000, context.UNSIGNED_BYTE, 0)");
-shouldThrow("context.drawElements(context.TRIANGLES, 0, context.UNSIGNED_BYTE, -1)");
-shouldThrow("context.drawElements(context.TRIANGLES, -1, context.UNSIGNED_BYTE, 1)");
-shouldThrow("context.drawElements(context.TRIANGLES, 1, context.UNSIGNED_BYTE, -1)");
-
-debug("")
-successfullyParsed = true;
-</script>
-
-<script src="../../js/resources/js-test-post.js"></script>
-</body>
-</html>
context.compileShader(fragmentShader);
return fragmentShader;
}
+
+function getGLErrorAsString(ctx, err) {
+ if (err === ctx.NO_ERROR)
+ return "NO_ERROR";
+ for (var name in ctx) {
+ if (ctx[name] === err)
+ return name;
+ }
+ return err.toString();
+}
+
+function shouldGenerateGLError(ctx, glError, evalStr) {
+ var exception;
+ try {
+ eval(evalStr);
+ } catch (e) {
+ exception = e;
+ }
+ if (exception) {
+ testFailed(evalStr + " threw exception " + exception);
+ } else {
+ var err = ctx.getError();
+ if (err != glError)
+ testFailed(evalStr + " expected GL error: " + getGLErrorAsString(ctx, glError) + ". Generated: " + getGLErrorAsString(ctx, err) + ".");
+ else
+ testPassed(evalStr + " generated expected GL error: " + getGLErrorAsString(ctx, glError) + ".");
+ }
+}
+2010-06-11 Zhenyao Mo <zmo@google.com>
+
+ Reviewed by Dimitri Glazkov.
+
+ drawElements/drawArrays should validate input parameters according to GLES2 spec
+ https://bugs.webkit.org/show_bug.cgi?id=38700
+
+ Tests: fast/canvas/webgl/draw-arrays-out-of-bounds.html
+ fast/canvas/webgl/draw-elements-out-of-bounds.html
+
+ * html/canvas/WebGLRenderingContext.cpp:
+ (WebCore::WebGLRenderingContext::drawArrays): Validate input parameters.
+ (WebCore::WebGLRenderingContext::drawElements): Ditto.
+ (WebCore::WebGLRenderingContext::validateDrawMode): Validate mode for draw{Arrays/Elements}.
+ * html/canvas/WebGLRenderingContext.h: Add validateDrawMode, fix incorrect parameter types.
+ * html/canvas/WebGLRenderingContext.idl: Fix incorrect parameter types.
+
2010-06-11 Luiz Agostini <luiz.agostini@openbossa.org>
Reviewed by Antti Koivisto.
void WebGLRenderingContext::drawArrays(unsigned long mode, long first, long count, ExceptionCode& ec)
{
UNUSED_PARAM(ec);
+
+ if (!validateDrawMode(mode))
+ return;
+
+ if (first < 0 || count < 0) {
+ m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE);
+ return;
+ }
+
+ if (!count)
+ return;
+
// Ensure we have a valid rendering state
- if (first < 0 || count < 0 || !validateRenderingState(first + count)) {
+ if (!validateRenderingState(first + count)) {
m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION);
return;
}
cleanupAfterGraphicsCall(true);
}
-void WebGLRenderingContext::drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset, ExceptionCode& ec)
+void WebGLRenderingContext::drawElements(unsigned long mode, long count, unsigned long type, long offset, ExceptionCode& ec)
{
UNUSED_PARAM(ec);
+
+ if (!validateDrawMode(mode))
+ return;
+
+ switch (type) {
+ case GraphicsContext3D::UNSIGNED_BYTE:
+ case GraphicsContext3D::UNSIGNED_SHORT:
+ break;
+ default:
+ m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM);
+ return;
+ }
+
+ if (count < 0 || offset < 0) {
+ m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE);
+ return;
+ }
+
+ if (!count)
+ return;
+
// Ensure we have a valid rendering state
long numElements;
- if (offset < 0 || !validateElementArraySize(count, type, offset)) {
+ if (!validateElementArraySize(count, type, offset)) {
m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION);
return;
}
return validateTexFuncFormatAndType(format, type);
}
+bool WebGLRenderingContext::validateDrawMode(unsigned long mode)
+{
+ switch (mode) {
+ case GraphicsContext3D::POINTS:
+ case GraphicsContext3D::LINE_STRIP:
+ case GraphicsContext3D::LINE_LOOP:
+ case GraphicsContext3D::LINES:
+ case GraphicsContext3D::TRIANGLE_STRIP:
+ case GraphicsContext3D::TRIANGLE_FAN:
+ case GraphicsContext3D::TRIANGLES:
+ return true;
+ default:
+ m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM);
+ return false;
+ }
+}
+
} // namespace WebCore
#endif // ENABLE(3D_CANVAS)
void disable(unsigned long cap);
void disableVertexAttribArray(unsigned long index, ExceptionCode&);
void drawArrays(unsigned long mode, long first, long count, ExceptionCode&);
- void drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset, ExceptionCode&);
+ void drawElements(unsigned long mode, long count, unsigned long type, long offset, ExceptionCode&);
void enable(unsigned long cap);
void enableVertexAttribArray(unsigned long index, ExceptionCode&);
long width, long height, long border,
unsigned long format, unsigned long type);
+ // Helper function to validate mode for draw{Arrays/Elements}.
+ bool validateDrawMode(unsigned long);
+
// Helper function for texParameterf and texParameteri.
void texParameter(unsigned long target, unsigned long pname, float parami, int paramf, bool isFloat);
void detachShader(in WebGLProgram program, in WebGLShader shader) raises(DOMException);
void disable(in unsigned long cap);
void disableVertexAttribArray(in unsigned long index) raises(DOMException);
- void drawArrays(in unsigned long mode, in long first, in unsigned long count) raises(DOMException);
- void drawElements(in unsigned long mode, in long count, in unsigned long type, in unsigned long offset) raises(DOMException);
+ void drawArrays(in unsigned long mode, in long first, in long count) raises(DOMException);
+ void drawElements(in unsigned long mode, in long count, in unsigned long type, in long offset) raises(DOMException);
void enable(in unsigned long cap);
void enableVertexAttribArray(in unsigned long index) raises(DOMException);