Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d94d3b89 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

avoid turning vsync off/on at each frame

always keep vsync active for an extra frame before
deciding if it should be turned off.

Change-Id: I55b03265b7851b33a595e46a013f2ab55e66c964
parent c522a6a5
Loading
Loading
Loading
Loading
+24 −10
Original line number Diff line number Diff line
@@ -123,13 +123,9 @@ bool EventThread::threadLoop() {

        Mutex::Autolock _l(mLock);
        do {
            // check if we have received a VSYNC event
            if (mVSyncTimestamp) {
                // we have a VSYNC event pending
            // latch VSYNC event if any
            timestamp = mVSyncTimestamp;
            mVSyncTimestamp = 0;
                break;
            }

            // check if we should be waiting for VSYNC events
            bool waitForNextVsync = false;
@@ -144,9 +140,27 @@ bool EventThread::threadLoop() {
                }
            }

            // enable or disable VSYNC events
            if (timestamp) {
                if (!waitForNextVsync) {
                    // we received a VSYNC but we have no clients
                    // don't report it, and disable VSYNC events
                    mHw.getHwComposer().eventControl(
                    HWComposer::EVENT_VSYNC, waitForNextVsync);
                            HWComposer::EVENT_VSYNC, false);
                } else {
                    // report VSYNC event
                    break;
                }
            } else {
                // never disable VSYNC events immediately, instead
                // we'll wait to receive the event and we'll
                // reevaluate whether we need to dispatch it and/or
                // disable VSYNC events then.
                if (waitForNextVsync) {
                    // enable
                    mHw.getHwComposer().eventControl(
                            HWComposer::EVENT_VSYNC, true);
                }
            }

            // wait for something to happen
            mCondition.wait(mLock);