blob: b009cc4f48f25738347036e54298e0c2e4f076a8 [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; }
Stan Ilieve0fae232020-01-07 17:21:49 -050053 void onFrameCompleted();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040054
55private:
56 friend class RenderThread;
57
Alec Mouri22d753f2019-09-05 17:11:45 -070058 explicit CacheManager();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040059
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010060#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
Greg Daniel660d6ec2017-12-08 11:44:27 -050061 void reset(sk_sp<GrContext> grContext);
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010062#endif
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040063 void destroy();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040064
65 const size_t mMaxSurfaceArea;
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010066#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040067 sk_sp<GrContext> mGrContext;
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010068#endif
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040069
Derek Sollenbergerb9e296e2019-04-18 16:21:42 -040070 const size_t mMaxResourceBytes;
71 const size_t mBackgroundResourceBytes;
72
73 const size_t mMaxGpuFontAtlasBytes;
74 const size_t mMaxCpuFontCacheBytes;
75 const size_t mBackgroundCpuFontCacheBytes;
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040076};
77
78} /* namespace renderthread */
79} /* namespace uirenderer */
80} /* namespace android */
81
82#endif /* CACHEMANAGER_H */