diff --git a/libs/global/CMakeLists.txt b/libs/global/CMakeLists.txt index 9dbbc2a819..441d87d157 100644 --- a/libs/global/CMakeLists.txt +++ b/libs/global/CMakeLists.txt @@ -1,56 +1,55 @@ add_subdirectory( tests ) include(CheckFunctionExists) check_function_exists(backtrace HAVE_BACKTRACE) configure_file(config-debug.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-debug.h) option(HAVE_MEMORY_LEAK_TRACKER "Enable memory leak tracker (always disabled in release build)" OFF) option(HAVE_BACKTRACE_SUPPORT "Enable recording of backtrace in memory leak tracker" OFF) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-memory-leak-tracker.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-memory-leak-tracker.h) ### WRONG PLACE??? set(kritaglobal_LIB_SRCS kis_assert.cpp kis_debug.cpp kis_algebra_2d.cpp kis_memory_leak_tracker.cpp kis_shared.cpp kis_dom_utils.cpp kis_painting_tweaks.cpp KisHandlePainterHelper.cpp KisHandleStyle.cpp - kis_relaxed_timer.cpp kis_signal_compressor.cpp kis_signal_compressor_with_param.cpp kis_thread_safe_signal_compressor.cpp kis_acyclic_signal_connector.cpp kis_latency_tracker.cpp KisQPainterStateSaver.cpp KisSharedThreadPoolAdapter.cpp KisSharedRunnable.cpp KisRollingMeanAccumulatorWrapper.cpp kis_config_notifier.cpp KisDeleteLaterWrapper.cpp KisUsageLogger.cpp KisFileUtils.cpp ) add_library(kritaglobal SHARED ${kritaglobal_LIB_SRCS} ) generate_export_header(kritaglobal BASE_NAME kritaglobal) target_link_libraries(kritaglobal PUBLIC kritaversion Qt5::Concurrent Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Xml KF5::I18n ) set_target_properties(kritaglobal PROPERTIES VERSION ${GENERIC_KRITA_LIB_VERSION} SOVERSION ${GENERIC_KRITA_LIB_SOVERSION} ) install(TARGETS kritaglobal ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/libs/global/kis_relaxed_timer.cpp b/libs/global/kis_relaxed_timer.cpp deleted file mode 100644 index 70a0d70c99..0000000000 --- a/libs/global/kis_relaxed_timer.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2017 Bernhard Liebl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "kis_relaxed_timer.h" -#include "kis_assert.h" - -KisRelaxedTimer::KisRelaxedTimer(QObject *parent) - : QObject(parent) - , m_interval(0) - , m_singleShot(false) - , m_nextTimerTickSeqNo(1) - , m_emitOnTimeTick(0) - , m_isEmitting(false) -{ -} - -void KisRelaxedTimer::setInterval(int interval) -{ - KIS_SAFE_ASSERT_RECOVER(!isActive()) { - this->stop(); - } - - m_interval = interval; -} - -void KisRelaxedTimer::setSingleShot(bool singleShot) -{ - m_singleShot = singleShot; -} - -int KisRelaxedTimer::remainingTime() const -{ - // in contrast to normal QTimers, the remaining time is calculated in - // terms of 2 * m_interval as this is the worst case interval. - - if (!isActive()) { - return -1; - } else { - return qMax(qint64(0), 2 * m_interval - qint64(m_elapsed.elapsed())); - } -} - -void KisRelaxedTimer::start() -{ - m_elapsed.start(); - - // cancels any previously scheduled timer and schedules a new timer to be - // triggered as soon as possible, but never sooner than \p m_interval ms. - - if (!m_timer.isActive()) { - // no internal timer is running. start one, and configure it to send - // us a timeout event on the next possible tick which will be exactly - // \p m_interval ms in the future. - - m_emitOnTimeTick = m_nextTimerTickSeqNo; - m_timer.start(m_interval, this); - } else if (m_isEmitting) { - // an internal timer is running and we are actually called from a - // timeout event. so we know the next tick will happen in exactly - // \p m_interval ms. - - m_emitOnTimeTick = m_nextTimerTickSeqNo; - } else { - // an internal timer is already running, but we do not know when - // the next tick will happen. we need to skip next tick as it - // will be sooner than m_delay. the one after that will be good as - // it will be m_interval * (1 + err) in the future. - - m_emitOnTimeTick = m_nextTimerTickSeqNo + 1; - } -} - -void KisRelaxedTimer::timerEvent(QTimerEvent *event) -{ - Q_UNUSED(event); - - const int ticksStopThreshold = 5; - - const qint64 timerTickSeqNo = m_nextTimerTickSeqNo; - - // from this point on, if this is an emit tick, we are no longer active. - m_nextTimerTickSeqNo++; - - if (timerTickSeqNo == m_emitOnTimeTick) { - if (m_singleShot) { - stop(); - } - const IsEmitting emitting(*this); - emit timeout(); - } else if (timerTickSeqNo - m_emitOnTimeTick > ticksStopThreshold) { - m_timer.stop(); - } -} diff --git a/libs/global/kis_relaxed_timer.h b/libs/global/kis_relaxed_timer.h deleted file mode 100644 index 01a9356ce6..0000000000 --- a/libs/global/kis_relaxed_timer.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2017 Bernhard Liebl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef __KIS_RELAXED_TIMER_H -#define __KIS_RELAXED_TIMER_H - -#include -#include -#include - -#include "kritaglobal_export.h" - -/** - * A timer using an interface like QTimer that relaxes the given interval callback - * time guarantees and minimizes internal timer restarts by keeping one long-running - * repeating timer. - * - * Users can use this just like a QTimer. The difference is that KisRelaxedTimer will - * relax the callback guarantee time as follows: timeouts will never happen earlier - * than \p interval ms, but may well happen only after 2 * \p interval ms (whereas - * QTimer guarantees a fixed interval of \p interval ms). - * - * The rationale for using this is that stopping and starting timers can produce a - * measurable performance overhead. KisRelaxedTimer removes that overhead. - */ -class KRITAGLOBAL_EXPORT KisRelaxedTimer : public QObject -{ - Q_OBJECT - -public: - KisRelaxedTimer(QObject *parent = nullptr); - - void start(); - - inline void stop() { - m_emitOnTimeTick = 0; - } - - void setInterval(int interval); - void setSingleShot(bool singleShot); - - inline bool isActive() const { - return m_emitOnTimeTick >= m_nextTimerTickSeqNo; - } - - int remainingTime() const; - -Q_SIGNALS: - void timeout(); - -protected: - void timerEvent(QTimerEvent *event) override; - -private: - int m_interval; - bool m_singleShot; - - QBasicTimer m_timer; - qint64 m_nextTimerTickSeqNo; - qint64 m_emitOnTimeTick; - - QElapsedTimer m_elapsed; - -protected: - class IsEmitting { - public: - IsEmitting(KisRelaxedTimer &timer) : m_timer(timer) { - timer.m_isEmitting = true; - } - - ~IsEmitting() { - m_timer.m_isEmitting = false; - } - - private: - KisRelaxedTimer &m_timer; - }; - - friend class IsEmitting; - - bool m_isEmitting; -}; - -#endif /* __KIS_RELAXED_TIMER_H */