[Mesa-dev] [PATCH] glx/dri3: Port LIBGL_SHOW_FPS=1 code from DRI2 to DRI3.
Kenneth Graunke
kenneth at whitecape.org
Tue Oct 28 00:09:24 PDT 2014
The code is cut-and-pasted from dri2_glx.c; we can't quite share it
because we have to use different structures.
Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Cc: Keith Packard <keithp at keithp.com>
---
src/glx/dri3_glx.c | 35 ++++++++++++++++++++++++++++++++++-
src/glx/dri3_priv.h | 6 +++++-
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c
index e8e5c4a..183b2c0 100644
--- a/src/glx/dri3_glx.c
+++ b/src/glx/dri3_glx.c
@@ -1474,6 +1474,30 @@ static const __DRIextension *loader_extensions[] = {
NULL
};
+static void
+show_fps(struct dri3_drawable *draw)
+{
+ const int interval =
+ ((struct dri3_screen *) draw->base.psc)->show_fps_interval;
+ struct timeval tv;
+ uint64_t current_time;
+
+ gettimeofday(&tv, 0);
+ current_time = (uint64_t) tv.tv_sec * 1000000 + (uint64_t) tv.tv_usec;
+
+ draw->frames++;
+
+ if (draw->previous_time + interval * 1000000 <= current_time) {
+ if (draw->previous_time) {
+ fprintf(stderr, "libGL: FPS = %.1f\n",
+ ((uint64_t)draw->frames * 1000000) /
+ (double)(current_time - draw->previous_time));
+ }
+ draw->frames = 0;
+ draw->previous_time = current_time;
+ }
+}
+
/** dri3_swap_buffers
*
* Make the current back buffer visible using the present extension
@@ -1568,6 +1592,10 @@ dri3_swap_buffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
(*psc->f->invalidate)(priv->driDrawable);
+ if (psc->show_fps_interval) {
+ show_fps(priv);
+ }
+
return ret;
}
@@ -1830,7 +1858,7 @@ dri3_create_screen(int screen, struct glx_display * priv)
struct dri3_screen *psc;
__GLXDRIscreen *psp;
struct glx_config *configs = NULL, *visuals = NULL;
- char *driverName, *deviceName;
+ char *driverName, *deviceName, *tmp;
int i;
psc = calloc(1, sizeof *psc);
@@ -1969,6 +1997,11 @@ dri3_create_screen(int screen, struct glx_display * priv)
free(driverName);
free(deviceName);
+ tmp = getenv("LIBGL_SHOW_FPS");
+ psc->show_fps_interval = tmp ? atoi(tmp) : 0;
+ if (psc->show_fps_interval < 0)
+ psc->show_fps_interval = 0;
+
return &psc->base;
handle_error:
diff --git a/src/glx/dri3_priv.h b/src/glx/dri3_priv.h
index bdfe224..2bd5a4d 100644
--- a/src/glx/dri3_priv.h
+++ b/src/glx/dri3_priv.h
@@ -138,7 +138,7 @@ struct dri3_screen {
int fd;
int is_different_gpu;
- Bool show_fps;
+ int show_fps_interval;
};
struct dri3_context
@@ -198,6 +198,10 @@ struct dri3_drawable {
xcb_present_event_t eid;
xcb_gcontext_t gc;
xcb_special_event_t *special_event;
+
+ /* LIBGL_SHOW_FPS support */
+ uint64_t previous_time;
+ unsigned frames;
};
--
2.1.2
More information about the mesa-dev
mailing list