Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_switch_time_stroke_strategy.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QMutex>
10#include <QMutexLocker>
11
15
16
18{
19 Private(int frameId, bool needsRegeneration)
20 : token(new SharedToken(frameId, needsRegeneration))
21 {
22 }
23
24 KisImageAnimationInterface *interface {nullptr};
27};
28
30 bool needsRegeneration,
32 KisPostExecutionUndoAdapter *undoAdapter)
33 : KisSimpleStrokeStrategy(QLatin1String("switch_current_frame_stroke"), kundo2_i18n("Switch Frames")),
34 m_d(new Private(frameId, needsRegeneration))
35{
36 m_d->interface = interface;
37 m_d->undoAdapter = undoAdapter;
38
39
41
42 // switching frames is a distinct user action, so it should
43 // cancel the playback or any action easily
46}
47
52{
53 const int frameId = m_d->token->fetchTime();
54
55 if (frameId == m_d->interface->currentTime()) return;
56
57 const int oldTime = m_d->interface->currentTime();
58 m_d->interface->explicitlySetCurrentTime(frameId);
59
60 if (m_d->undoAdapter) {
62 new KisSwitchCurrentTimeCommand(m_d->interface,
63 oldTime,
64 frameId));
65 m_d->undoAdapter->addCommand(cmd);
66 }
67}
69{
70 Q_UNUSED(levelOfDetail);
71
72 // This stroke is explicitly made LEGACY, so that it could create a barrier for
73 // time switch. Theoretically, we can have separate time ids for Lod0 and LodN,
74 // but currently this idea doesn't work for some reason. The consequences of
75 // making this stroke a barrier:
76 //
77 // * LodSync stroke is started after every time switch (not slow, but still...)
78 // * The frame switches only *after* all the pending strokes are finished
79 // * LodSync stroke is started even when the image is not changed (not regeneration needed)!
80
81 return 0;
82}
83
88
89
90/*****************************************************************/
91/* KisSwitchTimeStrokeStrategy::SharedToken */
92/*****************************************************************/
93
95 Private(int _time, bool _needsRegeneration)
96 : time(_time),
97 needsRegeneration(_needsRegeneration),
98 isCompleted(false)
99 {
100 }
101
102 QMutex mutex;
103 int time;
106};
107
108KisSwitchTimeStrokeStrategy::SharedToken::SharedToken(int initialTime, bool needsRegeneration)
109 : m_d(new Private(initialTime, needsRegeneration))
110{
111}
112
116
118{
119 QMutexLocker l(&m_d->mutex);
120
121 const bool result =
122 !m_d->isCompleted &&
123 (m_d->needsRegeneration || !needsRegeneration);
124
125 if (result) {
126 m_d->time = time;
127 }
128
129 return result;
130}
131
133{
134 QMutexLocker l(&m_d->mutex);
135 KIS_SAFE_ASSERT_RECOVER_NOOP(!m_d->isCompleted);
136
137 m_d->isCompleted = true;
138 return m_d->time;
139}
void enableJob(JobType type, bool enable=true, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
void setClearsRedoOnStart(bool value)
void setRequestsOtherStrokesToEnd(bool value)
KisSwitchTimeStrokeStrategy(int frameId, bool needsRegeneration, KisImageAnimationInterface *interface, KisPostExecutionUndoAdapter *undoAdapter)
const QScopedPointer< Private > m_d
KisStrokeStrategy * createLodClone(int levelOfDetail) override
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
KUndo2MagicString kundo2_i18n(const char *text)
bool tryResetDestinationTime(int time, bool needsRegeneration)
SharedToken(int initialTime, bool needsRegeneration)