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 | |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 17 | #pragma once |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 18 | |
John Reck | 8dc02f9 | 2017-07-17 09:55:02 -0700 | [diff] [blame] | 19 | #include "DeviceInfo.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 20 | #include "Extensions.h" |
| 21 | #include "FboCache.h" |
Chris Craik | c08820f | 2015-09-22 14:22:29 -0700 | [diff] [blame] | 22 | #include "GammaFontRenderer.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 23 | #include "GradientCache.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 24 | #include "PatchCache.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 25 | #include "PathCache.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 26 | #include "ProgramCache.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 27 | #include "RenderBufferCache.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 28 | #include "ResourceCache.h" |
| 29 | #include "TessellationCache.h" |
| 30 | #include "TextDropShadowCache.h" |
| 31 | #include "TextureCache.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 32 | #include "renderstate/PixelBufferState.h" |
| 33 | #include "renderstate/TextureState.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 34 | #include "thread/TaskManager.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 35 | #include "thread/TaskProcessor.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 36 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 37 | #include <memory> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 38 | #include <vector> |
Chris Craik | 59744b7 | 2014-07-01 17:56:52 -0700 | [diff] [blame] | 39 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 40 | #include <GLES3/gl3.h> |
| 41 | |
| 42 | #include <utils/KeyedVector.h> |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 43 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 44 | #include <cutils/compiler.h> |
| 45 | |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 46 | #include <SkPath.h> |
| 47 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 48 | #include <vector> |
| 49 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 50 | namespace android { |
| 51 | namespace uirenderer { |
| 52 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 53 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 54 | // Caches |
| 55 | /////////////////////////////////////////////////////////////////////////////// |
| 56 | |
John Reck | e18264b | 2014-03-12 13:56:30 -0700 | [diff] [blame] | 57 | class RenderNode; |
John Reck | 17035b0 | 2014-09-03 07:39:53 -0700 | [diff] [blame] | 58 | class RenderState; |
Romain Guy | bb0acdf | 2012-03-05 13:44:35 -0800 | [diff] [blame] | 59 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 60 | class ANDROID_API Caches { |
| 61 | public: |
| 62 | static Caches& createInstance(RenderState& renderState) { |
| 63 | LOG_ALWAYS_FATAL_IF(sInstance, "double create of Caches attempted"); |
| 64 | sInstance = new Caches(renderState); |
| 65 | return *sInstance; |
| 66 | } |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 67 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 68 | static Caches& getInstance() { |
| 69 | LOG_ALWAYS_FATAL_IF(!sInstance, "instance not yet created"); |
| 70 | return *sInstance; |
| 71 | } |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 72 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 73 | static bool hasInstance() { return sInstance != nullptr; } |
| 74 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 75 | private: |
Chih-Hung Hsieh | faecb78 | 2016-07-21 11:23:06 -0700 | [diff] [blame] | 76 | explicit Caches(RenderState& renderState); |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 77 | static Caches* sInstance; |
Romain Guy | 9bca479 | 2010-10-25 18:42:25 -0700 | [diff] [blame] | 78 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 79 | public: |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 80 | enum class FlushMode { Layers = 0, Moderate, Full }; |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 83 | * Initialize caches. |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 84 | */ |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 85 | bool init(); |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 86 | |
John Reck | db00917 | 2016-03-17 11:02:07 -0700 | [diff] [blame] | 87 | bool isInitialized() { return mInitialized; } |
| 88 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 89 | /** |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 90 | * Flush the cache. |
| 91 | * |
| 92 | * @param mode Indicates how much of the cache should be flushed |
| 93 | */ |
| 94 | void flush(FlushMode mode); |
| 95 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 96 | /** |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 97 | * Destroys all resources associated with this cache. This should |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame] | 98 | * be called after a flush(FlushMode::Full). |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 99 | */ |
| 100 | void terminate(); |
| 101 | |
| 102 | /** |
Romain Guy | 627c6fd | 2013-08-21 11:53:18 -0700 | [diff] [blame] | 103 | * Returns a non-premultiplied ARGB color for the specified |
| 104 | * amount of overdraw (1 for 1x, 2 for 2x, etc.) |
| 105 | */ |
| 106 | uint32_t getOverdrawColor(uint32_t amount) const; |
| 107 | |
| 108 | /** |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 109 | * Call this on each frame to ensure that garbage is deleted from |
| 110 | * GPU memory. |
| 111 | */ |
| 112 | void clearGarbage(); |
| 113 | |
| 114 | /** |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 115 | * Can be used to delete a layer from a non EGL thread. |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 116 | */ |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 117 | void deleteLayerDeferred(Layer* layer); |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 118 | |
Romain Guy | 82bc7a7 | 2012-01-03 14:13:39 -0800 | [diff] [blame] | 119 | /** |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 120 | * Returns the mesh used to draw regions. Calling this method will |
| 121 | * bind a VBO of type GL_ELEMENT_ARRAY_BUFFER that contains the |
| 122 | * indices for the region mesh. |
| 123 | */ |
| 124 | TextureVertex* getRegionMesh(); |
| 125 | |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 126 | /** |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 127 | * Returns the GL RGBA internal format to use for the current device |
| 128 | * If the device supports linear blending and needSRGB is true, |
| 129 | * this function returns GL_SRGB8_ALPHA8, otherwise it returns GL_RGBA |
| 130 | */ |
| 131 | constexpr GLint rgbaInternalFormat(bool needSRGB = true) const { |
Romain Guy | efb4b06 | 2017-02-27 11:00:04 -0800 | [diff] [blame] | 132 | return extensions().hasLinearBlending() && needSRGB ? GL_SRGB8_ALPHA8 : GL_RGBA; |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /** |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 136 | * Displays the memory usage of each cache and the total sum. |
| 137 | */ |
| 138 | void dumpMemoryUsage(); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 139 | void dumpMemoryUsage(String8& log); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 140 | |
Romain Guy | 746b740 | 2010-10-26 16:27:31 -0700 | [diff] [blame] | 141 | // Misc |
| 142 | GLint maxTextureSize; |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 143 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 144 | public: |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 145 | TextureCache textureCache; |
Romain Guy | 8d4aeb7 | 2013-02-12 16:08:55 -0800 | [diff] [blame] | 146 | RenderBufferCache renderBufferCache; |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 147 | GradientCache gradientCache; |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 148 | PatchCache patchCache; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 149 | PathCache pathCache; |
| 150 | ProgramCache programCache; |
Chris Craik | 05f3d6e | 2014-06-02 16:27:04 -0700 | [diff] [blame] | 151 | TessellationCache tessellationCache; |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 152 | TextDropShadowCache dropShadowCache; |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 153 | FboCache fboCache; |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 154 | |
Chris Craik | c08820f | 2015-09-22 14:22:29 -0700 | [diff] [blame] | 155 | GammaFontRenderer fontRenderer; |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 156 | |
Romain Guy | 5dc7fa7 | 2013-03-11 20:48:31 -0700 | [diff] [blame] | 157 | TaskManager tasks; |
| 158 | |
Romain Guy | f9f0016 | 2013-05-09 11:50:12 -0700 | [diff] [blame] | 159 | bool gpuPixelBuffersEnabled; |
| 160 | |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 161 | // Debug methods |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 162 | PFNGLINSERTEVENTMARKEREXTPROC eventMark; |
| 163 | PFNGLPUSHGROUPMARKEREXTPROC startMark; |
| 164 | PFNGLPOPGROUPMARKEREXTPROC endMark; |
| 165 | |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 166 | void setProgram(const ProgramDescription& description); |
| 167 | void setProgram(Program* program); |
| 168 | |
John Reck | 8dc02f9 | 2017-07-17 09:55:02 -0700 | [diff] [blame] | 169 | const Extensions& extensions() const { return DeviceInfo::get()->extensions(); } |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 170 | Program& program() { return *mProgram; } |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 171 | PixelBufferState& pixelBufferState() { return *mPixelBufferState; } |
| 172 | TextureState& textureState() { return *mTextureState; } |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 173 | |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 174 | private: |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 175 | void initExtensions(); |
| 176 | void initConstraints(); |
Romain Guy | f9f0016 | 2013-05-09 11:50:12 -0700 | [diff] [blame] | 177 | void initStaticProperties(); |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 178 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 179 | static void eventMarkNull(GLsizei length, const GLchar* marker) {} |
| 180 | static void startMarkNull(GLsizei length, const GLchar* marker) {} |
| 181 | static void endMarkNull() {} |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 182 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 183 | RenderState* mRenderState; |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 184 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 185 | // Used to render layers |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 186 | std::unique_ptr<TextureVertex[]> mRegionMesh; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 187 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 188 | mutable Mutex mGarbageLock; |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 189 | std::vector<Layer*> mLayerGarbage; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 190 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 191 | bool mInitialized; |
Romain Guy | 54c1a64 | 2012-09-27 17:55:46 -0700 | [diff] [blame] | 192 | |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 193 | // TODO: move below to RenderState |
| 194 | PixelBufferState* mPixelBufferState = nullptr; |
| 195 | TextureState* mTextureState = nullptr; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 196 | Program* mProgram = nullptr; // note: object owned by ProgramCache |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 197 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 198 | }; // class Caches |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 199 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 200 | }; // namespace uirenderer |
| 201 | }; // namespace android |