Loading services/surfaceflinger/DispSync.cpp +21 −22 Original line number Original line Diff line number Diff line Loading @@ -28,7 +28,6 @@ #include <utils/String8.h> #include <utils/String8.h> #include <utils/Thread.h> #include <utils/Thread.h> #include <utils/Trace.h> #include <utils/Trace.h> #include <utils/Vector.h> #include <ui/FenceTime.h> #include <ui/FenceTime.h> Loading Loading @@ -94,7 +93,7 @@ public: nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); while (true) { while (true) { Vector<CallbackInvocation> callbackInvocations; std::vector<CallbackInvocation> callbackInvocations; nsecs_t targetTime = 0; nsecs_t targetTime = 0; Loading Loading @@ -187,7 +186,7 @@ public: // allowing any past events to fire // allowing any past events to fire listener.mLastEventTime = systemTime() - mPeriod / 2 + mPhase - mWakeupLatency; listener.mLastEventTime = systemTime() - mPeriod / 2 + mPhase - mWakeupLatency; mEventListeners.push(listener); mEventListeners.push_back(listener); mCond.signal(); mCond.signal(); Loading @@ -198,9 +197,10 @@ public: if (kTraceDetailedInfo) ATRACE_CALL(); if (kTraceDetailedInfo) ATRACE_CALL(); Mutex::Autolock lock(mMutex); Mutex::Autolock lock(mMutex); for (size_t i = 0; i < mEventListeners.size(); i++) { for (std::vector<EventListener>::iterator it = mEventListeners.begin(); if (mEventListeners[i].mCallback == callback) { it != mEventListeners.end(); ++it) { mEventListeners.removeAt(i); if (it->mCallback == callback) { mEventListeners.erase(it); mCond.signal(); mCond.signal(); return NO_ERROR; return NO_ERROR; } } Loading @@ -213,11 +213,10 @@ public: if (kTraceDetailedInfo) ATRACE_CALL(); if (kTraceDetailedInfo) ATRACE_CALL(); Mutex::Autolock lock(mMutex); Mutex::Autolock lock(mMutex); for (size_t i = 0; i < mEventListeners.size(); i++) { for (auto& eventListener : mEventListeners) { if (mEventListeners[i].mCallback == callback) { if (eventListener.mCallback == callback) { EventListener& listener = mEventListeners.editItemAt(i); const nsecs_t oldPhase = eventListener.mPhase; const nsecs_t oldPhase = listener.mPhase; eventListener.mPhase = phase; listener.mPhase = phase; // Pretend that the last time this event was handled at the same frame but with the // Pretend that the last time this event was handled at the same frame but with the // new offset to allow for a seamless offset change without double-firing or // new offset to allow for a seamless offset change without double-firing or Loading @@ -228,7 +227,7 @@ public: } else if (diff < -mPeriod / 2) { } else if (diff < -mPeriod / 2) { diff += mPeriod; diff += mPeriod; } } listener.mLastEventTime -= diff; eventListener.mLastEventTime -= diff; mCond.signal(); mCond.signal(); return NO_ERROR; return NO_ERROR; } } Loading Loading @@ -274,23 +273,23 @@ private: return nextEventTime; return nextEventTime; } } Vector<CallbackInvocation> gatherCallbackInvocationsLocked(nsecs_t now) { std::vector<CallbackInvocation> gatherCallbackInvocationsLocked(nsecs_t now) { if (kTraceDetailedInfo) ATRACE_CALL(); if (kTraceDetailedInfo) ATRACE_CALL(); ALOGV("[%s] gatherCallbackInvocationsLocked @ %" PRId64, mName, ns2us(now)); ALOGV("[%s] gatherCallbackInvocationsLocked @ %" PRId64, mName, ns2us(now)); Vector<CallbackInvocation> callbackInvocations; std::vector<CallbackInvocation> callbackInvocations; nsecs_t onePeriodAgo = now - mPeriod; nsecs_t onePeriodAgo = now - mPeriod; for (size_t i = 0; i < mEventListeners.size(); i++) { for (auto& eventListener : mEventListeners) { nsecs_t t = computeListenerNextEventTimeLocked(mEventListeners[i], onePeriodAgo); nsecs_t t = computeListenerNextEventTimeLocked(eventListener, onePeriodAgo); if (t < now) { if (t < now) { CallbackInvocation ci; CallbackInvocation ci; ci.mCallback = mEventListeners[i].mCallback; ci.mCallback = eventListener.mCallback; ci.mEventTime = t; ci.mEventTime = t; ALOGV("[%s] [%s] Preparing to fire", mName, mEventListeners[i].mName); ALOGV("[%s] [%s] Preparing to fire", mName, eventListener.mName); callbackInvocations.push(ci); callbackInvocations.push_back(ci); mEventListeners.editItemAt(i).mLastEventTime = t; eventListener.mLastEventTime = t; } } } } Loading Loading @@ -348,7 +347,7 @@ private: return t; return t; } } void fireCallbackInvocations(const Vector<CallbackInvocation>& callbacks) { void fireCallbackInvocations(const std::vector<CallbackInvocation>& callbacks) { if (kTraceDetailedInfo) ATRACE_CALL(); if (kTraceDetailedInfo) ATRACE_CALL(); for (size_t i = 0; i < callbacks.size(); i++) { for (size_t i = 0; i < callbacks.size(); i++) { callbacks[i].mCallback->onDispSyncEvent(callbacks[i].mEventTime); callbacks[i].mCallback->onDispSyncEvent(callbacks[i].mEventTime); Loading @@ -366,7 +365,7 @@ private: int64_t mFrameNumber; int64_t mFrameNumber; Vector<EventListener> mEventListeners; std::vector<EventListener> mEventListeners; Mutex mMutex; Mutex mMutex; Condition mCond; Condition mCond; Loading Loading
services/surfaceflinger/DispSync.cpp +21 −22 Original line number Original line Diff line number Diff line Loading @@ -28,7 +28,6 @@ #include <utils/String8.h> #include <utils/String8.h> #include <utils/Thread.h> #include <utils/Thread.h> #include <utils/Trace.h> #include <utils/Trace.h> #include <utils/Vector.h> #include <ui/FenceTime.h> #include <ui/FenceTime.h> Loading Loading @@ -94,7 +93,7 @@ public: nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); while (true) { while (true) { Vector<CallbackInvocation> callbackInvocations; std::vector<CallbackInvocation> callbackInvocations; nsecs_t targetTime = 0; nsecs_t targetTime = 0; Loading Loading @@ -187,7 +186,7 @@ public: // allowing any past events to fire // allowing any past events to fire listener.mLastEventTime = systemTime() - mPeriod / 2 + mPhase - mWakeupLatency; listener.mLastEventTime = systemTime() - mPeriod / 2 + mPhase - mWakeupLatency; mEventListeners.push(listener); mEventListeners.push_back(listener); mCond.signal(); mCond.signal(); Loading @@ -198,9 +197,10 @@ public: if (kTraceDetailedInfo) ATRACE_CALL(); if (kTraceDetailedInfo) ATRACE_CALL(); Mutex::Autolock lock(mMutex); Mutex::Autolock lock(mMutex); for (size_t i = 0; i < mEventListeners.size(); i++) { for (std::vector<EventListener>::iterator it = mEventListeners.begin(); if (mEventListeners[i].mCallback == callback) { it != mEventListeners.end(); ++it) { mEventListeners.removeAt(i); if (it->mCallback == callback) { mEventListeners.erase(it); mCond.signal(); mCond.signal(); return NO_ERROR; return NO_ERROR; } } Loading @@ -213,11 +213,10 @@ public: if (kTraceDetailedInfo) ATRACE_CALL(); if (kTraceDetailedInfo) ATRACE_CALL(); Mutex::Autolock lock(mMutex); Mutex::Autolock lock(mMutex); for (size_t i = 0; i < mEventListeners.size(); i++) { for (auto& eventListener : mEventListeners) { if (mEventListeners[i].mCallback == callback) { if (eventListener.mCallback == callback) { EventListener& listener = mEventListeners.editItemAt(i); const nsecs_t oldPhase = eventListener.mPhase; const nsecs_t oldPhase = listener.mPhase; eventListener.mPhase = phase; listener.mPhase = phase; // Pretend that the last time this event was handled at the same frame but with the // Pretend that the last time this event was handled at the same frame but with the // new offset to allow for a seamless offset change without double-firing or // new offset to allow for a seamless offset change without double-firing or Loading @@ -228,7 +227,7 @@ public: } else if (diff < -mPeriod / 2) { } else if (diff < -mPeriod / 2) { diff += mPeriod; diff += mPeriod; } } listener.mLastEventTime -= diff; eventListener.mLastEventTime -= diff; mCond.signal(); mCond.signal(); return NO_ERROR; return NO_ERROR; } } Loading Loading @@ -274,23 +273,23 @@ private: return nextEventTime; return nextEventTime; } } Vector<CallbackInvocation> gatherCallbackInvocationsLocked(nsecs_t now) { std::vector<CallbackInvocation> gatherCallbackInvocationsLocked(nsecs_t now) { if (kTraceDetailedInfo) ATRACE_CALL(); if (kTraceDetailedInfo) ATRACE_CALL(); ALOGV("[%s] gatherCallbackInvocationsLocked @ %" PRId64, mName, ns2us(now)); ALOGV("[%s] gatherCallbackInvocationsLocked @ %" PRId64, mName, ns2us(now)); Vector<CallbackInvocation> callbackInvocations; std::vector<CallbackInvocation> callbackInvocations; nsecs_t onePeriodAgo = now - mPeriod; nsecs_t onePeriodAgo = now - mPeriod; for (size_t i = 0; i < mEventListeners.size(); i++) { for (auto& eventListener : mEventListeners) { nsecs_t t = computeListenerNextEventTimeLocked(mEventListeners[i], onePeriodAgo); nsecs_t t = computeListenerNextEventTimeLocked(eventListener, onePeriodAgo); if (t < now) { if (t < now) { CallbackInvocation ci; CallbackInvocation ci; ci.mCallback = mEventListeners[i].mCallback; ci.mCallback = eventListener.mCallback; ci.mEventTime = t; ci.mEventTime = t; ALOGV("[%s] [%s] Preparing to fire", mName, mEventListeners[i].mName); ALOGV("[%s] [%s] Preparing to fire", mName, eventListener.mName); callbackInvocations.push(ci); callbackInvocations.push_back(ci); mEventListeners.editItemAt(i).mLastEventTime = t; eventListener.mLastEventTime = t; } } } } Loading Loading @@ -348,7 +347,7 @@ private: return t; return t; } } void fireCallbackInvocations(const Vector<CallbackInvocation>& callbacks) { void fireCallbackInvocations(const std::vector<CallbackInvocation>& callbacks) { if (kTraceDetailedInfo) ATRACE_CALL(); if (kTraceDetailedInfo) ATRACE_CALL(); for (size_t i = 0; i < callbacks.size(); i++) { for (size_t i = 0; i < callbacks.size(); i++) { callbacks[i].mCallback->onDispSyncEvent(callbacks[i].mEventTime); callbacks[i].mCallback->onDispSyncEvent(callbacks[i].mEventTime); Loading @@ -366,7 +365,7 @@ private: int64_t mFrameNumber; int64_t mFrameNumber; Vector<EventListener> mEventListeners; std::vector<EventListener> mEventListeners; Mutex mMutex; Mutex mMutex; Condition mCond; Condition mCond; Loading