summaryrefslogtreecommitdiff
path: root/libs/gui/Surface.cpp
diff options
context:
space:
mode:
author Brian Anderson <brianderson@google.com> 2016-12-07 14:55:56 -0800
committer Brian Anderson <brianderson@google.com> 2017-02-13 16:01:47 -0800
commit0a61b0c813f5991bf462e36a2314dda062727a10 (patch)
tree4987f8f0e07bcda8e1dda882ebb6f4d6151c6107 /libs/gui/Surface.cpp
parent1049d1d0b21ee318e309f9a90098c092cb879c41 (diff)
EGL: Add eglGetCompositorTimingANDROID.
Exposes the composite deadline, composite interval, and the composite to present latency. A history of composite and present fences are stored. When the present fence's timestamp becomes known, the composite to present latency is updated with sampling jitter removed. The values are updated in the producer when timestamps are enabled and on queue and dequeue. The deadline is snapped to the next expected deadline based on the current systemTime(). Test: adb shell /data/nativetest/libgui_test/libgui_test --gtest_filter=*GetFrameTimestamps* Change-Id: I406814258613b984b56488236632494f2f61ff2e
Diffstat (limited to 'libs/gui/Surface.cpp')
-rw-r--r--libs/gui/Surface.cpp81
1 files changed, 63 insertions, 18 deletions
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index 2e3a7dedfb..b250f5d4b7 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -102,6 +102,10 @@ sp<ISurfaceComposer> Surface::composerService() const {
return ComposerService::getComposerService();
}
+nsecs_t Surface::now() const {
+ return systemTime();
+}
+
sp<IGraphicBufferProducer> Surface::getIGraphicBufferProducer() const {
return mGraphicBufferProducer;
}
@@ -144,11 +148,51 @@ status_t Surface::getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
outTransformMatrix);
}
+status_t Surface::getDisplayRefreshCycleDuration(nsecs_t* outRefreshDuration) {
+ ATRACE_CALL();
+
+ DisplayStatInfo stats;
+ status_t err = composerService()->getDisplayStats(NULL, &stats);
+
+ *outRefreshDuration = stats.vsyncPeriod;
+
+ return NO_ERROR;
+}
+
void Surface::enableFrameTimestamps(bool enable) {
Mutex::Autolock lock(mMutex);
+ // If going from disabled to enabled, get the initial values for
+ // compositor and display timing.
+ if (!mEnableFrameTimestamps && enable) {
+ FrameEventHistoryDelta delta;
+ mGraphicBufferProducer->getFrameTimestamps(&delta);
+ mFrameEventHistory->applyDelta(delta);
+ }
mEnableFrameTimestamps = enable;
}
+status_t Surface::getCompositorTiming(
+ nsecs_t* compositeDeadline, nsecs_t* compositeInterval,
+ nsecs_t* compositeToPresentLatency) {
+ Mutex::Autolock lock(mMutex);
+ if (!mEnableFrameTimestamps) {
+ return INVALID_OPERATION;
+ }
+
+ if (compositeDeadline != nullptr) {
+ *compositeDeadline =
+ mFrameEventHistory->getNextCompositeDeadline(now());
+ }
+ if (compositeInterval != nullptr) {
+ *compositeInterval = mFrameEventHistory->getCompositeInterval();
+ }
+ if (compositeToPresentLatency != nullptr) {
+ *compositeToPresentLatency =
+ mFrameEventHistory->getCompositeToPresentLatency();
+ }
+ return NO_ERROR;
+}
+
static bool checkConsumerForUpdates(
const FrameEvents* e, const uint64_t lastFrameNumber,
const nsecs_t* outLatchTime,
@@ -262,16 +306,6 @@ status_t Surface::getFrameTimestamps(uint64_t frameNumber,
return NO_ERROR;
}
-status_t Surface::getDisplayRefreshCycleDuration(nsecs_t* outRefreshDuration) {
- ATRACE_CALL();
-
- DisplayStatInfo stats;
- status_t err = composerService()->getDisplayStats(NULL, &stats);
-
- *outRefreshDuration = stats.vsyncPeriod;
-
- return NO_ERROR;
-}
int Surface::hook_setSwapInterval(ANativeWindow* window, int interval) {
Surface* c = getSelf(window);
@@ -833,18 +867,21 @@ int Surface::perform(int operation, va_list args)
case NATIVE_WINDOW_SET_AUTO_REFRESH:
res = dispatchSetAutoRefresh(args);
break;
+ case NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION:
+ res = dispatchGetDisplayRefreshCycleDuration(args);
+ break;
case NATIVE_WINDOW_GET_NEXT_FRAME_ID:
res = dispatchGetNextFrameId(args);
break;
case NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS:
res = dispatchEnableFrameTimestamps(args);
break;
+ case NATIVE_WINDOW_GET_COMPOSITOR_TIMING:
+ res = dispatchGetCompositorTiming(args);
+ break;
case NATIVE_WINDOW_GET_FRAME_TIMESTAMPS:
res = dispatchGetFrameTimestamps(args);
break;
- case NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION:
- res = dispatchGetDisplayRefreshCycleDuration(args);
- break;
default:
res = NAME_NOT_FOUND;
break;
@@ -965,6 +1002,11 @@ int Surface::dispatchSetAutoRefresh(va_list args) {
return setAutoRefresh(autoRefresh);
}
+int Surface::dispatchGetDisplayRefreshCycleDuration(va_list args) {
+ nsecs_t* outRefreshDuration = va_arg(args, int64_t*);
+ return getDisplayRefreshCycleDuration(outRefreshDuration);
+}
+
int Surface::dispatchGetNextFrameId(va_list args) {
uint64_t* nextFrameId = va_arg(args, uint64_t*);
*nextFrameId = getNextFrameNumber();
@@ -977,6 +1019,14 @@ int Surface::dispatchEnableFrameTimestamps(va_list args) {
return NO_ERROR;
}
+int Surface::dispatchGetCompositorTiming(va_list args) {
+ nsecs_t* compositeDeadline = va_arg(args, int64_t*);
+ nsecs_t* compositeInterval = va_arg(args, int64_t*);
+ nsecs_t* compositeToPresentLatency = va_arg(args, int64_t*);
+ return getCompositorTiming(compositeDeadline, compositeInterval,
+ compositeToPresentLatency);
+}
+
int Surface::dispatchGetFrameTimestamps(va_list args) {
uint64_t frameId = va_arg(args, uint64_t);
nsecs_t* outRequestedPresentTime = va_arg(args, int64_t*);
@@ -996,11 +1046,6 @@ int Surface::dispatchGetFrameTimestamps(va_list args) {
outDisplayRetireTime, outDequeueReadyTime, outReleaseTime);
}
-int Surface::dispatchGetDisplayRefreshCycleDuration(va_list args) {
- nsecs_t* outRefreshDuration = va_arg(args, int64_t*);
- return getDisplayRefreshCycleDuration(outRefreshDuration);
-}
-
int Surface::connect(int api) {
static sp<IProducerListener> listener = new DummyProducerListener();
return connect(api, listener);