blob: ad251f2364fe5513800904ef67357b2b830f4661 [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>
24#include <ui/DisplayInfo.h>
25#include <utils/String8.h>
26#include <vector>
Derek Sollenberger8ec9e882017-08-24 16:36:08 -040027
Stan Iliev3310fb12017-03-23 16:56:51 -040028#include "pipeline/skia/VectorDrawableAtlas.h"
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040029
30namespace android {
31
32class Surface;
33
34namespace uirenderer {
35
36class RenderState;
37
38namespace renderthread {
39
40class IRenderPipeline;
41class RenderThread;
42
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040043class CacheManager {
44public:
John Reck1bcacfd2017-11-03 10:12:19 -070045 enum class TrimMemoryMode { Complete, UiHidden };
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040046
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010047#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
Yichi Chen9f959552018-03-29 21:21:54 +080048 void configureContext(GrContextOptions* context, const void* identity, ssize_t size);
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010049#endif
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040050 void trimMemory(TrimMemoryMode mode);
51 void trimStaleResources();
52 void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr);
53
Stan Iliev3310fb12017-03-23 16:56:51 -040054 sp<skiapipeline::VectorDrawableAtlas> acquireVectorDrawableAtlas();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040055
56 size_t getCacheSize() const { return mMaxResourceBytes; }
57 size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; }
58
59private:
60 friend class RenderThread;
61
Chih-Hung Hsiehd736d4b2018-12-20 13:55:20 -080062 explicit CacheManager(const DisplayInfo& display);
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040063
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010064#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
Greg Daniel660d6ec2017-12-08 11:44:27 -050065 void reset(sk_sp<GrContext> grContext);
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010066#endif
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040067 void destroy();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040068
69 const size_t mMaxSurfaceArea;
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010070#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040071 sk_sp<GrContext> mGrContext;
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010072#endif
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040073
74 int mMaxResources = 0;
Derek Sollenbergerb9e296e2019-04-18 16:21:42 -040075 const size_t mMaxResourceBytes;
76 const size_t mBackgroundResourceBytes;
77
78 const size_t mMaxGpuFontAtlasBytes;
79 const size_t mMaxCpuFontCacheBytes;
80 const size_t mBackgroundCpuFontCacheBytes;
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040081
82 struct PipelineProps {
83 const void* pipelineKey = nullptr;
84 size_t surfaceArea = 0;
85 };
86
Stan Iliev3310fb12017-03-23 16:56:51 -040087 sp<skiapipeline::VectorDrawableAtlas> mVectorDrawableAtlas;
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040088};
89
90} /* namespace renderthread */
91} /* namespace uirenderer */
92} /* namespace android */
93
94#endif /* CACHEMANAGER_H */