File indexing completed on 2024-05-19 16:34:29

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2011 Thomas Lübking <thomas.luebking@web.de>
0006     SPDX-FileCopyrightText: 2018 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #include "anidata_p.h"
0012 
0013 #include "logging_p.h"
0014 
0015 namespace KWin
0016 {
0017 
0018 QDebug operator<<(QDebug dbg, const KWin::AniData &a)
0019 {
0020     dbg.nospace() << a.debugInfo();
0021     return dbg.space();
0022 }
0023 
0024 FullScreenEffectLock::FullScreenEffectLock(Effect *effect)
0025 {
0026     effects->setActiveFullScreenEffect(effect);
0027 }
0028 
0029 FullScreenEffectLock::~FullScreenEffectLock()
0030 {
0031     effects->setActiveFullScreenEffect(nullptr);
0032 }
0033 
0034 PreviousWindowPixmapLock::PreviousWindowPixmapLock(EffectWindow *w)
0035     : m_window(w)
0036 {
0037     m_window->referencePreviousWindowPixmap();
0038 }
0039 
0040 PreviousWindowPixmapLock::~PreviousWindowPixmapLock()
0041 {
0042     m_window->unreferencePreviousWindowPixmap();
0043 
0044     // Add synthetic repaint to prevent glitches after cross-fading
0045     // translucent windows.
0046     effects->addRepaint(m_window->expandedGeometry().toAlignedRect());
0047 }
0048 
0049 AniData::AniData()
0050     : attribute(AnimationEffect::Opacity)
0051     , customCurve(0) // Linear
0052     , meta(0)
0053     , frozenTime(-1)
0054     , startTime(0)
0055     , waitAtSource(false)
0056     , keepAlive(true)
0057 {
0058 }
0059 
0060 AniData::AniData(AnimationEffect::Attribute a, int meta_, const FPx2 &to_,
0061                  int delay, const FPx2 &from_, bool waitAtSource_,
0062                  FullScreenEffectLockPtr fullScreenEffectLock_, bool keepAlive,
0063                  PreviousWindowPixmapLockPtr previousWindowPixmapLock_, GLShader *shader)
0064     : attribute(a)
0065     , from(from_)
0066     , to(to_)
0067     , meta(meta_)
0068     , frozenTime(-1)
0069     , startTime(AnimationEffect::clock() + delay)
0070     , fullScreenEffectLock(std::move(fullScreenEffectLock_))
0071     , waitAtSource(waitAtSource_)
0072     , keepAlive(keepAlive)
0073     , previousWindowPixmapLock(std::move(previousWindowPixmapLock_))
0074     , shader(shader)
0075 {
0076 }
0077 
0078 bool AniData::isActive() const
0079 {
0080     if (!timeLine.done()) {
0081         return true;
0082     }
0083 
0084     if (timeLine.direction() == TimeLine::Backward) {
0085         return !(terminationFlags & AnimationEffect::TerminateAtSource);
0086     }
0087 
0088     return !(terminationFlags & AnimationEffect::TerminateAtTarget);
0089 }
0090 
0091 static QString attributeString(KWin::AnimationEffect::Attribute attribute)
0092 {
0093     switch (attribute) {
0094     case KWin::AnimationEffect::Opacity:
0095         return QStringLiteral("Opacity");
0096     case KWin::AnimationEffect::Brightness:
0097         return QStringLiteral("Brightness");
0098     case KWin::AnimationEffect::Saturation:
0099         return QStringLiteral("Saturation");
0100     case KWin::AnimationEffect::Scale:
0101         return QStringLiteral("Scale");
0102     case KWin::AnimationEffect::Translation:
0103         return QStringLiteral("Translation");
0104     case KWin::AnimationEffect::Rotation:
0105         return QStringLiteral("Rotation");
0106     case KWin::AnimationEffect::Position:
0107         return QStringLiteral("Position");
0108     case KWin::AnimationEffect::Size:
0109         return QStringLiteral("Size");
0110     case KWin::AnimationEffect::Clip:
0111         return QStringLiteral("Clip");
0112     default:
0113         return QStringLiteral(" ");
0114     }
0115 }
0116 
0117 QString AniData::debugInfo() const
0118 {
0119     return (QLatin1String("Animation: ") + attributeString(attribute)
0120             + QLatin1String("\n     From: ") + from.toString()
0121             + QLatin1String("\n       To: ") + to.toString()
0122             + QLatin1String("\n  Started: ") + QString::number(AnimationEffect::clock() - startTime) + QLatin1String("ms ago\n")
0123             + QLatin1String(" Duration: ") + QString::number(timeLine.duration().count()) + QLatin1String("ms\n")
0124             + QLatin1String("   Passed: ") + QString::number(timeLine.elapsed().count()) + QLatin1String("ms\n"));
0125 }
0126 
0127 } // namespace KWin