handle several vsync signal correctly

Change-Id: I34935d2197ce8e914fef2f110896e47b44225ad2
This commit is contained in:
Mathias Agopian 2013-08-21 17:45:46 -07:00
parent 0f288fcc9c
commit bef42c50eb
2 changed files with 18 additions and 8 deletions

View File

@ -87,12 +87,17 @@ HWComposer::HWComposer(
mFbDev(0), mHwc(0), mNumDisplays(1), mFbDev(0), mHwc(0), mNumDisplays(1),
mCBContext(new cb_context), mCBContext(new cb_context),
mEventHandler(handler), mEventHandler(handler),
mVSyncCount(0), mDebugForceFakeVSync(false) mDebugForceFakeVSync(false)
{ {
for (size_t i =0 ; i<MAX_HWC_DISPLAYS ; i++) { for (size_t i =0 ; i<MAX_HWC_DISPLAYS ; i++) {
mLists[i] = 0; mLists[i] = 0;
} }
for (size_t i=0 ; i<HWC_NUM_PHYSICAL_DISPLAY_TYPES ; i++) {
mLastHwVSync[i] = 0;
mVSyncCounts[i] = 0;
}
char value[PROPERTY_VALUE_MAX]; char value[PROPERTY_VALUE_MAX];
property_get("debug.sf.no_hw_vsync", value, "0"); property_get("debug.sf.no_hw_vsync", value, "0");
mDebugForceFakeVSync = atoi(value); mDebugForceFakeVSync = atoi(value);
@ -278,10 +283,15 @@ void HWComposer::invalidate() {
} }
void HWComposer::vsync(int disp, int64_t timestamp) { void HWComposer::vsync(int disp, int64_t timestamp) {
ATRACE_INT("VSYNC", ++mVSyncCount&1); if (uint32_t(disp) < HWC_NUM_PHYSICAL_DISPLAY_TYPES) {
mEventHandler.onVSyncReceived(disp, timestamp); char tag[16];
Mutex::Autolock _l(mLock); snprintf(tag, sizeof(tag), "VSYNC_%1u", disp);
mLastHwVSync = timestamp; ATRACE_INT(tag, ++mVSyncCounts[disp] & 1);
mEventHandler.onVSyncReceived(disp, timestamp);
Mutex::Autolock _l(mLock);
mLastHwVSync[disp] = timestamp;
}
} }
void HWComposer::hotplug(int disp, int connected) { void HWComposer::hotplug(int disp, int connected) {
@ -415,7 +425,7 @@ nsecs_t HWComposer::getRefreshTimestamp(int disp) const {
// the refresh period and whatever closest timestamp we have. // the refresh period and whatever closest timestamp we have.
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
nsecs_t now = systemTime(CLOCK_MONOTONIC); nsecs_t now = systemTime(CLOCK_MONOTONIC);
return now - ((now - mLastHwVSync) % mDisplayData[disp].refresh); return now - ((now - mLastHwVSync[disp]) % mDisplayData[disp].refresh);
} }
sp<Fence> HWComposer::getDisplayFence(int disp) const { sp<Fence> HWComposer::getDisplayFence(int disp) const {

View File

@ -342,14 +342,14 @@ private:
cb_context* mCBContext; cb_context* mCBContext;
EventHandler& mEventHandler; EventHandler& mEventHandler;
size_t mVSyncCount; size_t mVSyncCounts[HWC_NUM_PHYSICAL_DISPLAY_TYPES];
sp<VSyncThread> mVSyncThread; sp<VSyncThread> mVSyncThread;
bool mDebugForceFakeVSync; bool mDebugForceFakeVSync;
BitSet32 mAllocatedDisplayIDs; BitSet32 mAllocatedDisplayIDs;
// protected by mLock // protected by mLock
mutable Mutex mLock; mutable Mutex mLock;
mutable nsecs_t mLastHwVSync; mutable nsecs_t mLastHwVSync[HWC_NUM_PHYSICAL_DISPLAY_TYPES];
// thread-safe // thread-safe
mutable Mutex mEventControlLock; mutable Mutex mEventControlLock;