blob: faecadde245aae61dd4590e57d4f91945a096efb [file] [log] [blame]
Romain Guyfb8b7632010-08-23 21:05:08 -07001/*
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
Romain Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_CACHES_H
18#define ANDROID_HWUI_CACHES_H
Romain Guyfb8b7632010-08-23 21:05:08 -070019
Romain Guya2341a92010-09-08 18:04:33 -070020#ifndef LOG_TAG
21 #define LOG_TAG "OpenGLRenderer"
22#endif
Romain Guyfb8b7632010-08-23 21:05:08 -070023
24#include <utils/Singleton.h>
25
Romain Guy746b7402010-10-26 16:27:31 -070026#include "Extensions.h"
Romain Guy03750a02010-10-18 14:06:08 -070027#include "FontRenderer.h"
28#include "GammaFontRenderer.h"
Romain Guyfb8b7632010-08-23 21:05:08 -070029#include "TextureCache.h"
30#include "LayerCache.h"
31#include "GradientCache.h"
32#include "PatchCache.h"
Romain Guyfb8b7632010-08-23 21:05:08 -070033#include "ProgramCache.h"
Romain Guy01d58e42011-01-19 21:54:02 -080034#include "ShapeCache.h"
Romain Guyff26a0c2011-01-20 11:35:46 -080035#include "PathCache.h"
Romain Guyfb8b7632010-08-23 21:05:08 -070036#include "TextDropShadowCache.h"
Romain Guye2d345e2010-09-24 18:39:22 -070037#include "FboCache.h"
Chet Haase5c13d892010-10-08 08:37:55 -070038#include "ResourceCache.h"
Romain Guyfb8b7632010-08-23 21:05:08 -070039
40namespace android {
41namespace uirenderer {
42
Romain Guy03750a02010-10-18 14:06:08 -070043///////////////////////////////////////////////////////////////////////////////
44// Globals
45///////////////////////////////////////////////////////////////////////////////
46
47#define REQUIRED_TEXTURE_UNITS_COUNT 3
48
Romain Guy5b3b3522010-10-27 18:57:51 -070049#define REGION_MESH_QUAD_COUNT 512
50
Romain Guy03750a02010-10-18 14:06:08 -070051// 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
56static 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};
62static const GLsizei gMeshStride = sizeof(TextureVertex);
Chet Haase5b0200b2011-04-13 17:58:08 -070063static const GLsizei gVertexStride = sizeof(Vertex);
64static const GLsizei gAlphaVertexStride = sizeof(AlphaVertex);
Romain Guy03750a02010-10-18 14:06:08 -070065static const GLsizei gMeshTextureOffset = 2 * sizeof(float);
Chet Haase5b0200b2011-04-13 17:58:08 -070066static const GLsizei gVertexAlphaOffset = 2 * sizeof(float);
Romain Guy03750a02010-10-18 14:06:08 -070067static const GLsizei gMeshCount = 4;
68
69///////////////////////////////////////////////////////////////////////////////
70// Debug
71///////////////////////////////////////////////////////////////////////////////
72
Romain Guyfb8b7632010-08-23 21:05:08 -070073struct CacheLogger {
74 CacheLogger() {
Romain Guyc9855a52011-01-21 21:14:15 -080075 LOGD("Creating OpenGL renderer caches");
Romain Guyfb8b7632010-08-23 21:05:08 -070076 }
77}; // struct CacheLogger
78
Romain Guy03750a02010-10-18 14:06:08 -070079///////////////////////////////////////////////////////////////////////////////
80// Caches
81///////////////////////////////////////////////////////////////////////////////
82
Romain Guyfb8b7632010-08-23 21:05:08 -070083class Caches: public Singleton<Caches> {
Chet Haasedd78cca2010-10-22 18:59:26 -070084 Caches();
Romain Guy5b3b3522010-10-27 18:57:51 -070085 ~Caches();
Romain Guyfb8b7632010-08-23 21:05:08 -070086
87 friend class Singleton<Caches>;
88
Romain Guye190aa62010-11-10 19:01:29 -080089 CacheLogger mLogger;
Romain Guy9bca4792010-10-25 18:42:25 -070090
91 GLuint mCurrentBuffer;
Romain Guyfb8b7632010-08-23 21:05:08 -070092
Romain Guy5b3b3522010-10-27 18:57:51 -070093 // Used to render layers
94 TextureVertex* mRegionMesh;
95 GLuint mRegionMeshIndices;
96
Romain Guy57066eb2011-01-12 12:53:32 -080097 mutable Mutex mGarbageLock;
Romain Guyada830f2011-01-13 12:13:20 -080098 Vector<Layer*> mLayerGarbage;
Romain Guy57066eb2011-01-12 12:53:32 -080099
Romain Guyfb8b7632010-08-23 21:05:08 -0700100public:
Romain Guy5b3b3522010-10-27 18:57:51 -0700101 /**
Romain Guye190aa62010-11-10 19:01:29 -0800102 * Indicates whether the renderer is in debug mode.
103 * This debug mode provides limited information to app developers.
104 */
105 DebugLevel getDebugLevel() const {
106 return mDebugLevel;
107 }
108
109 /**
Romain Guyfe48f652010-11-11 15:36:56 -0800110 * Call this on each frame to ensure that garbage is deleted from
111 * GPU memory.
112 */
113 void clearGarbage();
114
115 /**
Romain Guyada830f2011-01-13 12:13:20 -0800116 * Can be used to delete a layer from a non EGL thread.
Romain Guy57066eb2011-01-12 12:53:32 -0800117 */
Romain Guyada830f2011-01-13 12:13:20 -0800118 void deleteLayerDeferred(Layer* layer);
Romain Guy57066eb2011-01-12 12:53:32 -0800119
120 /**
Romain Guy5b3b3522010-10-27 18:57:51 -0700121 * Binds the VBO used to render simple textured quads.
122 */
Chet Haasedd78cca2010-10-22 18:59:26 -0700123 void bindMeshBuffer();
Romain Guy5b3b3522010-10-27 18:57:51 -0700124
125 /**
126 * Binds the specified VBO if needed.
127 */
Chet Haasedd78cca2010-10-22 18:59:26 -0700128 void bindMeshBuffer(const GLuint buffer);
Romain Guy5b3b3522010-10-27 18:57:51 -0700129
130 /**
131 * Unbinds the VBO used to render simple textured quads.
132 */
Chet Haasedd78cca2010-10-22 18:59:26 -0700133 void unbindMeshBuffer();
Romain Guy03750a02010-10-18 14:06:08 -0700134
Romain Guy5b3b3522010-10-27 18:57:51 -0700135 /**
136 * Returns the mesh used to draw regions. Calling this method will
137 * bind a VBO of type GL_ELEMENT_ARRAY_BUFFER that contains the
138 * indices for the region mesh.
139 */
140 TextureVertex* getRegionMesh();
141
Romain Guyc15008e2010-11-10 11:59:15 -0800142 /**
143 * Displays the memory usage of each cache and the total sum.
144 */
145 void dumpMemoryUsage();
Chet Haase9c1e23b2011-03-24 10:51:31 -0700146 void dumpMemoryUsage(String8& log);
Romain Guyc15008e2010-11-10 11:59:15 -0800147
Romain Guyfb8b7632010-08-23 21:05:08 -0700148 bool blend;
149 GLenum lastSrcMode;
150 GLenum lastDstMode;
151 Program* currentProgram;
152
Romain Guy746b7402010-10-26 16:27:31 -0700153 // VBO to draw with
Romain Guy03750a02010-10-18 14:06:08 -0700154 GLuint meshBuffer;
Romain Guy03750a02010-10-18 14:06:08 -0700155
Romain Guy746b7402010-10-26 16:27:31 -0700156 // GL extensions
157 Extensions extensions;
158
159 // Misc
160 GLint maxTextureSize;
161
Romain Guyfb8b7632010-08-23 21:05:08 -0700162 TextureCache textureCache;
163 LayerCache layerCache;
164 GradientCache gradientCache;
165 ProgramCache programCache;
166 PathCache pathCache;
Romain Guy01d58e42011-01-19 21:54:02 -0800167 RoundRectShapeCache roundRectShapeCache;
168 CircleShapeCache circleShapeCache;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800169 OvalShapeCache ovalShapeCache;
170 RectShapeCache rectShapeCache;
Romain Guy8b2f5262011-01-23 16:15:02 -0800171 ArcShapeCache arcShapeCache;
Romain Guyfb8b7632010-08-23 21:05:08 -0700172 PatchCache patchCache;
173 TextDropShadowCache dropShadowCache;
Romain Guye2d345e2010-09-24 18:39:22 -0700174 FboCache fboCache;
Romain Guy11fd6542010-10-04 17:10:58 -0700175 GammaFontRenderer fontRenderer;
Chet Haase5c13d892010-10-08 08:37:55 -0700176 ResourceCache resourceCache;
Romain Guy29d89972010-09-22 16:10:57 -0700177
Romain Guye190aa62010-11-10 19:01:29 -0800178private:
179 DebugLevel mDebugLevel;
Romain Guyfb8b7632010-08-23 21:05:08 -0700180}; // class Caches
181
182}; // namespace uirenderer
Romain Guyfb8b7632010-08-23 21:05:08 -0700183}; // namespace android
184
Romain Guy5b3b3522010-10-27 18:57:51 -0700185#endif // ANDROID_HWUI_CACHES_H