2 * Copyright 2011, The Android Open Source Project
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef TiledTexture_h
27 #define TiledTexture_h
30 #include "BaseTileTexture.h"
31 #include "ClassTracker.h"
33 #include "LayerAndroid.h"
35 #include "TextureOwner.h"
36 #include "TilePainter.h"
42 class TiledTexture : public TilePainter {
44 TiledTexture(SurfacePainter* surface)
45 : m_paintingPicture(0)
50 , m_swapWhateverIsReady(false)
52 m_dirtyRegion.setEmpty();
54 ClassTracker::instance()->increment("TiledTexture");
58 virtual ~TiledTexture();
60 IntRect computeTilesArea(IntRect& visibleArea, float scale);
62 void prepare(GLWebViewState* state, float scale, bool repaint,
63 bool startFastSwap, IntRect& visibleArea);
67 void prepareTile(bool repaint, int x, int y);
68 void update(const SkRegion& dirtyArea, SkPicture* picture);
70 BaseTile* getTile(int x, int y);
73 void discardTextures();
74 bool owns(BaseTileTexture* texture);
76 // TilePainter methods
77 bool paint(BaseTile* tile, SkCanvas*, unsigned int*);
78 virtual const TransformationMatrix* transform();
80 float scale() { return m_scale; }
83 int nbTextures(IntRect& area, float scale);
86 bool tileIsVisible(BaseTile* tile);
88 // protect m_paintingPicture
89 // update() on UI thread modifies
90 // paint() on texture gen thread reads
91 android::Mutex m_paintingPictureSync;
92 SkPicture* m_paintingPicture;
94 SurfacePainter* m_surface;
95 Vector<BaseTile*> m_tiles;
97 // tile coordinates in viewport, set in prepare()
100 SkRegion m_dirtyRegion;
106 bool m_swapWhateverIsReady;
109 class DualTiledTexture {
111 DualTiledTexture(SurfacePainter* surface);
113 void prepare(GLWebViewState* state, float scale, bool repaint,
114 bool startFastSwap, IntRect& area);
118 void update(const SkRegion& dirtyArea, SkPicture* picture);
119 bool owns(BaseTileTexture* texture);
122 return !m_zooming && m_frontTexture->ready();
125 int nbTextures(IntRect& area, float scale)
127 // TODO: consider the zooming case for the backTexture
130 return m_frontTexture->nbTextures(area, scale);
134 // Delay before we schedule a new tile at the new scale factor
135 static const double s_zoomUpdateDelay = 0.2; // 200 ms
137 TiledTexture* m_frontTexture;
138 TiledTexture* m_backTexture;
139 TiledTexture* m_textureA;
140 TiledTexture* m_textureB;
143 double m_zoomUpdateTime;
145 IntRect m_preZoomVisibleArea;
148 } // namespace WebCore
150 #endif // TiledTexture_h