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 "LayerAndroid.h" 32 #include "ShaderProgram.h" 33 #include "TexturesGenerator.h" 34 #include "TilesProfiler.h" 35 #include "VideoLayerManager.h" 36 #include <utils/threads.h> 37 #include <wtf/HashMap.h> 38 39 namespace WebCore { 40 41 class OperationFilter; 42 class Tile; 43 class TileTexture; 44 class TransferQueue; 45 46 class TilesManager { 47 public: 48 // May only be called from the UI thread 49 static TilesManager* instance(); 50 hardwareAccelerationEnabled()51 static bool hardwareAccelerationEnabled() 52 { 53 return gInstance != 0; 54 } 55 removeOperationsForFilter(OperationFilter * filter)56 void removeOperationsForFilter(OperationFilter* filter) 57 { 58 m_pixmapsGenerationThread->removeOperationsForFilter(filter); 59 } 60 tryUpdateOperationWithPainter(Tile * tile,TilePainter * painter)61 bool tryUpdateOperationWithPainter(Tile* tile, TilePainter* painter) 62 { 63 return m_pixmapsGenerationThread->tryUpdateOperationWithPainter(tile, painter); 64 } 65 scheduleOperation(QueuedOperation * operation)66 void scheduleOperation(QueuedOperation* operation) 67 { 68 m_pixmapsGenerationThread->scheduleOperation(operation); 69 } 70 shader()71 ShaderProgram* shader() { return &m_shader; } 72 TransferQueue* transferQueue(); videoLayerManager()73 VideoLayerManager* videoLayerManager() { return &m_videoLayerManager; } 74 75 void updateTilesIfContextVerified(); 76 void cleanupGLResources(); 77 78 void gatherTextures(); layerTexturesRemain()79 bool layerTexturesRemain() { return m_layerTexturesRemain; } 80 void gatherTexturesNumbers(int* nbTextures, int* nbAllocatedTextures, 81 int* nbLayerTextures, int* nbAllocatedLayerTextures); 82 83 TileTexture* getAvailableTexture(Tile* owner); 84 85 void dirtyAllTiles(); 86 87 void printTextures(); 88 89 // m_highEndGfx is written/read only on UI thread, no need for a lock. 90 void setHighEndGfx(bool highEnd); 91 bool highEndGfx(); 92 93 int currentTextureCount(); 94 int currentLayerTextureCount(); 95 void setCurrentTextureCount(int newTextureCount); 96 void setCurrentLayerTextureCount(int newTextureCount); 97 static int tileWidth(); 98 static int tileHeight(); 99 100 void allocateTextures(); 101 102 // remove all tiles from textures (and optionally deallocate gl memory) 103 void discardTextures(bool allTextures, bool glTextures); 104 getShowVisualIndicator()105 bool getShowVisualIndicator() 106 { 107 return m_showVisualIndicator; 108 } 109 setShowVisualIndicator(bool showVisualIndicator)110 void setShowVisualIndicator(bool showVisualIndicator) 111 { 112 m_showVisualIndicator = showVisualIndicator; 113 } 114 getProfiler()115 TilesProfiler* getProfiler() 116 { 117 return &m_profiler; 118 } 119 invertedScreen()120 bool invertedScreen() 121 { 122 return m_invertedScreen; 123 } 124 setInvertedScreen(bool invert)125 void setInvertedScreen(bool invert) 126 { 127 m_invertedScreen = invert; 128 } 129 setInvertedScreenContrast(float contrast)130 void setInvertedScreenContrast(float contrast) 131 { 132 m_shader.setContrast(contrast); 133 } 134 setUseMinimalMemory(bool useMinimalMemory)135 void setUseMinimalMemory(bool useMinimalMemory) 136 { 137 m_useMinimalMemory = useMinimalMemory; 138 } 139 useMinimalMemory()140 bool useMinimalMemory() 141 { 142 return m_useMinimalMemory; 143 } 144 setUseDoubleBuffering(bool useDoubleBuffering)145 void setUseDoubleBuffering(bool useDoubleBuffering) 146 { 147 m_useDoubleBuffering = useDoubleBuffering; 148 } useDoubleBuffering()149 bool useDoubleBuffering() { return m_useDoubleBuffering; } 150 151 incWebkitContentUpdates()152 unsigned int incWebkitContentUpdates() { return m_webkitContentUpdates++; } 153 incContentUpdates()154 void incContentUpdates() { m_contentUpdates++; } getContentUpdates()155 unsigned int getContentUpdates() { return m_contentUpdates; } clearContentUpdates()156 void clearContentUpdates() { m_contentUpdates = 0; } 157 incDrawGLCount()158 void incDrawGLCount() 159 { 160 m_drawGLCount++; 161 } 162 getDrawGLCount()163 unsigned long long getDrawGLCount() 164 { 165 return m_drawGLCount; 166 } 167 168 private: 169 TilesManager(); 170 171 void discardTexturesVector(unsigned long long sparedDrawCount, 172 WTF::Vector<TileTexture*>& textures, 173 bool deallocateGLTextures); 174 void dirtyTexturesVector(WTF::Vector<TileTexture*>& textures); 175 void markAllGLTexturesZero(); 176 int getMaxTextureAllocation(); 177 178 WTF::Vector<TileTexture*> m_textures; 179 WTF::Vector<TileTexture*> m_availableTextures; 180 181 WTF::Vector<TileTexture*> m_tilesTextures; 182 WTF::Vector<TileTexture*> m_availableTilesTextures; 183 bool m_layerTexturesRemain; 184 185 bool m_highEndGfx; 186 int m_currentTextureCount; 187 int m_currentLayerTextureCount; 188 int m_maxTextureAllocation; 189 190 bool m_generatorReady; 191 192 bool m_showVisualIndicator; 193 bool m_invertedScreen; 194 195 bool m_useMinimalMemory; 196 197 bool m_useDoubleBuffering; 198 unsigned int m_contentUpdates; // nr of successful tiled paints 199 unsigned int m_webkitContentUpdates; // nr of paints from webkit 200 201 sp<TexturesGenerator> m_pixmapsGenerationThread; 202 203 android::Mutex m_texturesLock; 204 205 static TilesManager* gInstance; 206 207 ShaderProgram m_shader; 208 TransferQueue* m_queue; 209 210 VideoLayerManager m_videoLayerManager; 211 212 TilesProfiler m_profiler; 213 unsigned long long m_drawGLCount; 214 double m_lastTimeLayersUsed; 215 bool m_hasLayerTextures; 216 217 EGLContext m_eglContext; 218 }; 219 220 } // namespace WebCore 221 222 #endif // USE(ACCELERATED_COMPOSITING) 223 #endif // TilesManager_h 224