Merge "opengles emulator: added FPS statistics printout"

This commit is contained in:
David Turner
2011-08-13 15:43:11 -07:00
committed by Android Code Review
2 changed files with 24 additions and 1 deletions

View File

@@ -21,6 +21,7 @@
#include "GL2Dispatch.h" #include "GL2Dispatch.h"
#include "ThreadInfo.h" #include "ThreadInfo.h"
#include <stdio.h> #include <stdio.h>
#include "TimeUtils.h"
FrameBuffer *FrameBuffer::s_theFrameBuffer = NULL; FrameBuffer *FrameBuffer::s_theFrameBuffer = NULL;
HandleType FrameBuffer::s_nextHandle = 0; HandleType FrameBuffer::s_nextHandle = 0;
@@ -352,8 +353,11 @@ FrameBuffer::FrameBuffer(int p_x, int p_y, int p_width, int p_height) :
m_prevReadSurf(EGL_NO_SURFACE), m_prevReadSurf(EGL_NO_SURFACE),
m_prevDrawSurf(EGL_NO_SURFACE), m_prevDrawSurf(EGL_NO_SURFACE),
m_subWin(NULL), m_subWin(NULL),
m_subWinDisplay(NULL) m_subWinDisplay(NULL),
m_statsNumFrames(0),
m_statsStartTime(0LL)
{ {
m_fpsStats = getenv("SHOW_FPS_STATS") != NULL;
} }
FrameBuffer::~FrameBuffer() FrameBuffer::~FrameBuffer()
@@ -653,6 +657,21 @@ bool FrameBuffer::post(HandleType p_colorbuffer)
} }
ret = (*c).second->post(); ret = (*c).second->post();
if (ret) { 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); s_egl.eglSwapBuffers(m_eglDisplay, m_eglSurface);
} }
unbind_locked(); unbind_locked();

View File

@@ -106,5 +106,9 @@ private:
EGLSurface m_prevDrawSurf; EGLSurface m_prevDrawSurf;
EGLNativeWindowType m_subWin; EGLNativeWindowType m_subWin;
EGLNativeDisplayType m_subWinDisplay; EGLNativeDisplayType m_subWinDisplay;
int m_statsNumFrames;
long long m_statsStartTime;
bool m_fpsStats;
}; };
#endif #endif