Changeset 106891 in webkit


Ignore:
Timestamp:
Feb 6, 2012 6:24:29 PM (12 years ago)
Author:
jamesr@google.com
Message:

[chromium] canvas demo is slow due to unnecessary resource cleanups
https://bugs.webkit.org/show_bug.cgi?id=77135

Reviewed by Kenneth Russell.

Source/WebCore:

This defers dropping a ManagedTexture until it is evicted by the manager, the layer is destroyed, the
TextureManager is destroyed, or the layer is added to a CCLayerTreeHost that has a different texture manager. In
particular, removing a layer from a CCLayerTreeHost and then adding it back to the same host does not drop any
ManagedTextures unless the manager has to evict it for other reasons. This provides a big speedup on sites that
rebuild the compositing tree frequently.

New unit test added for ManagedTexture / TextureManager interaction.

  • platform/graphics/chromium/Canvas2DLayerChromium.cpp:

(WebCore::Canvas2DLayerChromium::setLayerTreeHost):
(WebCore::Canvas2DLayerChromium::setTextureManager):

  • platform/graphics/chromium/Canvas2DLayerChromium.h:

(Canvas2DLayerChromium):

  • platform/graphics/chromium/LayerChromium.cpp:

(WebCore::LayerChromium::setLayerTreeHost):

  • platform/graphics/chromium/LayerChromium.h:

(LayerChromium):

  • platform/graphics/chromium/ManagedTexture.cpp:

(WebCore::ManagedTexture::setTextureManager):
(WebCore):
(WebCore::ManagedTexture::steal):
(WebCore::ManagedTexture::clear):

  • platform/graphics/chromium/ManagedTexture.h:

(ManagedTexture):

  • platform/graphics/chromium/RenderSurfaceChromium.h:

(RenderSurfaceChromium):

  • platform/graphics/chromium/TiledLayerChromium.cpp:

(WebCore::TiledLayerChromium::setLayerTreeHost):
(WebCore):
(WebCore::TiledLayerChromium::prepareToUpdateTiles):

  • platform/graphics/chromium/TiledLayerChromium.h:

Source/WebKit/chromium:

  • tests/Canvas2DLayerChromiumTest.cpp:

(WebCore::Canvas2DLayerChromiumTest::fullLifecycleTest):

  • tests/TextureManagerTest.cpp:
  • tests/TiledLayerChromiumTest.cpp:
Location:
trunk/Source
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r106889 r106891  
     12012-02-06  James Robinson  <jamesr@chromium.org>
     2
     3        [chromium] canvas demo is slow due to unnecessary resource cleanups
     4        https://bugs.webkit.org/show_bug.cgi?id=77135
     5
     6        Reviewed by Kenneth Russell.
     7
     8        This defers dropping a ManagedTexture until it is evicted by the manager, the layer is destroyed, the
     9        TextureManager is destroyed, or the layer is added to a CCLayerTreeHost that has a different texture manager. In
     10        particular, removing a layer from a CCLayerTreeHost and then adding it back to the same host does not drop any
     11        ManagedTextures unless the manager has to evict it for other reasons. This provides a big speedup on sites that
     12        rebuild the compositing tree frequently.
     13
     14        New unit test added for ManagedTexture / TextureManager interaction.
     15
     16        * platform/graphics/chromium/Canvas2DLayerChromium.cpp:
     17        (WebCore::Canvas2DLayerChromium::setLayerTreeHost):
     18        (WebCore::Canvas2DLayerChromium::setTextureManager):
     19        * platform/graphics/chromium/Canvas2DLayerChromium.h:
     20        (Canvas2DLayerChromium):
     21        * platform/graphics/chromium/LayerChromium.cpp:
     22        (WebCore::LayerChromium::setLayerTreeHost):
     23        * platform/graphics/chromium/LayerChromium.h:
     24        (LayerChromium):
     25        * platform/graphics/chromium/ManagedTexture.cpp:
     26        (WebCore::ManagedTexture::setTextureManager):
     27        (WebCore):
     28        (WebCore::ManagedTexture::steal):
     29        (WebCore::ManagedTexture::clear):
     30        * platform/graphics/chromium/ManagedTexture.h:
     31        (ManagedTexture):
     32        * platform/graphics/chromium/RenderSurfaceChromium.h:
     33        (RenderSurfaceChromium):
     34        * platform/graphics/chromium/TiledLayerChromium.cpp:
     35        (WebCore::TiledLayerChromium::setLayerTreeHost):
     36        (WebCore):
     37        (WebCore::TiledLayerChromium::prepareToUpdateTiles):
     38        * platform/graphics/chromium/TiledLayerChromium.h:
     39
    1402012-02-06  Kentaro Hara  <haraken@chromium.org>
    241
  • trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp

    r106601 r106891  
    120120void Canvas2DLayerChromium::setLayerTreeHost(CCLayerTreeHost* host)
    121121{
    122     if (layerTreeHost() != host)
    123         setTextureManager(host ? host->contentsTextureManager() : 0);
     122    CanvasLayerChromium::setLayerTreeHost(host);
    124123
    125     CanvasLayerChromium::setLayerTreeHost(host);
     124    if (m_useDoubleBuffering && host)
     125        setTextureManager(host->contentsTextureManager());
    126126}
    127127
    128128void Canvas2DLayerChromium::setTextureManager(TextureManager* textureManager)
    129129{
    130     if (textureManager && m_useDoubleBuffering)
     130    if (m_frontTexture)
     131        m_frontTexture->setTextureManager(textureManager);
     132    else
    131133        m_frontTexture = ManagedTexture::create(textureManager);
    132     else
    133         m_frontTexture.clear();
    134134}
    135135
     
    167167}
    168168
    169 void Canvas2DLayerChromium::cleanupResources()
    170 {
    171     if (m_useDoubleBuffering)
    172         m_frontTexture.clear();
    173 }
    174 
    175169}
    176170
  • trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h

    r106500 r106891  
    6262    virtual void pushPropertiesTo(CCLayerImpl*);
    6363    virtual void unreserveContentsTexture();
    64     virtual void cleanupResources();
    6564
    6665    void setCanvas(SkCanvas*);
     
    6968    Canvas2DLayerChromium(GraphicsContext3D*, const IntSize&);
    7069
    71     // Visible for testing so we can bypass setLayerTreeHost.
    7270    friend class Canvas2DLayerChromiumTest;
    7371    void setTextureManager(TextureManager*);
  • trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.cpp

    r106383 r106891  
    9393}
    9494
    95 void LayerChromium::cleanupResources()
    96 {
    97 }
    98 
    9995void LayerChromium::setIsNonCompositedContent(bool isNonCompositedContent)
    10096{
     
    106102    if (m_layerTreeHost == host)
    107103        return;
    108 
    109     // If we're changing hosts then we need to free up any resources
    110     // allocated by the old host.
    111     if (m_layerTreeHost)
    112         cleanupResources();
    113104
    114105    m_layerTreeHost = host;
  • trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.h

    r106383 r106891  
    215215    LayerChromium();
    216216
    217     // This is called to clean up resources being held in the same context as
    218     // layerRendererContext(). Subclasses should override this method if they
    219     // hold context-dependent resources such as textures.
    220     virtual void cleanupResources();
    221 
    222217    bool isPaintedAxisAlignedInScreen() const;
    223218
  • trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp

    r106840 r106891  
    6262}
    6363
     64void ManagedTexture::setTextureManager(TextureManager* manager)
     65{
     66    if (manager == m_textureManager)
     67        return;
     68
     69    if (m_textureManager)
     70        m_textureManager->unregisterTexture(this);
     71    m_textureManager = manager;
     72    clear();
     73    if (m_textureManager)
     74        m_textureManager->registerTexture(this);
     75}
     76
    6477bool ManagedTexture::isValid(const IntSize& size, unsigned format)
    6578{
     
    120133{
    121134    OwnPtr<ManagedTexture> texture = adoptPtr(new ManagedTexture(m_textureManager, m_token, m_size, m_format, m_textureId));
     135    clear();
     136    return texture.release();
     137}
     138
     139void ManagedTexture::clear()
     140{
    122141    m_token = 0;
    123142    m_size = IntSize();
    124143    m_format = 0;
    125144    m_textureId = 0;
    126     return texture.release();
    127145}
    128 
    129146
    130147}
  • trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.h

    r106840 r106891  
    4747    ~ManagedTexture();
    4848
     49    void setTextureManager(TextureManager*);
    4950    void clearManager() { m_textureManager = 0; }
    5051
     
    7374    ManagedTexture(TextureManager*, TextureToken, IntSize, unsigned format, unsigned textureId);
    7475
     76    void clear();
     77
    7578    TextureManager* m_textureManager;
    7679    TextureToken m_token;
  • trunk/Source/WebCore/platform/graphics/chromium/RenderSurfaceChromium.h

    r106383 r106891  
    5252    bool prepareContentsTexture();
    5353    void releaseContentsTexture();
    54     void cleanupResources();
    5554    void draw(const IntRect& targetSurfaceRect);
    5655
  • trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp

    r106870 r106891  
    9393}
    9494
    95 void TiledLayerChromium::cleanupResources()
    96 {
    97     LayerChromium::cleanupResources();
    98 
    99     m_tiler->reset();
    100     m_paintRect = IntRect();
    101     m_requestedUpdateTilesRect = IntRect();
    102 }
    103 
    10495void TiledLayerChromium::updateTileSizeAndTilingOption()
    10596{
     
    274265        return 0;
    275266    return layerTreeHost()->contentsTextureManager();
     267}
     268
     269void TiledLayerChromium::setLayerTreeHost(CCLayerTreeHost* host)
     270{
     271    if (host && host != layerTreeHost()) {
     272        for (CCLayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().begin(); iter != m_tiler->tiles().end(); ++iter) {
     273            UpdatableTile* tile = static_cast<UpdatableTile*>(iter->second.get());
     274            tile->managedTexture()->setTextureManager(host->contentsTextureManager());
     275        }
     276    }
     277    LayerChromium::setLayerTreeHost(host);
    276278}
    277279
     
    386388                    if (!backgroundCoversViewport())
    387389                        m_skipsDraw = true;
    388                     cleanupResources();
     390                    m_tiler->reset();
     391                    m_paintRect = IntRect();
     392                    m_requestedUpdateTilesRect = IntRect();
    389393                }
    390394                return;
  • trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.h

    r106700 r106891  
    5959    virtual void setIsNonCompositedContent(bool);
    6060
     61    virtual void setLayerTreeHost(CCLayerTreeHost*);
     62
    6163    // Reserves all existing and valid tile textures to protect them from being
    6264    // recycled by the texture manager.
     
    7072    TiledLayerChromium();
    7173
    72     virtual void cleanupResources();
    7374    void updateTileSizeAndTilingOption();
    7475    void updateBounds();
  • trunk/Source/WebKit/chromium/ChangeLog

    r106887 r106891  
     12012-02-06  James Robinson  <jamesr@chromium.org>
     2
     3        [chromium] canvas demo is slow due to unnecessary resource cleanups
     4        https://bugs.webkit.org/show_bug.cgi?id=77135
     5
     6        Reviewed by Kenneth Russell.
     7
     8        * tests/Canvas2DLayerChromiumTest.cpp:
     9        (WebCore::Canvas2DLayerChromiumTest::fullLifecycleTest):
     10        * tests/TextureManagerTest.cpp:
     11        * tests/TiledLayerChromiumTest.cpp:
     12
    1132012-02-06  Julien Chaffraix  <jchaffraix@webkit.org>
    214
  • trunk/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp

    r106383 r106891  
    7676class Canvas2DLayerChromiumTest : public Test {
    7777protected:
    78     // This indirection is needed because individual tests aren't friends of Canvas2DLayerChromium.
    79     void setTextureManager(Canvas2DLayerChromium* layer, TextureManager* manager)
    80     {
    81         layer->setTextureManager(manager);
    82     }
    83 
    8478    void fullLifecycleTest(bool threaded)
    8579    {
     
    134128        RefPtr<Canvas2DLayerChromium> canvas = Canvas2DLayerChromium::create(mainContext.get(), size);
    135129        canvas->setIsDrawable(true);
    136         setTextureManager(canvas.get(), textureManager.get());
     130        canvas->setTextureManager(textureManager.get());
    137131        canvas->setBounds(IntSize(600, 300));
    138132        canvas->setTextureId(backTextureId);
  • trunk/Source/WebKit/chromium/tests/TextureManagerTest.cpp

    r106840 r106891  
    265265}
    266266
     267TEST_F(TextureManagerTest, textureMovedToNewManager)
     268{
     269    OwnPtr<TextureManager> textureManagerOne = createTextureManager(1, 1);
     270    OwnPtr<TextureManager> textureManagerTwo = createTextureManager(1, 1);
     271    OwnPtr<ManagedTexture> managedTexture = ManagedTexture::create(textureManagerOne.get());
     272
     273    IntSize size(50, 50);
     274    unsigned format = GraphicsContext3D::RGBA;
     275
     276    // Texture is initially invalid, but we should be able to reserve.
     277    EXPECT_FALSE(managedTexture->isValid(size, format));
     278    EXPECT_TRUE(managedTexture->reserve(size, format));
     279    EXPECT_TRUE(managedTexture->isValid(size, format));
     280
     281    // Setting to the same manager should be a no-op.
     282    managedTexture->setTextureManager(textureManagerOne.get());
     283    EXPECT_TRUE(managedTexture->isValid(size, format));
     284
     285    // Setting to a different manager should invalidate the texture.
     286    managedTexture->setTextureManager(textureManagerTwo.get());
     287
     288    EXPECT_FALSE(managedTexture->isValid(size, format));
     289    EXPECT_TRUE(managedTexture->reserve(size, format));
     290    EXPECT_TRUE(managedTexture->isValid(size, format));
     291}
     292
    267293} // namespace
  • trunk/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp

    r106870 r106891  
    460460
    461461    ccLayerTreeHost->commitComplete();
     462    textureManager->unprotectAllTextures(); // CCLayerTreeHost::commitComplete() normally does this, but since we're mocking out the manager we have to do it.
    462463
    463464    // Remove the child layer.
Note: See TracChangeset for help on using the changeset viewer.