John Reck | 5f66fb8 | 2022-09-23 17:49:23 -0400 | [diff] [blame] | 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 | struct 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 Reck | 9e08c2e | 2022-11-17 15:45:18 -0500 | [diff] [blame^] | 46 | nsecs_t contextTimeout = 10_s; |
John Reck | 5f66fb8 | 2022-09-23 17:49:23 -0400 | [diff] [blame] | 47 | // 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 Reck | 9e08c2e | 2022-11-17 15:45:18 -0500 | [diff] [blame^] | 52 | bool useAlternativeUiHidden = true; |
John Reck | 5f66fb8 | 2022-09-23 17:49:23 -0400 | [diff] [blame] | 53 | // Whether or not to only purge scratch resources when triggering UI Hidden or background |
| 54 | // collection |
| 55 | bool purgeScratchOnly = true; |
| 56 | // EXPERIMENTAL: Whether or not to trigger releasing GPU context when all contexts are stopped |
| 57 | bool releaseContextOnStoppedOnly = false; |
| 58 | }; |
| 59 | |
| 60 | const MemoryPolicy& loadMemoryPolicy(); |
| 61 | |
| 62 | } // namespace android::uirenderer |