| 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 |  | 
| Jernej Virag | 44db040 | 2023-05-09 20:24:48 +0200 | [diff] [blame] | 34 | enum class CacheTrimLevel { | 
|  | 35 | ALL_CACHES = 0, | 
|  | 36 | FONT_CACHE = 1, | 
|  | 37 | RESOURCE_CACHE = 2, | 
|  | 38 | }; | 
|  | 39 |  | 
| John Reck | 5f66fb8 | 2022-09-23 17:49:23 -0400 | [diff] [blame] | 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 | 
| John Reck | 9e08c2e | 2022-11-17 15:45:18 -0500 | [diff] [blame] | 52 | nsecs_t contextTimeout = 10_s; | 
| John Reck | 5f66fb8 | 2022-09-23 17:49:23 -0400 | [diff] [blame] | 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; | 
| John Reck | 57cee76 | 2023-05-19 10:48:02 -0400 | [diff] [blame] | 56 | // The maximum amount of time to hold onto items in the resource cache | 
|  | 57 | nsecs_t maximumResourceRetention = 100000_s; | 
| John Reck | 5f66fb8 | 2022-09-23 17:49:23 -0400 | [diff] [blame] | 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 | 
| John Reck | 9e08c2e | 2022-11-17 15:45:18 -0500 | [diff] [blame] | 60 | bool useAlternativeUiHidden = true; | 
| John Reck | 5f66fb8 | 2022-09-23 17:49:23 -0400 | [diff] [blame] | 61 | // Whether or not to only purge scratch resources when triggering UI Hidden or background | 
|  | 62 | // collection | 
|  | 63 | bool purgeScratchOnly = true; | 
| Jared Duke | fbf5a55 | 2023-02-17 00:02:29 +0000 | [diff] [blame] | 64 | // EXPERIMENTAL: Whether or not to trigger releasing GPU context when all contexts are stopped | 
| John Reck | c2f7201 | 2023-03-21 09:38:56 -0400 | [diff] [blame] | 65 | // WARNING: Enabling this option can lead to instability, see b/266626090 | 
| Jared Duke | fbf5a55 | 2023-02-17 00:02:29 +0000 | [diff] [blame] | 66 | bool releaseContextOnStoppedOnly = false; | 
| John Reck | 5f66fb8 | 2022-09-23 17:49:23 -0400 | [diff] [blame] | 67 | }; | 
|  | 68 |  | 
|  | 69 | const MemoryPolicy& loadMemoryPolicy(); | 
|  | 70 |  | 
|  | 71 | }  // namespace android::uirenderer |