1/*
2    Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
3    Copyright (C) 2012, 2013 Company 100, Inc.
4    Copyright (C) 2012, 2013 basysKom GmbH
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Library General Public
8    License as published by the Free Software Foundation; either
9    version 2 of the License, or (at your option) any later version.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Library General Public License for more details.
15
16    You should have received a copy of the GNU Library General Public License
17    along with this library; see the file COPYING.LIB.  If not, write to
18    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19    Boston, MA 02110-1301, USA.
20*/
21
22#include "config.h"
23
24#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
25
26#include "TextureMapperFPSCounter.h"
27
28#include "TextureMapper.h"
29#include <wtf/CurrentTime.h>
30
31namespace WebCore {
32
33TextureMapperFPSCounter::TextureMapperFPSCounter()
34    : m_isShowingFPS(false)
35    , m_fpsInterval(0)
36    , m_fpsTimestamp(0)
37    , m_lastFPS(0)
38    , m_frameCount(0)
39{
40    String showFPSEnvironment = getenv("WEBKIT_SHOW_FPS");
41    bool ok = false;
42    m_fpsInterval = showFPSEnvironment.toDouble(&ok);
43    if (ok && m_fpsInterval) {
44        m_isShowingFPS = true;
45        m_fpsTimestamp = WTF::currentTime();
46    }
47}
48
49void TextureMapperFPSCounter::updateFPSAndDisplay(TextureMapper* textureMapper, const FloatPoint& location, const TransformationMatrix& matrix)
50{
51    if (!m_isShowingFPS)
52        return;
53
54    m_frameCount++;
55    double delta = WTF::currentTime() - m_fpsTimestamp;
56    if (delta >= m_fpsInterval) {
57        m_lastFPS = int(m_frameCount / delta);
58        m_frameCount = 0;
59        m_fpsTimestamp += delta;
60    }
61
62    textureMapper->drawNumber(m_lastFPS, Color::black, location, matrix);
63}
64
65} // namespace WebCore
66
67#endif // USE(ACCELERATED_COMPOSITING)
68