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" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 21 | #include "ResourceCache.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 22 | #include "renderstate/PixelBufferState.h" |
| 23 | #include "renderstate/TextureState.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 24 | #include "thread/TaskManager.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 25 | #include "thread/TaskProcessor.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 26 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 27 | #include <memory> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 28 | #include <vector> |
Chris Craik | 59744b7 | 2014-07-01 17:56:52 -0700 | [diff] [blame] | 29 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 30 | #include <GLES3/gl3.h> |
| 31 | |
| 32 | #include <utils/KeyedVector.h> |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 33 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 34 | #include <cutils/compiler.h> |
| 35 | |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 36 | #include <SkPath.h> |
| 37 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 38 | #include <vector> |
| 39 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 40 | namespace android { |
| 41 | namespace uirenderer { |
| 42 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 43 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 44 | // Caches |
| 45 | /////////////////////////////////////////////////////////////////////////////// |
| 46 | |
John Reck | e18264b | 2014-03-12 13:56:30 -0700 | [diff] [blame] | 47 | class RenderNode; |
John Reck | 17035b0 | 2014-09-03 07:39:53 -0700 | [diff] [blame] | 48 | class RenderState; |
Romain Guy | bb0acdf | 2012-03-05 13:44:35 -0800 | [diff] [blame] | 49 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 50 | class ANDROID_API Caches { |
| 51 | public: |
| 52 | static Caches& createInstance(RenderState& renderState) { |
| 53 | LOG_ALWAYS_FATAL_IF(sInstance, "double create of Caches attempted"); |
| 54 | sInstance = new Caches(renderState); |
| 55 | return *sInstance; |
| 56 | } |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 57 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 58 | static Caches& getInstance() { |
| 59 | LOG_ALWAYS_FATAL_IF(!sInstance, "instance not yet created"); |
| 60 | return *sInstance; |
| 61 | } |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 62 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 63 | static bool hasInstance() { return sInstance != nullptr; } |
| 64 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 65 | private: |
Chih-Hung Hsieh | faecb78 | 2016-07-21 11:23:06 -0700 | [diff] [blame] | 66 | explicit Caches(RenderState& renderState); |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 67 | static Caches* sInstance; |
Romain Guy | 9bca479 | 2010-10-25 18:42:25 -0700 | [diff] [blame] | 68 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 69 | public: |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 70 | enum class FlushMode { Layers = 0, Moderate, Full }; |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 73 | * Initialize caches. |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 74 | */ |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 75 | bool init(); |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 76 | |
John Reck | db00917 | 2016-03-17 11:02:07 -0700 | [diff] [blame] | 77 | bool isInitialized() { return mInitialized; } |
| 78 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 79 | /** |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 80 | * Flush the cache. |
| 81 | * |
| 82 | * @param mode Indicates how much of the cache should be flushed |
| 83 | */ |
| 84 | void flush(FlushMode mode); |
| 85 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 86 | /** |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 87 | * Destroys all resources associated with this cache. This should |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame] | 88 | * be called after a flush(FlushMode::Full). |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 89 | */ |
| 90 | void terminate(); |
| 91 | |
| 92 | /** |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 93 | * Call this on each frame to ensure that garbage is deleted from |
| 94 | * GPU memory. |
| 95 | */ |
| 96 | void clearGarbage(); |
| 97 | |
| 98 | /** |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 99 | * Returns the GL RGBA internal format to use for the current device |
| 100 | * If the device supports linear blending and needSRGB is true, |
| 101 | * this function returns GL_SRGB8_ALPHA8, otherwise it returns GL_RGBA |
| 102 | */ |
| 103 | constexpr GLint rgbaInternalFormat(bool needSRGB = true) const { |
Romain Guy | efb4b06 | 2017-02-27 11:00:04 -0800 | [diff] [blame] | 104 | return extensions().hasLinearBlending() && needSRGB ? GL_SRGB8_ALPHA8 : GL_RGBA; |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 107 | public: |
Romain Guy | 5dc7fa7 | 2013-03-11 20:48:31 -0700 | [diff] [blame] | 108 | TaskManager tasks; |
| 109 | |
Romain Guy | f9f0016 | 2013-05-09 11:50:12 -0700 | [diff] [blame] | 110 | bool gpuPixelBuffersEnabled; |
| 111 | |
John Reck | 8dc02f9 | 2017-07-17 09:55:02 -0700 | [diff] [blame] | 112 | const Extensions& extensions() const { return DeviceInfo::get()->extensions(); } |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 113 | PixelBufferState& pixelBufferState() { return *mPixelBufferState; } |
| 114 | TextureState& textureState() { return *mTextureState; } |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 115 | |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 116 | private: |
Romain Guy | f9f0016 | 2013-05-09 11:50:12 -0700 | [diff] [blame] | 117 | void initStaticProperties(); |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 118 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 119 | static void eventMarkNull(GLsizei length, const GLchar* marker) {} |
| 120 | static void startMarkNull(GLsizei length, const GLchar* marker) {} |
| 121 | static void endMarkNull() {} |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 122 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 123 | // Used to render layers |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 124 | std::unique_ptr<TextureVertex[]> mRegionMesh; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 125 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 126 | bool mInitialized; |
Romain Guy | 54c1a64 | 2012-09-27 17:55:46 -0700 | [diff] [blame] | 127 | |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 128 | // TODO: move below to RenderState |
| 129 | PixelBufferState* mPixelBufferState = nullptr; |
| 130 | TextureState* mTextureState = nullptr; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 131 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 132 | }; // class Caches |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 133 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 134 | }; // namespace uirenderer |
| 135 | }; // namespace android |