blob: 2779dfdfed1c533d647ddddf740da9842ceaada8 [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"
Romain Guy29d89972010-09-22 16:10:57 -070037#include "Line.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);
63static const GLsizei gMeshTextureOffset = 2 * sizeof(float);
64static const GLsizei gMeshCount = 4;
65
66///////////////////////////////////////////////////////////////////////////////
67// Debug
68///////////////////////////////////////////////////////////////////////////////
69
Romain Guyfb8b7632010-08-23 21:05:08 -070070struct CacheLogger {
71 CacheLogger() {
72 LOGD("Creating caches");
73 }
74}; // struct CacheLogger
75
Romain Guy03750a02010-10-18 14:06:08 -070076///////////////////////////////////////////////////////////////////////////////
77// Caches
78///////////////////////////////////////////////////////////////////////////////
79
Romain Guyfb8b7632010-08-23 21:05:08 -070080class Caches: public Singleton<Caches> {
Chet Haasedd78cca2010-10-22 18:59:26 -070081 Caches();
Romain Guy5b3b3522010-10-27 18:57:51 -070082 ~Caches();
Romain Guyfb8b7632010-08-23 21:05:08 -070083
84 friend class Singleton<Caches>;
85
Romain Guye190aa62010-11-10 19:01:29 -080086 CacheLogger mLogger;
Romain Guy9bca4792010-10-25 18:42:25 -070087
88 GLuint mCurrentBuffer;
Romain Guyfb8b7632010-08-23 21:05:08 -070089
Romain Guy5b3b3522010-10-27 18:57:51 -070090 // Used to render layers
91 TextureVertex* mRegionMesh;
92 GLuint mRegionMeshIndices;
93
Romain Guyfb8b7632010-08-23 21:05:08 -070094public:
Romain Guy5b3b3522010-10-27 18:57:51 -070095 /**
Romain Guye190aa62010-11-10 19:01:29 -080096 * Indicates whether the renderer is in debug mode.
97 * This debug mode provides limited information to app developers.
98 */
99 DebugLevel getDebugLevel() const {
100 return mDebugLevel;
101 }
102
103 /**
Romain Guy5b3b3522010-10-27 18:57:51 -0700104 * Binds the VBO used to render simple textured quads.
105 */
Chet Haasedd78cca2010-10-22 18:59:26 -0700106 void bindMeshBuffer();
Romain Guy5b3b3522010-10-27 18:57:51 -0700107
108 /**
109 * Binds the specified VBO if needed.
110 */
Chet Haasedd78cca2010-10-22 18:59:26 -0700111 void bindMeshBuffer(const GLuint buffer);
Romain Guy5b3b3522010-10-27 18:57:51 -0700112
113 /**
114 * Unbinds the VBO used to render simple textured quads.
115 */
Chet Haasedd78cca2010-10-22 18:59:26 -0700116 void unbindMeshBuffer();
Romain Guy03750a02010-10-18 14:06:08 -0700117
Romain Guy5b3b3522010-10-27 18:57:51 -0700118 /**
119 * Returns the mesh used to draw regions. Calling this method will
120 * bind a VBO of type GL_ELEMENT_ARRAY_BUFFER that contains the
121 * indices for the region mesh.
122 */
123 TextureVertex* getRegionMesh();
124
Romain Guyc15008e2010-11-10 11:59:15 -0800125 /**
126 * Displays the memory usage of each cache and the total sum.
127 */
128 void dumpMemoryUsage();
129
Romain Guyfb8b7632010-08-23 21:05:08 -0700130 bool blend;
131 GLenum lastSrcMode;
132 GLenum lastDstMode;
133 Program* currentProgram;
134
Romain Guy746b7402010-10-26 16:27:31 -0700135 // VBO to draw with
Romain Guy03750a02010-10-18 14:06:08 -0700136 GLuint meshBuffer;
Romain Guy03750a02010-10-18 14:06:08 -0700137
Romain Guy746b7402010-10-26 16:27:31 -0700138 // GL extensions
139 Extensions extensions;
140
141 // Misc
142 GLint maxTextureSize;
143
Romain Guyfb8b7632010-08-23 21:05:08 -0700144 TextureCache textureCache;
145 LayerCache layerCache;
146 GradientCache gradientCache;
147 ProgramCache programCache;
148 PathCache pathCache;
149 PatchCache patchCache;
150 TextDropShadowCache dropShadowCache;
Romain Guye2d345e2010-09-24 18:39:22 -0700151 FboCache fboCache;
Romain Guy11fd6542010-10-04 17:10:58 -0700152 GammaFontRenderer fontRenderer;
Chet Haase5c13d892010-10-08 08:37:55 -0700153 ResourceCache resourceCache;
Romain Guy29d89972010-09-22 16:10:57 -0700154
155 Line line;
Romain Guye190aa62010-11-10 19:01:29 -0800156
157private:
158 DebugLevel mDebugLevel;
Romain Guyfb8b7632010-08-23 21:05:08 -0700159}; // class Caches
160
161}; // namespace uirenderer
Romain Guyfb8b7632010-08-23 21:05:08 -0700162}; // namespace android
163
Romain Guy5b3b3522010-10-27 18:57:51 -0700164#endif // ANDROID_HWUI_CACHES_H