blob: 049d58bcd1336b920c31f35e53594dfb8855d60e [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
Chris Craik96a5c4c2015-01-27 15:46:35 -080020#include "AssetAtlas.h"
21#include "Dither.h"
22#include "Extensions.h"
23#include "FboCache.h"
24#include "GradientCache.h"
25#include "LayerCache.h"
26#include "PatchCache.h"
27#include "ProgramCache.h"
28#include "PathCache.h"
29#include "RenderBufferCache.h"
30#include "renderstate/PixelBufferState.h"
Chris Craik44eb2c02015-01-29 09:45:09 -080031#include "renderstate/TextureState.h"
Chris Craik96a5c4c2015-01-27 15:46:35 -080032#include "ResourceCache.h"
33#include "TessellationCache.h"
34#include "TextDropShadowCache.h"
35#include "TextureCache.h"
36#include "thread/TaskProcessor.h"
37#include "thread/TaskManager.h"
38
Chris Craik59744b72014-07-01 17:56:52 -070039#include <vector>
Chris Craik96a5c4c2015-01-27 15:46:35 -080040#include <memory>
Chris Craik59744b72014-07-01 17:56:52 -070041
Romain Guy3b748a42013-04-17 18:54:38 -070042#include <GLES3/gl3.h>
43
44#include <utils/KeyedVector.h>
Romain Guyfb8b7632010-08-23 21:05:08 -070045#include <utils/Singleton.h>
46
Romain Guy79537452011-10-12 13:48:51 -070047#include <cutils/compiler.h>
48
Tom Hudson2dc236b2014-10-15 15:46:42 -040049#include <SkPath.h>
50
John Reck272a6852015-07-29 16:48:58 -070051#include <vector>
52
Romain Guyfb8b7632010-08-23 21:05:08 -070053namespace android {
54namespace uirenderer {
55
Tom Hudson2dc236b2014-10-15 15:46:42 -040056class GammaFontRenderer;
57
Romain Guy03750a02010-10-18 14:06:08 -070058///////////////////////////////////////////////////////////////////////////////
Romain Guy03750a02010-10-18 14:06:08 -070059// Caches
60///////////////////////////////////////////////////////////////////////////////
61
John Recke18264b2014-03-12 13:56:30 -070062class RenderNode;
John Reck17035b02014-09-03 07:39:53 -070063class RenderState;
Romain Guybb0acdf2012-03-05 13:44:35 -080064
Chris Craik96a5c4c2015-01-27 15:46:35 -080065class ANDROID_API Caches {
66public:
67 static Caches& createInstance(RenderState& renderState) {
68 LOG_ALWAYS_FATAL_IF(sInstance, "double create of Caches attempted");
69 sInstance = new Caches(renderState);
70 return *sInstance;
71 }
Romain Guyfb8b7632010-08-23 21:05:08 -070072
Chris Craik96a5c4c2015-01-27 15:46:35 -080073 static Caches& getInstance() {
74 LOG_ALWAYS_FATAL_IF(!sInstance, "instance not yet created");
75 return *sInstance;
76 }
Romain Guyfb8b7632010-08-23 21:05:08 -070077
Chris Craik96a5c4c2015-01-27 15:46:35 -080078 static bool hasInstance() {
Chris Craik2507c342015-05-04 14:36:49 -070079 return sInstance != nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -080080 }
81private:
82 Caches(RenderState& renderState);
83 static Caches* sInstance;
Romain Guy9bca4792010-10-25 18:42:25 -070084
Romain Guyfb8b7632010-08-23 21:05:08 -070085public:
Romain Guybdf76092011-07-18 15:00:43 -070086 enum FlushMode {
Romain Guy6d7475d2011-07-27 16:28:21 -070087 kFlushMode_Layers = 0,
88 kFlushMode_Moderate,
Romain Guybdf76092011-07-18 15:00:43 -070089 kFlushMode_Full
90 };
91
92 /**
Romain Guydfa10462012-05-12 16:18:58 -070093 * Initialize caches.
Romain Guy8ff6b9e2011-11-09 20:10:18 -080094 */
Romain Guy3b748a42013-04-17 18:54:38 -070095 bool init();
Romain Guy8ff6b9e2011-11-09 20:10:18 -080096
97 /**
Romain Guybdf76092011-07-18 15:00:43 -070098 * Flush the cache.
99 *
100 * @param mode Indicates how much of the cache should be flushed
101 */
102 void flush(FlushMode mode);
103
Romain Guy5b3b3522010-10-27 18:57:51 -0700104 /**
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800105 * Destroys all resources associated with this cache. This should
106 * be called after a flush(kFlushMode_Full).
107 */
108 void terminate();
109
110 /**
Romain Guy627c6fd2013-08-21 11:53:18 -0700111 * Returns a non-premultiplied ARGB color for the specified
112 * amount of overdraw (1 for 1x, 2 for 2x, etc.)
113 */
114 uint32_t getOverdrawColor(uint32_t amount) const;
115
116 /**
Romain Guyfe48f652010-11-11 15:36:56 -0800117 * Call this on each frame to ensure that garbage is deleted from
118 * GPU memory.
119 */
120 void clearGarbage();
121
122 /**
Romain Guyada830f2011-01-13 12:13:20 -0800123 * Can be used to delete a layer from a non EGL thread.
Romain Guy57066eb2011-01-12 12:53:32 -0800124 */
Romain Guyada830f2011-01-13 12:13:20 -0800125 void deleteLayerDeferred(Layer* layer);
Romain Guy57066eb2011-01-12 12:53:32 -0800126
Romain Guy15bc6432011-12-13 13:11:32 -0800127
Romain Guyef359272013-01-31 19:07:29 -0800128 void startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool discard);
Romain Guy85ef80d2012-09-13 20:26:50 -0700129 void endTiling();
130
Romain Guy82bc7a72012-01-03 14:13:39 -0800131 /**
Romain Guy5b3b3522010-10-27 18:57:51 -0700132 * Returns the mesh used to draw regions. Calling this method will
133 * bind a VBO of type GL_ELEMENT_ARRAY_BUFFER that contains the
134 * indices for the region mesh.
135 */
136 TextureVertex* getRegionMesh();
137
Romain Guyc15008e2010-11-10 11:59:15 -0800138 /**
139 * Displays the memory usage of each cache and the total sum.
140 */
141 void dumpMemoryUsage();
Chet Haase9c1e23b2011-03-24 10:51:31 -0700142 void dumpMemoryUsage(String8& log);
Romain Guyc15008e2010-11-10 11:59:15 -0800143
Romain Guy54c1a642012-09-27 17:55:46 -0700144 bool hasRegisteredFunctors();
145 void registerFunctors(uint32_t functorCount);
146 void unregisterFunctors(uint32_t functorCount);
147
Romain Guy746b7402010-10-26 16:27:31 -0700148 // Misc
149 GLint maxTextureSize;
Romain Guy3ff0bfd2013-02-25 14:15:37 -0800150
Chris Craik117bdbc2015-02-05 10:12:38 -0800151private:
152 // Declared before gradientCache and programCache which need this to initialize.
153 // TODO: cleanup / move elsewhere
154 Extensions mExtensions;
155public:
Romain Guyfb8b7632010-08-23 21:05:08 -0700156 TextureCache textureCache;
157 LayerCache layerCache;
Romain Guy8d4aeb72013-02-12 16:08:55 -0800158 RenderBufferCache renderBufferCache;
Romain Guyfb8b7632010-08-23 21:05:08 -0700159 GradientCache gradientCache;
Romain Guyfb8b7632010-08-23 21:05:08 -0700160 PatchCache patchCache;
Chris Craik117bdbc2015-02-05 10:12:38 -0800161 PathCache pathCache;
162 ProgramCache programCache;
Chris Craik05f3d6e2014-06-02 16:27:04 -0700163 TessellationCache tessellationCache;
Romain Guyfb8b7632010-08-23 21:05:08 -0700164 TextDropShadowCache dropShadowCache;
Romain Guye2d345e2010-09-24 18:39:22 -0700165 FboCache fboCache;
Romain Guy29d89972010-09-22 16:10:57 -0700166
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700167 GammaFontRenderer* fontRenderer;
168
Romain Guy5dc7fa72013-03-11 20:48:31 -0700169 TaskManager tasks;
170
Romain Guy0baaac52012-08-31 20:31:01 -0700171 Dither dither;
Romain Guy0baaac52012-08-31 20:31:01 -0700172
Romain Guyf9f00162013-05-09 11:50:12 -0700173 bool gpuPixelBuffersEnabled;
174
Romain Guydfa10462012-05-12 16:18:58 -0700175 // Debug methods
Romain Guy13631f32012-01-30 17:41:55 -0800176 PFNGLINSERTEVENTMARKEREXTPROC eventMark;
177 PFNGLPUSHGROUPMARKEREXTPROC startMark;
178 PFNGLPOPGROUPMARKEREXTPROC endMark;
179
Chris Craik6c15ffa2015-02-02 13:50:55 -0800180 void setProgram(const ProgramDescription& description);
181 void setProgram(Program* program);
182
Chris Craik117bdbc2015-02-05 10:12:38 -0800183 Extensions& extensions() { return mExtensions; }
Chris Craik6c15ffa2015-02-02 13:50:55 -0800184 Program& program() { return *mProgram; }
Chris Craik44eb2c02015-01-29 09:45:09 -0800185 PixelBufferState& pixelBufferState() { return *mPixelBufferState; }
186 TextureState& textureState() { return *mTextureState; }
Chris Craik96a5c4c2015-01-27 15:46:35 -0800187
Romain Guye190aa62010-11-10 19:01:29 -0800188private:
Romain Guy627c6fd2013-08-21 11:53:18 -0700189
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700190 void initFont();
Romain Guydfa10462012-05-12 16:18:58 -0700191 void initExtensions();
192 void initConstraints();
Romain Guyf9f00162013-05-09 11:50:12 -0700193 void initStaticProperties();
Romain Guydfa10462012-05-12 16:18:58 -0700194
Andreas Gampe64bb4132014-11-22 00:35:09 +0000195 static void eventMarkNull(GLsizei length, const GLchar* marker) { }
196 static void startMarkNull(GLsizei length, const GLchar* marker) { }
Romain Guy13631f32012-01-30 17:41:55 -0800197 static void endMarkNull() { }
198
Chris Craik96a5c4c2015-01-27 15:46:35 -0800199 RenderState* mRenderState;
Romain Guy3bbacf22013-02-06 16:51:04 -0800200
Romain Guyf3a910b42011-12-12 20:35:21 -0800201 // Used to render layers
Chris Craik51d6a3d2014-12-22 17:16:56 -0800202 std::unique_ptr<TextureVertex[]> mRegionMesh;
Romain Guy3b748a42013-04-17 18:54:38 -0700203
Romain Guyf3a910b42011-12-12 20:35:21 -0800204 mutable Mutex mGarbageLock;
John Reck272a6852015-07-29 16:48:58 -0700205 std::vector<Layer*> mLayerGarbage;
Romain Guyf3a910b42011-12-12 20:35:21 -0800206
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800207 bool mInitialized;
Romain Guy54c1a642012-09-27 17:55:46 -0700208
209 uint32_t mFunctorsCount;
Romain Guy8aa195d2013-06-04 18:00:09 -0700210
Chris Craik6c15ffa2015-02-02 13:50:55 -0800211 // TODO: move below to RenderState
212 PixelBufferState* mPixelBufferState = nullptr;
213 TextureState* mTextureState = nullptr;
214 Program* mProgram = nullptr; // note: object owned by ProgramCache
215
Romain Guyfb8b7632010-08-23 21:05:08 -0700216}; // class Caches
217
218}; // namespace uirenderer
Romain Guyfb8b7632010-08-23 21:05:08 -0700219}; // namespace android
220
Romain Guy5b3b3522010-10-27 18:57:51 -0700221#endif // ANDROID_HWUI_CACHES_H