EmuGL: enable SurfaceTexture async mode

Pass the swap interval from eglSwapInterval to the native window so it
can enable/disable SurfaceTexture's async mode. Fixes the deadlock in
SurfaceTextureGLToGLTest.EglDestroySurfaceUnrefsBuffers.

Change-Id: I19bf69247341f5617223722df63d6c7f8cf389c6
diff --git a/tools/emulator/opengl/system/egl/egl.cpp b/tools/emulator/opengl/system/egl/egl.cpp
index 2ca3e3b..e949b96 100644
--- a/tools/emulator/opengl/system/egl/egl.cpp
+++ b/tools/emulator/opengl/system/egl/egl.cpp
@@ -180,6 +180,7 @@
 
     virtual     EGLBoolean  connect() { return EGL_TRUE; }
     virtual     void        disconnect() {}
+    virtual     void        setSwapInterval(int interval) = 0;
     virtual     EGLBoolean     swapBuffers() { return EGL_TRUE; }
     virtual     EGLint        getSwapBehavior() const;
 
@@ -248,6 +249,7 @@
 
     virtual     EGLBoolean  connect();
     virtual     void        disconnect();
+    virtual     void        setSwapInterval(int interval);
     virtual     EGLBoolean  swapBuffers();
 
 private:
@@ -327,6 +329,11 @@
     }
 }
 
+void egl_window_surface_t::setSwapInterval(int interval)
+{
+    nativeWindow->setSwapInterval(nativeWindow, interval);
+}
+
 EGLBoolean egl_window_surface_t::swapBuffers()
 {
     if (!buffer) {
@@ -369,6 +376,7 @@
     virtual     EGLBoolean     rcDestroy();
 
     virtual     EGLBoolean    connect();
+    virtual     void          setSwapInterval(int interval) {}
 
     uint32_t    getRcColorBuffer(){ return rcColorBuffer; }
     void         setRcColorBuffer(uint32_t colorBuffer){ rcColorBuffer = colorBuffer; }
@@ -871,9 +879,20 @@
 EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval)
 {
     VALIDATE_DISPLAY_INIT(dpy, EGL_FALSE);
-
     DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE);
+
+    EGLContext_t* ctx = getEGLThreadInfo()->currentContext;
+    if (!ctx) {
+        setErrorReturn(EGL_BAD_CONTEXT, EGL_FALSE);
+    }
+    if (!ctx->draw) {
+        setErrorReturn(EGL_BAD_SURFACE, EGL_FALSE);
+    }
+    egl_surface_t* draw(static_cast<egl_surface_t*>(ctx->draw));
+    draw->setSwapInterval(interval);
+
     rcEnc->rcFBSetSwapInterval(rcEnc, interval); //TODO: implement on the host
+
     return EGL_TRUE;
 }