TextureMapperFPSCounter.cpp [plain text]
#include "config.h"
#include "TextureMapperFPSCounter.h"
#include "TextureMapper.h"
#include <wtf/text/WTFString.h>
namespace WebCore {
TextureMapperFPSCounter::TextureMapperFPSCounter()
: m_isShowingFPS(false)
, m_fpsInterval(0_s)
, m_lastFPS(0)
, m_frameCount(0)
{
String showFPSEnvironment = getenv("WEBKIT_SHOW_FPS");
bool ok = false;
m_fpsInterval = Seconds(showFPSEnvironment.toDouble(&ok));
if (ok && m_fpsInterval) {
m_isShowingFPS = true;
m_fpsTimestamp = MonotonicTime::now();
}
}
void TextureMapperFPSCounter::updateFPSAndDisplay(TextureMapper& textureMapper, const FloatPoint& location, const TransformationMatrix& matrix)
{
if (!m_isShowingFPS)
return;
m_frameCount++;
Seconds delta = MonotonicTime::now() - m_fpsTimestamp;
if (delta >= m_fpsInterval) {
m_lastFPS = int(m_frameCount / delta.seconds());
m_frameCount = 0;
m_fpsTimestamp += delta;
}
textureMapper.drawNumber(m_lastFPS, Color::black, location, matrix);
}
}