summaryrefslogtreecommitdiff
path: root/libs/gui/Surface.cpp
diff options
context:
space:
mode:
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);