blob: 3ba2690caf3150b55c7e5e7905e7421efc4d160f [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>
Derek Sollenberger8ec9e882017-08-24 16:36:08 -040025
Stan Iliev3310fb12017-03-23 16:56:51 -040026#include "pipeline/skia/VectorDrawableAtlas.h"
Derek Sollenberger8ec9e882017-08-24 16:36:08 -040027#include "thread/TaskManager.h"
28#include "thread/TaskProcessor.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:
45 enum class TrimMemoryMode {
46 Complete,
47 UiHidden
48 };
49
50 void configureContext(GrContextOptions* context);
51 void trimMemory(TrimMemoryMode mode);
52 void trimStaleResources();
53 void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr);
54
Stan Iliev3310fb12017-03-23 16:56:51 -040055 sp<skiapipeline::VectorDrawableAtlas> acquireVectorDrawableAtlas();
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040056
57 size_t getCacheSize() const { return mMaxResourceBytes; }
58 size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; }
59
Derek Sollenberger8ec9e882017-08-24 16:36:08 -040060 TaskManager* getTaskManager() { return &mTaskManager; }
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040061private:
62 friend class RenderThread;
63
64 CacheManager(const DisplayInfo& display);
65
66
67 void reset(GrContext* grContext);
68 void destroy();
69 void updateContextCacheSizes();
70
71 const size_t mMaxSurfaceArea;
72 sk_sp<GrContext> mGrContext;
73
74 int mMaxResources = 0;
75 size_t mMaxResourceBytes = 0;
76 size_t mBackgroundResourceBytes = 0;
77
78 struct PipelineProps {
79 const void* pipelineKey = nullptr;
80 size_t surfaceArea = 0;
81 };
82
Stan Iliev3310fb12017-03-23 16:56:51 -040083 sp<skiapipeline::VectorDrawableAtlas> mVectorDrawableAtlas;
Derek Sollenberger8ec9e882017-08-24 16:36:08 -040084
85 class SkiaTaskProcessor;
86 sp<SkiaTaskProcessor> mTaskProcessor;
87 TaskManager mTaskManager;
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040088};
89
90} /* namespace renderthread */
91} /* namespace uirenderer */
92} /* namespace android */
93
94#endif /* CACHEMANAGER_H */
95