BufferQueue improvements and APIs changes

this is the first step of a series of improvements to
BufferQueue. A few things happen in this change:

- setSynchronousMode() goes away as well as the SynchronousModeAllowed flag
- BufferQueue now defaults to (what used to be) synchronous mode
- a new "controlled by app" flag is passed when creating consumers and producers
  those flags are used to put the BufferQueue in a mode where it
  will never block if both flags are set. This is achieved by:
  - returning an error from dequeueBuffer() if it would block
  - making sure a buffer is always available by replacing
    the previous buffer with the new one in queueBuffer()
    (note: this is similar to what asynchrnous mode used to be)

Note: in this change EGL's swap-interval 0 is broken; this will be
fixed in another change.

Change-Id: I691f9507d6e2e158287e3039f2a79a4d4434211d
diff --git a/libs/gui/tests/SurfaceTexture_test.cpp b/libs/gui/tests/SurfaceTexture_test.cpp
index d97521a..e6d87db 100644
--- a/libs/gui/tests/SurfaceTexture_test.cpp
+++ b/libs/gui/tests/SurfaceTexture_test.cpp
@@ -944,7 +944,6 @@
     enum { texHeight = 16 };
     enum { numFrames = 1024 };
 
-    ASSERT_EQ(NO_ERROR, mST->setSynchronousMode(true));
     ASSERT_EQ(NO_ERROR, mST->setDefaultMaxBufferCount(2));
     ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
             texWidth, texHeight, HAL_PIXEL_FORMAT_YV12));
@@ -1211,10 +1210,8 @@
         sp<ANativeWindow> mANW;
     };
 
-    ASSERT_EQ(OK, mST->setSynchronousMode(true));
-
     sp<DisconnectWaiter> dw(new DisconnectWaiter());
-    mST->getBufferQueue()->consumerConnect(dw);
+    mST->getBufferQueue()->consumerConnect(dw, false);
 
 
     sp<Thread> pt(new ProducerThread(mANW));
@@ -1237,8 +1234,6 @@
 // when it is disconnected and reconnected.  Otherwise it will
 // attempt to release a buffer that it does not owned
 TEST_F(SurfaceTextureGLTest, DisconnectClearsCurrentTexture) {
-    ASSERT_EQ(OK, mST->setSynchronousMode(true));
-
     ASSERT_EQ(OK, native_window_api_connect(mANW.get(),
             NATIVE_WINDOW_API_EGL));
 
@@ -1258,8 +1253,6 @@
     ASSERT_EQ(OK, native_window_api_connect(mANW.get(),
             NATIVE_WINDOW_API_EGL));
 
-    ASSERT_EQ(OK, mST->setSynchronousMode(true));
-
     EXPECT_EQ(OK, native_window_dequeue_buffer_and_wait(mANW.get(), &anb));
     EXPECT_EQ(OK, mANW->queueBuffer(mANW.get(), anb, -1));
 
@@ -1272,8 +1265,6 @@
 }
 
 TEST_F(SurfaceTextureGLTest, ScaleToWindowMode) {
-    ASSERT_EQ(OK, mST->setSynchronousMode(true));
-
     ASSERT_EQ(OK, native_window_set_scaling_mode(mANW.get(),
         NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW));
 
@@ -1306,8 +1297,6 @@
 // the image such that it has the same aspect ratio as the
 // default buffer size
 TEST_F(SurfaceTextureGLTest, CroppedScalingMode) {
-    ASSERT_EQ(OK, mST->setSynchronousMode(true));
-
     ASSERT_EQ(OK, native_window_set_scaling_mode(mANW.get(),
         NATIVE_WINDOW_SCALING_MODE_SCALE_CROP));
 
@@ -1417,7 +1406,6 @@
         Mutex mMutex;
     };
 
-    ASSERT_EQ(OK, mST->setSynchronousMode(true));
     ASSERT_EQ(OK, mST->setDefaultMaxBufferCount(2));
 
     sp<Thread> pt(new ProducerThread(mANW));
@@ -1810,32 +1798,6 @@
     EXPECT_EQ(1, buffer->getStrongCount());
 }
 
-
-TEST_F(SurfaceTextureGLToGLTest, EglSurfaceDefaultsToSynchronousMode) {
-    // This test requires 3 buffers to run on a single thread.
-    mST->setDefaultMaxBufferCount(3);
-
-    ASSERT_TRUE(mST->isSynchronousMode());
-
-    for (int i = 0; i < 10; i++) {
-        // Produce a frame
-        EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
-                mProducerEglSurface, mProducerEglContext));
-        ASSERT_EQ(EGL_SUCCESS, eglGetError());
-        glClear(GL_COLOR_BUFFER_BIT);
-        EXPECT_TRUE(eglSwapBuffers(mEglDisplay, mProducerEglSurface));
-        ASSERT_EQ(EGL_SUCCESS, eglGetError());
-
-        // Consume a frame
-        EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
-                mEglContext));
-        ASSERT_EQ(EGL_SUCCESS, eglGetError());
-        ASSERT_EQ(NO_ERROR, mST->updateTexImage());
-    }
-
-    ASSERT_TRUE(mST->isSynchronousMode());
-}
-
 TEST_F(SurfaceTextureGLToGLTest, TexturingFromUserSizedGLFilledBuffer) {
     enum { texWidth = 64 };
     enum { texHeight = 64 };
@@ -2285,7 +2247,6 @@
         }
     };
 
-    ASSERT_EQ(OK, mST->setSynchronousMode(true));
     ASSERT_EQ(OK, mST->setDefaultMaxBufferCount(2));
 
     runProducerThread(new PT());
@@ -2826,7 +2787,6 @@
 
 TEST_F(SurfaceTextureMultiContextGLTest,
         UpdateTexImageSucceedsForBufferConsumedBeforeDetach) {
-    ASSERT_EQ(NO_ERROR, mST->setSynchronousMode(true));
     ASSERT_EQ(NO_ERROR, mST->setDefaultMaxBufferCount(2));
 
     // produce two frames and consume them both on the primary context