Changeset 106888 in webkit


Ignore:
Timestamp:
Feb 6, 2012 5:58:16 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

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

Patch by Yongsheng Zhu <yongsheng.zhu@intel.com> on 2012-02-06
Reviewed by Kenneth Russell.

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

  • platform/graphics/gpu/DrawingBuffer.cpp:

(WebCore):
(WebCore::DrawingBuffer::create):
(WebCore::DrawingBuffer::reset):

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/platform/chromium/test_expectations.txt

    r106864 r106888  
    37863786BUGWK76580 : media/media-document-audio-repaint.html = IMAGE PASS
    37873787
    3788 BUGWK76562 : fast/canvas/webgl/drawingbuffer-test.html = TEXT
    3789 
    37903788// This test is passing, but it doesn't seem possible to add GPU+Leopard specific baselines.
    37913789BUGJAMESR LEOPARD GPU : fast/canvas/quadraticCurveTo.xml = IMAGE
  • trunk/Source/WebCore/ChangeLog

    r106885 r106888  
     12012-02-06  Yongsheng Zhu  <yongsheng.zhu@intel.com>
     2
     3        WebGL must allocate smaller drawing buffer when the allocation fails.
     4        https://bugs.webkit.org/show_bug.cgi?id=76654
     5
     6        Reviewed by Kenneth Russell.
     7
     8        Test: fast/canvas/webgl/drawingbuffer-test.html
     9
     10        * platform/graphics/gpu/DrawingBuffer.cpp:
     11        (WebCore):
     12        (WebCore::DrawingBuffer::create):
     13        (WebCore::DrawingBuffer::reset):
     14
    1152012-02-06  Kentaro Hara  <haraken@chromium.org>
    216
  • trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp

    r106400 r106888  
    5050#endif
    5151static int s_currentResourceUsePixels = 0;
     52static const float s_resourceAdjustedRatio = 0.5;
    5253
    5354PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, const IntSize& size, bool separateBackingTexture)
     
    237238
    238239    int pixelDelta = newSize.width() * newSize.height();
    239     if (!m_size.isEmpty())
    240         pixelDelta -= m_size.width() * m_size.height();
    241 
    242     if (s_maximumResourceUsePixels && (s_currentResourceUsePixels + pixelDelta) > s_maximumResourceUsePixels) {
    243         clear();
    244         return false;
    245     }
    246     s_currentResourceUsePixels += pixelDelta;
     240    int oldSize = 0;
     241    if (!m_size.isEmpty()) {
     242        oldSize = m_size.width() * m_size.height();
     243        pixelDelta -= oldSize;
     244    }
     245
     246    IntSize adjustedSize = newSize;
     247    if (s_maximumResourceUsePixels) {
     248        while ((s_currentResourceUsePixels + pixelDelta) > s_maximumResourceUsePixels) {
     249            adjustedSize.scale(s_resourceAdjustedRatio);
     250            if (adjustedSize.isEmpty()) {
     251                clear();
     252                return false;
     253            }
     254            pixelDelta = adjustedSize.width() * adjustedSize.height();
     255            pixelDelta -= oldSize;
     256        }
     257     }
    247258
    248259    const GraphicsContext3D::Attributes& attributes = m_context->getContextAttributes();
    249260
    250     if (newSize != m_size) {
    251         m_size = newSize;
     261    if (adjustedSize != m_size) {
    252262
    253263        unsigned internalColorFormat, colorFormat, internalRenderbufferFormat;
     
    263273
    264274
    265         // resize multisample FBO
    266         if (multisample()) {
    267             int maxSampleCount = 0;
    268            
    269             m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCount);
    270             int sampleCount = std::min(4, maxSampleCount);
    271 
    272             m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
    273 
    274             m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
    275             m_context->getExtensions()->renderbufferStorageMultisample(GraphicsContext3D::RENDERBUFFER, sampleCount, internalRenderbufferFormat, m_size.width(), m_size.height());
    276             m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
    277             resizeDepthStencil(sampleCount);
    278             if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
    279                 // Cleanup
    280                 clear();
    281                 return false;
     275        do {
     276            m_size = adjustedSize;
     277            // resize multisample FBO
     278            if (multisample()) {
     279                int maxSampleCount = 0;
     280
     281                m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCount);
     282                int sampleCount = std::min(4, maxSampleCount);
     283
     284                m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
     285
     286                m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
     287                m_context->getExtensions()->renderbufferStorageMultisample(GraphicsContext3D::RENDERBUFFER, sampleCount, internalRenderbufferFormat, m_size.width(), m_size.height());
     288                m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
     289                resizeDepthStencil(sampleCount);
     290                if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
     291                    adjustedSize.scale(s_resourceAdjustedRatio);
     292                    continue;
     293                }
    282294            }
    283         }
    284 
    285         // resize regular FBO
    286         m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
    287 
    288         m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer);
    289         m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0);
    290 
    291         m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0);
    292 
    293         // resize the backing color buffer
    294         if (m_separateBackingTexture) {
    295             m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_backingColorBuffer);
     295
     296            // resize regular FBO
     297            m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
     298
     299            m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer);
    296300            m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0);
    297         }
    298 
    299         m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0);
    300 
    301         if (!multisample())
    302             resizeDepthStencil(0);
    303         if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
    304             // Cleanup
     301
     302            m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0);
     303
     304            // resize the backing color buffer
     305            if (m_separateBackingTexture) {
     306                m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_backingColorBuffer);
     307                m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0);
     308            }
     309
     310            m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0);
     311
     312            if (!multisample())
     313                resizeDepthStencil(0);
     314            if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) == GraphicsContext3D::FRAMEBUFFER_COMPLETE)
     315                break;
     316            adjustedSize.scale(s_resourceAdjustedRatio);
     317
     318        } while (!adjustedSize.isEmpty());
     319
     320        pixelDelta = m_size.width() * m_size.height();
     321        pixelDelta -= oldSize;
     322        s_currentResourceUsePixels += pixelDelta;
     323
     324        if (!newSize.isEmpty() && adjustedSize.isEmpty()) {
    305325            clear();
    306326            return false;
Note: See TracChangeset for help on using the changeset viewer.