Changeset 64660 in webkit


Ignore:
Timestamp:
Aug 4, 2010 11:39:02 AM (14 years ago)
Author:
kbr@google.com
Message:

2010-08-03 Kenneth Russell <kbr@google.com>

Reviewed by Nate Chapin.

Move WebGL-specific code out of GraphicsContext3D so that G3D can be used as a generic accelerated drawing API
https://bugs.webkit.org/show_bug.cgi?id=43221

Added a helper function to extract the contents of WebGL objects
to reduce duplicated code and fix a couple of potential crashes
introduced in the previous refactoring.

No new tests; ran existing WebGL tests.

  • html/canvas/WebGLRenderingContext.cpp: (WebCore::WebGLRenderingContext::attachShader): (WebCore::WebGLRenderingContext::bindAttribLocation): (WebCore::WebGLRenderingContext::bindBuffer): (WebCore::WebGLRenderingContext::bindFramebuffer): (WebCore::WebGLRenderingContext::bindRenderbuffer): (WebCore::WebGLRenderingContext::bindTexture): (WebCore::WebGLRenderingContext::compileShader): (WebCore::WebGLRenderingContext::detachShader): (WebCore::WebGLRenderingContext::framebufferRenderbuffer): (WebCore::WebGLRenderingContext::framebufferTexture2D): (WebCore::WebGLRenderingContext::getActiveAttrib): (WebCore::WebGLRenderingContext::getActiveUniform): (WebCore::WebGLRenderingContext::getAttachedShaders): (WebCore::WebGLRenderingContext::getAttribLocation): (WebCore::WebGLRenderingContext::getProgramParameter): (WebCore::WebGLRenderingContext::getProgramInfoLog): (WebCore::WebGLRenderingContext::getShaderParameter): (WebCore::WebGLRenderingContext::getShaderInfoLog): (WebCore::WebGLRenderingContext::getShaderSource): (WebCore::WebGLRenderingContext::getUniform): (WebCore::WebGLRenderingContext::getUniformLocation): (WebCore::WebGLRenderingContext::linkProgram): (WebCore::WebGLRenderingContext::shaderSource): (WebCore::WebGLRenderingContext::useProgram): (WebCore::WebGLRenderingContext::validateProgram): (WebCore::WebGLRenderingContext::handleNPOTTextures): (WebCore::WebGLRenderingContext::restoreStatesAfterVertexAttrib0Simulation):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r64659 r64660  
     12010-08-03  Kenneth Russell  <kbr@google.com>
     2
     3        Reviewed by Nate Chapin.
     4
     5        Move WebGL-specific code out of GraphicsContext3D so that G3D can be used as a generic accelerated drawing API
     6        https://bugs.webkit.org/show_bug.cgi?id=43221
     7
     8        Added a helper function to extract the contents of WebGL objects
     9        to reduce duplicated code and fix a couple of potential crashes
     10        introduced in the previous refactoring.
     11
     12        No new tests; ran existing WebGL tests.
     13
     14        * html/canvas/WebGLRenderingContext.cpp:
     15        (WebCore::WebGLRenderingContext::attachShader):
     16        (WebCore::WebGLRenderingContext::bindAttribLocation):
     17        (WebCore::WebGLRenderingContext::bindBuffer):
     18        (WebCore::WebGLRenderingContext::bindFramebuffer):
     19        (WebCore::WebGLRenderingContext::bindRenderbuffer):
     20        (WebCore::WebGLRenderingContext::bindTexture):
     21        (WebCore::WebGLRenderingContext::compileShader):
     22        (WebCore::WebGLRenderingContext::detachShader):
     23        (WebCore::WebGLRenderingContext::framebufferRenderbuffer):
     24        (WebCore::WebGLRenderingContext::framebufferTexture2D):
     25        (WebCore::WebGLRenderingContext::getActiveAttrib):
     26        (WebCore::WebGLRenderingContext::getActiveUniform):
     27        (WebCore::WebGLRenderingContext::getAttachedShaders):
     28        (WebCore::WebGLRenderingContext::getAttribLocation):
     29        (WebCore::WebGLRenderingContext::getProgramParameter):
     30        (WebCore::WebGLRenderingContext::getProgramInfoLog):
     31        (WebCore::WebGLRenderingContext::getShaderParameter):
     32        (WebCore::WebGLRenderingContext::getShaderInfoLog):
     33        (WebCore::WebGLRenderingContext::getShaderSource):
     34        (WebCore::WebGLRenderingContext::getUniform):
     35        (WebCore::WebGLRenderingContext::getUniformLocation):
     36        (WebCore::WebGLRenderingContext::linkProgram):
     37        (WebCore::WebGLRenderingContext::shaderSource):
     38        (WebCore::WebGLRenderingContext::useProgram):
     39        (WebCore::WebGLRenderingContext::validateProgram):
     40        (WebCore::WebGLRenderingContext::handleNPOTTextures):
     41        (WebCore::WebGLRenderingContext::restoreStatesAfterVertexAttrib0Simulation):
     42
    1432010-08-04  Mario Sanchez Prada  <msanchez@igalia.com>
    244
  • trunk/WebCore/html/canvas/WebGLRenderingContext.cpp

    r64582 r64660  
    5858namespace WebCore {
    5959
     60static inline Platform3DObject objectOrZero(CanvasObject* object)
     61{
     62    return object ? object->object() : 0;
     63}
     64
    6065class WebGLStateRestorer {
    6166public:
     
    221226    if (!validateWebGLObject(program) || !validateWebGLObject(shader))
    222227        return;
    223     m_context->attachShader(program ? program->object() : 0, shader ? shader->object() : 0);
     228    m_context->attachShader(objectOrZero(program), objectOrZero(shader));
    224229    cleanupAfterGraphicsCall(false);
    225230}
     
    230235    if (!validateWebGLObject(program))
    231236        return;
    232     m_context->bindAttribLocation(program ? program->object() : 0, index, name);
     237    m_context->bindAttribLocation(objectOrZero(program), index, name);
    233238    cleanupAfterGraphicsCall(false);
    234239}
     
    255260    }
    256261
    257     m_context->bindBuffer(target, buffer ? buffer->object() : 0);
     262    m_context->bindBuffer(target, objectOrZero(buffer));
    258263    if (buffer)
    259264        buffer->setTarget(target);
     
    274279    }
    275280    m_framebufferBinding = buffer;
    276     m_context->bindFramebuffer(target, buffer ? buffer->object() : 0);
     281    m_context->bindFramebuffer(target, objectOrZero(buffer));
    277282    if (m_framebufferBinding)
    278283        m_framebufferBinding->onBind();
     
    292297    }
    293298    m_renderbufferBinding = renderBuffer;
    294     m_context->bindRenderbuffer(target, renderBuffer ? renderBuffer->object() : 0);
     299    m_context->bindRenderbuffer(target, objectOrZero(renderBuffer));
    295300    cleanupAfterGraphicsCall(false);
    296301}
     
    315320        return;
    316321    }
    317     m_context->bindTexture(target, texture ? texture->object() : 0);
     322    m_context->bindTexture(target, objectOrZero(texture));
    318323    if (!isGLES2Compliant() && texture)
    319324        texture->setTarget(target, maxLevel);
     
    517522    if (!validateWebGLObject(shader))
    518523        return;
    519     m_context->compileShader(shader ? shader->object() : 0);
     524    m_context->compileShader(objectOrZero(shader));
    520525    cleanupAfterGraphicsCall(false);
    521526}
     
    707712    if (!validateWebGLObject(program) || !validateWebGLObject(shader))
    708713        return;
    709     m_context->detachShader(program ? program->object() : 0, shader ? shader->object() : 0);
     714    m_context->detachShader(objectOrZero(program), objectOrZero(shader));
    710715    cleanupAfterGraphicsCall(false);
    711716}
     
    10761081        }
    10771082    }
    1078     m_context->framebufferRenderbuffer(target, attachment, renderbuffertarget, buffer ? buffer->object() : 0);
     1083    m_context->framebufferRenderbuffer(target, attachment, renderbuffertarget, objectOrZero(buffer));
    10791084    m_framebufferBinding->setAttachment(attachment, buffer);
    10801085    cleanupAfterGraphicsCall(false);
     
    11011106        return;
    11021107    }
    1103     m_context->framebufferTexture2D(target, attachment, textarget, texture ? texture->object() : 0, level);
     1108    m_context->framebufferTexture2D(target, attachment, textarget, objectOrZero(texture), level);
    11041109    m_framebufferBinding->setAttachment(attachment, texture);
    11051110    cleanupAfterGraphicsCall(false);
     
    11391144    if (!validateWebGLObject(program))
    11401145        return 0;
    1141     if (!m_context->getActiveAttrib(program ? program->object() : 0, index, info)) {
     1146    if (!m_context->getActiveAttrib(objectOrZero(program), index, info)) {
    11421147        return 0;
    11431148    }
     
    11511156    if (!validateWebGLObject(program))
    11521157        return 0;
    1153     if (!m_context->getActiveUniform(program ? program->object() : 0, index, info)) {
     1158    if (!m_context->getActiveUniform(objectOrZero(program), index, info)) {
    11541159        return 0;
    11551160    }
     
    11681173        return false;
    11691174    int numShaders = 0;
    1170     m_context->getProgramiv(program ? program->object() : 0, GraphicsContext3D::ATTACHED_SHADERS, &numShaders);
     1175    m_context->getProgramiv(objectOrZero(program), GraphicsContext3D::ATTACHED_SHADERS, &numShaders);
    11711176    if (numShaders) {
    11721177        OwnArrayPtr<unsigned int> shaders(new unsigned int[numShaders]);
    11731178        int count;
    1174         m_context->getAttachedShaders(program ? program->object() : 0, numShaders, &count, shaders.get());
     1179        m_context->getAttachedShaders(objectOrZero(program), numShaders, &count, shaders.get());
    11751180        if (count != numShaders)
    11761181            return false;
     
    11901195int WebGLRenderingContext::getAttribLocation(WebGLProgram* program, const String& name)
    11911196{
    1192     return m_context->getAttribLocation(program ? program->object() : 0, name);
     1197    return m_context->getAttribLocation(objectOrZero(program), name);
    11931198}
    11941199
     
    14681473    case GraphicsContext3D::DELETE_STATUS:
    14691474    case GraphicsContext3D::VALIDATE_STATUS:
    1470         m_context->getProgramiv(program ? program->object() : 0, pname, &value);
     1475        m_context->getProgramiv(objectOrZero(program), pname, &value);
    14711476        return WebGLGetInfo(static_cast<bool>(value));
    14721477    case GraphicsContext3D::LINK_STATUS:
    14731478        if (program->isLinkFailureFlagSet())
    14741479            return WebGLGetInfo(false);
    1475         m_context->getProgramiv(program ? program->object() : 0, pname, &value);
     1480        m_context->getProgramiv(objectOrZero(program), pname, &value);
    14761481        return WebGLGetInfo(static_cast<bool>(value));
    14771482    case GraphicsContext3D::INFO_LOG_LENGTH:
     
    14811486    case GraphicsContext3D::ACTIVE_UNIFORMS:
    14821487    case GraphicsContext3D::ACTIVE_UNIFORM_MAX_LENGTH:
    1483         m_context->getProgramiv(program ? program->object() : 0, pname, &value);
     1488        m_context->getProgramiv(objectOrZero(program), pname, &value);
    14841489        return WebGLGetInfo(static_cast<long>(value));
    14851490    default:
     
    14951500        return "";
    14961501    WebGLStateRestorer(this, false);
    1497     return m_context->getProgramInfoLog(program ? program->object() : 0);
     1502    return m_context->getProgramInfoLog(objectOrZero(program));
    14981503}
    14991504
     
    15411546    case GraphicsContext3D::DELETE_STATUS:
    15421547    case GraphicsContext3D::COMPILE_STATUS:
    1543         m_context->getShaderiv(shader ? shader->object() : 0, pname, &value);
     1548        m_context->getShaderiv(objectOrZero(shader), pname, &value);
    15441549        return WebGLGetInfo(static_cast<bool>(value));
    15451550    case GraphicsContext3D::SHADER_TYPE:
    1546         m_context->getShaderiv(shader ? shader->object() : 0, pname, &value);
     1551        m_context->getShaderiv(objectOrZero(shader), pname, &value);
    15471552        return WebGLGetInfo(static_cast<unsigned long>(value));
    15481553    case GraphicsContext3D::INFO_LOG_LENGTH:
    15491554    case GraphicsContext3D::SHADER_SOURCE_LENGTH:
    1550         m_context->getShaderiv(shader ? shader->object() : 0, pname, &value);
     1555        m_context->getShaderiv(objectOrZero(shader), pname, &value);
    15511556        return WebGLGetInfo(static_cast<long>(value));
    15521557    default:
     
    15621567        return "";
    15631568    WebGLStateRestorer(this, false);
    1564     return m_context->getShaderInfoLog(shader ? shader->object() : 0);
     1569    return m_context->getShaderInfoLog(objectOrZero(shader));
    15651570}
    15661571
     
    15711576        return "";
    15721577    WebGLStateRestorer(this, false);
    1573     return m_context->getShaderSource(shader ? shader->object() : 0);
     1578    return m_context->getShaderSource(objectOrZero(shader));
    15741579}
    15751580
     
    16211626    // FIXME: make this more efficient using WebGLUniformLocation and caching types in it
    16221627    int activeUniforms = 0;
    1623     m_context->getProgramiv(program ? program->object() : 0, GraphicsContext3D::ACTIVE_UNIFORMS, &activeUniforms);
     1628    m_context->getProgramiv(objectOrZero(program), GraphicsContext3D::ACTIVE_UNIFORMS, &activeUniforms);
    16241629    for (int i = 0; i < activeUniforms; i++) {
    16251630        ActiveInfo info;
    1626         if (!m_context->getActiveUniform(program ? program->object() : 0, i, info))
     1631        if (!m_context->getActiveUniform(objectOrZero(program), i, info))
    16271632            return WebGLGetInfo();
    16281633        // Strip "[0]" from the name if it's an array.
     
    16381643            }
    16391644            // Now need to look this up by name again to find its location
    1640             long loc = m_context->getUniformLocation(program ? program->object() : 0, name);
     1645            long loc = m_context->getUniformLocation(objectOrZero(program), name);
    16411646            if (loc == location) {
    16421647                // Found it. Use the type in the ActiveInfo to determine the return type.
     
    17131718                case GraphicsContext3D::FLOAT: {
    17141719                    float value[16] = {0};
    1715                     m_context->getUniformfv(program ? program->object() : 0, location, value);
     1720                    m_context->getUniformfv(objectOrZero(program), location, value);
    17161721                    if (length == 1)
    17171722                        return WebGLGetInfo(value[0]);
     
    17201725                case GraphicsContext3D::INT: {
    17211726                    int value[16] = {0};
    1722                     m_context->getUniformiv(program ? program->object() : 0, location, value);
     1727                    m_context->getUniformiv(objectOrZero(program), location, value);
    17231728                    if (length == 1)
    17241729                        return WebGLGetInfo(static_cast<long>(value[0]));
     
    17271732                case GraphicsContext3D::BOOL: {
    17281733                    int value[16] = {0};
    1729                     m_context->getUniformiv(program ? program->object() : 0, location, value);
     1734                    m_context->getUniformiv(objectOrZero(program), location, value);
    17301735                    if (length > 1) {
    17311736                        unsigned char boolValue[16] = {0};
     
    17531758        return 0;
    17541759    WebGLStateRestorer(this, false);
    1755     long uniformLocation = m_context->getUniformLocation(program ? program->object() : 0, name);
     1760    long uniformLocation = m_context->getUniformLocation(objectOrZero(program), name);
    17561761    if (uniformLocation == -1)
    17571762        return 0;
     
    19161921    }
    19171922
    1918     m_context->linkProgram(program ? program->object() : 0);
     1923    m_context->linkProgram(objectOrZero(program));
    19191924    program->cacheActiveAttribLocations();
    19201925    cleanupAfterGraphicsCall(false);
     
    20612066    if (!validateWebGLObject(shader))
    20622067        return;
    2063     m_context->shaderSource(shader ? shader->object() : 0, string);
     2068    m_context->shaderSource(objectOrZero(shader), string);
    20642069    cleanupAfterGraphicsCall(false);
    20652070}
     
    29502955    }
    29512956    m_currentProgram = program;
    2952     m_context->useProgram(program ? program->object() : 0);
     2957    m_context->useProgram(objectOrZero(program));
    29532958    cleanupAfterGraphicsCall(false);
    29542959}
     
    29592964    if (!validateWebGLObject(program))
    29602965        return;
    2961     m_context->validateProgram(program ? program->object() : 0);
     2966    m_context->validateProgram(objectOrZero(program));
    29622967    cleanupAfterGraphicsCall(false);
    29632968}
     
    32623267            }
    32633268            if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_texture2DBinding->needToUseBlackTexture())
    3264                 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, tex2D->object());
     3269                m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, objectOrZero(tex2D));
    32653270            if (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii].m_textureCubeMapBinding->needToUseBlackTexture())
    3266                 m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, texCubeMap->object());
     3271                m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, objectOrZero(texCubeMap));
    32673272        }
    32683273    }
     
    37843789    const VertexAttribState& state = m_vertexAttribState[0];
    37853790    if (state.bufferBinding != m_vertexAttrib0Buffer) {
    3786         m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, state.bufferBinding->object());
     3791        m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, objectOrZero(state.bufferBinding.get()));
    37873792        m_context->vertexAttribPointer(0, state.size, state.type, state.normalized, state.originalStride, state.offset);
    37883793    }
    3789     m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_boundArrayBuffer->object());
     3794    m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, objectOrZero(m_boundArrayBuffer.get()));
    37903795}
    37913796
Note: See TracChangeset for help on using the changeset viewer.