blob: 41ced8cebf8322dbf10658f16bc5079a079b9a6b [file] [log] [blame]
John Reck5f66fb82022-09-23 17:49:23 -04001/*
2 * Copyright (C) 2022 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#pragma once
18
19#include "utils/TimeUtils.h"
20
21namespace android::uirenderer {
22
23// Values mirror those from ComponentCallbacks2.java
24enum class TrimLevel {
25 COMPLETE = 80,
26 MODERATE = 60,
27 BACKGROUND = 40,
28 UI_HIDDEN = 20,
29 RUNNING_CRITICAL = 15,
30 RUNNING_LOW = 10,
31 RUNNING_MODERATE = 5,
32};
33
34struct MemoryPolicy {
35 // The initial scale factor applied to the display resolution. The default is 1, but
36 // lower values may be used to start with a smaller initial cache size. The cache will
37 // be adjusted if larger frames are actually rendered
38 float initialMaxSurfaceAreaScale = 1.0f;
39 // The foreground cache size multiplier. The surface area of the screen will be multiplied
40 // by this
41 float surfaceSizeMultiplier = 12.0f * 4.0f;
42 // How much of the foreground cache size should be preserved when going into the background
43 float backgroundRetentionPercent = 0.5f;
44 // How long after the last renderer goes away before the GPU context is released. A value
45 // of 0 means only drop the context on background TRIM signals
John Reck9e08c2e2022-11-17 15:45:18 -050046 nsecs_t contextTimeout = 10_s;
John Reck5f66fb82022-09-23 17:49:23 -040047 // The minimum amount of time to hold onto items in the resource cache
48 // The actual time used will be the max of this & when frames were actually rendered
49 nsecs_t minimumResourceRetention = 10_s;
50 // If false, use only TRIM_UI_HIDDEN to drive background cache limits;
51 // If true, use all signals (such as all contexts are stopped) to drive the limits
John Reck9e08c2e2022-11-17 15:45:18 -050052 bool useAlternativeUiHidden = true;
John Reck5f66fb82022-09-23 17:49:23 -040053 // Whether or not to only purge scratch resources when triggering UI Hidden or background
54 // collection
55 bool purgeScratchOnly = true;
Jared Dukefbf5a552023-02-17 00:02:29 +000056 // EXPERIMENTAL: Whether or not to trigger releasing GPU context when all contexts are stopped
57 bool releaseContextOnStoppedOnly = false;
John Reck5f66fb82022-09-23 17:49:23 -040058};
59
60const MemoryPolicy& loadMemoryPolicy();
61
62} // namespace android::uirenderer