[Mesa-dev] [PATCH] glx/dri2: print FPS when env var MESA_SHOW_FPS is 1
Marek Olšák
maraeo at gmail.com
Tue Jan 3 21:05:09 PST 2012
This is useful for apps which don't print FPS.
Only enabled in SwapBuffers.
---
src/glx/dri2_glx.c | 36 +++++++++++++++++++++++++++++++++++-
1 files changed, 35 insertions(+), 1 deletions(-)
diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index a9bcebf..394823a 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -43,6 +43,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
+#include <sys/time.h>
#include "xf86drm.h"
#include "dri2.h"
#include "dri_common.h"
@@ -90,12 +91,17 @@ struct dri2_screen {
void *driver;
int fd;
+
+ Bool show_fps;
};
struct dri2_context
{
struct glx_context base;
__DRIcontext *driContext;
+
+ double previous_time;
+ unsigned frames;
};
struct dri2_drawable
@@ -576,6 +582,26 @@ unsigned dri2GetSwapEventType(Display* dpy, XID drawable)
return glx_dpy->codes->first_event + GLX_BufferSwapComplete;
}
+static void show_fps()
+{
+ struct glx_context *gc = __glXGetCurrentContext();
+ struct dri2_context *ctx = (struct dri2_context *)gc;
+ struct timeval tv;
+ double current_time;
+
+ gettimeofday(&tv, 0);
+ current_time = (double)tv.tv_sec + (double)tv.tv_usec * 0.000001;
+
+ ctx->frames++;
+
+ if (ctx->previous_time + 1 < current_time) {
+ fprintf(stderr, "Mesa: FPS = %.1f\n",
+ ctx->frames / (current_time - ctx->previous_time));
+ ctx->frames = 0;
+ ctx->previous_time = current_time;
+ }
+}
+
static int64_t
dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
int64_t remainder)
@@ -611,9 +637,14 @@ dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
DRI2SwapBuffers(psc->base.dpy, pdraw->xDrawable,
target_msc, divisor, remainder, &ret);
+
#endif
}
+ if (psc->show_fps) {
+ show_fps();
+ }
+
/* Old servers don't send invalidate events */
if (!pdp->invalidateAvailable)
dri2InvalidateBuffers(dpyPriv->dpy, pdraw->xDrawable);
@@ -870,7 +901,7 @@ dri2CreateScreen(int screen, struct glx_display * priv)
struct dri2_screen *psc;
__GLXDRIscreen *psp;
struct glx_config *configs = NULL, *visuals = NULL;
- char *driverName, *deviceName;
+ char *driverName, *deviceName, *tmp;
drm_magic_t magic;
int i;
@@ -1002,6 +1033,9 @@ dri2CreateScreen(int screen, struct glx_display * priv)
Xfree(driverName);
Xfree(deviceName);
+ tmp = getenv("MESA_SHOW_FPS");
+ psc->show_fps = tmp && strcmp(tmp, "1") == 0;
+
return &psc->base;
handle_error:
--
1.7.4.1
More information about the mesa-dev
mailing list