Move remaining bits of lockBuffer to dequeueBuffer

FramebufferNativeWindow::dequeueBuffer now waits for the next buffer
to be non-front in addition to being free.

Change-Id: I991f154958cc6b488b1241aba83d1f95a0513b3c
diff --git a/libs/ui/FramebufferNativeWindow.cpp b/libs/ui/FramebufferNativeWindow.cpp
index 84cb8f3..5a36c3b 100644
--- a/libs/ui/FramebufferNativeWindow.cpp
+++ b/libs/ui/FramebufferNativeWindow.cpp
@@ -237,10 +237,12 @@
     if (self->mBufferHead >= self->mNumBuffers)
         self->mBufferHead = 0;
 
-    // wait for a free buffer
-    while (!self->mNumFreeBuffers) {
+    // wait for a free non-front buffer
+    while (self->mNumFreeBuffers < 2) {
         self->mCondition.wait(self->mutex);
     }
+    ALOG_ASSERT(self->buffers[index] != self->front);
+
     // get this buffer
     self->mNumFreeBuffers--;
     self->mCurrentBufferIndex = index;
@@ -254,17 +256,6 @@
 int FramebufferNativeWindow::lockBuffer_DEPRECATED(ANativeWindow* window, 
         ANativeWindowBuffer* buffer)
 {
-    // XXX: Can this code all get ripped out?  Should it move to dequeueBuffer?
-    FramebufferNativeWindow* self = getSelf(window);
-    Mutex::Autolock _l(self->mutex);
-
-    const int index = self->mCurrentBufferIndex;
-
-    // wait that the buffer we're locking is not front anymore
-    while (self->front == buffer) {
-        self->mCondition.wait(self->mutex);
-    }
-
     return NO_ERROR;
 }