2011-01-26 Zhenyao Mo <zmo@google.com>
authorzmo@google.com <zmo@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Jan 2011 18:58:53 +0000 (18:58 +0000)
committerzmo@google.com <zmo@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Jan 2011 18:58:53 +0000 (18:58 +0000)
        Reviewed by Kenneth Russell.

        shaderSource needs to preserve original source
        https://bugs.webkit.org/show_bug.cgi?id=52833

        * fast/canvas/webgl/gl-getshadersource-expected.txt: Added.
        * fast/canvas/webgl/gl-getshadersource.html: Added.
2011-01-26  Zhenyao Mo  <zmo@google.com>

        Reviewed by Kenneth Russell.

        shaderSource needs to preserve original source
        https://bugs.webkit.org/show_bug.cgi?id=52833

        Test: fast/canvas/webgl/gl-getshadersource.html

        * html/canvas/WebGLRenderingContext.cpp:
        (WebCore::WebGLRenderingContext::getShaderParameter): Intercept SHADER_SOURCE_LENGTH.
        (WebCore::WebGLRenderingContext::getShaderSource): Intercept the call.
        (WebCore::WebGLRenderingContext::shaderSource): Cache the source.
        * html/canvas/WebGLShader.cpp: Cache shader source.
        (WebCore::WebGLShader::WebGLShader):
        * html/canvas/WebGLShader.h: Ditto.
        (WebCore::WebGLShader::getSource):
        (WebCore::WebGLShader::setSource):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@76814 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/canvas/webgl/gl-getshadersource-expected.txt [new file with mode: 0644]
LayoutTests/fast/canvas/webgl/gl-getshadersource.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/canvas/WebGLRenderingContext.cpp
Source/WebCore/html/canvas/WebGLShader.cpp
Source/WebCore/html/canvas/WebGLShader.h

index 47bf5a6..302d43d 100644 (file)
@@ -1,3 +1,13 @@
+2011-01-26  Zhenyao Mo  <zmo@google.com>
+
+        Reviewed by Kenneth Russell.
+
+        shaderSource needs to preserve original source
+        https://bugs.webkit.org/show_bug.cgi?id=52833
+
+        * fast/canvas/webgl/gl-getshadersource-expected.txt: Added.
+        * fast/canvas/webgl/gl-getshadersource.html: Added.
+
 2011-01-27  Philippe Normand  <pnormand@igalia.com>
 
         Unreviewed, skip flaky test, needs further investigation on the failure.
diff --git a/LayoutTests/fast/canvas/webgl/gl-getshadersource-expected.txt b/LayoutTests/fast/canvas/webgl/gl-getshadersource-expected.txt
new file mode 100644 (file)
index 0000000..8d1f57b
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that the source that goes into a shader is what comes out.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS sourceLength is 0
+PASS source is original
+PASS sourceLength is 17
+PASS getError was expected value: NO_ERROR : Should be no errors.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/canvas/webgl/gl-getshadersource.html b/LayoutTests/fast/canvas/webgl/gl-getshadersource.html
new file mode 100644 (file)
index 0000000..53739f2
--- /dev/null
@@ -0,0 +1,44 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+  "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'/>
+   <title>WebGL getShaderSource conformance test.</title>
+<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>
+<script src="resources/webgl-test-utils.js"> </script>
+</head>
+<body>
+<canvas id="example" width="4" height="4" style="width: 40px; height: 30px;"></canvas>
+<div id="description"></div>
+<div id="console"></div>
+<script id="vshader" type="x-shader/x-vertex">abc//defNOTASCII</script>
+<script>
+description("Tests that the source that goes into a shader is what comes out.");
+var wtu = WebGLTestUtils;
+var canvas = document.getElementById("example");
+var gl = wtu.create3DContext(canvas);
+var original = document.getElementById("vshader").text;
+var shader = gl.createShader(gl.VERTEX_SHADER);
+var sourceLength = gl.getShaderParameter(shader, gl.SHADER_SOURCE_LENGTH);
+shouldBe("sourceLength", "0");
+gl.shaderSource(shader, original);
+var source = gl.getShaderSource(shader);
+shouldBe("source", "original");
+sourceLength = gl.getShaderParameter(shader, gl.SHADER_SOURCE_LENGTH);
+shouldBe("sourceLength", "17");
+successfullyParsed = true;
+glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
+</script>
+</body>
+</body>
+<script src="../../js/resources/js-test-post.js"></script>
+
+<script>
+</script>
+
+</body>
+</html>
+
+
index 2f0a2ac..98a6932 100644 (file)
@@ -1,3 +1,22 @@
+2011-01-26  Zhenyao Mo  <zmo@google.com>
+
+        Reviewed by Kenneth Russell.
+
+        shaderSource needs to preserve original source
+        https://bugs.webkit.org/show_bug.cgi?id=52833
+
+        Test: fast/canvas/webgl/gl-getshadersource.html
+
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore::WebGLRenderingContext::getShaderParameter): Intercept SHADER_SOURCE_LENGTH.
+        (WebCore::WebGLRenderingContext::getShaderSource): Intercept the call.
+        (WebCore::WebGLRenderingContext::shaderSource): Cache the source.
+        * html/canvas/WebGLShader.cpp: Cache shader source.
+        (WebCore::WebGLShader::WebGLShader):
+        * html/canvas/WebGLShader.h: Ditto.
+        (WebCore::WebGLShader::getSource):
+        (WebCore::WebGLShader::setSource):
+
 2011-01-27  Patrick Gansterer  <paroga@webkit.org>
 
         Unreviewed WinCE build fix for r76743.
index ad8cb19..f4004f2 100644 (file)
@@ -2164,9 +2164,13 @@ WebGLGetInfo WebGLRenderingContext::getShaderParameter(WebGLShader* shader, GC3D
         m_context->getShaderiv(objectOrZero(shader), pname, &value);
         return WebGLGetInfo(static_cast<unsigned int>(value));
     case GraphicsContext3D::INFO_LOG_LENGTH:
-    case GraphicsContext3D::SHADER_SOURCE_LENGTH:
         m_context->getShaderiv(objectOrZero(shader), pname, &value);
         return WebGLGetInfo(value);
+    case GraphicsContext3D::SHADER_SOURCE_LENGTH:
+        value = static_cast<GC3Dint>(shader->getSource().length());
+        if (value > 0)
+            value++; // Includes the null termination character.
+        return WebGLGetInfo(value);
     default:
         m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM);
         return WebGLGetInfo();
@@ -2191,8 +2195,7 @@ String WebGLRenderingContext::getShaderSource(WebGLShader* shader, ExceptionCode
         return String();
     if (!validateWebGLObject(shader))
         return "";
-    WebGLStateRestorer(this, false);
-    return m_context->getShaderSource(objectOrZero(shader));
+    return shader->getSource();
 }
 
 Vector<String> WebGLRenderingContext::getSupportedExtensions()
@@ -2772,6 +2775,7 @@ void WebGLRenderingContext::shaderSource(WebGLShader* shader, const String& stri
     String stringWithoutComments = StripComments(string).result();
     if (!validateString(stringWithoutComments))
         return;
+    shader->setSource(string);
     m_context->shaderSource(objectOrZero(shader), stringWithoutComments);
     cleanupAfterGraphicsCall(false);
 }
index edd5a53..59695e4 100644 (file)
@@ -41,6 +41,7 @@ PassRefPtr<WebGLShader> WebGLShader::create(WebGLRenderingContext* ctx, GC3Denum
 WebGLShader::WebGLShader(WebGLRenderingContext* ctx, GC3Denum type)
     : WebGLObject(ctx)
     , m_type(type)
+    , m_source("")
 {
     setObject(context()->graphicsContext3D()->createShader(type));
 }
index 5deaf20..1d7a10c 100644 (file)
@@ -40,6 +40,9 @@ public:
     static PassRefPtr<WebGLShader> create(WebGLRenderingContext*, GC3Denum);
 
     GC3Denum getType() const { return m_type; }
+    const String& getSource() const { return m_source; }
+
+    void setSource(const String& source) { m_source = source; }
 
 private:
     WebGLShader(WebGLRenderingContext*, GC3Denum);
@@ -49,6 +52,7 @@ private:
     virtual bool isShader() const { return true; }
 
     GC3Denum m_type;
+    String m_source;
 };
 
 } // namespace WebCore