#endif // DEBUG
+// TODO: dynamically determine based on DPI
+#define PREFETCH_SCALE_MODIFIER 0.3
+#define PREFETCH_OPACITY 1
+#define PREFETCH_X_DIST 1
+#define PREFETCH_Y_DIST 2
+
namespace WebCore {
using namespace android;
}
#if USE(ACCELERATED_COMPOSITING)
+
+void BaseLayerAndroid::prefetchBasePicture(SkRect& viewport, float currentScale,
+ TiledPage* prefetchTiledPage)
+{
+ SkIRect bounds;
+ float prefetchScale = currentScale * PREFETCH_SCALE_MODIFIER;
+
+ float invTileWidth = (prefetchScale)
+ / TilesManager::instance()->tileWidth();
+ float invTileHeight = (prefetchScale)
+ / TilesManager::instance()->tileHeight();
+ bool goingDown = m_glWebViewState->goingDown();
+ bool goingLeft = m_glWebViewState->goingLeft();
+
+
+ XLOG("fetch rect %f %f %f %f, scale %f",
+ viewport.fLeft,
+ viewport.fTop,
+ viewport.fRight,
+ viewport.fBottom,
+ scale);
+
+ bounds.fLeft = static_cast<int>(floorf(viewport.fLeft * invTileWidth)) - PREFETCH_X_DIST;
+ bounds.fTop = static_cast<int>(floorf(viewport.fTop * invTileHeight)) - PREFETCH_Y_DIST;
+ bounds.fRight = static_cast<int>(ceilf(viewport.fRight * invTileWidth)) + PREFETCH_X_DIST;
+ bounds.fBottom = static_cast<int>(ceilf(viewport.fBottom * invTileHeight)) + PREFETCH_Y_DIST;
+
+ XLOG("prefetch rect %d %d %d %d, scale %f, preparing page %p",
+ bounds.fLeft, bounds.fTop,
+ bounds.fRight, bounds.fBottom,
+ scale * PREFETCH_SCALE,
+ prefetchTiledPage);
+
+ prefetchTiledPage->setScale(prefetchScale);
+ prefetchTiledPage->updateTileDirtiness(bounds);
+ prefetchTiledPage->prepare(goingDown, goingLeft, bounds,
+ TiledPage::ExpandedBounds);
+ prefetchTiledPage->swapBuffersIfReady(bounds,
+ prefetchScale,
+ TiledPage::SwapWhateverIsReady);
+ prefetchTiledPage->draw(PREFETCH_OPACITY, bounds);
+}
+
bool BaseLayerAndroid::drawBasePictureInGL(SkRect& viewport, float scale,
double currentTime, bool* buffersSwappedPtr)
{
bool scrolling = m_scrollState != NotScrolling;
bool zooming = ZoomManager::kNoScaleRequest != zoomManager->scaleRequestState();
+ // prefetch in the nextTiledPage if unused by zooming (even if not scrolling
+ // since we want the tiles to be ready before they're needed)
+ bool usePrefetchPage = !zooming;
+ nextTiledPage->setIsPrefetchPage(usePrefetchPage);
+ if (usePrefetchPage)
+ prefetchBasePicture(viewport, scale, nextTiledPage);
+
// When we aren't zooming, we should TRY and swap tile buffers if they're
// ready. When scrolling, we swap whatever's ready. Otherwise, buffer until
// the entire page is ready and then swap.
#include "GLUtils.h"
#include "IntRect.h"
#include "PaintTileOperation.h"
+#include "SkPaint.h"
+#include "SkPaintFlagsDrawFilter.h"
#include "TilesManager.h"
#include <cutils/log.h>
, m_glWebViewState(state)
, m_latestPictureInval(0)
, m_prepare(false)
+ , m_isPrefetchPage(false)
{
m_baseTiles = new BaseTile[TilesManager::getMaxTextureAllocation() + 1];
#ifdef DEBUG_COUNT
bool TiledPage::paint(BaseTile* tile, SkCanvas* canvas, unsigned int* pictureUsed)
{
+ // TODO: consider other flags so the pre-rendered tiles aren't so ugly
+ static SkPaintFlagsDrawFilter prefetchFilter(SkPaint::kAllFlags, 0);
+
if (!m_glWebViewState)
return false;
+ if (isPrefetchPage())
+ canvas->setDrawFilter(&prefetchFilter);
+
*pictureUsed = m_glWebViewState->paintBaseLayerContent(canvas);
return true;
}