opengles emulator: added FPS statistics printout

Make the renderer print FPS statistics every 1 second.
Need to set SHOW_FPS_STATS=1

Change-Id: I69e8c43a779e685ae0b34974d1ef33ad75e7a7e4
diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp b/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp
index 50ee9cb..a670136 100644
--- a/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp
+++ b/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp
@@ -21,6 +21,7 @@
 #include "GL2Dispatch.h"
 #include "ThreadInfo.h"
 #include <stdio.h>
+#include "TimeUtils.h"
 
 FrameBuffer *FrameBuffer::s_theFrameBuffer = NULL;
 HandleType FrameBuffer::s_nextHandle = 0;
@@ -352,8 +353,11 @@
     m_prevReadSurf(EGL_NO_SURFACE),
     m_prevDrawSurf(EGL_NO_SURFACE),
     m_subWin(NULL),
-    m_subWinDisplay(NULL)
+    m_subWinDisplay(NULL),
+    m_statsNumFrames(0),
+    m_statsStartTime(0LL)
 {
+    m_fpsStats = getenv("SHOW_FPS_STATS") != NULL;
 }
 
 FrameBuffer::~FrameBuffer()
@@ -653,6 +657,21 @@
         }
         ret = (*c).second->post();
         if (ret) {
+
+            //
+            // output FPS statistics
+            //
+            if (m_fpsStats) {
+                long long currTime = GetCurrentTimeMS();
+                m_statsNumFrames++;
+                if (currTime - m_statsStartTime >= 1000) {
+                    float dt = (float)(currTime - m_statsStartTime) / 1000.0f;
+                    printf("FPS: %5.3f\n", (float)m_statsNumFrames / dt);
+                    m_statsStartTime = currTime;
+                    m_statsNumFrames = 0;
+                }
+            }
+
             s_egl.eglSwapBuffers(m_eglDisplay, m_eglSurface);
         }
         unbind_locked();
diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.h b/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.h
index d2e7730..cfefcee 100644
--- a/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.h
+++ b/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.h
@@ -106,5 +106,9 @@
     EGLSurface m_prevDrawSurf;
     EGLNativeWindowType m_subWin;
     EGLNativeDisplayType m_subWinDisplay;
+
+    int m_statsNumFrames;
+    long long m_statsStartTime;
+    bool m_fpsStats;
 };
 #endif