Changeset 84163 in webkit


Ignore:
Timestamp:
Apr 18, 2011 11:16:12 AM (13 years ago)
Author:
senorblanco@chromium.org
Message:

2011-04-15 Stephen White <senorblanco@chromium.org>

Reviewed by Kenneth Russell.

Speed up DrawingBuffer::reset().
https://bugs.webkit.org/show_bug.cgi?id=58706

When DrawingBuffer::reset() is called, it should not reallocate
the FBOs if the size has not changed. It should just do a glClear().

Covered by tests in fast/canvas and canvas/philip.

  • platform/graphics/chromium/DrawingBufferChromium.cpp: (WebCore::DrawingBuffer::DrawingBuffer): Initialize the size to -1, -1, so the size change check will work on first reset.
  • platform/graphics/gpu/DrawingBuffer.cpp: (WebCore::DrawingBuffer::reset): If the size hasn't changed, don't resize the FBOs. Just clear the relevant buffers.
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r84161 r84163  
     12011-04-15  Stephen White  <senorblanco@chromium.org>
     2
     3        Reviewed by Kenneth Russell.
     4
     5        Speed up DrawingBuffer::reset().
     6        https://bugs.webkit.org/show_bug.cgi?id=58706
     7
     8        When DrawingBuffer::reset() is called, it should not reallocate
     9        the FBOs if the size has not changed.  It should just do a glClear().
     10
     11        Covered by tests in fast/canvas and canvas/philip.
     12
     13        * platform/graphics/chromium/DrawingBufferChromium.cpp:
     14        (WebCore::DrawingBuffer::DrawingBuffer):
     15        Initialize the size to -1, -1, so the size change check will work on
     16        first reset.
     17        * platform/graphics/gpu/DrawingBuffer.cpp:
     18        (WebCore::DrawingBuffer::reset):
     19        If the size hasn't changed, don't resize the FBOs.  Just clear the
     20        relevant buffers.
     21
    1222011-04-18  Pavel Feldman  <pfeldman@google.com>
    223
  • trunk/Source/WebCore/platform/graphics/chromium/DrawingBufferChromium.cpp

    r83733 r84163  
    7777                             bool packedDepthStencilExtensionSupported)
    7878    : m_context(context)
    79     , m_size(size)
     79    , m_size(-1, -1)
    8080    , m_multisampleExtensionSupported(multisampleExtensionSupported)
    8181    , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupported)
  • trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp

    r83355 r84163  
    159159    }
    160160
    161     m_size = newSize;
    162 
    163161    const GraphicsContext3D::Attributes& attributes = m_context->getContextAttributes();
    164     unsigned long internalColorFormat, colorFormat, internalRenderbufferFormat;
    165     if (attributes.alpha) {
    166         internalColorFormat = GraphicsContext3D::RGBA;
    167         colorFormat = GraphicsContext3D::RGBA;
    168         internalRenderbufferFormat = Extensions3D::RGBA8_OES;
    169     } else {
    170         internalColorFormat = GraphicsContext3D::RGB;
    171         colorFormat = GraphicsContext3D::RGB;
    172         internalRenderbufferFormat = Extensions3D::RGB8_OES;
    173     }
    174 
    175 
    176     // resize multisample FBO
    177     if (multisample()) {
    178         int maxSampleCount = 0;
    179        
    180         m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCount);
    181         int sampleCount = std::min(8, maxSampleCount);
    182 
    183         m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
    184 
    185         m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
    186         m_context->getExtensions()->renderbufferStorageMultisample(GraphicsContext3D::RENDERBUFFER, sampleCount, internalRenderbufferFormat, m_size.width(), m_size.height());
    187         m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
    188         resizeDepthStencil(sampleCount);
     162
     163    if (newSize != m_size) {
     164        m_size = newSize;
     165
     166        unsigned long internalColorFormat, colorFormat, internalRenderbufferFormat;
     167        if (attributes.alpha) {
     168            internalColorFormat = GraphicsContext3D::RGBA;
     169            colorFormat = GraphicsContext3D::RGBA;
     170            internalRenderbufferFormat = Extensions3D::RGBA8_OES;
     171        } else {
     172            internalColorFormat = GraphicsContext3D::RGB;
     173            colorFormat = GraphicsContext3D::RGB;
     174            internalRenderbufferFormat = Extensions3D::RGB8_OES;
     175        }
     176
     177
     178        // resize multisample FBO
     179        if (multisample()) {
     180            int maxSampleCount = 0;
     181           
     182            m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCount);
     183            int sampleCount = std::min(8, maxSampleCount);
     184
     185            m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
     186
     187            m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
     188            m_context->getExtensions()->renderbufferStorageMultisample(GraphicsContext3D::RENDERBUFFER, sampleCount, internalRenderbufferFormat, m_size.width(), m_size.height());
     189            m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer);
     190            resizeDepthStencil(sampleCount);
     191            if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
     192                // Cleanup
     193                clear();
     194                return false;
     195            }
     196        }
     197
     198        // resize regular FBO
     199        m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
     200
     201        m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer);
     202       
     203        m_context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE);
     204
     205        m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0);
     206        m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0);
     207
     208        if (!multisample())
     209            resizeDepthStencil(0);
    189210        if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
    190211            // Cleanup
     
    194215    }
    195216
    196     // resize regular FBO
    197     m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
    198 
    199     m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer);
    200    
    201     m_context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE);
    202 
    203     m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0);
    204     m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0);
    205 
    206     if (!multisample())
    207         resizeDepthStencil(0);
    208     if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
    209         // Cleanup
    210         clear();
    211         return false;
    212     }
    213 
    214     if (multisample())
    215         m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO);
    216 
    217     if (!m_context->getExtensions()->supports("GL_CHROMIUM_resource_safe")) {
    218         // Initialize renderbuffers (depth/stencil).
    219         float clearDepth = 0;
    220         int clearStencil = 0;
    221         unsigned char depthMask = true;
    222         unsigned int stencilMask = 0xffffffff;
    223         unsigned char isScissorEnabled = false;
    224         unsigned long clearMask = 0;
    225         if (attributes.depth) {
    226             m_context->getFloatv(GraphicsContext3D::DEPTH_CLEAR_VALUE, &clearDepth);
    227             m_context->clearDepth(1);
    228             m_context->getBooleanv(GraphicsContext3D::DEPTH_WRITEMASK, &depthMask);
    229             m_context->depthMask(true);
    230             clearMask |= GraphicsContext3D::DEPTH_BUFFER_BIT;
    231         }
    232         if (attributes.stencil) {
    233             m_context->getIntegerv(GraphicsContext3D::STENCIL_CLEAR_VALUE, &clearStencil);
    234             m_context->clearStencil(0);
    235             m_context->getIntegerv(GraphicsContext3D::STENCIL_WRITEMASK, reinterpret_cast<int*>(&stencilMask));
    236             m_context->stencilMaskSeparate(GraphicsContext3D::FRONT, 0xffffffff);
    237             clearMask |= GraphicsContext3D::STENCIL_BUFFER_BIT;
    238         }
    239         if (clearMask) {
    240             isScissorEnabled = m_context->isEnabled(GraphicsContext3D::SCISSOR_TEST);
    241             m_context->disable(GraphicsContext3D::SCISSOR_TEST);
    242 
    243             m_context->clear(clearMask);
    244 
    245             if (attributes.depth) {
    246                 m_context->clearDepth(clearDepth);
    247                 m_context->depthMask(depthMask);
    248             }
    249             if (attributes.stencil) {
    250                 m_context->clearStencil(clearStencil);
    251                 m_context->stencilMaskSeparate(GraphicsContext3D::FRONT, stencilMask);
    252             }
    253             if (isScissorEnabled)
    254                 m_context->enable(GraphicsContext3D::SCISSOR_TEST);
    255             else
    256                 m_context->disable(GraphicsContext3D::SCISSOR_TEST);
    257         }
    258     }
    259 
    260     m_context->flush();
    261    
     217    m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO ? m_multisampleFBO : m_fbo);
     218
     219    // Initialize renderbuffers (depth/stencil).
     220    float clearDepth = 0;
     221    int clearStencil = 0;
     222    unsigned char depthMask = true;
     223    unsigned int stencilMask = 0xffffffff;
     224    unsigned char isScissorEnabled = false;
     225    unsigned long clearMask = GraphicsContext3D::COLOR_BUFFER_BIT;
     226    if (attributes.depth) {
     227        m_context->getFloatv(GraphicsContext3D::DEPTH_CLEAR_VALUE, &clearDepth);
     228        m_context->clearDepth(1);
     229        m_context->getBooleanv(GraphicsContext3D::DEPTH_WRITEMASK, &depthMask);
     230        m_context->depthMask(true);
     231        clearMask |= GraphicsContext3D::DEPTH_BUFFER_BIT;
     232    }
     233    if (attributes.stencil) {
     234        m_context->getIntegerv(GraphicsContext3D::STENCIL_CLEAR_VALUE, &clearStencil);
     235        m_context->clearStencil(0);
     236        m_context->getIntegerv(GraphicsContext3D::STENCIL_WRITEMASK, reinterpret_cast<int*>(&stencilMask));
     237        m_context->stencilMaskSeparate(GraphicsContext3D::FRONT, 0xffffffff);
     238        clearMask |= GraphicsContext3D::STENCIL_BUFFER_BIT;
     239    }
     240    isScissorEnabled = m_context->isEnabled(GraphicsContext3D::SCISSOR_TEST);
     241    m_context->disable(GraphicsContext3D::SCISSOR_TEST);
     242
     243    float clearColor[4];
     244    m_context->getFloatv(GraphicsContext3D::COLOR_CLEAR_VALUE, clearColor);
     245    m_context->clearColor(0, 0, 0, 0);
     246    m_context->clear(clearMask);
     247    m_context->clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
     248
     249    if (attributes.depth) {
     250        m_context->clearDepth(clearDepth);
     251        m_context->depthMask(depthMask);
     252    }
     253    if (attributes.stencil) {
     254        m_context->clearStencil(clearStencil);
     255        m_context->stencilMaskSeparate(GraphicsContext3D::FRONT, stencilMask);
     256    }
     257    if (isScissorEnabled)
     258        m_context->enable(GraphicsContext3D::SCISSOR_TEST);
     259    else
     260        m_context->disable(GraphicsContext3D::SCISSOR_TEST);
     261
    262262    didReset();
    263263
Note: See TracChangeset for help on using the changeset viewer.