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