• 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 #include "pipeline/skia/VectorDrawableAtlas.h"
26 
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 
40 class CacheManager {
41 public:
42     enum class TrimMemoryMode {
43         Complete,
44         UiHidden
45     };
46 
47     void configureContext(GrContextOptions* context);
48     void trimMemory(TrimMemoryMode mode);
49     void trimStaleResources();
50     void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr);
51 
52     sp<skiapipeline::VectorDrawableAtlas> acquireVectorDrawableAtlas();
53 
getCacheSize()54     size_t getCacheSize() const { return mMaxResourceBytes; }
getBackgroundCacheSize()55     size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; }
56 
57 private:
58     friend class RenderThread;
59 
60     CacheManager(const DisplayInfo& display);
61 
62 
63     void reset(GrContext* grContext);
64     void destroy();
65     void updateContextCacheSizes();
66 
67     const size_t mMaxSurfaceArea;
68     sk_sp<GrContext> mGrContext;
69 
70     int mMaxResources = 0;
71     size_t mMaxResourceBytes = 0;
72     size_t mBackgroundResourceBytes = 0;
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 
88