Add support for basic GPU profiling of draw calls to retrace.

Currently only supports opengl using glBegin/EndQuery and glQueryCounter.

Based on code from Yuanhan Liu timing-trace branch.
Improved GPU profiling code.

Now only allows a certain number of active queries,
this fixes results with applications that have many draw calls.
Fixed gpu profiling under multiple contexts.

Now flushes the results for all queries on context switch.
Added support for recording GL_SAMPLES_PASSED.
Improved profiling capabilities.

Logs which shader is active to allow per shader profiling.
Merged cpu profiling code from retrace to trace_profiler.
Allow choice of profiling for gpu / cpu / pixels drawn.
Add a script to analyse profile output per shader.
Retrace should info correct image's format to qapitrace.

Signed-off-by: José Fonseca <jose.r.fonseca@gmail.com>
egl: EGL image trace support

Getting the dimension / format of EGL images is not straitghforward.
One way to get these would be through glGetTexLevelParameter, but it's
not supported by GLES. Another way is to attach the EGL image to a
renderbuffer and call glGetRenderbufferParameter on it, but at least
mesa doesn't support attaching images in RGBA_REV format. And that
format happens to be an important one in applications we care about
(like the Android browser). We could also check the parameters of the
underlying native buffer, but these are not exposed through any API (for
either Xpixmaps or Android native buffers)

So the only way I found is to try a non-destructive glCopyTexSubImage2D
with sizes starting from GL_MAX_TEXTURE_SIZE down to 1 and determine the
correct size based on whether this returns an error or not.

Signed-off-by: Imre Deak <imre.deak@intel.com>
Emit a fake glTexImage for glEGLImageTargetTexture2DOES.
Check if GL_ARB_timer_query is supported before using it.
Fixed bug in CPU profiling.
Cleaned up trace profiler output.

Updated profileshader.py to reflect these changes.
Removed arbitary limit on active queries.

This previously existed due to a suspected limit on queries on nvidia drivers,
however that bug was actually due to context switching which has now been fixed.
Avoid inserting 'inf' and friends into the json output.

The JSON-generating code was previously carefult to avoid emitting NaN
into its output, but it would still write "inf" for an infinite value,
(which is invalid JSON).

Fix by calling writeNull for any value for which std::isfinite returns
false, (rather than the previous test for merely (n != n)).
Recognize for context creation/destruction/binding functions (issue #90).

Thanks to gregory38 for spotting this.
Add missing comma in last commit.
Remove old unused function declaration.
Resize window on IDirect3DDevice9::Reset.
Process window events on d3dretrace.
Recreate egl surface when glViewport for watching framebuffer in qapitrace's surface tab.

It is quirk of mesa egl 1.4 with Nvidia-dri. It is ok with intel-dri.

After resizing XWindow, mesa egl does not know new size of the surface.
If you call eglQuerySurface(currentDisplay, currentSurface, EGL_WIDTH, width),
width is the width at the time to create the egl surface, not current width.
However, glx can know what the size of window well.

Signed-off-by: José Fonseca <jose.r.fonseca@gmail.com>