Implement X11 onscreen framerate counter.

This FPS counter is disabled by default.

Change-Id: Ida04352dece25a212cb678c9ceca4c31d654f373
Reviewed-on: https://swiftshader-review.googlesource.com/12128
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Main/FrameBufferX11.cpp b/src/Main/FrameBufferX11.cpp
index a065198..36ba38f 100644
--- a/src/Main/FrameBufferX11.cpp
+++ b/src/Main/FrameBufferX11.cpp
@@ -15,6 +15,7 @@
 #include "FrameBufferX11.hpp"
 
 #include "libX11.hpp"
+#include "Timer.hpp"
 
 #include <sys/ipc.h>
 #include <sys/shm.h>
@@ -140,6 +141,30 @@
 		}
 
 		libX11->XSync(x_display, False);
+
+		if(false)   // Draw the framerate on screen
+		{
+			static double fpsTime = sw::Timer::seconds();
+			static int framesSec = 0;
+
+			double time = sw::Timer::seconds();
+			double delta = time - fpsTime;
+			framesSec++;
+
+			static double FPS = 0.0;
+
+			if(delta > 1.0)
+			{
+				FPS = framesSec / delta;
+
+				fpsTime = time;
+				framesSec = 0;
+			}
+
+			char string[256];
+			sprintf(string, "FPS: %.1f", FPS);
+			libX11->XDrawString(x_display, x_window, x_gc, 50, 50, string, strlen(string));
+		}
 	}
 }