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 "recorder_format.h"
11
12#include <QObject>
13#include <QPointer>
14#include <QMutex>
15
17class RecorderConfig;
18class KisCanvas2;
19class QDir;
20
32
33// This class is used to provide mechanism ro sync the number of available
34// and used recording threads between the GUI and the RecorderWriterManager
35class ThreadCounter : public QObject
36{
37 Q_OBJECT
38public:
39 ThreadCounter() = default;
40 ThreadCounter(const ThreadCounter&) = delete;
44
45 bool set(int value);
46 void setAndNotify(int value);
47 unsigned int get() const;
48
49 bool setUsed(int value);
50 void setUsedAndNotify(int value);
51 void incUsedAndNotify();
52 void decUsedAndNotify();
53 unsigned int getUsed() const;
54
55Q_SIGNALS:
56 void notifyValueChange(bool valueWasIncreased);
57 void notifyInUseChange(bool valueWasIncreased);
58
59private:
60 bool setUsedImpl(int value);
61
62private:
63 unsigned int threads;
64 unsigned int inUse;
65 QMutex inUseMutex;
66};
67
69
70class RecorderWriter : public QObject
71{
72 Q_OBJECT
73public:
74 static constexpr int STATUS_OK = 0;
75 static constexpr int STATUS_ERROR = 1;
76 static constexpr int STATUS_BLOCKED = 2;
77
79 unsigned int i,
82 const QDir& d,
85
86 RecorderWriter() = delete;
91
92Q_SIGNALS:
93 void capturingDone(int writerId, int status);
94
95public Q_SLOTS:
96 void onCaptureImage(int writerId);
97
98private:
99 class Private;
100 Private *const d;
101 unsigned int id;
102};
103
104class RecorderWriterManager : public QObject
105{
106 Q_OBJECT
107public:
110
116
117 // restarts recorder
118 void setCanvas(QPointer<KisCanvas2> canvas);
119 // restarts recorder
120 void setup(const RecorderWriterSettings &settings);
121
122 void start(bool toggleEnabled = true);
123 bool stop(bool toggleEnabled = true);
124
125 void setEnabled(bool enabled);
126
127 // This does not do its own synchronization! At the time of writing, the
128 // behavior is:
129 // * Only the main thread writes to this. It takes the capture mutex.
130 // * Reading from the main thread does not take locks.
131 // * Reading from writer threads takes the capture mutex.
132 bool canStartCapture() const;
133
134 // This does not do its own synchronization, make sure access here is
135 // serialized! At the time of writing, this is accomplished by only calling
136 // this while the capture mutex is held.
138
139 QMutex *captureMutex();
140
141Q_SIGNALS:
142 void started();
143 void stopped();
147
148 void startCapturing(int writerId);
149
150private Q_SLOTS:
151 void onTimer();
152 void onCapturingDone(int workerId, int status);
153 void onImageModified();
154 void onToolChanged(const QString &toolId);
155 void onToolPrimaryActionActivated(bool activated);
156
157public:
159
160private:
161 class Private;
162 Private *const d;
164
165};
166
167#endif // RECORDER_WRITER_H
float value(const T *src, size_t ch)
RecorderWriterManager()=delete
void start(bool toggleEnabled=true)
void startCapturing(int writerId)
void onToolPrimaryActionActivated(bool activated)
RecorderWriterManager & operator=(RecorderWriterManager &&)=delete
void setCanvas(QPointer< KisCanvas2 > canvas)
bool stop(bool toggleEnabled=true)
void setEnabled(bool enabled)
void setup(const RecorderWriterSettings &settings)
ThreadCounter recorderThreads
RecorderWriterManager & operator=(const RecorderWriterManager &)=delete
const RecorderExportSettings & exporterSettings
void onCapturingDone(int workerId, int status)
RecorderWriterManager(const RecorderWriterManager &)=delete
void onToolChanged(const QString &toolId)
RecorderWriterManager(RecorderWriterManager &&)=delete
static constexpr int STATUS_OK
RecorderWriter()=delete
static constexpr int STATUS_ERROR
unsigned int id
void onCaptureImage(int writerId)
RecorderWriter(RecorderWriter &&)=delete
RecorderWriter & operator=(RecorderWriter &&)=delete
Private *const d
RecorderWriter & operator=(const RecorderWriter &)=delete
void capturingDone(int writerId, int status)
RecorderWriter(const RecorderWriter &)=delete
static constexpr int STATUS_BLOCKED
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