[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/gui/Surface.cpp b/libs/gui/Surface.cpp
index fb9d742..e490d6d 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -1087,6 +1087,12 @@
case NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT:
res = dispatchSetDequeueTimeout(args);
break;
+ case NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION:
+ res = dispatchGetLastDequeueDuration(args);
+ break;
+ case NATIVE_WINDOW_GET_LAST_QUEUE_DURATION:
+ res = dispatchGetLastQueueDuration(args);
+ break;
default:
res = NAME_NOT_FOUND;
break;
@@ -1303,6 +1309,18 @@
return setDequeueTimeout(timeout);
}
+int Surface::dispatchGetLastDequeueDuration(va_list args) {
+ int64_t* lastDequeueDuration = va_arg(args, int64_t*);
+ *lastDequeueDuration = mLastDequeueDuration;
+ return NO_ERROR;
+}
+
+int Surface::dispatchGetLastQueueDuration(va_list args) {
+ int64_t* lastQueueDuration = va_arg(args, int64_t*);
+ *lastQueueDuration = mLastQueueDuration;
+ return NO_ERROR;
+}
+
bool Surface::transformToDisplayInverse() {
return (mTransform & NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY) ==
NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;
diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h
index 2527ec0..e582509 100644
--- a/libs/gui/include/gui/Surface.h
+++ b/libs/gui/include/gui/Surface.h
@@ -246,6 +246,8 @@
int dispatchSetAutoPrerotation(va_list args);
int dispatchGetLastDequeueStartTime(va_list args);
int dispatchSetDequeueTimeout(va_list args);
+ int dispatchGetLastDequeueDuration(va_list args);
+ int dispatchGetLastQueueDuration(va_list args);
bool transformToDisplayInverse();
protected:
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) {