Changeset 70010 in webkit


Ignore:
Timestamp:
Oct 18, 2010 4:53:10 PM (14 years ago)
Author:
vangelis@chromium.org
Message:

2010-10-18 Vangelis Kokkevis <vangelis@chromium.org>

Reviewed by James Robinson.

[chromium] Prevent the creation of very large textures for layers by switching
to "large layer" mode when a texture is larger than some fixed reasonable size
(set to 2000 pixels for now).
https://bugs.webkit.org/show_bug.cgi?id=47751

The code also changes the large layer logic to use the current scissor rect used
by the compositor instead of the visible rect to determine how to clip large layers.
This will provide additional texture savings. In addition, the various layer rects
have been converted to use integers instead of floats to preserve uniformity in the code.


Tests: Existing large layer layout tests including huge-layer and huge-layer-img

  • platform/graphics/chromium/ContentLayerChromium.cpp: (WebCore::ContentLayerChromium::requiresClippedUpdateRect): (WebCore::ContentLayerChromium::calculateClippedUpdateRect):
  • platform/graphics/chromium/LayerChromium.cpp: (WebCore::LayerChromium::getDrawRect):
  • platform/graphics/chromium/LayerChromium.h:
  • platform/graphics/chromium/LayerRendererChromium.cpp: (WebCore::LayerRendererChromium::drawLayers): (WebCore::LayerRendererChromium::drawLayersRecursive): (WebCore::LayerRendererChromium::scissorToRect):
  • platform/graphics/chromium/LayerRendererChromium.h: (WebCore::LayerRendererChromium::currentScissorRect):
Location:
trunk/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r70003 r70010  
     12010-10-18  Vangelis Kokkevis  <vangelis@chromium.org>
     2
     3        Reviewed by James Robinson.
     4
     5        [chromium] Prevent the creation of very large textures for layers by switching
     6        to "large layer" mode when a texture is larger than some fixed reasonable size
     7        (set to 2000 pixels for now).
     8        https://bugs.webkit.org/show_bug.cgi?id=47751
     9
     10        The code also changes the large layer logic to use the current scissor rect used
     11        by the compositor instead of the visible rect to determine how to clip large layers.
     12        This will provide additional texture savings. In addition, the various layer rects
     13        have been converted to use integers instead of floats to preserve uniformity in the code.
     14       
     15        Tests: Existing large layer layout tests including huge-layer and huge-layer-img
     16
     17        * platform/graphics/chromium/ContentLayerChromium.cpp:
     18        (WebCore::ContentLayerChromium::requiresClippedUpdateRect):
     19        (WebCore::ContentLayerChromium::calculateClippedUpdateRect):
     20        * platform/graphics/chromium/LayerChromium.cpp:
     21        (WebCore::LayerChromium::getDrawRect):
     22        * platform/graphics/chromium/LayerChromium.h:
     23        * platform/graphics/chromium/LayerRendererChromium.cpp:
     24        (WebCore::LayerRendererChromium::drawLayers):
     25        (WebCore::LayerRendererChromium::drawLayersRecursive):
     26        (WebCore::LayerRendererChromium::scissorToRect):
     27        * platform/graphics/chromium/LayerRendererChromium.h:
     28        (WebCore::LayerRendererChromium::currentScissorRect):
     29
    1302010-10-18  Jia Pu  <jpu@apple.com>
    231
  • trunk/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp

    r69747 r70010  
    144144bool ContentLayerChromium::requiresClippedUpdateRect() const
    145145{
    146     return !layerRenderer()->checkTextureSize(m_bounds);
     146    // To avoid allocating excessively large textures, switch into "large layer mode" if
     147    // one of the layer's dimensions is larger than 2000 pixels or the current size
     148    // of the visible rect. This is a temporary measure until layer tiling is implemented.
     149    static const int maxLayerSize = 2000;
     150    return (m_bounds.width() > max(maxLayerSize, layerRenderer()->rootLayerContentRect().width())
     151            || m_bounds.height() > max(maxLayerSize, layerRenderer()->rootLayerContentRect().height())
     152            || !layerRenderer()->checkTextureSize(m_bounds));
    147153}
    148154
     
    153159    // 2) The content rect-relative rectangle to draw this texture in, returned in drawRect.
    154160
    155     const IntRect contentRect = layerRenderer()->rootLayerContentRect();
     161    const IntRect clipRect = layerRenderer()->currentScissorRect();
    156162    const TransformationMatrix& transform = drawTransform();
    157163    // The layer's draw transform points to the center of the layer, relative to
     
    161167                            m_bounds.height() / 2 - transform.m42());
    162168    // Transform the contentRect into the space of the layer.
    163     IntRect contentRectInLayerSpace(layerPos, contentRect.size());
     169    IntRect contentRectInLayerSpace(layerPos, clipRect.size());
    164170
    165171    // Clip the entire layer against the visible region in the content rect
  • trunk/WebCore/platform/graphics/chromium/LayerChromium.cpp

    r69166 r70010  
    452452}
    453453
    454 const FloatRect LayerChromium::getDrawRect() const
     454const IntRect LayerChromium::getDrawRect() const
    455455{
    456456    // Form the matrix used by the shader to map the corners of the layer's
    457457    // bounds into the view space.
    458     TransformationMatrix renderMatrix = drawTransform();
    459     renderMatrix.scale3d(bounds().width(), bounds().height(), 1);
    460 
    461     FloatRect layerRect(-0.5, -0.5, 1, 1);
    462     FloatRect mappedRect = renderMatrix.mapRect(layerRect);
     458    FloatRect layerRect(-0.5 * bounds().width(), -0.5 * bounds().height(), bounds().width(), bounds().height());
     459    IntRect mappedRect = enclosingIntRect(drawTransform().mapRect(layerRect));
    463460    return mappedRect;
    464461}
  • trunk/WebCore/platform/graphics/chromium/LayerChromium.h

    r69166 r70010  
    157157
    158158    // Returns the rect containtaining this layer in the current view's coordinate system.
    159     const FloatRect getDrawRect() const;
     159    const IntRect getDrawRect() const;
    160160
    161161    // These methods typically need to be overwritten by derived classes.
  • trunk/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp

    r69747 r70010  
    322322    // Enable scissoring to avoid rendering composited layers over the scrollbars.
    323323    GLC(m_context, m_context->enable(GraphicsContext3D::SCISSOR_TEST));
    324     FloatRect scissorRect(contentRect);
     324    IntRect scissorRect(contentRect);
    325325
    326326    // The scissorRect should not include the scroll offset.
     
    335335    // Traverse the layer tree one more time to draw the layers.
    336336    for (size_t i = 0; i < sublayers.size(); i++)
    337         drawLayersRecursive(sublayers[i].get(), scissorRect);
     337        drawLayersRecursive(sublayers[i].get());
    338338
    339339    GLC(m_context, m_context->disable(GraphicsContext3D::SCISSOR_TEST));
     
    502502
    503503// Recursively walk the layer tree and draw the layers.
    504 void LayerRendererChromium::drawLayersRecursive(LayerChromium* layer, const FloatRect& scissorRect)
     504void LayerRendererChromium::drawLayersRecursive(LayerChromium* layer)
    505505{
    506506    static bool depthTestEnabledForSubtree = false;
     
    508508
    509509    // Check if the layer falls within the visible bounds of the page.
    510     FloatRect layerRect = layer->getDrawRect();
    511     bool isLayerVisible = scissorRect.intersects(layerRect);
     510    IntRect layerRect = layer->getDrawRect();
     511    bool isLayerVisible = m_currentScissorRect.intersects(layerRect);
    512512
    513513    // Enable depth testing for this layer and all its descendants if preserves3D is set.
     
    528528    // FIXME: We should check here if the layer has descendants that draw content
    529529    // before we setup for clipping.
    530     FloatRect currentScissorRect = scissorRect;
     530    IntRect previousScissorRect = m_currentScissorRect;
    531531    bool mustResetScissorRect = false;
    532532    bool didStencilDraw = false;
     
    535535        // to clip using the stencil buffer.
    536536        if (layer->drawTransform().isIdentityOrTranslation()) {
     537            IntRect currentScissorRect = previousScissorRect;
    537538            currentScissorRect.intersect(layerRect);
    538             if (currentScissorRect != scissorRect) {
     539            if (currentScissorRect != previousScissorRect) {
    539540                scissorToRect(currentScissorRect);
    540541                mustResetScissorRect = true;
     
    581582
    582583        for (i = 0; i < sublayerList.size(); i++)
    583             drawLayersRecursive(sublayerList[i], currentScissorRect);
     584            drawLayersRecursive(sublayerList[i]);
    584585    } else {
    585586        const Vector<RefPtr<LayerChromium> >& sublayers = layer->getSublayers();
    586587        for (size_t i = 0; i < sublayers.size(); i++)
    587             drawLayersRecursive(sublayers[i].get(), currentScissorRect);
     588            drawLayersRecursive(sublayers[i].get());
    588589    }
    589590
     
    601602
    602603    if (mustResetScissorRect) {
    603         scissorToRect(scissorRect);
     604        scissorToRect(previousScissorRect);
    604605    }
    605606
     
    637638// Sets the scissor region to the given rectangle. The coordinate system for the
    638639// scissorRect has its origin at the top left corner of the current visible rect.
    639 void LayerRendererChromium::scissorToRect(const FloatRect& scissorRect)
     640void LayerRendererChromium::scissorToRect(const IntRect& scissorRect)
    640641{
    641642    // Compute the lower left corner of the scissor rect.
    642     float bottom = std::max((float)m_rootVisibleRect.height() - scissorRect.bottom(), 0.f);
     643    int bottom = std::max(m_rootVisibleRect.height() - scissorRect.bottom(), 0);
    643644    GLC(m_context, m_context->scissor(scissorRect.x(), bottom, scissorRect.width(), scissorRect.height()));
     645    m_currentScissorRect = scissorRect;
    644646}
    645647
  • trunk/WebCore/platform/graphics/chromium/LayerRendererChromium.h

    r69747 r70010  
    9393    void deleteLayerTexture(unsigned);
    9494
     95    IntRect currentScissorRect() const { return m_currentScissorRect; }
     96
    9597    static void debugGLCall(GraphicsContext3D*, const char* command, const char* file, int line);
    9698
     
    117119    void updateLayersRecursive(LayerChromium* layer, const TransformationMatrix& parentMatrix, float opacity);
    118120
    119     void drawLayersRecursive(LayerChromium*, const FloatRect& scissorRect);
     121    void drawLayersRecursive(LayerChromium*);
    120122
    121123    void drawLayer(LayerChromium*);
     
    125127    void drawLayerIntoStencilBuffer(LayerChromium*, bool decrement);
    126128
    127     void scissorToRect(const FloatRect&);
     129    void scissorToRect(const IntRect&);
    128130
    129131    bool makeContextCurrent();
     
    164166    IntRect m_rootVisibleRect;
    165167    IntRect m_rootContentRect;
     168    IntRect m_currentScissorRect;
    166169
    167170    int m_maxTextureSize;
Note: See TracChangeset for help on using the changeset viewer.