Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d88a487 authored by Steven Thomas's avatar Steven Thomas
Browse files

Add setFrameRate() api

setFrameRate() is a new api in Android 11 that will enable apps to
specify their intended frame rate.

Bug: 143912624
Bug: 137287430

Test: Added a new CTS test - android.graphics.cts.SetFrameRateTest.

Change-Id: I0150055fbffd37f2d644829e9dadbfc517045d8e
parent c34a8a2e
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -407,6 +407,33 @@ void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* transactio

#endif // __ANDROID_API__ >= 29

#if __ANDROID_API__ >= 30

/*
 * Sets the intended frame rate for |surface_control|.
 *
 * On devices that are capable of running the display at different refresh rates, the system may
 * choose a display refresh rate to better match this surface's frame rate. Usage of this API won't
 * directly affect 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.
 *
 * |frameRate| is the intended frame rate of this surface. 0 is a special value that indicates the
 * app will accept the system's choice for the display frame rate, which is the default behavior if
 * this function isn't called. The frameRate param does *not* need to be a valid refresh rate for
 * this device's display - e.g., it's fine to pass 30fps to a device that can only run the display
 * at 60fps.
 *
 * Available since API level 30.
 */
void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* transaction,
                                      ASurfaceControl* surface_control,
                                      float frameRate)
                                      __INTRODUCED_IN(30);

#endif // __ANDROID_API__ >= 30

__END_DECLS

#endif // ANDROID_SURFACE_CONTROL_H
+7 −0
Original line number Diff line number Diff line
@@ -158,6 +158,13 @@ int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) {
    return query(window, NATIVE_WINDOW_DATASPACE);
}

int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate) {
    if (!window || !query(window, NATIVE_WINDOW_IS_VALID) || frameRate < 0) {
        return -EINVAL;
    }
    return native_window_set_frame_rate(window, frameRate);
}

/**************************************************************************************************
 * vndk-stable
 **************************************************************************************************/
+33 −0
Original line number Diff line number Diff line
@@ -230,6 +230,39 @@ int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) __INTRODUCED_IN

#endif // __ANDROID_API__ >= 28

#if __ANDROID_API__ >= 30

/**
 * Sets the intended frame rate for this window.
 *
 * On devices that are capable of running the display at different refresh
 * rates, the system may choose a display refresh rate to better match this
 * window'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.
 *
 * Note that this only has an effect for windows presented on the display. If
 * this ANativeWindow is consumed by something other than the system compositor,
 * e.g. a media codec, this call has no effect.
 *
 * Available since API level 30.
 *
 * \param frameRate The intended frame rate of this window. 0 is a special value
 * that indicates the app will accept the system's choice for the display frame
 * rate, which is the default behavior if this function isn't called. The
 * frameRate param does *not* need to be a valid refresh rate for this device's
 * display - e.g., it's fine to pass 30fps to a device that can only run the
 * display at 60fps.
 *
 * \return 0 for success, -EINVAL if the window or frame rate are invalid.
 */
int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate) __INTRODUCED_IN(30);

#endif // __ANDROID_API__ >= 30

#ifdef __cplusplus
};
#endif
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ LIBNATIVEWINDOW {
    ANativeWindow_setDequeueTimeout; # apex # introduced=30
    ANativeWindow_setSharedBufferMode; # llndk
    ANativeWindow_setSwapInterval; # llndk
    ANativeWindow_setFrameRate; # introduced=30
    ANativeWindow_setUsage; # llndk
    ANativeWindow_unlockAndPost;
  local: