From d6a18387c2f508ca52aecf4d96419c28b3581752 Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Mon, 30 Sep 2024 22:36:21 +0000 Subject: Remove API level mentions from typedefs Change-Id: I0a988f72133ee4ee0a8c686262b4f5a7efb3985c Flag: EXEMPT bug fix Fixes: 367739111 Test: presubmit --- include/android/surface_control.h | 6 ------ 1 file changed, 6 deletions(-) (limited to 'include/android') diff --git a/include/android/surface_control.h b/include/android/surface_control.h index bf9acb37da..8d61e772cc 100644 --- a/include/android/surface_control.h +++ b/include/android/surface_control.h @@ -156,8 +156,6 @@ typedef struct ASurfaceTransactionStats ASurfaceTransactionStats; * * THREADING * The transaction completed callback can be invoked on any thread. - * - * Available since API level 29. */ typedef void (*ASurfaceTransaction_OnComplete)(void* _Null_unspecified context, ASurfaceTransactionStats* _Nonnull stats); @@ -184,8 +182,6 @@ typedef void (*ASurfaceTransaction_OnComplete)(void* _Null_unspecified context, * * THREADING * The transaction committed callback can be invoked on any thread. - * - * Available since API level 31. */ typedef void (*ASurfaceTransaction_OnCommit)(void* _Null_unspecified context, ASurfaceTransactionStats* _Nonnull stats); @@ -213,8 +209,6 @@ typedef void (*ASurfaceTransaction_OnCommit)(void* _Null_unspecified context, * * THREADING * The callback can be invoked on any thread. - * - * Available since API level 36. */ typedef void (*ASurfaceTransaction_OnBufferRelease)(void* _Null_unspecified context, int release_fence_fd); -- cgit v1.2.3-59-g8ed1b From 769de4ac09e2e4c2bf7ef3da987063769faa78d5 Mon Sep 17 00:00:00 2001 From: Rachel Lee Date: Mon, 28 Oct 2024 10:32:55 -0700 Subject: Define new ASurfaceTransaction_setFrameRateParams API In libandroid. Bug: 362798998 Test: atest SetFrameRateTest Flag: EXEMPT NDK Change-Id: Id52288f77bf43f4c7573c6743e5307d849490852 --- include/android/surface_control.h | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'include/android') diff --git a/include/android/surface_control.h b/include/android/surface_control.h index 8d61e772cc..fe38e86015 100644 --- a/include/android/surface_control.h +++ b/include/android/surface_control.h @@ -762,6 +762,69 @@ void ASurfaceTransaction_setFrameRateWithChangeStrategy(ASurfaceTransaction* _No int8_t changeFrameRateStrategy) __INTRODUCED_IN(31); +/** + * Sets the intended frame rate for the given \a surface_control. + * + * On devices that are capable of running the display at different frame rates, + * the system may choose a display refresh rate to better match this surface's frame + * rate. Usage of this API won't introduce frame rate throttling, or affect other + * aspects of the application's frame production pipeline. However, because the system + * may change the display refresh rate, calls to this function may result in changes + * to Choreographer callback timings, and changes to the time interval at which the + * system releases buffers back to the application. + * + * You can register for changes in the refresh rate using + * \a AChoreographer_registerRefreshRateCallback. + * + * See ASurfaceTransaction_clearFrameRate(). + * + * Available since API level 36. + * + * \param desiredMinRate The desired minimum frame rate (inclusive) for the surface, specifying that + * the surface prefers the device render rate to be at least `desiredMinRate`. + * + *

Set `desiredMinRate` = `desiredMaxRate` to indicate the surface prefers an exact frame rate. + * + *

Set `desiredMinRate` = 0 to indicate the surface has no preference + * and any frame rate is acceptable. + * + *

The value should be greater than or equal to 0. + * + * \param desiredMaxRate The desired maximum frame rate (inclusive) for the surface, specifying that + * the surface prefers the device render rate to be at most `desiredMaxRate`. + * + *

Set `desiredMaxRate` = `desiredMinRate` to indicate the surface prefers an exact frame rate. + * + *

Set `desiredMaxRate` = positive infinity to indicate the surface has no preference + * and any frame rate is acceptable. + * + *

The value should be greater than or equal to `desiredMinRate`. + * + * \param fixedSourceRate The "fixed source" frame rate of the surface if the content has an + * inherently fixed frame rate, e.g. a video that has a specific frame rate. + * + *

When the frame rate chosen for the surface is the `fixedSourceRate` or a + * multiple, the surface can render without frame pulldown, for optimal smoothness. For + * example, a 30 fps video (`fixedSourceRate`=30) renders just as smoothly on 30 fps, + * 60 fps, 90 fps, 120 fps, and so on. + * + *

Setting the fixed source rate can also be used together with a desired + * frame rate min and max via setting `desiredMinRate` and `desiredMaxRate`. This still + * means the surface's content has a fixed frame rate of `fixedSourceRate`, but additionally + * specifies the preference to be in the range [`desiredMinRate`, `desiredMaxRate`]. For example, an + * app might want to specify there is 30 fps video (`fixedSourceRate`=30) as well as a smooth + * animation on the same surface which looks good when drawing within a frame rate range such as + * [`desiredMinRate`, `desiredMaxRate`] = [60,120]. + * + * \param changeFrameRateStrategy Whether display refresh rate transitions caused by this surface + * should be seamless. A seamless transition is one that doesn't have any visual interruptions, such + * as a black screen for a second or two. + */ +void ASurfaceTransaction_setFrameRateParams( + ASurfaceTransaction* _Nonnull transaction, ASurfaceControl* _Nonnull surface_control, + float desiredMinRate, float desiredMaxRate, float fixedSourceRate, + ANativeWindow_ChangeFrameRateStrategy changeFrameRateStrategy) __INTRODUCED_IN(36); + /** * Clears the frame rate which is set for \a surface_control. * -- cgit v1.2.3-59-g8ed1b From 122a1173634edcaf5b50e836185ae0c09c14ac2e Mon Sep 17 00:00:00 2001 From: Matt Buckley Date: Mon, 21 Oct 2024 12:16:36 -0700 Subject: Add public ADPF load hints with better rate limiter and hint batching - Adds ADPF public load hint NDK API - Updates rate limiter to use a single budget for all load hints - Adds support for load hint batching, to send multiple hints at a time - Requires users of load hints to annotate their hints for better traces Bug: 367803904 Test: atest HintManagerServiceTest Test: atest PerformanceHintNativeTestCases Flag: android.os.adpf_use_load_hints Change-Id: I08502599aff0471bd73adc586245da2c924d24e0 --- include/android/performance_hint.h | 64 +++++++++++++++++++++++++++++- include/private/performance_hint_private.h | 12 ++++++ 2 files changed, 75 insertions(+), 1 deletion(-) (limited to 'include/android') diff --git a/include/android/performance_hint.h b/include/android/performance_hint.h index 3f32a5abb3..4233064424 100644 --- a/include/android/performance_hint.h +++ b/include/android/performance_hint.h @@ -19,9 +19,23 @@ * * APerformanceHint allows apps to create performance hint sessions for groups * of threads, and provide hints to the system about the workload of those threads, - * to help the system more accurately allocate power for them. It is the NDK + * to help the system more accurately allocate resources for them. It is the NDK * counterpart to the Java PerformanceHintManager SDK API. * + * This API is intended for periodic workloads, such as frame production. Clients are + * expected to create an instance of APerformanceHintManager, create a session with + * that, and then set a target duration for the session. Then, they can report the actual + * work duration at the end of each cycle to inform the framework about how long those + * workloads are taking. The framework will then compare the actual durations to the target + * duration and attempt to help the client reach a steady state under the target. + * + * Unlike reportActualWorkDuration, the "notify..." hints are intended to be sent in + * advance of large changes in the workload, to prevent them from going over the target + * when there is a sudden, unforseen change. Their effects are intended to last for only + * one cycle, after which reportActualWorkDuration will have a chance to catch up. + * These hints should be used judiciously, only in cases where the workload is changing + * substantially. To enforce that, they are tracked using a per-app rate limiter to avoid + * excessive hinting and encourage clients to be mindful about when to send them. * @{ */ @@ -250,6 +264,54 @@ int APerformanceHint_reportActualWorkDuration2( APerformanceHintSession* _Nonnull session, AWorkDuration* _Nonnull workDuration) __INTRODUCED_IN(__ANDROID_API_V__); +/** + * Informs the framework of an upcoming increase in the workload of a graphics pipeline + * bound to this session. The user can specify whether the increase is expected to be + * on the CPU, GPU, or both. + * + * Sending hints for both CPU and GPU counts as two separate hints for the purposes of the + * rate limiter. + * + * @param cpu Indicates if the workload increase is expected to affect the CPU. + * @param gpu Indicates if the workload increase is expected to affect the GPU. + * @param debugName A required string used to identify this specific hint during + * tracing. This debug string will only be held for the duration of the + * method, and can be safely discarded after. + * + * @return 0 on success. + * EINVAL if no hints were requested. + * EBUSY if the hint was rate limited. + * EPIPE if communication with the system service has failed. + * ENOTSUP if the hint is not supported. + */ +int APerformanceHint_notifyWorkloadIncrease( + APerformanceHintSession* _Nonnull session, + bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36); + +/** + * Informs the framework of an upcoming reset in the workload of a graphics pipeline + * bound to this session, or the imminent start of a new workload. The user can specify + * whether the reset is expected to affect the CPU, GPU, or both. + * + * Sending hints for both CPU and GPU counts as two separate hints for the purposes of the + * this load tracking. + * + * @param cpu Indicates if the workload reset is expected to affect the CPU. + * @param gpu Indicates if the workload reset is expected to affect the GPU. + * @param debugName A required string used to identify this specific hint during + * tracing. This debug string will only be held for the duration of the + * method, and can be safely discarded after. + * + * @return 0 on success. + * EINVAL if no hints were requested. + * EBUSY if the hint was rate limited. + * EPIPE if communication with the system service has failed. + * ENOTSUP if the hint is not supported. + */ +int APerformanceHint_notifyWorkloadReset( + APerformanceHintSession* _Nonnull session, + bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36); + /** * Creates a new AWorkDuration. When the client finishes using {@link AWorkDuration}, it should * call {@link AWorkDuration_release()} to destroy {@link AWorkDuration} and release all resources diff --git a/include/private/performance_hint_private.h b/include/private/performance_hint_private.h index b7308c266c..3229e45203 100644 --- a/include/private/performance_hint_private.h +++ b/include/private/performance_hint_private.h @@ -114,6 +114,18 @@ APerformanceHintSession* APerformanceHint_createSessionInternal(APerformanceHint */ void APerformanceHint_setUseFMQForTesting(bool enabled); +/** + * Get the rate limiter properties for testing. + */ +void APerformanceHint_getRateLimiterPropertiesForTesting( + int32_t* maxLoadHintsPerInterval, int64_t* loadHintInterval); + +/* + * Forces the "new load hint" flag to be disabled for testing. + */ +void APerformanceHint_setUseNewLoadHintBehaviorForTesting(bool newBehavior); + + __END_DECLS #endif // ANDROID_PRIVATE_NATIVE_PERFORMANCE_HINT_PRIVATE_H -- cgit v1.2.3-59-g8ed1b From 3a28c3165d1a6c05c0e176b005eaa8596c487499 Mon Sep 17 00:00:00 2001 From: Vaibhav Devmurari Date: Mon, 4 Nov 2024 11:55:14 +0000 Subject: Add new 25Q2 keycodes to native Test: None Bug: 365920375 Flag: com.android.hardware.input.enable_new_25q2_keycodes Change-Id: If8d07744844eff38226e022dfb04195321a0976b --- include/android/keycodes.h | 38 ++++++++++++++++++++++++++++++++++++++ libs/input/InputEventLabels.cpp | 21 ++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) (limited to 'include/android') diff --git a/include/android/keycodes.h b/include/android/keycodes.h index 79cdbcaf7b..495e0bdb1f 100644 --- a/include/android/keycodes.h +++ b/include/android/keycodes.h @@ -843,6 +843,44 @@ enum { AKEYCODE_EMOJI_PICKER = 317, /** Take Screenshot */ AKEYCODE_SCREENSHOT = 318, + /** To start dictate to an input field */ + AKEYCODE_DICTATE = 319, + /** AC New */ + AKEYCODE_NEW = 320, + /** AC Close */ + AKEYCODE_CLOSE = 321, + /** To toggle 'Do Not Disturb' mode */ + AKEYCODE_DO_NOT_DISTURB = 322, + /** To Print */ + AKEYCODE_PRINT = 323, + /** To Lock the screen */ + AKEYCODE_LOCK = 324, + /** To toggle fullscreen mode (on the current application) */ + AKEYCODE_FULLSCREEN = 325, + /** F13 key */ + AKEYCODE_F13 = 326, + /** F14 key */ + AKEYCODE_F14 = 327, + /** F15 key */ + AKEYCODE_F15 = 328, + /** F16 key */ + AKEYCODE_F16 = 329, + /** F17 key */ + AKEYCODE_F17 = 330, + /** F18 key */ + AKEYCODE_F18 = 331, + /** F19 key */ + AKEYCODE_F19 = 332, + /** F20 key */ + AKEYCODE_F20 = 333, + /** F21 key */ + AKEYCODE_F21 = 334, + /** F22 key */ + AKEYCODE_F22 = 335, + /** F23 key */ + AKEYCODE_F23 = 336, + /** F24 key */ + AKEYCODE_F24 = 337, // NOTE: If you add a new keycode here you must also add it to several other files. // Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list. diff --git a/libs/input/InputEventLabels.cpp b/libs/input/InputEventLabels.cpp index 8db0ca588b..b537feb68f 100644 --- a/libs/input/InputEventLabels.cpp +++ b/libs/input/InputEventLabels.cpp @@ -350,7 +350,26 @@ namespace android { DEFINE_KEYCODE(MACRO_3), \ DEFINE_KEYCODE(MACRO_4), \ DEFINE_KEYCODE(EMOJI_PICKER), \ - DEFINE_KEYCODE(SCREENSHOT) + DEFINE_KEYCODE(SCREENSHOT), \ + DEFINE_KEYCODE(DICTATE), \ + DEFINE_KEYCODE(NEW), \ + DEFINE_KEYCODE(CLOSE), \ + DEFINE_KEYCODE(DO_NOT_DISTURB), \ + DEFINE_KEYCODE(PRINT), \ + DEFINE_KEYCODE(LOCK), \ + DEFINE_KEYCODE(FULLSCREEN), \ + DEFINE_KEYCODE(F13), \ + DEFINE_KEYCODE(F14), \ + DEFINE_KEYCODE(F15), \ + DEFINE_KEYCODE(F16), \ + DEFINE_KEYCODE(F17), \ + DEFINE_KEYCODE(F18), \ + DEFINE_KEYCODE(F19),\ + DEFINE_KEYCODE(F20), \ + DEFINE_KEYCODE(F21), \ + DEFINE_KEYCODE(F22), \ + DEFINE_KEYCODE(F23), \ + DEFINE_KEYCODE(F24) // NOTE: If you add a new axis here you must also add it to several other files. // Refer to frameworks/base/core/java/android/view/MotionEvent.java for the full list. -- cgit v1.2.3-59-g8ed1b From 960967767d222348825e91287255db7cff157325 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Mon, 11 Nov 2024 22:56:34 +0000 Subject: Remove stray character. Change-Id: Id0dc26c5639417061f2676ab25e5c62b775e1a65 Test: None Bug: None --- include/android/choreographer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/android') diff --git a/include/android/choreographer.h b/include/android/choreographer.h index bec3283cd8..2622a01935 100644 --- a/include/android/choreographer.h +++ b/include/android/choreographer.h @@ -318,7 +318,7 @@ size_t AChoreographerFrameCallbackData_getPreferredFrameTimelineIndex( /** * Gets the token used by the platform to identify the frame timeline at the given \c index. - * q + * * Available since API level 33. * * \param index index of a frame timeline, in \f( [0, FrameTimelinesLength) \f). See -- cgit v1.2.3-59-g8ed1b From 147f08c2186062e69f32b1d0a1ea4fc0aeab3ece Mon Sep 17 00:00:00 2001 From: "Priyanka Advani (xWF)" Date: Tue, 12 Nov 2024 18:15:58 +0000 Subject: Revert "Add public ADPF load hints with better rate limiter and ..." Revert submission 29997970-load_hints Reason for revert: Droidmonitor created revert due to b/378700893. Will be verifying through ABTD before submission. Reverted changes: /q/submissionid:29997970-load_hints Change-Id: Ib42a3f0478b84bb36d0a49a311cc3844512f094a --- include/android/performance_hint.h | 64 +----------------------------- include/private/performance_hint_private.h | 12 ------ 2 files changed, 1 insertion(+), 75 deletions(-) (limited to 'include/android') diff --git a/include/android/performance_hint.h b/include/android/performance_hint.h index 4233064424..3f32a5abb3 100644 --- a/include/android/performance_hint.h +++ b/include/android/performance_hint.h @@ -19,23 +19,9 @@ * * APerformanceHint allows apps to create performance hint sessions for groups * of threads, and provide hints to the system about the workload of those threads, - * to help the system more accurately allocate resources for them. It is the NDK + * to help the system more accurately allocate power for them. It is the NDK * counterpart to the Java PerformanceHintManager SDK API. * - * This API is intended for periodic workloads, such as frame production. Clients are - * expected to create an instance of APerformanceHintManager, create a session with - * that, and then set a target duration for the session. Then, they can report the actual - * work duration at the end of each cycle to inform the framework about how long those - * workloads are taking. The framework will then compare the actual durations to the target - * duration and attempt to help the client reach a steady state under the target. - * - * Unlike reportActualWorkDuration, the "notify..." hints are intended to be sent in - * advance of large changes in the workload, to prevent them from going over the target - * when there is a sudden, unforseen change. Their effects are intended to last for only - * one cycle, after which reportActualWorkDuration will have a chance to catch up. - * These hints should be used judiciously, only in cases where the workload is changing - * substantially. To enforce that, they are tracked using a per-app rate limiter to avoid - * excessive hinting and encourage clients to be mindful about when to send them. * @{ */ @@ -264,54 +250,6 @@ int APerformanceHint_reportActualWorkDuration2( APerformanceHintSession* _Nonnull session, AWorkDuration* _Nonnull workDuration) __INTRODUCED_IN(__ANDROID_API_V__); -/** - * Informs the framework of an upcoming increase in the workload of a graphics pipeline - * bound to this session. The user can specify whether the increase is expected to be - * on the CPU, GPU, or both. - * - * Sending hints for both CPU and GPU counts as two separate hints for the purposes of the - * rate limiter. - * - * @param cpu Indicates if the workload increase is expected to affect the CPU. - * @param gpu Indicates if the workload increase is expected to affect the GPU. - * @param debugName A required string used to identify this specific hint during - * tracing. This debug string will only be held for the duration of the - * method, and can be safely discarded after. - * - * @return 0 on success. - * EINVAL if no hints were requested. - * EBUSY if the hint was rate limited. - * EPIPE if communication with the system service has failed. - * ENOTSUP if the hint is not supported. - */ -int APerformanceHint_notifyWorkloadIncrease( - APerformanceHintSession* _Nonnull session, - bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36); - -/** - * Informs the framework of an upcoming reset in the workload of a graphics pipeline - * bound to this session, or the imminent start of a new workload. The user can specify - * whether the reset is expected to affect the CPU, GPU, or both. - * - * Sending hints for both CPU and GPU counts as two separate hints for the purposes of the - * this load tracking. - * - * @param cpu Indicates if the workload reset is expected to affect the CPU. - * @param gpu Indicates if the workload reset is expected to affect the GPU. - * @param debugName A required string used to identify this specific hint during - * tracing. This debug string will only be held for the duration of the - * method, and can be safely discarded after. - * - * @return 0 on success. - * EINVAL if no hints were requested. - * EBUSY if the hint was rate limited. - * EPIPE if communication with the system service has failed. - * ENOTSUP if the hint is not supported. - */ -int APerformanceHint_notifyWorkloadReset( - APerformanceHintSession* _Nonnull session, - bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36); - /** * Creates a new AWorkDuration. When the client finishes using {@link AWorkDuration}, it should * call {@link AWorkDuration_release()} to destroy {@link AWorkDuration} and release all resources diff --git a/include/private/performance_hint_private.h b/include/private/performance_hint_private.h index 3229e45203..b7308c266c 100644 --- a/include/private/performance_hint_private.h +++ b/include/private/performance_hint_private.h @@ -114,18 +114,6 @@ APerformanceHintSession* APerformanceHint_createSessionInternal(APerformanceHint */ void APerformanceHint_setUseFMQForTesting(bool enabled); -/** - * Get the rate limiter properties for testing. - */ -void APerformanceHint_getRateLimiterPropertiesForTesting( - int32_t* maxLoadHintsPerInterval, int64_t* loadHintInterval); - -/* - * Forces the "new load hint" flag to be disabled for testing. - */ -void APerformanceHint_setUseNewLoadHintBehaviorForTesting(bool newBehavior); - - __END_DECLS #endif // ANDROID_PRIVATE_NATIVE_PERFORMANCE_HINT_PRIVATE_H -- cgit v1.2.3-59-g8ed1b From 43a8bd948d9638454e007317ad987d0ff3f34633 Mon Sep 17 00:00:00 2001 From: Matt Buckley Date: Tue, 12 Nov 2024 18:32:39 +0000 Subject: Revert "Revert "Add public ADPF load hints with better rate limi..." Revert submission 30360907-revert-29997970-load_hints-VOSJCKDBUL Reason for revert: because the patch is fine, actually Reverted changes: /q/submissionid:30360907-revert-29997970-load_hints-VOSJCKDBUL Change-Id: I7395b8224c5d2cda2aa02b63e11c9575fbe0db23 --- include/android/performance_hint.h | 64 +++++++++++++++++++++++++++++- include/private/performance_hint_private.h | 12 ++++++ 2 files changed, 75 insertions(+), 1 deletion(-) (limited to 'include/android') diff --git a/include/android/performance_hint.h b/include/android/performance_hint.h index 3f32a5abb3..4233064424 100644 --- a/include/android/performance_hint.h +++ b/include/android/performance_hint.h @@ -19,9 +19,23 @@ * * APerformanceHint allows apps to create performance hint sessions for groups * of threads, and provide hints to the system about the workload of those threads, - * to help the system more accurately allocate power for them. It is the NDK + * to help the system more accurately allocate resources for them. It is the NDK * counterpart to the Java PerformanceHintManager SDK API. * + * This API is intended for periodic workloads, such as frame production. Clients are + * expected to create an instance of APerformanceHintManager, create a session with + * that, and then set a target duration for the session. Then, they can report the actual + * work duration at the end of each cycle to inform the framework about how long those + * workloads are taking. The framework will then compare the actual durations to the target + * duration and attempt to help the client reach a steady state under the target. + * + * Unlike reportActualWorkDuration, the "notify..." hints are intended to be sent in + * advance of large changes in the workload, to prevent them from going over the target + * when there is a sudden, unforseen change. Their effects are intended to last for only + * one cycle, after which reportActualWorkDuration will have a chance to catch up. + * These hints should be used judiciously, only in cases where the workload is changing + * substantially. To enforce that, they are tracked using a per-app rate limiter to avoid + * excessive hinting and encourage clients to be mindful about when to send them. * @{ */ @@ -250,6 +264,54 @@ int APerformanceHint_reportActualWorkDuration2( APerformanceHintSession* _Nonnull session, AWorkDuration* _Nonnull workDuration) __INTRODUCED_IN(__ANDROID_API_V__); +/** + * Informs the framework of an upcoming increase in the workload of a graphics pipeline + * bound to this session. The user can specify whether the increase is expected to be + * on the CPU, GPU, or both. + * + * Sending hints for both CPU and GPU counts as two separate hints for the purposes of the + * rate limiter. + * + * @param cpu Indicates if the workload increase is expected to affect the CPU. + * @param gpu Indicates if the workload increase is expected to affect the GPU. + * @param debugName A required string used to identify this specific hint during + * tracing. This debug string will only be held for the duration of the + * method, and can be safely discarded after. + * + * @return 0 on success. + * EINVAL if no hints were requested. + * EBUSY if the hint was rate limited. + * EPIPE if communication with the system service has failed. + * ENOTSUP if the hint is not supported. + */ +int APerformanceHint_notifyWorkloadIncrease( + APerformanceHintSession* _Nonnull session, + bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36); + +/** + * Informs the framework of an upcoming reset in the workload of a graphics pipeline + * bound to this session, or the imminent start of a new workload. The user can specify + * whether the reset is expected to affect the CPU, GPU, or both. + * + * Sending hints for both CPU and GPU counts as two separate hints for the purposes of the + * this load tracking. + * + * @param cpu Indicates if the workload reset is expected to affect the CPU. + * @param gpu Indicates if the workload reset is expected to affect the GPU. + * @param debugName A required string used to identify this specific hint during + * tracing. This debug string will only be held for the duration of the + * method, and can be safely discarded after. + * + * @return 0 on success. + * EINVAL if no hints were requested. + * EBUSY if the hint was rate limited. + * EPIPE if communication with the system service has failed. + * ENOTSUP if the hint is not supported. + */ +int APerformanceHint_notifyWorkloadReset( + APerformanceHintSession* _Nonnull session, + bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36); + /** * Creates a new AWorkDuration. When the client finishes using {@link AWorkDuration}, it should * call {@link AWorkDuration_release()} to destroy {@link AWorkDuration} and release all resources diff --git a/include/private/performance_hint_private.h b/include/private/performance_hint_private.h index b7308c266c..3229e45203 100644 --- a/include/private/performance_hint_private.h +++ b/include/private/performance_hint_private.h @@ -114,6 +114,18 @@ APerformanceHintSession* APerformanceHint_createSessionInternal(APerformanceHint */ void APerformanceHint_setUseFMQForTesting(bool enabled); +/** + * Get the rate limiter properties for testing. + */ +void APerformanceHint_getRateLimiterPropertiesForTesting( + int32_t* maxLoadHintsPerInterval, int64_t* loadHintInterval); + +/* + * Forces the "new load hint" flag to be disabled for testing. + */ +void APerformanceHint_setUseNewLoadHintBehaviorForTesting(bool newBehavior); + + __END_DECLS #endif // ANDROID_PRIVATE_NATIVE_PERFORMANCE_HINT_PRIVATE_H -- cgit v1.2.3-59-g8ed1b From feb30df98609fc7f1a290187092b97dba423eff5 Mon Sep 17 00:00:00 2001 From: Matt Buckley Date: Sun, 17 Nov 2024 01:56:15 +0000 Subject: Add support for converting java hint sessions to native hint sessions Add an API called "APerformanceHint_getSessionFromJava" for Java clients to access the native APerformanceHintSession objects that Java hint sessions wrap. This should will make the Java and Native APIs substantially more interoperable. This patch also makes the native code aware of when it is being used in Java, to allow it to have slightly different behavior, especially when it is being directly accessed through JNI. The main place where this mostly matters is in preventing clients from closing Java-owned sessions through the JNI, as that could cause weird behavior otherwise. Bug: 367803904 Test: atest HintManagerServiceTest Test: atest PerformanceHintNativeTestCases Flag: EXEMPT trivial refactor Change-Id: I9bae7f78b61e40037de63839103906c3e536a743 --- include/android/performance_hint.h | 19 +++++++++++++++++++ include/private/performance_hint_private.h | 12 ++++++++++++ 2 files changed, 31 insertions(+) (limited to 'include/android') diff --git a/include/android/performance_hint.h b/include/android/performance_hint.h index 976c7d6fb3..22eab9410c 100644 --- a/include/android/performance_hint.h +++ b/include/android/performance_hint.h @@ -49,6 +49,7 @@ #define ANDROID_NATIVE_PERFORMANCE_HINT_H #include +#include /****************************************************************** * @@ -202,6 +203,9 @@ int APerformanceHint_reportActualWorkDuration( * Release the performance hint manager pointer acquired via * {@link APerformanceHint_createSession}. * + * This cannot be used to close a Java PerformanceHintManager.Session, as its + * lifecycle is tied to the object in the SDK. + * * @param session The performance hint session instance to release. */ void APerformanceHint_closeSession( @@ -370,6 +374,21 @@ void AWorkDuration_setActualCpuDurationNanos(AWorkDuration* _Nonnull aWorkDurati void AWorkDuration_setActualGpuDurationNanos(AWorkDuration* _Nonnull aWorkDuration, int64_t actualGpuDurationNanos) __INTRODUCED_IN(__ANDROID_API_V__); +/** + * Return the APerformanceHintSession wrapped by a Java PerformanceHintManager.Session object. + * + * The Java session maintains ownership over the wrapped native session, so it cannot be + * closed using {@link APerformanceHint_closeSession}. + * + * @param env The Java environment where the PerformanceHintManager.Session lives. + * @param sessionObj The Java Session to unwrap. + * + * @return A pointer to the APerformanceHintManager that backs the Java Session. + */ +APerformanceHintSession* _Nonnull APerformanceHint_borrowSessionFromJava( + JNIEnv* _Nonnull env, jobject _Nonnull sessionObj) __INTRODUCED_IN(36); + + __END_DECLS #endif // ANDROID_NATIVE_PERFORMANCE_HINT_H diff --git a/include/private/performance_hint_private.h b/include/private/performance_hint_private.h index 3229e45203..fb31351807 100644 --- a/include/private/performance_hint_private.h +++ b/include/private/performance_hint_private.h @@ -109,6 +109,18 @@ APerformanceHintSession* APerformanceHint_createSessionInternal(APerformanceHint const int32_t* threadIds, size_t size, int64_t initialTargetWorkDurationNanos, SessionTag tag); +/** + * Creates a session from the Java SDK implementation + */ +APerformanceHintSession* APerformanceHint_createSessionFromJava(APerformanceHintManager* manager, + const int32_t* threadIds, size_t size, + int64_t initialTargetWorkDurationNanos); + +/** + * Special method for Java SDK implementation to kill sessions + */ +void APerformanceHint_closeSessionFromJava(APerformanceHintSession* session); + /** * Forces FMQ to be enabled or disabled, for testing only. */ -- cgit v1.2.3-59-g8ed1b From fa8eb01f88bfc8ef61ba863d95c31605f563a721 Mon Sep 17 00:00:00 2001 From: Andy Yu Date: Tue, 15 Oct 2024 17:00:09 -0700 Subject: Implement NDK createSessionUsingConfig API This patch implements a new way to create ADPF hint session, with a new parcelable SessionCreationConfig. This object encapsulates the required information for session creation, with a set of setters to assign values to those fields in the session creation config. This object can be reused on the client side in order to streamline the session creation process. Bug: 362801903 Bug: 367803904 Test: atest HintManagerServiceTest atest PerformanceHintNativeTest Flag: EXEMPT_NDK Change-Id: Idd2ea87886c664b625f40066cc05c6df1bf0e6d4 --- include/android/performance_hint.h | 139 ++++++++++++++++++++++++++++- include/private/performance_hint_private.h | 10 +++ 2 files changed, 145 insertions(+), 4 deletions(-) (limited to 'include/android') diff --git a/include/android/performance_hint.h b/include/android/performance_hint.h index 22eab9410c..37d320a662 100644 --- a/include/android/performance_hint.h +++ b/include/android/performance_hint.h @@ -110,10 +110,25 @@ typedef struct AWorkDuration AWorkDuration; */ typedef struct APerformanceHintManager APerformanceHintManager; +/** + * An opaque type representing a handle to a performance hint session creation configuration. + * It is consumed by {@link APerformanceHint_createSessionUsingConfig}. + * + * A session creation config encapsulates the required information for a session. + * Additionally, the caller can set various settings for the session, + * to be passed during creation, streamlining the session setup process. + * + * The caller may reuse this object and modify the settings in it + * to create additional sessions. + * + */ +typedef struct ASessionCreationConfig ASessionCreationConfig; + /** * An opaque type representing a handle to a performance hint session. * A session can only be acquired from a {@link APerformanceHintManager} - * with {@link APerformanceHint_createSession}. It must be + * with {@link APerformanceHint_createSession} + * or {@link APerformanceHint_createSessionUsingConfig}. It must be * freed with {@link APerformanceHint_closeSession} after use. * * A Session represents a group of threads with an inter-related workload such that hints for @@ -153,13 +168,27 @@ APerformanceHintManager* _Nullable APerformanceHint_getManager() * @param size The size of the list of threadIds. * @param initialTargetWorkDurationNanos The target duration in nanoseconds for the new session. * This must be positive if using the work duration API, or 0 otherwise. - * @return APerformanceHintManager instance on success, nullptr on failure. + * @return APerformanceHintSession pointer on success, nullptr on failure. */ APerformanceHintSession* _Nullable APerformanceHint_createSession( APerformanceHintManager* _Nonnull manager, const int32_t* _Nonnull threadIds, size_t size, int64_t initialTargetWorkDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__); +/** + * Creates a session for the given set of threads that are graphics pipeline threads + * and set their initial target work duration. + * + * @param manager The performance hint manager instance. + * @param config The configuration struct containing required information + * to create a session. + * @return APerformanceHintSession pointer on success, nullptr on failure. + */ +APerformanceHintSession* _Nullable APerformanceHint_createSessionUsingConfig( + APerformanceHintManager* _Nonnull manager, + ASessionCreationConfig* _Nonnull config) + __INTRODUCED_IN(36); + /** * Get preferred update rate information for this device. * @@ -169,6 +198,15 @@ APerformanceHintSession* _Nullable APerformanceHint_createSession( int64_t APerformanceHint_getPreferredUpdateRateNanos( APerformanceHintManager* _Nonnull manager) __INTRODUCED_IN(__ANDROID_API_T__); +/** + * Get maximum number of graphics pipieline threads per-app for this device. + * + * @param manager The performance hint manager instance. + * @return the maximum number of graphics pipeline threads supported by device. + */ + int APerformanceHint_getMaxGraphicsPipelineThreadsCount( + APerformanceHintManager* _Nonnull manager) __INTRODUCED_IN(36); + /** * Updates this session's target duration for each cycle of work. * @@ -320,12 +358,12 @@ int APerformanceHint_notifyWorkloadReset( * call {@link AWorkDuration_release()} to destroy {@link AWorkDuration} and release all resources * associated with it. * - * @return AWorkDuration on success and nullptr otherwise. + * @return AWorkDuration pointer. */ AWorkDuration* _Nonnull AWorkDuration_create() __INTRODUCED_IN(__ANDROID_API_V__); /** - * Destroys {@link AWorkDuration} and free all resources associated to it. + * Destroys a {@link AWorkDuration} and frees all resources associated with it. * * @param aWorkDuration The {@link AWorkDuration} created by calling {@link AWorkDuration_create()} */ @@ -388,6 +426,99 @@ void AWorkDuration_setActualGpuDurationNanos(AWorkDuration* _Nonnull aWorkDurati APerformanceHintSession* _Nonnull APerformanceHint_borrowSessionFromJava( JNIEnv* _Nonnull env, jobject _Nonnull sessionObj) __INTRODUCED_IN(36); +/* + * Creates a new ASessionCreationConfig. + * + * When the client finishes using {@link ASessionCreationConfig}, it should + * call {@link ASessionCreationConfig_release()} to destroy + * {@link ASessionCreationConfig} and release all resources + * associated with it. + * + * @return ASessionCreationConfig pointer. + */ +ASessionCreationConfig* _Nonnull ASessionCreationConfig_create() + __INTRODUCED_IN(36); + + +/** + * Destroys a {@link ASessionCreationConfig} and frees all + * resources associated with it. + * + * @param config The {@link ASessionCreationConfig} + * created by calling {@link ASessionCreationConfig_create()}. + */ +void ASessionCreationConfig_release( + ASessionCreationConfig* _Nonnull config) __INTRODUCED_IN(36); + +/** + * Sets the tids to be associated with the session to be created. + * + * @param config The {@link ASessionCreationConfig} + * created by calling {@link ASessionCreationConfig_create()} + * @param tids The list of tids to be associated with this session. They must be part of + * this process' thread group. + * @param size The size of the list of tids. + * + * @return 0 on success. + * EINVAL if invalid array pointer or the value of size + */ +int ASessionCreationConfig_setTids( + ASessionCreationConfig* _Nonnull config, + const pid_t* _Nonnull tids, size_t size) __INTRODUCED_IN(36); + +/** + * Sets the initial target work duration in nanoseconds for the session to be created. + * + * @param config The {@link ASessionCreationConfig} + * created by calling {@link ASessionCreationConfig_create()}. + * @param targetWorkDurationNanos The parameter to specify a target duration + * in nanoseconds for the new session; this value must be positive to use + * the work duration API. + * + * @return 0 on success. + * ENOTSUP if unsupported + * EINVAL if invalid value + */ +int ASessionCreationConfig_setTargetWorkDurationNanos( + ASessionCreationConfig* _Nonnull config, + int64_t targetWorkDurationNanos) __INTRODUCED_IN(36); + +/** + * Sets whether power efficiency mode will be enabled for the session. + * This tells the session that these threads can be + * safely scheduled to prefer power efficiency over performance. + * + * @param config The {@link ASessionCreationConfig} + * created by calling {@link ASessionCreationConfig_create()}. + * @param enabled Whether power efficiency mode will be enabled. + * + * @return 0 on success. + * ENOTSUP if unsupported + * EINVAL if invalid pointer to creation config + */ +int ASessionCreationConfig_setPreferPowerEfficiency( + ASessionCreationConfig* _Nonnull config, bool enabled) __INTRODUCED_IN(36); + +/** + * Sessions setting this hint are expected to time the critical path of + * graphics pipeline from end to end, with the total work duration + * representing the time from the start of frame production until the + * buffer is fully finished drawing. + * + * It should include any threads on the critical path of that pipeline, + * up to a limit accessible from {@link getMaxGraphicsPipelineThreadsCount()}. + * + * @param config The {@link ASessionCreationConfig} + * created by calling {@link ASessionCreationConfig_create()}. + * @param enabled Whether this session manages a graphics pipeline's critical path. + * + * @return 0 on success. + * ENOTSUP if unsupported + * EINVAL if invalid pointer to creation config or maximum threads for graphics + pipeline is reached. + */ +int ASessionCreationConfig_setGraphicsPipeline( + ASessionCreationConfig* _Nonnull confi, bool enabled) __INTRODUCED_IN(36); __END_DECLS diff --git a/include/private/performance_hint_private.h b/include/private/performance_hint_private.h index fb31351807..f150fb1f3e 100644 --- a/include/private/performance_hint_private.h +++ b/include/private/performance_hint_private.h @@ -108,6 +108,12 @@ int APerformanceHint_getThreadIds(APerformanceHintSession* session, APerformanceHintSession* APerformanceHint_createSessionInternal(APerformanceHintManager* manager, const int32_t* threadIds, size_t size, int64_t initialTargetWorkDurationNanos, SessionTag tag); +/** + * Creates a session using ASessionCreationConfig + */ +APerformanceHintSession* APerformanceHint_createSessionUsingConfigInternal( + APerformanceHintManager* manager, ASessionCreationConfig* sessionCreationConfig, + SessionTag tag); /** * Creates a session from the Java SDK implementation @@ -137,6 +143,10 @@ void APerformanceHint_getRateLimiterPropertiesForTesting( */ void APerformanceHint_setUseNewLoadHintBehaviorForTesting(bool newBehavior); +/* + * Forces the graphics pipeline flag to be enabled or disabled, for testing only. + */ +void APerformanceHint_setUseGraphicsPipelineForTesting(bool enabled); __END_DECLS -- cgit v1.2.3-59-g8ed1b From 01e9f30b4616c68252bf8b5c97031a827a1029e6 Mon Sep 17 00:00:00 2001 From: Sally Qi Date: Mon, 4 Nov 2024 11:40:06 -0800 Subject: [Lut NDK] Add new ASurfaceTransaction_setLuts api. - also provide display_luts.h file for lut and lut entry Bug: 377329333 Test: android.view.surfacecontrol.cts.ASurfaceControlTest#testSurfaceTransaction_setLuts Flag: EXEMPT NDK Change-Id: I4caa4572b5dffb3311c9743e0a2c25ca133d4834 --- include/android/display_luts.h | 163 +++++++++++++++++++++++++++++++++ include/android/surface_control.h | 18 ++++ include/private/display_luts_private.h | 65 +++++++++++++ 3 files changed, 246 insertions(+) create mode 100644 include/android/display_luts.h create mode 100644 include/private/display_luts_private.h (limited to 'include/android') diff --git a/include/android/display_luts.h b/include/android/display_luts.h new file mode 100644 index 0000000000..5026646b4b --- /dev/null +++ b/include/android/display_luts.h @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup NativeActivity Native Activity + * @{ + */ + +/** + * @file display_luts.h + */ +#pragma once + +#include + +__BEGIN_DECLS + +/** + * The dimension of the lut + */ +enum ADisplayLuts_Dimension : int32_t { + ADISPLAYLUTS_ONE_DIMENSION = 1, + ADISPLAYLUTS_THREE_DIMENSION = 3, +}; + +/** + * The sampling key used by the lut + */ +enum ADisplayLuts_SamplingKey : int32_t { + ADISPLAYLUTS_SAMPLINGKEY_RGB = 0, + ADISPLAYLUTS_SAMPLINGKEY_MAX_RGB = 1, +}; + +/** + * Used to get and set display luts entry + */ +typedef struct ADisplayLutsEntry ADisplayLutsEntry; + +/** + * Used to get and set display luts + */ +typedef struct ADisplayLuts ADisplayLuts; + +/** + * Creates a \a ADisplayLutsEntry entry. + * + * You are responsible for mamanging the memory of the returned object. + * Always call \a ADisplayLutsEntry_destroy to release it after use. + * + * Functions like \a ADisplayLuts_set create their own copies of entries, + * therefore they don't take the ownership of the instance created by + * \a ADisplayLutsEntry_create. + * + * @param buffer The lut raw buffer. The function creates a copy of it and does not need to + * outlive the life of the ADisplayLutsEntry. + * @param length The length of lut raw buffer + * @param dimension The dimension of the lut. see \a ADisplayLuts_Dimension + * @param key The sampling key used by the lut. see \a ADisplayLuts_SamplingKey + * @return a new \a ADisplayLutsEntry instance. + */ +ADisplayLutsEntry* _Nonnull ADisplayLutsEntry_createEntry(float* _Nonnull buffer, + int32_t length, int32_t dimension, int32_t key) __INTRODUCED_IN(36); + +/** + * Destroy the \a ADisplayLutsEntry instance. + * + * @param entry The entry to be destroyed + */ +void ADisplayLutsEntry_destroy(ADisplayLutsEntry* _Nullable entry) __INTRODUCED_IN(36); + +/** + * Gets the dimension of the entry. + * + * The function is only valid for the lifetime of the `entry`. + * + * @param entry The entry to query + * @return the dimension of the lut + */ +ADisplayLuts_Dimension ADisplayLutsEntry_getDimension(const ADisplayLutsEntry* _Nonnull entry) + __INTRODUCED_IN(36); + +/** + * Gets the size for each dimension of the entry. + * + * The function is only valid for the lifetime of the `entry`. + * + * @param entry The entry to query + * @return the size of each dimension of the lut + */ +int32_t ADisplayLutsEntry_getSize(const ADisplayLutsEntry* _Nonnull entry) + __INTRODUCED_IN(36); + +/** + * Gets the sampling key used by the entry. + * + * The function is only valid for the lifetime of the `entry`. + * + * @param entry The entry to query + * @return the sampling key used by the lut + */ +ADisplayLuts_SamplingKey ADisplayLutsEntry_getSamplingKey(const ADisplayLutsEntry* _Nonnull entry) + __INTRODUCED_IN(36); + +/** + * Gets the lut buffer of the entry. + * + * The function is only valid for the lifetime of the `entry`. + * + * @param entry The entry to query + * @return a pointer to the raw lut buffer + */ +const float* _Nonnull ADisplayLutsEntry_getBuffer(const ADisplayLutsEntry* _Nonnull entry) + __INTRODUCED_IN(36); + +/** + * Creates a \a ADisplayLuts instance. + * + * You are responsible for mamanging the memory of the returned object. + * Always call \a ADisplayLuts_destroy to release it after use. E.g., after calling + * the function \a ASurfaceTransaction_setLuts. + * + * @return a new \a ADisplayLuts instance + */ +ADisplayLuts* _Nonnull ADisplayLuts_create() __INTRODUCED_IN(36); + +/** + * Sets Luts in order to be applied. + * + * The function accepts a single 1D Lut, or a single 3D Lut or both 1D and 3D Lut in order. + * And the function will replace any previously set lut(s). + * If you want to clear the previously set lut(s), set `entries` to be nullptr, + * and `numEntries` will be internally ignored. + * + * @param luts the pointer of the \a ADisplayLuts instance + * @param entries the pointer of the array of lut entries to be applied + * @param numEntries the number of lut entries. The value should be either 1 or 2. + */ +void ADisplayLuts_setEntries(ADisplayLuts* _Nonnull luts, + ADisplayLutsEntry* _Nullable *_Nullable entries, int32_t numEntries) __INTRODUCED_IN(36); + +/** + * Deletes the \a ADisplayLuts instance. + * + * @param luts The luts to be destroyed + */ +void ADisplayLuts_destroy(ADisplayLuts* _Nullable luts) __INTRODUCED_IN(36); + +__END_DECLS + +/** @} */ \ No newline at end of file diff --git a/include/android/surface_control.h b/include/android/surface_control.h index fe38e86015..95540153b3 100644 --- a/include/android/surface_control.h +++ b/include/android/surface_control.h @@ -28,6 +28,7 @@ #include +#include #include #include #include @@ -712,6 +713,23 @@ void ASurfaceTransaction_setDesiredHdrHeadroom(ASurfaceTransaction* _Nonnull tra float desiredHeadroom) __INTRODUCED_IN(__ANDROID_API_V__); +/** + * Sets the Lut(s) to be applied for the layer. + * + * The function makes a deep copy of the provided `luts`. + * Any modifications made to the `luts` object after calling this function + * will not affect the Lut(s) applied to the layer. + * + * @param surface_control The layer where Lut(s) is being applied + * @param luts The Lut(s) to be applied + * + * Available since API level 36. + */ +void ASurfaceTransaction_setLuts(ASurfaceTransaction* _Nonnull transaction, + ASurfaceControl* _Nonnull surface_control, + const struct ADisplayLuts* _Nullable luts) + __INTRODUCED_IN(36); + /** * Same as ASurfaceTransaction_setFrameRateWithChangeStrategy(transaction, surface_control, * frameRate, compatibility, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS). diff --git a/include/private/display_luts_private.h b/include/private/display_luts_private.h new file mode 100644 index 0000000000..240e1f98cf --- /dev/null +++ b/include/private/display_luts_private.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +using namespace android; + +__BEGIN_DECLS + +struct ADisplayLutsEntry_buffer { + std::vector data; +}; + +struct ADisplayLutsEntry_properties { + int32_t dimension; + int32_t size; + int32_t samplingKey; +}; + +struct ADisplayLutsEntry: public RefBase { + struct ADisplayLutsEntry_buffer buffer; + struct ADisplayLutsEntry_properties properties; + ADisplayLutsEntry() {} + + // copy constructor + ADisplayLutsEntry(const ADisplayLutsEntry& other) : + buffer(other.buffer), + properties(other.properties) {} + + // copy operator + ADisplayLutsEntry& operator=(const ADisplayLutsEntry& other) { + if (this != &other) { // Protect against self-assignment + buffer = other.buffer; + properties = other.properties; + } + return *this; + } +}; + +struct ADisplayLuts: public RefBase { + int32_t totalBufferSize; + std::vector offsets; + std::vector> entries; + + ADisplayLuts() : totalBufferSize(0) {} +}; + +__END_DECLS \ No newline at end of file -- cgit v1.2.3-59-g8ed1b From d54e5890517ed5318a80e3b12ba75544f6972a1d Mon Sep 17 00:00:00 2001 From: Andy Yu Date: Thu, 21 Nov 2024 09:46:22 -0800 Subject: Fix typo in ASessionConfig_setGraphicsPipeline signature Bug: 362801903 Bug: 367803904 Test: atest HintManagerServiceTest atest PerformanceHintNativeTest Flag: EXEMPT_NDK Change-Id: I04e0248572dd9342d1ac35b8fce80768502c56dc --- include/android/performance_hint.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/android') diff --git a/include/android/performance_hint.h b/include/android/performance_hint.h index 37d320a662..fba063db69 100644 --- a/include/android/performance_hint.h +++ b/include/android/performance_hint.h @@ -518,7 +518,7 @@ int ASessionCreationConfig_setPreferPowerEfficiency( pipeline is reached. */ int ASessionCreationConfig_setGraphicsPipeline( - ASessionCreationConfig* _Nonnull confi, bool enabled) __INTRODUCED_IN(36); + ASessionCreationConfig* _Nonnull config, bool enabled) __INTRODUCED_IN(36); __END_DECLS -- cgit v1.2.3-59-g8ed1b From 345be9446f75f29753f4531502270a251b194e38 Mon Sep 17 00:00:00 2001 From: Sally Qi Date: Fri, 22 Nov 2024 19:11:28 +0000 Subject: Fix the return type of ADisplayLutsEntry_getDimension and ADisplayLutsEntry_getSamplingKey. - to fix https://screenshot.googleplex.com/4BTVD4TjjDfuwcs Bug: n/a Change-Id: I9fdc07acef94be75f251a0246cea5116ac01f892 Test: builds Flag: EXEMPT NDK --- include/android/display_luts.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/android') diff --git a/include/android/display_luts.h b/include/android/display_luts.h index 5026646b4b..08dfb12d6c 100644 --- a/include/android/display_luts.h +++ b/include/android/display_luts.h @@ -35,6 +35,7 @@ enum ADisplayLuts_Dimension : int32_t { ADISPLAYLUTS_ONE_DIMENSION = 1, ADISPLAYLUTS_THREE_DIMENSION = 3, }; +typedef enum ADisplayLuts_Dimension ADisplayLuts_Dimension; /** * The sampling key used by the lut @@ -43,6 +44,7 @@ enum ADisplayLuts_SamplingKey : int32_t { ADISPLAYLUTS_SAMPLINGKEY_RGB = 0, ADISPLAYLUTS_SAMPLINGKEY_MAX_RGB = 1, }; +typedef enum ADisplayLuts_SamplingKey ADisplayLuts_SamplingKey; /** * Used to get and set display luts entry -- cgit v1.2.3-59-g8ed1b From c3cab95207ee962e30e80e48b5d86b0732e17664 Mon Sep 17 00:00:00 2001 From: Sally Qi Date: Fri, 22 Nov 2024 21:18:11 +0000 Subject: [LUT NDK] Add CIE_Y sampling key to ADisplayLuts_SamplingKey enum. Bug: 358422255 Change-Id: I33ffd8c9a843740653f7b838b426ba412aa292a1 Test: builds Flag: EXEMPT NDK --- include/android/display_luts.h | 4 +++- include/private/display_luts_private.h | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'include/android') diff --git a/include/android/display_luts.h b/include/android/display_luts.h index 08dfb12d6c..eae2bfd351 100644 --- a/include/android/display_luts.h +++ b/include/android/display_luts.h @@ -43,6 +43,7 @@ typedef enum ADisplayLuts_Dimension ADisplayLuts_Dimension; enum ADisplayLuts_SamplingKey : int32_t { ADISPLAYLUTS_SAMPLINGKEY_RGB = 0, ADISPLAYLUTS_SAMPLINGKEY_MAX_RGB = 1, + ADISPLAYLUTS_SAMPLINGKEY_CIE_Y = 2, }; typedef enum ADisplayLuts_SamplingKey ADisplayLuts_SamplingKey; @@ -74,7 +75,8 @@ typedef struct ADisplayLuts ADisplayLuts; * @return a new \a ADisplayLutsEntry instance. */ ADisplayLutsEntry* _Nonnull ADisplayLutsEntry_createEntry(float* _Nonnull buffer, - int32_t length, int32_t dimension, int32_t key) __INTRODUCED_IN(36); + int32_t length, ADisplayLuts_Dimension dimension, ADisplayLuts_SamplingKey key) + __INTRODUCED_IN(36); /** * Destroy the \a ADisplayLutsEntry instance. diff --git a/include/private/display_luts_private.h b/include/private/display_luts_private.h index 240e1f98cf..c347a0c85d 100644 --- a/include/private/display_luts_private.h +++ b/include/private/display_luts_private.h @@ -16,6 +16,7 @@ #pragma once +#include #include #include #include @@ -29,9 +30,9 @@ struct ADisplayLutsEntry_buffer { }; struct ADisplayLutsEntry_properties { - int32_t dimension; + ADisplayLuts_Dimension dimension; int32_t size; - int32_t samplingKey; + ADisplayLuts_SamplingKey samplingKey; }; struct ADisplayLutsEntry: public RefBase { -- cgit v1.2.3-59-g8ed1b From 4b8c0c6212f28a733a28ca8eb529772534aecf48 Mon Sep 17 00:00:00 2001 From: Matt Buckley Date: Tue, 19 Nov 2024 14:36:42 -0800 Subject: Add new surface binding for ADPF Timeline API Add new APIs to allow sessions to bind to ANativeWindows and ASurfaceControls for the ADPF timeline API, and expose a new way for sessions to run automatically in certain circumstances. Flag: EXEMPT NDK_API Bug: 360908317 Bug: 367803904 Test: atest HintManagerServiceTest Test: atest PerformanceHintManagerTest Test: atest PerformanceHintNativeTestCases Change-Id: I0a60743ba6815d400210dc04b9116a675880d443 --- include/android/performance_hint.h | 92 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 'include/android') diff --git a/include/android/performance_hint.h b/include/android/performance_hint.h index fba063db69..75a8bd49fc 100644 --- a/include/android/performance_hint.h +++ b/include/android/performance_hint.h @@ -76,6 +76,8 @@ __BEGIN_DECLS struct APerformanceHintManager; struct APerformanceHintSession; struct AWorkDuration; +struct ANativeWindow; +struct ASurfaceControl; /** * {@link AWorkDuration} is an opaque type that represents the breakdown of the @@ -353,6 +355,39 @@ int APerformanceHint_notifyWorkloadReset( APerformanceHintSession* _Nonnull session, bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36); +/** + * Associates a session with any {@link ASurfaceControl} or {@link ANativeWindow} + * instances managed by this session. + * + * This method is primarily intended for sessions that manage the timing of an entire + * graphics pipeline end-to-end, such as those using the + * {@link ASessionCreationConfig_setGraphicsPipeline} API. However, any session directly + * or indirectly managing a graphics pipeline should still associate themselves with + * directly relevant ASurfaceControl or ANativeWindow instances for better optimization. + * + * To see any benefit from this method, the client must make sure they are updating the framerate + * of attached surfaces using methods such as {@link ANativeWindow_setFrameRate}, or by updating + * any associated ASurfaceControls with transactions that have {ASurfaceTransaction_setFrameRate}. + * + * @param session The {@link APerformanceHintSession} instance to update. + * @param nativeWindows A pointer to a list of ANativeWindows associated with this session. + * nullptr can be passed to indicate there are no associated ANativeWindows. + * @param nativeWindowsSize The number of ANativeWindows in the list. + * @param surfaceControls A pointer to a list of ASurfaceControls associated with this session. + * nullptr can be passed to indicate there are no associated ASurfaceControls. + * @param surfaceControlsSize The number of ASurfaceControls in the list. + * + * @return 0 on success. + * EPIPE if communication has failed. + * ENOTSUP if unsupported. + * EINVAL if invalid or empty arguments passed. + */ + +int APerformanceHint_setNativeSurfaces(APerformanceHintSession* _Nonnull session, + ANativeWindow* _Nonnull* _Nullable nativeWindows, int nativeWindowsSize, + ASurfaceControl* _Nonnull* _Nullable surfaceControls, int surfaceControlsSize) + __INTRODUCED_IN(36); + /** * Creates a new AWorkDuration. When the client finishes using {@link AWorkDuration}, it should * call {@link AWorkDuration_release()} to destroy {@link AWorkDuration} and release all resources @@ -520,6 +555,63 @@ int ASessionCreationConfig_setPreferPowerEfficiency( int ASessionCreationConfig_setGraphicsPipeline( ASessionCreationConfig* _Nonnull config, bool enabled) __INTRODUCED_IN(36); +/** + * Associates a session with any {@link ASurfaceControl} or {@link ANativeWindow} + * instances managed by this session. See {@link APerformanceHint_setNativeSurfaces} + * for more details. + * + * @param config The {@link ASessionCreationConfig} + * created by calling {@link ASessionCreationConfig_create()}. + * @param nativeWindows A pointer to a list of ANativeWindows associated with this session. + * nullptr can be passed to indicate there are no associated ANativeWindows. + * @param nativeWindowsSize The number of ANativeWindows in the list. + * @param surfaceControls A pointer to a list of ASurfaceControls associated with this session. + * nullptr can be passed to indicate there are no associated ASurfaceControls. + * @param surfaceControlsSize The number of ASurfaceControls in the list. + * + * @return 0 on success. + * ENOTSUP if unsupported. + * EINVAL if invalid or empty arguments passed. + */ +int ASessionCreationConfig_setNativeSurfaces( + ASessionCreationConfig* _Nonnull config, + ANativeWindow* _Nonnull* _Nullable nativeWindows, int nativeWindowsSize, + ASurfaceControl* _Nonnull* _Nullable surfaceControls, int surfaceControlsSize) + __INTRODUCED_IN(36); + +/** + * Enable automatic timing mode for sessions using the GRAPHICS_PIPELINE API with an attached + * surface. In this mode, sessions do not need to report actual durations and only need + * to keep their thread list up-to-date, set a native surface, call + * {@link ASessionCreationConfig_setGraphicsPipeline()} to signal that the session is in + * "graphics pipeline" mode, and then set whether automatic timing is desired for the + * CPU, GPU, or both, using this method. + * + * It is still be beneficial to set an accurate target time, as this may help determine + * timing information for some workloads where there is less information available from + * the framework, such as games. Additionally, reported CPU durations will be ignored + * while automatic CPU timing is enabled, and similarly GPU durations will be ignored + * when automatic GPU timing is enabled. When both are enabled, the entire + * reportActualWorkDuration call will be ignored, and the session will be managed + * completely automatically. + * + * This mode will not work unless the client makes sure they are updating the framerate + * of attached surfaces with methods such as {@link ANativeWindow_setFrameRate}, or updating + * any associated ASurfaceControls with transactions that have {ASurfaceTransaction_setFrameRate}. + * + * @param config The {@link ASessionCreationConfig} + * created by calling {@link ASessionCreationConfig_create()}. + * @param cpu Whether to enable automatic timing for the CPU for this session. + * @param gpu Whether to enable automatic timing for the GPU for this session. + * + * @return 0 on success. + * ENOTSUP if unsupported. + */ +int ASessionCreationConfig_setUseAutoTiming( + ASessionCreationConfig* _Nonnull config, + bool cpu, bool gpu) + __INTRODUCED_IN(36); + __END_DECLS #endif // ANDROID_NATIVE_PERFORMANCE_HINT_H -- cgit v1.2.3-59-g8ed1b From fff23909b5b3c8bfcb83f3099d7ad598a85c9e62 Mon Sep 17 00:00:00 2001 From: Matt Buckley Date: Wed, 27 Nov 2024 21:54:48 +0000 Subject: Fix c compat issues Bug: 381293544 Change-Id: Ied40d74f9f96e647aa56500b7ed04c573be24b98 Test: build Flag: EXEMPT NDK --- include/android/performance_hint.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/android') diff --git a/include/android/performance_hint.h b/include/android/performance_hint.h index 75a8bd49fc..ca86c2730f 100644 --- a/include/android/performance_hint.h +++ b/include/android/performance_hint.h @@ -152,6 +152,9 @@ typedef struct ASessionCreationConfig ASessionCreationConfig; */ typedef struct APerformanceHintSession APerformanceHintSession; +typedef struct ANativeWindow ANativeWindow; +typedef struct ASurfaceControl ASurfaceControl; + /** * Acquire an instance of the performance hint manager. * -- cgit v1.2.3-59-g8ed1b From c0db0c95889375af2a8b374bfc186b952fcd6c18 Mon Sep 17 00:00:00 2001 From: Rachel Lee Date: Tue, 26 Nov 2024 19:22:53 +0000 Subject: Revert "Define new ASurfaceTransaction_setFrameRateParams API" Revert submission 30112724-asurfacetransaction-setframerateparams Reason for revert: removing API to be landed in another release. Reverted changes: /q/submissionid:30112724-asurfacetransaction-setframerateparams Change-Id: I47b48906c6ac1f77b731637dcb5d30e70b0dc28c --- include/android/surface_control.h | 63 --------------------------------------- 1 file changed, 63 deletions(-) (limited to 'include/android') diff --git a/include/android/surface_control.h b/include/android/surface_control.h index 95540153b3..6323333429 100644 --- a/include/android/surface_control.h +++ b/include/android/surface_control.h @@ -780,69 +780,6 @@ void ASurfaceTransaction_setFrameRateWithChangeStrategy(ASurfaceTransaction* _No int8_t changeFrameRateStrategy) __INTRODUCED_IN(31); -/** - * Sets the intended frame rate for the given \a surface_control. - * - * On devices that are capable of running the display at different frame rates, - * the system may choose a display refresh rate to better match this surface's frame - * rate. Usage of this API won't introduce frame rate throttling, or affect other - * aspects of the application's frame production pipeline. However, because the system - * may change the display refresh rate, calls to this function may result in changes - * to Choreographer callback timings, and changes to the time interval at which the - * system releases buffers back to the application. - * - * You can register for changes in the refresh rate using - * \a AChoreographer_registerRefreshRateCallback. - * - * See ASurfaceTransaction_clearFrameRate(). - * - * Available since API level 36. - * - * \param desiredMinRate The desired minimum frame rate (inclusive) for the surface, specifying that - * the surface prefers the device render rate to be at least `desiredMinRate`. - * - *

Set `desiredMinRate` = `desiredMaxRate` to indicate the surface prefers an exact frame rate. - * - *

Set `desiredMinRate` = 0 to indicate the surface has no preference - * and any frame rate is acceptable. - * - *

The value should be greater than or equal to 0. - * - * \param desiredMaxRate The desired maximum frame rate (inclusive) for the surface, specifying that - * the surface prefers the device render rate to be at most `desiredMaxRate`. - * - *

Set `desiredMaxRate` = `desiredMinRate` to indicate the surface prefers an exact frame rate. - * - *

Set `desiredMaxRate` = positive infinity to indicate the surface has no preference - * and any frame rate is acceptable. - * - *

The value should be greater than or equal to `desiredMinRate`. - * - * \param fixedSourceRate The "fixed source" frame rate of the surface if the content has an - * inherently fixed frame rate, e.g. a video that has a specific frame rate. - * - *

When the frame rate chosen for the surface is the `fixedSourceRate` or a - * multiple, the surface can render without frame pulldown, for optimal smoothness. For - * example, a 30 fps video (`fixedSourceRate`=30) renders just as smoothly on 30 fps, - * 60 fps, 90 fps, 120 fps, and so on. - * - *

Setting the fixed source rate can also be used together with a desired - * frame rate min and max via setting `desiredMinRate` and `desiredMaxRate`. This still - * means the surface's content has a fixed frame rate of `fixedSourceRate`, but additionally - * specifies the preference to be in the range [`desiredMinRate`, `desiredMaxRate`]. For example, an - * app might want to specify there is 30 fps video (`fixedSourceRate`=30) as well as a smooth - * animation on the same surface which looks good when drawing within a frame rate range such as - * [`desiredMinRate`, `desiredMaxRate`] = [60,120]. - * - * \param changeFrameRateStrategy Whether display refresh rate transitions caused by this surface - * should be seamless. A seamless transition is one that doesn't have any visual interruptions, such - * as a black screen for a second or two. - */ -void ASurfaceTransaction_setFrameRateParams( - ASurfaceTransaction* _Nonnull transaction, ASurfaceControl* _Nonnull surface_control, - float desiredMinRate, float desiredMaxRate, float fixedSourceRate, - ANativeWindow_ChangeFrameRateStrategy changeFrameRateStrategy) __INTRODUCED_IN(36); - /** * Clears the frame rate which is set for \a surface_control. * -- cgit v1.2.3-59-g8ed1b From 684eaa791c1ae29e3236106fd2843fdacabf2209 Mon Sep 17 00:00:00 2001 From: Xiang Wang Date: Wed, 23 Oct 2024 17:41:11 -0700 Subject: Add NDK support for thermal headroom callback API Update the thermal headroom thresholds polling API doc on removal of cache update for Android 16. Bug: 360486877 Flag: EXEMPT NDK Test: atest NativeThermalTest NativeThermalUnitTest Change-Id: If5456fdc009b1154101cdae95d8d2943b030fbad --- include/android/thermal.h | 115 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 94 insertions(+), 21 deletions(-) (limited to 'include/android') diff --git a/include/android/thermal.h b/include/android/thermal.h index 7f9d2edfc7..e5d46b5b8a 100644 --- a/include/android/thermal.h +++ b/include/android/thermal.h @@ -140,45 +140,47 @@ void AThermal_releaseManager(AThermalManager* _Nonnull manager) __INTRODUCED_IN( * Available since API level 30. * * @param manager The manager instance to use to query the thermal status. - * Acquired via {@link AThermal_acquireManager}. + * Acquired via {@link AThermal_acquireManager}. * * @return current thermal status, ATHERMAL_STATUS_ERROR on failure. */ AThermalStatus -AThermal_getCurrentThermalStatus(AThermalManager* _Nonnull manager) __INTRODUCED_IN(30); +AThermal_getCurrentThermalStatus(AThermalManager *_Nonnull manager) __INTRODUCED_IN(30); /** - * Register the thermal status listener for thermal status change. + * Register a thermal status listener for thermal status change. * * Available since API level 30. * * @param manager The manager instance to use to register. - * Acquired via {@link AThermal_acquireManager}. - * @param callback The callback function to be called when thermal status updated. + * Acquired via {@link AThermal_acquireManager}. + * @param callback The callback function to be called on system binder thread pool when thermal + * status updated. * @param data The data pointer to be passed when callback is called. * * @return 0 on success * EINVAL if the listener and data pointer were previously added and not removed. - * EPERM if the required permission is not held. - * EPIPE if communication with the system service has failed. + * EPIPE if communication with the system service has failed, the listener will not get + * removed and this call should be retried */ -int AThermal_registerThermalStatusListener(AThermalManager* _Nonnull manager, +int AThermal_registerThermalStatusListener(AThermalManager *_Nonnull manager, AThermal_StatusCallback _Nullable callback, void* _Nullable data) __INTRODUCED_IN(30); /** - * Unregister the thermal status listener previously resgistered. + * Unregister a thermal status listener previously registered. + * + * No subsequent invocations of the callback will occur after this function returns successfully. * * Available since API level 30. * * @param manager The manager instance to use to unregister. - * Acquired via {@link AThermal_acquireManager}. - * @param callback The callback function to be called when thermal status updated. + * Acquired via {@link AThermal_acquireManager}. + * @param callback The callback function that was previously registered. * @param data The data pointer to be passed when callback is called. * * @return 0 on success * EINVAL if the listener and data pointer were not previously added. - * EPERM if the required permission is not held. * EPIPE if communication with the system service has failed. */ int AThermal_unregisterThermalStatusListener(AThermalManager* _Nonnull manager, @@ -254,7 +256,7 @@ typedef struct AThermalHeadroomThreshold AThermalHeadroomThreshold; * The headroom threshold is used to interpret the possible thermal throttling status based on * the headroom prediction. For example, if the headroom threshold for * {@link ATHERMAL_STATUS_LIGHT} is 0.7, and a headroom prediction in 10s returns 0.75 - * (or {@code AThermal_getThermalHeadroom(10)=0.75}), one can expect that in 10 seconds the system + * (or `AThermal_getThermalHeadroom(10)=0.75}`, one can expect that in 10 seconds the system * could be in lightly throttled state if the workload remains the same. The app can consider * taking actions according to the nearest throttling status the difference between the headroom and * the threshold. @@ -262,24 +264,30 @@ typedef struct AThermalHeadroomThreshold AThermalHeadroomThreshold; * For new devices it's guaranteed to have a single sensor, but for older devices with multiple * sensors reporting different threshold values, the minimum threshold is taken to be conservative * on predictions. Thus, when reading real-time headroom, it's not guaranteed that a real-time value - * of 0.75 (or {@code AThermal_getThermalHeadroom(0)}=0.75) exceeding the threshold of 0.7 above + * of 0.75 (or `AThermal_getThermalHeadroom(0)=0.75`) exceeding the threshold of 0.7 above * will always come with lightly throttled state - * (or {@code AThermal_getCurrentThermalStatus()=ATHERMAL_STATUS_LIGHT}) but it can be lower - * (or {@code AThermal_getCurrentThermalStatus()=ATHERMAL_STATUS_NONE}). + * (or `AThermal_getCurrentThermalStatus()=ATHERMAL_STATUS_LIGHT`) but it can be lower + * (or `AThermal_getCurrentThermalStatus()=ATHERMAL_STATUS_NONE`). * While it's always guaranteed that the device won't be throttled heavier than the unmet * threshold's state, so a real-time headroom of 0.75 will never come with * {@link #ATHERMAL_STATUS_MODERATE} but always lower, and 0.65 will never come with * {@link ATHERMAL_STATUS_LIGHT} but {@link #ATHERMAL_STATUS_NONE}. *

- * The returned list of thresholds is cached on first successful query and owned by the thermal - * manager, which will not change between calls to this function. The caller should only need to - * free the manager with {@link AThermal_releaseManager}. + * Starting in Android 16, this polling API may return different results when called depending on + * the device. The new headroom listener API {@link #AThermal_HeadroomCallback} can be used to + * detect headroom thresholds changes. + *

+ * Before API level 36 the returned list of thresholds is cached on first successful query and owned + * by the thermal manager, which will not change between calls to this function. The caller should + * only need to free the manager with {@link AThermal_releaseManager}. + *

* * @param manager The manager instance to use. * Acquired via {@link AThermal_acquireManager}. * @param outThresholds non-null output pointer to null AThermalHeadroomThreshold pointer, which - * will be set to the cached array of thresholds if thermal thresholds are supported - * by the system or device, otherwise nullptr or unmodified. + * will be set to a new array of thresholds if thermal thresholds are supported + * by the system or device, otherwise nullptr or unmodified. The client should + * clean up the thresholds by array-deleting the threshold pointer. * @param size non-null output pointer whose value will be set to the size of the threshold array * or 0 if it's not supported. * @return 0 on success @@ -292,6 +300,71 @@ int AThermal_getThermalHeadroomThresholds(AThermalManager* _Nonnull manager, * _Nullable outThresholds, size_t* _Nonnull size) __INTRODUCED_IN(35); +/** + * Prototype of the function that is called when thermal headroom or thresholds changes. + * It's passed the updated thermal headroom and thresholds as parameters, as well as the + * pointer provided by the client that registered a callback. + * + * @param data The data pointer to be passed when callback is called. + * @param headroom The current non-negative normalized headroom value, also see + * {@link AThermal_getThermalHeadroom}. + * @param forecastHeadroom The forecasted non-negative normalized headroom value, also see + * {@link AThermal_getThermalHeadroom}. + * @param forecastSeconds The seconds used for the forecast by the system. + * @param thresholds The current headroom thresholds. The thresholds pointer will be a constant + * shared across all callbacks registered from the same process, and it will be + * destroyed after all the callbacks are finished. If the client intents to + * persist the values, it should make a copy of it during the callback. + * @param thresholdsCount The count of thresholds. + */ +typedef void (*AThermal_HeadroomCallback)(void *_Nullable data, + float headroom, + float forecastHeadroom, + int forecastSeconds, + const AThermalHeadroomThreshold* _Nullable thresholds, + size_t thresholdsCount); + +/** + * Register a thermal headroom listener for thermal headroom or thresholds change. + * + * Available since API level 36. + * + * @param manager The manager instance to use to register. + * Acquired via {@link AThermal_acquireManager}. + * @param callback The callback function to be called on system binder thread pool when thermal + * headroom or thresholds update. + * @param data The data pointer to be passed when callback is called. + * + * @return 0 on success + * EINVAL if the listener and data pointer were previously added and not removed. + * EPIPE if communication with the system service has failed. + */ +int AThermal_registerThermalHeadroomListener(AThermalManager* _Nonnull manager, + AThermal_HeadroomCallback _Nullable callback, + void* _Nullable data) __INTRODUCED_IN(36); + +/** + * Unregister a thermal headroom listener previously registered. + * + * No subsequent invocations of the callback will occur after this function returns successfully. + * + * Available since API level 36. + * + * @param manager The manager instance to use to unregister. + * Acquired via {@link AThermal_acquireManager}. + * @param callback The callback function that was previously registered. + * @param data The data pointer that was previously registered. + * + * @return 0 on success + * EINVAL if the listener and data pointer were not previously added. + * EPIPE if communication with the system service has failed, the listener will not get + * removed and this call should be retried + */ + +int AThermal_unregisterThermalHeadroomListener(AThermalManager* _Nonnull manager, + AThermal_HeadroomCallback _Nullable callback, + void* _Nullable data) __INTRODUCED_IN(36); + #ifdef __cplusplus } #endif -- cgit v1.2.3-59-g8ed1b From 565c1f97824e9cf5f5b1d8c3625d6640dd67c0b8 Mon Sep 17 00:00:00 2001 From: Xiang Wang Date: Tue, 22 Oct 2024 15:56:45 -0700 Subject: Add NDK CPU/GPU headroom APIs Bug: 346604998 Flag: EXEMPT ndk Test: TBD in next change Change-Id: I4a5b04cc40907effff8d68140b89517ffbf3c7f9 --- include/android/system_health.h | 349 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 349 insertions(+) create mode 100644 include/android/system_health.h (limited to 'include/android') diff --git a/include/android/system_health.h b/include/android/system_health.h new file mode 100644 index 0000000000..63465af595 --- /dev/null +++ b/include/android/system_health.h @@ -0,0 +1,349 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @defgroup SystemHealth +* @{ +*/ + +/** + * @file system_health.h + */ + +#ifndef _ANDROID_SYSTEM_HEALTH_H +#define _ANDROID_SYSTEM_HEALTH_H + +#include + +/****************************************************************** + * + * IMPORTANT NOTICE: + * + * This file is part of Android's set of stable system headers + * exposed by the Android NDK (Native Development Kit). + * + * Third-party source AND binary code relies on the definitions + * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. + * + * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) + * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS + * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY + * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES + */ + + +#include +#include + +#if !defined(__INTRODUCED_IN) +#define __INTRODUCED_IN(__api_level) /* nothing */ +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Params used to customize the calculation of CPU headroom. + * + * Also see {@link ASystemHealth_getCpuHeadroom}. + */ +typedef struct ACpuHeadroomParams ACpuHeadroomParams; + +/** + * Params used to customize the calculation of GPU headroom. + * + * Also see {@link ASystemHealth_getGpuHeadroom}. + */ +typedef struct AGpuHeadroomParams AGpuHeadroomParams; + +/** + * Creates a new instance of ACpuHeadroomParams. + * + * When the client finishes using {@link ACpuHeadroomParams}, + * {@link ACpuHeadroomParams_destroy()} must be called to destroy + * and free up the resources associated with {@link ACpuHeadroomParams}. + * + * Available since API level 36. + * + * @return A new instance of ACpuHeadroomParams. + */ +ACpuHeadroomParams *_Nonnull ACpuHeadroomParams_create() +__INTRODUCED_IN(36); + +enum ACpuHeadroomCalculationType { + /** + * Use the minimum headroom value within the calculation window. + * Introduced in API level 36. + */ + ACPU_HEADROOM_CALCULATION_TYPE_MIN = 0, + /** + * Use the average headroom value within the calculation window. + * Introduced in API level 36. + */ + ACPU_HEADROOM_CALCULATION_TYPE_AVERAGE = 1, +}; + +enum AGpuHeadroomCalculationType { + /** + * Use the minimum headroom value within the calculation window. + * Introduced in API level 36. + */ + AGPU_HEADROOM_CALCULATION_TYPE_MIN = 0, + /** + * Use the average headroom value within the calculation window. + * Introduced in API level 36. + */ + AGPU_HEADROOM_CALCULATION_TYPE_AVERAGE = 1, +}; + +/** + * Sets the headroom calculation window size in ACpuHeadroomParams. + * + * Available since API level 36. + * + * @param params The params to be set. + * @param windowMillis The window size in milliseconds ranged from [50, 10000]. The smaller the + * window size, the larger fluctuation in the headroom value should be expected. + * The default value can be retrieved from the + * {@link #ACpuHeadroomParams_getCalculationWindowMillis} if not set. The device + * will try to use the closest feasible window size to this param. + */ +void ACpuHeadroomParams_setCalculationWindowMillis(ACpuHeadroomParams *_Nonnull params, + int windowMillis) +__INTRODUCED_IN(36); + +/** + * Gets the headroom calculation window size in ACpuHeadroomParams. + * + * Available since API level 36. + * + * @param params The params to be set. + * @return This will return the default value chosen by the device if the params is not set. + */ +int ACpuHeadroomParams_getCalculationWindowMillis(ACpuHeadroomParams *_Nonnull params) +__INTRODUCED_IN(36); + +/** + * Sets the headroom calculation window size in AGpuHeadroomParams. + * + * Available since API level 36. + * + * @param params The params to be set. + * @param windowMillis The window size in milliseconds ranged from [50, 10000]. The smaller the + * window size, the larger fluctuation in the headroom value should be expected. + * The default value can be retrieved from the + * {@link #AGpuHeadroomParams_getCalculationWindowMillis} if not set. The device + * will try to use the closest feasible window size to this param. + */ +void AGpuHeadroomParams_setCalculationWindowMillis(AGpuHeadroomParams *_Nonnull params, + int windowMillis) +__INTRODUCED_IN(36); + +/** + * Gets the headroom calculation window size in AGpuHeadroomParams. + * + * Available since API level 36. + * + * @param params The params to be set. + * @return This will return the default value chosen by the device if the params is not set. + */ +int AGpuHeadroomParams_getCalculationWindowMillis(AGpuHeadroomParams *_Nonnull params) +__INTRODUCED_IN(36); + +/** + * Sets the headroom calculation type in ACpuHeadroomParams. + * + * Available since API level 36. + * + * @param params The params to be set. + * @param calculationType The headroom calculation type. + */ +void ACpuHeadroomParams_setCalculationType(ACpuHeadroomParams *_Nonnull params, + ACpuHeadroomCalculationType calculationType) +__INTRODUCED_IN(36); + +/** + * Gets the headroom calculation type in ACpuHeadroomParams. + * + * Available since API level 36. + * + * @param params The params to be set. + * @return The headroom calculation type. + */ +ACpuHeadroomCalculationType +ACpuHeadroomParams_getCalculationType(ACpuHeadroomParams *_Nonnull params) +__INTRODUCED_IN(36); + +/** + * Sets the headroom calculation type in AGpuHeadroomParams. + * + * Available since API level 36. + * + * @param params The params to be set. + * @param calculationType The headroom calculation type. + */ +void AGpuHeadroomParams_setCalculationType(AGpuHeadroomParams *_Nonnull params, + AGpuHeadroomCalculationType calculationType) +__INTRODUCED_IN(36); + +/** + * Gets the headroom calculation type in AGpuHeadroomParams. + * + * Available since API level 36. + * + * @param params The params to be set. + * @return The headroom calculation type. + */ +AGpuHeadroomCalculationType +AGpuHeadroomParams_getCalculationType(AGpuHeadroomParams *_Nonnull params) +__INTRODUCED_IN(36); + +/** + * Sets the thread TIDs to track in ACpuHeadroomParams. + * + * Available since API level 36. + * + * @param params The params to be set. + * @param tids Non-null array of TIDs, maximum 5. + * @param tidsSize The size of the tids array. + */ +void ACpuHeadroomParams_setTids(ACpuHeadroomParams *_Nonnull params, const int *_Nonnull tids, + int tidsSize) +__INTRODUCED_IN(36); + +/** + * Creates a new instance of AGpuHeadroomParams. + * + * When the client finishes using {@link AGpuHeadroomParams}, + * {@link AGpuHeadroomParams_destroy()} must be called to destroy + * and free up the resources associated with {@link AGpuHeadroomParams}. + * + * Available since API level 36. + * + * @return A new instance of AGpuHeadroomParams. + */ +AGpuHeadroomParams *_Nonnull AGpuHeadroomParams_create() +__INTRODUCED_IN(36); + +/** + * Deletes the ACpuHeadroomParams instance. + * + * Available since API level 36. + * + * @param params The params to be deleted. + */ +void ACpuHeadroomParams_destroy(ACpuHeadroomParams *_Nonnull params) +__INTRODUCED_IN(36); + +/** + * Deletes the AGpuHeadroomParams instance. + * + * Available since API level 36. + * + * @param params The params to be deleted. + */ +void AGpuHeadroomParams_destroy(AGpuHeadroomParams *_Nonnull params) +__INTRODUCED_IN(36); + +/** + * Provides an estimate of available CPU capacity headroom of the device. + * + * The value can be used by the calling application to determine if the workload was CPU bound and + * then take action accordingly to ensure that the workload can be completed smoothly. It can also + * be used with the thermal status and headroom to determine if reducing the CPU bound workload can + * help reduce the device temperature to avoid thermal throttling. + * + * Available since API level 36. + * + * @param params The params to customize the CPU headroom calculation, or nullptr to use the default + * @param outHeadroom Non-null output pointer to a single float, which will be set to the CPU + * headroom value. The value will be a single value or `Float.NaN` if it's + * temporarily unavailable. + * Each valid value ranges from [0, 100], where 0 indicates no more cpu resources + * can be granted. + * @return 0 on success + * EPIPE if failed to get the CPU headroom. + * EPERM if the TIDs do not belong to the same process. + * ENOTSUP if API or requested params is unsupported. + */ +int ASystemHealth_getCpuHeadroom(const ACpuHeadroomParams *_Nullable params, + float *_Nonnull outHeadroom) +__INTRODUCED_IN(36); + +/** + * Provides an estimate of available GPU capacity headroom of the device. + * + * The value can be used by the calling application to determine if the workload was GPU bound and + * then take action accordingly to ensure that the workload can be completed smoothly. It can also + * be used with the thermal status and headroom to determine if reducing the GPU bound workload can + * help reduce the device temperature to avoid thermal throttling. + * + * Available since API level 36 + * + * @param params The params to customize the GPU headroom calculation, or nullptr to use the default + * @param outHeadroom Non-null output pointer to a single float, which will be set to the GPU + * headroom value. The value will be a single value or `Float.NaN` if it's + * temporarily unavailable. + * Each valid value ranges from [0, 100], where 0 indicates no more gpu resources + * can be granted. + * @return 0 on success + * EPIPE if failed to get the GPU headroom. + * ENOTSUP if API or requested params is unsupported. + */ +int ASystemHealth_getGpuHeadroom(const AGpuHeadroomParams *_Nullable params, + float *_Nonnull outHeadroom) +__INTRODUCED_IN(36); + +/** + * Gets minimum polling interval for calling {@link ASystemHealth_getCpuHeadroom} in milliseconds. + * + * The getCpuHeadroom API may return cached result if called more frequently than the interval. + * + * Available since API level 36. + * + * @param outMinIntervalMillis Non-null output pointer to a int64_t, which + * will be set to the minimum polling interval in milliseconds. + * @return 0 on success + * EPIPE if failed to get the minimum polling interval. + * ENOTSUP if API is unsupported. + */ +int ASystemHealth_getCpuHeadroomMinIntervalMillis(int64_t *_Nonnull outMinIntervalMillis) +__INTRODUCED_IN(36); + +/** + * Gets minimum polling interval for calling {@link ASystemHealth_getGpuHeadroom} in milliseconds. + * + * The getGpuHeadroom API may return cached result if called more frequent than the interval. + * + * Available since API level 36. + * + * @param outMinIntervalMillis Non-null output pointer to a int64_t, which + * will be set to the minimum polling interval in milliseconds. + * @return 0 on success + * EPIPE if failed to get the minimum polling interval. + * ENOTSUP if API is unsupported. + */ +int ASystemHealth_getGpuHeadroomMinIntervalMillis(int64_t *_Nonnull outMinIntervalMillis) +__INTRODUCED_IN(36); + +#ifdef __cplusplus +} +#endif + +#endif // _ANDROID_SYSTEM_HEALTH_H + +/** @} */ -- cgit v1.2.3-59-g8ed1b From 5415547da945e8ae7ec8ad6370542814ea2a3a02 Mon Sep 17 00:00:00 2001 From: Xiang Wang Date: Tue, 3 Dec 2024 17:31:19 -0800 Subject: Add enum tag to refer to the types Bug: 346604998 Flag: EXEMPT ndk Test: build Change-Id: I859685babd1552b45ad48e1fe64d21ed84b55faf --- include/android/system_health.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/android') diff --git a/include/android/system_health.h b/include/android/system_health.h index 63465af595..69620df16e 100644 --- a/include/android/system_health.h +++ b/include/android/system_health.h @@ -96,6 +96,7 @@ enum ACpuHeadroomCalculationType { */ ACPU_HEADROOM_CALCULATION_TYPE_AVERAGE = 1, }; +typedef enum ACpuHeadroomCalculationType ACpuHeadroomCalculationType; enum AGpuHeadroomCalculationType { /** @@ -109,6 +110,7 @@ enum AGpuHeadroomCalculationType { */ AGPU_HEADROOM_CALCULATION_TYPE_AVERAGE = 1, }; +typedef enum AGpuHeadroomCalculationType AGpuHeadroomCalculationType; /** * Sets the headroom calculation window size in ACpuHeadroomParams. -- cgit v1.2.3-59-g8ed1b From fd2b786912b72f53f52a39880a4c1cad74ff2841 Mon Sep 17 00:00:00 2001 From: Matt Buckley Date: Tue, 3 Dec 2024 17:18:33 -0800 Subject: Add CPU/GPU_LOAD_SPIKE hints for one-off expensive workloads Currently there is ambiguity between single-frame expensive ops (eg: shader compilation) and longer-duration expensive ops (eg: SF client compositon). This load hint aims to resolve this by explicitly annotating one-time expensive workloads so they can be given unique boost and hysteresis expectations. For example, a load_spike aware tracker might want to ignore the timing that comes from a LOAD_SPIKE-marked frame, as it is known to not be representative of the overall workload. Flag: EXEMPT NDK Test: atest PerformanceHintNativeTestCases Test: atest PerformanceHintManagerTest Bug: 367803904 Change-Id: I22458f0d8f0819499f3463aa36e8bb7eb7af15be --- include/android/performance_hint.h | 25 +++++++++++++++++++++++++ include/private/performance_hint_private.h | 14 ++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'include/android') diff --git a/include/android/performance_hint.h b/include/android/performance_hint.h index ca86c2730f..2b4a5f5f53 100644 --- a/include/android/performance_hint.h +++ b/include/android/performance_hint.h @@ -358,6 +358,31 @@ int APerformanceHint_notifyWorkloadReset( APerformanceHintSession* _Nonnull session, bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36); +/** + * Informs the framework of an upcoming one-off expensive frame for a graphics pipeline + * bound to this session. This frame will be treated as not representative of the workload as a + * whole, and it will be discarded the purposes of load tracking. The user can specify + * whether the workload spike is expected to be on the CPU, GPU, or both. + * + * Sending hints for both CPU and GPU counts as two separate hints for the purposes of the + * rate limiter. + * + * @param cpu Indicates if the workload spike is expected to affect the CPU. + * @param gpu Indicates if the workload spike is expected to affect the GPU. + * @param debugName A required string used to identify this specific hint during + * tracing. This debug string will only be held for the duration of the + * method, and can be safely discarded after. + * + * @return 0 on success. + * EINVAL if no hints were requested. + * EBUSY if the hint was rate limited. + * EPIPE if communication with the system service has failed. + * ENOTSUP if the hint is not supported. + */ +int APerformanceHint_notifyWorkloadSpike( + APerformanceHintSession* _Nonnull session, + bool cpu, bool gpu, const char* _Nonnull debugName) __INTRODUCED_IN(36); + /** * Associates a session with any {@link ASurfaceControl} or {@link ANativeWindow} * instances managed by this session. diff --git a/include/private/performance_hint_private.h b/include/private/performance_hint_private.h index f150fb1f3e..e3f98badbe 100644 --- a/include/private/performance_hint_private.h +++ b/include/private/performance_hint_private.h @@ -74,6 +74,20 @@ enum SessionHint: int32_t { * baseline to prepare for an arbitrary load, and must wake up if inactive. */ GPU_LOAD_RESET = 7, + + /** + * This hint indicates an upcoming CPU workload that is abnormally large and + * not representative of the workload. This should be used for rare, one-time + * operations and should be ignored by any load tracking or session hysteresis. + */ + CPU_LOAD_SPIKE = 8, + + /** + * This hint indicates an upcoming GPU workload that is abnormally large and + * not representative of the workload. This should be used for rare, one-time + * operations and should be ignored by any load tracking or session hysteresis. + */ + GPU_LOAD_SPIKE = 9, }; // Allows access to PowerHAL's SessionTags without needing to import its AIDL -- cgit v1.2.3-59-g8ed1b