Krita Source Code Documentation
Loading...
Searching...
No Matches
KisStoryboardThumbnailRenderScheduler.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2020 Saurabh Kumar <saurabhk660@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7
10#include "kis_paint_device.h"
11
14
16 : QObject(parent)
17 , m_renderer(new KisAsyncStoryboardThumbnailRenderer(this))
18 , m_currentFrame(-1)
19{
20 //connect signals to the renderer.
21 connect(m_renderer, SIGNAL(sigNotifyFrameCompleted(int,KisPaintDeviceSP)), this, SLOT(slotFrameRegenerationCompleted(int, KisPaintDeviceSP)));
23}
24
29
31{
32 if (m_image == image) {
33 return;
34 }
36 m_image = image;
37}
38
40{
41 if (affected && m_affectedFramesQueue.contains(frame)) {
42 return;
43 }
44 else if (affected && !m_changedFramesQueue.contains(frame)) {
45 m_affectedFramesQueue.prepend(frame);
46 }
47 else {
48 if (m_changedFramesQueue.contains(frame)) {
49 int framePos = m_changedFramesQueue.indexOf(frame);
50 if (framePos == 0) {
51 return;
52 }
53 m_changedFramesQueue.move(framePos, 0);
54 }
55 else {
56 m_changedFramesQueue.prepend(frame);
57 }
59 }
60}
61
71
73{
74 if (frame < 0) {
75 return;
76 }
77 if (m_renderer->isActive() && frame == m_currentFrame) {
79 m_currentFrame = -1;
80 }
81 else if (m_changedFramesQueue.contains(frame)) {
82 m_changedFramesQueue.removeAll(frame);
83 }
84 else if (m_affectedFramesQueue.contains(frame)) {
85 m_affectedFramesQueue.removeAll(frame);
86 }
87}
88
90{
91 //if the renderer is idle start rendering the frames in queues
92 if (!m_renderer->isActive()) {
94 }
95}
96
97
103
109
111{
112 int lastChangedFrame = m_changedFramesQueue[0];
113
114 //sort the affected queue based on proximity to the last changed frame.
115 std::sort(m_affectedFramesQueue.begin(), m_affectedFramesQueue.end(),
116 [lastChangedFrame](const int &arg1, const int &arg2)
117 {
118 return std::abs(arg1 - lastChangedFrame) < std::abs(arg2 - lastChangedFrame);
119 });
120}
121
123{
124 if (!m_image || !m_image->isIdle()) {
125 return;
126 }
127
128 if (m_changedFramesQueue.isEmpty() && m_affectedFramesQueue.isEmpty()) {
129 return;
130 }
131
133 return;
134 }
135
136 KisImageSP image = m_image->clone(false);
138
139 int frame = !m_changedFramesQueue.isEmpty() ? m_changedFramesQueue.takeFirst() : m_affectedFramesQueue.takeFirst();;
140
141 KisLockFrameGenerationLock lock(image->animationInterface());
142
144 m_currentFrame = frame;
145}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
requests regeneration of a frame. The regeneration should be requested after switching the KisImage t...
KisImageAnimationInterface * animationInterface() const
bool isIdle(bool allowLocked=false)
Definition kis_image.cc:788
KisImage * clone(bool exactCopy=false)
Definition kis_image.cc:405
void slotFrameRegenerationCancelled(int frame)
Emits sigFrameCancelled(int) and schedules the next frame for regeneration.
void renderNextFrame()
Renders the next frame, either from affected or changed queue. Changed queue is given preference....
void slotFrameRegenerationCompleted(int frame, KisPaintDeviceSP contents)
Emits sigFrameCompleted(int,KisPaintDeviceSP) if the regeneration was complete and calls regeneration...
void sigFrameCompleted(int frame, KisPaintDeviceSP dev)
void sortAffectedFrameQueue()
Sorts the m_affectedFramesQueue based on proximity to the last changed frame.
void cancelFrameRendering(int frame)
Cancel rendering of a single frame.
void scheduleFrameForRegeneration(int frame, bool affected)
Adds the frame to the list of "to be regenerated" frames.
void cancelAllFrameRendering()
Cancels all frame rendering. Empties all queues and cancels the current rendering,...
void setImage(KisImageSP image)
Sets an image, the class takes an image, clones it and calls frame regeneration on the clone so do no...
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
void startFrameRegeneration(KisImageSP image, int frame, const KisRegion &regionOfInterest, Flags flags, KisLockFrameGenerationLock &&frameGenerationLock)
void cancelCurrentFrameRendering(CancelReason cancelReason)
cancels current rendering operation