Changeset 264889 in webkit


Ignore:
Timestamp:
Jul 25, 2020 12:48:56 PM (4 years ago)
Author:
commit-queue@webkit.org
Message:

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

Patch by Kenneth Russell <kbr@chromium.org> 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:
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r264887 r264889  
     12020-07-25  Kenneth Russell  <kbr@chromium.org>
     2
     3        [WebGL2] Context state updates
     4        https://bugs.webkit.org/show_bug.cgi?id=209513
     5
     6        Reviewed by Dean Jackson.
     7
     8        Refactor a few methods related to context state to reduce
     9        duplicated code between WebGL 1.0 and 2.0. No behavioral changes.
     10
     11        Covered by existing WebGL conformance tests.
     12
     13        * html/canvas/WebGL2RenderingContext.cpp:
     14        (WebCore::WebGL2RenderingContext::validateCapability):
     15        (WebCore::WebGL2RenderingContext::clear): Deleted.
     16        (WebCore::WebGL2RenderingContext::hint): Deleted.
     17        * html/canvas/WebGL2RenderingContext.h:
     18        * html/canvas/WebGLRenderingContext.cpp:
     19        (WebCore::WebGLRenderingContext::hint): Deleted.
     20        (WebCore::WebGLRenderingContext::clear): Deleted.
     21        (WebCore::WebGLRenderingContext::validateCapability): Deleted.
     22        * html/canvas/WebGLRenderingContext.h:
     23        * html/canvas/WebGLRenderingContextBase.cpp:
     24        (WebCore::WebGLRenderingContextBase::clear):
     25        (WebCore::WebGLRenderingContextBase::hint):
     26        (WebCore::WebGLRenderingContextBase::validateCapability):
     27        * html/canvas/WebGLRenderingContextBase.h:
     28
    1292020-07-24  Brady Eidson  <beidson@apple.com>
    230
  • trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.cpp

    r264845 r264889  
    17161716}
    17171717
    1718 void WebGL2RenderingContext::clear(GCGLbitfield mask)
    1719 {
    1720     if (isContextLostOrPending())
    1721         return;
    1722 #if !USE(ANGLE)
    1723     if (mask & ~(GraphicsContextGL::COLOR_BUFFER_BIT | GraphicsContextGL::DEPTH_BUFFER_BIT | GraphicsContextGL::STENCIL_BUFFER_BIT)) {
    1724         synthesizeGLError(GraphicsContextGL::INVALID_VALUE, "clear", "invalid mask");
    1725         return;
    1726     }
    1727     const char* reason = "framebuffer incomplete";
    1728     if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContextGL(), &reason)) {
    1729         synthesizeGLError(GraphicsContextGL::INVALID_FRAMEBUFFER_OPERATION, "clear", reason);
    1730         return;
    1731     }
    1732     if (m_framebufferBinding && (mask & GraphicsContextGL::COLOR_BUFFER_BIT) && m_framebufferBinding->getColorBufferFormat() && isIntegerFormat(m_framebufferBinding->getColorBufferFormat())) {
    1733         synthesizeGLError(GraphicsContextGL::INVALID_OPERATION, "clear", "cannot clear an integer buffer");
    1734         return;
    1735     }
    1736 #endif
    1737     if (!clearIfComposited(mask))
    1738         m_context->clear(mask);
    1739     markContextChangedAndNotifyCanvasObserver();
    1740 }
    1741 
    17421718void WebGL2RenderingContext::vertexAttribDivisor(GCGLuint index, GCGLuint divisor)
    17431719{
     
    29642940    else
    29652941        m_context->renderbufferStorage(target, internalformat, width, height);
    2966 }
    2967 
    2968 void WebGL2RenderingContext::hint(GCGLenum target, GCGLenum mode)
    2969 {
    2970     if (isContextLostOrPending())
    2971         return;
    2972     bool isValid = false;
    2973     switch (target) {
    2974     case GraphicsContextGL::GENERATE_MIPMAP_HINT:
    2975     case GraphicsContextGL::FRAGMENT_SHADER_DERIVATIVE_HINT:
    2976         isValid = true;
    2977         break;
    2978     }
    2979     if (!isValid) {
    2980         synthesizeGLError(GraphicsContextGL::INVALID_ENUM, "hint", "invalid target");
    2981         return;
    2982     }
    2983     m_context->hint(target, mode);
    29842942}
    29852943
     
    33483306{
    33493307    switch (cap) {
    3350     case GraphicsContextGL::BLEND:
    3351     case GraphicsContextGL::CULL_FACE:
    3352     case GraphicsContextGL::DEPTH_TEST:
    3353     case GraphicsContextGL::DITHER:
    3354     case GraphicsContextGL::POLYGON_OFFSET_FILL:
    3355     case GraphicsContextGL::SAMPLE_ALPHA_TO_COVERAGE:
    3356     case GraphicsContextGL::SAMPLE_COVERAGE:
    3357     case GraphicsContextGL::SCISSOR_TEST:
    3358     case GraphicsContextGL::STENCIL_TEST:
    33593308    case GraphicsContextGL::RASTERIZER_DISCARD:
    33603309        return true;
    33613310    default:
    3362         synthesizeGLError(GraphicsContextGL::INVALID_ENUM, functionName, "invalid capability");
    3363         return false;
     3311        return WebGLRenderingContextBase::validateCapability(functionName, cap);
    33643312    }
    33653313}
  • trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.h

    r264845 r264889  
    179179
    180180    // Writing to the drawing buffer
    181     void clear(GCGLbitfield mask) final;
    182181    void vertexAttribDivisor(GCGLuint index, GCGLuint divisor);
    183182    void drawArraysInstanced(GCGLenum mode, GCGLint first, GCGLsizei count, GCGLsizei instanceCount);
     
    256255    void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, ArrayBufferView& dstData, GLuint dstOffset);
    257256
    258     void hint(GCGLenum target, GCGLenum mode) final;
    259257    GCGLuint maxTransformFeedbackSeparateAttribs() const;
    260258
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp

    r264845 r264889  
    324324}
    325325
    326 void WebGLRenderingContext::hint(GCGLenum target, GCGLenum mode)
    327 {
    328     if (isContextLostOrPending())
    329         return;
    330     bool isValid = false;
    331     switch (target) {
    332     case GraphicsContextGL::GENERATE_MIPMAP_HINT:
    333         isValid = true;
    334         break;
    335     case ExtensionsGL::FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives
    336         if (m_oesStandardDerivatives)
    337             isValid = true;
    338         break;
    339     }
    340     if (!isValid) {
    341         synthesizeGLError(GraphicsContextGL::INVALID_ENUM, "hint", "invalid target");
    342         return;
    343     }
    344     m_context->hint(target, mode);
    345 }
    346 
    347 void WebGLRenderingContext::clear(GCGLbitfield mask)
    348 {
    349     if (isContextLostOrPending())
    350         return;
    351 #if !USE(ANGLE)
    352     if (mask & ~(GraphicsContextGL::COLOR_BUFFER_BIT | GraphicsContextGL::DEPTH_BUFFER_BIT | GraphicsContextGL::STENCIL_BUFFER_BIT)) {
    353         synthesizeGLError(GraphicsContextGL::INVALID_VALUE, "clear", "invalid mask");
    354         return;
    355     }
    356     const char* reason = "framebuffer incomplete";
    357     if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) {
    358         synthesizeGLError(GraphicsContextGL::INVALID_FRAMEBUFFER_OPERATION, "clear", reason);
    359         return;
    360     }
    361 #endif
    362     if (!clearIfComposited(mask))
    363         m_context->clear(mask);
    364     markContextChangedAndNotifyCanvasObserver();
    365 }
    366 
    367326GCGLint WebGLRenderingContext::getMaxDrawBuffers()
    368327{
     
    471430}
    472431
    473 bool WebGLRenderingContext::validateCapability(const char* functionName, GCGLenum cap)
    474 {
    475     switch (cap) {
    476     case GraphicsContextGL::BLEND:
    477     case GraphicsContextGL::CULL_FACE:
    478     case GraphicsContextGL::DEPTH_TEST:
    479     case GraphicsContextGL::DITHER:
    480     case GraphicsContextGL::POLYGON_OFFSET_FILL:
    481     case GraphicsContextGL::SAMPLE_ALPHA_TO_COVERAGE:
    482     case GraphicsContextGL::SAMPLE_COVERAGE:
    483     case GraphicsContextGL::SCISSOR_TEST:
    484     case GraphicsContextGL::STENCIL_TEST:
    485         return true;
    486     default:
    487         synthesizeGLError(GraphicsContextGL::INVALID_ENUM, functionName, "invalid capability");
    488         return false;
    489     }
    490 }
    491 
    492432} // namespace WebCore
    493433
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h

    r264845 r264889  
    4545
    4646    WebGLAny getFramebufferAttachmentParameter(GCGLenum target, GCGLenum attachment, GCGLenum pname) final;
    47     void hint(GCGLenum target, GCGLenum mode) final;
    48     void clear(GCGLbitfield mask) final;
    4947
    5048    GCGLint getMaxDrawBuffers() final;
     
    5351    bool validateIndexArrayConservative(GCGLenum type, unsigned& numElementsRequired) final;
    5452    bool validateBlendEquation(const char* functionName, GCGLenum mode) final;
    55     bool validateCapability(const char* functionName, GCGLenum cap) final;
    5653
    5754private:
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp

    r264845 r264889  
    16521652    return result;
    16531653#endif
     1654}
     1655
     1656void WebGLRenderingContextBase::clear(GCGLbitfield mask)
     1657{
     1658    if (isContextLostOrPending())
     1659        return;
     1660#if !USE(ANGLE)
     1661    if (mask & ~(GraphicsContextGL::COLOR_BUFFER_BIT | GraphicsContextGL::DEPTH_BUFFER_BIT | GraphicsContextGL::STENCIL_BUFFER_BIT)) {
     1662        synthesizeGLError(GraphicsContextGL::INVALID_VALUE, "clear", "invalid mask");
     1663        return;
     1664    }
     1665    const char* reason = "framebuffer incomplete";
     1666    if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) {
     1667        synthesizeGLError(GraphicsContextGL::INVALID_FRAMEBUFFER_OPERATION, "clear", reason);
     1668        return;
     1669    }
     1670#endif
     1671    if (!clearIfComposited(mask))
     1672        m_context->clear(mask);
     1673    markContextChangedAndNotifyCanvasObserver();
    16541674}
    16551675
     
    36923712}
    36933713
     3714void WebGLRenderingContextBase::hint(GCGLenum target, GCGLenum mode)
     3715{
     3716    if (isContextLostOrPending())
     3717        return;
     3718    bool isValid = false;
     3719    switch (target) {
     3720    case GraphicsContextGL::GENERATE_MIPMAP_HINT:
     3721        isValid = true;
     3722        break;
     3723    case ExtensionsGL::FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives, or core in WebGL 2.0
     3724        if (m_oesStandardDerivatives || isWebGL2())
     3725            isValid = true;
     3726        break;
     3727    }
     3728    if (!isValid) {
     3729        synthesizeGLError(GraphicsContextGL::INVALID_ENUM, "hint", "invalid target");
     3730        return;
     3731    }
     3732    m_context->hint(target, mode);
     3733}
     3734
    36943735GCGLboolean WebGLRenderingContextBase::isBuffer(WebGLBuffer* buffer)
    36953736{
     
    69096950}
    69106951
     6952bool WebGLRenderingContextBase::validateCapability(const char* functionName, GCGLenum cap)
     6953{
     6954    switch (cap) {
     6955    case GraphicsContextGL::BLEND:
     6956    case GraphicsContextGL::CULL_FACE:
     6957    case GraphicsContextGL::DEPTH_TEST:
     6958    case GraphicsContextGL::DITHER:
     6959    case GraphicsContextGL::POLYGON_OFFSET_FILL:
     6960    case GraphicsContextGL::SAMPLE_ALPHA_TO_COVERAGE:
     6961    case GraphicsContextGL::SAMPLE_COVERAGE:
     6962    case GraphicsContextGL::SCISSOR_TEST:
     6963    case GraphicsContextGL::STENCIL_TEST:
     6964        return true;
     6965    default:
     6966        synthesizeGLError(GraphicsContextGL::INVALID_ENUM, functionName, "invalid capability");
     6967        return false;
     6968    }
     6969}
     6970
    69116971bool WebGLRenderingContextBase::validateUniformParameters(const char* functionName, const WebGLUniformLocation* location, const Float32List& v, GCGLsizei requiredMinSize, GCGLuint srcOffset, GCGLuint srcLength)
    69126972{
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h

    r264845 r264889  
    142142
    143143    GCGLenum checkFramebufferStatus(GCGLenum target);
    144     virtual void clear(GCGLbitfield mask) = 0;
     144    void clear(GCGLbitfield mask);
    145145    void clearColor(GCGLfloat red, GCGLfloat green, GCGLfloat blue, GCGLfloat alpha);
    146146    void clearDepth(GCGLfloat);
     
    224224    void setPreventBufferClearForInspector(bool value) { m_preventBufferClearForInspector = value; }
    225225
    226     virtual void hint(GCGLenum target, GCGLenum mode) = 0;
     226    void hint(GCGLenum target, GCGLenum mode);
    227227    GCGLboolean isBuffer(WebGLBuffer*);
    228228    bool isContextLost() const;
     
    964964
    965965    // Helper function to validate a GL capability.
    966     virtual bool validateCapability(const char* functionName, GCGLenum) = 0;
     966    virtual bool validateCapability(const char* functionName, GCGLenum);
    967967
    968968    // Helper function to validate input parameters for uniform functions.
Note: See TracChangeset for help on using the changeset viewer.