Caches.h revision a957eea78557cb47a91d44d9e6ee641c58cf1c07
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_HWUI_CACHES_H
18#define ANDROID_HWUI_CACHES_H
19
20#ifndef LOG_TAG
21    #define LOG_TAG "OpenGLRenderer"
22#endif
23
24#include <utils/Singleton.h>
25
26#include "Extensions.h"
27#include "FontRenderer.h"
28#include "GammaFontRenderer.h"
29#include "TextureCache.h"
30#include "LayerCache.h"
31#include "GradientCache.h"
32#include "PatchCache.h"
33#include "ProgramCache.h"
34#include "PathCache.h"
35#include "TextDropShadowCache.h"
36#include "FboCache.h"
37#include "ResourceCache.h"
38
39namespace android {
40namespace uirenderer {
41
42///////////////////////////////////////////////////////////////////////////////
43// Globals
44///////////////////////////////////////////////////////////////////////////////
45
46#define REQUIRED_TEXTURE_UNITS_COUNT 3
47
48#define REGION_MESH_QUAD_COUNT 512
49
50// 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
69struct CacheLogger {
70    CacheLogger() {
71        LOGD("Creating caches");
72    }
73}; // struct CacheLogger
74
75///////////////////////////////////////////////////////////////////////////////
76// Caches
77///////////////////////////////////////////////////////////////////////////////
78
79class Caches: public Singleton<Caches> {
80    Caches();
81    ~Caches();
82
83    friend class Singleton<Caches>;
84
85    CacheLogger mLogger;
86
87    GLuint mCurrentBuffer;
88
89    // Used to render layers
90    TextureVertex* mRegionMesh;
91    GLuint mRegionMeshIndices;
92
93public:
94    /**
95     * Indicates whether the renderer is in debug mode.
96     * This debug mode provides limited information to app developers.
97     */
98    DebugLevel getDebugLevel() const {
99        return mDebugLevel;
100    }
101
102    /**
103     * Call this on each frame to ensure that garbage is deleted from
104     * GPU memory.
105     */
106    void clearGarbage();
107
108    /**
109     * Binds the VBO used to render simple textured quads.
110     */
111    void bindMeshBuffer();
112
113    /**
114     * Binds the specified VBO if needed.
115     */
116    void bindMeshBuffer(const GLuint buffer);
117
118    /**
119     * Unbinds the VBO used to render simple textured quads.
120     */
121    void unbindMeshBuffer();
122
123    /**
124     * Returns the mesh used to draw regions. Calling this method will
125     * bind a VBO of type GL_ELEMENT_ARRAY_BUFFER that contains the
126     * indices for the region mesh.
127     */
128    TextureVertex* getRegionMesh();
129
130    /**
131     * Displays the memory usage of each cache and the total sum.
132     */
133    void dumpMemoryUsage();
134
135    bool blend;
136    GLenum lastSrcMode;
137    GLenum lastDstMode;
138    Program* currentProgram;
139
140    // VBO to draw with
141    GLuint meshBuffer;
142
143    // GL extensions
144    Extensions extensions;
145
146    // Misc
147    GLint maxTextureSize;
148
149    TextureCache textureCache;
150    LayerCache layerCache;
151    GradientCache gradientCache;
152    ProgramCache programCache;
153    PathCache pathCache;
154    PatchCache patchCache;
155    TextDropShadowCache dropShadowCache;
156    FboCache fboCache;
157    GammaFontRenderer fontRenderer;
158    ResourceCache resourceCache;
159
160private:
161    DebugLevel mDebugLevel;
162}; // class Caches
163
164}; // namespace uirenderer
165}; // namespace android
166
167#endif // ANDROID_HWUI_CACHES_H
168