Stan Iliev | a683eb3 | 2018-09-04 15:42:18 +0000 | [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 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include "DeviceInfo.h" |
| 20 | #include "Extensions.h" |
| 21 | #include "ResourceCache.h" |
| 22 | #include "renderstate/PixelBufferState.h" |
| 23 | #include "renderstate/TextureState.h" |
| 24 | #include "thread/TaskManager.h" |
| 25 | #include "thread/TaskProcessor.h" |
| 26 | |
| 27 | #include <memory> |
| 28 | #include <vector> |
| 29 | |
| 30 | #include <GLES3/gl3.h> |
| 31 | |
| 32 | #include <utils/KeyedVector.h> |
| 33 | |
| 34 | #include <cutils/compiler.h> |
| 35 | |
| 36 | #include <SkPath.h> |
| 37 | |
| 38 | #include <vector> |
| 39 | |
| 40 | namespace android { |
| 41 | namespace uirenderer { |
| 42 | |
| 43 | /////////////////////////////////////////////////////////////////////////////// |
| 44 | // Caches |
| 45 | /////////////////////////////////////////////////////////////////////////////// |
| 46 | |
| 47 | class RenderNode; |
| 48 | class RenderState; |
| 49 | |
| 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 | } |
| 57 | |
| 58 | static Caches& getInstance() { |
| 59 | LOG_ALWAYS_FATAL_IF(!sInstance, "instance not yet created"); |
| 60 | return *sInstance; |
| 61 | } |
| 62 | |
| 63 | static bool hasInstance() { return sInstance != nullptr; } |
| 64 | |
| 65 | private: |
| 66 | explicit Caches(RenderState& renderState); |
| 67 | static Caches* sInstance; |
| 68 | |
| 69 | public: |
| 70 | enum class FlushMode { Layers = 0, Moderate, Full }; |
| 71 | |
| 72 | /** |
| 73 | * Initialize caches. |
| 74 | */ |
| 75 | bool init(); |
| 76 | |
| 77 | bool isInitialized() { return mInitialized; } |
| 78 | |
| 79 | /** |
| 80 | * Flush the cache. |
| 81 | * |
| 82 | * @param mode Indicates how much of the cache should be flushed |
| 83 | */ |
| 84 | void flush(FlushMode mode); |
| 85 | |
| 86 | /** |
| 87 | * Destroys all resources associated with this cache. This should |
| 88 | * be called after a flush(FlushMode::Full). |
| 89 | */ |
| 90 | void terminate(); |
| 91 | |
| 92 | /** |
| 93 | * Call this on each frame to ensure that garbage is deleted from |
| 94 | * GPU memory. |
| 95 | */ |
| 96 | void clearGarbage(); |
| 97 | |
| 98 | /** |
| 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 { |
| 104 | return extensions().hasLinearBlending() && needSRGB ? GL_SRGB8_ALPHA8 : GL_RGBA; |
| 105 | } |
| 106 | |
| 107 | public: |
| 108 | TaskManager tasks; |
| 109 | |
| 110 | bool gpuPixelBuffersEnabled; |
| 111 | |
| 112 | const Extensions& extensions() const { return DeviceInfo::get()->extensions(); } |
| 113 | PixelBufferState& pixelBufferState() { return *mPixelBufferState; } |
| 114 | TextureState& textureState() { return *mTextureState; } |
| 115 | |
| 116 | private: |
| 117 | void initStaticProperties(); |
| 118 | |
| 119 | static void eventMarkNull(GLsizei length, const GLchar* marker) {} |
| 120 | static void startMarkNull(GLsizei length, const GLchar* marker) {} |
| 121 | static void endMarkNull() {} |
| 122 | |
| 123 | // Used to render layers |
| 124 | std::unique_ptr<TextureVertex[]> mRegionMesh; |
| 125 | |
| 126 | bool mInitialized; |
| 127 | |
| 128 | // TODO: move below to RenderState |
| 129 | PixelBufferState* mPixelBufferState = nullptr; |
| 130 | TextureState* mTextureState = nullptr; |
| 131 | |
| 132 | }; // class Caches |
| 133 | |
| 134 | }; // namespace uirenderer |
| 135 | }; // namespace android |