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> |
Derek Sollenberger | 8ec9e88 | 2017-08-24 16:36:08 -0400 | [diff] [blame] | 25 | |
Stan Iliev | 3310fb1 | 2017-03-23 16:56:51 -0400 | [diff] [blame] | 26 | #include "pipeline/skia/VectorDrawableAtlas.h" |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | class Surface; |
| 31 | |
| 32 | namespace uirenderer { |
| 33 | |
| 34 | class RenderState; |
| 35 | |
| 36 | namespace renderthread { |
| 37 | |
| 38 | class IRenderPipeline; |
| 39 | class RenderThread; |
| 40 | |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 41 | class CacheManager { |
| 42 | public: |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 43 | enum class TrimMemoryMode { Complete, UiHidden }; |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 44 | |
Yichi Chen | 9f95955 | 2018-03-29 21:21:54 +0800 | [diff] [blame] | 45 | void configureContext(GrContextOptions* context, const void* identity, ssize_t size); |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 46 | void trimMemory(TrimMemoryMode mode); |
| 47 | void trimStaleResources(); |
| 48 | void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr); |
| 49 | |
Stan Iliev | 3310fb1 | 2017-03-23 16:56:51 -0400 | [diff] [blame] | 50 | sp<skiapipeline::VectorDrawableAtlas> acquireVectorDrawableAtlas(); |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 51 | |
| 52 | size_t getCacheSize() const { return mMaxResourceBytes; } |
| 53 | size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; } |
| 54 | |
| 55 | private: |
| 56 | friend class RenderThread; |
| 57 | |
Chih-Hung Hsieh | d736d4b | 2018-12-20 13:55:20 -0800 | [diff] [blame] | 58 | explicit CacheManager(const DisplayInfo& display); |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 59 | |
Greg Daniel | 660d6ec | 2017-12-08 11:44:27 -0500 | [diff] [blame] | 60 | void reset(sk_sp<GrContext> grContext); |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 61 | void destroy(); |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 62 | |
| 63 | const size_t mMaxSurfaceArea; |
| 64 | sk_sp<GrContext> mGrContext; |
| 65 | |
| 66 | int mMaxResources = 0; |
Derek Sollenberger | b9e296e | 2019-04-18 16:21:42 -0400 | [diff] [blame^] | 67 | const size_t mMaxResourceBytes; |
| 68 | const size_t mBackgroundResourceBytes; |
| 69 | |
| 70 | const size_t mMaxGpuFontAtlasBytes; |
| 71 | const size_t mMaxCpuFontCacheBytes; |
| 72 | const size_t mBackgroundCpuFontCacheBytes; |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 73 | |
| 74 | struct PipelineProps { |
| 75 | const void* pipelineKey = nullptr; |
| 76 | size_t surfaceArea = 0; |
| 77 | }; |
| 78 | |
Stan Iliev | 3310fb1 | 2017-03-23 16:56:51 -0400 | [diff] [blame] | 79 | sp<skiapipeline::VectorDrawableAtlas> mVectorDrawableAtlas; |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | } /* namespace renderthread */ |
| 83 | } /* namespace uirenderer */ |
| 84 | } /* namespace android */ |
| 85 | |
| 86 | #endif /* CACHEMANAGER_H */ |