• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
21 namespace android::uirenderer {
22 
23 // Values mirror those from ComponentCallbacks2.java
24 enum 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 
34 enum class CacheTrimLevel {
35     ALL_CACHES = 0,
36     FONT_CACHE = 1,
37     RESOURCE_CACHE = 2,
38 };
39 
40 struct 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
52     nsecs_t contextTimeout = 10_s;
53     // 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     // The maximum amount of time to hold onto items in the resource cache
57     nsecs_t maximumResourceRetention = 100000_s;
58     // If false, use only TRIM_UI_HIDDEN to drive background cache limits;
59     // If true, use all signals (such as all contexts are stopped) to drive the limits
60     bool useAlternativeUiHidden = true;
61     // Whether or not to only purge scratch resources when triggering UI Hidden or background
62     // collection
63     bool purgeScratchOnly = true;
64     // EXPERIMENTAL: Whether or not to trigger releasing GPU context when all contexts are stopped
65     // WARNING: Enabling this option can lead to instability, see b/266626090
66     bool releaseContextOnStoppedOnly = false;
67 };
68 
69 const MemoryPolicy& loadMemoryPolicy();
70 
71 }  // namespace android::uirenderer