• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "pipeline/skia/VectorDrawableAtlas.h"
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 
41 class CacheManager {
42 public:
43     enum class TrimMemoryMode { Complete, UiHidden };
44 
45     void configureContext(GrContextOptions* context, const void* identity, ssize_t size);
46     void trimMemory(TrimMemoryMode mode);
47     void trimStaleResources();
48     void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr);
49 
50     sp<skiapipeline::VectorDrawableAtlas> acquireVectorDrawableAtlas();
51 
getCacheSize()52     size_t getCacheSize() const { return mMaxResourceBytes; }
getBackgroundCacheSize()53     size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; }
54 
55 private:
56     friend class RenderThread;
57 
58     explicit CacheManager(const DisplayInfo& display);
59 
60     void reset(sk_sp<GrContext> grContext);
61     void destroy();
62 
63     const size_t mMaxSurfaceArea;
64     sk_sp<GrContext> mGrContext;
65 
66     int mMaxResources = 0;
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;
73 
74     struct PipelineProps {
75         const void* pipelineKey = nullptr;
76         size_t surfaceArea = 0;
77     };
78 
79     sp<skiapipeline::VectorDrawableAtlas> mVectorDrawableAtlas;
80 };
81 
82 } /* namespace renderthread */
83 } /* namespace uirenderer */
84 } /* namespace android */
85 
86 #endif /* CACHEMANAGER_H */
87