blob: 76dff4b4078ba649c38c1597157dfedac1bb0281 [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);
Chet Haase99585ad2011-05-02 15:00:16 -070065static const GLsizei gAAVertexStride = sizeof(AAVertex);
Romain Guy03750a02010-10-18 14:06:08 -070066static const GLsizei gMeshTextureOffset = 2 * sizeof(float);
Chet Haase99585ad2011-05-02 15:00:16 -070067static const GLsizei gVertexAAWidthOffset = 2 * sizeof(float);
68static const GLsizei gVertexAALengthOffset = 3 * sizeof(float);
Romain Guy03750a02010-10-18 14:06:08 -070069static const GLsizei gMeshCount = 4;
70
71///////////////////////////////////////////////////////////////////////////////
72// Debug
73///////////////////////////////////////////////////////////////////////////////
74
Romain Guyfb8b7632010-08-23 21:05:08 -070075struct CacheLogger {
76 CacheLogger() {
Romain Guyd6b2a002011-06-17 17:45:59 -070077 INIT_LOGD("Creating OpenGL renderer caches");
Romain Guyfb8b7632010-08-23 21:05:08 -070078 }
79}; // struct CacheLogger
80
Romain Guy03750a02010-10-18 14:06:08 -070081///////////////////////////////////////////////////////////////////////////////
82// Caches
83///////////////////////////////////////////////////////////////////////////////
84
Romain Guyfb8b7632010-08-23 21:05:08 -070085class Caches: public Singleton<Caches> {
Chet Haasedd78cca2010-10-22 18:59:26 -070086 Caches();
Romain Guy5b3b3522010-10-27 18:57:51 -070087 ~Caches();
Romain Guyfb8b7632010-08-23 21:05:08 -070088
89 friend class Singleton<Caches>;
90
Romain Guye190aa62010-11-10 19:01:29 -080091 CacheLogger mLogger;
Romain Guy9bca4792010-10-25 18:42:25 -070092
93 GLuint mCurrentBuffer;
Romain Guyfb8b7632010-08-23 21:05:08 -070094
Romain Guy5b3b3522010-10-27 18:57:51 -070095 // Used to render layers
96 TextureVertex* mRegionMesh;
97 GLuint mRegionMeshIndices;
98
Romain Guy57066eb2011-01-12 12:53:32 -080099 mutable Mutex mGarbageLock;
Romain Guyada830f2011-01-13 12:13:20 -0800100 Vector<Layer*> mLayerGarbage;
Romain Guy57066eb2011-01-12 12:53:32 -0800101
Romain Guyfb8b7632010-08-23 21:05:08 -0700102public:
Romain Guybdf76092011-07-18 15:00:43 -0700103 enum FlushMode {
104 kFlushMode_Moderate = 0,
105 kFlushMode_Full
106 };
107
108 /**
109 * Flush the cache.
110 *
111 * @param mode Indicates how much of the cache should be flushed
112 */
113 void flush(FlushMode mode);
114
Romain Guy5b3b3522010-10-27 18:57:51 -0700115 /**
Romain Guye190aa62010-11-10 19:01:29 -0800116 * Indicates whether the renderer is in debug mode.
117 * This debug mode provides limited information to app developers.
118 */
119 DebugLevel getDebugLevel() const {
120 return mDebugLevel;
121 }
122
123 /**
Romain Guyfe48f652010-11-11 15:36:56 -0800124 * Call this on each frame to ensure that garbage is deleted from
125 * GPU memory.
126 */
127 void clearGarbage();
128
129 /**
Romain Guyada830f2011-01-13 12:13:20 -0800130 * Can be used to delete a layer from a non EGL thread.
Romain Guy57066eb2011-01-12 12:53:32 -0800131 */
Romain Guyada830f2011-01-13 12:13:20 -0800132 void deleteLayerDeferred(Layer* layer);
Romain Guy57066eb2011-01-12 12:53:32 -0800133
134 /**
Romain Guy5b3b3522010-10-27 18:57:51 -0700135 * Binds the VBO used to render simple textured quads.
136 */
Chet Haasedd78cca2010-10-22 18:59:26 -0700137 void bindMeshBuffer();
Romain Guy5b3b3522010-10-27 18:57:51 -0700138
139 /**
140 * Binds the specified VBO if needed.
141 */
Chet Haasedd78cca2010-10-22 18:59:26 -0700142 void bindMeshBuffer(const GLuint buffer);
Romain Guy5b3b3522010-10-27 18:57:51 -0700143
144 /**
145 * Unbinds the VBO used to render simple textured quads.
146 */
Chet Haasedd78cca2010-10-22 18:59:26 -0700147 void unbindMeshBuffer();
Romain Guy03750a02010-10-18 14:06:08 -0700148
Romain Guy5b3b3522010-10-27 18:57:51 -0700149 /**
150 * Returns the mesh used to draw regions. Calling this method will
151 * bind a VBO of type GL_ELEMENT_ARRAY_BUFFER that contains the
152 * indices for the region mesh.
153 */
154 TextureVertex* getRegionMesh();
155
Romain Guyc15008e2010-11-10 11:59:15 -0800156 /**
157 * Displays the memory usage of each cache and the total sum.
158 */
159 void dumpMemoryUsage();
Chet Haase9c1e23b2011-03-24 10:51:31 -0700160 void dumpMemoryUsage(String8& log);
Romain Guyc15008e2010-11-10 11:59:15 -0800161
Romain Guyfb8b7632010-08-23 21:05:08 -0700162 bool blend;
163 GLenum lastSrcMode;
164 GLenum lastDstMode;
165 Program* currentProgram;
166
Romain Guy746b7402010-10-26 16:27:31 -0700167 // VBO to draw with
Romain Guy03750a02010-10-18 14:06:08 -0700168 GLuint meshBuffer;
Romain Guy03750a02010-10-18 14:06:08 -0700169
Romain Guy746b7402010-10-26 16:27:31 -0700170 // GL extensions
171 Extensions extensions;
172
173 // Misc
174 GLint maxTextureSize;
175
Romain Guyfb8b7632010-08-23 21:05:08 -0700176 TextureCache textureCache;
177 LayerCache layerCache;
178 GradientCache gradientCache;
179 ProgramCache programCache;
180 PathCache pathCache;
Romain Guy01d58e42011-01-19 21:54:02 -0800181 RoundRectShapeCache roundRectShapeCache;
182 CircleShapeCache circleShapeCache;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800183 OvalShapeCache ovalShapeCache;
184 RectShapeCache rectShapeCache;
Romain Guy8b2f5262011-01-23 16:15:02 -0800185 ArcShapeCache arcShapeCache;
Romain Guyfb8b7632010-08-23 21:05:08 -0700186 PatchCache patchCache;
187 TextDropShadowCache dropShadowCache;
Romain Guye2d345e2010-09-24 18:39:22 -0700188 FboCache fboCache;
Romain Guy11fd6542010-10-04 17:10:58 -0700189 GammaFontRenderer fontRenderer;
Chet Haase5c13d892010-10-08 08:37:55 -0700190 ResourceCache resourceCache;
Romain Guy29d89972010-09-22 16:10:57 -0700191
Romain Guye190aa62010-11-10 19:01:29 -0800192private:
193 DebugLevel mDebugLevel;
Romain Guyfb8b7632010-08-23 21:05:08 -0700194}; // class Caches
195
196}; // namespace uirenderer
Romain Guyfb8b7632010-08-23 21:05:08 -0700197}; // namespace android
198
Romain Guy5b3b3522010-10-27 18:57:51 -0700199#endif // ANDROID_HWUI_CACHES_H