Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 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 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HWUI_CACHES_H |
| 18 | #define ANDROID_HWUI_CACHES_H |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 19 | |
Romain Guy | a2341a9 | 2010-09-08 18:04:33 -0700 | [diff] [blame] | 20 | #ifndef LOG_TAG |
| 21 | #define LOG_TAG "OpenGLRenderer" |
| 22 | #endif |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 23 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 24 | |
| 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 Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 36 | #include "renderstate/TextureState.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 37 | #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 Craik | 59744b7 | 2014-07-01 17:56:52 -0700 | [diff] [blame] | 44 | #include <vector> |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 45 | #include <memory> |
Chris Craik | 59744b7 | 2014-07-01 17:56:52 -0700 | [diff] [blame] | 46 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 47 | #include <GLES3/gl3.h> |
| 48 | |
| 49 | #include <utils/KeyedVector.h> |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 50 | #include <utils/Singleton.h> |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 51 | #include <utils/Vector.h> |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 52 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 53 | #include <cutils/compiler.h> |
| 54 | |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 55 | #include <SkPath.h> |
| 56 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 57 | namespace android { |
| 58 | namespace uirenderer { |
| 59 | |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 60 | class GammaFontRenderer; |
| 61 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 62 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 63 | // Caches |
| 64 | /////////////////////////////////////////////////////////////////////////////// |
| 65 | |
John Reck | e18264b | 2014-03-12 13:56:30 -0700 | [diff] [blame] | 66 | class RenderNode; |
John Reck | 17035b0 | 2014-09-03 07:39:53 -0700 | [diff] [blame] | 67 | class RenderState; |
Romain Guy | bb0acdf | 2012-03-05 13:44:35 -0800 | [diff] [blame] | 68 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 69 | class ANDROID_API Caches { |
| 70 | public: |
| 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 Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 76 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 77 | static Caches& getInstance() { |
| 78 | LOG_ALWAYS_FATAL_IF(!sInstance, "instance not yet created"); |
| 79 | return *sInstance; |
| 80 | } |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 81 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 82 | static bool hasInstance() { |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 83 | return sInstance != nullptr; |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 84 | } |
| 85 | private: |
| 86 | Caches(RenderState& renderState); |
| 87 | static Caches* sInstance; |
Romain Guy | 9bca479 | 2010-10-25 18:42:25 -0700 | [diff] [blame] | 88 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 89 | public: |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 90 | enum FlushMode { |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 91 | kFlushMode_Layers = 0, |
| 92 | kFlushMode_Moderate, |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 93 | kFlushMode_Full |
| 94 | }; |
| 95 | |
| 96 | /** |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 97 | * Initialize caches. |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 98 | */ |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 99 | bool init(); |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 100 | |
| 101 | /** |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 102 | * Flush the cache. |
| 103 | * |
| 104 | * @param mode Indicates how much of the cache should be flushed |
| 105 | */ |
| 106 | void flush(FlushMode mode); |
| 107 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 108 | /** |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 109 | * Destroys all resources associated with this cache. This should |
| 110 | * be called after a flush(kFlushMode_Full). |
| 111 | */ |
| 112 | void terminate(); |
| 113 | |
| 114 | /** |
Romain Guy | 627c6fd | 2013-08-21 11:53:18 -0700 | [diff] [blame] | 115 | * Returns a non-premultiplied ARGB color for the specified |
| 116 | * amount of overdraw (1 for 1x, 2 for 2x, etc.) |
| 117 | */ |
| 118 | uint32_t getOverdrawColor(uint32_t amount) const; |
| 119 | |
| 120 | /** |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 121 | * Call this on each frame to ensure that garbage is deleted from |
| 122 | * GPU memory. |
| 123 | */ |
| 124 | void clearGarbage(); |
| 125 | |
| 126 | /** |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 127 | * Can be used to delete a layer from a non EGL thread. |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 128 | */ |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 129 | void deleteLayerDeferred(Layer* layer); |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 130 | |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 131 | |
Romain Guy | ef35927 | 2013-01-31 19:07:29 -0800 | [diff] [blame] | 132 | void startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool discard); |
Romain Guy | 85ef80d | 2012-09-13 20:26:50 -0700 | [diff] [blame] | 133 | void endTiling(); |
| 134 | |
Romain Guy | 82bc7a7 | 2012-01-03 14:13:39 -0800 | [diff] [blame] | 135 | /** |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 136 | * Returns the mesh used to draw regions. Calling this method will |
| 137 | * bind a VBO of type GL_ELEMENT_ARRAY_BUFFER that contains the |
| 138 | * indices for the region mesh. |
| 139 | */ |
| 140 | TextureVertex* getRegionMesh(); |
| 141 | |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 142 | /** |
| 143 | * Displays the memory usage of each cache and the total sum. |
| 144 | */ |
| 145 | void dumpMemoryUsage(); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 146 | void dumpMemoryUsage(String8& log); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 147 | |
Romain Guy | 54c1a64 | 2012-09-27 17:55:46 -0700 | [diff] [blame] | 148 | bool hasRegisteredFunctors(); |
| 149 | void registerFunctors(uint32_t functorCount); |
| 150 | void unregisterFunctors(uint32_t functorCount); |
| 151 | |
Romain Guy | 746b740 | 2010-10-26 16:27:31 -0700 | [diff] [blame] | 152 | // Misc |
| 153 | GLint maxTextureSize; |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 154 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 155 | private: |
| 156 | // Declared before gradientCache and programCache which need this to initialize. |
| 157 | // TODO: cleanup / move elsewhere |
| 158 | Extensions mExtensions; |
| 159 | public: |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 160 | TextureCache textureCache; |
| 161 | LayerCache layerCache; |
Romain Guy | 8d4aeb7 | 2013-02-12 16:08:55 -0800 | [diff] [blame] | 162 | RenderBufferCache renderBufferCache; |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 163 | GradientCache gradientCache; |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 164 | PatchCache patchCache; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 165 | PathCache pathCache; |
| 166 | ProgramCache programCache; |
Chris Craik | 05f3d6e | 2014-06-02 16:27:04 -0700 | [diff] [blame] | 167 | TessellationCache tessellationCache; |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 168 | TextDropShadowCache dropShadowCache; |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 169 | FboCache fboCache; |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 170 | |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 171 | GammaFontRenderer* fontRenderer; |
| 172 | |
Romain Guy | 5dc7fa7 | 2013-03-11 20:48:31 -0700 | [diff] [blame] | 173 | TaskManager tasks; |
| 174 | |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 175 | Dither dither; |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 176 | |
Romain Guy | f9f0016 | 2013-05-09 11:50:12 -0700 | [diff] [blame] | 177 | bool gpuPixelBuffersEnabled; |
| 178 | |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 179 | // Debug methods |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 180 | PFNGLINSERTEVENTMARKEREXTPROC eventMark; |
| 181 | PFNGLPUSHGROUPMARKEREXTPROC startMark; |
| 182 | PFNGLPOPGROUPMARKEREXTPROC endMark; |
| 183 | |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 184 | void setProgram(const ProgramDescription& description); |
| 185 | void setProgram(Program* program); |
| 186 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 187 | Extensions& extensions() { return mExtensions; } |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 188 | Program& program() { return *mProgram; } |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 189 | PixelBufferState& pixelBufferState() { return *mPixelBufferState; } |
| 190 | TextureState& textureState() { return *mTextureState; } |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 191 | |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 192 | private: |
Romain Guy | 627c6fd | 2013-08-21 11:53:18 -0700 | [diff] [blame] | 193 | |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 194 | void initFont(); |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 195 | void initExtensions(); |
| 196 | void initConstraints(); |
Romain Guy | f9f0016 | 2013-05-09 11:50:12 -0700 | [diff] [blame] | 197 | void initStaticProperties(); |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 198 | |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 199 | static void eventMarkNull(GLsizei length, const GLchar* marker) { } |
| 200 | static void startMarkNull(GLsizei length, const GLchar* marker) { } |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 201 | static void endMarkNull() { } |
| 202 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 203 | RenderState* mRenderState; |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 204 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 205 | // Used to render layers |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 206 | std::unique_ptr<TextureVertex[]> mRegionMesh; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 207 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 208 | mutable Mutex mGarbageLock; |
| 209 | Vector<Layer*> mLayerGarbage; |
| 210 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 211 | bool mInitialized; |
Romain Guy | 54c1a64 | 2012-09-27 17:55:46 -0700 | [diff] [blame] | 212 | |
| 213 | uint32_t mFunctorsCount; |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 214 | |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 215 | // TODO: move below to RenderState |
| 216 | PixelBufferState* mPixelBufferState = nullptr; |
| 217 | TextureState* mTextureState = nullptr; |
| 218 | Program* mProgram = nullptr; // note: object owned by ProgramCache |
| 219 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 220 | }; // class Caches |
| 221 | |
| 222 | }; // namespace uirenderer |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 223 | }; // namespace android |
| 224 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 225 | #endif // ANDROID_HWUI_CACHES_H |