Mercurial > hg > svgui
diff layer/RenderTimer.h @ 1324:13d9b422f7fe zoom
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 17 Sep 2018 13:51:31 +0100 |
parents | a34a2a25907c |
children |
line wrap: on
line diff
--- a/layer/RenderTimer.h Mon Dec 12 15:18:52 2016 +0000 +++ b/layer/RenderTimer.h Mon Sep 17 13:51:31 2018 +0100 @@ -21,16 +21,16 @@ { public: enum Type { - /// A normal rendering operation with normal responsiveness demands - FastRender, + /// A normal rendering operation with normal responsiveness demands + FastRender, - /// An operation that the user might accept being slower - SlowRender, + /// An operation that the user might accept being slower + SlowRender, - /// An operation that should always complete, i.e. as if there - /// were no RenderTimer in use, but without having to change - /// client code structurally - NoTimeout + /// An operation that should always complete, i.e. as if there + /// were no RenderTimer in use, but without having to change + /// client code structurally + NoTimeout }; /** @@ -41,19 +41,19 @@ * happened. */ RenderTimer(Type t) : - m_start(std::chrono::steady_clock::now()), - m_haveLimits(true), - m_minFraction(0.1), - m_softLimit(0.1), - m_hardLimit(0.2), - m_softLimitOverridden(false) { + m_start(std::chrono::steady_clock::now()), + m_haveLimits(true), + m_minFraction(0.1), + m_softLimit(0.1), + m_hardLimit(0.2), + m_softLimitOverridden(false) { - if (t == NoTimeout) { - m_haveLimits = false; - } else if (t == SlowRender) { - m_softLimit = 0.2; - m_hardLimit = 0.4; - } + if (t == NoTimeout) { + m_haveLimits = false; + } else if (t == SlowRender) { + m_softLimit = 0.2; + m_hardLimit = 0.4; + } } @@ -66,36 +66,46 @@ */ bool outOfTime(double fractionComplete) { - if (!m_haveLimits || fractionComplete < m_minFraction) { - return false; - } - - auto t = std::chrono::steady_clock::now(); - double elapsed = std::chrono::duration<double>(t - m_start).count(); - - if (elapsed > m_hardLimit) { - return true; - } else if (!m_softLimitOverridden && elapsed > m_softLimit) { - if (fractionComplete > 0.6) { - // If we're significantly more than half way by the - // time we reach the soft limit, ignore it (though - // always respect the hard limit, above). Otherwise - // respect the soft limit and report out of time now. - m_softLimitOverridden = true; - } else { - return true; - } - } + if (!m_haveLimits || fractionComplete < m_minFraction) { + return false; + } + + auto t = std::chrono::steady_clock::now(); + double elapsed = std::chrono::duration<double>(t - m_start).count(); + + if (elapsed > m_hardLimit) { + return true; + } else if (!m_softLimitOverridden && elapsed > m_softLimit) { + if (fractionComplete > 0.6) { + // If we're significantly more than half way by the + // time we reach the soft limit, ignore it (though + // always respect the hard limit, above). Otherwise + // respect the soft limit and report out of time now. + m_softLimitOverridden = true; + } else { + return true; + } + } - return false; + return false; + } + + double secondsPerItem(int itemsRendered) const { + + if (itemsRendered == 0) return 0.0; + + auto t = std::chrono::steady_clock::now(); + double elapsed = std::chrono::duration<double>(t - m_start).count(); + + return elapsed / itemsRendered; } private: std::chrono::time_point<std::chrono::steady_clock> m_start; bool m_haveLimits; - double m_minFraction; - double m_softLimit; - double m_hardLimit; + double m_minFraction; // proportion, 0.0 -> 1.0 + double m_softLimit; // seconds + double m_hardLimit; // seconds bool m_softLimitOverridden; };