2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_HWUI_CACHES_H
18 #define ANDROID_HWUI_CACHES_H
20 #include "AssetAtlas.h"
22 #include "Extensions.h"
24 #include "GammaFontRenderer.h"
25 #include "GradientCache.h"
26 #include "LayerCache.h"
27 #include "PatchCache.h"
28 #include "ProgramCache.h"
29 #include "PathCache.h"
30 #include "RenderBufferCache.h"
31 #include "renderstate/PixelBufferState.h"
32 #include "renderstate/TextureState.h"
33 #include "ResourceCache.h"
34 #include "TessellationCache.h"
35 #include "TextDropShadowCache.h"
36 #include "TextureCache.h"
37 #include "thread/TaskProcessor.h"
38 #include "thread/TaskManager.h"
43 #include <GLES3/gl3.h>
45 #include <utils/KeyedVector.h>
47 #include <cutils/compiler.h>
54 namespace uirenderer {
56 ///////////////////////////////////////////////////////////////////////////////
58 ///////////////////////////////////////////////////////////////////////////////
63 class ANDROID_API Caches {
65 static Caches& createInstance(RenderState& renderState) {
66 LOG_ALWAYS_FATAL_IF(sInstance, "double create of Caches attempted");
67 sInstance = new Caches(renderState);
71 static Caches& getInstance() {
72 LOG_ALWAYS_FATAL_IF(!sInstance, "instance not yet created");
76 static bool hasInstance() {
77 return sInstance != nullptr;
80 Caches(RenderState& renderState);
81 static Caches* sInstance;
84 enum class FlushMode {
95 bool isInitialized() { return mInitialized; }
100 * @param mode Indicates how much of the cache should be flushed
102 void flush(FlushMode mode);
105 * Destroys all resources associated with this cache. This should
106 * be called after a flush(FlushMode::Full).
111 * Returns a non-premultiplied ARGB color for the specified
112 * amount of overdraw (1 for 1x, 2 for 2x, etc.)
114 uint32_t getOverdrawColor(uint32_t amount) const;
117 * Call this on each frame to ensure that garbage is deleted from
123 * Can be used to delete a layer from a non EGL thread.
125 void deleteLayerDeferred(Layer* layer);
128 * Returns the mesh used to draw regions. Calling this method will
129 * bind a VBO of type GL_ELEMENT_ARRAY_BUFFER that contains the
130 * indices for the region mesh.
132 TextureVertex* getRegionMesh();
135 * Displays the memory usage of each cache and the total sum.
137 void dumpMemoryUsage();
138 void dumpMemoryUsage(String8& log);
141 GLint maxTextureSize;
144 // Declared before gradientCache and programCache which need this to initialize.
145 // TODO: cleanup / move elsewhere
146 Extensions mExtensions;
148 TextureCache textureCache;
149 LayerCache layerCache;
150 RenderBufferCache renderBufferCache;
151 GradientCache gradientCache;
152 PatchCache patchCache;
154 ProgramCache programCache;
155 TessellationCache tessellationCache;
156 TextDropShadowCache dropShadowCache;
159 GammaFontRenderer fontRenderer;
165 bool gpuPixelBuffersEnabled;
168 PFNGLINSERTEVENTMARKEREXTPROC eventMark;
169 PFNGLPUSHGROUPMARKEREXTPROC startMark;
170 PFNGLPOPGROUPMARKEREXTPROC endMark;
172 void setProgram(const ProgramDescription& description);
173 void setProgram(Program* program);
175 Extensions& extensions() { return mExtensions; }
176 Program& program() { return *mProgram; }
177 PixelBufferState& pixelBufferState() { return *mPixelBufferState; }
178 TextureState& textureState() { return *mTextureState; }
181 void initExtensions();
182 void initConstraints();
183 void initStaticProperties();
185 static void eventMarkNull(GLsizei length, const GLchar* marker) { }
186 static void startMarkNull(GLsizei length, const GLchar* marker) { }
187 static void endMarkNull() { }
189 RenderState* mRenderState;
191 // Used to render layers
192 std::unique_ptr<TextureVertex[]> mRegionMesh;
194 mutable Mutex mGarbageLock;
195 std::vector<Layer*> mLayerGarbage;
199 // TODO: move below to RenderState
200 PixelBufferState* mPixelBufferState = nullptr;
201 TextureState* mTextureState = nullptr;
202 Program* mProgram = nullptr; // note: object owned by ProgramCache
206 }; // namespace uirenderer
207 }; // namespace android
209 #endif // ANDROID_HWUI_CACHES_H