2 * Copyright 2010, 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 TilesManager_h
27 #define TilesManager_h
29 #if USE(ACCELERATED_COMPOSITING)
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>
52 static TilesManager* instance();
53 static GLint getMaxTextureSize();
54 static int getMaxTextureAllocation();
56 static bool hardwareAccelerationEnabled()
58 return gInstance != 0;
61 void removeOperationsForFilter(OperationFilter* filter, bool waitForRunning = false)
63 m_pixmapsGenerationThread->removeOperationsForFilter(filter, waitForRunning);
66 void removeOperationsForPage(TiledPage* page)
68 m_pixmapsGenerationThread->removeOperationsForPage(page);
71 void removePaintOperationsForPage(TiledPage* page, bool waitForCompletion)
73 m_pixmapsGenerationThread->removePaintOperationsForPage(page, waitForCompletion);
76 void scheduleOperation(QueuedOperation* operation)
78 m_pixmapsGenerationThread->scheduleOperation(operation);
81 void swapLayersTextures(LayerAndroid* newTree, LayerAndroid* oldTree);
82 void addPaintedSurface(PaintedSurface* surface);
84 ShaderProgram* shader() { return &m_shader; }
85 TransferQueue* transferQueue() { return &m_queue; }
86 VideoLayerManager* videoLayerManager() { return &m_videoLayerManager; }
88 void gatherLayerTextures();
89 void gatherTextures();
90 bool layerTexturesRemain() { return m_layerTexturesRemain; }
92 BaseTileTexture* getAvailableTexture(BaseTile* owner);
94 void markGeneratorAsReady()
97 android::Mutex::Autolock lock(m_generatorLock);
98 m_generatorReady = true;
100 m_generatorReadyCond.signal();
103 void printTextures();
105 void resetTextureUsage(TiledPage* page);
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);
118 void allocateTiles();
120 // Called when webview is hidden to discard graphics memory
121 void deallocateTextures(bool allTextures);
123 bool getShowVisualIndicator()
125 return m_showVisualIndicator;
128 void setShowVisualIndicator(bool showVisualIndicator)
130 m_showVisualIndicator = showVisualIndicator;
133 SharedTextureMode getSharedTextureMode()
135 return SurfaceTextureMode;
138 TilesProfiler* getProfiler()
143 TilesTracker* getTilesTracker()
145 return &m_tilesTracker;
148 bool invertedScreen()
150 return m_invertedScreen;
153 bool invertedScreenSwitch()
155 return m_invertedScreenSwitch;
158 void setInvertedScreen(bool invert)
160 if (m_invertedScreen != invert)
161 m_invertedScreenSwitch = true;
162 m_invertedScreen = invert;
165 void setInvertedScreenSwitch(bool invertedSwitch)
167 m_invertedScreenSwitch = invertedSwitch;
170 void setInvertedScreenContrast(float contrast)
172 m_shader.setContrast(contrast);
175 void setUseMinimalMemory(bool useMinimalMemory)
177 m_useMinimalMemory = useMinimalMemory;
180 bool useMinimalMemory()
182 return m_useMinimalMemory;
185 void incDrawGLCount()
190 unsigned long long getDrawGLCount()
192 return m_drawGLCount;
195 int getPaintedSurfaceCount()
197 return m_paintedSurfaces.size();
203 void waitForGenerator()
205 android::Mutex::Autolock lock(m_generatorLock);
206 while (!m_generatorReady)
207 m_generatorReadyCond.wait(m_generatorLock);
210 void deallocateTexturesVector(unsigned long long sparedDrawCount,
211 WTF::Vector<BaseTileTexture*>& textures);
213 Vector<BaseTileTexture*> m_textures;
214 Vector<BaseTileTexture*> m_availableTextures;
216 Vector<BaseTileTexture*> m_tilesTextures;
217 Vector<BaseTileTexture*> m_availableTilesTextures;
218 bool m_layerTexturesRemain;
220 Vector<PaintedSurface*> m_paintedSurfaces;
222 int m_maxTextureCount;
223 int m_maxLayerTextureCount;
225 bool m_generatorReady;
227 bool m_showVisualIndicator;
228 bool m_invertedScreen;
229 bool m_invertedScreenSwitch;
231 bool m_useMinimalMemory;
233 sp<TexturesGenerator> m_pixmapsGenerationThread;
235 android::Mutex m_texturesLock;
236 android::Mutex m_generatorLock;
237 android::Condition m_generatorReadyCond;
239 static TilesManager* gInstance;
241 ShaderProgram m_shader;
242 TransferQueue m_queue;
244 VideoLayerManager m_videoLayerManager;
246 TilesProfiler m_profiler;
247 TilesTracker m_tilesTracker;
248 unsigned long long m_drawGLCount;
249 double m_lastTimeLayersUsed;
250 bool m_hasLayerTextures;
253 } // namespace WebCore
255 #endif // USE(ACCELERATED_COMPOSITING)
256 #endif // TilesManager_h