Changeset 60874 in webkit


Ignore:
Timestamp:
Jun 8, 2010 5:45:24 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-06-08 Zhenyao Mo <zmo@google.com>

Reviewed by Dimitri Glazkov.

Validate *tex* functions input parameters according to ES2 conformance
https://bugs.webkit.org/show_bug.cgi?id=38145

  • fast/canvas/webgl/tex-image-and-sub-image-2d-with-image.html: Internalformat and format need to be the same.
  • fast/canvas/webgl/tex-input-validation-expected.txt: Added.
  • fast/canvas/webgl/tex-input-validation.html: Added.

2010-06-08 Zhenyao Mo <zmo@google.com>

Reviewed by Dimitri Glazkov.

Validate *tex* functions input parameters according to ES2 conformance
https://bugs.webkit.org/show_bug.cgi?id=38145

Test: fast/canvas/webgl/tex-input-validation.html

  • html/canvas/WebGLFramebuffer.cpp: (WebCore::WebGLFramebuffer::getColorBufferFormat): Get color buffer internalformat.
  • html/canvas/WebGLFramebuffer.h: Ditto.
  • html/canvas/WebGLRenderingContext.cpp: (WebCore::WebGLRenderingContext::WebGLRenderingContext): Deal with max tex units and max texture size. (WebCore::WebGLRenderingContext::copyTexImage2D): Validate input parameters. (WebCore::WebGLRenderingContext::copyTexSubImage2D): Ditto. (WebCore::WebGLRenderingContext::texImage2DBase): Ditto. (WebCore::WebGLRenderingContext::texParameterf): Ditto. (WebCore::WebGLRenderingContext::texParameteri): Ditto. (WebCore::WebGLRenderingContext::texSubImage2DBase): Ditto. (WebCore::WebGLRenderingContext::handleNPOTTextures): Deal with max tex units. (WebCore::WebGLRenderingContext::isTexInternalformatColorBufferCombinationValid): Check whether the texture format and framebuffer color buffer internalformat combination is valid. (WebCore::WebGLRenderingContext::getTextureBinding): get the current bound texture for given target. (WebCore::WebGLRenderingContext::validateTexFuncFormatAndType): Validate input format/type for *tex* functions. (WebCore::WebGLRenderingContext::validateTexFuncParameters): Validate input parameters for *tex* functions. (WebCore::WebGLRenderingContext::texParameter): Base function for texParameteri and texParameterf.
  • html/canvas/WebGLRenderingContext.h: Deal with max tex units.
  • html/canvas/WebGLTexture.cpp: (WebCore::WebGLTexture::WebGLTexture): Cache internalformat.
  • html/canvas/WebGLTexture.h: Ditto. (WebCore::WebGLTexture::setInternalformat): (WebCore::WebGLTexture::getInternalformat):
  • platform/graphics/GraphicsContext3D.cpp: internalformat and format need to be the same. (WebCore::GraphicsContext3D::extractImageData):
Location:
trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r60873 r60874  
     12010-06-08  Zhenyao Mo  <zmo@google.com>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        Validate *tex* functions input parameters according to ES2 conformance
     6        https://bugs.webkit.org/show_bug.cgi?id=38145
     7
     8        * fast/canvas/webgl/tex-image-and-sub-image-2d-with-image.html: Internalformat and format need to be the same.
     9        * fast/canvas/webgl/tex-input-validation-expected.txt: Added.
     10        * fast/canvas/webgl/tex-input-validation.html: Added.
     11
    1122010-06-08  Erik Arvidsson  <arv@chromium.org>
    213
  • trunk/LayoutTests/fast/canvas/webgl/tex-image-and-sub-image-2d-with-image.html

    r55282 r60874  
    118118    if (useTexSubImage2D) {
    119119        // Initialize the texture to black first
    120         gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, image.width, image.height, 0,
     120        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, image.width, image.height, 0,
    121121                      gl.RGBA, gl.UNSIGNED_BYTE, null);
    122122        gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, image, flipY, false);
     
    129129    // Draw the triangles
    130130    gl.drawArrays(gl.TRIANGLES, 0, 6);
    131 
    132131    // Read back the rendering results
    133132    var width = 32;
  • trunk/WebCore/ChangeLog

    r60873 r60874  
     12010-06-08  Zhenyao Mo  <zmo@google.com>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        Validate *tex* functions input parameters according to ES2 conformance
     6        https://bugs.webkit.org/show_bug.cgi?id=38145
     7
     8        Test: fast/canvas/webgl/tex-input-validation.html
     9
     10        * html/canvas/WebGLFramebuffer.cpp:
     11        (WebCore::WebGLFramebuffer::getColorBufferFormat): Get color buffer internalformat.
     12        * html/canvas/WebGLFramebuffer.h: Ditto.
     13        * html/canvas/WebGLRenderingContext.cpp:
     14        (WebCore::WebGLRenderingContext::WebGLRenderingContext): Deal with max tex units and max texture size.
     15        (WebCore::WebGLRenderingContext::copyTexImage2D): Validate input parameters.
     16        (WebCore::WebGLRenderingContext::copyTexSubImage2D): Ditto.
     17        (WebCore::WebGLRenderingContext::texImage2DBase): Ditto.
     18        (WebCore::WebGLRenderingContext::texParameterf): Ditto.
     19        (WebCore::WebGLRenderingContext::texParameteri): Ditto.
     20        (WebCore::WebGLRenderingContext::texSubImage2DBase): Ditto.
     21        (WebCore::WebGLRenderingContext::handleNPOTTextures): Deal with max tex units.
     22        (WebCore::WebGLRenderingContext::isTexInternalformatColorBufferCombinationValid): Check whether the texture format and framebuffer color buffer internalformat combination is valid.
     23        (WebCore::WebGLRenderingContext::getTextureBinding): get the current bound texture for given target.
     24        (WebCore::WebGLRenderingContext::validateTexFuncFormatAndType): Validate input format/type for *tex* functions.
     25        (WebCore::WebGLRenderingContext::validateTexFuncParameters): Validate input parameters for *tex* functions.
     26        (WebCore::WebGLRenderingContext::texParameter): Base function for texParameteri and texParameterf.
     27        * html/canvas/WebGLRenderingContext.h: Deal with max tex units.
     28        * html/canvas/WebGLTexture.cpp:
     29        (WebCore::WebGLTexture::WebGLTexture): Cache internalformat.
     30        * html/canvas/WebGLTexture.h: Ditto.
     31        (WebCore::WebGLTexture::setInternalformat):
     32        (WebCore::WebGLTexture::getInternalformat):
     33        * platform/graphics/GraphicsContext3D.cpp: internalformat and format need to be the same.
     34        (WebCore::GraphicsContext3D::extractImageData):
     35
    1362010-06-08  Erik Arvidsson  <arv@chromium.org>
    237
  • trunk/WebCore/html/canvas/WebGLFramebuffer.cpp

    r60290 r60874  
    8888}
    8989
     90unsigned long WebGLFramebuffer::getColorBufferFormat()
     91{
     92    if (object() && m_colorAttachment && m_colorAttachment->object()) {
     93        if (m_colorAttachment->isRenderbuffer()) {
     94            unsigned long format = (reinterpret_cast<WebGLRenderbuffer*>(m_colorAttachment))->getInternalformat();
     95            switch (format) {
     96            case GraphicsContext3D::RGBA4:
     97            case GraphicsContext3D::RGB5_A1:
     98                return GraphicsContext3D::RGBA;
     99            case GraphicsContext3D::RGB565:
     100                return GraphicsContext3D::RGB;
     101            }
     102        } else if (m_colorAttachment->isTexture())
     103            return (reinterpret_cast<WebGLTexture*>(m_colorAttachment))->getInternalformat();
     104    }
     105    return 0;
     106}
     107
    90108void WebGLFramebuffer::_deleteObject(Platform3DObject object)
    91109{
  • trunk/WebCore/html/canvas/WebGLFramebuffer.h

    r60290 r60874  
    5858        void onAttachedObjectChange(CanvasObject*);
    5959
     60        unsigned long getColorBufferFormat();
     61
    6062    protected:
    6163        WebGLFramebuffer(WebGLRenderingContext*);
  • trunk/WebCore/html/canvas/WebGLRenderingContext.cpp

    r60290 r60874  
    5151
    5252#include <wtf/ByteArray.h>
     53#include <wtf/MathExtras.h>
    5354
    5455namespace WebCore {
     
    9495{
    9596    ASSERT(m_context);
     97
     98    int numCombinedTextureImageUnits = 0;
     99    m_context->getIntegerv(GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS, &numCombinedTextureImageUnits);
     100    m_textureUnits.resize(numCombinedTextureImageUnits);
     101
    96102    int numVertexAttribs = 0;
    97103    m_context->getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &numVertexAttribs);
    98104    m_maxVertexAttribs = numVertexAttribs;
     105
    99106    int implementationColorReadFormat = GraphicsContext3D::RGBA;
    100107    m_context->getIntegerv(GraphicsContext3D::IMPLEMENTATION_COLOR_READ_FORMAT, &implementationColorReadFormat);
     
    103110    m_context->getIntegerv(GraphicsContext3D::IMPLEMENTATION_COLOR_READ_TYPE, &implementationColorReadType);
    104111    m_implementationColorReadType = implementationColorReadType;
     112
     113    int maxTextureSize = 0;
     114    m_context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &maxTextureSize);
     115    m_maxTextureSize = maxTextureSize;
     116    int maxCubeMapTextureSize = 0;
     117    m_context->getIntegerv(GraphicsContext3D::MAX_CUBE_MAP_TEXTURE_SIZE, &maxCubeMapTextureSize);
     118    m_maxCubeMapTextureSize = maxCubeMapTextureSize;
     119
    105120    if (!isGLES2Compliant())
    106121        createFallbackBlackTextures1x1();
     
    434449void WebGLRenderingContext::copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border)
    435450{
    436     RefPtr<WebGLTexture> tex = 0;
    437     switch (target) {
    438     case GraphicsContext3D::TEXTURE_2D:
    439         tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding;
    440         break;
    441     case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X:
    442     case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X:
    443     case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y:
    444     case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y:
    445     case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z:
    446     case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z:
    447         tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding;
    448         break;
    449     }
     451    if (!validateTexFuncParameters(target, level, internalformat, width, height, border, internalformat, GraphicsContext3D::UNSIGNED_BYTE))
     452        return;
    450453    if (!isGLES2Compliant()) {
     454        if (m_framebufferBinding && m_framebufferBinding->object()
     455            && !isTexInternalformatColorBufferCombinationValid(internalformat,
     456                                                               m_framebufferBinding->getColorBufferFormat())) {
     457            m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION);
     458            return;
     459        }
    451460        if (level && WebGLTexture::isNPOT(width, height)) {
    452461            m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE);
    453462            return;
    454463        }
     464    }
     465    m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border);
     466    // FIXME: if the framebuffer is not complete, none of the below should be executed.
     467    WebGLTexture* tex = getTextureBinding(target);
     468    if (!isGLES2Compliant()) {
    455469        if (tex && !level) // only for level 0
    456470            tex->setSize(target, width, height);
    457     }
    458     m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border);
     471        if (tex)
     472            tex->setInternalformat(internalformat);
     473    }
    459474    if (m_framebufferBinding && tex)
    460         m_framebufferBinding->onAttachedObjectChange(tex.get());
     475        m_framebufferBinding->onAttachedObjectChange(tex);
    461476    cleanupAfterGraphicsCall(false);
    462477}
     
    464479void WebGLRenderingContext::copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height)
    465480{
     481    if (!isGLES2Compliant()) {
     482        WebGLTexture* tex = getTextureBinding(target);
     483        if (m_framebufferBinding && m_framebufferBinding->object() && tex
     484            && !isTexInternalformatColorBufferCombinationValid(tex->getInternalformat(),
     485                                                               m_framebufferBinding->getColorBufferFormat())) {
     486            m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION);
     487            return;
     488        }
     489    }
    466490    m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
    467491    cleanupAfterGraphicsCall(false);
     
    18061830                                           unsigned format, unsigned type, void* pixels, ExceptionCode& ec)
    18071831{
    1808     RefPtr<WebGLTexture> tex = 0;
    1809     switch (target) {
    1810     case GraphicsContext3D::TEXTURE_2D:
    1811         tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding;
    1812         break;
    1813     case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X:
    1814     case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X:
    1815     case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y:
    1816     case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y:
    1817     case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z:
    1818     case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z:
    1819         tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding;
    1820         break;
    1821     }
    18221832    // FIXME: For now we ignore any errors returned
    18231833    ec = 0;
     1834    if (!validateTexFuncParameters(target, level, internalformat, width, height, border, format, type))
     1835        return;
    18241836    if (!isGLES2Compliant()) {
    18251837        if (level && WebGLTexture::isNPOT(width, height)) {
     
    18271839            return;
    18281840        }
     1841    }
     1842    m_context->texImage2D(target, level, internalformat, width, height,
     1843                          border, format, type, pixels);
     1844    WebGLTexture* tex = getTextureBinding(target);
     1845    if (!isGLES2Compliant()) {
    18291846        if (tex && !level) // only for level 0
    18301847            tex->setSize(target, width, height);
    1831     }
    1832     m_context->texImage2D(target, level, internalformat, width, height,
    1833                           border, format, type, pixels);
     1848        if (tex)
     1849            tex->setInternalformat(internalformat);
     1850    }
    18341851    if (m_framebufferBinding && tex)
    1835         m_framebufferBinding->onAttachedObjectChange(tex.get());
     1852        m_framebufferBinding->onAttachedObjectChange(tex);
    18361853    cleanupAfterGraphicsCall(false);
    18371854}
     
    19581975}
    19591976
    1960 void WebGLRenderingContext::texParameterf(unsigned target, unsigned pname, float param)
    1961 {
    1962     m_context->texParameterf(target, pname, param);
     1977void WebGLRenderingContext::texParameter(unsigned long target, unsigned long pname, float paramf, int parami, bool isFloat)
     1978{
    19631979    if (!isGLES2Compliant()) {
    19641980        RefPtr<WebGLTexture> tex = 0;
    1965         if (target == GraphicsContext3D::TEXTURE_2D)
     1981        switch (target) {
     1982        case GraphicsContext3D::TEXTURE_2D:
    19661983            tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding;
    1967         else if (target == GraphicsContext3D::TEXTURE_CUBE_MAP)
     1984            break;
     1985        case GraphicsContext3D::TEXTURE_CUBE_MAP:
    19681986            tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding;
    1969         if (tex)
    1970             tex->setParameterf(pname, param);
    1971     }
    1972     cleanupAfterGraphicsCall(false);
     1987            break;
     1988        default:
     1989            m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM);
     1990            return;
     1991        }
     1992        switch (pname) {
     1993        case GraphicsContext3D::TEXTURE_MIN_FILTER:
     1994        case GraphicsContext3D::TEXTURE_MAG_FILTER:
     1995            break;
     1996        case GraphicsContext3D::TEXTURE_WRAP_S:
     1997        case GraphicsContext3D::TEXTURE_WRAP_T:
     1998            if (isFloat && paramf != GraphicsContext3D::CLAMP_TO_EDGE && paramf != GraphicsContext3D::MIRRORED_REPEAT && paramf != GraphicsContext3D::REPEAT
     1999                || !isFloat && parami != GraphicsContext3D::CLAMP_TO_EDGE && parami != GraphicsContext3D::MIRRORED_REPEAT && parami != GraphicsContext3D::REPEAT) {
     2000                m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM);
     2001                return;
     2002            }
     2003            break;
     2004        default:
     2005            m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM);
     2006            return;
     2007        }
     2008        if (tex) {
     2009            if (isFloat)
     2010                tex->setParameterf(pname, paramf);
     2011            else
     2012                tex->setParameteri(pname, parami);
     2013        }
     2014    }
     2015    if (isFloat)
     2016        m_context->texParameterf(target, pname, paramf);
     2017    else
     2018        m_context->texParameteri(target, pname, parami);
     2019    cleanupAfterGraphicsCall(false);
     2020}
     2021
     2022void WebGLRenderingContext::texParameterf(unsigned target, unsigned pname, float param)
     2023{
     2024    texParameter(target, pname, param, 0, true);
    19732025}
    19742026
    19752027void WebGLRenderingContext::texParameteri(unsigned target, unsigned pname, int param)
    19762028{
    1977     m_context->texParameteri(target, pname, param);
    1978     if (!isGLES2Compliant()) {
    1979         RefPtr<WebGLTexture> tex = 0;
    1980         if (target == GraphicsContext3D::TEXTURE_2D)
    1981             tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding;
    1982         else if (target == GraphicsContext3D::TEXTURE_CUBE_MAP)
    1983             tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding;
    1984         if (tex)
    1985             tex->setParameteri(pname, param);
    1986     }
    1987     cleanupAfterGraphicsCall(false);
     2029    texParameter(target, pname, 0, param, false);
    19882030}
    19892031
     
    19942036    // FIXME: For now we ignore any errors returned
    19952037    ec = 0;
     2038    if (!validateTexFuncFormatAndType(format, type))
     2039        return;
     2040
    19962041    m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
    19972042    cleanupAfterGraphicsCall(false);
     
    30433088        return;
    30443089    bool resetActiveUnit = false;
    3045     // FIXME: active texture unit limits should be queries instead of 32.
    3046     for (unsigned long ii = 0; ii < 32; ++ii) {
     3090    for (unsigned ii = 0; ii < m_textureUnits.size(); ++ii) {
    30473091        if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_texture2DBinding->needToUseBlackTexture()
    30483092            || m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii].m_textureCubeMapBinding->needToUseBlackTexture()) {
     
    30983142}
    30993143
     3144bool WebGLRenderingContext::isTexInternalformatColorBufferCombinationValid(unsigned long texInternalformat,
     3145                                                                           unsigned long colorBufferFormat)
     3146{
     3147    switch (colorBufferFormat) {
     3148    case GraphicsContext3D::ALPHA:
     3149        if (texInternalformat == GraphicsContext3D::ALPHA)
     3150            return true;
     3151        break;
     3152    case GraphicsContext3D::RGB:
     3153        if (texInternalformat == GraphicsContext3D::LUMINANCE
     3154            || texInternalformat == GraphicsContext3D::RGB)
     3155            return true;
     3156        break;
     3157    case GraphicsContext3D::RGBA:
     3158        return true;
     3159    }
     3160    return false;
     3161}
     3162
     3163WebGLTexture* WebGLRenderingContext::getTextureBinding(unsigned long target)
     3164{
     3165    RefPtr<WebGLTexture> tex = 0;
     3166    switch (target) {
     3167    case GraphicsContext3D::TEXTURE_2D:
     3168        tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding;
     3169        break;
     3170    case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X:
     3171    case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X:
     3172    case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y:
     3173    case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y:
     3174    case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z:
     3175    case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z:
     3176        tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding;
     3177        break;
     3178    }
     3179    if (tex && tex->object())
     3180        return tex.get();
     3181    return 0;
     3182}
     3183
     3184bool WebGLRenderingContext::validateTexFuncFormatAndType(unsigned long format, unsigned long type)
     3185{
     3186    switch (format) {
     3187    case GraphicsContext3D::ALPHA:
     3188    case GraphicsContext3D::LUMINANCE:
     3189    case GraphicsContext3D::LUMINANCE_ALPHA:
     3190    case GraphicsContext3D::RGB:
     3191    case GraphicsContext3D::RGBA:
     3192        break;
     3193    default:
     3194        m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM);
     3195        return false;
     3196    }
     3197
     3198    switch (type) {
     3199    case GraphicsContext3D::UNSIGNED_BYTE:
     3200    case GraphicsContext3D::UNSIGNED_SHORT_5_6_5:
     3201    case GraphicsContext3D::UNSIGNED_SHORT_4_4_4_4:
     3202    case GraphicsContext3D::UNSIGNED_SHORT_5_5_5_1:
     3203        break;
     3204    default:
     3205        m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM);
     3206        return false;
     3207    }
     3208
     3209    return true;
     3210}
     3211
     3212bool WebGLRenderingContext::validateTexFuncParameters(unsigned long target, long level,
     3213                                                      unsigned long internalformat,
     3214                                                      long width, long height, long border,
     3215                                                      unsigned long format, unsigned long type)
     3216{
     3217    if (isGLES2Compliant())
     3218        return true;
     3219
     3220    if (width < 0 || height < 0 || level < 0) {
     3221        m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE);
     3222        return false;
     3223    }
     3224
     3225    switch (target) {
     3226    case GraphicsContext3D::TEXTURE_2D:
     3227        if (width > m_maxTextureSize || height > m_maxTextureSize || level > log2(m_maxTextureSize)) {
     3228            m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE);
     3229            return false;
     3230        }
     3231        break;
     3232    case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X:
     3233    case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X:
     3234    case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y:
     3235    case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y:
     3236    case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z:
     3237    case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z:
     3238        if (width != height || width > m_maxCubeMapTextureSize || level > log2(m_maxCubeMapTextureSize)) {
     3239            m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE);
     3240            return false;
     3241        }
     3242        break;
     3243    default:
     3244        m_context->synthesizeGLError(GraphicsContext3D::INVALID_ENUM);
     3245        return false;
     3246    }
     3247
     3248    if (format != internalformat) {
     3249        m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION);
     3250        return false;
     3251    }
     3252
     3253    if (border) {
     3254        m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE);
     3255        return false;
     3256    }
     3257
     3258    return validateTexFuncFormatAndType(format, type);
     3259}
     3260
    31003261} // namespace WebCore
    31013262
  • trunk/WebCore/html/canvas/WebGLRenderingContext.h

    r59499 r60874  
    354354            RefPtr<WebGLTexture> m_textureCubeMapBinding;
    355355        };
    356         TextureUnitState m_textureUnits[32];
     356        Vector<TextureUnitState> m_textureUnits;
    357357        unsigned long m_activeTextureUnit;
    358358
    359359        RefPtr<WebGLTexture> m_blackTexture2D;
    360360        RefPtr<WebGLTexture> m_blackTextureCubeMap;
     361
     362        long m_maxTextureSize;
     363        long m_maxCubeMapTextureSize;
    361364
    362365        int m_packAlignment;
     
    390393        void createFallbackBlackTextures1x1();
    391394
     395        // Helper function for copyTex{Sub}Image, check whether the internalformat
     396        // and the color buffer format of the current bound framebuffer combination
     397        // is valid.
     398        bool isTexInternalformatColorBufferCombinationValid(unsigned long texInternalformat,
     399                                                            unsigned long colorBufferFormat);
     400
     401        // Helper function to get the current bound texture.
     402        WebGLTexture* getTextureBinding(unsigned long target);
     403
     404        // Helper function to check input format/type for functions {copy}Tex{Sub}Image.
     405        // Generate GL error and return false if parameters are invalid.
     406        bool validateTexFuncFormatAndType(unsigned long format, unsigned long type);
     407
     408        // Helper function to check input parameters for functions {copy}Tex{Sub}Image.
     409        // Generate GL error and return false if parameters are invalid.
     410        bool validateTexFuncParameters(unsigned long target, long level,
     411                                       unsigned long internalformat,
     412                                       long width, long height, long border,
     413                                       unsigned long format, unsigned long type);
     414
     415        // Helper function for texParameterf and texParameteri.
     416        void texParameter(unsigned long target, unsigned long pname, float parami, int paramf, bool isFloat);
     417
    392418        friend class WebGLStateRestorer;
    393419    };
  • trunk/WebCore/html/canvas/WebGLTexture.cpp

    r59470 r60874  
    4646    , m_wrapS(GraphicsContext3D::REPEAT)
    4747    , m_wrapT(GraphicsContext3D::REPEAT)
     48    , m_internalformat(0)
    4849    , m_isNPOT(false)
    4950    , m_needToUseBlackTexture(false)
  • trunk/WebCore/html/canvas/WebGLTexture.h

    r59470 r60874  
    5353        void setSize(unsigned long target, unsigned width, unsigned height);
    5454
     55        void setInternalformat(unsigned long internalformat) { m_internalformat = internalformat; }
     56        unsigned long getInternalformat() const { return m_internalformat; }
     57
    5558        static bool isNPOT(unsigned, unsigned);
    5659
     
    7881        int m_wrapT;
    7982
     83        unsigned long m_internalformat;
     84
    8085        unsigned m_width[6];
    8186        unsigned m_height[6];
  • trunk/WebCore/platform/graphics/GraphicsContext3D.cpp

    r55283 r60874  
    5555                     flipY,
    5656                     alphaOp);
    57     *internalFormat = (hasAlphaChannel ? RGBA : RGB);
     57    // For GLES2 tex functions, internalformat has to match format.
     58    *internalFormat = *format;
    5859    return true;
    5960}
Note: See TracChangeset for help on using the changeset viewer.