SurfaceTexture: change onFrameAvailable behavior

This change alters the conditions under which the onFrameAvailable
callback gets called by the C++ SurfaceTexture class.  The new behavior
is to call the callback whenever a frame gets queued that will be
visible to the buffer consumer.  This means that buffers queued in
synchronous mode always trigger the callback, as those buffers will
remain pending until they are consumed.  Buffers queued in asynchronous
mode will only trigger the callback if there was not previously an
unconsumed buffer pending.

The new behavior means that a consumer should perform a draw operation
exactly once for every onFrameAvailable call that it recieves.  This
change also modifies SurfaceFlinger and the SurfaceTexture JNI to
support of the new behavior.

Change-Id: I8b2c6e00961d3d58b11c6af50b555b6e4c5f5b40
diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp
index 37e6d11..96ab284 100644
--- a/libs/gui/SurfaceTexture.cpp
+++ b/libs/gui/SurfaceTexture.cpp
@@ -417,17 +417,22 @@
             return -EINVAL;
         }
 
-        if (mQueue.empty()) {
-            listener = mFrameAvailableListener;
-        }
-
         if (mSynchronousMode) {
-            // in synchronous mode we queue all buffers in a FIFO
+            // In synchronous mode we queue all buffers in a FIFO.
             mQueue.push_back(buf);
+
+            // Synchronous mode always signals that an additional frame should
+            // be consumed.
+            listener = mFrameAvailableListener;
         } else {
-            // in asynchronous mode we only keep the most recent buffer
+            // In asynchronous mode we only keep the most recent buffer.
             if (mQueue.empty()) {
                 mQueue.push_back(buf);
+
+                // Asynchronous mode only signals that a frame should be
+                // consumed if no previous frame was pending. If a frame were
+                // pending then the consumer would have already been notified.
+                listener = mFrameAvailableListener;
             } else {
                 Fifo::iterator front(mQueue.begin());
                 // buffer currently queued is freed
@@ -561,11 +566,6 @@
     return OK;
 }
 
-size_t SurfaceTexture::getQueuedCount() const {
-    Mutex::Autolock lock(mMutex);
-    return mQueue.size();
-}
-
 bool SurfaceTexture::isExternalFormat(uint32_t format)
 {
     switch (format) {