Title: [264889] trunk/Source/WebCore
Revision
264889
Author
[email protected]
Date
2020-07-25 12:48:56 -0700 (Sat, 25 Jul 2020)

Log Message

[WebGL2] Context state updates
https://bugs.webkit.org/show_bug.cgi?id=209513

Patch by Kenneth Russell <[email protected]> on 2020-07-25
Reviewed by Dean Jackson.

Refactor a few methods related to context state to reduce
duplicated code between WebGL 1.0 and 2.0. No behavioral changes.

Covered by existing WebGL conformance tests.

* html/canvas/WebGL2RenderingContext.cpp:
(WebCore::WebGL2RenderingContext::validateCapability):
(WebCore::WebGL2RenderingContext::clear): Deleted.
(WebCore::WebGL2RenderingContext::hint): Deleted.
* html/canvas/WebGL2RenderingContext.h:
* html/canvas/WebGLRenderingContext.cpp:
(WebCore::WebGLRenderingContext::hint): Deleted.
(WebCore::WebGLRenderingContext::clear): Deleted.
(WebCore::WebGLRenderingContext::validateCapability): Deleted.
* html/canvas/WebGLRenderingContext.h:
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::clear):
(WebCore::WebGLRenderingContextBase::hint):
(WebCore::WebGLRenderingContextBase::validateCapability):
* html/canvas/WebGLRenderingContextBase.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (264888 => 264889)


--- trunk/Source/WebCore/ChangeLog	2020-07-25 05:58:39 UTC (rev 264888)
+++ trunk/Source/WebCore/ChangeLog	2020-07-25 19:48:56 UTC (rev 264889)
@@ -1,3 +1,31 @@
+2020-07-25  Kenneth Russell  <[email protected]>
+
+        [WebGL2] Context state updates
+        https://bugs.webkit.org/show_bug.cgi?id=209513
+
+        Reviewed by Dean Jackson.
+
+        Refactor a few methods related to context state to reduce
+        duplicated code between WebGL 1.0 and 2.0. No behavioral changes.
+
+        Covered by existing WebGL conformance tests.
+
+        * html/canvas/WebGL2RenderingContext.cpp:
+        (WebCore::WebGL2RenderingContext::validateCapability):
+        (WebCore::WebGL2RenderingContext::clear): Deleted.
+        (WebCore::WebGL2RenderingContext::hint): Deleted.
+        * html/canvas/WebGL2RenderingContext.h:
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore::WebGLRenderingContext::hint): Deleted.
+        (WebCore::WebGLRenderingContext::clear): Deleted.
+        (WebCore::WebGLRenderingContext::validateCapability): Deleted.
+        * html/canvas/WebGLRenderingContext.h:
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::clear):
+        (WebCore::WebGLRenderingContextBase::hint):
+        (WebCore::WebGLRenderingContextBase::validateCapability):
+        * html/canvas/WebGLRenderingContextBase.h:
+
 2020-07-24  Brady Eidson  <[email protected]>
 
         Throw another one on the pile take 2.

Modified: trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.cpp (264888 => 264889)


--- trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.cpp	2020-07-25 05:58:39 UTC (rev 264888)
+++ trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.cpp	2020-07-25 19:48:56 UTC (rev 264889)
@@ -1715,30 +1715,6 @@
     m_context->vertexAttribIPointer(index, size, type, stride, offset);
 }
 
-void WebGL2RenderingContext::clear(GCGLbitfield mask)
-{
-    if (isContextLostOrPending())
-        return;
-#if !USE(ANGLE)
-    if (mask & ~(GraphicsContextGL::COLOR_BUFFER_BIT | GraphicsContextGL::DEPTH_BUFFER_BIT | GraphicsContextGL::STENCIL_BUFFER_BIT)) {
-        synthesizeGLError(GraphicsContextGL::INVALID_VALUE, "clear", "invalid mask");
-        return;
-    }
-    const char* reason = "framebuffer incomplete";
-    if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContextGL(), &reason)) {
-        synthesizeGLError(GraphicsContextGL::INVALID_FRAMEBUFFER_OPERATION, "clear", reason);
-        return;
-    }
-    if (m_framebufferBinding && (mask & GraphicsContextGL::COLOR_BUFFER_BIT) && m_framebufferBinding->getColorBufferFormat() && isIntegerFormat(m_framebufferBinding->getColorBufferFormat())) {
-        synthesizeGLError(GraphicsContextGL::INVALID_OPERATION, "clear", "cannot clear an integer buffer");
-        return;
-    }
-#endif
-    if (!clearIfComposited(mask))
-        m_context->clear(mask);
-    markContextChangedAndNotifyCanvasObserver();
-}
-
 void WebGL2RenderingContext::vertexAttribDivisor(GCGLuint index, GCGLuint divisor)
 {
     if (isContextLostOrPending())
@@ -2965,24 +2941,6 @@
         m_context->renderbufferStorage(target, internalformat, width, height);
 }
 
-void WebGL2RenderingContext::hint(GCGLenum target, GCGLenum mode)
-{
-    if (isContextLostOrPending())
-        return;
-    bool isValid = false;
-    switch (target) {
-    case GraphicsContextGL::GENERATE_MIPMAP_HINT:
-    case GraphicsContextGL::FRAGMENT_SHADER_DERIVATIVE_HINT:
-        isValid = true;
-        break;
-    }
-    if (!isValid) {
-        synthesizeGLError(GraphicsContextGL::INVALID_ENUM, "hint", "invalid target");
-        return;
-    }
-    m_context->hint(target, mode);
-}
-
 GCGLuint WebGL2RenderingContext::maxTransformFeedbackSeparateAttribs() const
 {
     return m_maxTransformFeedbackSeparateAttribs;
@@ -3347,20 +3305,10 @@
 bool WebGL2RenderingContext::validateCapability(const char* functionName, GCGLenum cap)
 {
     switch (cap) {
-    case GraphicsContextGL::BLEND:
-    case GraphicsContextGL::CULL_FACE:
-    case GraphicsContextGL::DEPTH_TEST:
-    case GraphicsContextGL::DITHER:
-    case GraphicsContextGL::POLYGON_OFFSET_FILL:
-    case GraphicsContextGL::SAMPLE_ALPHA_TO_COVERAGE:
-    case GraphicsContextGL::SAMPLE_COVERAGE:
-    case GraphicsContextGL::SCISSOR_TEST:
-    case GraphicsContextGL::STENCIL_TEST:
     case GraphicsContextGL::RASTERIZER_DISCARD:
         return true;
     default:
-        synthesizeGLError(GraphicsContextGL::INVALID_ENUM, functionName, "invalid capability");
-        return false;
+        return WebGLRenderingContextBase::validateCapability(functionName, cap);
     }
 }
 

Modified: trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.h (264888 => 264889)


--- trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.h	2020-07-25 05:58:39 UTC (rev 264888)
+++ trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.h	2020-07-25 19:48:56 UTC (rev 264889)
@@ -178,7 +178,6 @@
     void uniformMatrix4fv(WebGLUniformLocation* location, GLboolean transpose, Float32List data, GLuint srcOffset, GLuint srcLength);
 
     // Writing to the drawing buffer
-    void clear(GCGLbitfield mask) final;
     void vertexAttribDivisor(GCGLuint index, GCGLuint divisor);
     void drawArraysInstanced(GCGLenum mode, GCGLint first, GCGLsizei count, GCGLsizei instanceCount);
     void drawElementsInstanced(GCGLenum mode, GCGLsizei count, GCGLenum type, GCGLint64 offset, GCGLsizei instanceCount);
@@ -255,7 +254,6 @@
     void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLintptr offset);
     void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, ArrayBufferView& dstData, GLuint dstOffset);
 
-    void hint(GCGLenum target, GCGLenum mode) final;
     GCGLuint maxTransformFeedbackSeparateAttribs() const;
 
     GraphicsContextGLOpenGL::PixelStoreParams getPackPixelStoreParams() const override;

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp (264888 => 264889)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp	2020-07-25 05:58:39 UTC (rev 264888)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp	2020-07-25 19:48:56 UTC (rev 264889)
@@ -323,47 +323,6 @@
     }
 }
 
-void WebGLRenderingContext::hint(GCGLenum target, GCGLenum mode)
-{
-    if (isContextLostOrPending())
-        return;
-    bool isValid = false;
-    switch (target) {
-    case GraphicsContextGL::GENERATE_MIPMAP_HINT:
-        isValid = true;
-        break;
-    case ExtensionsGL::FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives
-        if (m_oesStandardDerivatives)
-            isValid = true;
-        break;
-    }
-    if (!isValid) {
-        synthesizeGLError(GraphicsContextGL::INVALID_ENUM, "hint", "invalid target");
-        return;
-    }
-    m_context->hint(target, mode);
-}
-
-void WebGLRenderingContext::clear(GCGLbitfield mask)
-{
-    if (isContextLostOrPending())
-        return;
-#if !USE(ANGLE)
-    if (mask & ~(GraphicsContextGL::COLOR_BUFFER_BIT | GraphicsContextGL::DEPTH_BUFFER_BIT | GraphicsContextGL::STENCIL_BUFFER_BIT)) {
-        synthesizeGLError(GraphicsContextGL::INVALID_VALUE, "clear", "invalid mask");
-        return;
-    }
-    const char* reason = "framebuffer incomplete";
-    if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) {
-        synthesizeGLError(GraphicsContextGL::INVALID_FRAMEBUFFER_OPERATION, "clear", reason);
-        return;
-    }
-#endif
-    if (!clearIfComposited(mask))
-        m_context->clear(mask);
-    markContextChangedAndNotifyCanvasObserver();
-}
-
 GCGLint WebGLRenderingContext::getMaxDrawBuffers()
 {
     if (!supportsDrawBuffers())
@@ -470,25 +429,6 @@
     }
 }
 
-bool WebGLRenderingContext::validateCapability(const char* functionName, GCGLenum cap)
-{
-    switch (cap) {
-    case GraphicsContextGL::BLEND:
-    case GraphicsContextGL::CULL_FACE:
-    case GraphicsContextGL::DEPTH_TEST:
-    case GraphicsContextGL::DITHER:
-    case GraphicsContextGL::POLYGON_OFFSET_FILL:
-    case GraphicsContextGL::SAMPLE_ALPHA_TO_COVERAGE:
-    case GraphicsContextGL::SAMPLE_COVERAGE:
-    case GraphicsContextGL::SCISSOR_TEST:
-    case GraphicsContextGL::STENCIL_TEST:
-        return true;
-    default:
-        synthesizeGLError(GraphicsContextGL::INVALID_ENUM, functionName, "invalid capability");
-        return false;
-    }
-}
-
 } // namespace WebCore
 
 #endif // ENABLE(WEBGL)

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h (264888 => 264889)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h	2020-07-25 05:58:39 UTC (rev 264888)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h	2020-07-25 19:48:56 UTC (rev 264889)
@@ -44,8 +44,6 @@
     Optional<Vector<String>> getSupportedExtensions() final;
 
     WebGLAny getFramebufferAttachmentParameter(GCGLenum target, GCGLenum attachment, GCGLenum pname) final;
-    void hint(GCGLenum target, GCGLenum mode) final;
-    void clear(GCGLbitfield mask) final;
 
     GCGLint getMaxDrawBuffers() final;
     GCGLint getMaxColorAttachments() final;
@@ -52,7 +50,6 @@
     void initializeVertexArrayObjects() final;
     bool validateIndexArrayConservative(GCGLenum type, unsigned& numElementsRequired) final;
     bool validateBlendEquation(const char* functionName, GCGLenum mode) final;
-    bool validateCapability(const char* functionName, GCGLenum cap) final;
 
 private:
     WebGLRenderingContext(CanvasBase&, GraphicsContextGLAttributes);

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (264888 => 264889)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2020-07-25 05:58:39 UTC (rev 264888)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2020-07-25 19:48:56 UTC (rev 264889)
@@ -1653,6 +1653,26 @@
 #endif
 }
 
+void WebGLRenderingContextBase::clear(GCGLbitfield mask)
+{
+    if (isContextLostOrPending())
+        return;
+#if !USE(ANGLE)
+    if (mask & ~(GraphicsContextGL::COLOR_BUFFER_BIT | GraphicsContextGL::DEPTH_BUFFER_BIT | GraphicsContextGL::STENCIL_BUFFER_BIT)) {
+        synthesizeGLError(GraphicsContextGL::INVALID_VALUE, "clear", "invalid mask");
+        return;
+    }
+    const char* reason = "framebuffer incomplete";
+    if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) {
+        synthesizeGLError(GraphicsContextGL::INVALID_FRAMEBUFFER_OPERATION, "clear", reason);
+        return;
+    }
+#endif
+    if (!clearIfComposited(mask))
+        m_context->clear(mask);
+    markContextChangedAndNotifyCanvasObserver();
+}
+
 void WebGLRenderingContextBase::clearColor(GCGLfloat r, GCGLfloat g, GCGLfloat b, GCGLfloat a)
 {
     if (isContextLostOrPending())
@@ -3691,6 +3711,27 @@
     m_context->enablePreserveDrawingBuffer();
 }
 
+void WebGLRenderingContextBase::hint(GCGLenum target, GCGLenum mode)
+{
+    if (isContextLostOrPending())
+        return;
+    bool isValid = false;
+    switch (target) {
+    case GraphicsContextGL::GENERATE_MIPMAP_HINT:
+        isValid = true;
+        break;
+    case ExtensionsGL::FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives, or core in WebGL 2.0
+        if (m_oesStandardDerivatives || isWebGL2())
+            isValid = true;
+        break;
+    }
+    if (!isValid) {
+        synthesizeGLError(GraphicsContextGL::INVALID_ENUM, "hint", "invalid target");
+        return;
+    }
+    m_context->hint(target, mode);
+}
+
 GCGLboolean WebGLRenderingContextBase::isBuffer(WebGLBuffer* buffer)
 {
     if (!buffer || isContextLostOrPending())
@@ -6908,6 +6949,25 @@
     return true;
 }
 
+bool WebGLRenderingContextBase::validateCapability(const char* functionName, GCGLenum cap)
+{
+    switch (cap) {
+    case GraphicsContextGL::BLEND:
+    case GraphicsContextGL::CULL_FACE:
+    case GraphicsContextGL::DEPTH_TEST:
+    case GraphicsContextGL::DITHER:
+    case GraphicsContextGL::POLYGON_OFFSET_FILL:
+    case GraphicsContextGL::SAMPLE_ALPHA_TO_COVERAGE:
+    case GraphicsContextGL::SAMPLE_COVERAGE:
+    case GraphicsContextGL::SCISSOR_TEST:
+    case GraphicsContextGL::STENCIL_TEST:
+        return true;
+    default:
+        synthesizeGLError(GraphicsContextGL::INVALID_ENUM, functionName, "invalid capability");
+        return false;
+    }
+}
+
 bool WebGLRenderingContextBase::validateUniformParameters(const char* functionName, const WebGLUniformLocation* location, const Float32List& v, GCGLsizei requiredMinSize, GCGLuint srcOffset, GCGLuint srcLength)
 {
     return validateUniformMatrixParameters(functionName, location, false, v.data(), v.length(), requiredMinSize, srcOffset, srcLength);

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h (264888 => 264889)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h	2020-07-25 05:58:39 UTC (rev 264888)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h	2020-07-25 19:48:56 UTC (rev 264889)
@@ -141,7 +141,7 @@
     void bufferSubData(GCGLenum target, long long offset, Optional<BufferDataSource>&&);
 
     GCGLenum checkFramebufferStatus(GCGLenum target);
-    virtual void clear(GCGLbitfield mask) = 0;
+    void clear(GCGLbitfield mask);
     void clearColor(GCGLfloat red, GCGLfloat green, GCGLfloat blue, GCGLfloat alpha);
     void clearDepth(GCGLfloat);
     void clearStencil(GCGLint);
@@ -223,7 +223,7 @@
     bool preventBufferClearForInspector() const { return m_preventBufferClearForInspector; }
     void setPreventBufferClearForInspector(bool value) { m_preventBufferClearForInspector = value; }
 
-    virtual void hint(GCGLenum target, GCGLenum mode) = 0;
+    void hint(GCGLenum target, GCGLenum mode);
     GCGLboolean isBuffer(WebGLBuffer*);
     bool isContextLost() const;
     GCGLboolean isEnabled(GCGLenum cap);
@@ -963,7 +963,7 @@
     bool validateBlendFuncFactors(const char* functionName, GCGLenum src, GCGLenum dst);
 
     // Helper function to validate a GL capability.
-    virtual bool validateCapability(const char* functionName, GCGLenum) = 0;
+    virtual bool validateCapability(const char* functionName, GCGLenum);
 
     // Helper function to validate input parameters for uniform functions.
     bool validateUniformLocation(const char* functionName, const WebGLUniformLocation*);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to