From ce0e4b6b423e45f5a1c2eeedd8a5eff9d24f666e Mon Sep 17 00:00:00 2001 From: Teng-Hui Zhu Date: Mon, 30 Apr 2012 16:56:14 -0700 Subject: Fix max texture setup bug:5698410 Change-Id: Idff9cb52cabd4cc87427f975fee4968e779139bf --- .../platform/graphics/android/GLWebViewState.cpp | 8 +- .../graphics/android/rendering/TilesManager.cpp | 94 +++++++++++----------- .../graphics/android/rendering/TilesManager.h | 18 ++--- 3 files changed, 58 insertions(+), 62 deletions(-) (limited to 'Source/WebCore/platform/graphics/android') diff --git a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp index 7a94eb5..6fea786 100644 --- a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp +++ b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp @@ -135,7 +135,7 @@ void GLWebViewState::setViewport(const SkRect& viewport, float scale) TilesManager* tilesManager = TilesManager::instance(); int maxTextureCount = viewMaxTileX * viewMaxTileY * (tilesManager->highEndGfx() ? 4 : 2); - tilesManager->setMaxTextureCount(maxTextureCount); + tilesManager->setCurrentTextureCount(maxTextureCount); // TODO: investigate whether we can move this return earlier. if ((m_viewport == viewport) @@ -227,11 +227,11 @@ bool GLWebViewState::setLayersRenderingMode(TexturesResult& nbTexturesNeeded) bool invalBase = false; if (!nbTexturesNeeded.full) - TilesManager::instance()->setMaxLayerTextureCount(0); + TilesManager::instance()->setCurrentLayerTextureCount(0); else - TilesManager::instance()->setMaxLayerTextureCount((2*nbTexturesNeeded.full)+1); + TilesManager::instance()->setCurrentLayerTextureCount((2 * nbTexturesNeeded.full) + 1); - int maxTextures = TilesManager::instance()->maxLayerTextureCount(); + int maxTextures = TilesManager::instance()->currentLayerTextureCount(); LayersRenderingMode layersRenderingMode = m_layersRenderingMode; if (m_layersRenderingMode == kSingleSurfaceRendering) { diff --git a/Source/WebCore/platform/graphics/android/rendering/TilesManager.cpp b/Source/WebCore/platform/graphics/android/rendering/TilesManager.cpp index 731db23..5693d28 100644 --- a/Source/WebCore/platform/graphics/android/rendering/TilesManager.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/TilesManager.cpp @@ -50,10 +50,10 @@ // one viewport, otherwise the allocation may stall. // We need n textures for one TiledPage, and another n textures for the // second page used when scaling. -// In our case, we use 256*256 textures. On the tablet, this equates to -// at least 60 textures, or 112 with expanded tile boundaries. -// 112(tiles)*256*256*4(bpp)*2(pages) = 56MB -// It turns out the viewport dependent value m_maxTextureCount is a reasonable +// In our case, we use 256*256 textures. Both base and layers can use up to +// MAX_TEXTURE_ALLOCATION textures, which is 224MB GPU memory in total. +// For low end graphics systems, we cut this upper limit to half. +// We've found the viewport dependent value m_currentTextureCount is a reasonable // number to cap the layer tile texturs, it worked on both phones and tablets. // TODO: after merge the pool of base tiles and layer tiles, we should revisit // the logic of allocation management. @@ -67,24 +67,26 @@ namespace WebCore { -GLint TilesManager::getMaxTextureSize() -{ - static GLint maxTextureSize = 0; - if (!maxTextureSize) - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); - return maxTextureSize; -} - int TilesManager::getMaxTextureAllocation() { - return MAX_TEXTURE_ALLOCATION; + if (m_maxTextureAllocation == -1) { + GLint glMaxTextureSize = 0; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &glMaxTextureSize); + GLUtils::checkGlError("TilesManager::getMaxTextureAllocation"); + // Half of glMaxTextureSize can be used for base, the other half for layers. + m_maxTextureAllocation = std::min(MAX_TEXTURE_ALLOCATION, glMaxTextureSize / 2); + if (!m_highEndGfx) + m_maxTextureAllocation = m_maxTextureAllocation / 2; + } + return m_maxTextureAllocation; } TilesManager::TilesManager() : m_layerTexturesRemain(true) , m_highEndGfx(false) - , m_maxTextureCount(0) - , m_maxLayerTextureCount(0) + , m_currentTextureCount(0) + , m_currentLayerTextureCount(0) + , m_maxTextureAllocation(-1) , m_generatorReady(false) , m_showVisualIndicator(false) , m_invertedScreen(false) @@ -107,10 +109,10 @@ TilesManager::TilesManager() m_pixmapsGenerationThread->run("TexturesGenerator"); } -void TilesManager::allocateTiles() +void TilesManager::allocateTextures() { - int nbTexturesToAllocate = m_maxTextureCount - m_textures.size(); - ALOGV("%d tiles to allocate (%d textures planned)", nbTexturesToAllocate, m_maxTextureCount); + int nbTexturesToAllocate = m_currentTextureCount - m_textures.size(); + ALOGV("%d tiles to allocate (%d textures planned)", nbTexturesToAllocate, m_currentTextureCount); int nbTexturesAllocated = 0; for (int i = 0; i < nbTexturesToAllocate; i++) { TileTexture* texture = new TileTexture( @@ -124,9 +126,9 @@ void TilesManager::allocateTiles() nbTexturesAllocated++; } - int nbLayersTexturesToAllocate = m_maxLayerTextureCount - m_tilesTextures.size(); + int nbLayersTexturesToAllocate = m_currentLayerTextureCount - m_tilesTextures.size(); ALOGV("%d layers tiles to allocate (%d textures planned)", - nbLayersTexturesToAllocate, m_maxLayerTextureCount); + nbLayersTexturesToAllocate, m_currentLayerTextureCount); int nbLayersTexturesAllocated = 0; for (int i = 0; i < nbLayersTexturesToAllocate; i++) { TileTexture* texture = new TileTexture( @@ -202,9 +204,9 @@ void TilesManager::discardTexturesVector(unsigned long long sparedDrawCount, textures.remove(discardedIndex[i]); int remainedTextureNumber = textures.size(); - int* countPtr = base ? &m_maxTextureCount : &m_maxLayerTextureCount; + int* countPtr = base ? &m_currentTextureCount : &m_currentLayerTextureCount; if (remainedTextureNumber < *countPtr) { - ALOGV("reset maxTextureCount for %s tiles from %d to %d", + ALOGV("reset currentTextureCount for %s tiles from %d to %d", base ? "base" : "layer", *countPtr, remainedTextureNumber); *countPtr = remainedTextureNumber; } @@ -356,41 +358,39 @@ bool TilesManager::highEndGfx() return m_highEndGfx; } -int TilesManager::maxTextureCount() +int TilesManager::currentTextureCount() { android::Mutex::Autolock lock(m_texturesLock); - return m_maxTextureCount; + return m_currentTextureCount; } -int TilesManager::maxLayerTextureCount() +int TilesManager::currentLayerTextureCount() { android::Mutex::Autolock lock(m_texturesLock); - return m_maxLayerTextureCount; + return m_currentLayerTextureCount; } -void TilesManager::setMaxTextureCount(int max) +void TilesManager::setCurrentTextureCount(int newTextureCount) { - ALOGV("setMaxTextureCount: %d (current: %d, total:%d)", - max, m_maxTextureCount, MAX_TEXTURE_ALLOCATION); - if (m_maxTextureCount == MAX_TEXTURE_ALLOCATION || - max <= m_maxTextureCount) + int maxTextureAllocation = getMaxTextureAllocation(); + ALOGV("setCurrentTextureCount: %d (current: %d, max:%d)", + newTextureCount, m_currentTextureCount, maxTextureAllocation); + if (m_currentTextureCount == maxTextureAllocation || + newTextureCount <= m_currentTextureCount) return; android::Mutex::Autolock lock(m_texturesLock); + m_currentTextureCount = std::min(newTextureCount, maxTextureAllocation); - if (max < MAX_TEXTURE_ALLOCATION) - m_maxTextureCount = max; - else - m_maxTextureCount = MAX_TEXTURE_ALLOCATION; - - allocateTiles(); + allocateTextures(); } -void TilesManager::setMaxLayerTextureCount(int max) +void TilesManager::setCurrentLayerTextureCount(int newTextureCount) { - ALOGV("setMaxLayerTextureCount: %d (current: %d, total:%d)", - max, m_maxLayerTextureCount, MAX_TEXTURE_ALLOCATION); - if (!max && m_hasLayerTextures) { + int maxTextureAllocation = getMaxTextureAllocation(); + ALOGV("setCurrentLayerTextureCount: %d (current: %d, max:%d)", + newTextureCount, m_currentLayerTextureCount, maxTextureAllocation); + if (!newTextureCount && m_hasLayerTextures) { double secondsSinceLayersUsed = WTF::currentTime() - m_lastTimeLayersUsed; if (secondsSinceLayersUsed > LAYER_TEXTURES_DESTROY_TIMEOUT) { unsigned long long sparedDrawCount = ~0; // by default, spare no textures @@ -401,18 +401,14 @@ void TilesManager::setMaxLayerTextureCount(int max) return; } m_lastTimeLayersUsed = WTF::currentTime(); - if (m_maxLayerTextureCount == MAX_TEXTURE_ALLOCATION || - max <= m_maxLayerTextureCount) + if (m_currentLayerTextureCount == maxTextureAllocation || + newTextureCount <= m_currentLayerTextureCount) return; android::Mutex::Autolock lock(m_texturesLock); + m_currentLayerTextureCount = std::min(newTextureCount, maxTextureAllocation); - if (max < MAX_TEXTURE_ALLOCATION) - m_maxLayerTextureCount = max; - else - m_maxLayerTextureCount = MAX_TEXTURE_ALLOCATION; - - allocateTiles(); + allocateTextures(); m_hasLayerTextures = true; } diff --git a/Source/WebCore/platform/graphics/android/rendering/TilesManager.h b/Source/WebCore/platform/graphics/android/rendering/TilesManager.h index 17d44b5..834f36d 100644 --- a/Source/WebCore/platform/graphics/android/rendering/TilesManager.h +++ b/Source/WebCore/platform/graphics/android/rendering/TilesManager.h @@ -47,8 +47,6 @@ class TilesManager { public: // May only be called from the UI thread static TilesManager* instance(); - static GLint getMaxTextureSize(); - static int getMaxTextureAllocation(); static bool hardwareAccelerationEnabled() { @@ -85,14 +83,14 @@ public: void setHighEndGfx(bool highEnd); bool highEndGfx(); - int maxTextureCount(); - int maxLayerTextureCount(); - void setMaxTextureCount(int max); - void setMaxLayerTextureCount(int max); + int currentTextureCount(); + int currentLayerTextureCount(); + void setCurrentTextureCount(int newTextureCount); + void setCurrentLayerTextureCount(int newTextureCount); static float tileWidth(); static float tileHeight(); - void allocateTiles(); + void allocateTextures(); // remove all tiles from textures (and optionally deallocate gl memory) void discardTextures(bool allTextures, bool glTextures); @@ -168,6 +166,7 @@ private: bool deallocateGLTextures); void markAllGLTexturesZero(); bool updateContextIfChanged(); + int getMaxTextureAllocation(); WTF::Vector m_textures; WTF::Vector m_availableTextures; @@ -177,8 +176,9 @@ private: bool m_layerTexturesRemain; bool m_highEndGfx; - int m_maxTextureCount; - int m_maxLayerTextureCount; + int m_currentTextureCount; + int m_currentLayerTextureCount; + int m_maxTextureAllocation; bool m_generatorReady; -- cgit v1.1