Patch removing duplicated code in the setup of the DrawingBuffer used
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 Nov 2011 20:21:09 +0000 (20:21 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 Nov 2011 20:21:09 +0000 (20:21 +0000)
to host the back-buffer for WebGL contents.
https://bugs.webkit.org/show_bug.cgi?id=72327

Patch by Jeff Timanus <twiz@chromium.org> on 2011-11-15
Reviewed by Julien Chaffraix.

* html/canvas/WebGLRenderingContext.cpp:
(WebCore::WebGLRenderingContext::copyTexImage2D):
(WebCore::WebGLRenderingContext::copyTexSubImage2D):
(WebCore::WebGLRenderingContext::readPixels):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@100308 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/html/canvas/WebGLRenderingContext.cpp

index 55839e273ec53efc74229ef43f74885dc7f1de77..15d65d14377ae82e4c0f3b6a025a3cbda0e5960f 100644 (file)
@@ -1,3 +1,16 @@
+2011-11-15  Jeff Timanus  <twiz@chromium.org>
+
+        Patch removing duplicated code in the setup of the DrawingBuffer used
+        to host the back-buffer for WebGL contents.
+        https://bugs.webkit.org/show_bug.cgi?id=72327
+
+        Reviewed by Julien Chaffraix.
+
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore::WebGLRenderingContext::copyTexImage2D):
+        (WebCore::WebGLRenderingContext::copyTexSubImage2D):
+        (WebCore::WebGLRenderingContext::readPixels):
+
 2011-11-15  Eugene Nalimov  <enal@google.com>
 
         Event listener for active DOM object that is also DOM node can be garbage collected prematurely.
index 8a4de93dfa5eb25d2dc197ba1cf6dde1fcb151f7..4bb8f1492fe739fee3e8795bfd65d0f55a6b788d 100644 (file)
@@ -82,6 +82,29 @@ const double secondsBetweenRestoreAttempts = 1.0;
 
 namespace {
 
+    class ScopedDrawingBufferBinder {
+    public:
+        ScopedDrawingBufferBinder(DrawingBuffer* drawingBuffer, WebGLFramebuffer* framebufferBinding)
+            : m_drawingBuffer(drawingBuffer)
+            , m_framebufferBinding(framebufferBinding)
+        {
+            // Commit DrawingBuffer if needed (e.g., for multisampling)
+            if (!m_framebufferBinding && m_drawingBuffer)
+                m_drawingBuffer->commit();
+        }
+
+        ~ScopedDrawingBufferBinder()
+        {
+            // Restore DrawingBuffer if needed
+            if (!m_framebufferBinding && m_drawingBuffer)
+                m_drawingBuffer->bind();
+        }
+
+    private:
+        DrawingBuffer* m_drawingBuffer;
+        WebGLFramebuffer* m_framebufferBinding;
+    };
+
     Platform3DObject objectOrZero(WebGLObject* object)
     {
         return object ? object->object() : 0;
@@ -1164,20 +1187,10 @@ void WebGLRenderingContext::copyTexImage2D(GC3Denum target, GC3Dint level, GC3De
     }
     clearIfComposited();
     if (isResourceSafe()) {
-        // Commit DrawingBuffer if needed (e.g., for multisampling)
-        if (!m_framebufferBinding && m_drawingBuffer)
-            m_drawingBuffer->commit();
-
+        ScopedDrawingBufferBinder(m_drawingBuffer.get(), m_framebufferBinding.get());
         m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border);
-
-        // Restore DrawingBuffer if needed
-        if (!m_framebufferBinding && m_drawingBuffer)
-            m_drawingBuffer->bind();
     } else {
-        // Commit DrawingBuffer if needed (e.g., for multisampling)
-        if (!m_framebufferBinding && m_drawingBuffer)
-            m_drawingBuffer->commit();
-
+        ScopedDrawingBufferBinder(m_drawingBuffer.get(), m_framebufferBinding.get());
         GC3Dint clippedX, clippedY;
         GC3Dsizei clippedWidth, clippedHeight;
         if (clip2D(x, y, width, height, getBoundFramebufferWidth(), getBoundFramebufferHeight(), &clippedX, &clippedY, &clippedWidth, &clippedHeight)) {
@@ -1189,10 +1202,6 @@ void WebGLRenderingContext::copyTexImage2D(GC3Denum target, GC3Dint level, GC3De
             }
         } else
             m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border);
-
-        // Restore DrawingBuffer if needed
-        if (!m_framebufferBinding && m_drawingBuffer)
-            m_drawingBuffer->bind();
     }
     // FIXME: if the framebuffer is not complete, none of the below should be executed.
     tex->setLevelInfo(target, level, internalformat, width, height, GraphicsContext3D::UNSIGNED_BYTE);
@@ -1223,17 +1232,10 @@ void WebGLRenderingContext::copyTexSubImage2D(GC3Denum target, GC3Dint level, GC
         return;
     }
     clearIfComposited();
-    if (isResourceSafe())
-        // Commit DrawingBuffer if needed (e.g., for multisampling)
-        if (!m_framebufferBinding && m_drawingBuffer)
-            m_drawingBuffer->commit();
-
+    if (isResourceSafe()) {
+        ScopedDrawingBufferBinder(m_drawingBuffer.get(), m_framebufferBinding.get());
         m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
-
-        // Restore DrawingBuffer if needed
-        if (!m_framebufferBinding && m_drawingBuffer)
-            m_drawingBuffer->bind();
-    else {
+    } else {
         GC3Dint clippedX, clippedY;
         GC3Dsizei clippedWidth, clippedHeight;
         if (clip2D(x, y, width, height, getBoundFramebufferWidth(), getBoundFramebufferHeight(), &clippedX, &clippedY, &clippedWidth, &clippedHeight)) {
@@ -1256,27 +1258,13 @@ void WebGLRenderingContext::copyTexSubImage2D(GC3Denum target, GC3Dint level, GC
             }
             m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, zero.get());
             if (clippedWidth > 0 && clippedHeight > 0) {
-                // Commit DrawingBuffer if needed (e.g., for multisampling)
-                if (!m_framebufferBinding && m_drawingBuffer)
-                    m_drawingBuffer->commit();
-
+                ScopedDrawingBufferBinder(m_drawingBuffer.get(), m_framebufferBinding.get());
                 m_context->copyTexSubImage2D(target, level, xoffset + clippedX - x, yoffset + clippedY - y,
                                              clippedX, clippedY, clippedWidth, clippedHeight);
-
-               // Restore DrawingBuffer if needed
-               if (!m_framebufferBinding && m_drawingBuffer)
-                  m_drawingBuffer->bind();
             }
         } else {
-            // Commit DrawingBuffer if needed (e.g., for multisampling)
-            if (!m_framebufferBinding && m_drawingBuffer)
-                m_drawingBuffer->commit();
-
+            ScopedDrawingBufferBinder(m_drawingBuffer.get(), m_framebufferBinding.get());
             m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
-
-            // Restore DrawingBuffer if needed
-            if (!m_framebufferBinding && m_drawingBuffer)
-                m_drawingBuffer->bind();
         }
     }
     cleanupAfterGraphicsCall(false);
@@ -3041,15 +3029,10 @@ void WebGLRenderingContext::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC
     clearIfComposited();
     void* data = pixels->baseAddress();
 
-    // Commit DrawingBuffer if needed (e.g., for multisampling)
-    if (!m_framebufferBinding && m_drawingBuffer)
-        m_drawingBuffer->commit();
-
-    m_context->readPixels(x, y, width, height, format, type, data);
-
-    // Restore DrawingBuffer if needed
-    if (!m_framebufferBinding && m_drawingBuffer)
-        m_drawingBuffer->bind();
+    {
+        ScopedDrawingBufferBinder(m_drawingBuffer.get(), m_framebufferBinding.get());
+        m_context->readPixels(x, y, width, height, format, type, data);
+    }
 
 #if OS(DARWIN)
     // FIXME: remove this section when GL driver bug on Mac is fixed, i.e.,