Changeset 119014 in webkit


Ignore:
Timestamp:
May 30, 2012, 6:31:46 PM (13 years ago)
Author:
zmo@google.com
Message:

WebKit incorrectly clears the alpha channel on readPixels, even for Framebuffers
https://bugs.webkit.org/show_bug.cgi?id=87310

Reviewed by Kenneth Russell.

Source/WebCore:

  • html/canvas/WebGLRenderingContext.cpp:

(WebCore):
(WebCore::WebGLRenderingContext::getParameter): set DEPTH_BITS/STENCIL_BITS to 0 if related channels are not requested.
(WebCore::WebGLRenderingContext::readPixels): don't do the alpha value fix if the current bound is not the internal drawing buffer.

LayoutTests:

  • fast/canvas/webgl/context-attributes-alpha-depth-stencil-antialias-expected.txt:
  • fast/canvas/webgl/context-attributes-alpha-depth-stencil-antialias.html: synced with khronos
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r119013 r119014  
     12012-05-30  Zhenyao Mo  <zmo@google.com>
     2
     3        WebKit incorrectly clears the alpha channel on readPixels, even for Framebuffers
     4        https://bugs.webkit.org/show_bug.cgi?id=87310
     5
     6        Reviewed by Kenneth Russell.
     7
     8        * fast/canvas/webgl/context-attributes-alpha-depth-stencil-antialias-expected.txt:
     9        * fast/canvas/webgl/context-attributes-alpha-depth-stencil-antialias.html: synced with khronos
     10
    1112012-05-30  Sheriff Bot  <webkit.review.bot@gmail.com>
    212
  • trunk/LayoutTests/fast/canvas/webgl/context-attributes-alpha-depth-stencil-antialias-expected.txt

    r115870 r119014  
    44
    55Testing alpha = true
    6 PASS webGL = getWebGL(1, 1, { alpha: true, depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 0 ], 1, 0) is non-null.
    7 PASS contextAttribs = webGL.getContextAttributes() is non-null.
     6PASS getError was expected value: NO_ERROR : should be no errors
     7PASS gl = getWebGL(1, 1, { alpha: true, depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 0 ], 1, 0) is non-null.
     8PASS gl.getParameter(gl.ALPHA_BITS) >= 8 is true
     9PASS gl.getParameter(gl.RED_BITS) >= 8 is true
     10PASS gl.getParameter(gl.GREEN_BITS) >= 8 is true
     11PASS gl.getParameter(gl.BLUE_BITS) >= 8 is true
     12PASS gl.getParameter(gl.DEPTH_BITS) == 0 is true
     13PASS gl.getParameter(gl.STENCIL_BITS) == 0 is true
     14PASS contextAttribs = gl.getContextAttributes() is non-null.
    815PASS contextAttribs.alpha == true is true
    916PASS pixel is correctColor
     17PASS Math.abs(pixel[0] - 127) <= 1 && Math.abs(pixel[1] - 127) <= 1 && Math.abs(pixel[2] - 127) <= 1 && Math.abs(pixel[3] - 127) <= 1 is true
    1018Testing alpha = false
    11 PASS webGL = getWebGL(1, 1, { alpha: false, depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 0 ], 1, 0) is non-null.
    12 PASS contextAttribs = webGL.getContextAttributes() is non-null.
     19PASS getError was expected value: NO_ERROR : should be no errors
     20PASS gl = getWebGL(1, 1, { alpha: false, depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 0 ], 1, 0) is non-null.
     21PASS gl.getParameter(gl.ALPHA_BITS) == 0 is true
     22PASS gl.getParameter(gl.RED_BITS) >= 8 is true
     23PASS gl.getParameter(gl.GREEN_BITS) >= 8 is true
     24PASS gl.getParameter(gl.BLUE_BITS) >= 8 is true
     25PASS gl.getParameter(gl.DEPTH_BITS) == 0 is true
     26PASS gl.getParameter(gl.STENCIL_BITS) == 0 is true
     27PASS contextAttribs = gl.getContextAttributes() is non-null.
    1328PASS contextAttribs.alpha == false is true
    1429PASS pixel is correctColor
     30PASS Math.abs(pixel[0] - 127) <= 1 && Math.abs(pixel[1] - 127) <= 1 && Math.abs(pixel[2] - 127) <= 1 && Math.abs(pixel[3] - 127) <= 1 is true
    1531Testing depth = true
    16 PASS webGL = getWebGL(1, 1, { stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
    17 PASS contextAttribs = webGL.getContextAttributes() is non-null.
     32PASS getError was expected value: NO_ERROR : should be no errors
     33PASS gl = getWebGL(1, 1, { stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
     34PASS gl.getParameter(gl.DEPTH_BITS) >= 16 is true
     35PASS gl.getParameter(gl.RED_BITS) >= 8 is true
     36PASS gl.getParameter(gl.GREEN_BITS) >= 8 is true
     37PASS gl.getParameter(gl.BLUE_BITS) >= 8 is true
     38PASS gl.getParameter(gl.ALPHA_BITS) >= 8 is true
     39PASS contextAttribs = gl.getContextAttributes() is non-null.
    1840PASS pixel is correctColor
     41PASS pixel is [0, 0, 0, 255]
    1942Testing depth = false
    20 PASS webGL = getWebGL(1, 1, { depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
    21 PASS contextAttribs = webGL.getContextAttributes() is non-null.
     43PASS getError was expected value: NO_ERROR : should be no errors
     44PASS gl = getWebGL(1, 1, { depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
     45PASS gl.getParameter(gl.DEPTH_BITS) == 0 is true
     46PASS gl.getParameter(gl.RED_BITS) >= 8 is true
     47PASS gl.getParameter(gl.GREEN_BITS) >= 8 is true
     48PASS gl.getParameter(gl.BLUE_BITS) >= 8 is true
     49PASS gl.getParameter(gl.ALPHA_BITS) >= 8 is true
     50PASS contextAttribs = gl.getContextAttributes() is non-null.
    2251PASS pixel is correctColor
     52PASS pixel is [0, 0, 0, 255]
    2353Testing stencil = true, depth = false
    24 PASS webGL = getWebGL(1, 1, { depth: false, stencil: true, antialias: false }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
    25 PASS contextAttribs = webGL.getContextAttributes() is non-null.
     54PASS getError was expected value: NO_ERROR : should be no errors
     55PASS gl = getWebGL(1, 1, { depth: false, stencil: true, antialias: false }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
     56PASS gl.getParameter(gl.RED_BITS) >= 8 is true
     57PASS gl.getParameter(gl.GREEN_BITS) >= 8 is true
     58PASS gl.getParameter(gl.BLUE_BITS) >= 8 is true
     59PASS gl.getParameter(gl.ALPHA_BITS) >= 8 is true
     60PASS gl.getParameter(gl.DEPTH_BITS) == 0 is true
     61PASS gl.getParameter(gl.STENCIL_BITS) >= 8 is true
     62PASS contextAttribs = gl.getContextAttributes() is non-null.
    2663PASS pixel is correctColor
     64PASS pixel is [0, 0, 0, 255]
    2765Testing stencil = false, depth = false
    28 PASS webGL = getWebGL(1, 1, { depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
    29 PASS contextAttribs = webGL.getContextAttributes() is non-null.
     66PASS getError was expected value: NO_ERROR : should be no errors
     67PASS gl = getWebGL(1, 1, { depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
     68PASS gl.getParameter(gl.RED_BITS) >= 8 is true
     69PASS gl.getParameter(gl.GREEN_BITS) >= 8 is true
     70PASS gl.getParameter(gl.BLUE_BITS) >= 8 is true
     71PASS gl.getParameter(gl.ALPHA_BITS) >= 8 is true
     72PASS gl.getParameter(gl.DEPTH_BITS) == 0 is true
     73PASS gl.getParameter(gl.STENCIL_BITS) == 0 is true
     74PASS contextAttribs = gl.getContextAttributes() is non-null.
    3075PASS pixel is correctColor
     76PASS pixel is [0, 0, 0, 255]
    3177Testing stencil = true, depth = true
    32 PASS webGL = getWebGL(1, 1, { depth: true, stencil: true, antialias: false }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
    33 PASS contextAttribs = webGL.getContextAttributes() is non-null.
     78PASS getError was expected value: NO_ERROR : should be no errors
     79PASS gl = getWebGL(1, 1, { depth: true, stencil: true, antialias: false }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
     80PASS gl.getParameter(gl.RED_BITS) >= 8 is true
     81PASS gl.getParameter(gl.GREEN_BITS) >= 8 is true
     82PASS gl.getParameter(gl.BLUE_BITS) >= 8 is true
     83PASS gl.getParameter(gl.ALPHA_BITS) >= 8 is true
     84PASS gl.getParameter(gl.DEPTH_BITS) >= 16 is true
     85PASS gl.getParameter(gl.STENCIL_BITS) >= 8 is true
     86PASS contextAttribs = gl.getContextAttributes() is non-null.
    3487PASS pixel is correctColor
     88PASS pixel is [0, 0, 0, 255]
    3589Testing stencil = false, depth = true
    36 PASS webGL = getWebGL(1, 1, { depth: true, stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
    37 PASS contextAttribs = webGL.getContextAttributes() is non-null.
     90PASS getError was expected value: NO_ERROR : should be no errors
     91PASS gl = getWebGL(1, 1, { depth: true, stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
     92PASS gl.getParameter(gl.RED_BITS) >= 8 is true
     93PASS gl.getParameter(gl.GREEN_BITS) >= 8 is true
     94PASS gl.getParameter(gl.BLUE_BITS) >= 8 is true
     95PASS gl.getParameter(gl.ALPHA_BITS) >= 8 is true
     96PASS gl.getParameter(gl.DEPTH_BITS) >= 16 is true
     97PASS gl.getParameter(gl.STENCIL_BITS) == 0 is true
     98PASS contextAttribs = gl.getContextAttributes() is non-null.
    3899PASS pixel is correctColor
     100PASS pixel is [0, 0, 0, 255]
    39101Testing antialias = true
    40 PASS webGL = getWebGL(2, 2, { depth: false, stencil: false, alpha: false, antialias: true }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
    41 PASS contextAttribs = webGL.getContextAttributes() is non-null.
     102PASS getError was expected value: NO_ERROR : should be no errors
     103PASS gl = getWebGL(2, 2, { depth: false, stencil: false, alpha: false, antialias: true }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
     104PASS contextAttribs = gl.getContextAttributes() is non-null.
    42105PASS pixel[0] != 255 && pixel[0] != 0 is contextAttribs.antialias
    43106Testing antialias = false
    44 PASS webGL = getWebGL(2, 2, { depth: false, stencil: false, alpha: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
    45 PASS contextAttribs = webGL.getContextAttributes() is non-null.
     107PASS getError was expected value: NO_ERROR : should be no errors
     108PASS gl = getWebGL(2, 2, { depth: false, stencil: false, alpha: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0) is non-null.
     109PASS contextAttribs = gl.getContextAttributes() is non-null.
    46110PASS pixel[0] != 255 && pixel[0] != 0 is contextAttribs.antialias
    47111PASS successfullyParsed is true
  • trunk/LayoutTests/fast/canvas/webgl/context-attributes-alpha-depth-stencil-antialias.html

    r115870 r119014  
     1
     2<!DOCTYPE html>
    13<html>
    24<head>
     5<meta charset="utf-8">
     6<link rel="stylesheet" href="../../js/resources/js-test-style.css"/>
    37<script src="../../js/resources/js-test-pre.js"></script>
    48<script src="resources/webgl-test.js"></script>
     
    2731
    2832<script>
     33var successfullyParsed = false;
    2934
    3035// These four declarations need to be global for "shouldBe" to see them
    31 var webGL = null;
     36var gl;
    3237var contextAttribs = null;
    3338var pixel = [0, 0, 0, 1];
    3439var correctColor = null;
     40var framebuffer;
     41var fbHasColor;
     42var fbHasDepth;
     43var fbHasStencil;
    3544
    3645function init()
     
    5362    canvas.height = canvasHeight;
    5463
    55     var context = create3DContext(canvas, contextAttribs);
    56     if (!context)
     64    gl = create3DContext(canvas, contextAttribs);
     65    if (!gl)
    5766        return null;
    5867
    59     context.program = createProgram(context, "vshader", "fshader", ["pos", "colorIn"]);
    60     if (!context.program)
     68    var program = createProgram(gl, "vshader", "fshader", ["pos", "colorIn"]);
     69    if (!program)
    6170        return null;
    6271
    63     context.useProgram(context.program);
    64 
    65     context.enable(context.DEPTH_TEST);
    66     context.enable(context.STENCIL_TEST);
    67     context.disable(context.BLEND);
    68 
    69     context.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
    70     context.clearDepth(clearDepth);
    71     context.clearStencil(clearStencil);
    72     context.clear(context.COLOR_BUFFER_BIT | context.DEPTH_BUFFER_BIT | context.STENCIL_BUFFER_BIT);
    73 
    74     return context;
     72    gl.useProgram(program);
     73
     74    gl.enable(gl.DEPTH_TEST);
     75    gl.enable(gl.STENCIL_TEST);
     76    gl.disable(gl.BLEND);
     77
     78    gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
     79    gl.clearDepth(clearDepth);
     80    gl.clearStencil(clearStencil);
     81    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
     82
     83    framebuffer = gl.createFramebuffer();
     84    gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
     85    var texture = gl.createTexture();
     86    gl.bindTexture(gl.TEXTURE_2D, texture);
     87    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.canvas.width, gl.canvas.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
     88    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
     89    fbHasStencil = false;
     90    fbHasDepth = false;
     91    fbHasColor = gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE;
     92    if (fbHasColor) {
     93      var depthStencil = gl.createRenderbuffer();
     94      gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencil);
     95      gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, gl.canvas.width, gl.canvas.height);
     96      gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, depthStencil);
     97      fbHasDepth = gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE;
     98      if (!fbHasDepth) {
     99        gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, null);
     100        shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
     101      } else {
     102        fbHasStencil = true;
     103      }
     104    }
     105    gl.bindFramebuffer(gl.FRAMEBUFFER, null);
     106    glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
     107
     108    return gl;
    75109}
    76110
     
    100134{
    101135    debug("Testing alpha = " + alpha);
    102     if (alpha)
    103         shouldBeNonNull("webGL = getWebGL(1, 1, { alpha: true, depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 0 ], 1, 0)");
    104     else
    105         shouldBeNonNull("webGL = getWebGL(1, 1, { alpha: false, depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 0 ], 1, 0)");
    106     shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
     136    if (alpha) {
     137        shouldBeNonNull("gl = getWebGL(1, 1, { alpha: true, depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 0 ], 1, 0)");
     138        shouldBeTrue("gl.getParameter(gl.ALPHA_BITS) >= 8");
     139    } else {
     140        shouldBeNonNull("gl = getWebGL(1, 1, { alpha: false, depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 0 ], 1, 0)");
     141        shouldBeTrue("gl.getParameter(gl.ALPHA_BITS) == 0");
     142    }
     143    shouldBeTrue("gl.getParameter(gl.RED_BITS) >= 8");
     144    shouldBeTrue("gl.getParameter(gl.GREEN_BITS) >= 8");
     145    shouldBeTrue("gl.getParameter(gl.BLUE_BITS) >= 8");
     146    shouldBeTrue("gl.getParameter(gl.DEPTH_BITS) == 0");
     147    shouldBeTrue("gl.getParameter(gl.STENCIL_BITS) == 0");
     148
     149    shouldBeNonNull("contextAttribs = gl.getContextAttributes()");
    107150    shouldBeTrue("contextAttribs.alpha == " + alpha);
    108151
    109152    var buf = new Uint8Array(1 * 1 * 4);
    110     webGL.readPixels(0, 0, 1, 1, webGL.RGBA, webGL.UNSIGNED_BYTE, buf);
     153    gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
    111154    pixel[0] = buf[0];
    112155    pixel[1] = buf[1];
     
    115158    correctColor = (contextAttribs.alpha ? [0, 0, 0, 0] : [0, 0, 0, 255]);
    116159    shouldBe("pixel", "correctColor");
     160
     161    if (fbHasColor) {
     162      gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
     163      gl.clearColor(0.5, 0.5, 0.5, 0.5);
     164      gl.clear(gl.COLOR_BUFFER_BIT);
     165      gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
     166      pixel[0] = buf[0];
     167      pixel[1] = buf[1];
     168      pixel[2] = buf[2];
     169      pixel[3] = buf[3];
     170      shouldBeTrue("Math.abs(pixel[0] - 127) <= 1 && Math.abs(pixel[1] - 127) <= 1 && Math.abs(pixel[2] - 127) <= 1 && Math.abs(pixel[3] - 127) <= 1");
     171      gl.bindFramebuffer(gl.FRAMEBUFFER, null);
     172    }
    117173}
    118174
     
    120176{
    121177    debug("Testing depth = " + depth);
    122     if (depth)
    123         shouldBeNonNull("webGL = getWebGL(1, 1, { stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
    124     else
    125         shouldBeNonNull("webGL = getWebGL(1, 1, { depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
    126     shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
    127 
    128     webGL.depthFunc(webGL.NEVER);
     178    if (depth) {
     179        shouldBeNonNull("gl = getWebGL(1, 1, { stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
     180        shouldBeTrue("gl.getParameter(gl.DEPTH_BITS) >= 16");
     181    } else {
     182        shouldBeNonNull("gl = getWebGL(1, 1, { depth: false, stencil: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
     183        shouldBeTrue("gl.getParameter(gl.DEPTH_BITS) == 0");
     184    }
     185    shouldBeTrue("gl.getParameter(gl.RED_BITS) >= 8");
     186    shouldBeTrue("gl.getParameter(gl.GREEN_BITS) >= 8");
     187    shouldBeTrue("gl.getParameter(gl.BLUE_BITS) >= 8");
     188    shouldBeTrue("gl.getParameter(gl.ALPHA_BITS) >= 8");
     189
     190    shouldBeNonNull("contextAttribs = gl.getContextAttributes()");
     191
     192    gl.depthFunc(gl.NEVER);
    129193
    130194    var vertices = new Float32Array([
     
    143207        255, 0, 0, 255]);
    144208
    145     var buf = drawAndReadPixel(webGL, vertices, colors, 0, 0);
     209    var buf = drawAndReadPixel(gl, vertices, colors, 0, 0);
    146210    pixel[0] = buf[0];
    147211    pixel[1] = buf[1];
     
    150214    correctColor = (contextAttribs.depth ? [0, 0, 0, 255] : [255, 0, 0, 255]);
    151215    shouldBe("pixel", "correctColor");
     216
     217    if (fbHasDepth) {
     218      gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
     219      gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
     220      var buf = drawAndReadPixel(gl, vertices, colors, 0, 0);
     221      pixel[0] = buf[0];
     222      pixel[1] = buf[1];
     223      pixel[2] = buf[2];
     224      pixel[3] = buf[3];
     225      shouldBe("pixel", "[0, 0, 0, 255]");
     226      gl.bindFramebuffer(gl.FRAMEBUFFER, null);
     227    }
    152228}
    153229
     
    156232    debug("Testing stencil = " + stencil + ", depth = " + depth);
    157233    var creationString =
    158         "webGL = getWebGL(1, 1, { depth: " + depth + ", stencil: " + stencil + ", antialias: false }, [ 0, 0, 0, 1 ], 1, 0)";
     234        "gl = getWebGL(1, 1, { depth: " + depth + ", stencil: " + stencil + ", antialias: false }, [ 0, 0, 0, 1 ], 1, 0)";
    159235    shouldBeNonNull(creationString);
    160     shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
     236
     237    shouldBeTrue("gl.getParameter(gl.RED_BITS) >= 8");
     238    shouldBeTrue("gl.getParameter(gl.GREEN_BITS) >= 8");
     239    shouldBeTrue("gl.getParameter(gl.BLUE_BITS) >= 8");
     240    shouldBeTrue("gl.getParameter(gl.ALPHA_BITS) >= 8");
     241    if (depth)
     242        shouldBeTrue("gl.getParameter(gl.DEPTH_BITS) >= 16");
     243    else
     244        shouldBeTrue("gl.getParameter(gl.DEPTH_BITS) == 0");
     245
     246    if (stencil)
     247        shouldBeTrue("gl.getParameter(gl.STENCIL_BITS) >= 8");
     248    else
     249        shouldBeTrue("gl.getParameter(gl.STENCIL_BITS) == 0");
     250
     251    shouldBeNonNull("contextAttribs = gl.getContextAttributes()");
     252    if (!depth && contextAttribs.depth) {
     253        testFailed("WebGL implementation provided a depth buffer when it should not have");
     254    }
     255    if (!contextAttribs.depth)
     256        depth = false;
    161257    if (!stencil && contextAttribs.stencil) {
    162258        testFailed("WebGL implementation provided a stencil buffer when it should not have");
     
    165261        stencil = false;
    166262
    167     webGL.depthFunc(webGL.ALWAYS);
    168 
    169     webGL.stencilFunc(webGL.NEVER, 1, 1);
    170     webGL.stencilOp(webGL.KEEP, webGL.KEEP, webGL.KEEP);
     263    gl.depthFunc(gl.ALWAYS);
     264
     265    gl.stencilFunc(gl.NEVER, 1, 1);
     266    gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
    171267
    172268    var vertices = new Float32Array([
     
    185281        255, 0, 0, 255]);
    186282
    187     var buf = drawAndReadPixel(webGL, vertices, colors, 0, 0);
     283    var buf = drawAndReadPixel(gl, vertices, colors, 0, 0);
    188284    pixel[0] = buf[0];
    189285    pixel[1] = buf[1];
     
    192288    correctColor = (stencil ? [0, 0, 0, 255] : [255, 0, 0, 255]);
    193289    shouldBe("pixel", "correctColor");
     290
     291    if (fbHasStencil) {
     292      gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
     293      gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
     294      var buf = drawAndReadPixel(gl, vertices, colors, 0, 0);
     295      pixel[0] = buf[0];
     296      pixel[1] = buf[1];
     297      pixel[2] = buf[2];
     298      pixel[3] = buf[3];
     299      shouldBe("pixel", "[0, 0, 0, 255]");
     300      gl.bindFramebuffer(gl.FRAMEBUFFER, null);
     301    }
    194302}
    195303
     
    198306    debug("Testing antialias = " + antialias);
    199307    if (antialias)
    200         shouldBeNonNull("webGL = getWebGL(2, 2, { depth: false, stencil: false, alpha: false, antialias: true }, [ 0, 0, 0, 1 ], 1, 0)");
     308        shouldBeNonNull("gl = getWebGL(2, 2, { depth: false, stencil: false, alpha: false, antialias: true }, [ 0, 0, 0, 1 ], 1, 0)");
    201309    else
    202         shouldBeNonNull("webGL = getWebGL(2, 2, { depth: false, stencil: false, alpha: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
    203     shouldBeNonNull("contextAttribs = webGL.getContextAttributes()");
     310        shouldBeNonNull("gl = getWebGL(2, 2, { depth: false, stencil: false, alpha: false, antialias: false }, [ 0, 0, 0, 1 ], 1, 0)");
     311    shouldBeNonNull("contextAttribs = gl.getContextAttributes()");
    204312
    205313    var vertices = new Float32Array([
     
    211319        255, 0, 0, 255,
    212320        255, 0, 0, 255]);
    213     var buf = drawAndReadPixel(webGL, vertices, colors, 0, 0);
     321    var buf = drawAndReadPixel(gl, vertices, colors, 0, 0);
    214322    pixel[0] = buf[0];
    215323    shouldBe("pixel[0] != 255 && pixel[0] != 0", "contextAttribs.antialias");
  • trunk/Source/WebCore/ChangeLog

    r119013 r119014  
     12012-05-30  Zhenyao Mo  <zmo@google.com>
     2
     3        WebKit incorrectly clears the alpha channel on readPixels, even for Framebuffers
     4        https://bugs.webkit.org/show_bug.cgi?id=87310
     5
     6        Reviewed by Kenneth Russell.
     7
     8        * html/canvas/WebGLRenderingContext.cpp:
     9        (WebCore):
     10        (WebCore::WebGLRenderingContext::getParameter): set DEPTH_BITS/STENCIL_BITS to 0 if related channels are not requested.
     11        (WebCore::WebGLRenderingContext::readPixels): don't do the alpha value fix if the current bound is not the internal drawing buffer.
     12
    1132012-05-30  Sheriff Bot  <webkit.review.bot@gmail.com>
    214
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp

    r117918 r119014  
    24022402    if (isContextLost())
    24032403        return WebGLGetInfo();
     2404    const int intZero = 0;
    24042405    WebGLStateRestorer(this, false);
    24052406    switch (pname) {
     
    24452446        return WebGLGetInfo(PassRefPtr<WebGLProgram>(m_currentProgram));
    24462447    case GraphicsContext3D::DEPTH_BITS:
     2448        if (!m_attributes.depth)
     2449            return WebGLGetInfo(intZero);
    24472450        return getIntParameter(pname);
    24482451    case GraphicsContext3D::DEPTH_CLEAR_VALUE:
     
    25382541        return getUnsignedIntParameter(pname);
    25392542    case GraphicsContext3D::STENCIL_BITS:
     2543        if (!m_attributes.stencil)
     2544            return WebGLGetInfo(intZero);
    25402545        return getIntParameter(pname);
    25412546    case GraphicsContext3D::STENCIL_CLEAR_VALUE:
     
    32923297    // FIXME: remove this section when GL driver bug on Mac is fixed, i.e.,
    32933298    // when alpha is off, readPixels should set alpha to 255 instead of 0.
    3294     if (!m_context->getContextAttributes().alpha) {
     3299    if (!m_framebufferBinding && !m_context->getContextAttributes().alpha) {
    32953300        unsigned char* pixels = reinterpret_cast<unsigned char*>(data);
    32963301        for (GC3Dsizei iy = 0; iy < height; ++iy) {
Note: See TracChangeset for help on using the changeset viewer.