• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
hardwareAccelerationEnabled()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 
removeOperationsForPage(TiledPage * page)66     void removeOperationsForPage(TiledPage* page)
67     {
68         m_pixmapsGenerationThread->removeOperationsForPage(page);
69     }
70 
removePaintOperationsForPage(TiledPage * page,bool waitForCompletion)71     void removePaintOperationsForPage(TiledPage* page, bool waitForCompletion)
72     {
73         m_pixmapsGenerationThread->removePaintOperationsForPage(page, waitForCompletion);
74     }
75 
scheduleOperation(QueuedOperation * operation)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 
shader()84     ShaderProgram* shader() { return &m_shader; }
transferQueue()85     TransferQueue* transferQueue() { return &m_queue; }
videoLayerManager()86     VideoLayerManager* videoLayerManager() { return &m_videoLayerManager; }
87 
88     void gatherLayerTextures();
89     void gatherTextures();
layerTexturesRemain()90     bool layerTexturesRemain() { return m_layerTexturesRemain; }
91 
92     BaseTileTexture* getAvailableTexture(BaseTile* owner);
93 
markGeneratorAsReady()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     void setMaxTextureCount(int max);
109     static float tileWidth();
110     static float tileHeight();
111     static float layerTileWidth();
112     static float layerTileHeight();
113     void paintedSurfacesCleanup(GLWebViewState* state);
114     void unregisterGLWebViewState(GLWebViewState* state);
115 
116     void allocateTiles();
117 
118     // Called when webview is hidden to discard graphics memory
119     void deallocateTextures(bool allTextures);
120 
getShowVisualIndicator()121     bool getShowVisualIndicator()
122     {
123         return m_showVisualIndicator;
124     }
125 
setShowVisualIndicator(bool showVisualIndicator)126     void setShowVisualIndicator(bool showVisualIndicator)
127     {
128         m_showVisualIndicator = showVisualIndicator;
129     }
130 
getSharedTextureMode()131     SharedTextureMode getSharedTextureMode()
132     {
133         return SurfaceTextureMode;
134     }
135 
getProfiler()136     TilesProfiler* getProfiler()
137     {
138         return &m_profiler;
139     }
140 
getTilesTracker()141     TilesTracker* getTilesTracker()
142     {
143         return &m_tilesTracker;
144     }
145 
invertedScreen()146     bool invertedScreen()
147     {
148         return m_invertedScreen;
149     }
150 
invertedScreenSwitch()151     bool invertedScreenSwitch()
152     {
153         return m_invertedScreenSwitch;
154     }
155 
setInvertedScreen(bool invert)156     void setInvertedScreen(bool invert)
157     {
158         if (m_invertedScreen != invert)
159             m_invertedScreenSwitch = true;
160         m_invertedScreen = invert;
161     }
162 
setInvertedScreenSwitch(bool invertedSwitch)163     void setInvertedScreenSwitch(bool invertedSwitch)
164     {
165         m_invertedScreenSwitch = invertedSwitch;
166     }
167 
setInvertedScreenContrast(float contrast)168     void setInvertedScreenContrast(float contrast)
169     {
170         m_shader.setContrast(contrast);
171     }
172 
incDrawGLCount()173     void incDrawGLCount()
174     {
175         m_drawGLCount++;
176     }
177 
getDrawGLCount()178     unsigned long long getDrawGLCount()
179     {
180         return m_drawGLCount;
181     }
182 
183 private:
184     TilesManager();
185 
waitForGenerator()186     void waitForGenerator()
187     {
188         android::Mutex::Autolock lock(m_generatorLock);
189         while (!m_generatorReady)
190             m_generatorReadyCond.wait(m_generatorLock);
191     }
192 
193     Vector<BaseTileTexture*> m_textures;
194     Vector<BaseTileTexture*> m_availableTextures;
195 
196     Vector<BaseTileTexture*> m_tilesTextures;
197     Vector<BaseTileTexture*> m_availableTilesTextures;
198     bool m_layerTexturesRemain;
199 
200     Vector<PaintedSurface*> m_paintedSurfaces;
201 
202     int m_maxTextureCount;
203 
204     bool m_generatorReady;
205 
206     bool m_showVisualIndicator;
207     bool m_invertedScreen;
208     bool m_invertedScreenSwitch;
209 
210     sp<TexturesGenerator> m_pixmapsGenerationThread;
211 
212     android::Mutex m_texturesLock;
213     android::Mutex m_generatorLock;
214     android::Condition m_generatorReadyCond;
215 
216     static TilesManager* gInstance;
217 
218     ShaderProgram m_shader;
219     TransferQueue m_queue;
220 
221     VideoLayerManager m_videoLayerManager;
222 
223     TilesProfiler m_profiler;
224     TilesTracker m_tilesTracker;
225     unsigned long long m_drawGLCount;
226 };
227 
228 } // namespace WebCore
229 
230 #endif // USE(ACCELERATED_COMPOSITING)
231 #endif // TilesManager_h
232