[ANativeWindow] Increase precision for duration queries.
Use perform() instead in query() to retrieve dequeue/queue durations for
nanosecond resolution.
Bug: 137012798
Test: atest
Change-Id: I894a8784f3321d4ab6f538d7e7fc1457de26f289
diff --git a/libs/nativewindow/ANativeWindow.cpp b/libs/nativewindow/ANativeWindow.cpp
index fecfa19..0ba01f4 100644
--- a/libs/nativewindow/ANativeWindow.cpp
+++ b/libs/nativewindow/ANativeWindow.cpp
@@ -33,6 +33,12 @@
return res < 0 ? res : value;
}
+static int64_t query64(ANativeWindow* window, int what) {
+ int64_t value;
+ int res = window->perform(window, what, &value);
+ return res < 0 ? res : value;
+}
+
static bool isDataSpaceValid(ANativeWindow* window, int32_t dataSpace) {
bool supported = false;
switch (dataSpace) {
@@ -271,18 +277,16 @@
* apex-stable
**************************************************************************************************/
-int ANativeWindow_getLastDequeueDuration(ANativeWindow* window) {
- return query(window, NATIVE_WINDOW_LAST_DEQUEUE_DURATION);
+int64_t ANativeWindow_getLastDequeueDuration(ANativeWindow* window) {
+ return query64(window, NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION);
}
-int ANativeWindow_getLastQueueDuration(ANativeWindow* window) {
- return query(window, NATIVE_WINDOW_LAST_QUEUE_DURATION);
+int64_t ANativeWindow_getLastQueueDuration(ANativeWindow* window) {
+ return query64(window, NATIVE_WINDOW_GET_LAST_QUEUE_DURATION);
}
int64_t ANativeWindow_getLastDequeueStartTime(ANativeWindow* window) {
- int64_t time;
- int success = window->perform(window, NATIVE_WINDOW_GET_LAST_DEQUEUE_START, &time);
- return success < 0 ? success : time;
+ return query64(window, NATIVE_WINDOW_GET_LAST_DEQUEUE_START);
}
int ANativeWindow_setDequeueTimeout(ANativeWindow* window, int64_t timeout) {
diff --git a/libs/nativewindow/include/apex/window.h b/libs/nativewindow/include/apex/window.h
index 9798c2f..869b22e 100644
--- a/libs/nativewindow/include/apex/window.h
+++ b/libs/nativewindow/include/apex/window.h
@@ -27,17 +27,17 @@
* Retrieves how long it took for the last time a buffer was dequeued.
*
* \return a negative value on error, otherwise returns the duration in
- * microseconds.
+ * nanoseconds
*/
-int ANativeWindow_getLastDequeueDuration(ANativeWindow* window);
+int64_t ANativeWindow_getLastDequeueDuration(ANativeWindow* window);
/**
* Retrieves how long it took for the last time a buffer was queued.
*
* \return a negative value on error, otherwise returns the duration in
- * microseconds
+ * nanoseconds.
*/
-int ANativeWindow_getLastQueueDuration(ANativeWindow* window);
+int64_t ANativeWindow_getLastQueueDuration(ANativeWindow* window);
/**
* Retrieves the system time in nanoseconds when the last time a buffer
diff --git a/libs/nativewindow/include/system/window.h b/libs/nativewindow/include/system/window.h
index 8f85007..1814ab5 100644
--- a/libs/nativewindow/include/system/window.h
+++ b/libs/nativewindow/include/system/window.h
@@ -63,9 +63,9 @@
/* attributes queriable with query() */
enum {
- NATIVE_WINDOW_WIDTH = 0,
- NATIVE_WINDOW_HEIGHT = 1,
- NATIVE_WINDOW_FORMAT = 2,
+ NATIVE_WINDOW_WIDTH = 0,
+ NATIVE_WINDOW_HEIGHT = 1,
+ NATIVE_WINDOW_FORMAT = 2,
/* see ANativeWindowQuery in vndk/window.h */
NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS,
@@ -147,11 +147,15 @@
/*
* Returns the duration of the last dequeueBuffer call in microseconds
+ * Deprecated: please use NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION in
+ * perform() instead, which supports nanosecond precision.
*/
NATIVE_WINDOW_LAST_DEQUEUE_DURATION = 14,
/*
* Returns the duration of the last queueBuffer call in microseconds
+ * Deprecated: please use NATIVE_WINDOW_GET_LAST_QUEUE_DURATION in
+ * perform() instead, which supports nanosecond precision.
*/
NATIVE_WINDOW_LAST_QUEUE_DURATION = 15,
@@ -241,6 +245,8 @@
NATIVE_WINDOW_SET_AUTO_PREROTATION = 35,
NATIVE_WINDOW_GET_LAST_DEQUEUE_START = 36, /* private */
NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT = 37, /* private */
+ NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION = 38, /* private */
+ NATIVE_WINDOW_GET_LAST_QUEUE_DURATION = 39, /* private */
// clang-format on
};
diff --git a/libs/nativewindow/tests/ANativeWindowTest.cpp b/libs/nativewindow/tests/ANativeWindowTest.cpp
index 4d2b8c8..6cf8291 100644
--- a/libs/nativewindow/tests/ANativeWindowTest.cpp
+++ b/libs/nativewindow/tests/ANativeWindowTest.cpp
@@ -74,7 +74,7 @@
TEST_F(ANativeWindowTest, getLastDequeueDuration_noDequeue_returnsZero) {
int result = ANativeWindow_getLastDequeueDuration(mWindow.get());
EXPECT_EQ(0, result);
- EXPECT_EQ(0, mWindow->getLastDequeueDuration() / 1000);
+ EXPECT_EQ(0, mWindow->getLastDequeueDuration());
}
TEST_F(ANativeWindowTest, getLastDequeueDuration_withDequeue_returnsTime) {
@@ -86,7 +86,7 @@
result = ANativeWindow_getLastDequeueDuration(mWindow.get());
EXPECT_GT(result, 0);
- EXPECT_EQ(result, mWindow->getLastDequeueDuration() / 1000);
+ EXPECT_EQ(result, mWindow->getLastDequeueDuration());
}
TEST_F(ANativeWindowTest, getLastQueueDuration_noDequeue_returnsZero) {
@@ -118,7 +118,7 @@
result = ANativeWindow_getLastQueueDuration(mWindow.get());
EXPECT_GT(result, 0);
- EXPECT_EQ(result, mWindow->getLastQueueDuration() / 1000);
+ EXPECT_EQ(result, mWindow->getLastQueueDuration());
}
TEST_F(ANativeWindowTest, getLastDequeueStartTime_noDequeue_returnsZero) {