1 /*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2011 Thomas Lübking <thomas.luebking@web.de>
6 SPDX-FileCopyrightText: 2018 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11 #include "anidata_p.h"
12
13 #include "logging_p.h"
14
15 namespace KWin
16 {
17
operator <<(QDebug dbg,const KWin::AniData & a)18 QDebug operator<<(QDebug dbg, const KWin::AniData &a)
19 {
20 dbg.nospace() << a.debugInfo();
21 return dbg.space();
22 }
23
FullScreenEffectLock(Effect * effect)24 FullScreenEffectLock::FullScreenEffectLock(Effect *effect)
25 {
26 effects->setActiveFullScreenEffect(effect);
27 }
28
~FullScreenEffectLock()29 FullScreenEffectLock::~FullScreenEffectLock()
30 {
31 effects->setActiveFullScreenEffect(nullptr);
32 }
33
KeepAliveLock(EffectWindow * w)34 KeepAliveLock::KeepAliveLock(EffectWindow *w)
35 : m_window(w)
36 {
37 m_window->refWindow();
38 }
39
~KeepAliveLock()40 KeepAliveLock::~KeepAliveLock()
41 {
42 m_window->unrefWindow();
43 }
44
PreviousWindowPixmapLock(EffectWindow * w)45 PreviousWindowPixmapLock::PreviousWindowPixmapLock(EffectWindow *w)
46 : m_window(w)
47 {
48 m_window->referencePreviousWindowPixmap();
49 }
50
~PreviousWindowPixmapLock()51 PreviousWindowPixmapLock::~PreviousWindowPixmapLock()
52 {
53 m_window->unreferencePreviousWindowPixmap();
54
55 // Add synthetic repaint to prevent glitches after cross-fading
56 // translucent windows.
57 effects->addRepaint(m_window->expandedGeometry());
58 }
59
AniData()60 AniData::AniData()
61 : attribute(AnimationEffect::Opacity)
62 , customCurve(0) // Linear
63 , meta(0)
64 , startTime(0)
65 , waitAtSource(false)
66 , keepAlive(true)
67 , lastPresentTime(std::chrono::milliseconds::zero())
68 {
69 }
70
AniData(AnimationEffect::Attribute a,int meta_,const FPx2 & to_,int delay,const FPx2 & from_,bool waitAtSource_,FullScreenEffectLockPtr fullScreenEffectLock_,bool keepAlive,PreviousWindowPixmapLockPtr previousWindowPixmapLock_)71 AniData::AniData(AnimationEffect::Attribute a, int meta_, const FPx2 &to_,
72 int delay, const FPx2 &from_, bool waitAtSource_,
73 FullScreenEffectLockPtr fullScreenEffectLock_, bool keepAlive,
74 PreviousWindowPixmapLockPtr previousWindowPixmapLock_)
75 : attribute(a)
76 , from(from_)
77 , to(to_)
78 , meta(meta_)
79 , startTime(AnimationEffect::clock() + delay)
80 , fullScreenEffectLock(std::move(fullScreenEffectLock_))
81 , waitAtSource(waitAtSource_)
82 , keepAlive(keepAlive)
83 , previousWindowPixmapLock(std::move(previousWindowPixmapLock_))
84 , lastPresentTime(std::chrono::milliseconds::zero())
85 {
86 }
87
isActive() const88 bool AniData::isActive() const
89 {
90 if (!timeLine.done()) {
91 return true;
92 }
93
94 if (timeLine.direction() == TimeLine::Backward) {
95 return !(terminationFlags & AnimationEffect::TerminateAtSource);
96 }
97
98 return !(terminationFlags & AnimationEffect::TerminateAtTarget);
99 }
100
attributeString(KWin::AnimationEffect::Attribute attribute)101 static QString attributeString(KWin::AnimationEffect::Attribute attribute)
102 {
103 switch (attribute) {
104 case KWin::AnimationEffect::Opacity: return QStringLiteral("Opacity");
105 case KWin::AnimationEffect::Brightness: return QStringLiteral("Brightness");
106 case KWin::AnimationEffect::Saturation: return QStringLiteral("Saturation");
107 case KWin::AnimationEffect::Scale: return QStringLiteral("Scale");
108 case KWin::AnimationEffect::Translation: return QStringLiteral("Translation");
109 case KWin::AnimationEffect::Rotation: return QStringLiteral("Rotation");
110 case KWin::AnimationEffect::Position: return QStringLiteral("Position");
111 case KWin::AnimationEffect::Size: return QStringLiteral("Size");
112 case KWin::AnimationEffect::Clip: return QStringLiteral("Clip");
113 default: return QStringLiteral(" ");
114 }
115 }
116
debugInfo() const117 QString AniData::debugInfo() const
118 {
119 return QLatin1String("Animation: ") + attributeString(attribute) +
120 QLatin1String("\n From: ") + from.toString() +
121 QLatin1String("\n To: ") + to.toString() +
122 QLatin1String("\n Started: ") + QString::number(AnimationEffect::clock() - startTime) + QLatin1String("ms ago\n") +
123 QLatin1String( " Duration: ") + QString::number(timeLine.duration().count()) + QLatin1String("ms\n") +
124 QLatin1String( " Passed: ") + QString::number(timeLine.elapsed().count()) + QLatin1String("ms\n");
125 }
126
127 } // namespace KWin
128