Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | #ifndef CACHEMANAGER_H |
| 18 | #define CACHEMANAGER_H |
| 19 | |
| 20 | #include <GrContext.h> |
| 21 | #include <SkSurface.h> |
| 22 | #include <ui/DisplayInfo.h> |
| 23 | #include <utils/String8.h> |
| 24 | #include <vector> |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | class Surface; |
| 29 | |
| 30 | namespace uirenderer { |
| 31 | |
| 32 | class RenderState; |
| 33 | |
| 34 | namespace renderthread { |
| 35 | |
| 36 | class IRenderPipeline; |
| 37 | class RenderThread; |
| 38 | |
| 39 | struct VectorDrawableAtlas { |
| 40 | sk_sp<SkSurface> surface; |
| 41 | bool isNewAtlas = true; |
| 42 | }; |
| 43 | |
| 44 | class CacheManager { |
| 45 | public: |
| 46 | enum class TrimMemoryMode { |
| 47 | Complete, |
| 48 | UiHidden |
| 49 | }; |
| 50 | |
| 51 | void configureContext(GrContextOptions* context); |
| 52 | void trimMemory(TrimMemoryMode mode); |
| 53 | void trimStaleResources(); |
| 54 | void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr); |
| 55 | |
| 56 | VectorDrawableAtlas* acquireVectorDrawableAtlas(); |
| 57 | void releaseVectorDrawableAtlas(VectorDrawableAtlas*); |
| 58 | |
| 59 | size_t getCacheSize() const { return mMaxResourceBytes; } |
| 60 | size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; } |
| 61 | |
| 62 | private: |
| 63 | friend class RenderThread; |
| 64 | |
| 65 | CacheManager(const DisplayInfo& display); |
| 66 | |
| 67 | |
| 68 | void reset(GrContext* grContext); |
| 69 | void destroy(); |
| 70 | void updateContextCacheSizes(); |
| 71 | |
| 72 | const size_t mMaxSurfaceArea; |
| 73 | sk_sp<GrContext> mGrContext; |
| 74 | |
| 75 | int mMaxResources = 0; |
| 76 | size_t mMaxResourceBytes = 0; |
| 77 | size_t mBackgroundResourceBytes = 0; |
| 78 | |
| 79 | struct PipelineProps { |
| 80 | const void* pipelineKey = nullptr; |
| 81 | size_t surfaceArea = 0; |
| 82 | }; |
| 83 | |
| 84 | std::unique_ptr<VectorDrawableAtlas> mVectorDrawableAtlas; |
| 85 | }; |
| 86 | |
| 87 | } /* namespace renderthread */ |
| 88 | } /* namespace uirenderer */ |
| 89 | } /* namespace android */ |
| 90 | |
| 91 | #endif /* CACHEMANAGER_H */ |
| 92 | |