From e02f7b3fa88a895ee93030bc7bd2a3fa010c1a8f Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 24 Jan 2012 16:39:14 -0800 Subject: SF now synchronizes to VSYNC Change-Id: Ic5e4f2ea9927ce133eef9499c03161325e9d02c5 --- services/surfaceflinger/EventThread.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'services/surfaceflinger/EventThread.cpp') diff --git a/services/surfaceflinger/EventThread.cpp b/services/surfaceflinger/EventThread.cpp index 6796d7dee2a7..92d4266a8fd9 100644 --- a/services/surfaceflinger/EventThread.cpp +++ b/services/surfaceflinger/EventThread.cpp @@ -36,6 +36,7 @@ namespace android { EventThread::EventThread(const sp& flinger) : mFlinger(flinger), mHw(flinger->graphicPlane(0).displayHardware()), + mLastVSyncTimestamp(0), mDeliveredEvents(0) { } @@ -44,6 +45,20 @@ void EventThread::onFirstRef() { run("EventThread", PRIORITY_URGENT_DISPLAY + PRIORITY_MORE_FAVORABLE); } +sp EventThread::createEventConnection() const { + return new DisplayEventConnection(const_cast(this)); +} + +nsecs_t EventThread::getLastVSyncTimestamp() const { + Mutex::Autolock _l(mLock); + return mLastVSyncTimestamp; +} + +nsecs_t EventThread::getVSyncPeriod() const { + return mHw.getRefreshPeriod(); + +} + status_t EventThread::registerDisplayEventConnection( const sp& connection) { Mutex::Autolock _l(mLock); @@ -80,8 +95,11 @@ void EventThread::setVsyncRate(uint32_t count, Mutex::Autolock _l(mLock); ConnectionInfo* info = getConnectionInfoLocked(connection); if (info) { - info->count = (count == 0) ? -1 : count; - mCondition.signal(); + const int32_t new_count = (count == 0) ? -1 : count; + if (info->count != new_count) { + info->count = new_count; + mCondition.signal(); + } } } } @@ -90,10 +108,8 @@ void EventThread::requestNextVsync( const wp& connection) { Mutex::Autolock _l(mLock); ConnectionInfo* info = getConnectionInfoLocked(connection); - if (info) { - if (info->count < 0) { - info->count = 0; - } + if (info && info->count < 0) { + info->count = 0; mCondition.signal(); } } @@ -132,6 +148,7 @@ bool EventThread::threadLoop() { timestamp = mHw.waitForRefresh(); mLock.lock(); mDeliveredEvents++; + mLastVSyncTimestamp = timestamp; // now see if we still need to report this VSYNC event bool reportVsync = false; -- cgit v1.2.3-59-g8ed1b