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 | |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 20 | #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 21 | #include <GrContext.h> |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 22 | #endif |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 23 | #include <SkSurface.h> |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 24 | #include <utils/String8.h> |
| 25 | #include <vector> |
Derek Sollenberger | 8ec9e88 | 2017-08-24 16:36:08 -0400 | [diff] [blame] | 26 | |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 27 | namespace android { |
| 28 | |
| 29 | class Surface; |
| 30 | |
| 31 | namespace uirenderer { |
| 32 | |
| 33 | class RenderState; |
| 34 | |
| 35 | namespace renderthread { |
| 36 | |
| 37 | class IRenderPipeline; |
| 38 | class RenderThread; |
| 39 | |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 40 | class CacheManager { |
| 41 | public: |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 42 | enum class TrimMemoryMode { Complete, UiHidden }; |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 43 | |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 44 | #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration |
Yichi Chen | 9f95955 | 2018-03-29 21:21:54 +0800 | [diff] [blame] | 45 | void configureContext(GrContextOptions* context, const void* identity, ssize_t size); |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 46 | #endif |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 47 | void trimMemory(TrimMemoryMode mode); |
| 48 | void trimStaleResources(); |
| 49 | void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr); |
| 50 | |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 51 | size_t getCacheSize() const { return mMaxResourceBytes; } |
| 52 | size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; } |
Stan Iliev | e0fae23 | 2020-01-07 17:21:49 -0500 | [diff] [blame] | 53 | void onFrameCompleted(); |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 54 | |
| 55 | private: |
| 56 | friend class RenderThread; |
| 57 | |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 58 | explicit CacheManager(); |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 59 | |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 60 | #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration |
Greg Daniel | 660d6ec | 2017-12-08 11:44:27 -0500 | [diff] [blame] | 61 | void reset(sk_sp<GrContext> grContext); |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 62 | #endif |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 63 | void destroy(); |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 64 | |
| 65 | const size_t mMaxSurfaceArea; |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 66 | #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 67 | sk_sp<GrContext> mGrContext; |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 68 | #endif |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 69 | |
Derek Sollenberger | b9e296e | 2019-04-18 16:21:42 -0400 | [diff] [blame] | 70 | const size_t mMaxResourceBytes; |
| 71 | const size_t mBackgroundResourceBytes; |
| 72 | |
| 73 | const size_t mMaxGpuFontAtlasBytes; |
| 74 | const size_t mMaxCpuFontCacheBytes; |
| 75 | const size_t mBackgroundCpuFontCacheBytes; |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | } /* namespace renderthread */ |
| 79 | } /* namespace uirenderer */ |
| 80 | } /* namespace android */ |
| 81 | |
| 82 | #endif /* CACHEMANAGER_H */ |