blob: 347daf34f52a52b6bcf0e3de39e7e8a920090768 [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
Jernej Virag44db0402023-05-09 20:24:48 +020034enum class CacheTrimLevel {
35 ALL_CACHES = 0,
36 FONT_CACHE = 1,
37 RESOURCE_CACHE = 2,
38};
39
John Reck5f66fb82022-09-23 17:49:23 -040040struct MemoryPolicy {
41 // The initial scale factor applied to the display resolution. The default is 1, but
42 // lower values may be used to start with a smaller initial cache size. The cache will
43 // be adjusted if larger frames are actually rendered
44 float initialMaxSurfaceAreaScale = 1.0f;
45 // The foreground cache size multiplier. The surface area of the screen will be multiplied
46 // by this
47 float surfaceSizeMultiplier = 12.0f * 4.0f;
48 // How much of the foreground cache size should be preserved when going into the background
49 float backgroundRetentionPercent = 0.5f;
50 // How long after the last renderer goes away before the GPU context is released. A value
51 // of 0 means only drop the context on background TRIM signals
John Reck9e08c2e2022-11-17 15:45:18 -050052 nsecs_t contextTimeout = 10_s;
John Reck5f66fb82022-09-23 17:49:23 -040053 // The minimum amount of time to hold onto items in the resource cache
54 // The actual time used will be the max of this & when frames were actually rendered
55 nsecs_t minimumResourceRetention = 10_s;
56 // If false, use only TRIM_UI_HIDDEN to drive background cache limits;
57 // If true, use all signals (such as all contexts are stopped) to drive the limits
John Reck9e08c2e2022-11-17 15:45:18 -050058 bool useAlternativeUiHidden = true;
John Reck5f66fb82022-09-23 17:49:23 -040059 // Whether or not to only purge scratch resources when triggering UI Hidden or background
60 // collection
61 bool purgeScratchOnly = true;
Jared Dukefbf5a552023-02-17 00:02:29 +000062 // EXPERIMENTAL: Whether or not to trigger releasing GPU context when all contexts are stopped
John Reckc2f72012023-03-21 09:38:56 -040063 // WARNING: Enabling this option can lead to instability, see b/266626090
Jared Dukefbf5a552023-02-17 00:02:29 +000064 bool releaseContextOnStoppedOnly = false;
John Reck5f66fb82022-09-23 17:49:23 -040065};
66
67const MemoryPolicy& loadMemoryPolicy();
68
69} // namespace android::uirenderer