| Differences between
and this patch
- Source/WebCore/ChangeLog +32 lines
Lines 1-3 Source/WebCore/ChangeLog_sec1
1
2012-04-23  Zhenyao Mo  <zmo@google.com>
2
3
        framebuffer binding should not be changed after canvas resize or compositing
4
        https://bugs.webkit.org/show_bug.cgi?id=84609
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Test: fast/canvas/webgl/framebuffer-bindings-unaffected-on-resize.html
9
10
        * html/canvas/WebGLRenderingContext.cpp: set framebuffer binding to DrawingBuffer.
11
        (WebCore):
12
        (WebCore::WebGLRenderingContext::bindFramebuffer):
13
        (WebCore::WebGLRenderingContext::deleteFramebuffer):
14
        (WebCore::WebGLRenderingContext::loseContextImpl):
15
        * platform/graphics/cairo/DrawingBufferCairo.cpp: initialize m_framebufferBinding.
16
        (WebCore::DrawingBuffer::DrawingBuffer):
17
        * platform/graphics/chromium/DrawingBufferChromium.cpp: Ditto.
18
        (WebCore::DrawingBuffer::DrawingBuffer):
19
        * platform/graphics/chromium/WebGLLayerChromium.cpp: Recover framebuffer binding after update().
20
        (WebCore::WebGLLayerChromium::update):
21
        * platform/graphics/gpu/DrawingBuffer.cpp: Add a function to restore framebuffer binding.
22
        (WebCore::DrawingBuffer::restoreFramebufferBinding):
23
        (WebCore):
24
        * platform/graphics/gpu/DrawingBuffer.h: Ditto.
25
        (WebCore::DrawingBuffer::setTexture2DBinding):
26
        (DrawingBuffer):
27
        (WebCore::DrawingBuffer::setFramebufferBinding):
28
        * platform/graphics/gpu/mac/DrawingBufferMac.mm: initialize m_framebufferBinding.
29
        (WebCore::DrawingBuffer::DrawingBuffer):
30
        * platform/graphics/gpu/qt/DrawingBufferQt.cpp: initialize m_framebufferBinding.
31
        (WebCore::DrawingBuffer::DrawingBuffer):
32
1
2012-04-17  Kentaro Hara  <haraken@chromium.org>
33
2012-04-17  Kentaro Hara  <haraken@chromium.org>
2
34
3
        [Performance][V8] Skip Isolate look-up to find StringCache
35
        [Performance][V8] Skip Isolate look-up to find StringCache
- Source/WebCore/html/canvas/WebGLRenderingContext.cpp -4 / +8 lines
Lines 920-925 void WebGLRenderingContext::bindFramebuf Source/WebCore/html/canvas/WebGLRenderingContext.cpp_sec1
920
        return;
920
        return;
921
    }
921
    }
922
    m_framebufferBinding = buffer;
922
    m_framebufferBinding = buffer;
923
    if (m_drawingBuffer)
924
        m_drawingBuffer->setFramebufferBinding(objectOrZero(m_framebufferBinding.get()));
923
    if (!m_framebufferBinding && m_drawingBuffer) {
925
    if (!m_framebufferBinding && m_drawingBuffer) {
924
        // Instead of binding fb 0, bind the drawing buffer.
926
        // Instead of binding fb 0, bind the drawing buffer.
925
        m_drawingBuffer->bind();
927
        m_drawingBuffer->bind();
Lines 1533-1542 void WebGLRenderingContext::deleteFrameb Source/WebCore/html/canvas/WebGLRenderingContext.cpp_sec2
1533
        return;
1535
        return;
1534
    if (framebuffer == m_framebufferBinding) {
1536
    if (framebuffer == m_framebufferBinding) {
1535
        m_framebufferBinding = 0;
1537
        m_framebufferBinding = 0;
1536
        // Have to call bindFramebuffer here to bind back to internal fbo.
1538
        if (m_drawingBuffer) {
1537
        if (m_drawingBuffer)
1539
            m_drawingBuffer->setFramebufferBinding(0);
1540
            // Have to call bindFramebuffer here to bind back to internal fbo.
1538
            m_drawingBuffer->bind();
1541
            m_drawingBuffer->bind();
1539
        else
1542
        } else
1540
            m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0);
1543
            m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0);
1541
    }
1544
    }
1542
}
1545
}
Lines 4307-4314 void WebGLRenderingContext::loseContextI Source/WebCore/html/canvas/WebGLRenderingContext.cpp_sec3
4307
    detachAndRemoveAllObjects();
4310
    detachAndRemoveAllObjects();
4308
4311
4309
    if (m_drawingBuffer) {
4312
    if (m_drawingBuffer) {
4310
        // Make absolutely sure we do not refer to an already-deleted texture.
4313
        // Make absolutely sure we do not refer to an already-deleted texture or framebuffer.
4311
        m_drawingBuffer->setTexture2DBinding(0);
4314
        m_drawingBuffer->setTexture2DBinding(0);
4315
        m_drawingBuffer->setFramebufferBinding(0);
4312
    }
4316
    }
4313
4317
4314
    // There is no direct way to clear errors from a GL implementation and
4318
    // There is no direct way to clear errors from a GL implementation and
- Source/WebCore/platform/graphics/cairo/DrawingBufferCairo.cpp +1 lines
Lines 43-48 DrawingBuffer::DrawingBuffer(GraphicsCon Source/WebCore/platform/graphics/cairo/DrawingBufferCairo.cpp_sec1
43
    , m_alpha(alpha)
43
    , m_alpha(alpha)
44
    , m_scissorEnabled(false)
44
    , m_scissorEnabled(false)
45
    , m_texture2DBinding(0)
45
    , m_texture2DBinding(0)
46
    , m_framebufferBinding(0)
46
    , m_activeTextureUnit(GraphicsContext3D::TEXTURE0)
47
    , m_activeTextureUnit(GraphicsContext3D::TEXTURE0)
47
    , m_context(context)
48
    , m_context(context)
48
    , m_size(-1, -1)
49
    , m_size(-1, -1)
- Source/WebCore/platform/graphics/chromium/DrawingBufferChromium.cpp +1 lines
Lines 69-74 DrawingBuffer::DrawingBuffer(GraphicsCon Source/WebCore/platform/graphics/chromium/DrawingBufferChromium.cpp_sec1
69
    , m_alpha(alpha)
69
    , m_alpha(alpha)
70
    , m_scissorEnabled(false)
70
    , m_scissorEnabled(false)
71
    , m_texture2DBinding(0)
71
    , m_texture2DBinding(0)
72
    , m_framebufferBinding(0)
72
    , m_activeTextureUnit(GraphicsContext3D::TEXTURE0)
73
    , m_activeTextureUnit(GraphicsContext3D::TEXTURE0)
73
    , m_context(context)
74
    , m_context(context)
74
    , m_size(-1, -1)
75
    , m_size(-1, -1)
- Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp +2 lines
Lines 86-91 void WebGLLayerChromium::update(CCTextur Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp_sec1
86
    m_textureId = m_drawingBuffer->frontColorBuffer();
86
    m_textureId = m_drawingBuffer->frontColorBuffer();
87
    if (m_drawingBuffer->requiresCopyFromBackToFrontBuffer())
87
    if (m_drawingBuffer->requiresCopyFromBackToFrontBuffer())
88
        updater.appendCopy(m_drawingBuffer->colorBuffer(), m_textureId, bounds());
88
        updater.appendCopy(m_drawingBuffer->colorBuffer(), m_textureId, bounds());
89
90
    m_drawingBuffer->restoreFramebufferBinding();
89
}
91
}
90
92
91
void WebGLLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
93
void WebGLLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
- Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp +8 lines
Lines 336-341 void DrawingBuffer::commit(long x, long Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp_sec1
336
    m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
336
    m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
337
}
337
}
338
338
339
void DrawingBuffer::restoreFramebufferBinding()
340
{
341
    if (!m_context || !m_framebufferBinding)
342
        return;
343
344
    m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_framebufferBinding);
345
}
346
339
bool DrawingBuffer::multisample() const
347
bool DrawingBuffer::multisample() const
340
{
348
{
341
    return m_context && m_context->getContextAttributes().antialias && m_multisampleExtensionSupported;
349
    return m_context && m_context->getContextAttributes().antialias && m_multisampleExtensionSupported;
- Source/WebCore/platform/graphics/gpu/DrawingBuffer.h -1 / +9 lines
Lines 99-105 public: Source/WebCore/platform/graphics/gpu/DrawingBuffer.h_sec1
99
99
100
    // The DrawingBuffer needs to track the texture bound to texture unit 0.
100
    // The DrawingBuffer needs to track the texture bound to texture unit 0.
101
    // The bound texture is tracked to avoid costly queries during rendering.
101
    // The bound texture is tracked to avoid costly queries during rendering.
102
    void setTexture2DBinding(GC3Dint texture) { m_texture2DBinding = texture; }
102
    void setTexture2DBinding(Platform3DObject texture) { m_texture2DBinding = texture; }
103
104
    // The DrawingBuffer needs to track the currently bound framebuffer so it
105
    // restore the binding when needed.
106
    void setFramebufferBinding(Platform3DObject fbo) { m_framebufferBinding = fbo; }
107
108
    // Bind to the m_framebufferBinding if it's not 0.
109
    void restoreFramebufferBinding();
103
110
104
    // Track the currently active texture unit. Texture unit 0 is used as host for a scratch
111
    // Track the currently active texture unit. Texture unit 0 is used as host for a scratch
105
    // texture.
112
    // texture.
Lines 135-140 private: Source/WebCore/platform/graphics/gpu/DrawingBuffer.h_sec2
135
    AlphaRequirement m_alpha;
142
    AlphaRequirement m_alpha;
136
    bool m_scissorEnabled;
143
    bool m_scissorEnabled;
137
    Platform3DObject m_texture2DBinding;
144
    Platform3DObject m_texture2DBinding;
145
    Platform3DObject m_framebufferBinding;
138
    GC3Denum m_activeTextureUnit;
146
    GC3Denum m_activeTextureUnit;
139
147
140
    RefPtr<GraphicsContext3D> m_context;
148
    RefPtr<GraphicsContext3D> m_context;
- Source/WebCore/platform/graphics/gpu/mac/DrawingBufferMac.mm +1 lines
Lines 46-51 DrawingBuffer::DrawingBuffer(GraphicsCon Source/WebCore/platform/graphics/gpu/mac/DrawingBufferMac.mm_sec1
46
    , m_alpha(alpha)
46
    , m_alpha(alpha)
47
    , m_scissorEnabled(false)
47
    , m_scissorEnabled(false)
48
    , m_texture2DBinding(0)
48
    , m_texture2DBinding(0)
49
    , m_framebufferBinding(0)
49
    , m_activeTextureUnit(GraphicsContext3D::TEXTURE0)
50
    , m_activeTextureUnit(GraphicsContext3D::TEXTURE0)
50
    , m_context(context)
51
    , m_context(context)
51
    , m_size(-1, -1)
52
    , m_size(-1, -1)
- Source/WebCore/platform/graphics/gpu/qt/DrawingBufferQt.cpp +1 lines
Lines 41-46 DrawingBuffer::DrawingBuffer(GraphicsCon Source/WebCore/platform/graphics/gpu/qt/DrawingBufferQt.cpp_sec1
41
    , m_alpha(alpha)
41
    , m_alpha(alpha)
42
    , m_scissorEnabled(false)
42
    , m_scissorEnabled(false)
43
    , m_texture2DBinding(0)
43
    , m_texture2DBinding(0)
44
    , m_framebufferBinding(0)
44
    , m_activeTextureUnit(GraphicsContext3D::TEXTURE0)
45
    , m_activeTextureUnit(GraphicsContext3D::TEXTURE0)
45
    , m_context(context)
46
    , m_context(context)
46
    , m_size(-1, -1)
47
    , m_size(-1, -1)
- LayoutTests/ChangeLog +13 lines
Lines 1-3 LayoutTests/ChangeLog_sec1
1
2012-04-23  Zhenyao Mo  <zmo@google.com>
2
3
        framebuffer binding should not be changed after canvas resize or compositing
4
        https://bugs.webkit.org/show_bug.cgi?id=84609
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        * fast/canvas/webgl/framebuffer-bindings-unaffected-on-resize-expected.txt: Added.
9
        * fast/canvas/webgl/framebuffer-bindings-unaffected-on-resize.html: Added.
10
        * fast/canvas/webgl/resources/webgl-test-utils.js: Sync with khronos side (partial)
11
        (WebGLTestUtils.):
12
        (WebGLTestUtils):
13
1
2012-04-23  Pierre Rossi  <pierre.rossi@gmail.com>
14
2012-04-23  Pierre Rossi  <pierre.rossi@gmail.com>
2
15
3
        [Qt] Unreviewed gardening.
16
        [Qt] Unreviewed gardening.
- LayoutTests/fast/canvas/webgl/framebuffer-bindings-unaffected-on-resize-expected.txt +26 lines
Line 0 LayoutTests/fast/canvas/webgl/framebuffer-bindings-unaffected-on-resize-expected.txt_sec1
1
Verifies that GL framebuffer bindings do not change when canvas is resized
2
3
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4
5
PASS fboSize < canvas.width is true
6
PASS gl.checkFramebufferStatus(gl.FRAMEBUFFER) is gl.FRAMEBUFFER_COMPLETE
7
test before resizing canvas
8
PASS should be blue
9
PASS area outside fbo should be transparent black
10
PASS should be green
11
PASS area outside fbo should be transparent black
12
test after resizing canvas
13
PASS should be blue
14
PASS area outside fbo should be transparent black
15
PASS should be green
16
PASS area outside fbo should be transparent black
17
test after resizing canvas and waiting for compositing
18
PASS should be blue
19
PASS area outside fbo should be transparent black
20
PASS should be green
21
PASS area outside fbo should be transparent black
22
PASS getError was expected value: NO_ERROR : Should be no errors.
23
PASS successfullyParsed is true
24
25
TEST COMPLETE
26
0
  + LF
27
  + LF
- LayoutTests/fast/canvas/webgl/framebuffer-bindings-unaffected-on-resize.html +83 lines
Line 0 LayoutTests/fast/canvas/webgl/framebuffer-bindings-unaffected-on-resize.html_sec1
1
2
<!DOCTYPE html>
3
<html>
4
<head>
5
<meta charset="utf-8">
6
<title>Verifies that GL framebuffer bindings do not change when canvas is resized</title>
7
<link rel="stylesheet" href="../../js/resources/js-test-style.css"/>
8
<script src="../../js/resources/js-test-pre.js"></script>
9
<script src="resources/webgl-test.js"></script>
10
<script src="resources/webgl-test-utils.js"></script>
11
</head>
12
<body>
13
<canvas id="example" width="4px" height="4px"></canvas>
14
<div id="description"></div>
15
<div id="console"></div>
16
<script>
17
description("Verifies that GL framebuffer bindings do not change when canvas is resized");
18
19
if (window.initNonKhronosFramework) {
20
  window.initNonKhronosFramework(true);
21
}
22
23
var err;
24
var wtu = WebGLTestUtils;
25
var canvas = document.getElementById("example");
26
var gl = wtu.create3DContext(canvas);
27
var green = [0, 255, 0, 255];
28
var blue = [0, 0, 255, 255];
29
var fboSize = 2;
30
shouldBeTrue("fboSize < canvas.width");
31
var fbo = gl.createFramebuffer();
32
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
33
var fboTex = gl.createTexture();
34
gl.activeTexture(gl.TEXTURE1);
35
gl.bindTexture(gl.TEXTURE_2D, fboTex);
36
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fboTex, 0);
37
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, fboSize, fboSize, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
38
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
39
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
40
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
41
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
42
shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
43
44
function checkFBO(color, msg) {
45
  wtu.checkCanvasRect(gl, 0, 0, fboSize, fboSize, color, msg);
46
  wtu.checkCanvasRect(gl, fboSize, fboSize, fboSize, fboSize, [0, 0, 0, 0], "area outside fbo should be transparent black");
47
}
48
49
// The FBO is 2x2 and it's bound so clearing should clear a 2x2 area
50
// and calling read pixels should read the clear color in that 2x2 area
51
// and 0,0,0,0 outside that area.
52
//
53
// If the FBO is no longer bound because of a WebGL implementation error
54
// then likely the clear will clear the backbuffer and reading outside
55
// the 2x2 area will not be 0,0,0,0
56
57
function test() {
58
  gl.clearColor(0, 0, 1, 1);
59
  gl.clear(gl.COLOR_BUFFER_BIT);
60
  checkFBO(blue, "should be blue");
61
  gl.clearColor(0, 1, 0, 1);
62
  gl.clear(gl.COLOR_BUFFER_BIT);
63
  checkFBO(green, "should be green");
64
}
65
66
debug("test before resizing canvas");
67
test();
68
debug("test after resizing canvas");
69
canvas.width = 8;
70
test();
71
debug("test after resizing canvas and waiting for compositing");
72
canvas.width = 16;
73
wtu.waitFrames(5, function() {
74
  test();
75
  finishTest();
76
  glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
77
});
78
79
successfullyParsed = true;
80
</script>
81
</body>
82
</html>
83
0
  + LF
84
  + LF
- LayoutTests/fast/canvas/webgl/resources/webgl-test-utils.js +61 lines
Lines 1104-1110 var getUrlArguments = function() { LayoutTests/fast/canvas/webgl/resources/webgl-test-utils.js_sec1
1104
  return args;
1104
  return args;
1105
};
1105
};
1106
1106
1107
/**
1108
 * Provides requestAnimationFrame in a cross browser way.
1109
 */
1110
var requestAnimFrameImpl_;
1111
1112
var requestAnimFrame = function(callback, element) {
1113
  if (!requestAnimFrameImpl_) {
1114
    requestAnimFrameImpl_ = function() {
1115
      var functionNames = [
1116
        "requestAnimationFrame",
1117
        "webkitRequestAnimationFrame",
1118
        "mozRequestAnimationFrame",
1119
        "oRequestAnimationFrame",
1120
        "msRequestAnimationFrame"
1121
      ];
1122
      for (var jj = 0; jj < functionNames.length; ++jj) {
1123
        var functionName = functionNames[jj];
1124
        if (window[functionName]) {
1125
          return function(name) {
1126
            return function(callback, element) {
1127
              return window[name].call(window, callback, element);
1128
            };
1129
          }(functionName);
1130
        }
1131
      }
1132
      return function(callback, element) {
1133
           return window.setTimeout(callback, 1000 / 70);
1134
        };
1135
    }();
1136
  }
1137
1138
  return requestAnimFrameImpl_(callback, element);
1139
};
1140
1141
/**
1142
 * Provides cancelRequestAnimationFrame in a cross browser way.
1143
 */
1144
var cancelRequestAnimFrame = (function() {
1145
  return window.cancelCancelRequestAnimationFrame ||
1146
         window.webkitCancelRequestAnimationFrame ||
1147
         window.mozCancelRequestAnimationFrame ||
1148
         window.oCancelRequestAnimationFrame ||
1149
         window.msCancelRequestAnimationFrame ||
1150
         window.clearTimeout;
1151
})();
1152
1153
var waitFrames = function(frames, callback) {
1154
  var countDown = function() {
1155
    if (frames == 0) {
1156
      callback();
1157
    } else {
1158
      --frames;
1159
      requestAnimFrame(countDown);
1160
    }
1161
  };
1162
  countDown();
1163
};
1164
1107
return {
1165
return {
1166
  cancelRequestAnimFrame: cancelRequestAnimFrame,
1108
  create3DContext: create3DContext,
1167
  create3DContext: create3DContext,
1109
  create3DContextWithWrapperThatThrowsOnGLError:
1168
  create3DContextWithWrapperThatThrowsOnGLError:
1110
    create3DContextWithWrapperThatThrowsOnGLError,
1169
    create3DContextWithWrapperThatThrowsOnGLError,
Lines 1147-1152 return { LayoutTests/fast/canvas/webgl/resources/webgl-test-utils.js_sec2
1147
  shouldGenerateGLError: shouldGenerateGLError,
1206
  shouldGenerateGLError: shouldGenerateGLError,
1148
  readFile: readFile,
1207
  readFile: readFile,
1149
  readFileList: readFileList,
1208
  readFileList: readFileList,
1209
  requestAnimFrame: requestAnimFrame,
1210
  waitFrames: waitFrames,
1150
1211
1151
  none: false
1212
  none: false
1152
};
1213
};

Return to Bug 84609