OSDN Git Service

tile prefetching now triggered automatically
authorChris Craik <ccraik@google.com>
Wed, 17 Aug 2011 18:59:05 +0000 (11:59 -0700)
committerChris Craik <ccraik@google.com>
Thu, 18 Aug 2011 00:10:32 +0000 (17:10 -0700)
bug:5178457
bug:5168261
Tiles are now prefetched at a distance of 2 from the view if the content is at
least 1.2x the size of the view (in each dimension independantly)

Change-Id: I1c251ffbbae709f8924133b9b22df39b4fa88b4c

Source/WebCore/platform/graphics/android/GLWebViewState.cpp
Source/WebCore/platform/graphics/android/GLWebViewState.h
Source/WebCore/platform/graphics/android/TiledPage.cpp
Source/WebCore/platform/graphics/android/TilesManager.cpp
Source/WebCore/platform/graphics/android/TilesManager.h
Source/WebKit/android/nav/WebView.cpp

index 9978327..c821523 100644 (file)
@@ -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);
index 82b6f12..f3cbf74 100644 (file)
 // #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
index a8be501..2776181 100644 (file)
@@ -258,25 +258,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 +313,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];
index c634be0..fc7feb6 100644 (file)
 
 #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)
@@ -342,14 +330,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);
index 8f0ac7f..66de048 100644 (file)
@@ -106,18 +106,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;
@@ -175,7 +168,6 @@ private:
     unsigned int m_layersMemoryUsage;
 
     int m_maxTextureCount;
-    bool m_expandedTileBounds;
 
     bool m_generatorReady;
 
index c1cb95c..95c560d 100644 (file)
@@ -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",