blob: a11b6bc1ec086362bad8133eb3c15d43343e2b6a [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"
34#include "PathCache.h"
35#include "TextDropShadowCache.h"
Romain Guye2d345e2010-09-24 18:39:22 -070036#include "FboCache.h"
Chet Haase5c13d892010-10-08 08:37:55 -070037#include "ResourceCache.h"
Romain Guyfb8b7632010-08-23 21:05:08 -070038
39namespace android {
40namespace uirenderer {
41
Romain Guy03750a02010-10-18 14:06:08 -070042///////////////////////////////////////////////////////////////////////////////
43// Globals
44///////////////////////////////////////////////////////////////////////////////
45
46#define REQUIRED_TEXTURE_UNITS_COUNT 3
47
Romain Guy5b3b3522010-10-27 18:57:51 -070048#define REGION_MESH_QUAD_COUNT 512
49
Romain Guy03750a02010-10-18 14:06:08 -070050// Generates simple and textured vertices
51#define FV(x, y, u, v) { { x, y }, { u, v } }
52
53// This array is never used directly but used as a memcpy source in the
54// OpenGLRenderer constructor
55static const TextureVertex gMeshVertices[] = {
56 FV(0.0f, 0.0f, 0.0f, 0.0f),
57 FV(1.0f, 0.0f, 1.0f, 0.0f),
58 FV(0.0f, 1.0f, 0.0f, 1.0f),
59 FV(1.0f, 1.0f, 1.0f, 1.0f)
60};
61static const GLsizei gMeshStride = sizeof(TextureVertex);
62static const GLsizei gMeshTextureOffset = 2 * sizeof(float);
63static const GLsizei gMeshCount = 4;
64
65///////////////////////////////////////////////////////////////////////////////
66// Debug
67///////////////////////////////////////////////////////////////////////////////
68
Romain Guyfb8b7632010-08-23 21:05:08 -070069struct CacheLogger {
70 CacheLogger() {
71 LOGD("Creating caches");
72 }
73}; // struct CacheLogger
74
Romain Guy03750a02010-10-18 14:06:08 -070075///////////////////////////////////////////////////////////////////////////////
76// Caches
77///////////////////////////////////////////////////////////////////////////////
78
Romain Guyfb8b7632010-08-23 21:05:08 -070079class Caches: public Singleton<Caches> {
Chet Haasedd78cca2010-10-22 18:59:26 -070080 Caches();
Romain Guy5b3b3522010-10-27 18:57:51 -070081 ~Caches();
Romain Guyfb8b7632010-08-23 21:05:08 -070082
83 friend class Singleton<Caches>;
84
Romain Guye190aa62010-11-10 19:01:29 -080085 CacheLogger mLogger;
Romain Guy9bca4792010-10-25 18:42:25 -070086
87 GLuint mCurrentBuffer;
Romain Guyfb8b7632010-08-23 21:05:08 -070088
Romain Guy5b3b3522010-10-27 18:57:51 -070089 // Used to render layers
90 TextureVertex* mRegionMesh;
91 GLuint mRegionMeshIndices;
92
Romain Guy57066eb2011-01-12 12:53:32 -080093 mutable Mutex mGarbageLock;
Romain Guyada830f2011-01-13 12:13:20 -080094 Vector<Layer*> mLayerGarbage;
Romain Guy57066eb2011-01-12 12:53:32 -080095
Romain Guyfb8b7632010-08-23 21:05:08 -070096public:
Romain Guy5b3b3522010-10-27 18:57:51 -070097 /**
Romain Guye190aa62010-11-10 19:01:29 -080098 * Indicates whether the renderer is in debug mode.
99 * This debug mode provides limited information to app developers.
100 */
101 DebugLevel getDebugLevel() const {
102 return mDebugLevel;
103 }
104
105 /**
Romain Guyfe48f652010-11-11 15:36:56 -0800106 * Call this on each frame to ensure that garbage is deleted from
107 * GPU memory.
108 */
109 void clearGarbage();
110
111 /**
Romain Guyada830f2011-01-13 12:13:20 -0800112 * Can be used to delete a layer from a non EGL thread.
Romain Guy57066eb2011-01-12 12:53:32 -0800113 */
Romain Guyada830f2011-01-13 12:13:20 -0800114 void deleteLayerDeferred(Layer* layer);
Romain Guy57066eb2011-01-12 12:53:32 -0800115
116 /**
Romain Guy5b3b3522010-10-27 18:57:51 -0700117 * Binds the VBO used to render simple textured quads.
118 */
Chet Haasedd78cca2010-10-22 18:59:26 -0700119 void bindMeshBuffer();
Romain Guy5b3b3522010-10-27 18:57:51 -0700120
121 /**
122 * Binds the specified VBO if needed.
123 */
Chet Haasedd78cca2010-10-22 18:59:26 -0700124 void bindMeshBuffer(const GLuint buffer);
Romain Guy5b3b3522010-10-27 18:57:51 -0700125
126 /**
127 * Unbinds the VBO used to render simple textured quads.
128 */
Chet Haasedd78cca2010-10-22 18:59:26 -0700129 void unbindMeshBuffer();
Romain Guy03750a02010-10-18 14:06:08 -0700130
Romain Guy5b3b3522010-10-27 18:57:51 -0700131 /**
132 * Returns the mesh used to draw regions. Calling this method will
133 * bind a VBO of type GL_ELEMENT_ARRAY_BUFFER that contains the
134 * indices for the region mesh.
135 */
136 TextureVertex* getRegionMesh();
137
Romain Guyc15008e2010-11-10 11:59:15 -0800138 /**
139 * Displays the memory usage of each cache and the total sum.
140 */
141 void dumpMemoryUsage();
142
Romain Guyfb8b7632010-08-23 21:05:08 -0700143 bool blend;
144 GLenum lastSrcMode;
145 GLenum lastDstMode;
146 Program* currentProgram;
147
Romain Guy746b7402010-10-26 16:27:31 -0700148 // VBO to draw with
Romain Guy03750a02010-10-18 14:06:08 -0700149 GLuint meshBuffer;
Romain Guy03750a02010-10-18 14:06:08 -0700150
Romain Guy746b7402010-10-26 16:27:31 -0700151 // GL extensions
152 Extensions extensions;
153
154 // Misc
155 GLint maxTextureSize;
156
Romain Guyfb8b7632010-08-23 21:05:08 -0700157 TextureCache textureCache;
158 LayerCache layerCache;
159 GradientCache gradientCache;
160 ProgramCache programCache;
161 PathCache pathCache;
162 PatchCache patchCache;
163 TextDropShadowCache dropShadowCache;
Romain Guye2d345e2010-09-24 18:39:22 -0700164 FboCache fboCache;
Romain Guy11fd6542010-10-04 17:10:58 -0700165 GammaFontRenderer fontRenderer;
Chet Haase5c13d892010-10-08 08:37:55 -0700166 ResourceCache resourceCache;
Romain Guy29d89972010-09-22 16:10:57 -0700167
Romain Guye190aa62010-11-10 19:01:29 -0800168private:
169 DebugLevel mDebugLevel;
Romain Guyfb8b7632010-08-23 21:05:08 -0700170}; // class Caches
171
172}; // namespace uirenderer
Romain Guyfb8b7632010-08-23 21:05:08 -0700173}; // namespace android
174
Romain Guy5b3b3522010-10-27 18:57:51 -0700175#endif // ANDROID_HWUI_CACHES_H