1 /* fps, Copyright (c) 2001-2014 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 #else /* !HAVE_COCOA -- real Xlib */
22 #endif /* !HAVE_COCOA */
26 #endif /* HAVE_JWZGLES */
28 #include "xlockmoreI.h"
32 /* These are in xlock-gl.c */
33 extern void clear_gl_error (void);
34 extern void check_gl_error (const char *type);
38 xlockmore_gl_fps_init (fps_state *st)
40 st->gl_fps_data = load_texture_font (st->dpy, "fpsFont");
45 /* Callback in xscreensaver_function_table, via xlockmore.c.
48 xlockmore_gl_compute_fps (Display *dpy, Window w, fps_state *fpst,
51 ModeInfo *mi = (ModeInfo *) closure;
55 xlockmore_gl_fps_init (fpst);
58 fps_compute (fpst, mi->polygon_count, mi->recursion_depth);
62 /* Called directly from GL programs (as `do_fps') before swapping buffers.
65 xlockmore_gl_draw_fps (ModeInfo *mi)
67 fps_state *st = mi->fpst;
68 if (st) /* might be too early */
70 XWindowAttributes xgwa;
73 int lh = st->font->ascent + st->font->descent;
76 XGetWindowAttributes (st->dpy, st->window, &xgwa);
77 for (s = st->string; *s; s++)
78 if (*s == '\n') lines++;
81 y = xgwa.height + y - lines*lh;
82 y += lines*lh + st->font->descent;
85 print_gl_string (st->dpy, st->gl_fps_data,
86 xgwa.width, xgwa.height,
87 st->x, y, st->string, st->clear_p);