summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Steven Thomas <steventhomas@google.com> 2019-12-02 22:00:47 -0800
committer Steven Thomas <steventhomas@google.com> 2020-01-22 13:18:17 -0800
commit6d88a487b0fe7f72314f81e81c9786005032afa3 (patch)
tree6cc4cbc2cc65e51d2b633653c77303d3269bc091
parentc34a8a2e960393f434d8307edeb495d0e301c70d (diff)
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
-rw-r--r--include/android/surface_control.h27
-rw-r--r--libs/nativewindow/ANativeWindow.cpp7
-rw-r--r--libs/nativewindow/include/android/native_window.h33
-rw-r--r--libs/nativewindow/libnativewindow.map.txt1
4 files changed, 68 insertions, 0 deletions
diff --git a/include/android/surface_control.h b/include/android/surface_control.h
index 31abb6622e..157b4242fe 100644
--- a/include/android/surface_control.h
+++ b/include/android/surface_control.h
@@ -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
diff --git a/libs/nativewindow/ANativeWindow.cpp b/libs/nativewindow/ANativeWindow.cpp
index 842af18c8c..a60bc4dad3 100644
--- a/libs/nativewindow/ANativeWindow.cpp
+++ b/libs/nativewindow/ANativeWindow.cpp
@@ -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
**************************************************************************************************/
diff --git a/libs/nativewindow/include/android/native_window.h b/libs/nativewindow/include/android/native_window.h
index 3e436e3b07..0637db390d 100644
--- a/libs/nativewindow/include/android/native_window.h
+++ b/libs/nativewindow/include/android/native_window.h
@@ -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
diff --git a/libs/nativewindow/libnativewindow.map.txt b/libs/nativewindow/libnativewindow.map.txt
index f59e8f0546..3002da29e7 100644
--- a/libs/nativewindow/libnativewindow.map.txt
+++ b/libs/nativewindow/libnativewindow.map.txt
@@ -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: