1 /* 2 * Copyright 2011, The Android Open Source Project 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef ZoomManager_h 27 #define ZoomManager_h 28 29 #if USE(ACCELERATED_COMPOSITING) 30 31 #include "SkRect.h" 32 33 namespace WebCore { 34 35 class GLWebViewState; 36 37 class ZoomManager { 38 public: 39 enum GLScaleStates { 40 kNoScaleRequest = 0, 41 kWillScheduleRequest = 1, 42 kRequestNewScale = 2, 43 kReceivedNewScale = 3 44 }; 45 typedef int32_t GLScaleState; 46 47 ZoomManager(GLWebViewState* state); 48 49 void scheduleUpdate(const double& currentTime, const SkIRect& viewport, float scale); 50 scaleRequestState()51 GLScaleState scaleRequestState() const { return m_scaleRequestState; } setScaleRequestState(GLScaleState state)52 void setScaleRequestState(GLScaleState state) { m_scaleRequestState = state; } currentScale()53 float currentScale() const { return m_currentScale; } setCurrentScale(float scale)54 void setCurrentScale(float scale) { m_currentScale = scale; } futureScale()55 float futureScale() const { return m_futureScale; } setFutureScale(float scale)56 void setFutureScale(float scale) { m_futureScale = scale; } layersScale()57 float layersScale() const { return m_layersScale; } 58 double zoomInTransitionTime(double currentTime); 59 double zoomOutTransitionTime(double currentTime); 60 float zoomInTransparency(double currentTime); 61 float zoomOutTransparency(double currentTime); resetTransitionTime()62 void resetTransitionTime() { m_transitionTime = -1; } updateTime()63 double updateTime() const { return m_updateTime; } setUpdateTime(double value)64 void setUpdateTime(double value) { m_updateTime = value; } 65 66 // state used by BaseLayerAndroid needPrepareNextTiledPage()67 bool needPrepareNextTiledPage() { return m_prepareNextTiledPage; } zooming()68 bool zooming() { return m_zooming; } 69 didFireRequest()70 bool didFireRequest() { return m_scaleRequestState == ZoomManager::kRequestNewScale; } setReceivedRequest()71 void setReceivedRequest() { 72 m_scaleRequestState = ZoomManager::kReceivedNewScale; 73 m_layersScale = m_futureScale; 74 } didReceivedRequest()75 bool didReceivedRequest() { return m_scaleRequestState == ZoomManager::kReceivedNewScale; } 76 transitionTime(double currentTime,float scale)77 double transitionTime(double currentTime, float scale) { 78 return (scale < m_currentScale) ? zoomOutTransitionTime(currentTime) 79 : zoomInTransitionTime(currentTime); 80 } 81 void processTransition(double currentTime, float scale, bool* doSwap, 82 float* backPageTransparency, float* frontPageTransparency); 83 84 bool swapPages(); 85 86 void processNewScale(double currentTime, float scale); 87 88 private: 89 // Delay between scheduling a new page when the scale 90 // factor changes (i.e. zooming in or out) 91 static const double s_updateInitialDelay = 0.3; // 300 ms 92 // If the scale factor continued to change and we completed 93 // the original delay, we push back the update by this value 94 static const double s_updateDelay = 0.1; // 100 ms 95 96 // Delay for the transition between the two pages 97 static const double s_zoomInTransitionDelay = 0.1; // 100 ms 98 static const double s_invZoomInTransitionDelay = 10; 99 static const double s_zoomOutTransitionDelay = 0.2; // 200 ms 100 static const double s_invZoomOutTransitionDelay = 5; 101 102 GLScaleState m_scaleRequestState; 103 float m_currentScale; 104 float m_futureScale; 105 float m_layersScale; 106 double m_updateTime; 107 double m_transitionTime; 108 109 bool m_prepareNextTiledPage; 110 bool m_zooming; 111 112 GLWebViewState* m_glWebViewState; 113 }; 114 115 } // namespace WebCore 116 117 #endif // USE(ACCELERATED_COMPOSITING) 118 #endif // ZoomManager_h 119