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 | #include "TextureMapperFPSCounter.h" |
25 | |
26 | #include "TextureMapper.h" |
27 | #include <wtf/text/WTFString.h> |
28 | |
29 | namespace WebCore { |
30 | |
31 | TextureMapperFPSCounter::TextureMapperFPSCounter() |
32 | : m_isShowingFPS(false) |
33 | , m_fpsInterval(0_s) |
34 | , m_lastFPS(0) |
35 | , m_frameCount(0) |
36 | { |
37 | String showFPSEnvironment = getenv("WEBKIT_SHOW_FPS" ); |
38 | bool ok = false; |
39 | m_fpsInterval = Seconds(showFPSEnvironment.toDouble(&ok)); |
40 | if (ok && m_fpsInterval) { |
41 | m_isShowingFPS = true; |
42 | m_fpsTimestamp = MonotonicTime::now(); |
43 | } |
44 | } |
45 | |
46 | void TextureMapperFPSCounter::updateFPSAndDisplay(TextureMapper& textureMapper, const FloatPoint& location, const TransformationMatrix& matrix) |
47 | { |
48 | if (!m_isShowingFPS) |
49 | return; |
50 | |
51 | m_frameCount++; |
52 | Seconds delta = MonotonicTime::now() - m_fpsTimestamp; |
53 | if (delta >= m_fpsInterval) { |
54 | m_lastFPS = int(m_frameCount / delta.seconds()); |
55 | m_frameCount = 0; |
56 | m_fpsTimestamp += delta; |
57 | } |
58 | |
59 | textureMapper.drawNumber(m_lastFPS, Color::black, location, matrix); |
60 | } |
61 | |
62 | } // namespace WebCore |
63 | |