blob: 18bb5e6eba1ee3b56b62c9cdbf8296c2eb8290d5 [file] [log] [blame]
Romain Guyfb8b7632010-08-23 21:05:08 -07001/*
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 Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_CACHES_H
18#define ANDROID_HWUI_CACHES_H
Romain Guyfb8b7632010-08-23 21:05:08 -070019
Romain Guya2341a92010-09-08 18:04:33 -070020#ifndef LOG_TAG
21 #define LOG_TAG "OpenGLRenderer"
22#endif
Romain Guyfb8b7632010-08-23 21:05:08 -070023
Chris Craik96a5c4c2015-01-27 15:46:35 -080024
25#include "AssetAtlas.h"
26#include "Dither.h"
27#include "Extensions.h"
28#include "FboCache.h"
29#include "GradientCache.h"
30#include "LayerCache.h"
31#include "PatchCache.h"
32#include "ProgramCache.h"
33#include "PathCache.h"
34#include "RenderBufferCache.h"
35#include "renderstate/PixelBufferState.h"
Chris Craik44eb2c02015-01-29 09:45:09 -080036#include "renderstate/TextureState.h"
Chris Craik96a5c4c2015-01-27 15:46:35 -080037#include "ResourceCache.h"
38#include "TessellationCache.h"
39#include "TextDropShadowCache.h"
40#include "TextureCache.h"
41#include "thread/TaskProcessor.h"
42#include "thread/TaskManager.h"
43
Chris Craik59744b72014-07-01 17:56:52 -070044#include <vector>
Chris Craik96a5c4c2015-01-27 15:46:35 -080045#include <memory>
Chris Craik59744b72014-07-01 17:56:52 -070046
Romain Guy3b748a42013-04-17 18:54:38 -070047#include <GLES3/gl3.h>
48
49#include <utils/KeyedVector.h>
Romain Guyfb8b7632010-08-23 21:05:08 -070050#include <utils/Singleton.h>
Romain Guy3b748a42013-04-17 18:54:38 -070051#include <utils/Vector.h>
Romain Guyfb8b7632010-08-23 21:05:08 -070052
Romain Guy79537452011-10-12 13:48:51 -070053#include <cutils/compiler.h>
54
Tom Hudson2dc236b2014-10-15 15:46:42 -040055#include <SkPath.h>
56
Romain Guyfb8b7632010-08-23 21:05:08 -070057namespace android {
58namespace uirenderer {
59
Tom Hudson2dc236b2014-10-15 15:46:42 -040060class GammaFontRenderer;
61
Romain Guy03750a02010-10-18 14:06:08 -070062///////////////////////////////////////////////////////////////////////////////
Romain Guy03750a02010-10-18 14:06:08 -070063// Caches
64///////////////////////////////////////////////////////////////////////////////
65
John Recke18264b2014-03-12 13:56:30 -070066class RenderNode;
John Reck17035b02014-09-03 07:39:53 -070067class RenderState;
Romain Guybb0acdf2012-03-05 13:44:35 -080068
Chris Craik96a5c4c2015-01-27 15:46:35 -080069class ANDROID_API Caches {
70public:
71 static Caches& createInstance(RenderState& renderState) {
72 LOG_ALWAYS_FATAL_IF(sInstance, "double create of Caches attempted");
73 sInstance = new Caches(renderState);
74 return *sInstance;
75 }
Romain Guyfb8b7632010-08-23 21:05:08 -070076
Chris Craik96a5c4c2015-01-27 15:46:35 -080077 static Caches& getInstance() {
78 LOG_ALWAYS_FATAL_IF(!sInstance, "instance not yet created");
79 return *sInstance;
80 }
Romain Guyfb8b7632010-08-23 21:05:08 -070081
Chris Craik96a5c4c2015-01-27 15:46:35 -080082 static bool hasInstance() {
83 return sInstance != 0;
84 }
85private:
86 Caches(RenderState& renderState);
87 static Caches* sInstance;
Romain Guy9bca4792010-10-25 18:42:25 -070088
Romain Guyfb8b7632010-08-23 21:05:08 -070089public:
Romain Guybdf76092011-07-18 15:00:43 -070090 enum FlushMode {
Romain Guy6d7475d2011-07-27 16:28:21 -070091 kFlushMode_Layers = 0,
92 kFlushMode_Moderate,
Romain Guybdf76092011-07-18 15:00:43 -070093 kFlushMode_Full
94 };
95
96 /**
Romain Guydfa10462012-05-12 16:18:58 -070097 * Initialize caches.
Romain Guy8ff6b9e2011-11-09 20:10:18 -080098 */
Romain Guy3b748a42013-04-17 18:54:38 -070099 bool init();
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800100
101 /**
Romain Guy5bb3c732012-11-29 17:52:58 -0800102 * Initialize global system properties.
103 */
104 bool initProperties();
105
106 /**
Romain Guybdf76092011-07-18 15:00:43 -0700107 * Flush the cache.
108 *
109 * @param mode Indicates how much of the cache should be flushed
110 */
111 void flush(FlushMode mode);
112
Romain Guy5b3b3522010-10-27 18:57:51 -0700113 /**
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800114 * Destroys all resources associated with this cache. This should
115 * be called after a flush(kFlushMode_Full).
116 */
117 void terminate();
118
119 /**
Romain Guye190aa62010-11-10 19:01:29 -0800120 * Indicates whether the renderer is in debug mode.
121 * This debug mode provides limited information to app developers.
122 */
123 DebugLevel getDebugLevel() const {
124 return mDebugLevel;
125 }
126
127 /**
Romain Guy627c6fd2013-08-21 11:53:18 -0700128 * Returns a non-premultiplied ARGB color for the specified
129 * amount of overdraw (1 for 1x, 2 for 2x, etc.)
130 */
131 uint32_t getOverdrawColor(uint32_t amount) const;
132
133 /**
Romain Guyfe48f652010-11-11 15:36:56 -0800134 * Call this on each frame to ensure that garbage is deleted from
135 * GPU memory.
136 */
137 void clearGarbage();
138
139 /**
Romain Guyada830f2011-01-13 12:13:20 -0800140 * Can be used to delete a layer from a non EGL thread.
Romain Guy57066eb2011-01-12 12:53:32 -0800141 */
Romain Guyada830f2011-01-13 12:13:20 -0800142 void deleteLayerDeferred(Layer* layer);
Romain Guy57066eb2011-01-12 12:53:32 -0800143
Romain Guy15bc6432011-12-13 13:11:32 -0800144
Romain Guyef359272013-01-31 19:07:29 -0800145 void startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool discard);
Romain Guy85ef80d2012-09-13 20:26:50 -0700146 void endTiling();
147
Romain Guy82bc7a72012-01-03 14:13:39 -0800148 /**
Romain Guy5b3b3522010-10-27 18:57:51 -0700149 * Returns the mesh used to draw regions. Calling this method will
150 * bind a VBO of type GL_ELEMENT_ARRAY_BUFFER that contains the
151 * indices for the region mesh.
152 */
153 TextureVertex* getRegionMesh();
154
Romain Guyc15008e2010-11-10 11:59:15 -0800155 /**
156 * Displays the memory usage of each cache and the total sum.
157 */
158 void dumpMemoryUsage();
Chet Haase9c1e23b2011-03-24 10:51:31 -0700159 void dumpMemoryUsage(String8& log);
Romain Guyc15008e2010-11-10 11:59:15 -0800160
Romain Guy54c1a642012-09-27 17:55:46 -0700161 bool hasRegisteredFunctors();
162 void registerFunctors(uint32_t functorCount);
163 void unregisterFunctors(uint32_t functorCount);
164
Romain Guy0f6675332013-03-01 14:31:04 -0800165 bool drawDeferDisabled;
166 bool drawReorderDisabled;
167
Romain Guy746b7402010-10-26 16:27:31 -0700168 // Misc
169 GLint maxTextureSize;
Romain Guy3ff0bfd2013-02-25 14:15:37 -0800170
171 // Debugging
Romain Guy4ff0cf42012-08-06 14:51:10 -0700172 bool debugLayersUpdates;
Romain Guy7c450aa2012-09-21 19:15:00 -0700173 bool debugOverdraw;
Romain Guy746b7402010-10-26 16:27:31 -0700174
Romain Guy3ff0bfd2013-02-25 14:15:37 -0800175 enum StencilClipDebug {
176 kStencilHide,
177 kStencilShowHighlight,
178 kStencilShowRegion
179 };
180 StencilClipDebug debugStencilClip;
Chris Craik117bdbc2015-02-05 10:12:38 -0800181private:
182 // Declared before gradientCache and programCache which need this to initialize.
183 // TODO: cleanup / move elsewhere
184 Extensions mExtensions;
185public:
Romain Guyfb8b7632010-08-23 21:05:08 -0700186 TextureCache textureCache;
187 LayerCache layerCache;
Romain Guy8d4aeb72013-02-12 16:08:55 -0800188 RenderBufferCache renderBufferCache;
Romain Guyfb8b7632010-08-23 21:05:08 -0700189 GradientCache gradientCache;
Romain Guyfb8b7632010-08-23 21:05:08 -0700190 PatchCache patchCache;
Chris Craik117bdbc2015-02-05 10:12:38 -0800191 PathCache pathCache;
192 ProgramCache programCache;
Chris Craik05f3d6e2014-06-02 16:27:04 -0700193 TessellationCache tessellationCache;
Romain Guyfb8b7632010-08-23 21:05:08 -0700194 TextDropShadowCache dropShadowCache;
Romain Guye2d345e2010-09-24 18:39:22 -0700195 FboCache fboCache;
Romain Guy29d89972010-09-22 16:10:57 -0700196
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700197 GammaFontRenderer* fontRenderer;
198
Romain Guy5dc7fa72013-03-11 20:48:31 -0700199 TaskManager tasks;
200
Romain Guy0baaac52012-08-31 20:31:01 -0700201 Dither dither;
Romain Guy0baaac52012-08-31 20:31:01 -0700202
Romain Guyf9f00162013-05-09 11:50:12 -0700203 bool gpuPixelBuffersEnabled;
204
Romain Guydfa10462012-05-12 16:18:58 -0700205 // Debug methods
Romain Guy13631f32012-01-30 17:41:55 -0800206 PFNGLINSERTEVENTMARKEREXTPROC eventMark;
207 PFNGLPUSHGROUPMARKEREXTPROC startMark;
208 PFNGLPOPGROUPMARKEREXTPROC endMark;
209
Romain Guydfa10462012-05-12 16:18:58 -0700210 PFNGLLABELOBJECTEXTPROC setLabel;
211 PFNGLGETOBJECTLABELEXTPROC getLabel;
212
Chris Craikba9b6132013-12-15 17:10:19 -0800213 // TEMPORARY properties
214 void initTempProperties();
215 void setTempProperty(const char* name, const char* value);
ztenghuicc3c2562014-01-17 10:34:10 -0800216
Chris Craikf5be3ca2014-04-30 18:20:03 -0700217 float propertyLightDiameter;
218 float propertyLightPosY;
219 float propertyLightPosZ;
220 float propertyAmbientRatio;
ztenghui14a4e352014-08-13 10:44:39 -0700221 int propertyAmbientShadowStrength;
222 int propertySpotShadowStrength;
223
Chris Craik6c15ffa2015-02-02 13:50:55 -0800224 void setProgram(const ProgramDescription& description);
225 void setProgram(Program* program);
226
Chris Craik117bdbc2015-02-05 10:12:38 -0800227 Extensions& extensions() { return mExtensions; }
Chris Craik6c15ffa2015-02-02 13:50:55 -0800228 Program& program() { return *mProgram; }
Chris Craik44eb2c02015-01-29 09:45:09 -0800229 PixelBufferState& pixelBufferState() { return *mPixelBufferState; }
230 TextureState& textureState() { return *mTextureState; }
Chris Craik96a5c4c2015-01-27 15:46:35 -0800231
Romain Guye190aa62010-11-10 19:01:29 -0800232private:
Romain Guy627c6fd2013-08-21 11:53:18 -0700233 enum OverdrawColorSet {
234 kColorSet_Default = 0,
235 kColorSet_Deuteranomaly
236 };
237
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700238 void initFont();
Romain Guydfa10462012-05-12 16:18:58 -0700239 void initExtensions();
240 void initConstraints();
Romain Guyf9f00162013-05-09 11:50:12 -0700241 void initStaticProperties();
Romain Guydfa10462012-05-12 16:18:58 -0700242
Andreas Gampe64bb4132014-11-22 00:35:09 +0000243 static void eventMarkNull(GLsizei length, const GLchar* marker) { }
244 static void startMarkNull(GLsizei length, const GLchar* marker) { }
Romain Guy13631f32012-01-30 17:41:55 -0800245 static void endMarkNull() { }
246
Andreas Gampe64bb4132014-11-22 00:35:09 +0000247 static void setLabelNull(GLenum type, uint object, GLsizei length,
248 const char* label) { }
249 static void getLabelNull(GLenum type, uint object, GLsizei bufferSize,
Romain Guydfa10462012-05-12 16:18:58 -0700250 GLsizei* length, char* label) {
251 if (length) *length = 0;
252 if (label) *label = '\0';
253 }
254
Chris Craik96a5c4c2015-01-27 15:46:35 -0800255 RenderState* mRenderState;
Romain Guy3bbacf22013-02-06 16:51:04 -0800256
Romain Guyf3a910b42011-12-12 20:35:21 -0800257 // Used to render layers
Chris Craik51d6a3d2014-12-22 17:16:56 -0800258 std::unique_ptr<TextureVertex[]> mRegionMesh;
Romain Guy3b748a42013-04-17 18:54:38 -0700259
Romain Guyf3a910b42011-12-12 20:35:21 -0800260 mutable Mutex mGarbageLock;
261 Vector<Layer*> mLayerGarbage;
262
Romain Guye190aa62010-11-10 19:01:29 -0800263 DebugLevel mDebugLevel;
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800264 bool mInitialized;
Romain Guy54c1a642012-09-27 17:55:46 -0700265
266 uint32_t mFunctorsCount;
Romain Guy8aa195d2013-06-04 18:00:09 -0700267
Romain Guy627c6fd2013-08-21 11:53:18 -0700268 OverdrawColorSet mOverdrawDebugColorSet;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800269
270 // TODO: move below to RenderState
271 PixelBufferState* mPixelBufferState = nullptr;
272 TextureState* mTextureState = nullptr;
273 Program* mProgram = nullptr; // note: object owned by ProgramCache
274
Romain Guyfb8b7632010-08-23 21:05:08 -0700275}; // class Caches
276
277}; // namespace uirenderer
Romain Guyfb8b7632010-08-23 21:05:08 -0700278}; // namespace android
279
Romain Guy5b3b3522010-10-27 18:57:51 -0700280#endif // ANDROID_HWUI_CACHES_H