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