OSDN Git Service

0c3e9000e160d28d0ea91f0e4558696e77ec3df8
[android-x86/external-webkit.git] / Source / WebCore / platform / graphics / android / TilesManager.h
1 /*
2  * Copyright 2010, 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 TilesManager_h
27 #define TilesManager_h
28
29 #if USE(ACCELERATED_COMPOSITING)
30
31 #include "BaseTile.h"
32 #include "BaseTileTexture.h"
33 #include "ImageTexture.h"
34 #include "LayerAndroid.h"
35 #include "ShaderProgram.h"
36 #include "SkBitmapRef.h"
37 #include "TexturesGenerator.h"
38 #include "TiledPage.h"
39 #include "TilesProfiler.h"
40 #include "TilesTracker.h"
41 #include "TransferQueue.h"
42 #include "VideoLayerManager.h"
43 #include <utils/threads.h>
44 #include <wtf/HashMap.h>
45
46 namespace WebCore {
47
48 class PaintedSurface;
49
50 class TilesManager {
51 public:
52     static TilesManager* instance();
53     static GLint getMaxTextureSize();
54     static int getMaxTextureAllocation();
55
56     static bool hardwareAccelerationEnabled()
57     {
58         return gInstance != 0;
59     }
60
61     void removeOperationsForFilter(OperationFilter* filter, bool waitForRunning = false)
62     {
63         m_pixmapsGenerationThread->removeOperationsForFilter(filter, waitForRunning);
64     }
65
66     void removeOperationsForPage(TiledPage* page)
67     {
68         m_pixmapsGenerationThread->removeOperationsForPage(page);
69     }
70
71     void removePaintOperationsForPage(TiledPage* page, bool waitForCompletion)
72     {
73         m_pixmapsGenerationThread->removePaintOperationsForPage(page, waitForCompletion);
74     }
75
76     void scheduleOperation(QueuedOperation* operation)
77     {
78         m_pixmapsGenerationThread->scheduleOperation(operation);
79     }
80
81     void swapLayersTextures(LayerAndroid* newTree, LayerAndroid* oldTree);
82     void addPaintedSurface(PaintedSurface* surface);
83
84     ShaderProgram* shader() { return &m_shader; }
85     TransferQueue* transferQueue() { return &m_queue; }
86     VideoLayerManager* videoLayerManager() { return &m_videoLayerManager; }
87
88     void gatherLayerTextures();
89     void gatherTextures();
90     bool layerTexturesRemain() { return m_layerTexturesRemain; }
91
92     BaseTileTexture* getAvailableTexture(BaseTile* owner);
93
94     void markGeneratorAsReady()
95     {
96         {
97             android::Mutex::Autolock lock(m_generatorLock);
98             m_generatorReady = true;
99         }
100         m_generatorReadyCond.signal();
101     }
102
103     void printTextures();
104
105     void resetTextureUsage(TiledPage* page);
106
107     int maxTextureCount();
108     int maxLayerTextureCount();
109     void setMaxTextureCount(int max);
110     void setMaxLayerTextureCount(int max);
111     static float tileWidth();
112     static float tileHeight();
113     static float layerTileWidth();
114     static float layerTileHeight();
115     void paintedSurfacesCleanup(GLWebViewState* state = 0);
116     void unregisterGLWebViewState(GLWebViewState* state);
117
118     void allocateTiles();
119
120     // Called when webview is hidden to discard graphics memory
121     void deallocateTextures(bool allTextures);
122
123     bool getShowVisualIndicator()
124     {
125         return m_showVisualIndicator;
126     }
127
128     void setShowVisualIndicator(bool showVisualIndicator)
129     {
130         m_showVisualIndicator = showVisualIndicator;
131     }
132
133     SharedTextureMode getSharedTextureMode()
134     {
135         return SurfaceTextureMode;
136     }
137
138     TilesProfiler* getProfiler()
139     {
140         return &m_profiler;
141     }
142
143     TilesTracker* getTilesTracker()
144     {
145         return &m_tilesTracker;
146     }
147
148     bool invertedScreen()
149     {
150         return m_invertedScreen;
151     }
152
153     bool invertedScreenSwitch()
154     {
155         return m_invertedScreenSwitch;
156     }
157
158     void setInvertedScreen(bool invert)
159     {
160         if (m_invertedScreen != invert)
161             m_invertedScreenSwitch = true;
162         m_invertedScreen = invert;
163     }
164
165     void setInvertedScreenSwitch(bool invertedSwitch)
166     {
167         m_invertedScreenSwitch = invertedSwitch;
168     }
169
170     void setInvertedScreenContrast(float contrast)
171     {
172         m_shader.setContrast(contrast);
173     }
174
175     void setUseMinimalMemory(bool useMinimalMemory)
176     {
177         m_useMinimalMemory = useMinimalMemory;
178     }
179
180     bool useMinimalMemory()
181     {
182         return m_useMinimalMemory;
183     }
184
185     void incDrawGLCount()
186     {
187         m_drawGLCount++;
188     }
189
190     unsigned long long getDrawGLCount()
191     {
192         return m_drawGLCount;
193     }
194
195     int getPaintedSurfaceCount()
196     {
197         return m_paintedSurfaces.size();
198     }
199
200 private:
201     TilesManager();
202
203     void waitForGenerator()
204     {
205         android::Mutex::Autolock lock(m_generatorLock);
206         while (!m_generatorReady)
207             m_generatorReadyCond.wait(m_generatorLock);
208     }
209
210     void deallocateTexturesVector(unsigned long long sparedDrawCount,
211                                   WTF::Vector<BaseTileTexture*>& textures);
212
213     Vector<BaseTileTexture*> m_textures;
214     Vector<BaseTileTexture*> m_availableTextures;
215
216     Vector<BaseTileTexture*> m_tilesTextures;
217     Vector<BaseTileTexture*> m_availableTilesTextures;
218     bool m_layerTexturesRemain;
219
220     Vector<PaintedSurface*> m_paintedSurfaces;
221
222     int m_maxTextureCount;
223     int m_maxLayerTextureCount;
224
225     bool m_generatorReady;
226
227     bool m_showVisualIndicator;
228     bool m_invertedScreen;
229     bool m_invertedScreenSwitch;
230
231     bool m_useMinimalMemory;
232
233     sp<TexturesGenerator> m_pixmapsGenerationThread;
234
235     android::Mutex m_texturesLock;
236     android::Mutex m_generatorLock;
237     android::Condition m_generatorReadyCond;
238
239     static TilesManager* gInstance;
240
241     ShaderProgram m_shader;
242     TransferQueue m_queue;
243
244     VideoLayerManager m_videoLayerManager;
245
246     TilesProfiler m_profiler;
247     TilesTracker m_tilesTracker;
248     unsigned long long m_drawGLCount;
249     double m_lastTimeLayersUsed;
250     bool m_hasLayerTextures;
251 };
252
253 } // namespace WebCore
254
255 #endif // USE(ACCELERATED_COMPOSITING)
256 #endif // TilesManager_h