Krita Source Code Documentation
Loading...
Searching...
No Matches
RecorderWriterManager::Private Class Reference

Public Member Functions

bool canStartCapture ()
 
bool clearWriterPool ()
 
void createWriters ()
 
int findLastIndex (const QString &directory)
 
 Private (RecorderWriterManager *q_ptr, ThreadCounter &rt)
 
void searchForFreeWriter ()
 

Public Attributes

QPointer< KisCanvas2 > canvas
 
bool captureTail = false
 
bool destroyingWriters = false
 
volatile std::atomic_bool enabled = false
 
std::atomic_int freeWriterId = -1
 
volatile std::atomic_bool imageModified = false
 
int interval = 1
 
volatile std::atomic_bool isActivateBlackTool = false
 
volatile std::atomic_bool isForceBlackTool = false
 
QRect oldRegion = QRect(-1, -1, -1, -1)
 
QDir outputDir
 
int partIndex = 0
 
RecorderWriterManager *const q
 
ThreadCounter & recorderThreads
 
RecorderWriterSettings settings {}
 
QTimer timer
 
volatile std::atomic_bool toolActivated = false
 
WriterPool writerPool
 

Detailed Description

Definition at line 367 of file recorder_writer.cpp.

Constructor & Destructor Documentation

◆ Private()

RecorderWriterManager::Private::Private ( RecorderWriterManager * q_ptr,
ThreadCounter & rt )
inline

Definition at line 370 of file recorder_writer.cpp.

371 : q(q_ptr)
372 , recorderThreads(rt)
373 {}
RecorderWriterManager *const q

Member Function Documentation

◆ canStartCapture()

bool RecorderWriterManager::Private::canStartCapture ( )
inline

Definition at line 499 of file recorder_writer.cpp.

500 {
502 return false;
504 return false;
505 return true;
506 }
volatile std::atomic_bool toolActivated
volatile std::atomic_bool isActivateBlackTool
volatile std::atomic_bool isForceBlackTool

References isActivateBlackTool, isForceBlackTool, and toolActivated.

◆ clearWriterPool()

bool RecorderWriterManager::Private::clearWriterPool ( )
inline

Definition at line 420 of file recorder_writer.cpp.

421 {
422 QScopedValueRollback rollback(destroyingWriters, true);
423 bool result = true;
424 bool alreadyWarn = false;
425 bool alreadyErr = false;
426
427 // Wait until all the jobs processes
428 canvas->image()->waitForDone();
429
430 // Make sure the signals are delivered
431 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
432
433 for (auto &el : writerPool) {
434 el.thread->quit();
435 el.thread->wait(RecorderConst::waitThreadTimeoutMs);
436 disconnect(el.writer.get(), SIGNAL(capturingDone(int, bool)), q, SLOT(onCapturingDone(int, bool)));
437 if (el.thread->isRunning())
438 {
439 if (!alreadyWarn) {
440 warnResources << "One of the Recorder WriterPool threads has been blocked and has to be terminated. "
441 << "Thread Name: " << el.thread->objectName();
442 alreadyWarn = true;
443 }
444 el.thread->terminate();
445 if (!el.thread->wait(RecorderConst::waitThreadTimeoutMs))
446 {
447 if (!alreadyErr) {
448 errResources << "Something odd has been happen. Krita was unable to stop one of the Recorder WriterPool Threads. "
449 << "Thread Name: " << el.thread->objectName();
450 alreadyErr = true;
451 }
452 result = false;
453 }
454 }
455
456 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
457 }
458
459 writerPool.clear();
460 freeWriterId = -1;
461
462 if (!result)
463 Q_EMIT q->recorderStopWarning();
464
465 return result;
466 }
void onCapturingDone(int workerId, bool success)
#define errResources
Definition kis_debug.h:113
#define warnResources
Definition kis_debug.h:92
constexpr int waitThreadTimeoutMs

References canvas, destroyingWriters, errResources, freeWriterId, RecorderWriterManager::onCapturingDone(), q, RecorderWriterManager::recorderStopWarning(), RecorderConst::waitThreadTimeoutMs, warnResources, and writerPool.

◆ createWriters()

void RecorderWriterManager::Private::createWriters ( )
inline

Definition at line 468 of file recorder_writer.cpp.

469 {
470 writerPool.reserve(recorderThreads.get());
471 while (static_cast<int>(recorderThreads.get()) > writerPool.size()) {
472 auto newWorkerId = writerPool.size();
473 freeWriterId = newWorkerId - 1; // Set the value to the last existing writerEl index ->
474 // The next call of searchForFreeWriter() will than automatically find newWorkerId
475
476 writerPool.append(WriterPoolEl(q, newWorkerId, canvas, settings, outputDir));
477
478 auto writerPtr = writerPool[newWorkerId].writer;
479 auto threadPtr = writerPool[newWorkerId].thread;
480 threadPtr->setObjectName(QString("Krita-Recorder-WriterPool#%1").arg(newWorkerId));
481 connect(writerPtr.get(), SIGNAL(capturingDone(int, bool)), q, SLOT(onCapturingDone(int, bool)));
482 writerPtr->moveToThread(threadPtr.get());
483 threadPtr->start(QThread::IdlePriority);
484 }
485 }
RecorderWriterSettings settings
unsigned int get() const

References canvas, freeWriterId, ThreadCounter::get(), RecorderWriterManager::onCapturingDone(), outputDir, q, recorderThreads, settings, and writerPool.

◆ findLastIndex()

int RecorderWriterManager::Private::findLastIndex ( const QString & directory)
inline

Definition at line 394 of file recorder_writer.cpp.

395 {
396 QElapsedTimer dbgTimer;
397 dbgTimer.start();
398
399 QDirIterator dirIterator(directory);
401 const QRegularExpression &snapshotFilePattern = RecorderConst::snapshotFilePatternFor(extension);
402
403 int recordIndex = -1;
404 while (dirIterator.hasNext()) {
405 dirIterator.next();
406
407 const QString &fileName = dirIterator.fileName();
408 const QRegularExpressionMatch &match = snapshotFilePattern.match(fileName);
409 if (match.hasMatch()) {
410 int index = match.captured(1).toInt();
411 if (recordIndex < index)
412 recordIndex = index;
413 }
414 }
415 dbgTools << "findLastPartNumber for" << directory << ": " << dbgTimer.elapsed() << "ms";
416
417 return recordIndex;
418 }
#define dbgTools
Definition kis_debug.h:52
QRegularExpression snapshotFilePatternFor(const QString &extension)
QLatin1String fileExtension(RecorderFormat format)

References dbgTools, RecorderFormatInfo::fileExtension(), RecorderWriterSettings::format, settings, and RecorderConst::snapshotFilePatternFor().

◆ searchForFreeWriter()

void RecorderWriterManager::Private::searchForFreeWriter ( )
inline

Definition at line 487 of file recorder_writer.cpp.

488 {
489 auto j = freeWriterId + 1;
490 for(auto i = 0; i < writerPool.size(); i++, j++)
491 {
492 freeWriterId = j % writerPool.size();
493 if (writerPool[freeWriterId].thread->isRunning() && !writerPool[freeWriterId].inUse)
494 return;
495 }
496 freeWriterId = -1;
497 }

References freeWriterId, and writerPool.

Member Data Documentation

◆ canvas

QPointer<KisCanvas2> RecorderWriterManager::Private::canvas

Definition at line 385 of file recorder_writer.cpp.

◆ captureTail

bool RecorderWriterManager::Private::captureTail = false

Definition at line 390 of file recorder_writer.cpp.

◆ destroyingWriters

bool RecorderWriterManager::Private::destroyingWriters = false

Definition at line 392 of file recorder_writer.cpp.

◆ enabled

volatile std::atomic_bool RecorderWriterManager::Private::enabled = false

Definition at line 377 of file recorder_writer.cpp.

◆ freeWriterId

std::atomic_int RecorderWriterManager::Private::freeWriterId = -1

Definition at line 383 of file recorder_writer.cpp.

◆ imageModified

volatile std::atomic_bool RecorderWriterManager::Private::imageModified = false

Definition at line 378 of file recorder_writer.cpp.

◆ interval

int RecorderWriterManager::Private::interval = 1

Definition at line 384 of file recorder_writer.cpp.

◆ isActivateBlackTool

volatile std::atomic_bool RecorderWriterManager::Private::isActivateBlackTool = false

Definition at line 380 of file recorder_writer.cpp.

◆ isForceBlackTool

volatile std::atomic_bool RecorderWriterManager::Private::isForceBlackTool = false

Definition at line 379 of file recorder_writer.cpp.

◆ oldRegion

QRect RecorderWriterManager::Private::oldRegion = QRect(-1, -1, -1, -1)

Definition at line 391 of file recorder_writer.cpp.

◆ outputDir

QDir RecorderWriterManager::Private::outputDir

Definition at line 389 of file recorder_writer.cpp.

◆ partIndex

int RecorderWriterManager::Private::partIndex = 0

Definition at line 382 of file recorder_writer.cpp.

◆ q

RecorderWriterManager* const RecorderWriterManager::Private::q

Definition at line 375 of file recorder_writer.cpp.

◆ recorderThreads

ThreadCounter& RecorderWriterManager::Private::recorderThreads

Definition at line 376 of file recorder_writer.cpp.

◆ settings

RecorderWriterSettings RecorderWriterManager::Private::settings {}

Definition at line 388 of file recorder_writer.cpp.

388{};

◆ timer

QTimer RecorderWriterManager::Private::timer

Definition at line 386 of file recorder_writer.cpp.

◆ toolActivated

volatile std::atomic_bool RecorderWriterManager::Private::toolActivated = false

Definition at line 381 of file recorder_writer.cpp.

◆ writerPool

WriterPool RecorderWriterManager::Private::writerPool

Definition at line 387 of file recorder_writer.cpp.


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