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 SurfaceBacking_h 27 #define SurfaceBacking_h 28 29 #include "SkRefCnt.h" 30 #include "TileGrid.h" 31 32 namespace WebCore { 33 34 class LayerAndroid; 35 class TexturesResult; 36 class TilePainter; 37 38 class SurfaceBacking : public SkRefCnt { 39 // TODO: investigate webkit threadsafe ref counting 40 public: 41 SurfaceBacking(bool isBaseSurface); 42 ~SurfaceBacking(); 43 void prepareGL(GLWebViewState* state, float maxZoomScale, 44 const IntRect& prepareArea, const IntRect& fullContentArea, 45 TilePainter* painter, bool aggressiveRendering, 46 bool updateWithBlit); 47 bool swapTiles(); 48 void drawGL(const IntRect& visibleContentArea, float opacity, 49 const TransformationMatrix* transform, bool aggressiveRendering, 50 const Color* background); 51 void markAsDirty(const SkRegion& dirtyArea); 52 void computeTexturesAmount(TexturesResult* result, 53 const IntRect& visibleContentArea, 54 const IntRect& fullContentArea, 55 LayerAndroid* layer); 56 void discardTextures() 57 { 58 m_frontTileGrid->discardTextures(); 59 m_backTileGrid->discardTextures(); 60 } 61 bool isReady() 62 { 63 return !m_zooming && m_frontTileGrid->isReady() && m_scale > 0; 64 } 65 66 bool isDirty() 67 { 68 return m_frontTileGrid->isDirty(); 69 } 70 71 bool isMissingContent() 72 { 73 return m_zooming || m_frontTileGrid->isMissingContent(); 74 } 75 76 int nbTextures(IntRect& area, float scale) 77 { 78 // TODO: consider the zooming case for the backTileGrid 79 if (!m_frontTileGrid) 80 return 0; 81 return m_frontTileGrid->nbTextures(area, scale); 82 } 83 84 private: 85 void swapTileGrids(); 86 87 // Delay before we schedule a new tile at the new scale factor 88 static const double s_zoomUpdateDelay = 0.1; // 100 ms 89 90 TileGrid* m_frontTileGrid; 91 TileGrid* m_backTileGrid; 92 TileGrid* m_lowResTileGrid; 93 94 float m_scale; 95 float m_futureScale; 96 double m_zoomUpdateTime; 97 bool m_zooming; 98 float m_maxZoomScale; 99 }; 100 101 } // namespace WebCore 102 103 #endif // SurfaceBacking_h 104