Caches.h revision 44eb2c00861098dd3e2950d923646814b4cc57c2
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 25#include "AssetAtlas.h" 26#include "Dither.h" 27#include "Extensions.h" 28#include "FboCache.h" 29#include "GradientCache.h" 30#include "LayerCache.h" 31#include "PatchCache.h" 32#include "ProgramCache.h" 33#include "PathCache.h" 34#include "RenderBufferCache.h" 35#include "renderstate/PixelBufferState.h" 36#include "renderstate/TextureState.h" 37#include "ResourceCache.h" 38#include "TessellationCache.h" 39#include "TextDropShadowCache.h" 40#include "TextureCache.h" 41#include "thread/TaskProcessor.h" 42#include "thread/TaskManager.h" 43 44#include <vector> 45#include <memory> 46 47#include <GLES3/gl3.h> 48 49#include <utils/KeyedVector.h> 50#include <utils/Singleton.h> 51#include <utils/Vector.h> 52 53#include <cutils/compiler.h> 54 55#include <SkPath.h> 56 57namespace android { 58namespace uirenderer { 59 60class GammaFontRenderer; 61 62/////////////////////////////////////////////////////////////////////////////// 63// Caches 64/////////////////////////////////////////////////////////////////////////////// 65 66class RenderNode; 67class RenderState; 68 69class ANDROID_API Caches { 70public: 71 static Caches& createInstance(RenderState& renderState) { 72 LOG_ALWAYS_FATAL_IF(sInstance, "double create of Caches attempted"); 73 sInstance = new Caches(renderState); 74 return *sInstance; 75 } 76 77 static Caches& getInstance() { 78 LOG_ALWAYS_FATAL_IF(!sInstance, "instance not yet created"); 79 return *sInstance; 80 } 81 82 static bool hasInstance() { 83 return sInstance != 0; 84 } 85private: 86 Caches(RenderState& renderState); 87 static Caches* sInstance; 88 89public: 90 enum FlushMode { 91 kFlushMode_Layers = 0, 92 kFlushMode_Moderate, 93 kFlushMode_Full 94 }; 95 96 /** 97 * Initialize caches. 98 */ 99 bool init(); 100 101 /** 102 * Initialize global system properties. 103 */ 104 bool initProperties(); 105 106 /** 107 * Flush the cache. 108 * 109 * @param mode Indicates how much of the cache should be flushed 110 */ 111 void flush(FlushMode mode); 112 113 /** 114 * Destroys all resources associated with this cache. This should 115 * be called after a flush(kFlushMode_Full). 116 */ 117 void terminate(); 118 119 /** 120 * Indicates whether the renderer is in debug mode. 121 * This debug mode provides limited information to app developers. 122 */ 123 DebugLevel getDebugLevel() const { 124 return mDebugLevel; 125 } 126 127 /** 128 * Returns a non-premultiplied ARGB color for the specified 129 * amount of overdraw (1 for 1x, 2 for 2x, etc.) 130 */ 131 uint32_t getOverdrawColor(uint32_t amount) const; 132 133 /** 134 * Call this on each frame to ensure that garbage is deleted from 135 * GPU memory. 136 */ 137 void clearGarbage(); 138 139 /** 140 * Can be used to delete a layer from a non EGL thread. 141 */ 142 void deleteLayerDeferred(Layer* layer); 143 144 145 void startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool discard); 146 void endTiling(); 147 148 /** 149 * Returns the mesh used to draw regions. Calling this method will 150 * bind a VBO of type GL_ELEMENT_ARRAY_BUFFER that contains the 151 * indices for the region mesh. 152 */ 153 TextureVertex* getRegionMesh(); 154 155 /** 156 * Displays the memory usage of each cache and the total sum. 157 */ 158 void dumpMemoryUsage(); 159 void dumpMemoryUsage(String8& log); 160 161 bool hasRegisteredFunctors(); 162 void registerFunctors(uint32_t functorCount); 163 void unregisterFunctors(uint32_t functorCount); 164 165 Program* currentProgram; 166 167 bool drawDeferDisabled; 168 bool drawReorderDisabled; 169 170 // Misc 171 GLint maxTextureSize; 172 173 // Debugging 174 bool debugLayersUpdates; 175 bool debugOverdraw; 176 177 enum StencilClipDebug { 178 kStencilHide, 179 kStencilShowHighlight, 180 kStencilShowRegion 181 }; 182 StencilClipDebug debugStencilClip; 183 184 TextureCache textureCache; 185 LayerCache layerCache; 186 RenderBufferCache renderBufferCache; 187 GradientCache gradientCache; 188 ProgramCache programCache; 189 PathCache pathCache; 190 PatchCache patchCache; 191 TessellationCache tessellationCache; 192 TextDropShadowCache dropShadowCache; 193 FboCache fboCache; 194 195 GammaFontRenderer* fontRenderer; 196 197 TaskManager tasks; 198 199 Dither dither; 200 201 bool gpuPixelBuffersEnabled; 202 203 // Debug methods 204 PFNGLINSERTEVENTMARKEREXTPROC eventMark; 205 PFNGLPUSHGROUPMARKEREXTPROC startMark; 206 PFNGLPOPGROUPMARKEREXTPROC endMark; 207 208 PFNGLLABELOBJECTEXTPROC setLabel; 209 PFNGLGETOBJECTLABELEXTPROC getLabel; 210 211 // TEMPORARY properties 212 void initTempProperties(); 213 void setTempProperty(const char* name, const char* value); 214 215 float propertyLightDiameter; 216 float propertyLightPosY; 217 float propertyLightPosZ; 218 float propertyAmbientRatio; 219 int propertyAmbientShadowStrength; 220 int propertySpotShadowStrength; 221 222 PixelBufferState& pixelBufferState() { return *mPixelBufferState; } 223 TextureState& textureState() { return *mTextureState; } 224 225private: 226 enum OverdrawColorSet { 227 kColorSet_Default = 0, 228 kColorSet_Deuteranomaly 229 }; 230 231 void initFont(); 232 void initExtensions(); 233 void initConstraints(); 234 void initStaticProperties(); 235 236 static void eventMarkNull(GLsizei length, const GLchar* marker) { } 237 static void startMarkNull(GLsizei length, const GLchar* marker) { } 238 static void endMarkNull() { } 239 240 static void setLabelNull(GLenum type, uint object, GLsizei length, 241 const char* label) { } 242 static void getLabelNull(GLenum type, uint object, GLsizei bufferSize, 243 GLsizei* length, char* label) { 244 if (length) *length = 0; 245 if (label) *label = '\0'; 246 } 247 248 RenderState* mRenderState; 249 250 PixelBufferState* mPixelBufferState = nullptr; // TODO: move to RenderState 251 TextureState* mTextureState = nullptr; // TODO: move to RenderState 252 253 Extensions& mExtensions; 254 255 // Used to render layers 256 std::unique_ptr<TextureVertex[]> mRegionMesh; 257 258 mutable Mutex mGarbageLock; 259 Vector<Layer*> mLayerGarbage; 260 261 DebugLevel mDebugLevel; 262 bool mInitialized; 263 264 uint32_t mFunctorsCount; 265 266 OverdrawColorSet mOverdrawDebugColorSet; 267}; // class Caches 268 269}; // namespace uirenderer 270}; // namespace android 271 272#endif // ANDROID_HWUI_CACHES_H 273