blob: 90362f33358d7278e764ccc288e5eb30d51a8a60 [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>
Stan Iliev3310fb12017-03-23 16:56:51 -040025#include "pipeline/skia/VectorDrawableAtlas.h"
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040026
27namespace 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:
42 enum class TrimMemoryMode {
43 Complete,
44 UiHidden
45 };
46
47 void configureContext(GrContextOptions* context);
48 void trimMemory(TrimMemoryMode mode);
49 void trimStaleResources();
50 void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr);
51
Stan Iliev3310fb12017-03-23 16:56:51 -040052 sp<skiapipeline::VectorDrawableAtlas> acquireVectorDrawableAtlas();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040053
54 size_t getCacheSize() const { return mMaxResourceBytes; }
55 size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; }
56
57private:
58 friend class RenderThread;
59
60 CacheManager(const DisplayInfo& display);
61
62
63 void reset(GrContext* grContext);
64 void destroy();
65 void updateContextCacheSizes();
66
67 const size_t mMaxSurfaceArea;
68 sk_sp<GrContext> mGrContext;
69
70 int mMaxResources = 0;
71 size_t mMaxResourceBytes = 0;
72 size_t mBackgroundResourceBytes = 0;
73
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 */
87