diff options
-rw-r--r-- | WebCore/platform/graphics/android/GLWebViewState.cpp | 3 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/TiledPage.cpp | 50 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/TilesManager.cpp | 17 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/TilesManager.h | 7 | ||||
-rw-r--r-- | WebKit/android/jni/WebViewCore.cpp | 12 |
5 files changed, 56 insertions, 33 deletions
diff --git a/WebCore/platform/graphics/android/GLWebViewState.cpp b/WebCore/platform/graphics/android/GLWebViewState.cpp index 63fe730..38b747d 100644 --- a/WebCore/platform/graphics/android/GLWebViewState.cpp +++ b/WebCore/platform/graphics/android/GLWebViewState.cpp @@ -288,7 +288,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()+1)*(m_viewportTileBounds.height()+1)*2; + int maxTextureCount = (m_viewportTileBounds.width() + TilesManager::instance()->expandedTileBoundsX() * 2 + 1) * + (m_viewportTileBounds.height() + TilesManager::instance()->expandedTileBoundsY() * 2 + 1) * 2; TilesManager::instance()->setMaxTextureCount(maxTextureCount); m_tiledPageA->updateBaseTileSize(); m_tiledPageB->updateBaseTileSize(); diff --git a/WebCore/platform/graphics/android/TiledPage.cpp b/WebCore/platform/graphics/android/TiledPage.cpp index b6d2205..620aa6f 100644 --- a/WebCore/platform/graphics/android/TiledPage.cpp +++ b/WebCore/platform/graphics/android/TiledPage.cpp @@ -244,43 +244,29 @@ void TiledPage::prepare(bool goingDown, bool goingLeft, const SkIRect& tileBound int nbTilesWidth = tileBounds.width(); int nbTilesHeight = tileBounds.height(); - const int lastTileX = tileBounds.fRight - 1; - const int lastTileY = tileBounds.fBottom - 1; + int lastTileX = tileBounds.fRight - 1; + int lastTileY = tileBounds.fBottom - 1; const int baseContentHeight = m_glWebViewState->baseContentHeight(); const int baseContentWidth = m_glWebViewState->baseContentWidth(); TileSet* highResSet = new TileSet(this, nbTilesHeight, nbTilesWidth); + // 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; - - // PREPARE OFF-SCREEN TILES FOR SMOOTHER SCROLLING - // if you are going down and you are not already at the bottom of the page - // go ahead and prepare the tiles just off-screen beneath the viewport. - // Ensure we have enough tiles to do this with. - if (nTilesToPrepare + nbTilesWidth <= nMaxTilesPerPage) { - if (goingDown && baseContentHeight > lastTileY * TilesManager::tileHeight()) - nbTilesHeight++; - // if you are going up and you are not already at the top of the page go - // ahead and prepare the tiles just off-screen above the viewport. - else if (!goingDown && firstTileY > 0) { - firstTileY--; - nbTilesHeight++; - } + 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 + nbTilesHeight <= nMaxTilesPerPage) { - // if you are going right and you are not already at the edge of the page go - // ahead and prepare the tiles just off-screen to the right of the viewport. - if (!goingLeft && baseContentWidth > lastTileX * TilesManager::tileWidth()) - nbTilesWidth++; - // if you are going left and you are not already at the edge of the page go - // ahead and prepare the tiles just off-screen to the left of the viewport. - else if (goingLeft && firstTileX > 0) { - firstTileX--; - nbTilesWidth++; - } + if (nTilesToPrepare + (nbTilesWidth * expandY * 2) <= nMaxTilesPerPage) { + firstTileY -= expandY; + lastTileY += expandY; + nbTilesHeight += expandY * 2; } // We chose to prepare tiles depending on the scroll direction. Tiles are @@ -331,10 +317,16 @@ void TiledPage::draw(float transparency, const SkIRect& tileBounds) const float tileWidth = TilesManager::tileWidth() * m_invScale; 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(); + XLOG("WE DRAW %x (%.2f) with transparency %.2f", this, scale(), transparency); for (int j = 0; j < m_baseTileSize; j++) { BaseTile& tile = m_baseTiles[j]; - if (tileBounds.contains(tile.x(), tile.y())) { + if (actualTileBounds.contains(tile.x(), tile.y())) { SkRect rect; rect.fLeft = tile.x() * tileWidth; diff --git a/WebCore/platform/graphics/android/TilesManager.cpp b/WebCore/platform/graphics/android/TilesManager.cpp index 81b0404..21162ff 100644 --- a/WebCore/platform/graphics/android/TilesManager.cpp +++ b/WebCore/platform/graphics/android/TilesManager.cpp @@ -54,9 +54,11 @@ // 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 equals to -// at least 24 (6 * 4) textures, hence 48. -#define MAX_TEXTURE_ALLOCATION 48 +// In our case, we use 300x300 textures. On the tablet, this equates to +// at least 5 * 3 = 15 textures. We can also enable offscreen textures +#define EXPANDED_TILE_BOUNDS_X 1 +#define EXPANDED_TILE_BOUNDS_Y 4 +#define MAX_TEXTURE_ALLOCATION (5+EXPANDED_TILE_BOUNDS_X*2)*(3+EXPANDED_TILE_BOUNDS_Y*2)*2 #define TILE_WIDTH 300 #define TILE_HEIGHT 300 @@ -69,6 +71,7 @@ namespace WebCore { TilesManager::TilesManager() : m_layersMemoryUsage(0) , m_maxTextureCount(0) + , m_expandedTileBounds(false) , m_generatorReady(false) { XLOG("TilesManager ctor"); @@ -366,6 +369,14 @@ float TilesManager::tileHeight() return TILE_HEIGHT; } +int TilesManager::expandedTileBoundsX() { + return m_expandedTileBounds ? EXPANDED_TILE_BOUNDS_X : 0; +} + +int TilesManager::expandedTileBoundsY() { + return m_expandedTileBounds ? EXPANDED_TILE_BOUNDS_Y : 0; +} + TilesManager* TilesManager::instance() { if (!gInstance) { diff --git a/WebCore/platform/graphics/android/TilesManager.h b/WebCore/platform/graphics/android/TilesManager.h index 92306b5..de22242 100644 --- a/WebCore/platform/graphics/android/TilesManager.h +++ b/WebCore/platform/graphics/android/TilesManager.h @@ -90,9 +90,15 @@ public: void setMaxTextureCount(int max); static float tileWidth(); static float tileHeight(); + int expandedTileBoundsX(); + int expandedTileBoundsY(); void allocateTiles(); + void setExpandedTileBounds(bool enabled) { + m_expandedTileBounds = enabled; + } + private: TilesManager(); @@ -112,6 +118,7 @@ private: unsigned int m_totalMaxTextureSize; int m_maxTextureCount; + bool m_expandedTileBounds; bool m_generatorReady; diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index 3328acd..5a16461 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -108,6 +108,7 @@ #include "SkPicture.h" #include "SkUtils.h" #include "Text.h" +#include "TilesManager.h" #include "TypingCommand.h" #include "WebCoreFrameBridge.h" #include "WebFrameView.h" @@ -4511,6 +4512,15 @@ static void AutoFillForm(JNIEnv* env, jobject obj, jint queryId) #endif } +static void SetExpandedTileBounds(JNIEnv *env, jobject obj, jboolean enabled) +{ + WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj); + if (!viewImpl) + return; + TilesManager::instance()->setExpandedTileBounds(enabled); +} + + // ---------------------------------------------------------------------------- /* @@ -4618,6 +4628,8 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = { (void*) GetTouchHighlightRects }, { "nativeAutoFillForm", "(I)V", (void*) AutoFillForm }, + { "nativeSetExpandedTileBounds", "(Z)V", + (void*) SetExpandedTileBounds }, }; int registerWebViewCore(JNIEnv* env) |