Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 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 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HWUI_CACHES_H |
| 18 | #define ANDROID_HWUI_CACHES_H |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 19 | |
Romain Guy | a2341a9 | 2010-09-08 18:04:33 -0700 | [diff] [blame] | 20 | #ifndef LOG_TAG |
| 21 | #define LOG_TAG "OpenGLRenderer" |
| 22 | #endif |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 23 | |
| 24 | #include <utils/Singleton.h> |
| 25 | |
Romain Guy | 746b740 | 2010-10-26 16:27:31 -0700 | [diff] [blame] | 26 | #include "Extensions.h" |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 27 | #include "FontRenderer.h" |
| 28 | #include "GammaFontRenderer.h" |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 29 | #include "TextureCache.h" |
| 30 | #include "LayerCache.h" |
| 31 | #include "GradientCache.h" |
| 32 | #include "PatchCache.h" |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 33 | #include "ProgramCache.h" |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 34 | #include "ShapeCache.h" |
Romain Guy | ff26a0c | 2011-01-20 11:35:46 -0800 | [diff] [blame] | 35 | #include "PathCache.h" |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 36 | #include "TextDropShadowCache.h" |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 37 | #include "FboCache.h" |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 38 | #include "ResourceCache.h" |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 39 | |
| 40 | namespace android { |
| 41 | namespace uirenderer { |
| 42 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 43 | /////////////////////////////////////////////////////////////////////////////// |
| 44 | // Globals |
| 45 | /////////////////////////////////////////////////////////////////////////////// |
| 46 | |
| 47 | #define REQUIRED_TEXTURE_UNITS_COUNT 3 |
| 48 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 49 | #define REGION_MESH_QUAD_COUNT 512 |
| 50 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 51 | // 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 |
| 56 | static 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 | }; |
| 62 | static const GLsizei gMeshStride = sizeof(TextureVertex); |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame^] | 63 | static const GLsizei gVertexStride = sizeof(Vertex); |
| 64 | static const GLsizei gAlphaVertexStride = sizeof(AlphaVertex); |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 65 | static const GLsizei gMeshTextureOffset = 2 * sizeof(float); |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame^] | 66 | static const GLsizei gVertexAlphaOffset = 2 * sizeof(float); |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 67 | static const GLsizei gMeshCount = 4; |
| 68 | |
| 69 | /////////////////////////////////////////////////////////////////////////////// |
| 70 | // Debug |
| 71 | /////////////////////////////////////////////////////////////////////////////// |
| 72 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 73 | struct CacheLogger { |
| 74 | CacheLogger() { |
Romain Guy | c9855a5 | 2011-01-21 21:14:15 -0800 | [diff] [blame] | 75 | LOGD("Creating OpenGL renderer caches"); |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 76 | } |
| 77 | }; // struct CacheLogger |
| 78 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 79 | /////////////////////////////////////////////////////////////////////////////// |
| 80 | // Caches |
| 81 | /////////////////////////////////////////////////////////////////////////////// |
| 82 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 83 | class Caches: public Singleton<Caches> { |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 84 | Caches(); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 85 | ~Caches(); |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 86 | |
| 87 | friend class Singleton<Caches>; |
| 88 | |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 89 | CacheLogger mLogger; |
Romain Guy | 9bca479 | 2010-10-25 18:42:25 -0700 | [diff] [blame] | 90 | |
| 91 | GLuint mCurrentBuffer; |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 92 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 93 | // Used to render layers |
| 94 | TextureVertex* mRegionMesh; |
| 95 | GLuint mRegionMeshIndices; |
| 96 | |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 97 | mutable Mutex mGarbageLock; |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 98 | Vector<Layer*> mLayerGarbage; |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 99 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 100 | public: |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 101 | /** |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 102 | * 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 Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 110 | * Call this on each frame to ensure that garbage is deleted from |
| 111 | * GPU memory. |
| 112 | */ |
| 113 | void clearGarbage(); |
| 114 | |
| 115 | /** |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 116 | * Can be used to delete a layer from a non EGL thread. |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 117 | */ |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 118 | void deleteLayerDeferred(Layer* layer); |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 119 | |
| 120 | /** |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 121 | * Binds the VBO used to render simple textured quads. |
| 122 | */ |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 123 | void bindMeshBuffer(); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 124 | |
| 125 | /** |
| 126 | * Binds the specified VBO if needed. |
| 127 | */ |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 128 | void bindMeshBuffer(const GLuint buffer); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * Unbinds the VBO used to render simple textured quads. |
| 132 | */ |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 133 | void unbindMeshBuffer(); |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 134 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 135 | /** |
| 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 Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 142 | /** |
| 143 | * Displays the memory usage of each cache and the total sum. |
| 144 | */ |
| 145 | void dumpMemoryUsage(); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 146 | void dumpMemoryUsage(String8& log); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 147 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 148 | bool blend; |
| 149 | GLenum lastSrcMode; |
| 150 | GLenum lastDstMode; |
| 151 | Program* currentProgram; |
| 152 | |
Romain Guy | 746b740 | 2010-10-26 16:27:31 -0700 | [diff] [blame] | 153 | // VBO to draw with |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 154 | GLuint meshBuffer; |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 155 | |
Romain Guy | 746b740 | 2010-10-26 16:27:31 -0700 | [diff] [blame] | 156 | // GL extensions |
| 157 | Extensions extensions; |
| 158 | |
| 159 | // Misc |
| 160 | GLint maxTextureSize; |
| 161 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 162 | TextureCache textureCache; |
| 163 | LayerCache layerCache; |
| 164 | GradientCache gradientCache; |
| 165 | ProgramCache programCache; |
| 166 | PathCache pathCache; |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 167 | RoundRectShapeCache roundRectShapeCache; |
| 168 | CircleShapeCache circleShapeCache; |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 169 | OvalShapeCache ovalShapeCache; |
| 170 | RectShapeCache rectShapeCache; |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 171 | ArcShapeCache arcShapeCache; |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 172 | PatchCache patchCache; |
| 173 | TextDropShadowCache dropShadowCache; |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 174 | FboCache fboCache; |
Romain Guy | 11fd654 | 2010-10-04 17:10:58 -0700 | [diff] [blame] | 175 | GammaFontRenderer fontRenderer; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 176 | ResourceCache resourceCache; |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 177 | |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 178 | private: |
| 179 | DebugLevel mDebugLevel; |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 180 | }; // class Caches |
| 181 | |
| 182 | }; // namespace uirenderer |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 183 | }; // namespace android |
| 184 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 185 | #endif // ANDROID_HWUI_CACHES_H |