Title: [106376] trunk
Revision
106376
Author
[email protected]
Date
2012-01-31 12:00:09 -0800 (Tue, 31 Jan 2012)

Log Message

WebGL must allocate smaller drawing buffer when the allocation fails.
https://bugs.webkit.org/show_bug.cgi?id=76654

Patch by Yongsheng Zhu <[email protected]> on 2012-01-31
Reviewed by Kenneth Russell.

Test: fast/canvas/webgl/drawingbuffer-test.html

* platform/graphics/gpu/DrawingBuffer.cpp:
(WebCore):
(WebCore::DrawingBuffer::create):
(WebCore::DrawingBuffer::reset):

Modified Paths

Diff

Modified: trunk/LayoutTests/platform/chromium/test_expectations.txt (106375 => 106376)


--- trunk/LayoutTests/platform/chromium/test_expectations.txt	2012-01-31 19:58:07 UTC (rev 106375)
+++ trunk/LayoutTests/platform/chromium/test_expectations.txt	2012-01-31 20:00:09 UTC (rev 106376)
@@ -3831,8 +3831,6 @@
 
 BUGWK76580 : media/media-document-audio-repaint.html = IMAGE PASS
 
-BUGWK76562 : fast/canvas/webgl/drawingbuffer-test.html = TEXT
-
 // This test is passing, but it doesn't seem possible to add GPU+Leopard specific baselines.
 BUGJAMESR LEOPARD GPU : fast/canvas/quadraticCurveTo.xml = IMAGE
 

Modified: trunk/Source/WebCore/ChangeLog (106375 => 106376)


--- trunk/Source/WebCore/ChangeLog	2012-01-31 19:58:07 UTC (rev 106375)
+++ trunk/Source/WebCore/ChangeLog	2012-01-31 20:00:09 UTC (rev 106376)
@@ -1,3 +1,17 @@
+2012-01-31  Yongsheng Zhu  <[email protected]>
+
+        WebGL must allocate smaller drawing buffer when the allocation fails. 
+        https://bugs.webkit.org/show_bug.cgi?id=76654
+
+        Reviewed by Kenneth Russell.
+
+        Test: fast/canvas/webgl/drawingbuffer-test.html
+
+        * platform/graphics/gpu/DrawingBuffer.cpp:
+        (WebCore):
+        (WebCore::DrawingBuffer::create):
+        (WebCore::DrawingBuffer::reset):
+
 2012-01-25  Eric Seidel  <[email protected]>
 
         HTMLIsIndexElement should not expose HTMLInputElement properties

Modified: trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp (106375 => 106376)


--- trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp	2012-01-31 19:58:07 UTC (rev 106375)
+++ trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp	2012-01-31 20:00:09 UTC (rev 106376)
@@ -49,6 +49,7 @@
 static int s_maximumResourceUsePixels = 0;
 #endif
 static int s_currentResourceUsePixels = 0;
+static const float s_resourceAdjustedRatio = 0.5;
 
 PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, const IntSize& size, bool separateBackingTexture)
 {
@@ -236,19 +237,28 @@
     }
 
     int pixelDelta = newSize.width() * newSize.height();
-    if (!m_size.isEmpty())
-        pixelDelta -= m_size.width() * m_size.height();
+    int oldSize = 0;
+    if (!m_size.isEmpty()) {
+        oldSize = m_size.width() * m_size.height();
+        pixelDelta -= oldSize;
+    }
 
-    if (s_maximumResourceUsePixels && (s_currentResourceUsePixels + pixelDelta) > s_maximumResourceUsePixels) {
-        clear();
-        return false;
+    IntSize adjustedSize = newSize;
+    if (s_maximumResourceUsePixels) {
+        while ((s_currentResourceUsePixels + pixelDelta) > s_maximumResourceUsePixels) {
+            adjustedSize.scale(s_resourceAdjustedRatio);
+            if (adjustedSize.isEmpty()) {
+                clear();
+                return false;
+            }
+            pixelDelta = adjustedSize.width() * adjustedSize.height();
+            pixelDelta -= oldSize;
+        }
     }
-    s_currentResourceUsePixels += pixelDelta;
 
     const GraphicsContext3D::Attributes& attributes = m_context->getContextAttributes();
 
-    if (newSize != m_size) {
-        m_size = newSize;
+    if (adjustedSize != m_size) {
 
         unsigned internalColorFormat, colorFormat, internalRenderbufferFormat;
         if (attributes.alpha) {
@@ -261,47 +271,57 @@
             internalRenderbufferFormat = Extensions3D::RGB8_OES;
         }
 
+        do {
+            m_size = adjustedSize;
 
-        // resize multisample FBO
-        if (multisample()) {
-            int maxSampleCount = 0;
-            
-            m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCount);
-            int sampleCount = std::min(4, maxSampleCount);
+            // resize multisample FBO
+            if (multisample()) {
+                int maxSampleCount = 0;
 
-            m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
+                m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCount);
+                int sampleCount = std::min(4, maxSampleCount);
 
-            m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
-            m_context->getExtensions()->renderbufferStorageMultisample(GraphicsContext3D::RENDERBUFFER, sampleCount, internalRenderbufferFormat, m_size.width(), m_size.height());
-            m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
-            resizeDepthStencil(sampleCount);
-            if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
-                // Cleanup
-                clear();
-                return false;
+                m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
+
+                m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
+                m_context->getExtensions()->renderbufferStorageMultisample(GraphicsContext3D::RENDERBUFFER, sampleCount, internalRenderbufferFormat, m_size.width(), m_size.height());
+                m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
+                resizeDepthStencil(sampleCount);
+                if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
+                    adjustedSize.scale(s_resourceAdjustedRatio);
+                    continue;
+                }
             }
-        }
 
-        // resize regular FBO
-        m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
+            // resize regular FBO
+            m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
 
-        m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer);
-        m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0);
+            m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer);
+            m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0);
 
-        m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0);
+            m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0);
 
-        // resize the backing color buffer
-        if (m_separateBackingTexture) {
-            m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_backingColorBuffer);
-            m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0);
-        }
+            // resize the backing color buffer
+            if (m_separateBackingTexture) {
+                m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_backingColorBuffer);
+                m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0);
+            }
 
-        m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0);
+            m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0);
 
-        if (!multisample())
-            resizeDepthStencil(0);
-        if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
-            // Cleanup
+            if (!multisample())
+                resizeDepthStencil(0);
+            if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) == GraphicsContext3D::FRAMEBUFFER_COMPLETE)
+                break;
+            adjustedSize.scale(s_resourceAdjustedRatio);
+
+        } while (!adjustedSize.isEmpty());
+
+        pixelDelta = m_size.width() * m_size.height();
+        pixelDelta -= oldSize;
+        s_currentResourceUsePixels += pixelDelta;
+
+        if (adjustedSize.isEmpty()) {
             clear();
             return false;
         }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to