1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_HWUI_CACHES_H 18 #define ANDROID_HWUI_CACHES_H 19 20 #ifndef LOG_TAG 21 #define LOG_TAG "OpenGLRenderer" 22 #endif 23 24 #include <utils/Singleton.h> 25 26 #include "Extensions.h" 27 #include "FontRenderer.h" 28 #include "GammaFontRenderer.h" 29 #include "TextureCache.h" 30 #include "LayerCache.h" 31 #include "GradientCache.h" 32 #include "PatchCache.h" 33 #include "ProgramCache.h" 34 #include "ShapeCache.h" 35 #include "PathCache.h" 36 #include "TextDropShadowCache.h" 37 #include "FboCache.h" 38 #include "ResourceCache.h" 39 40 namespace android { 41 namespace uirenderer { 42 43 /////////////////////////////////////////////////////////////////////////////// 44 // Globals 45 /////////////////////////////////////////////////////////////////////////////// 46 47 #define REQUIRED_TEXTURE_UNITS_COUNT 3 48 49 #define REGION_MESH_QUAD_COUNT 512 50 51 // Generates simple and textured vertices 52 #define FV(x, y, u, v) { { x, y }, { u, v } } 53 54 // This array is never used directly but used as a memcpy source in the 55 // OpenGLRenderer constructor 56 static const TextureVertex gMeshVertices[] = { 57 FV(0.0f, 0.0f, 0.0f, 0.0f), 58 FV(1.0f, 0.0f, 1.0f, 0.0f), 59 FV(0.0f, 1.0f, 0.0f, 1.0f), 60 FV(1.0f, 1.0f, 1.0f, 1.0f) 61 }; 62 static const GLsizei gMeshStride = sizeof(TextureVertex); 63 static const GLsizei gVertexStride = sizeof(Vertex); 64 static const GLsizei gAlphaVertexStride = sizeof(AlphaVertex); 65 static const GLsizei gAAVertexStride = sizeof(AAVertex); 66 static const GLsizei gMeshTextureOffset = 2 * sizeof(float); 67 static const GLsizei gVertexAAWidthOffset = 2 * sizeof(float); 68 static const GLsizei gVertexAALengthOffset = 3 * sizeof(float); 69 static const GLsizei gMeshCount = 4; 70 71 /////////////////////////////////////////////////////////////////////////////// 72 // Debug 73 /////////////////////////////////////////////////////////////////////////////// 74 75 struct CacheLogger { 76 CacheLogger() { 77 INIT_LOGD("Creating OpenGL renderer caches"); 78 } 79 }; // struct CacheLogger 80 81 /////////////////////////////////////////////////////////////////////////////// 82 // Caches 83 /////////////////////////////////////////////////////////////////////////////// 84 85 class Caches: public Singleton<Caches> { 86 Caches(); 87 ~Caches(); 88 89 friend class Singleton<Caches>; 90 91 CacheLogger mLogger; 92 93 GLuint mCurrentBuffer; 94 95 // Used to render layers 96 TextureVertex* mRegionMesh; 97 GLuint mRegionMeshIndices; 98 99 mutable Mutex mGarbageLock; 100 Vector<Layer*> mLayerGarbage; 101 102 public: 103 enum FlushMode { 104 kFlushMode_Layers = 0, 105 kFlushMode_Moderate, 106 kFlushMode_Full 107 }; 108 109 /** 110 * Flush the cache. 111 * 112 * @param mode Indicates how much of the cache should be flushed 113 */ 114 void flush(FlushMode mode); 115 116 /** 117 * Indicates whether the renderer is in debug mode. 118 * This debug mode provides limited information to app developers. 119 */ 120 DebugLevel getDebugLevel() const { 121 return mDebugLevel; 122 } 123 124 /** 125 * Call this on each frame to ensure that garbage is deleted from 126 * GPU memory. 127 */ 128 void clearGarbage(); 129 130 /** 131 * Can be used to delete a layer from a non EGL thread. 132 */ 133 void deleteLayerDeferred(Layer* layer); 134 135 /** 136 * Binds the VBO used to render simple textured quads. 137 */ 138 void bindMeshBuffer(); 139 140 /** 141 * Binds the specified VBO if needed. 142 */ 143 void bindMeshBuffer(const GLuint buffer); 144 145 /** 146 * Unbinds the VBO used to render simple textured quads. 147 */ 148 void unbindMeshBuffer(); 149 150 /** 151 * Returns the mesh used to draw regions. Calling this method will 152 * bind a VBO of type GL_ELEMENT_ARRAY_BUFFER that contains the 153 * indices for the region mesh. 154 */ 155 TextureVertex* getRegionMesh(); 156 157 /** 158 * Displays the memory usage of each cache and the total sum. 159 */ 160 void dumpMemoryUsage(); 161 void dumpMemoryUsage(String8& log); 162 163 bool blend; 164 GLenum lastSrcMode; 165 GLenum lastDstMode; 166 Program* currentProgram; 167 168 // VBO to draw with 169 GLuint meshBuffer; 170 171 // GL extensions 172 Extensions extensions; 173 174 // Misc 175 GLint maxTextureSize; 176 177 TextureCache textureCache; 178 LayerCache layerCache; 179 GradientCache gradientCache; 180 ProgramCache programCache; 181 PathCache pathCache; 182 RoundRectShapeCache roundRectShapeCache; 183 CircleShapeCache circleShapeCache; 184 OvalShapeCache ovalShapeCache; 185 RectShapeCache rectShapeCache; 186 ArcShapeCache arcShapeCache; 187 PatchCache patchCache; 188 TextDropShadowCache dropShadowCache; 189 FboCache fboCache; 190 GammaFontRenderer fontRenderer; 191 ResourceCache resourceCache; 192 193 private: 194 DebugLevel mDebugLevel; 195 }; // class Caches 196 197 }; // namespace uirenderer 198 }; // namespace android 199 200 #endif // ANDROID_HWUI_CACHES_H 201