Diff
Modified: trunk/Source/WebCore/ChangeLog (106890 => 106891)
--- trunk/Source/WebCore/ChangeLog 2012-02-07 02:21:09 UTC (rev 106890)
+++ trunk/Source/WebCore/ChangeLog 2012-02-07 02:24:29 UTC (rev 106891)
@@ -1,3 +1,42 @@
+2012-02-06 James Robinson <[email protected]>
+
+ [chromium] canvas demo is slow due to unnecessary resource cleanups
+ https://bugs.webkit.org/show_bug.cgi?id=77135
+
+ Reviewed by Kenneth Russell.
+
+ 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:
+
2012-02-06 Kentaro Hara <[email protected]>
Unreviewed, rolling out r106883.
Modified: trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp (106890 => 106891)
--- trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp 2012-02-07 02:21:09 UTC (rev 106890)
+++ trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp 2012-02-07 02:24:29 UTC (rev 106891)
@@ -119,18 +119,18 @@
void Canvas2DLayerChromium::setLayerTreeHost(CCLayerTreeHost* host)
{
- if (layerTreeHost() != host)
- setTextureManager(host ? host->contentsTextureManager() : 0);
-
CanvasLayerChromium::setLayerTreeHost(host);
+
+ if (m_useDoubleBuffering && host)
+ setTextureManager(host->contentsTextureManager());
}
void Canvas2DLayerChromium::setTextureManager(TextureManager* textureManager)
{
- if (textureManager && m_useDoubleBuffering)
- m_frontTexture = ManagedTexture::create(textureManager);
+ if (m_frontTexture)
+ m_frontTexture->setTextureManager(textureManager);
else
- m_frontTexture.clear();
+ m_frontTexture = ManagedTexture::create(textureManager);
}
void Canvas2DLayerChromium::updateCompositorResources(GraphicsContext3D* context, CCTextureUpdater& updater)
@@ -166,12 +166,6 @@
m_frontTexture->unreserve();
}
-void Canvas2DLayerChromium::cleanupResources()
-{
- if (m_useDoubleBuffering)
- m_frontTexture.clear();
}
-}
-
#endif // USE(ACCELERATED_COMPOSITING)
Modified: trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h (106890 => 106891)
--- trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h 2012-02-07 02:21:09 UTC (rev 106890)
+++ trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h 2012-02-07 02:24:29 UTC (rev 106891)
@@ -61,14 +61,12 @@
virtual void updateCompositorResources(GraphicsContext3D*, CCTextureUpdater&);
virtual void pushPropertiesTo(CCLayerImpl*);
virtual void unreserveContentsTexture();
- virtual void cleanupResources();
void setCanvas(SkCanvas*);
private:
Canvas2DLayerChromium(GraphicsContext3D*, const IntSize&);
- // Visible for testing so we can bypass setLayerTreeHost.
friend class Canvas2DLayerChromiumTest;
void setTextureManager(TextureManager*);
Modified: trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.cpp (106890 => 106891)
--- trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.cpp 2012-02-07 02:21:09 UTC (rev 106890)
+++ trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.cpp 2012-02-07 02:24:29 UTC (rev 106891)
@@ -92,10 +92,6 @@
removeAllChildren();
}
-void LayerChromium::cleanupResources()
-{
-}
-
void LayerChromium::setIsNonCompositedContent(bool isNonCompositedContent)
{
m_isNonCompositedContent = isNonCompositedContent;
@@ -106,11 +102,6 @@
if (m_layerTreeHost == host)
return;
- // If we're changing hosts then we need to free up any resources
- // allocated by the old host.
- if (m_layerTreeHost)
- cleanupResources();
-
m_layerTreeHost = host;
for (size_t i = 0; i < m_children.size(); ++i)
Modified: trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.h (106890 => 106891)
--- trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.h 2012-02-07 02:21:09 UTC (rev 106890)
+++ trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.h 2012-02-07 02:24:29 UTC (rev 106891)
@@ -214,11 +214,6 @@
protected:
LayerChromium();
- // This is called to clean up resources being held in the same context as
- // layerRendererContext(). Subclasses should override this method if they
- // hold context-dependent resources such as textures.
- virtual void cleanupResources();
-
bool isPaintedAxisAlignedInScreen() const;
void setNeedsCommit();
Modified: trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp (106890 => 106891)
--- trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp 2012-02-07 02:21:09 UTC (rev 106890)
+++ trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp 2012-02-07 02:24:29 UTC (rev 106891)
@@ -61,6 +61,19 @@
m_textureManager->releaseToken(m_token);
}
+void ManagedTexture::setTextureManager(TextureManager* manager)
+{
+ if (manager == m_textureManager)
+ return;
+
+ if (m_textureManager)
+ m_textureManager->unregisterTexture(this);
+ m_textureManager = manager;
+ clear();
+ if (m_textureManager)
+ m_textureManager->registerTexture(this);
+}
+
bool ManagedTexture::isValid(const IntSize& size, unsigned format)
{
return m_token && size == m_size && format == m_format && m_textureManager && m_textureManager->hasTexture(m_token);
@@ -119,14 +132,18 @@
PassOwnPtr<ManagedTexture> ManagedTexture::steal()
{
OwnPtr<ManagedTexture> texture = adoptPtr(new ManagedTexture(m_textureManager, m_token, m_size, m_format, m_textureId));
+ clear();
+ return texture.release();
+}
+
+void ManagedTexture::clear()
+{
m_token = 0;
m_size = IntSize();
m_format = 0;
m_textureId = 0;
- return texture.release();
}
-
}
#endif // USE(ACCELERATED_COMPOSITING)
Modified: trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.h (106890 => 106891)
--- trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.h 2012-02-07 02:21:09 UTC (rev 106890)
+++ trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.h 2012-02-07 02:24:29 UTC (rev 106891)
@@ -46,6 +46,7 @@
}
~ManagedTexture();
+ void setTextureManager(TextureManager*);
void clearManager() { m_textureManager = 0; }
bool isValid(const IntSize&, unsigned format);
@@ -72,6 +73,8 @@
explicit ManagedTexture(TextureManager*);
ManagedTexture(TextureManager*, TextureToken, IntSize, unsigned format, unsigned textureId);
+ void clear();
+
TextureManager* m_textureManager;
TextureToken m_token;
IntSize m_size;
Modified: trunk/Source/WebCore/platform/graphics/chromium/RenderSurfaceChromium.h (106890 => 106891)
--- trunk/Source/WebCore/platform/graphics/chromium/RenderSurfaceChromium.h 2012-02-07 02:21:09 UTC (rev 106890)
+++ trunk/Source/WebCore/platform/graphics/chromium/RenderSurfaceChromium.h 2012-02-07 02:24:29 UTC (rev 106891)
@@ -51,7 +51,6 @@
bool prepareContentsTexture();
void releaseContentsTexture();
- void cleanupResources();
void draw(const IntRect& targetSurfaceRect);
// Returns the rect that encloses the RenderSurface including any reflection.
Modified: trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp (106890 => 106891)
--- trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp 2012-02-07 02:21:09 UTC (rev 106890)
+++ trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp 2012-02-07 02:24:29 UTC (rev 106891)
@@ -92,15 +92,6 @@
return CCTiledLayerImpl::create(id());
}
-void TiledLayerChromium::cleanupResources()
-{
- LayerChromium::cleanupResources();
-
- m_tiler->reset();
- m_paintRect = IntRect();
- m_requestedUpdateTilesRect = IntRect();
-}
-
void TiledLayerChromium::updateTileSizeAndTilingOption()
{
const IntSize tileSize(min(defaultTileSize, contentBounds().width()), min(defaultTileSize, contentBounds().height()));
@@ -275,6 +266,17 @@
return layerTreeHost()->contentsTextureManager();
}
+void TiledLayerChromium::setLayerTreeHost(CCLayerTreeHost* host)
+{
+ if (host && host != layerTreeHost()) {
+ for (CCLayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().begin(); iter != m_tiler->tiles().end(); ++iter) {
+ UpdatableTile* tile = static_cast<UpdatableTile*>(iter->second.get());
+ tile->managedTexture()->setTextureManager(host->contentsTextureManager());
+ }
+ }
+ LayerChromium::setLayerTreeHost(host);
+}
+
UpdatableTile* TiledLayerChromium::tileAt(int i, int j) const
{
return static_cast<UpdatableTile*>(m_tiler->tileAt(i, j));
@@ -385,7 +387,9 @@
// layer so that checkerboarded tiles will still draw.
if (!backgroundCoversViewport())
m_skipsDraw = true;
- cleanupResources();
+ m_tiler->reset();
+ m_paintRect = IntRect();
+ m_requestedUpdateTilesRect = IntRect();
}
return;
}
Modified: trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.h (106890 => 106891)
--- trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.h 2012-02-07 02:21:09 UTC (rev 106890)
+++ trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.h 2012-02-07 02:24:29 UTC (rev 106891)
@@ -58,6 +58,8 @@
virtual void setIsNonCompositedContent(bool);
+ virtual void setLayerTreeHost(CCLayerTreeHost*);
+
// Reserves all existing and valid tile textures to protect them from being
// recycled by the texture manager.
void protectTileTextures(const IntRect& layerRect);
@@ -69,7 +71,6 @@
protected:
TiledLayerChromium();
- virtual void cleanupResources();
void updateTileSizeAndTilingOption();
void updateBounds();
Modified: trunk/Source/WebKit/chromium/ChangeLog (106890 => 106891)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-02-07 02:21:09 UTC (rev 106890)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-02-07 02:24:29 UTC (rev 106891)
@@ -1,3 +1,15 @@
+2012-02-06 James Robinson <[email protected]>
+
+ [chromium] canvas demo is slow due to unnecessary resource cleanups
+ https://bugs.webkit.org/show_bug.cgi?id=77135
+
+ Reviewed by Kenneth Russell.
+
+ * tests/Canvas2DLayerChromiumTest.cpp:
+ (WebCore::Canvas2DLayerChromiumTest::fullLifecycleTest):
+ * tests/TextureManagerTest.cpp:
+ * tests/TiledLayerChromiumTest.cpp:
+
2012-02-06 Julien Chaffraix <[email protected]>
Unreviewed gardening.
Modified: trunk/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp (106890 => 106891)
--- trunk/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp 2012-02-07 02:21:09 UTC (rev 106890)
+++ trunk/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp 2012-02-07 02:24:29 UTC (rev 106891)
@@ -75,12 +75,6 @@
class Canvas2DLayerChromiumTest : public Test {
protected:
- // This indirection is needed because individual tests aren't friends of Canvas2DLayerChromium.
- void setTextureManager(Canvas2DLayerChromium* layer, TextureManager* manager)
- {
- layer->setTextureManager(manager);
- }
-
void fullLifecycleTest(bool threaded)
{
GraphicsContext3D::Attributes attrs;
@@ -133,7 +127,7 @@
RefPtr<Canvas2DLayerChromium> canvas = Canvas2DLayerChromium::create(mainContext.get(), size);
canvas->setIsDrawable(true);
- setTextureManager(canvas.get(), textureManager.get());
+ canvas->setTextureManager(textureManager.get());
canvas->setBounds(IntSize(600, 300));
canvas->setTextureId(backTextureId);
Modified: trunk/Source/WebKit/chromium/tests/TextureManagerTest.cpp (106890 => 106891)
--- trunk/Source/WebKit/chromium/tests/TextureManagerTest.cpp 2012-02-07 02:21:09 UTC (rev 106890)
+++ trunk/Source/WebKit/chromium/tests/TextureManagerTest.cpp 2012-02-07 02:24:29 UTC (rev 106891)
@@ -264,4 +264,30 @@
EXPECT_FALSE(managedTexture->reserve(size, format));
}
+TEST_F(TextureManagerTest, textureMovedToNewManager)
+{
+ OwnPtr<TextureManager> textureManagerOne = createTextureManager(1, 1);
+ OwnPtr<TextureManager> textureManagerTwo = createTextureManager(1, 1);
+ OwnPtr<ManagedTexture> managedTexture = ManagedTexture::create(textureManagerOne.get());
+
+ IntSize size(50, 50);
+ unsigned format = GraphicsContext3D::RGBA;
+
+ // Texture is initially invalid, but we should be able to reserve.
+ EXPECT_FALSE(managedTexture->isValid(size, format));
+ EXPECT_TRUE(managedTexture->reserve(size, format));
+ EXPECT_TRUE(managedTexture->isValid(size, format));
+
+ // Setting to the same manager should be a no-op.
+ managedTexture->setTextureManager(textureManagerOne.get());
+ EXPECT_TRUE(managedTexture->isValid(size, format));
+
+ // Setting to a different manager should invalidate the texture.
+ managedTexture->setTextureManager(textureManagerTwo.get());
+
+ EXPECT_FALSE(managedTexture->isValid(size, format));
+ EXPECT_TRUE(managedTexture->reserve(size, format));
+ EXPECT_TRUE(managedTexture->isValid(size, format));
+}
+
} // namespace
Modified: trunk/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp (106890 => 106891)
--- trunk/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp 2012-02-07 02:21:09 UTC (rev 106890)
+++ trunk/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp 2012-02-07 02:24:29 UTC (rev 106891)
@@ -459,6 +459,7 @@
EXPECT_FALSE(childLayer->skipsDraw());
ccLayerTreeHost->commitComplete();
+ textureManager->unprotectAllTextures(); // CCLayerTreeHost::commitComplete() normally does this, but since we're mocking out the manager we have to do it.
// Remove the child layer.
rootLayer->removeAllChildren();