glx/dri2: print FPS when env var LIBGL_SHOW_FPS is 1 (v2)
This is useful for apps which don't print FPS. Only enabled in SwapBuffers. v2: track state per drawable, use libGL prefix Reviewed-by: Michel Dänzer <michel@daenzer.net>
This commit is contained in:
@@ -43,6 +43,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include "xf86drm.h"
|
#include "xf86drm.h"
|
||||||
#include "dri2.h"
|
#include "dri2.h"
|
||||||
#include "dri_common.h"
|
#include "dri_common.h"
|
||||||
@@ -90,6 +91,8 @@ struct dri2_screen {
|
|||||||
|
|
||||||
void *driver;
|
void *driver;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
Bool show_fps;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct dri2_context
|
struct dri2_context
|
||||||
@@ -108,6 +111,9 @@ struct dri2_drawable
|
|||||||
int have_back;
|
int have_back;
|
||||||
int have_fake_front;
|
int have_fake_front;
|
||||||
int swap_interval;
|
int swap_interval;
|
||||||
|
|
||||||
|
double previous_time;
|
||||||
|
unsigned frames;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct glx_context_vtable dri2_context_vtable;
|
static const struct glx_context_vtable dri2_context_vtable;
|
||||||
@@ -661,6 +667,26 @@ unsigned dri2GetSwapEventType(Display* dpy, XID drawable)
|
|||||||
return glx_dpy->codes->first_event + GLX_BufferSwapComplete;
|
return glx_dpy->codes->first_event + GLX_BufferSwapComplete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void show_fps(struct dri2_drawable *draw)
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
double current_time;
|
||||||
|
|
||||||
|
gettimeofday(&tv, 0);
|
||||||
|
current_time = (double)tv.tv_sec + (double)tv.tv_usec * 0.000001;
|
||||||
|
|
||||||
|
draw->frames++;
|
||||||
|
|
||||||
|
if (draw->previous_time + 1 < current_time) {
|
||||||
|
if (draw->previous_time) {
|
||||||
|
fprintf(stderr, "libGL: FPS = %.1f\n",
|
||||||
|
draw->frames / (current_time - draw->previous_time));
|
||||||
|
}
|
||||||
|
draw->frames = 0;
|
||||||
|
draw->previous_time = current_time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int64_t
|
static int64_t
|
||||||
dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
|
dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
|
||||||
int64_t remainder)
|
int64_t remainder)
|
||||||
@@ -699,6 +725,10 @@ dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (psc->show_fps) {
|
||||||
|
show_fps(priv);
|
||||||
|
}
|
||||||
|
|
||||||
/* Old servers don't send invalidate events */
|
/* Old servers don't send invalidate events */
|
||||||
if (!pdp->invalidateAvailable)
|
if (!pdp->invalidateAvailable)
|
||||||
dri2InvalidateBuffers(dpyPriv->dpy, pdraw->xDrawable);
|
dri2InvalidateBuffers(dpyPriv->dpy, pdraw->xDrawable);
|
||||||
@@ -967,7 +997,7 @@ dri2CreateScreen(int screen, struct glx_display * priv)
|
|||||||
struct dri2_screen *psc;
|
struct dri2_screen *psc;
|
||||||
__GLXDRIscreen *psp;
|
__GLXDRIscreen *psp;
|
||||||
struct glx_config *configs = NULL, *visuals = NULL;
|
struct glx_config *configs = NULL, *visuals = NULL;
|
||||||
char *driverName, *deviceName;
|
char *driverName, *deviceName, *tmp;
|
||||||
drm_magic_t magic;
|
drm_magic_t magic;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -1099,6 +1129,9 @@ dri2CreateScreen(int screen, struct glx_display * priv)
|
|||||||
Xfree(driverName);
|
Xfree(driverName);
|
||||||
Xfree(deviceName);
|
Xfree(deviceName);
|
||||||
|
|
||||||
|
tmp = getenv("LIBGL_SHOW_FPS");
|
||||||
|
psc->show_fps = tmp && strcmp(tmp, "1") == 0;
|
||||||
|
|
||||||
return &psc->base;
|
return &psc->base;
|
||||||
|
|
||||||
handle_error:
|
handle_error:
|
||||||
|
Reference in New Issue
Block a user