@@ -107,27 +107,17 @@ bool EventThread::threadLoop() {
107107 { // scope for the lock
108108 Mutex::Autolock _l (mLock );
109109 do {
110- // wait for listeners
110+ // see if we need to wait for the VSYNC at all
111111 do {
112112 bool waitForNextVsync = false ;
113113 size_t count = mDisplayEventConnections .size ();
114114 for (size_t i=0 ; i<count ; i++) {
115115 const ConnectionInfo& info (
116116 mDisplayEventConnections .valueAt (i));
117- if (info.count >= 1 ) {
118- // continuous mode
117+ if (info.count >= 0 ) {
118+ // at least one continuous mode or active one-shot event
119119 waitForNextVsync = true ;
120- } else {
121- // one-shot event
122- if (info.count >= -1 ) {
123- ConnectionInfo& info (
124- mDisplayEventConnections .editValueAt (i));
125- info.count --;
126- if (info.count == -1 ) {
127- // fired this time around
128- waitForNextVsync = true ;
129- }
130- }
120+ break ;
131121 }
132122 }
133123
@@ -137,14 +127,38 @@ bool EventThread::threadLoop() {
137127 mCondition .wait (mLock );
138128 } while (true );
139129
140- // wait for vsync
130+ // at least one listener requested VSYNC
141131 mLock .unlock ();
142132 timestamp = mHw .waitForVSync ();
143133 mLock .lock ();
144134 mDeliveredEvents ++;
145135
146- // make sure we still have some listeners
147- } while (!mDisplayEventConnections .size ());
136+ // now see if we still need to report this VSYNC event
137+ bool reportVsync = false ;
138+ size_t count = mDisplayEventConnections .size ();
139+ for (size_t i=0 ; i<count ; i++) {
140+ const ConnectionInfo& info (
141+ mDisplayEventConnections .valueAt (i));
142+ if (info.count >= 1 ) {
143+ if (info.count ==1 || (mDeliveredEvents % info.count ) == 0 ) {
144+ // continuous event, and time to report it
145+ reportVsync = true ;
146+ }
147+ } else if (info.count >= -1 ) {
148+ ConnectionInfo& info (
149+ mDisplayEventConnections .editValueAt (i));
150+ if (info.count == 0 ) {
151+ // fired this time around
152+ reportVsync = true ;
153+ }
154+ info.count --;
155+ }
156+ }
157+
158+ if (reportVsync) {
159+ break ;
160+ }
161+ } while (true );
148162
149163 // dispatch vsync events to listeners...
150164 vsync.header .type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC;
@@ -161,27 +175,6 @@ bool EventThread::threadLoop() {
161175 sp<DisplayEventConnection> conn (displayEventConnections.keyAt (i).promote ());
162176 // make sure the connection didn't die
163177 if (conn != NULL ) {
164-
165- const ConnectionInfo& info (
166- displayEventConnections.valueAt (i));
167-
168- if ((info.count > 1 ) && (mDeliveredEvents % info.count )) {
169- // continuous event, but not time to send this event yet
170- continue ;
171- } else if (info.count < -1 ) {
172- // disabled event
173- continue ;
174- } else if (info.count == 0 ) {
175- // impossible by construction. but we prefer to be safe.
176- continue ;
177- }
178-
179- // here, either:
180- // count = -1 : one-shot scheduled this time around
181- // count = 1 : continuous not rate-limited
182- // count > 1 : continuous, rate-limited
183- // Note: count == 0 is not possible by construction
184-
185178 status_t err = conn->postEvent (vsync);
186179 if (err == -EAGAIN || err == -EWOULDBLOCK) {
187180 // The destination doesn't accept events anymore, it's probably
0 commit comments