gfx: extract GPU timing code from main.c

Just a bit of refactoring.
gfx: count the # of rendered primitives

Doesn't seem to work for the integrated intel card, even though it
advertises 32 bits of precision for GL_PRIMITIVES_RENDERED, it always
returns 0. At first I thought it was a flaw in my code but it works fine on
the discrete radeon.