From c9fd04afee3d831e2200bb29f03cf0525b63f620 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 13 Nov 2022 22:46:53 +0200 Subject: [PATCH] do not register QColor, QVector2D, QVector3D and QVector2D interpolators as external now the interpolators global mutex will be held 4 times less when the GUI component library is loaded and 4 more times when it is unloaded Signed-off-by: Ivailo Monev --- src/gui/CMakeLists.txt | 1 - src/gui/animation/qguivariantanimation.cpp | 83 ------------------------------ src/gui/animation/qvariantanimation.cpp | 41 +++++++++++++-- 3 files changed, 36 insertions(+), 89 deletions(-) delete mode 100644 src/gui/animation/qguivariantanimation.cpp diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 1416e9e44..c2f900032 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -582,7 +582,6 @@ set(GUI_HEADERS ) set(GUI_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/animation/qguivariantanimation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/animation/qabstractanimation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/animation/qvariantanimation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/animation/qpropertyanimation.cpp diff --git a/src/gui/animation/qguivariantanimation.cpp b/src/gui/animation/qguivariantanimation.cpp deleted file mode 100644 index fcc771e2f..000000000 --- a/src/gui/animation/qguivariantanimation.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Copyright (C) 2016 Ivailo Monev -** -** This file is part of the QtGui module of the Katie Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "qvariantanimation.h" -#include "qvariantanimation_p.h" - -#ifndef QT_NO_ANIMATION - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -template<> Q_INLINE_TEMPLATE QColor _q_interpolate(const QColor &f,const QColor &t, qreal progress) -{ - return QColor(qBound(0,_q_interpolate(f.red(), t.red(), progress),255), - qBound(0,_q_interpolate(f.green(), t.green(), progress),255), - qBound(0,_q_interpolate(f.blue(), t.blue(), progress),255), - qBound(0,_q_interpolate(f.alpha(), t.alpha(), progress),255)); -} - -static int qRegisterGuiGetInterpolator() -{ - qRegisterAnimationInterpolator(_q_interpolateVariant); -#ifndef QT_NO_VECTOR2D - qRegisterAnimationInterpolator(_q_interpolateVariant); -#endif // QT_NO_VECTOR2D -#ifndef QT_NO_VECTOR3D - qRegisterAnimationInterpolator(_q_interpolateVariant); -#endif // QT_NO_VECTOR3D -#ifndef QT_NO_VECTOR4D - qRegisterAnimationInterpolator(_q_interpolateVariant); -#endif // QT_NO_VECTOR4D - return 1; -} -Q_CONSTRUCTOR_FUNCTION(qRegisterGuiGetInterpolator) - -static int qUnregisterGuiGetInterpolator() -{ - // casts required by Sun CC 5.5 - qRegisterAnimationInterpolator( - (QVariant (*)(const QColor &, const QColor &, qreal))0); -#ifndef QT_NO_VECTOR2D - qRegisterAnimationInterpolator( - (QVariant (*)(const QVector2D &, const QVector2D &, qreal))0); -#endif // QT_NO_VECTOR2D -#ifndef QT_NO_VECTOR3D - qRegisterAnimationInterpolator( - (QVariant (*)(const QVector3D &, const QVector3D &, qreal))0); -#endif // QT_NO_VECTOR3D -#ifndef QT_NO_VECTOR4D - qRegisterAnimationInterpolator( - (QVariant (*)(const QVector4D &, const QVector4D &, qreal))0); -#endif // QT_NO_VECTOR4D - - return 1; -} -Q_DESTRUCTOR_FUNCTION(qUnregisterGuiGetInterpolator) - -QT_END_NAMESPACE - -#endif //QT_NO_ANIMATION - - diff --git a/src/gui/animation/qvariantanimation.cpp b/src/gui/animation/qvariantanimation.cpp index 813e84dba..a15ee68a0 100644 --- a/src/gui/animation/qvariantanimation.cpp +++ b/src/gui/animation/qvariantanimation.cpp @@ -25,6 +25,10 @@ #include #include #include +#include +#include +#include +#include #ifndef QT_NO_ANIMATION @@ -44,8 +48,8 @@ QT_BEGIN_NAMESPACE class; it has a pure virtual method called updateCurrentValue(). The class performs interpolation over \l{QVariant}s, but leaves using the interpolated values to its - subclasses. Currently, Qt provides QPropertyAnimation, which - animates Qt \l{Qt's Property System}{properties}. See the + subclasses. Currently, Katie provides QPropertyAnimation, which + animates Katie \l{Katie's Property System}{properties}. See the QPropertyAnimation class description if you wish to animate such properties. @@ -69,7 +73,7 @@ QT_BEGIN_NAMESPACE the virtual interpolated() function. Subclassing QVariantAnimation can be an alternative if you have - \l{QVariant}s that you do not wish to declare as Qt properties. + \l{QVariant}s that you do not wish to declare as Katie properties. Note, however, that you in most cases will be better off declaring your QVariant as a property. @@ -90,6 +94,9 @@ QT_BEGIN_NAMESPACE \o \l{QMetaType::}{QRect} \o \l{QMetaType::}{QRectF} \o \l{QMetaType::}{QColor} + \o \l{QMetaType::}{QVector2D} + \o \l{QMetaType::}{QVector3D} + \o \l{QMetaType::}{QVector4D} \endlist If you need to interpolate other variant types, including custom @@ -170,6 +177,14 @@ template<> Q_INLINE_TEMPLATE QLineF _q_interpolate(const QLineF &f, const QLineF return QLineF( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress)); } +template<> Q_INLINE_TEMPLATE QColor _q_interpolate(const QColor &f,const QColor &t, qreal progress) +{ + return QColor(qBound(0,_q_interpolate(f.red(), t.red(), progress),255), + qBound(0,_q_interpolate(f.green(), t.green(), progress),255), + qBound(0,_q_interpolate(f.blue(), t.blue(), progress),255), + qBound(0,_q_interpolate(f.alpha(), t.alpha(), progress),255)); +} + QVariantAnimationPrivate::QVariantAnimationPrivate() : duration(250), interpolator(&defaultInterpolator) { } @@ -322,14 +337,16 @@ void QVariantAnimationPrivate::setDefaultStartEndValue(const QVariant &value) Construct a QVariantAnimation object. \a parent is passed to QAbstractAnimation's constructor. */ -QVariantAnimation::QVariantAnimation(QObject *parent) : QAbstractAnimation(*new QVariantAnimationPrivate, parent) +QVariantAnimation::QVariantAnimation(QObject *parent) + : QAbstractAnimation(*new QVariantAnimationPrivate, parent) { } /*! \internal */ -QVariantAnimation::QVariantAnimation(QVariantAnimationPrivate &dd, QObject *parent) : QAbstractAnimation(dd, parent) +QVariantAnimation::QVariantAnimation(QVariantAnimationPrivate &dd, QObject *parent) + : QAbstractAnimation(dd, parent) { } @@ -453,6 +470,20 @@ QVariantAnimation::Interpolator QVariantAnimationPrivate::getInterpolator(int in return reinterpret_cast(_q_interpolateVariant); case QMetaType::QRectF: return reinterpret_cast(_q_interpolateVariant); + case QMetaType::QColor: + return reinterpret_cast(_q_interpolateVariant); +#ifndef QT_NO_VECTOR2D + case QMetaType::QVector2D: + return reinterpret_cast(_q_interpolateVariant); +#endif // QT_NO_VECTOR2D +#ifndef QT_NO_VECTOR3D + case QMetaType::QVector3D: + return reinterpret_cast(_q_interpolateVariant); +#endif // QT_NO_VECTOR3D +#ifndef QT_NO_VECTOR4D + case QMetaType::QVector4D: + return reinterpret_cast(_q_interpolateVariant); +#endif // QT_NO_VECTOR4D default: return 0; //this type is not handled } -- 2.11.0