Krita Source Code Documentation
Loading...
Searching...
No Matches
recorder_writer.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2020 Dmitrii Utkin <loentar@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 */
6
7#ifndef RECORDER_WRITER_H
8#define RECORDER_WRITER_H
9
10#include "kis_types.h"
11#include "recorder_format.h"
12
13#include <QMutex>
14#include <QObject>
15#include <QPointer>
16#include <kis_paint_device.h>
17
19class RecorderConfig;
20class KisCanvas2;
21class QDir;
22
35
36// This class is used to provide mechanism ro sync the number of available
37// and used recording threads between the GUI and the RecorderWriterManager
38class ThreadCounter : public QObject
39{
40 Q_OBJECT
41public:
42 ThreadCounter() = default;
43 ThreadCounter(const ThreadCounter&) = delete;
47
48 bool set(int value);
49 void setAndNotify(int value);
50 unsigned int get() const;
51
52 bool setUsed(int value);
53 void setUsedAndNotify(int value);
54 void incUsedAndNotify();
55 void decUsedAndNotify();
56 unsigned int getUsed() const;
57
58Q_SIGNALS:
59 void notifyValueChange(bool valueWasIncreased);
60 void notifyInUseChange(bool valueWasIncreased);
61
62private:
63 bool setUsedImpl(int value);
64
65private:
66 unsigned int threads;
67 unsigned int inUse;
68 QMutex inUseMutex;
69};
70
71class RecorderWriter : public QObject
72{
73 Q_OBJECT
74public:
76 unsigned int i,
79 const QDir& d);
81
82 RecorderWriter() = delete;
87
88 bool isActive();
89
90Q_SIGNALS:
91 void capturingDone(int writerId, bool success);
92
93public Q_SLOTS:
94 void onCaptureImage(int index, QVector<QRect> regions, KisPaintDeviceSP device);
95
96private:
97 bool onCaptureImageImpl(int index, QRect region, KisPaintDevice* device);
98
99private:
100 class Private;
101 Private *const d;
102 unsigned int id;
103};
104
105class RecorderWriterManager : public QObject
106{
107 Q_OBJECT
108public:
111
117
118 // restarts recorder
119 void setCanvas(QPointer<KisCanvas2> canvas);
120 // restarts recorder
121 void setup(const RecorderWriterSettings &settings);
122
123 void start(bool toggleEnabled, bool restoreState);
124 bool stop(bool toggleEnabled, bool saveState);
125
126 void setEnabled(bool enabled);
127
129 void saveState();
131 void restoreState();
132
133 // A note about tail frames:
134 // They are needed for focused recording. It is possible that the recording is stopped with the last frame being
135 // very zoomed in, so if a user tries to export the timelapse in this state, it won't properly dispaly the resulting
136 // artwork. One option to fix that is to capture an overview frame whenever a timelapse is epxorted, but the artwork
137 // may have changed while recording was off, so we can't do that
138 //
139 // My solution is a "tail" frame, an overivew captured whenever recording is stopped, and removed if recording is
140 // resumed, to avoid adding dead air to timelapses.
141 //
142 // To avoid big jumps we capture multiple of them with interpolated motion with the last frame, like any other
143 // frame.
144 //
145 // They are technically not needed if the user isn't using focused recording, but they don't hurt to have.
146
147 // Saving the oldRegion varaible, for smooth frame motion, it is very cheap to do as it's literally just 16 bytes,
148 // so we're free to do it excessively without worrying. We also use it to keep track of the region with multiple
149 // files open, instead of doing that with some global state
150 void saveRegion();
151 void tryRestoreRegion();
152
153 bool canStartCapture() const;
154
155Q_SIGNALS:
156 void started();
157 void stopped();
161
162private Q_SLOTS:
163 void onTimer();
164 void onCapturingDone(int workerId, bool success);
165 void onImageModified();
166 void onToolChanged(const QString &toolId);
167 void onToolPrimaryActionActivated(bool activated);
168
169public:
171
172private:
173 class Private;
174 Private *const d;
176
177};
178
179#endif // RECORDER_WRITER_H
float value(const T *src, size_t ch)
bool canStartCapture() const
void saveState()
Generate a tail and save the recording region.
RecorderWriterManager()=delete
void start(bool toggleEnabled, bool restoreState)
bool stop(bool toggleEnabled, bool saveState)
void restoreState()
Remove the tail and restore region from a file.
void onCapturingDone(int workerId, bool success)
void onToolPrimaryActionActivated(bool activated)
RecorderWriterManager & operator=(RecorderWriterManager &&)=delete
void setCanvas(QPointer< KisCanvas2 > canvas)
void setEnabled(bool enabled)
void setup(const RecorderWriterSettings &settings)
ThreadCounter recorderThreads
RecorderWriterManager & operator=(const RecorderWriterManager &)=delete
const RecorderExportSettings & exporterSettings
RecorderWriterManager(const RecorderWriterManager &)=delete
void onToolChanged(const QString &toolId)
RecorderWriterManager(RecorderWriterManager &&)=delete
RecorderWriter()=delete
unsigned int id
RecorderWriter(RecorderWriter &&)=delete
void onCaptureImage(int index, QVector< QRect > regions, KisPaintDeviceSP device)
RecorderWriter & operator=(RecorderWriter &&)=delete
bool onCaptureImageImpl(int index, QRect region, KisPaintDevice *device)
Private *const d
RecorderWriter & operator=(const RecorderWriter &)=delete
void capturingDone(int writerId, bool success)
RecorderWriter(const RecorderWriter &)=delete
void setUsedAndNotify(int value)
ThreadCounter(const ThreadCounter &)=delete
bool setUsedImpl(int value)
unsigned int getUsed() const
unsigned int get() const
void notifyValueChange(bool valueWasIncreased)
ThreadCounter(ThreadCounter &&)=delete
ThreadCounter & operator=(const ThreadCounter &)=delete
ThreadCounter()=default
unsigned int threads
void setAndNotify(int value)
bool setUsed(int value)
bool set(int value)
unsigned int inUse
ThreadCounter & operator=(ThreadCounter &&)=delete
void notifyInUseChange(bool valueWasIncreased)
RecorderFormat