OSDN Git Service

Fix image layer codepath
[android-x86/external-webkit.git] / Source / WebCore / platform / graphics / android / TiledTexture.h
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
38 class SkCanvas;
39
40 namespace WebCore {
41
42 class TiledTexture : public TilePainter {
43 public:
44     TiledTexture(SurfacePainter* surface)
45         : m_paintingPicture(0)
46         , m_surface(surface)
47         , m_prevTileX(0)
48         , m_prevTileY(0)
49         , m_scale(1)
50         , m_swapWhateverIsReady(false)
51     {
52         m_dirtyRegion.setEmpty();
53 #ifdef DEBUG_COUNT
54         ClassTracker::instance()->increment("TiledTexture");
55 #endif
56     }
57
58     virtual ~TiledTexture();
59
60     IntRect computeTilesArea(IntRect& visibleArea, float scale);
61
62     void prepare(GLWebViewState* state, float scale, bool repaint,
63                  bool startFastSwap, IntRect& visibleArea);
64     void swapTiles();
65     bool draw();
66
67     void prepareTile(bool repaint, int x, int y);
68     void update(const SkRegion& dirtyArea, SkPicture* picture);
69
70     BaseTile* getTile(int x, int y);
71
72     void removeTiles();
73     void discardTextures();
74     bool owns(BaseTileTexture* texture);
75
76     // TilePainter methods
77     bool paint(BaseTile* tile, SkCanvas*, unsigned int*);
78     virtual const TransformationMatrix* transform();
79
80     float scale() { return m_scale; }
81     bool ready();
82
83     int nbTextures(IntRect& area, float scale);
84
85 private:
86     bool tileIsVisible(BaseTile* tile);
87
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;
93
94     SurfacePainter* m_surface;
95     Vector<BaseTile*> m_tiles;
96
97     // tile coordinates in viewport, set in prepare()
98     IntRect m_area;
99
100     SkRegion m_dirtyRegion;
101
102     int m_prevTileX;
103     int m_prevTileY;
104     float m_scale;
105
106     bool m_swapWhateverIsReady;
107 };
108
109 class DualTiledTexture {
110 public:
111     DualTiledTexture(SurfacePainter* surface);
112     ~DualTiledTexture();
113     void prepare(GLWebViewState* state, float scale, bool repaint,
114                  bool startFastSwap, IntRect& area);
115     void swapTiles();
116     void swap();
117     bool draw();
118     void update(const SkRegion& dirtyArea, SkPicture* picture);
119     bool owns(BaseTileTexture* texture);
120     bool isReady()
121     {
122         return !m_zooming && m_frontTexture->ready();
123     }
124
125     int nbTextures(IntRect& area, float scale)
126     {
127         // TODO: consider the zooming case for the backTexture
128         if (!m_frontTexture)
129             return 0;
130         return m_frontTexture->nbTextures(area, scale);
131     }
132
133 private:
134     // Delay before we schedule a new tile at the new scale factor
135     static const double s_zoomUpdateDelay = 0.2; // 200 ms
136
137     TiledTexture* m_frontTexture;
138     TiledTexture* m_backTexture;
139     TiledTexture* m_textureA;
140     TiledTexture* m_textureB;
141     float m_scale;
142     float m_futureScale;
143     double m_zoomUpdateTime;
144     bool m_zooming;
145     IntRect m_preZoomVisibleArea;
146 };
147
148 } // namespace WebCore
149
150 #endif // TiledTexture_h