Diff
Modified: trunk/Source/WebCore/ChangeLog (90504 => 90505)
--- trunk/Source/WebCore/ChangeLog 2011-07-06 21:57:56 UTC (rev 90504)
+++ trunk/Source/WebCore/ChangeLog 2011-07-06 22:33:24 UTC (rev 90505)
@@ -1,3 +1,30 @@
+2011-07-06 Adrienne Walker <[email protected]>
+
+ [chromium] Add compositor texture manager soft limits and lost focus reclaiming
+ https://bugs.webkit.org/show_bug.cgi?id=64009
+
+ Reviewed by James Robinson.
+
+ Add a soft limit for texture memory. Unprotected textures will get
+ reclaimed when above this limit. Increase the hard limit for maximum
+ texture memory as well, now that there is a better heuristic and
+ textures are reclaimed from tabs without focus.
+
+ Landing this for [email protected].
+
+ * platform/graphics/chromium/LayerRendererChromium.cpp:
+ (WebCore::LayerRendererChromium::releaseTextures):
+ (WebCore::LayerRendererChromium::initializeSharedObjects):
+ * platform/graphics/chromium/LayerRendererChromium.h:
+ * platform/graphics/chromium/LayerTilerChromium.cpp:
+ (WebCore::LayerTilerChromium::protectTileTextures):
+ * platform/graphics/chromium/LayerTilerChromium.h:
+ * platform/graphics/chromium/TextureManager.cpp:
+ (WebCore::TextureManager::TextureManager):
+ (WebCore::TextureManager::requestTexture):
+ * platform/graphics/chromium/TextureManager.h:
+ (WebCore::TextureManager::create):
+
2011-07-06 Pavel Feldman <[email protected]>
Not reviewed: Web Inspector: fixing typo introduced in the r90397.
Modified: trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp (90504 => 90505)
--- trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp 2011-07-06 21:57:56 UTC (rev 90504)
+++ trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp 2011-07-06 22:33:24 UTC (rev 90505)
@@ -65,8 +65,14 @@
namespace WebCore {
// FIXME: Make this limit adjustable and give it a useful value.
-static size_t textureMemoryLimitBytes = 64 * 1024 * 1024;
+// Absolute maximum limit for texture allocations for this instance.
+static size_t textureMemoryHighLimitBytes = 128 * 1024 * 1024;
+// Preferred texture size limit. Can be exceeded if needed.
+static size_t textureMemoryReclaimLimitBytes = 64 * 1024 * 1024;
+// The maximum texture memory usage when asked to release textures.
+static size_t textureMemoryLowLimitBytes = 3 * 1024 * 1024;
+
#ifndef NDEBUG
bool LayerRendererChromium::s_inPaintLayerContents = false;
#endif
@@ -201,6 +207,15 @@
m_rootLayerContentTiler->invalidateRect(dirtyRect);
}
+void LayerRendererChromium::releaseTextures()
+{
+ // Reduces texture memory usage to textureMemoryLowLimitBytes by deleting non root layer
+ // textures.
+ m_rootLayerContentTiler->protectTileTextures(m_viewportVisibleRect);
+ m_textureManager->reduceMemoryToLimit(textureMemoryLowLimitBytes);
+ m_textureManager->unprotectAllTextures();
+}
+
void LayerRendererChromium::updateRootLayerContents()
{
TRACE_EVENT("LayerRendererChromium::updateRootLayerContents", this, 0);
@@ -1114,7 +1129,10 @@
GLC(m_context.get(), m_context->flush());
- m_textureManager = TextureManager::create(m_context.get(), textureMemoryLimitBytes, m_maxTextureSize);
+ TextureManager::TextureMemoryLimits limits;
+ limits.upperLimit = textureMemoryHighLimitBytes;
+ limits.reclaimLimit = textureMemoryReclaimLimitBytes;
+ m_textureManager = TextureManager::create(m_context.get(), limits, m_maxTextureSize);
return true;
}
Modified: trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h (90504 => 90505)
--- trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h 2011-07-06 21:57:56 UTC (rev 90504)
+++ trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h 2011-07-06 22:33:24 UTC (rev 90505)
@@ -156,6 +156,8 @@
// Return true if the compositor context has an error.
bool isCompositorContextLost();
+ void releaseTextures();
+
#ifndef NDEBUG
static bool s_inPaintLayerContents;
#endif
Modified: trunk/Source/WebCore/platform/graphics/chromium/LayerTilerChromium.cpp (90504 => 90505)
--- trunk/Source/WebCore/platform/graphics/chromium/LayerTilerChromium.cpp 2011-07-06 21:57:56 UTC (rev 90504)
+++ trunk/Source/WebCore/platform/graphics/chromium/LayerTilerChromium.cpp 2011-07-06 22:33:24 UTC (rev 90505)
@@ -226,6 +226,25 @@
m_tilingData.setTotalSize(0, 0);
}
+void LayerTilerChromium::protectTileTextures(const IntRect& contentRect)
+{
+ if (contentRect.isEmpty())
+ return;
+
+ int left, top, right, bottom;
+ contentRectToTileIndices(contentRect, left, top, right, bottom);
+
+ for (int j = top; j <= bottom; ++j) {
+ for (int i = left; i <= right; ++i) {
+ Tile* tile = tileAt(i, j);
+ if (!tile || !tile->texture()->isValid(m_tileSize, GraphicsContext3D::RGBA))
+ continue;
+
+ tile->texture()->reserve(m_tileSize, GraphicsContext3D::RGBA);
+ }
+ }
+}
+
void LayerTilerChromium::prepareToUpdate(const IntRect& contentRect, LayerTextureUpdater* textureUpdater)
{
m_skipsDraw = false;
Modified: trunk/Source/WebCore/platform/graphics/chromium/LayerTilerChromium.h (90504 => 90505)
--- trunk/Source/WebCore/platform/graphics/chromium/LayerTilerChromium.h 2011-07-06 21:57:56 UTC (rev 90504)
+++ trunk/Source/WebCore/platform/graphics/chromium/LayerTilerChromium.h 2011-07-06 22:33:24 UTC (rev 90505)
@@ -70,6 +70,10 @@
bool skipsDraw() const { return m_skipsDraw; }
+ // Reserves all existing and valid tile textures to protect them from being
+ // recycled by the texture manager.
+ void protectTileTextures(const IntRect& contentRect);
+
typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexAlpha> Program;
// Shader program that swaps red and blue components of texture.
// Used when texture format does not match native color format.
Modified: trunk/Source/WebCore/platform/graphics/chromium/TextureManager.cpp (90504 => 90505)
--- trunk/Source/WebCore/platform/graphics/chromium/TextureManager.cpp 2011-07-06 21:57:56 UTC (rev 90504)
+++ trunk/Source/WebCore/platform/graphics/chromium/TextureManager.cpp 2011-07-06 22:33:24 UTC (rev 90505)
@@ -38,9 +38,9 @@
return size.width() * size.height() * 4;
}
-TextureManager::TextureManager(GraphicsContext3D* context, size_t memoryLimitBytes, int maxTextureSize)
+TextureManager::TextureManager(GraphicsContext3D* context, const TextureMemoryLimits& memoryLimits, int maxTextureSize)
: m_context(context)
- , m_memoryLimitBytes(memoryLimitBytes)
+ , m_memoryLimits(memoryLimits)
, m_memoryUseBytes(0)
, m_maxTextureSize(maxTextureSize)
, m_nextToken(1)
@@ -97,7 +97,7 @@
it->second.isProtected = false;
}
-bool TextureManager::reduceMemoryToLimit(size_t limit)
+void TextureManager::reduceMemoryToLimit(size_t limit)
{
while (m_memoryUseBytes > limit) {
ASSERT(!m_textureLRUSet.isEmpty());
@@ -112,9 +112,8 @@
break;
}
if (!foundCandidate)
- return false;
+ return;
}
- return true;
}
void TextureManager::addTexture(TextureToken token, TextureInfo info)
@@ -137,7 +136,7 @@
GLC(m_context.get(), m_context->deleteTexture(info.textureId));
}
-unsigned TextureManager::requestTexture(TextureToken token, IntSize size, unsigned format, bool* newTexture)
+unsigned TextureManager::requestTexture(TextureToken token, IntSize size, unsigned format)
{
if (size.width() > m_maxTextureSize || size.height() > m_maxTextureSize)
return 0;
@@ -149,7 +148,10 @@
}
size_t memoryRequiredBytes = memoryUseBytes(size, format);
- if (memoryRequiredBytes > m_memoryLimitBytes || !reduceMemoryToLimit(m_memoryLimitBytes - memoryRequiredBytes))
+
+ // Reclaim existing unreserved textures to try to stay below the reclaim limit.
+ reduceMemoryToLimit(std::max(m_memoryLimits.reclaimLimit - memoryRequiredBytes, static_cast<size_t>(0)));
+ if (m_memoryUseBytes + memoryRequiredBytes > m_memoryLimits.upperLimit)
return 0;
unsigned textureId;
Modified: trunk/Source/WebCore/platform/graphics/chromium/TextureManager.h (90504 => 90505)
--- trunk/Source/WebCore/platform/graphics/chromium/TextureManager.h 2011-07-06 21:57:56 UTC (rev 90504)
+++ trunk/Source/WebCore/platform/graphics/chromium/TextureManager.h 2011-07-06 22:33:24 UTC (rev 90505)
@@ -40,24 +40,33 @@
class TextureManager {
WTF_MAKE_NONCOPYABLE(TextureManager);
public:
- static PassOwnPtr<TextureManager> create(GraphicsContext3D* context, size_t memoryLimitBytes, int maxTextureSize)
+ struct TextureMemoryLimits {
+ // Maximum texture allocation size.
+ size_t upperLimit;
+ // Limit over which existing unreserved textures will be reclaimed.
+ size_t reclaimLimit;
+ };
+
+ static PassOwnPtr<TextureManager> create(GraphicsContext3D* context, const TextureMemoryLimits& memoryLimits, int maxTextureSize)
{
- return adoptPtr(new TextureManager(context, memoryLimitBytes, maxTextureSize));
+ return adoptPtr(new TextureManager(context, memoryLimits, maxTextureSize));
}
TextureToken getToken();
void releaseToken(TextureToken);
bool hasTexture(TextureToken);
- unsigned requestTexture(TextureToken, IntSize, unsigned textureFormat, bool* newTexture = 0);
+ unsigned requestTexture(TextureToken, IntSize, unsigned textureFormat);
void protectTexture(TextureToken);
void unprotectTexture(TextureToken);
void unprotectAllTextures();
bool isProtected(TextureToken);
+ void reduceMemoryToLimit(size_t);
+
private:
- TextureManager(GraphicsContext3D*, size_t memoryLimitBytes, int maxTextureSize);
+ TextureManager(GraphicsContext3D*, const TextureMemoryLimits&, int maxTextureSize);
struct TextureInfo {
IntSize size;
@@ -66,7 +75,6 @@
bool isProtected;
};
- bool reduceMemoryToLimit(size_t);
void addTexture(TextureToken, TextureInfo);
void removeTexture(TextureToken, TextureInfo);
@@ -76,7 +84,7 @@
TextureMap m_textures;
ListHashSet<TextureToken> m_textureLRUSet;
- size_t m_memoryLimitBytes;
+ TextureMemoryLimits m_memoryLimits;
size_t m_memoryUseBytes;
int m_maxTextureSize;
TextureToken m_nextToken;
Modified: trunk/Source/WebKit/chromium/ChangeLog (90504 => 90505)
--- trunk/Source/WebKit/chromium/ChangeLog 2011-07-06 21:57:56 UTC (rev 90504)
+++ trunk/Source/WebKit/chromium/ChangeLog 2011-07-06 22:33:24 UTC (rev 90505)
@@ -1,3 +1,15 @@
+2011-07-06 Adrienne Walker <[email protected]>
+
+ [chromium] Add compositor texture manager soft limits and lost focus reclaiming
+ https://bugs.webkit.org/show_bug.cgi?id=64009
+
+ Reviewed by James Robinson.
+
+ Reclaim textures when the tab loses focus.
+
+ * src/WebViewImpl.cpp:
+ (WebKit::WebViewImpl::setVisibilityState):
+
2011-06-30 Cris Neckar <[email protected]>
Reviewed by Darin Fisher.
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (90504 => 90505)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2011-07-06 21:57:56 UTC (rev 90504)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2011-07-06 22:33:24 UTC (rev 90505)
@@ -2651,15 +2651,20 @@
void WebViewImpl::setVisibilityState(WebPageVisibilityState visibilityState,
bool isInitialState) {
-#if ENABLE(PAGE_VISIBILITY_API)
if (!page())
return;
+#if ENABLE(PAGE_VISIBILITY_API)
ASSERT(visibilityState == WebPageVisibilityStateVisible
|| visibilityState == WebPageVisibilityStateHidden
|| visibilityState == WebPageVisibilityStatePrerender);
m_page->setVisibilityState(static_cast<PageVisibilityState>(static_cast<int>(visibilityState)), isInitialState);
#endif
+
+#if USE(ACCELERATED_COMPOSITING)
+ if (isAcceleratedCompositingActive() && visibilityState == WebPageVisibilityStateHidden)
+ m_layerRenderer->releaseTextures();
+#endif
}
} // namespace WebKit