blob: 968251e9f467a58bbe148667def3d57cc4c2f71c [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
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040027namespace android {
28
29class Surface;
30
31namespace uirenderer {
32
33class RenderState;
34
35namespace renderthread {
36
37class IRenderPipeline;
38class RenderThread;
39
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040040class CacheManager {
41public:
John Reck1bcacfd2017-11-03 10:12:19 -070042 enum class TrimMemoryMode { Complete, UiHidden };
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040043
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010044#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
Yichi Chen9f959552018-03-29 21:21:54 +080045 void configureContext(GrContextOptions* context, const void* identity, ssize_t size);
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010046#endif
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040047 void trimMemory(TrimMemoryMode mode);
48 void trimStaleResources();
49 void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr);
50
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040051 size_t getCacheSize() const { return mMaxResourceBytes; }
52 size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; }
53
54private:
55 friend class RenderThread;
56
Alec Mouri22d753f2019-09-05 17:11:45 -070057 explicit CacheManager();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040058
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010059#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
Greg Daniel660d6ec2017-12-08 11:44:27 -050060 void reset(sk_sp<GrContext> grContext);
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010061#endif
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040062 void destroy();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040063
64 const size_t mMaxSurfaceArea;
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010065#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040066 sk_sp<GrContext> mGrContext;
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010067#endif
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040068
Derek Sollenbergerb9e296e2019-04-18 16:21:42 -040069 const size_t mMaxResourceBytes;
70 const size_t mBackgroundResourceBytes;
71
72 const size_t mMaxGpuFontAtlasBytes;
73 const size_t mMaxCpuFontCacheBytes;
74 const size_t mBackgroundCpuFontCacheBytes;
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040075};
76
77} /* namespace renderthread */
78} /* namespace uirenderer */
79} /* namespace android */
80
81#endif /* CACHEMANAGER_H */