summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alec Mouri <alecmouri@google.com> 2019-08-21 19:30:48 -0700
committer Alec Mouri <alecmouri@google.com> 2019-09-06 11:41:45 -0700
commita161966a658f46f8bec93ea0490bef799843c3c6 (patch)
tree6d3fa8630a2872bdec3324d11caae8f0caff0f70
parent0d1398b2da8aee028c52a90be6d3b75b4f12b9d6 (diff)
[ANativeWindow] Add apex stub for getLastDequeueStartTime
Also adding private query64 hook so that timing queries can have nanosecond precision. Otherwise with a 32-bit width we can only have millisecond precision for timestamps and microsecond precision for time intervals, and really we shouldn't need to be less precise if we can help it. Bug: 137012798 Test: libnativewindow_test Change-Id: I62233a588eee80f7ea70b74824c8e47461a3be81
-rw-r--r--libs/gui/Surface.cpp14
-rw-r--r--libs/gui/include/gui/Surface.h4
-rw-r--r--libs/gui/tests/Surface_test.cpp2
-rw-r--r--libs/nativewindow/ANativeWindow.cpp6
-rw-r--r--libs/nativewindow/include/apex/window.h9
-rw-r--r--libs/nativewindow/include/system/window.h2
-rw-r--r--libs/nativewindow/libnativewindow.map.txt1
-rw-r--r--libs/nativewindow/tests/ANativeWindowTest.cpp21
8 files changed, 49 insertions, 10 deletions
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index 7e356e4eb1..aad18491b4 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -1081,6 +1081,9 @@ int Surface::perform(int operation, va_list args)
case NATIVE_WINDOW_SET_AUTO_PREROTATION:
res = dispatchSetAutoPrerotation(args);
break;
+ case NATIVE_WINDOW_GET_LAST_DEQUEUE_START:
+ res = dispatchGetLastDequeueStartTime(args);
+ break;
default:
res = NAME_NOT_FOUND;
break;
@@ -1286,6 +1289,12 @@ int Surface::dispatchSetAutoPrerotation(va_list args) {
return setAutoPrerotation(autoPrerotation);
}
+int Surface::dispatchGetLastDequeueStartTime(va_list args) {
+ int64_t* lastDequeueStartTime = va_arg(args, int64_t*);
+ *lastDequeueStartTime = mLastDequeueStartTime;
+ return NO_ERROR;
+}
+
bool Surface::transformToDisplayInverse() {
return (mTransform & NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY) ==
NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;
@@ -1950,11 +1959,6 @@ int Surface::getConsumerUsage(uint64_t* outUsage) const {
return mGraphicBufferProducer->getConsumerUsage(outUsage);
}
-nsecs_t Surface::getLastDequeueStartTime() const {
- Mutex::Autolock lock(mMutex);
- return mLastDequeueStartTime;
-}
-
status_t Surface::getAndFlushRemovedBuffers(std::vector<sp<GraphicBuffer>>* out) {
if (out == nullptr) {
ALOGE("%s: out must not be null!", __FUNCTION__);
diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h
index 28f5a26072..5bcfcda6ad 100644
--- a/libs/gui/include/gui/Surface.h
+++ b/libs/gui/include/gui/Surface.h
@@ -179,9 +179,6 @@ public:
status_t getUniqueId(uint64_t* outId) const;
status_t getConsumerUsage(uint64_t* outUsage) const;
- // Returns the CLOCK_MONOTONIC start time of the last dequeueBuffer call
- nsecs_t getLastDequeueStartTime() const;
-
protected:
virtual ~Surface();
@@ -247,6 +244,7 @@ private:
int dispatchGetHdrSupport(va_list args);
int dispatchGetConsumerUsage64(va_list args);
int dispatchSetAutoPrerotation(va_list args);
+ int dispatchGetLastDequeueStartTime(va_list args);
bool transformToDisplayInverse();
protected:
diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp
index 5a121d77ab..0b61d9231c 100644
--- a/libs/gui/tests/Surface_test.cpp
+++ b/libs/gui/tests/Surface_test.cpp
@@ -617,7 +617,7 @@ TEST_F(SurfaceTest, TestGetLastDequeueStartTime) {
anw->dequeueBuffer(anw.get(), &buffer, &fenceFd);
nsecs_t after = systemTime(CLOCK_MONOTONIC);
- nsecs_t lastDequeueTime = mSurface->getLastDequeueStartTime();
+ nsecs_t lastDequeueTime = ANativeWindow_getLastDequeueStartTime(anw.get());
ASSERT_LE(before, lastDequeueTime);
ASSERT_GE(after, lastDequeueTime);
}
diff --git a/libs/nativewindow/ANativeWindow.cpp b/libs/nativewindow/ANativeWindow.cpp
index 5c91d587bc..3b195f7913 100644
--- a/libs/nativewindow/ANativeWindow.cpp
+++ b/libs/nativewindow/ANativeWindow.cpp
@@ -278,3 +278,9 @@ int ANativeWindow_getLastDequeueDuration(ANativeWindow* window) {
int ANativeWindow_getLastQueueDuration(ANativeWindow* window) {
return query(window, NATIVE_WINDOW_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;
+}
diff --git a/libs/nativewindow/include/apex/window.h b/libs/nativewindow/include/apex/window.h
index 82ff50d2d5..3ddd5493ac 100644
--- a/libs/nativewindow/include/apex/window.h
+++ b/libs/nativewindow/include/apex/window.h
@@ -39,4 +39,13 @@ int ANativeWindow_getLastDequeueDuration(ANativeWindow* window);
*/
int ANativeWindow_getLastQueueDuration(ANativeWindow* window);
+/**
+ * Retrieves the system time in nanoseconds when the last time a buffer
+ * was dequeued.
+ *
+ * \return a negative value on error, otherwise returns the duration in
+ * nanoseconds.
+ */
+int64_t ANativeWindow_getLastDequeueStartTime(ANativeWindow* window);
+
__END_DECLS
diff --git a/libs/nativewindow/include/system/window.h b/libs/nativewindow/include/system/window.h
index 78354bba6b..b7ae28a93c 100644
--- a/libs/nativewindow/include/system/window.h
+++ b/libs/nativewindow/include/system/window.h
@@ -93,7 +93,6 @@ enum {
*/
NATIVE_WINDOW_CONCRETE_TYPE = 5,
-
/*
* Default width and height of ANativeWindow buffers, these are the
* dimensions of the window buffers irrespective of the
@@ -240,6 +239,7 @@ enum {
NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA = 33,
NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA = 34,
NATIVE_WINDOW_SET_AUTO_PREROTATION = 35,
+ NATIVE_WINDOW_GET_LAST_DEQUEUE_START = 36, /* private */
// clang-format on
};
diff --git a/libs/nativewindow/libnativewindow.map.txt b/libs/nativewindow/libnativewindow.map.txt
index b8b45ae62b..33c6400d52 100644
--- a/libs/nativewindow/libnativewindow.map.txt
+++ b/libs/nativewindow/libnativewindow.map.txt
@@ -23,6 +23,7 @@ LIBNATIVEWINDOW {
ANativeWindow_getFormat;
ANativeWindow_getHeight;
ANativeWindow_getLastDequeueDuration; # apex # introduced=30
+ ANativeWindow_getLastDequeueStartTime; # apex # introduced=30
ANativeWindow_getLastQueueDuration; # apex # introduced=30
ANativeWindow_getWidth;
ANativeWindow_lock;
diff --git a/libs/nativewindow/tests/ANativeWindowTest.cpp b/libs/nativewindow/tests/ANativeWindowTest.cpp
index 9b358da4b5..947217d52c 100644
--- a/libs/nativewindow/tests/ANativeWindowTest.cpp
+++ b/libs/nativewindow/tests/ANativeWindowTest.cpp
@@ -39,6 +39,9 @@ public:
// Exposes the internal last queue duration that's stored on the Surface.
nsecs_t getLastQueueDuration() const { return mLastQueueDuration; }
+
+ // Exposes the internal last dequeue start time that's stored on the Surface.
+ nsecs_t getLastDequeueStartTime() const { return mLastDequeueStartTime; }
};
class ANativeWindowTest : public ::testing::Test {
@@ -117,3 +120,21 @@ TEST_F(ANativeWindowTest, getLastQueueDuration_withQueue_returnsTime) {
EXPECT_GT(result, 0);
EXPECT_EQ(result, mWindow->getLastQueueDuration() / 1000);
}
+
+TEST_F(ANativeWindowTest, getLastDequeueStartTime_noDequeue_returnsZero) {
+ int64_t result = ANativeWindow_getLastDequeueStartTime(mWindow.get());
+ EXPECT_EQ(0, result);
+ EXPECT_EQ(0, mWindow->getLastQueueDuration());
+}
+
+TEST_F(ANativeWindowTest, getLastDequeueStartTime_withDequeue_returnsTime) {
+ ANativeWindowBuffer* buffer;
+ int fd;
+ int dequeueResult = ANativeWindow_dequeueBuffer(mWindow.get(), &buffer, &fd);
+ close(fd);
+ EXPECT_EQ(0, dequeueResult);
+
+ int64_t result = ANativeWindow_getLastDequeueStartTime(mWindow.get());
+ EXPECT_GT(result, 0);
+ EXPECT_EQ(result, mWindow->getLastDequeueStartTime());
+}