1 /* fps, Copyright (c) 2001-2015 Jamie Zawinski <jwz@jwz.org>
2 * Draw a frames-per-second display (Xlib and OpenGL).
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
15 #endif /* HAVE_CONFIG_H */
19 #elif defined(HAVE_ANDROID)
24 #endif /* !HAVE_COCOA */
28 #endif /* HAVE_JWZGLES */
30 #include "xlockmoreI.h"
34 /* These are in xlock-gl.c */
35 extern void clear_gl_error (void);
36 extern void check_gl_error (const char *type);
39 texture_font_data *texfont;
46 xlockmore_gl_fps_init (fps_state *st)
48 gl_fps_data *data = (gl_fps_data *) calloc (1, sizeof(*data));
50 data->top_p = get_boolean_resource (st->dpy, "fpsTop", "FPSTop");
51 data->texfont = load_texture_font (st->dpy, "fpsFont");
52 texture_string_metrics (data->texfont, "M", 0, &ascent, &descent);
53 data->line_height = ascent + descent;
54 st->gl_fps_data = data;
58 /* Callback in xscreensaver_function_table, via xlockmore.c.
61 xlockmore_gl_compute_fps (Display *dpy, Window w, fps_state *fpst,
64 ModeInfo *mi = (ModeInfo *) closure;
68 xlockmore_gl_fps_init (fpst);
71 fps_compute (fpst, mi->polygon_count, mi->recursion_depth);
75 /* Called directly from GL programs (as `do_fps') before swapping buffers.
78 xlockmore_gl_draw_fps (ModeInfo *mi)
80 fps_state *st = mi->fpst;
81 if (st) /* might be too early */
83 gl_fps_data *data = (gl_fps_data *) st->gl_fps_data;
84 XWindowAttributes xgwa;
88 XGetWindowAttributes (st->dpy, st->window, &xgwa);
89 for (s = st->string; *s; s++)
90 if (*s == '\n') lines++;
93 print_texture_label (st->dpy, data->texfont,
94 xgwa.width, xgwa.height,
95 (data->top_p ? 1 : 2),