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 | |
| 17 | #ifndef ANDROID_UI_CACHES_H |
| 18 | #define ANDROID_UI_CACHES_H |
| 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 | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 26 | #include "FontRenderer.h" |
| 27 | #include "GammaFontRenderer.h" |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 28 | #include "TextureCache.h" |
| 29 | #include "LayerCache.h" |
| 30 | #include "GradientCache.h" |
| 31 | #include "PatchCache.h" |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 32 | #include "ProgramCache.h" |
| 33 | #include "PathCache.h" |
| 34 | #include "TextDropShadowCache.h" |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 35 | #include "FboCache.h" |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 36 | #include "Line.h" |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame^] | 37 | #include "ResourceCache.h" |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 38 | |
| 39 | namespace android { |
| 40 | namespace uirenderer { |
| 41 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 42 | /////////////////////////////////////////////////////////////////////////////// |
| 43 | // Globals |
| 44 | /////////////////////////////////////////////////////////////////////////////// |
| 45 | |
| 46 | #define REQUIRED_TEXTURE_UNITS_COUNT 3 |
| 47 | |
| 48 | // Generates simple and textured vertices |
| 49 | #define FV(x, y, u, v) { { x, y }, { u, v } } |
| 50 | |
| 51 | // This array is never used directly but used as a memcpy source in the |
| 52 | // OpenGLRenderer constructor |
| 53 | static const TextureVertex gMeshVertices[] = { |
| 54 | FV(0.0f, 0.0f, 0.0f, 0.0f), |
| 55 | FV(1.0f, 0.0f, 1.0f, 0.0f), |
| 56 | FV(0.0f, 1.0f, 0.0f, 1.0f), |
| 57 | FV(1.0f, 1.0f, 1.0f, 1.0f) |
| 58 | }; |
| 59 | static const GLsizei gMeshStride = sizeof(TextureVertex); |
| 60 | static const GLsizei gMeshTextureOffset = 2 * sizeof(float); |
| 61 | static const GLsizei gMeshCount = 4; |
| 62 | |
| 63 | /////////////////////////////////////////////////////////////////////////////// |
| 64 | // Debug |
| 65 | /////////////////////////////////////////////////////////////////////////////// |
| 66 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 67 | struct CacheLogger { |
| 68 | CacheLogger() { |
| 69 | LOGD("Creating caches"); |
| 70 | } |
| 71 | }; // struct CacheLogger |
| 72 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 73 | /////////////////////////////////////////////////////////////////////////////// |
| 74 | // Caches |
| 75 | /////////////////////////////////////////////////////////////////////////////// |
| 76 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 77 | class Caches: public Singleton<Caches> { |
| 78 | Caches(): Singleton<Caches>(), blend(false), lastSrcMode(GL_ZERO), |
| 79 | lastDstMode(GL_ZERO), currentProgram(NULL) { |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 80 | GLint maxTextureUnits; |
| 81 | glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits); |
| 82 | if (maxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) { |
| 83 | LOGW("At least %d texture units are required!", REQUIRED_TEXTURE_UNITS_COUNT); |
| 84 | } |
| 85 | |
| 86 | glGenBuffers(1, &meshBuffer); |
| 87 | glBindBuffer(GL_ARRAY_BUFFER, meshBuffer); |
| 88 | glBufferData(GL_ARRAY_BUFFER, sizeof(gMeshVertices), gMeshVertices, GL_STATIC_DRAW); |
| 89 | |
| 90 | currentBuffer = meshBuffer; |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | friend class Singleton<Caches>; |
| 94 | |
| 95 | CacheLogger logger; |
| 96 | |
| 97 | public: |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 98 | /** |
| 99 | * Binds the VBO used to render simple textured quads. |
| 100 | */ |
| 101 | inline void bindMeshBuffer() { |
| 102 | bindMeshBuffer(meshBuffer); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Binds the specified VBO. |
| 107 | */ |
| 108 | inline void bindMeshBuffer(const GLuint buffer) { |
| 109 | if (currentBuffer != buffer) { |
| 110 | glBindBuffer(GL_ARRAY_BUFFER, buffer); |
| 111 | currentBuffer = buffer; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Unbinds the VBO used to render simple textured quads. |
| 117 | */ |
| 118 | inline void unbindMeshBuffer() { |
| 119 | if (currentBuffer) { |
| 120 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 121 | currentBuffer = 0; |
| 122 | } |
| 123 | } |
| 124 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 125 | bool blend; |
| 126 | GLenum lastSrcMode; |
| 127 | GLenum lastDstMode; |
| 128 | Program* currentProgram; |
| 129 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 130 | GLuint meshBuffer; |
| 131 | GLuint currentBuffer; |
| 132 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 133 | TextureCache textureCache; |
| 134 | LayerCache layerCache; |
| 135 | GradientCache gradientCache; |
| 136 | ProgramCache programCache; |
| 137 | PathCache pathCache; |
| 138 | PatchCache patchCache; |
| 139 | TextDropShadowCache dropShadowCache; |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 140 | FboCache fboCache; |
Romain Guy | 11fd654 | 2010-10-04 17:10:58 -0700 | [diff] [blame] | 141 | GammaFontRenderer fontRenderer; |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame^] | 142 | ResourceCache resourceCache; |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 143 | |
| 144 | Line line; |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 145 | }; // class Caches |
| 146 | |
| 147 | }; // namespace uirenderer |
| 148 | |
Romain Guy | f6fcac7 | 2010-08-24 18:17:31 -0700 | [diff] [blame] | 149 | #ifdef USE_OPENGL_RENDERER |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 150 | using namespace uirenderer; |
| 151 | ANDROID_SINGLETON_STATIC_INSTANCE(Caches); |
Romain Guy | f6fcac7 | 2010-08-24 18:17:31 -0700 | [diff] [blame] | 152 | #endif |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 153 | |
| 154 | }; // namespace android |
| 155 | |
| 156 | #endif // ANDROID_UI_CACHES_H |