OSDN Git Service

Merge "tile prefetching now triggered automatically"
[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 "LayerAndroid.h"
34 #include "ShaderProgram.h"
35 #include "TexturesGenerator.h"
36 #include "TiledPage.h"
37 #include "TilesProfiler.h"
38 #include "TilesTracker.h"
39 #include "TransferQueue.h"
40 #include "VideoLayerManager.h"
41 #include <utils/threads.h>
42 #include <wtf/HashMap.h>
43
44 namespace WebCore {
45
46 class PaintedSurface;
47
48 class TilesManager {
49 public:
50     static TilesManager* instance();
51     static GLint getMaxTextureSize();
52     static int getMaxTextureAllocation();
53
54     static bool hardwareAccelerationEnabled()
55     {
56         return gInstance != 0;
57     }
58
59     void removeOperationsForFilter(OperationFilter* filter, bool waitForRunning = false)
60     {
61         m_pixmapsGenerationThread->removeOperationsForFilter(filter, waitForRunning);
62     }
63
64     void removeOperationsForPage(TiledPage* page)
65     {
66         m_pixmapsGenerationThread->removeOperationsForPage(page);
67     }
68
69     void removePaintOperationsForPage(TiledPage* page, bool waitForCompletion)
70     {
71         m_pixmapsGenerationThread->removePaintOperationsForPage(page, waitForCompletion);
72     }
73
74     void scheduleOperation(QueuedOperation* operation)
75     {
76         m_pixmapsGenerationThread->scheduleOperation(operation);
77     }
78
79     void swapLayersTextures(LayerAndroid* newTree, LayerAndroid* oldTree);
80     void addPaintedSurface(PaintedSurface* surface);
81
82     ShaderProgram* shader() { return &m_shader; }
83     TransferQueue* transferQueue() { return &m_queue; }
84     VideoLayerManager* videoLayerManager() { return &m_videoLayerManager; }
85
86     void gatherLayerTextures();
87     void gatherTextures();
88     BaseTileTexture* getAvailableTexture(BaseTile* owner);
89
90     void markGeneratorAsReady()
91     {
92         {
93             android::Mutex::Autolock lock(m_generatorLock);
94             m_generatorReady = true;
95         }
96         m_generatorReadyCond.signal();
97     }
98
99     void printTextures();
100
101     void resetTextureUsage(TiledPage* page);
102
103     int maxLayersAllocation();
104     int maxLayerAllocation();
105     int maxTextureCount();
106     void setMaxTextureCount(int max);
107     static float tileWidth();
108     static float tileHeight();
109     static float layerTileWidth();
110     static float layerTileHeight();
111     void registerGLWebViewState(GLWebViewState* state);
112     void unregisterGLWebViewState(GLWebViewState* state);
113
114     void allocateTiles();
115
116     bool getShowVisualIndicator()
117     {
118         return m_showVisualIndicator;
119     }
120
121     void setShowVisualIndicator(bool showVisualIndicator)
122     {
123         m_showVisualIndicator = showVisualIndicator;
124     }
125
126     SharedTextureMode getSharedTextureMode()
127     {
128         return SurfaceTextureMode;
129     }
130
131     TilesProfiler* getProfiler()
132     {
133         return &m_profiler;
134     }
135
136     TilesTracker* getTilesTracker()
137     {
138         return &m_tilesTracker;
139     }
140
141     bool invertedScreen()
142     {
143         return m_invertedScreen;
144     }
145
146     void setInvertedScreen(bool invert)
147     {
148         m_invertedScreen = invert;
149     }
150
151     void setInvertedScreenContrast(float contrast)
152     {
153         m_shader.setContrast(contrast);
154     }
155
156 private:
157     TilesManager();
158
159     void waitForGenerator()
160     {
161         android::Mutex::Autolock lock(m_generatorLock);
162         while (!m_generatorReady)
163             m_generatorReadyCond.wait(m_generatorLock);
164     }
165
166     Vector<BaseTileTexture*> m_textures;
167     Vector<BaseTileTexture*> m_availableTextures;
168
169     Vector<BaseTileTexture*> m_tilesTextures;
170     Vector<BaseTileTexture*> m_availableTilesTextures;
171
172     Vector<PaintedSurface*> m_paintedSurfaces;
173
174     unsigned int m_layersMemoryUsage;
175
176     int m_maxTextureCount;
177
178     bool m_generatorReady;
179
180     bool m_showVisualIndicator;
181     bool m_invertedScreen;
182
183     sp<TexturesGenerator> m_pixmapsGenerationThread;
184
185     android::Mutex m_texturesLock;
186     android::Mutex m_generatorLock;
187     android::Condition m_generatorReadyCond;
188
189     static TilesManager* gInstance;
190
191     ShaderProgram m_shader;
192     TransferQueue m_queue;
193
194     VideoLayerManager m_videoLayerManager;
195
196     HashMap<GLWebViewState*, unsigned int> m_glWebViewStateMap;
197     unsigned int m_drawRegistrationCount;
198
199     unsigned int getGLWebViewStateDrawCount(GLWebViewState* state);
200
201     TilesProfiler m_profiler;
202     TilesTracker m_tilesTracker;
203 };
204
205 } // namespace WebCore
206
207 #endif // USE(ACCELERATED_COMPOSITING)
208 #endif // TilesManager_h