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 "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>
50 static TilesManager* instance();
51 static GLint getMaxTextureSize();
52 static int getMaxTextureAllocation();
54 static bool hardwareAccelerationEnabled()
56 return gInstance != 0;
59 void removeOperationsForFilter(OperationFilter* filter, bool waitForRunning = false)
61 m_pixmapsGenerationThread->removeOperationsForFilter(filter, waitForRunning);
64 void removeOperationsForPage(TiledPage* page)
66 m_pixmapsGenerationThread->removeOperationsForPage(page);
69 void removePaintOperationsForPage(TiledPage* page, bool waitForCompletion)
71 m_pixmapsGenerationThread->removePaintOperationsForPage(page, waitForCompletion);
74 void scheduleOperation(QueuedOperation* operation)
76 m_pixmapsGenerationThread->scheduleOperation(operation);
79 void swapLayersTextures(LayerAndroid* newTree, LayerAndroid* oldTree);
80 void addPaintedSurface(PaintedSurface* surface);
82 ShaderProgram* shader() { return &m_shader; }
83 TransferQueue* transferQueue() { return &m_queue; }
84 VideoLayerManager* videoLayerManager() { return &m_videoLayerManager; }
86 void gatherLayerTextures();
87 void gatherTextures();
88 BaseTileTexture* getAvailableTexture(BaseTile* owner);
90 void markGeneratorAsReady()
93 android::Mutex::Autolock lock(m_generatorLock);
94 m_generatorReady = true;
96 m_generatorReadyCond.signal();
101 void resetTextureUsage(TiledPage* page);
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);
114 void allocateTiles();
116 bool getShowVisualIndicator()
118 return m_showVisualIndicator;
121 void setShowVisualIndicator(bool showVisualIndicator)
123 m_showVisualIndicator = showVisualIndicator;
126 SharedTextureMode getSharedTextureMode()
128 return SurfaceTextureMode;
131 TilesProfiler* getProfiler()
136 TilesTracker* getTilesTracker()
138 return &m_tilesTracker;
141 bool invertedScreen()
143 return m_invertedScreen;
146 void setInvertedScreen(bool invert)
148 m_invertedScreen = invert;
151 void setInvertedScreenContrast(float contrast)
153 m_shader.setContrast(contrast);
159 void waitForGenerator()
161 android::Mutex::Autolock lock(m_generatorLock);
162 while (!m_generatorReady)
163 m_generatorReadyCond.wait(m_generatorLock);
166 Vector<BaseTileTexture*> m_textures;
167 Vector<BaseTileTexture*> m_availableTextures;
169 Vector<BaseTileTexture*> m_tilesTextures;
170 Vector<BaseTileTexture*> m_availableTilesTextures;
172 Vector<PaintedSurface*> m_paintedSurfaces;
174 unsigned int m_layersMemoryUsage;
176 int m_maxTextureCount;
178 bool m_generatorReady;
180 bool m_showVisualIndicator;
181 bool m_invertedScreen;
183 sp<TexturesGenerator> m_pixmapsGenerationThread;
185 android::Mutex m_texturesLock;
186 android::Mutex m_generatorLock;
187 android::Condition m_generatorReadyCond;
189 static TilesManager* gInstance;
191 ShaderProgram m_shader;
192 TransferQueue m_queue;
194 VideoLayerManager m_videoLayerManager;
196 HashMap<GLWebViewState*, unsigned int> m_glWebViewStateMap;
197 unsigned int m_drawRegistrationCount;
199 unsigned int getGLWebViewStateDrawCount(GLWebViewState* state);
201 TilesProfiler m_profiler;
202 TilesTracker m_tilesTracker;
205 } // namespace WebCore
207 #endif // USE(ACCELERATED_COMPOSITING)
208 #endif // TilesManager_h