blob: 9a5a00fcf762b7c2756cdc1827526af8d511ac70 [file] [log] [blame]
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -04001/*
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 Sollenberger8ec9e882017-08-24 16:36:08 -040025
Stan Iliev3310fb12017-03-23 16:56:51 -040026#include "pipeline/skia/VectorDrawableAtlas.h"
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040027
28namespace android {
29
30class Surface;
31
32namespace uirenderer {
33
34class RenderState;
35
36namespace renderthread {
37
38class IRenderPipeline;
39class RenderThread;
40
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040041class CacheManager {
42public:
John Reck1bcacfd2017-11-03 10:12:19 -070043 enum class TrimMemoryMode { Complete, UiHidden };
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040044
Yichi Chen9f959552018-03-29 21:21:54 +080045 void configureContext(GrContextOptions* context, const void* identity, ssize_t size);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040046 void trimMemory(TrimMemoryMode mode);
47 void trimStaleResources();
48 void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr);
49
Stan Iliev3310fb12017-03-23 16:56:51 -040050 sp<skiapipeline::VectorDrawableAtlas> acquireVectorDrawableAtlas();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040051
52 size_t getCacheSize() const { return mMaxResourceBytes; }
53 size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; }
54
55private:
56 friend class RenderThread;
57
Chih-Hung Hsiehd736d4b2018-12-20 13:55:20 -080058 explicit CacheManager(const DisplayInfo& display);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040059
Greg Daniel660d6ec2017-12-08 11:44:27 -050060 void reset(sk_sp<GrContext> grContext);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040061 void destroy();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040062
63 const size_t mMaxSurfaceArea;
64 sk_sp<GrContext> mGrContext;
65
66 int mMaxResources = 0;
Derek Sollenbergerb9e296e2019-04-18 16:21:42 -040067 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 Sollenbergerf9e45d12017-06-01 13:07:39 -040073
74 struct PipelineProps {
75 const void* pipelineKey = nullptr;
76 size_t surfaceArea = 0;
77 };
78
Stan Iliev3310fb12017-03-23 16:56:51 -040079 sp<skiapipeline::VectorDrawableAtlas> mVectorDrawableAtlas;
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040080};
81
82} /* namespace renderthread */
83} /* namespace uirenderer */
84} /* namespace android */
85
86#endif /* CACHEMANAGER_H */