summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/WebCore/platform/graphics/android/GLWebViewState.cpp8
-rw-r--r--Source/WebCore/platform/graphics/android/rendering/TilesManager.cpp94
-rw-r--r--Source/WebCore/platform/graphics/android/rendering/TilesManager.h18
-rw-r--r--Source/WebKit/android/nav/WebView.cpp10
4 files changed, 66 insertions, 64 deletions
diff --git a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp
index 398beea..89c0ead 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<TileTexture*> m_textures;
WTF::Vector<TileTexture*> 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;
diff --git a/Source/WebKit/android/nav/WebView.cpp b/Source/WebKit/android/nav/WebView.cpp
index 0caa624..51ffdfe 100644
--- a/Source/WebKit/android/nav/WebView.cpp
+++ b/Source/WebKit/android/nav/WebView.cpp
@@ -304,8 +304,14 @@ PictureSet* draw(SkCanvas* canvas, SkColor bgColor, DrawExtras extras, bool spli
// draw the content of the base layer first
LayerContent* content = m_baseLayer->content();
int sc = canvas->save(SkCanvas::kClip_SaveFlag);
- canvas->clipRect(SkRect::MakeLTRB(0, 0, content->width(),
- content->height()), SkRegion::kDifference_Op);
+ int contentWidth = 0;
+ int contentHeight = 0;
+ if (content) {
+ contentWidth = content->width();
+ contentHeight = content->height();
+ }
+ canvas->clipRect(SkRect::MakeLTRB(0, 0, contentWidth, contentHeight),
+ SkRegion::kDifference_Op);
Color c = m_baseLayer->getBackgroundColor();
canvas->drawColor(SkColorSetARGBInline(c.alpha(), c.red(), c.green(), c.blue()));
canvas->restoreToCount(sc);