opengles emulator: inc/dec ref-count of buffer on SwapBuffers

On every swapBuffers, we make sure to decRef on the prev buffer,
and incRef on the current buffer. This fixes all the anoying
crashes on application exit, and also after the speech windows
on Replica Island

Change-Id: I1981fbf17a24ef6f60cdcf6d7ec3a5e7eef5377f
diff --git a/tools/emulator/opengl/system/egl/egl.cpp b/tools/emulator/opengl/system/egl/egl.cpp
index 79fffe9..c920e0c 100644
--- a/tools/emulator/opengl/system/egl/egl.cpp
+++ b/tools/emulator/opengl/system/egl/egl.cpp
@@ -361,9 +361,16 @@
 
     rcEnc->rcFlushWindowColorBuffer(rcEnc, rcSurface);
 
+    android_native_buffer_t* prevBuf = buffer;
     //post the back buffer
     nativeWindow->queueBuffer(nativeWindow, buffer);
 
+    buffer->common.incRef(&buffer->common);
+
+    if (prevBuf) {
+        prevBuf->common.decRef(&prevBuf->common);
+    }
+
     // dequeue a new buffer
     if (nativeWindow->dequeueBuffer(nativeWindow, &buffer)) {
         setErrorReturn(EGL_BAD_ALLOC, EGL_FALSE);