Krita Source Code Documentation
Loading...
Searching...
No Matches
KisAsyncAnimationRendererBase Class Referenceabstract

#include <KisAsyncAnimationRendererBase.h>

+ Inheritance diagram for KisAsyncAnimationRendererBase:

Public Types

enum  CancelReason { UserCancelled = 0 , RenderingFailed , RenderingTimedOut }
 
enum  Flag { None = 0x0 , Cancellable = 0x1 }
 

Public Slots

void cancelCurrentFrameRendering (CancelReason cancelReason)
 cancels current rendering operation
 

Signals

void sigFrameCancelled (int frame, KisAsyncAnimationRendererBase::CancelReason cancelReason)
 
void sigFrameCompleted (int frame)
 

Public Member Functions

bool isActive () const
 
 KisAsyncAnimationRendererBase (QObject *parent=0)
 
void startFrameRegeneration (KisImageSP image, int frame, const KisRegion &regionOfInterest, Flags flags, KisLockFrameGenerationLock &&frameGenerationLock)
 
void startFrameRegeneration (KisImageSP image, int frame, Flags flags, KisLockFrameGenerationLock &&frameGenerationLock)
 
virtual ~KisAsyncAnimationRendererBase ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Public Attributes

KisSignalAutoConnectionsStore imageRequestConnections
 
bool isCancelled = false
 
QTimer regenerationTimeout
 
int requestedFrame = -1
 
KisImageSP requestedImage
 
KisRegion requestedRegion
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Protected Slots

void notifyFrameCancelled (int frame, KisAsyncAnimationRendererBase::CancelReason cancelReason)
 
void notifyFrameCompleted (int frame)
 

Protected Member Functions

virtual void clearFrameRegenerationState (bool isCancelled)
 
virtual void frameCancelledCallback (int frame, CancelReason cancelReason)=0
 frameCancelledCallback is called when the rendering of the frame was cancelled.
 
virtual void frameCompletedCallback (int frame, const KisRegion &requestedRegion)=0
 frameCompletedCallback is called by the renderer when a new frame becomes ready
 
KisImageSP requestedImage () const
 

Private Slots

void slotFrameRegenerationCancelled ()
 
void slotFrameRegenerationFinished (int frame)
 
void slotFrameRegenerationTimedOut ()
 

Private Attributes

const QScopedPointer< Privatem_d
 

Detailed Description

KisAsyncAnimationRendererBase is a special class representing a single worker thread inside KisAsyncAnimationRenderDialogBase. It connects the specified image using correct Qt::DirectConnection connections and reacts on them. On sigFrameReady() signal it calls frameCompletedCallback(), so the derived class can fetch a frame from the image and process it. On sigFrameCancelled() it calls frameCancelledCallback(). The derived class should override these two methods to do the actual work.

Definition at line 23 of file KisAsyncAnimationRendererBase.cpp.

Member Enumeration Documentation

◆ CancelReason

◆ Flag

Constructor & Destructor Documentation

◆ KisAsyncAnimationRendererBase()

KisAsyncAnimationRendererBase::KisAsyncAnimationRendererBase ( QObject * parent = 0)
explicit

Definition at line 35 of file KisAsyncAnimationRendererBase.cpp.

36 : QObject(parent),
37 m_d(new Private())
38{
39 connect(&m_d->regenerationTimeout, SIGNAL(timeout()), SLOT(slotFrameRegenerationTimedOut()));
40
41 KisImageConfig cfg(true);
42
43 m_d->regenerationTimeout.setSingleShot(true);
44 m_d->regenerationTimeout.setInterval(cfg.frameRenderingTimeout());
45}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
const QScopedPointer< Private > m_d

References connect(), KisImageConfig::frameRenderingTimeout(), m_d, and slotFrameRegenerationTimedOut().

◆ ~KisAsyncAnimationRendererBase()

KisAsyncAnimationRendererBase::~KisAsyncAnimationRendererBase ( )
virtual

Definition at line 47 of file KisAsyncAnimationRendererBase.cpp.

48{
49
50}

Member Function Documentation

◆ cancelCurrentFrameRendering

void KisAsyncAnimationRendererBase::cancelCurrentFrameRendering ( CancelReason cancelReason)
slot

cancels current rendering operation

After calling this slot requestedImage() becomes invalid.

See also
requestedImage()

Definition at line 88 of file KisAsyncAnimationRendererBase.cpp.

89{
90 KIS_SAFE_ASSERT_RECOVER_RETURN(m_d->requestedImage);
91 frameCancelledCallback(m_d->requestedFrame, cancelReason);
92}
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
virtual void frameCancelledCallback(int frame, CancelReason cancelReason)=0
frameCancelledCallback is called when the rendering of the frame was cancelled.

References frameCancelledCallback(), KIS_SAFE_ASSERT_RECOVER_RETURN, and m_d.

◆ clearFrameRegenerationState()

void KisAsyncAnimationRendererBase::clearFrameRegenerationState ( bool isCancelled)
protectedvirtual

Called by KisAsyncAnimationRendererBase when the processing has been completed and the internal state of the populator should be cleared

Parameters
isCancelledtells if frame regeneration has failed to be regenerated

Reimplemented in KisAsyncAnimationCacheRenderer, and KisAsyncStoryboardThumbnailRenderer.

Definition at line 165 of file KisAsyncAnimationRendererBase.cpp.

166{
167 // TODO: for some reason we mark the process as cancelled in any case, and it
168 // seem to be a correct behavior
169 Q_UNUSED(isCancelled);
170
171 m_d->imageRequestConnections.clear();
172 m_d->requestedImage = 0;
173 m_d->requestedFrame = -1;
174 m_d->regenerationTimeout.stop();
175 m_d->isCancelled = true;
176 m_d->requestedRegion = KisRegion();
177}

References isCancelled, and m_d.

◆ frameCancelledCallback()

virtual void KisAsyncAnimationRendererBase::frameCancelledCallback ( int frame,
CancelReason cancelReason )
protectedpure virtual

frameCancelledCallback is called when the rendering of the frame was cancelled.

The rendering of the frame can be either cancelled by the image itself or by receiving a timeout signal (10 seconds).

NOTE: the slot is called in the GUI thread. Don't forget to call notifyFrameCancelled() in he end of your call.

Implemented in KisAsyncAnimationCacheRenderer, KisAsyncAnimationFramesSavingRenderer, and KisAsyncStoryboardThumbnailRenderer.

◆ frameCompletedCallback()

virtual void KisAsyncAnimationRendererBase::frameCompletedCallback ( int frame,
const KisRegion & requestedRegion )
protectedpure virtual

frameCompletedCallback is called by the renderer when a new frame becomes ready

NOTE1: the callback is called from the context of a image worker thread! So it is asynchronous from the GUI thread. NOTE2: in case of successful processing of the frame, the callback must issue some signal, connected to notifyFrameCompleted() via auto connection, to continue processing. Please do not call the method directly, because notifyFame*() slots should be called from the context of the GUI thread. NOTE3: In case of failure, notifyFrameCancelled(). The same threading rules apply.

Implemented in KisAsyncAnimationCacheRenderer, KisAsyncAnimationFramesSavingRenderer, and KisAsyncStoryboardThumbnailRenderer.

◆ isActive()

bool KisAsyncAnimationRendererBase::isActive ( ) const
Returns
true if the regeneration process is in progress

Definition at line 83 of file KisAsyncAnimationRendererBase.cpp.

84{
85 return m_d->requestedImage;
86}

References m_d.

◆ notifyFrameCancelled

void KisAsyncAnimationRendererBase::notifyFrameCancelled ( int frame,
KisAsyncAnimationRendererBase::CancelReason cancelReason )
protectedslot

Called by a derived class to cancel processing of the frames. After calling this method, the dialog will stop processing the frames and close.

Definition at line 144 of file KisAsyncAnimationRendererBase.cpp.

145{
146 KIS_SAFE_ASSERT_RECOVER_NOOP(QThread::currentThread() == this->thread());
147
148 // the image events can come with a delay, even after
149 // the processing was cancelled
150 if (m_d->isCancelled) return;
151
152 {
153 // clean state right after the assert checks
154 auto cleanup = kismpl::finally([&] () {
156 });
157
158 KIS_SAFE_ASSERT_RECOVER_RETURN(m_d->requestedImage);
159 KIS_SAFE_ASSERT_RECOVER_RETURN(m_d->requestedFrame == frame);
160 }
161
162 Q_EMIT sigFrameCancelled(frame, cancelReason);
163}
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
void sigFrameCancelled(int frame, KisAsyncAnimationRendererBase::CancelReason cancelReason)
virtual void clearFrameRegenerationState(bool isCancelled)

References clearFrameRegenerationState(), KIS_SAFE_ASSERT_RECOVER_NOOP, KIS_SAFE_ASSERT_RECOVER_RETURN, m_d, and sigFrameCancelled().

◆ notifyFrameCompleted

void KisAsyncAnimationRendererBase::notifyFrameCompleted ( int frame)
protectedslot

Called by a derived class to continue processing of the frames

Definition at line 122 of file KisAsyncAnimationRendererBase.cpp.

123{
124 KIS_SAFE_ASSERT_RECOVER_NOOP(QThread::currentThread() == this->thread());
125
126 // the image events can come with a delay, even after
127 // the processing was cancelled
128 if (m_d->isCancelled) return;
129
130 {
131 // clean state right after the assert checks
132 auto cleanup = kismpl::finally([&] () {
134 });
135
136 KIS_SAFE_ASSERT_RECOVER_RETURN(m_d->requestedImage);
137 KIS_SAFE_ASSERT_RECOVER_RETURN(m_d->requestedFrame == frame);
138 }
139
140
141 Q_EMIT sigFrameCompleted(frame);
142}
void sigFrameCompleted(int frame)

References clearFrameRegenerationState(), KIS_SAFE_ASSERT_RECOVER_NOOP, KIS_SAFE_ASSERT_RECOVER_RETURN, m_d, and sigFrameCompleted().

◆ requestedImage()

KisImageSP KisAsyncAnimationRendererBase::requestedImage ( ) const
protected
Returns
the image that for which the rendering was requested using startFrameRegeneration(). Should be used by the derived classes only.

Please note that requestedImage() will become null as soon as the user cancels the processing. That happens in the GUI thread so frameCompletedCallback() should be extremely careful when requesting the value (check the shared pointer after fetching).

◆ sigFrameCancelled

void KisAsyncAnimationRendererBase::sigFrameCancelled ( int frame,
KisAsyncAnimationRendererBase::CancelReason cancelReason )
signal

◆ sigFrameCompleted

void KisAsyncAnimationRendererBase::sigFrameCompleted ( int frame)
signal

◆ slotFrameRegenerationCancelled

void KisAsyncAnimationRendererBase::slotFrameRegenerationCancelled ( )
privateslot

Definition at line 94 of file KisAsyncAnimationRendererBase.cpp.

95{
96 // the cancel can arrive in async way
97 if (!m_d->requestedImage) return;
99}

References frameCancelledCallback(), m_d, and RenderingFailed.

◆ slotFrameRegenerationFinished

void KisAsyncAnimationRendererBase::slotFrameRegenerationFinished ( int frame)
privateslot

Definition at line 108 of file KisAsyncAnimationRendererBase.cpp.

109{
110 // We might have already cancelled the regeneration. We don't check
111 // isCancelled flag here because this code runs asynchronously.
112 if (!m_d->requestedImage) return;
113
114 // WARNING: executed in the context of image worker thread!
115
116 // probably a bit too strict...
117 KIS_SAFE_ASSERT_RECOVER_NOOP(QThread::currentThread() != this->thread());
118
119 frameCompletedCallback(frame, m_d->requestedRegion);
120}
virtual void frameCompletedCallback(int frame, const KisRegion &requestedRegion)=0
frameCompletedCallback is called by the renderer when a new frame becomes ready

References frameCompletedCallback(), KIS_SAFE_ASSERT_RECOVER_NOOP, and m_d.

◆ slotFrameRegenerationTimedOut

void KisAsyncAnimationRendererBase::slotFrameRegenerationTimedOut ( )
privateslot

Definition at line 101 of file KisAsyncAnimationRendererBase.cpp.

102{
103 // the timeout can arrive in async way
104 if (!m_d->requestedImage) return;
106}

References frameCancelledCallback(), m_d, and RenderingTimedOut.

◆ startFrameRegeneration() [1/2]

void KisAsyncAnimationRendererBase::startFrameRegeneration ( KisImageSP image,
int frame,
const KisRegion & regionOfInterest,
Flags flags,
KisLockFrameGenerationLock && frameGenerationLock )

Initiates the rendering of the frame frame on an image image. Only regionOfInterest is regenerated. If regionOfInterest is empty, then entire bounds of the image is regenerated.

Definition at line 52 of file KisAsyncAnimationRendererBase.cpp.

53{
54 KIS_SAFE_ASSERT_RECOVER_NOOP(QThread::currentThread() == this->thread());
55
56 m_d->requestedImage = image;
57 m_d->requestedFrame = frame;
58 m_d->isCancelled = false;
59 m_d->requestedRegion = !regionOfInterest.isEmpty() ? regionOfInterest : image->bounds();
60
61 KisImageAnimationInterface *animation = m_d->requestedImage->animationInterface();
62
63 m_d->imageRequestConnections.clear();
64 m_d->imageRequestConnections.addConnection(
65 animation, SIGNAL(sigFrameReady(int)),
66 this, SLOT(slotFrameRegenerationFinished(int)),
67 Qt::DirectConnection);
68
69 m_d->imageRequestConnections.addConnection(
70 animation, SIGNAL(sigFrameCancelled()),
72 Qt::AutoConnection);
73
74 m_d->regenerationTimeout.start();
75 animation->requestFrameRegeneration(m_d->requestedFrame, m_d->requestedRegion, flags & Cancellable, std::move(frameGenerationLock));
76}
void requestFrameRegeneration(int frameId, const KisRegion &dirtyRegion, bool isCancellable, KisLockFrameGenerationLock &&lock)
QRect bounds() const override
bool isEmpty() const

References KisImage::bounds(), Cancellable, KisRegion::isEmpty(), KIS_SAFE_ASSERT_RECOVER_NOOP, m_d, KisImageAnimationInterface::requestFrameRegeneration(), sigFrameCancelled(), slotFrameRegenerationCancelled(), and slotFrameRegenerationFinished().

◆ startFrameRegeneration() [2/2]

void KisAsyncAnimationRendererBase::startFrameRegeneration ( KisImageSP image,
int frame,
Flags flags,
KisLockFrameGenerationLock && frameGenerationLock )

Convenience overload that regenerates the full image

Definition at line 78 of file KisAsyncAnimationRendererBase.cpp.

79{
80 startFrameRegeneration(image, frame, KisRegion(), flags, std::move(frameGenerationLock));
81}
void startFrameRegeneration(KisImageSP image, int frame, const KisRegion &regionOfInterest, Flags flags, KisLockFrameGenerationLock &&frameGenerationLock)

References startFrameRegeneration().

Member Data Documentation

◆ imageRequestConnections

KisSignalAutoConnectionsStore KisAsyncAnimationRendererBase::imageRequestConnections

Definition at line 26 of file KisAsyncAnimationRendererBase.cpp.

◆ isCancelled

bool KisAsyncAnimationRendererBase::isCancelled = false

Definition at line 31 of file KisAsyncAnimationRendererBase.cpp.

◆ m_d

const QScopedPointer<Private> KisAsyncAnimationRendererBase::m_d
private

Definition at line 150 of file KisAsyncAnimationRendererBase.h.

◆ regenerationTimeout

QTimer KisAsyncAnimationRendererBase::regenerationTimeout

Definition at line 27 of file KisAsyncAnimationRendererBase.cpp.

◆ requestedFrame

int KisAsyncAnimationRendererBase::requestedFrame = -1

Definition at line 30 of file KisAsyncAnimationRendererBase.cpp.

◆ requestedImage

KisImageSP KisAsyncAnimationRendererBase::requestedImage

Definition at line 29 of file KisAsyncAnimationRendererBase.cpp.

◆ requestedRegion

KisRegion KisAsyncAnimationRendererBase::requestedRegion

Definition at line 32 of file KisAsyncAnimationRendererBase.cpp.


The documentation for this class was generated from the following files: