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 TiledTexture_h 27 #define TiledTexture_h 28 29 #include "BaseTile.h" 30 #include "BaseTileTexture.h" 31 #include "ClassTracker.h" 32 #include "IntRect.h" 33 #include "LayerAndroid.h" 34 #include "SkRegion.h" 35 #include "TextureOwner.h" 36 #include "TilePainter.h" 37 #include "UpdateManager.h" 38 39 class SkCanvas; 40 41 namespace WebCore { 42 43 class UpdateManager; 44 class PaintedSurface; 45 46 class TiledTexture : public TilePainter { 47 public: TiledTexture(PaintedSurface * surface)48 TiledTexture(PaintedSurface* surface) 49 : m_surface(surface) 50 , m_prevTileX(0) 51 , m_prevTileY(0) 52 , m_scale(1) 53 , m_swapWhateverIsReady(false) 54 { 55 m_dirtyRegion.setEmpty(); 56 #ifdef DEBUG_COUNT 57 ClassTracker::instance()->increment("TiledTexture"); 58 #endif 59 } ~TiledTexture()60 virtual ~TiledTexture() 61 { 62 #ifdef DEBUG_COUNT 63 ClassTracker::instance()->decrement("TiledTexture"); 64 #endif 65 removeTiles(); 66 }; 67 68 void prepare(GLWebViewState* state, float scale, bool repaint, 69 bool startFastSwap, IntRect& visibleArea); 70 bool draw(); 71 72 void prepareTile(bool repaint, int x, int y); 73 void update(const SkRegion& dirtyArea, SkPicture* picture); 74 75 BaseTile* getTile(int x, int y); 76 77 void removeTiles(); 78 void discardTextures(); 79 bool owns(BaseTileTexture* texture); 80 81 // TilePainter methods 82 bool paint(BaseTile* tile, SkCanvas*, unsigned int*); 83 virtual void paintExtra(SkCanvas*); 84 virtual const TransformationMatrix* transform(); 85 scale()86 float scale() { return m_scale; } 87 bool ready(); 88 surface()89 PaintedSurface* surface() { return m_surface; } 90 91 private: 92 bool tileIsVisible(BaseTile* tile); 93 94 UpdateManager m_updateManager; 95 96 PaintedSurface* m_surface; 97 Vector<BaseTile*> m_tiles; 98 99 // tile coordinates in viewport, set in prepare() 100 IntRect m_area; 101 102 SkRegion m_dirtyRegion; 103 104 int m_prevTileX; 105 int m_prevTileY; 106 float m_scale; 107 108 bool m_swapWhateverIsReady; 109 }; 110 111 class DualTiledTexture { 112 public: 113 DualTiledTexture(PaintedSurface* surface); 114 ~DualTiledTexture(); 115 void prepare(GLWebViewState* state, float scale, bool repaint, 116 bool startFastSwap, IntRect& area); 117 void swap(); 118 bool draw(); 119 void update(const SkRegion& dirtyArea, SkPicture* picture); 120 bool owns(BaseTileTexture* texture); 121 private: 122 // Delay before we schedule a new tile at the new scale factor 123 static const double s_zoomUpdateDelay = 0.2; // 200 ms 124 125 TiledTexture* m_frontTexture; 126 TiledTexture* m_backTexture; 127 TiledTexture* m_textureA; 128 TiledTexture* m_textureB; 129 float m_scale; 130 float m_futureScale; 131 double m_zoomUpdateTime; 132 bool m_zooming; 133 IntRect m_preZoomVisibleArea; 134 }; 135 136 } // namespace WebCore 137 138 #endif // TiledTexture_h 139