diff options
author | Nicolas Roard <nicolas@android.com> | 2010-11-22 19:48:11 -0800 |
---|---|---|
committer | Nicolas Roard <nicolas@android.com> | 2010-11-24 13:42:16 -0800 |
commit | 7a661f000fc142aec9e4f88b04d0a0ee20a0151e (patch) | |
tree | bebb79f89eea3e9dc9f2ad974f5b1fcf89db40dd /WebCore/platform/graphics/android | |
parent | eabb311cd2b57ff80b4cf632078cf078d789b563 (diff) | |
download | external_webkit-7a661f000fc142aec9e4f88b04d0a0ee20a0151e.zip external_webkit-7a661f000fc142aec9e4f88b04d0a0ee20a0151e.tar.gz external_webkit-7a661f000fc142aec9e4f88b04d0a0ee20a0151e.tar.bz2 |
Refactoring the zoom
Change-Id: I84d44b6aab2222b52d21a65ceb74e390c677fe72
Diffstat (limited to 'WebCore/platform/graphics/android')
-rw-r--r-- | WebCore/platform/graphics/android/BaseLayerAndroid.cpp | 81 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/GLWebViewState.cpp | 6 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/GLWebViewState.h | 5 |
3 files changed, 52 insertions, 40 deletions
diff --git a/WebCore/platform/graphics/android/BaseLayerAndroid.cpp b/WebCore/platform/graphics/android/BaseLayerAndroid.cpp index 7f85899..f139eeb 100644 --- a/WebCore/platform/graphics/android/BaseLayerAndroid.cpp +++ b/WebCore/platform/graphics/android/BaseLayerAndroid.cpp @@ -137,6 +137,7 @@ bool BaseLayerAndroid::drawBasePictureInGL(SkRect& viewport, float scale) || m_glWebViewState->preZoomBounds().isEmpty()) m_glWebViewState->setPreZoomBounds(viewportTileBounds); + bool prepareNextTiledPage = false; // If we have a different scale than the current one, we have to // decide what to do. The current behaviour is to delay an update, // so that we do not slow down zooming unnecessarily. @@ -144,53 +145,57 @@ bool BaseLayerAndroid::drawBasePictureInGL(SkRect& viewport, float scale) && (m_glWebViewState->scaleRequestState() == GLWebViewState::kNoScaleRequest || m_glWebViewState->scaleRequestState() == GLWebViewState::kWillScheduleRequest || m_glWebViewState->futureScale() != scale)) { - m_glWebViewState->scheduleUpdate(currentTime, scale); - if (m_glWebViewState->scaleRequestState() == GLWebViewState::kRequestNewScale) { - // schedule the new request - TiledPage* nextTiledPage = m_glWebViewState->backPage(); - nextTiledPage->setScale(scale); - nextTiledPage->prepare(goingDown, goingLeft, viewportTileBounds); - } + // schedule the new request + m_glWebViewState->scheduleUpdate(currentTime, viewportTileBounds, scale); + + // If it's a new request, we will have to prepare the page. + if (m_glWebViewState->scaleRequestState() == GLWebViewState::kRequestNewScale) + prepareNextTiledPage = true; } - float transparency = 1; - bool doSwap = false; + // If the viewport has changed since we scheduled the request, we also need to prepare. + if (((m_glWebViewState->scaleRequestState() == GLWebViewState::kRequestNewScale) + || (m_glWebViewState->scaleRequestState() == GLWebViewState::kReceivedNewScale)) + && (m_glWebViewState->futureViewport() != viewportTileBounds)) + prepareNextTiledPage = true; - // Here we have to schedule the painting of the tiles corresponding - // to the new tiles for the new scale factor (see above) - if (m_glWebViewState->scaleRequestState() == GLWebViewState::kRequestNewScale - || m_glWebViewState->scaleRequestState() == GLWebViewState::kReceivedNewScale) { + // Let's prepare the page if needed + if (prepareNextTiledPage) { TiledPage* nextTiledPage = m_glWebViewState->backPage(); nextTiledPage->setScale(scale); + m_glWebViewState->setFutureViewport(viewportTileBounds); + nextTiledPage->prepare(goingDown, goingLeft, viewportTileBounds); + } + + float transparency = 1; + bool doSwap = false; - // Check if the page is ready... - if (m_glWebViewState->scaleRequestState() == GLWebViewState::kRequestNewScale - && nextTiledPage->ready(viewportTileBounds)) { + // If we fired a request, let's check if it's ready to use + if (m_glWebViewState->scaleRequestState() == GLWebViewState::kRequestNewScale) { + TiledPage* nextTiledPage = m_glWebViewState->backPage(); + if (nextTiledPage->ready(viewportTileBounds)) m_glWebViewState->setScaleRequestState(GLWebViewState::kReceivedNewScale); - } + } + + // If the page is ready, display it. We do a short transition between + // the two pages (current one and future one with the new scale factor) + if (m_glWebViewState->scaleRequestState() == GLWebViewState::kReceivedNewScale) { + TiledPage* nextTiledPage = m_glWebViewState->backPage(); + double transitionTime = m_glWebViewState->transitionTime(currentTime); + transparency = m_glWebViewState->transparency(currentTime); + + float newTilesTransparency = 1; + if (scale < m_glWebViewState->currentScale()) + newTilesTransparency = 1 - transparency; + + nextTiledPage->draw(newTilesTransparency, viewport, viewportTileBounds); - // If the page is ready, display it. We do a short transition between - // the two pages (current one and future one with the new scale factor) - if (m_glWebViewState->scaleRequestState() == GLWebViewState::kReceivedNewScale) { - double transitionTime = m_glWebViewState->transitionTime(currentTime); - transparency = m_glWebViewState->transparency(currentTime); - - float newTilesTransparency = 1; - if (scale < m_glWebViewState->currentScale()) - newTilesTransparency = 1 - transparency; - - nextTiledPage->draw(newTilesTransparency, viewport, viewportTileBounds); - - // The transition between the two pages is finished, swap them - if (currentTime > transitionTime) { - m_glWebViewState->setCurrentScale(scale); - m_glWebViewState->resetTransitionTime(); - doSwap = true; - } - } else { - // If the page is not ready, schedule it if needed. - nextTiledPage->prepare(goingDown, goingLeft, viewportTileBounds); + // The transition between the two pages is finished, swap them + if (currentTime > transitionTime) { + m_glWebViewState->setCurrentScale(scale); + m_glWebViewState->resetTransitionTime(); + doSwap = true; } } diff --git a/WebCore/platform/graphics/android/GLWebViewState.cpp b/WebCore/platform/graphics/android/GLWebViewState.cpp index 145bd89..fbf33c2 100644 --- a/WebCore/platform/graphics/android/GLWebViewState.cpp +++ b/WebCore/platform/graphics/android/GLWebViewState.cpp @@ -74,6 +74,7 @@ GLWebViewState::GLWebViewState() , m_usePageA(true) { m_viewport.setEmpty(); + m_futureViewportTileBounds.setEmpty(); m_viewportTileBounds.setEmpty(); m_preZoomBounds.setEmpty(); @@ -133,13 +134,15 @@ unsigned int GLWebViewState::paintBaseLayerContent(SkCanvas* canvas) return m_currentPictureCounter; } -void GLWebViewState::scheduleUpdate(const double& currentTime, float scale) +void GLWebViewState::scheduleUpdate(const double& currentTime, + const SkIRect& viewport, float scale) { // if no update time, set it if (updateTime() == -1) { m_scaleRequestState = kWillScheduleRequest; setUpdateTime(currentTime + s_updateInitialDelay); setFutureScale(scale); + setFutureViewport(viewport); return; } @@ -158,6 +161,7 @@ void GLWebViewState::scheduleUpdate(const double& currentTime, float scale) // in the process of zooming. Let's push the update time a bit. setUpdateTime(currentTime + s_updateDelay); setFutureScale(scale); + setFutureViewport(viewport); } } diff --git a/WebCore/platform/graphics/android/GLWebViewState.h b/WebCore/platform/graphics/android/GLWebViewState.h index e50c5f4..698eb4a 100644 --- a/WebCore/platform/graphics/android/GLWebViewState.h +++ b/WebCore/platform/graphics/android/GLWebViewState.h @@ -160,6 +160,8 @@ public: void setCurrentScale(float scale) { m_currentScale = scale; } float futureScale() const { return m_futureScale; } void setFutureScale(float scale) { m_futureScale = scale; } + const SkIRect& futureViewport() const { return m_futureViewportTileBounds; } + void setFutureViewport(const SkIRect& viewport) { m_futureViewportTileBounds = viewport; } double updateTime() const { return m_updateTime; } void setUpdateTime(double value) { m_updateTime = value; } double transitionTime(double currentTime); @@ -169,7 +171,7 @@ public: unsigned int paintBaseLayerContent(SkCanvas* canvas); void setBaseLayer(BaseLayerAndroid* layer, const IntRect& rect); void setExtra(BaseLayerAndroid* , SkPicture& , const IntRect& ); - void scheduleUpdate(const double& currentTime, float scale); + void scheduleUpdate(const double& currentTime, const SkIRect& viewport, float scale); TiledPage* frontPage(); TiledPage* backPage(); @@ -213,6 +215,7 @@ private: android::Mutex m_tiledPageLock; SkRect m_viewport; SkIRect m_viewportTileBounds; + SkIRect m_futureViewportTileBounds; SkIRect m_preZoomBounds; android::Mutex m_baseLayerLock; BaseLayerAndroid* m_baseLayer; |