summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/WebCore/platform/graphics/android/GLWebViewState.cpp21
-rw-r--r--Source/WebCore/platform/graphics/android/GLWebViewState.h12
-rw-r--r--Source/WebCore/platform/graphics/android/PaintTileOperation.cpp6
-rw-r--r--Source/WebCore/platform/graphics/android/TiledPage.cpp35
-rw-r--r--Source/WebCore/platform/graphics/android/TilesManager.cpp66
-rw-r--r--Source/WebCore/platform/graphics/android/TilesManager.h14
-rw-r--r--Source/WebCore/platform/graphics/android/TransferQueue.cpp64
-rw-r--r--Source/WebKit/android/nav/WebView.cpp7
8 files changed, 117 insertions, 108 deletions
diff --git a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp
index 9978327..c54977d 100644
--- a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp
+++ b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp
@@ -83,6 +83,8 @@ GLWebViewState::GLWebViewState(android::Mutex* buttonMutex)
, m_focusRingTexture(-1)
, m_goingDown(true)
, m_goingLeft(false)
+ , m_expandedTileBoundsX(0)
+ , m_expandedTileBoundsY(0)
{
m_viewport.setEmpty();
m_previousViewport.setEmpty();
@@ -426,12 +428,11 @@ void GLWebViewState::swapPages()
int GLWebViewState::baseContentWidth()
{
- return m_currentBaseLayer ? m_currentBaseLayer->getWidth() : 0;
-
+ return m_currentBaseLayer ? m_currentBaseLayer->content()->width() : 0;
}
int GLWebViewState::baseContentHeight()
{
- return m_currentBaseLayer ? m_currentBaseLayer->getHeight() : 0;
+ return m_currentBaseLayer ? m_currentBaseLayer->content()->height() : 0;
}
void GLWebViewState::setViewport(SkRect& viewport, float scale)
@@ -455,8 +456,8 @@ void GLWebViewState::setViewport(SkRect& viewport, float scale)
static_cast<int>(ceilf(viewport.fRight * invTileContentWidth)),
static_cast<int>(ceilf(viewport.fBottom * invTileContentHeight)));
- int maxTextureCount = (m_viewportTileBounds.width() + TilesManager::instance()->expandedTileBoundsX() * 2 + 1) *
- (m_viewportTileBounds.height() + TilesManager::instance()->expandedTileBoundsY() * 2 + 1) * 2;
+ int maxTextureCount = (m_viewportTileBounds.width() + TILE_PREFETCH_DISTANCE * 2 + 1) *
+ (m_viewportTileBounds.height() + TILE_PREFETCH_DISTANCE * 2 + 1) * 2;
TilesManager::instance()->setMaxTextureCount(maxTextureCount);
m_tiledPageA->updateBaseTileSize();
m_tiledPageB->updateBaseTileSize();
@@ -532,6 +533,13 @@ bool GLWebViewState::drawGL(IntRect& rect, SkRect& viewport, IntRect* invalRect,
return false;
}
+ float viewWidth = (viewport.fRight - viewport.fLeft) * TILE_PREFETCH_RATIO;
+ float viewHeight = (viewport.fBottom - viewport.fTop) * TILE_PREFETCH_RATIO;
+ bool useHorzPrefetch = viewWidth < baseContentWidth();
+ bool useVertPrefetch = viewHeight < baseContentHeight();
+ m_expandedTileBoundsX = (useHorzPrefetch) ? TILE_PREFETCH_DISTANCE : 0;
+ m_expandedTileBoundsY = (useVertPrefetch) ? TILE_PREFETCH_DISTANCE : 0;
+
XLOG("drawGL, rect(%d, %d, %d, %d), viewport(%.2f, %.2f, %.2f, %.2f)",
rect.x(), rect.y(), rect.width(), rect.height(),
viewport.fLeft, viewport.fTop, viewport.fRight, viewport.fBottom);
@@ -554,6 +562,9 @@ bool GLWebViewState::drawGL(IntRect& rect, SkRect& viewport, IntRect* invalRect,
// the BaseTiles' texture.
TilesManager::instance()->transferQueue()->updateDirtyBaseTiles();
+ // gather the textures we can use
+ TilesManager::instance()->gatherLayerTextures();
+
if (compositedRoot != m_previouslyUsedRoot)
TilesManager::instance()->swapLayersTextures(m_previouslyUsedRoot, compositedRoot);
diff --git a/Source/WebCore/platform/graphics/android/GLWebViewState.h b/Source/WebCore/platform/graphics/android/GLWebViewState.h
index 82b6f12..f3cbf74 100644
--- a/Source/WebCore/platform/graphics/android/GLWebViewState.h
+++ b/Source/WebCore/platform/graphics/android/GLWebViewState.h
@@ -42,6 +42,12 @@
// #define MEASURES_PERF
#define MAX_MEASURES_PERF 2000
+// Prefetch and render 2 tiles ahead of the scroll
+#define TILE_PREFETCH_DISTANCE 2
+
+// ratio of content to view required for prefetching to enable
+#define TILE_PREFETCH_RATIO 1.2
+
namespace WebCore {
class BaseLayerAndroid;
@@ -248,6 +254,9 @@ public:
m_goingLeft = goingLeft;
}
+ int expandedTileBoundsX() { return m_expandedTileBoundsX; }
+ int expandedTileBoundsY() { return m_expandedTileBoundsY; }
+
private:
void inval(const IntRect& rect); // caller must hold m_baseLayerLock
void invalRegion(const SkRegion& region);
@@ -308,6 +317,9 @@ private:
bool m_goingDown;
bool m_goingLeft;
+
+ int m_expandedTileBoundsX;
+ int m_expandedTileBoundsY;
};
} // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/android/PaintTileOperation.cpp b/Source/WebCore/platform/graphics/android/PaintTileOperation.cpp
index 064ffb9..3aac918 100644
--- a/Source/WebCore/platform/graphics/android/PaintTileOperation.cpp
+++ b/Source/WebCore/platform/graphics/android/PaintTileOperation.cpp
@@ -76,8 +76,12 @@ int PaintTileOperation::priority()
if (!m_tile || m_tile->usedLevel() < 0)
return -1;
+ // for now, use a constant value for layers,
+ // lower than the base layer tiles (as layers
+ // will always be on top of the base surface)
if (m_tile->isLayerTile())
- return 25; // for now, use a constant value.
+ return -2;
+
bool goingDown = m_tile->page()->scrollingDown();
SkIRect *rect = m_tile->page()->expandedTileBounds();
diff --git a/Source/WebCore/platform/graphics/android/TiledPage.cpp b/Source/WebCore/platform/graphics/android/TiledPage.cpp
index a8be501..a69f9d1 100644
--- a/Source/WebCore/platform/graphics/android/TiledPage.cpp
+++ b/Source/WebCore/platform/graphics/android/TiledPage.cpp
@@ -245,6 +245,7 @@ void TiledPage::prepare(bool goingDown, bool goingLeft, const SkIRect& tileBound
if (!m_glWebViewState)
return;
+ TilesManager::instance()->gatherTextures();
// update the tiles distance from the viewport
updateTileState(tileBounds);
m_prepare = true;
@@ -258,25 +259,21 @@ void TiledPage::prepare(bool goingDown, bool goingLeft, const SkIRect& tileBound
int lastTileX = tileBounds.fRight - 1;
int lastTileY = tileBounds.fBottom - 1;
- const int baseContentHeight = m_glWebViewState->baseContentHeight();
- const int baseContentWidth = m_glWebViewState->baseContentWidth();
-
// Expand number of tiles to allow tiles outside of viewport to be prepared for
// smoother scrolling.
int nTilesToPrepare = nbTilesWidth * nbTilesHeight;
int nMaxTilesPerPage = m_baseTileSize / 2;
- int expandX = TilesManager::instance()->expandedTileBoundsX();
- int expandY = TilesManager::instance()->expandedTileBoundsY();
- if (nTilesToPrepare + (nbTilesHeight * expandX * 2) <= nMaxTilesPerPage) {
- firstTileX -= expandX;
- lastTileX += expandX;
- nbTilesWidth += expandX * 2;
- }
- if (nTilesToPrepare + (nbTilesWidth * expandY * 2) <= nMaxTilesPerPage) {
- firstTileY -= expandY;
- lastTileY += expandY;
- nbTilesHeight += expandY * 2;
- }
+ int expandX = m_glWebViewState->expandedTileBoundsX();
+ int expandY = m_glWebViewState->expandedTileBoundsY();
+
+ firstTileX -= expandX;
+ lastTileX += expandX;
+ nbTilesWidth += expandX * 2;
+
+ firstTileY -= expandY;
+ lastTileY += expandY;
+ nbTilesHeight += expandY * 2;
+
m_expandedTileBounds.fLeft = firstTileX;
m_expandedTileBounds.fTop = firstTileY;
m_expandedTileBounds.fRight = lastTileX;
@@ -317,10 +314,10 @@ void TiledPage::draw(float transparency, const SkIRect& tileBounds)
const float tileHeight = TilesManager::tileHeight() * m_invScale;
SkIRect actualTileBounds = tileBounds;
- actualTileBounds.fTop -= TilesManager::instance()->expandedTileBoundsY();
- actualTileBounds.fBottom += TilesManager::instance()->expandedTileBoundsY();
- actualTileBounds.fLeft -= TilesManager::instance()->expandedTileBoundsX();
- actualTileBounds.fRight += TilesManager::instance()->expandedTileBoundsX();
+ actualTileBounds.fTop -= m_glWebViewState->expandedTileBoundsY();
+ actualTileBounds.fBottom += m_glWebViewState->expandedTileBoundsY();
+ actualTileBounds.fLeft -= m_glWebViewState->expandedTileBoundsX();
+ actualTileBounds.fRight += m_glWebViewState->expandedTileBoundsX();
for (int j = 0; j < m_baseTileSize; j++) {
BaseTile& tile = m_baseTiles[j];
diff --git a/Source/WebCore/platform/graphics/android/TilesManager.cpp b/Source/WebCore/platform/graphics/android/TilesManager.cpp
index c634be0..6e1ce31 100644
--- a/Source/WebCore/platform/graphics/android/TilesManager.cpp
+++ b/Source/WebCore/platform/graphics/android/TilesManager.cpp
@@ -58,19 +58,8 @@
#endif // DEBUG
-// Important: We need at least twice as much textures as is needed to cover
-// 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 300x300 textures. On the tablet, this equates to
-// at least 24 textures. That is consuming almost 50MB GPU memory.
-// 24*300*300*4(bpp)*2(pages)*3(triple buffering in Surface Texture) = 49.4MB
-// In order to avoid OOM issue, we limit the bounds number to 0 for now.
-// TODO: We should either dynamically change the outer bound by detecting the
-// HW limit or save further in the GPU memory consumption.
-#define EXPANDED_TILE_BOUNDS_X 0
-#define EXPANDED_TILE_BOUNDS_Y 0
-#define MAX_TEXTURE_ALLOCATION 3+(6+EXPANDED_TILE_BOUNDS_X*2)*(4+EXPANDED_TILE_BOUNDS_Y*2)*2
+// Number of tiles for base layer
+#define MAX_TEXTURE_ALLOCATION 51
#define TILE_WIDTH 256
#define TILE_HEIGHT 256
#define LAYER_TILE_WIDTH 256
@@ -101,7 +90,6 @@ int TilesManager::getMaxTextureAllocation()
TilesManager::TilesManager()
: m_layersMemoryUsage(0)
, m_maxTextureCount(0)
- , m_expandedTileBounds(false)
, m_generatorReady(false)
, m_showVisualIndicator(false)
, m_invertedScreen(false)
@@ -109,6 +97,9 @@ TilesManager::TilesManager()
{
XLOG("TilesManager ctor");
m_textures.reserveCapacity(MAX_TEXTURE_ALLOCATION);
+ m_availableTextures.reserveCapacity(MAX_TEXTURE_ALLOCATION);
+ m_tilesTextures.reserveCapacity(LAYER_TILES);
+ m_availableTilesTextures.reserveCapacity(LAYER_TILES);
m_pixmapsGenerationThread = new TexturesGenerator();
m_pixmapsGenerationThread->run("TexturesGenerator");
}
@@ -212,6 +203,18 @@ void TilesManager::addPaintedSurface(PaintedSurface* surface)
m_paintedSurfaces.append(surface);
}
+void TilesManager::gatherTextures()
+{
+ android::Mutex::Autolock lock(m_texturesLock);
+ m_availableTextures = m_textures;
+}
+
+void TilesManager::gatherLayerTextures()
+{
+ android::Mutex::Autolock lock(m_texturesLock);
+ m_availableTilesTextures = m_tilesTextures;
+}
+
BaseTileTexture* TilesManager::getAvailableTexture(BaseTile* owner)
{
android::Mutex::Autolock lock(m_texturesLock);
@@ -221,26 +224,36 @@ BaseTileTexture* TilesManager::getAvailableTexture(BaseTile* owner)
owner->texture()->setUsedLevel(0);
XLOG("same owner (%d, %d), getAvailableTexture(%x) => texture %x",
owner->x(), owner->y(), owner, owner->texture());
+ if (owner->isLayerTile())
+ m_availableTilesTextures.remove(m_availableTilesTextures.find(owner->texture()));
+ else
+ m_availableTextures.remove(m_availableTextures.find(owner->texture()));
return owner->texture();
}
if (owner->isLayerTile()) {
- unsigned int max = m_tilesTextures.size();
+ BaseTileTexture* layerTexture = 0;
+ unsigned int max = m_availableTilesTextures.size();
for (unsigned int i = 0; i < max; i++) {
- BaseTileTexture* texture = m_tilesTextures[i];
+ BaseTileTexture* texture = m_availableTilesTextures[i];
if (texture->owner() && texture->owner()->isRepaintPending())
continue;
if (!texture->owner() && texture->acquire(owner)) {
- return texture;
+ layerTexture = texture;
+ break;
}
if (texture->usedLevel() != 0 && texture->acquire(owner)) {
- return texture;
+ layerTexture = texture;
+ break;
}
if (texture->scale() != owner->scale() && texture->acquire(owner)) {
- return texture;
+ layerTexture = texture;
+ break;
}
}
- return 0;
+ if (layerTexture)
+ m_availableTilesTextures.remove(m_availableTilesTextures.find(layerTexture));
+ return layerTexture;
}
// The heuristic for selecting a texture is as follows:
@@ -251,9 +264,9 @@ BaseTileTexture* TilesManager::getAvailableTexture(BaseTile* owner)
BaseTileTexture* farthestTexture = 0;
int farthestTextureLevel = 0;
unsigned int lowestDrawCount = ~0; //maximum uint
- const unsigned int max = m_textures.size();
+ const unsigned int max = m_availableTextures.size();
for (unsigned int i = 0; i < max; i++) {
- BaseTileTexture* texture = m_textures[i];
+ BaseTileTexture* texture = m_availableTextures[i];
if (texture->usedLevel() == -1) { // found an unused texture, grab it
farthestTexture = texture;
@@ -276,6 +289,7 @@ BaseTileTexture* TilesManager::getAvailableTexture(BaseTile* owner)
XLOG("farthest texture, getAvailableTexture(%x) => texture %x (level %d, drawCount %d)",
owner, farthestTexture, farthestTextureLevel, lowestDrawCount);
farthestTexture->setUsedLevel(0);
+ m_availableTextures.remove(m_availableTextures.find(farthestTexture));
return farthestTexture;
}
@@ -342,14 +356,6 @@ float TilesManager::layerTileHeight()
return LAYER_TILE_HEIGHT;
}
-int TilesManager::expandedTileBoundsX() {
- return m_expandedTileBounds ? EXPANDED_TILE_BOUNDS_X : 0;
-}
-
-int TilesManager::expandedTileBoundsY() {
- return m_expandedTileBounds ? EXPANDED_TILE_BOUNDS_Y : 0;
-}
-
void TilesManager::registerGLWebViewState(GLWebViewState* state)
{
m_glWebViewStateMap.set(state, m_drawRegistrationCount);
diff --git a/Source/WebCore/platform/graphics/android/TilesManager.h b/Source/WebCore/platform/graphics/android/TilesManager.h
index 8f0ac7f..471bece 100644
--- a/Source/WebCore/platform/graphics/android/TilesManager.h
+++ b/Source/WebCore/platform/graphics/android/TilesManager.h
@@ -83,6 +83,8 @@ public:
TransferQueue* transferQueue() { return &m_queue; }
VideoLayerManager* videoLayerManager() { return &m_videoLayerManager; }
+ void gatherLayerTextures();
+ void gatherTextures();
BaseTileTexture* getAvailableTexture(BaseTile* owner);
void markGeneratorAsReady()
@@ -106,18 +108,11 @@ public:
static float tileHeight();
static float layerTileWidth();
static float layerTileHeight();
- int expandedTileBoundsX();
- int expandedTileBoundsY();
void registerGLWebViewState(GLWebViewState* state);
void unregisterGLWebViewState(GLWebViewState* state);
void allocateTiles();
- void setExpandedTileBounds(bool enabled)
- {
- m_expandedTileBounds = enabled;
- }
-
bool getShowVisualIndicator()
{
return m_showVisualIndicator;
@@ -169,13 +164,16 @@ private:
}
Vector<BaseTileTexture*> m_textures;
+ Vector<BaseTileTexture*> m_availableTextures;
+
Vector<BaseTileTexture*> m_tilesTextures;
+ Vector<BaseTileTexture*> m_availableTilesTextures;
+
Vector<PaintedSurface*> m_paintedSurfaces;
unsigned int m_layersMemoryUsage;
int m_maxTextureCount;
- bool m_expandedTileBounds;
bool m_generatorReady;
diff --git a/Source/WebCore/platform/graphics/android/TransferQueue.cpp b/Source/WebCore/platform/graphics/android/TransferQueue.cpp
index 1a377f2..8b4b596 100644
--- a/Source/WebCore/platform/graphics/android/TransferQueue.cpp
+++ b/Source/WebCore/platform/graphics/android/TransferQueue.cpp
@@ -297,50 +297,38 @@ void TransferQueue::updateQueueWithBitmap(const TileRenderInfo* renderInfo,
renderInfo->x, renderInfo->y);
return;
}
- // Dequeue the Surface Texture.
- sp<ANativeWindow> ANW = m_ANW;
- if (!ANW.get()) {
+
+ // a) Dequeue the Surface Texture and write into the buffer
+ if (!m_ANW.get()) {
XLOG("ERROR: ANW is null");
return;
}
- ANativeWindowBuffer* anb;
-
- int status = ANW->dequeueBuffer(ANW.get(), &anb);
- GLUtils::checkSurfaceTextureError("dequeueBuffer", status);
- // a) Update surface texture
- sp<android::GraphicBuffer> buf(new android::GraphicBuffer(anb, false));
- status |= ANW->lockBuffer(ANW.get(), buf->getNativeBuffer()); // Mutex Lock
- GLUtils::checkSurfaceTextureError("lockBuffer", status);
-
- // Fill the buffer with the content of the bitmap
- uint8_t* img = 0;
- status |= buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
- GLUtils::checkSurfaceTextureError("lock", status);
-
- if (status == NO_ERROR) {
- int row, col;
- int bpp = 4; // Now we only deal with RGBA8888 format.
- int width = TilesManager::instance()->tileWidth();
- int height = TilesManager::instance()->tileHeight();
- if (!x && !y && bitmap.width() == width && bitmap.height() == height) {
- bitmap.lockPixels();
- uint8_t* bitmapOrigin = static_cast<uint8_t*>(bitmap.getPixels());
- // Copied line by line since we need to handle the offsets and stride.
- for (row = 0 ; row < bitmap.height(); row ++) {
- uint8_t* dst = &(img[(buf->getStride() * (row + x) + y) * bpp]);
- uint8_t* src = &(bitmapOrigin[bitmap.width() * row * bpp]);
- memcpy(dst, src, bpp * bitmap.width());
- }
- bitmap.unlockPixels();
- } else {
- // TODO: implement the partial invalidate here!
- XLOG("ERROR: don't expect to get here yet before we support partial inval");
+
+ ANativeWindow_Buffer buffer;
+ if (ANativeWindow_lock(m_ANW.get(), &buffer, 0))
+ return;
+
+ uint8_t* img = (uint8_t*)buffer.bits;
+ int row, col;
+ int bpp = 4; // Now we only deal with RGBA8888 format.
+ int width = TilesManager::instance()->tileWidth();
+ int height = TilesManager::instance()->tileHeight();
+ if (!x && !y && bitmap.width() == width && bitmap.height() == height) {
+ bitmap.lockPixels();
+ uint8_t* bitmapOrigin = static_cast<uint8_t*>(bitmap.getPixels());
+ // Copied line by line since we need to handle the offsets and stride.
+ for (row = 0 ; row < bitmap.height(); row ++) {
+ uint8_t* dst = &(img[(buffer.stride * (row + x) + y) * bpp]);
+ uint8_t* src = &(bitmapOrigin[bitmap.width() * row * bpp]);
+ memcpy(dst, src, bpp * bitmap.width());
}
+ bitmap.unlockPixels();
+ } else {
+ // TODO: implement the partial invalidate here!
+ XLOG("ERROR: don't expect to get here yet before we support partial inval");
}
- buf->unlock();
- status = ANW->queueBuffer(ANW.get(), buf->getNativeBuffer());
- GLUtils::checkSurfaceTextureError("queueBuffer", status);
+ ANativeWindow_unlockAndPost(m_ANW.get());
// b) After update the Surface Texture, now udpate the transfer queue info.
addItemInTransferQueue(renderInfo);
diff --git a/Source/WebKit/android/nav/WebView.cpp b/Source/WebKit/android/nav/WebView.cpp
index c1cb95c..95c560d 100644
--- a/Source/WebKit/android/nav/WebView.cpp
+++ b/Source/WebKit/android/nav/WebView.cpp
@@ -2608,11 +2608,6 @@ static bool nativeScrollLayer(JNIEnv* env, jobject obj, jint layerId, jint x,
return false;
}
-static void nativeSetExpandedTileBounds(JNIEnv*, jobject, jboolean enabled)
-{
- TilesManager::instance()->setExpandedTileBounds(enabled);
-}
-
static void nativeUseHardwareAccelSkia(JNIEnv*, jobject, jboolean enabled)
{
BaseRenderer::setCurrentRendererType(enabled ? BaseRenderer::Ganesh : BaseRenderer::Raster);
@@ -2827,8 +2822,6 @@ static JNINativeMethod gJavaWebViewMethods[] = {
(void*) nativeScrollableLayer },
{ "nativeScrollLayer", "(III)Z",
(void*) nativeScrollLayer },
- { "nativeSetExpandedTileBounds", "(Z)V",
- (void*) nativeSetExpandedTileBounds },
{ "nativeUseHardwareAccelSkia", "(Z)V",
(void*) nativeUseHardwareAccelSkia },
{ "nativeGetBackgroundColor", "()I",