File indexing completed on 2024-05-26 04:32:43
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Saurabh Kumar <saurabhk660@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KISASYNCSTORYBOARDTHUMBNAILRENDERSCHEDULER_H 0008 #define KISASYNCSTORYBOARDTHUMBNAILRENDERSCHEDULER_H 0009 0010 #include <QObject> 0011 #include <QVector> 0012 0013 #include <kis_image.h> 0014 0015 class KisPaintDevice; 0016 class KisAsyncStoryboardThumbnailRenderer; 0017 0018 /** 0019 * @class KisStoryboardThumbnailRenderScheduler 0020 * @brief This class maintains queues of dirty frames sorted in the order of proximity 0021 * to the last changed frame. It regenerates the frames emits the paintdevice for each 0022 * of the frames. The m_changedFramesQueue list is given preference. 0023 */ 0024 class KisStoryboardThumbnailRenderScheduler : public QObject 0025 { 0026 Q_OBJECT 0027 public: 0028 KisStoryboardThumbnailRenderScheduler(QObject *parent); 0029 ~KisStoryboardThumbnailRenderScheduler(); 0030 0031 /** 0032 * @brief Sets an image, the class takes an image, clones it and calls frame 0033 * regeneration on the clone so do not pass cloned image explicitly. The image 0034 * should be set only_once and not every time before scheduling a frame for 0035 * regeneration. Setting an image cancels rendering of all previously scheduled frames. 0036 * @param image Image whose frames are to be rendered. 0037 */ 0038 void setImage(KisImageSP image); 0039 /** 0040 * @brief Adds the frame to the list of "to be regenerated" frames. 0041 * @param frame To be regenerated frame 0042 * @param affected Denotes whether this frame was directly changed or affected 0043 * by changes made to other keyframes. 0044 */ 0045 void scheduleFrameForRegeneration(int frame, bool affected); 0046 /** 0047 * @brief Cancels all frame rendering. Empties all queues and cancels the current rendering, if any. 0048 */ 0049 void cancelAllFrameRendering(); 0050 /** 0051 * @brief Cancel rendering of a single frame. 0052 * @param frame The frame whose rendering is to be cancelled. 0053 */ 0054 void cancelFrameRendering(int frame); 0055 0056 public Q_SLOTS: 0057 void slotStartFrameRendering(); 0058 0059 private Q_SLOTS: 0060 /** 0061 * @brief Emits @c sigFrameCompleted(int,KisPaintDeviceSP) if the regeneration was complete 0062 * and calls regeneration of the next frame in queue. 0063 */ 0064 void slotFrameRegenerationCompleted(int frame, KisPaintDeviceSP contents); 0065 0066 /** 0067 * @brief Emits @c sigFrameCancelled(int) and schedules the next frame for regeneration. 0068 */ 0069 void slotFrameRegenerationCancelled(int frame); 0070 0071 private: 0072 /** 0073 * @brief Sorts the @c m_affectedFramesQueue based on proximity to the last changed frame 0074 */ 0075 void sortAffectedFrameQueue(); 0076 0077 /** 0078 * @brief Renders the next frame, either from affected or changed queue. Changed 0079 * queue is given preference. It removes the frame from the queue right after 0080 * calling @c startFrameRegeneration() 0081 */ 0082 void renderNextFrame(); 0083 0084 Q_SIGNALS: 0085 void sigFrameCompleted(int frame, KisPaintDeviceSP dev); 0086 void sigFrameCancelled(int frame); 0087 0088 private: 0089 QVector<int> m_changedFramesQueue; 0090 QVector<int> m_affectedFramesQueue; 0091 KisAsyncStoryboardThumbnailRenderer *m_renderer; 0092 KisImageSP m_image; 0093 int m_currentFrame; 0094 }; 0095 0096 #endif