blob: dacb7bdb92078508e56c1fcc56b731164bbda440 [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
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010020#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040021#include <GrContext.h>
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010022#endif
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040023#include <SkSurface.h>
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040024#include <utils/String8.h>
25#include <vector>
Derek Sollenberger8ec9e882017-08-24 16:36:08 -040026
Stan Iliev3310fb12017-03-23 16:56:51 -040027#include "pipeline/skia/VectorDrawableAtlas.h"
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040028
29namespace android {
30
31class Surface;
32
33namespace uirenderer {
34
35class RenderState;
36
37namespace renderthread {
38
39class IRenderPipeline;
40class RenderThread;
41
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040042class CacheManager {
43public:
John Reck1bcacfd2017-11-03 10:12:19 -070044 enum class TrimMemoryMode { Complete, UiHidden };
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040045
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010046#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
Yichi Chen9f959552018-03-29 21:21:54 +080047 void configureContext(GrContextOptions* context, const void* identity, ssize_t size);
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010048#endif
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040049 void trimMemory(TrimMemoryMode mode);
50 void trimStaleResources();
51 void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr);
52
Stan Iliev3310fb12017-03-23 16:56:51 -040053 sp<skiapipeline::VectorDrawableAtlas> acquireVectorDrawableAtlas();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040054
55 size_t getCacheSize() const { return mMaxResourceBytes; }
56 size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; }
57
58private:
59 friend class RenderThread;
60
Alec Mouri22d753f2019-09-05 17:11:45 -070061 explicit CacheManager();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040062
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010063#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
Greg Daniel660d6ec2017-12-08 11:44:27 -050064 void reset(sk_sp<GrContext> grContext);
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010065#endif
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040066 void destroy();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040067
68 const size_t mMaxSurfaceArea;
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010069#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040070 sk_sp<GrContext> mGrContext;
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010071#endif
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040072
Derek Sollenbergerb9e296e2019-04-18 16:21:42 -040073 const size_t mMaxResourceBytes;
74 const size_t mBackgroundResourceBytes;
75
76 const size_t mMaxGpuFontAtlasBytes;
77 const size_t mMaxCpuFontCacheBytes;
78 const size_t mBackgroundCpuFontCacheBytes;
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040079
80 struct PipelineProps {
81 const void* pipelineKey = nullptr;
82 size_t surfaceArea = 0;
83 };
84
Stan Iliev3310fb12017-03-23 16:56:51 -040085 sp<skiapipeline::VectorDrawableAtlas> mVectorDrawableAtlas;
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040086};
87
88} /* namespace renderthread */
89} /* namespace uirenderer */
90} /* namespace android */
91
92#endif /* CACHEMANAGER_H */