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

#include <recorder_writer.h>

+ Inheritance diagram for RecorderWriterManager:

Classes

class  Private
 

Signals

void frameWriteFailed ()
 
void lowPerformanceWarning ()
 
void recorderStopWarning ()
 
void startCapturing (int writerId, int index, KisPaintDeviceSP device)
 
void started ()
 
void stopped ()
 

Public Member Functions

RecorderWriterManager & operator= (const RecorderWriterManager &)=delete
 
RecorderWriterManager & operator= (RecorderWriterManager &&)=delete
 
 RecorderWriterManager ()=delete
 
 RecorderWriterManager (const RecorderExportSettings &es)
 
 RecorderWriterManager (const RecorderWriterManager &)=delete
 
 RecorderWriterManager (RecorderWriterManager &&)=delete
 
void setCanvas (QPointer< KisCanvas2 > canvas)
 
void setEnabled (bool enabled)
 
void setup (const RecorderWriterSettings &settings)
 
void start (bool toggleEnabled=true)
 
bool stop (bool toggleEnabled=true)
 
 ~RecorderWriterManager ()
 

Public Attributes

ThreadCounter recorderThreads {}
 

Private Slots

void onCapturingDone (int workerId, bool success)
 
void onImageModified ()
 
void onTimer ()
 
void onToolChanged (const QString &toolId)
 
void onToolPrimaryActionActivated (bool activated)
 

Private Attributes

Private *const d
 
const RecorderExportSettings & exporterSettings
 

Detailed Description

Definition at line 100 of file recorder_writer.h.

Constructor & Destructor Documentation

◆ RecorderWriterManager() [1/4]

RecorderWriterManager::RecorderWriterManager ( const RecorderExportSettings & es)
explicit

Definition at line 497 of file recorder_writer.cpp.

498 : d(new Private(this, recorderThreads))
499 , exporterSettings(es)
500{
501 d->timer.setTimerType(Qt::PreciseTimer);
502}
ThreadCounter recorderThreads
const RecorderExportSettings & exporterSettings

References d, and RecorderWriterManager::Private::timer.

◆ ~RecorderWriterManager()

RecorderWriterManager::~RecorderWriterManager ( )

Definition at line 504 of file recorder_writer.cpp.

505{
506 delete d;
507}

References d.

◆ RecorderWriterManager() [2/4]

RecorderWriterManager::RecorderWriterManager ( )
delete

◆ RecorderWriterManager() [3/4]

RecorderWriterManager::RecorderWriterManager ( const RecorderWriterManager & )
delete

◆ RecorderWriterManager() [4/4]

RecorderWriterManager::RecorderWriterManager ( RecorderWriterManager && )
delete

Member Function Documentation

◆ frameWriteFailed

void RecorderWriterManager::frameWriteFailed ( )
signal

◆ lowPerformanceWarning

void RecorderWriterManager::lowPerformanceWarning ( )
signal

◆ onCapturingDone

void RecorderWriterManager::onCapturingDone ( int workerId,
bool success )
privateslot

Definition at line 655 of file recorder_writer.cpp.

656{
657 if (workerId >= d->writerPool.size())
658 return;
659 d->writerPool[workerId].inUse = false;
660 d->writerPool[workerId].thread->setPriority(QThread::IdlePriority);
662 if (!success) {
663 stop();
664 Q_EMIT frameWriteFailed();
665 }
666}
bool stop(bool toggleEnabled=true)

References d, ThreadCounter::decUsedAndNotify(), frameWriteFailed(), recorderThreads, stop(), and RecorderWriterManager::Private::writerPool.

◆ onImageModified

void RecorderWriterManager::onImageModified ( )
privateslot

◆ onTimer

void RecorderWriterManager::onTimer ( )
privateslot

Definition at line 607 of file recorder_writer.cpp.

608{
609 if (!d->enabled || !d->canvas)
610 return;
611
612 // take snapshots only if main window is active
613 // else some dialogs like filters may disappear when canvas->image()->lock() is called
614 if (qobject_cast<KisMainWindow*>(QApplication::activeWindow()) == nullptr)
615 return;
616
618 (d->canvas->image()->isIsolatingLayer() || d->canvas->image()->isIsolatingGroup())) {
619 return;
620 }
621
622 if (!d->imageModified)
623 return;
624
625 d->imageModified = false;
626
627 if (!d->canStartCapture())
628 return;
629
631
632 if (d->freeWriterId == -1)
633 {
634 Q_EMIT lowPerformanceWarning();
635 return;
636 }
637
638 d->writerPool[d->freeWriterId].inUse = true;
639 d->writerPool[d->freeWriterId].thread->setPriority(QThread::HighPriority);
641
642 RecorderImageCopyingJob *job = new RecorderImageCopyingJob(d->canvas->image()->projection(),
643 d->canvas->image()->bounds(),
645 ++d->partIndex);
646
647 connect(job,
648 SIGNAL(sigImageCopyingDoneWithData(int, int, KisPaintDeviceSP)),
649 this,
650 SIGNAL(startCapturing(int, int, KisPaintDeviceSP)));
651
652 d->canvas->image()->addSpontaneousJob(job);
653}
void startCapturing(int writerId, int index, KisPaintDeviceSP device)

References RecorderWriterManager::Private::canStartCapture(), RecorderWriterManager::Private::canvas, d, RecorderWriterManager::Private::enabled, RecorderWriterManager::Private::freeWriterId, RecorderWriterManager::Private::imageModified, ThreadCounter::incUsedAndNotify(), lowPerformanceWarning(), RecorderWriterManager::Private::partIndex, recorderThreads, RecorderWriterSettings::recordIsolateLayerMode, RecorderWriterManager::Private::searchForFreeWriter(), RecorderWriterManager::Private::settings, startCapturing(), and RecorderWriterManager::Private::writerPool.

◆ onToolChanged

void RecorderWriterManager::onToolChanged ( const QString & toolId)
privateslot

Definition at line 680 of file recorder_writer.cpp.

681{
682 d->isForceBlackTool = forceBlacklistedTools.contains(toolId);
683 d->isActivateBlackTool = activateBlacklistedTools.contains(toolId);
684}
volatile std::atomic_bool isActivateBlackTool
volatile std::atomic_bool isForceBlackTool

References d, RecorderWriterManager::Private::isActivateBlackTool, and RecorderWriterManager::Private::isForceBlackTool.

◆ onToolPrimaryActionActivated

void RecorderWriterManager::onToolPrimaryActionActivated ( bool activated)
privateslot

Definition at line 686 of file recorder_writer.cpp.

687{
688 d->toolActivated = activated;
689}
volatile std::atomic_bool toolActivated

References d, and RecorderWriterManager::Private::toolActivated.

◆ operator=() [1/2]

RecorderWriterManager & RecorderWriterManager::operator= ( const RecorderWriterManager & )
delete

◆ operator=() [2/2]

RecorderWriterManager & RecorderWriterManager::operator= ( RecorderWriterManager && )
delete

◆ recorderStopWarning

void RecorderWriterManager::recorderStopWarning ( )
signal

◆ setCanvas()

void RecorderWriterManager::setCanvas ( QPointer< KisCanvas2 > canvas)

Definition at line 509 of file recorder_writer.cpp.

510{
511 // Restart writers if canvas changes
512 bool restart = d->timer.isActive();
513 if (restart) {
514 stop(false);
515 }
516
517 if (d->canvas) {
518 KoToolProxy *proxy = d->canvas->toolProxy();
519 KisToolProxy *kritaProxy = dynamic_cast<KisToolProxy*>(proxy);
520
521 disconnect(proxy, SIGNAL(toolChanged(QString)), this, SLOT(onToolChanged(QString)));
522 disconnect(kritaProxy, SIGNAL(toolPrimaryActionActivated(bool)), this, SLOT(onToolPrimaryActionActivated(bool)));
523 disconnect(d->canvas->image(), SIGNAL(sigImageUpdated(QRect)), this, SLOT(onImageModified()));
524 }
525
526 d->canvas = canvas;
527
528 if (d->canvas) {
529 KoToolProxy *proxy = d->canvas->toolProxy();
530 KisToolProxy *kritaProxy = dynamic_cast<KisToolProxy*>(proxy);
531
532 connect(proxy, SIGNAL(toolChanged(QString)), this, SLOT(onToolChanged(QString)),
533 Qt::DirectConnection); // need to handle it even if our event loop is not running
534 connect(kritaProxy, SIGNAL(toolPrimaryActionActivated(bool)), this, SLOT(onToolPrimaryActionActivated(bool)),
535 Qt::DirectConnection);
536 connect(d->canvas->image(), SIGNAL(sigImageUpdated(QRect)), this, SLOT(onImageModified()),
537 Qt::DirectConnection); // because it spams
538 }
539
540 if (restart) {
541 start(false);
542 }
543}
void start(bool toggleEnabled=true)
void onToolPrimaryActionActivated(bool activated)
void onToolChanged(const QString &toolId)

References RecorderWriterManager::Private::canvas, d, onImageModified(), onToolChanged(), onToolPrimaryActionActivated(), start(), stop(), and RecorderWriterManager::Private::timer.

◆ setEnabled()

void RecorderWriterManager::setEnabled ( bool enabled = false)

Definition at line 602 of file recorder_writer.cpp.

603{
604 d->enabled = enabled;
605}

References d, and RecorderWriterManager::Private::enabled.

◆ setup()

void RecorderWriterManager::setup ( const RecorderWriterSettings & settings)

Definition at line 545 of file recorder_writer.cpp.

546{
547 // Restart writers if setup changes
548 bool restart = d->timer.isActive();
549 if (restart) {
550 stop(false);
551 }
552
553 d->settings = settings;
554 d->outputDir.setPath(settings.outputDirectory);
555
557
558 if (restart) {
559 start(false);
560 }
561}
int findLastIndex(const QString &directory)

References d, RecorderWriterManager::Private::findLastIndex(), RecorderWriterManager::Private::outputDir, RecorderWriterSettings::outputDirectory, RecorderWriterManager::Private::partIndex, RecorderWriterManager::Private::settings, start(), stop(), and RecorderWriterManager::Private::timer.

◆ start()

void RecorderWriterManager::start ( bool toggleEnabled = true)

Definition at line 563 of file recorder_writer.cpp.

564{
565 if (d->timer.isActive())
566 return;
567
568 if (!d->canvas)
569 return;
570
571 d->enabled = true;
572 d->imageModified = false;
573
574 connect(&d->timer, SIGNAL (timeout()), this, SLOT (onTimer()));
576 d->interval = static_cast<int>(1000.0/static_cast<double>(exporterSettings.fps));
577 } else {
578 d->interval = static_cast<int>(qMax(d->settings.captureInterval, .1) * 1000.0);
579 }
581 d->timer.start(d->interval);
582 if (toggleEnabled) {
583 Q_EMIT started();
584 }
585}

References RecorderWriterManager::Private::canvas, RecorderWriterSettings::captureInterval, d, RecorderWriterManager::Private::enabled, RecorderWriterManager::Private::enlargeWriterPool(), exporterSettings, RecorderExportSettings::fps, RecorderWriterManager::Private::imageModified, RecorderWriterManager::Private::interval, onTimer(), RecorderWriterSettings::realTimeCaptureMode, RecorderWriterManager::Private::settings, started(), and RecorderWriterManager::Private::timer.

◆ startCapturing

void RecorderWriterManager::startCapturing ( int writerId,
int index,
KisPaintDeviceSP device )
signal

◆ started

void RecorderWriterManager::started ( )
signal

◆ stop()

bool RecorderWriterManager::stop ( bool toggleEnabled = true)

Definition at line 587 of file recorder_writer.cpp.

588{
589 //Check if the timer is active, so that we don't try to clear the writer pool multiple times
590 if (!d->timer.isActive())
591 return true;
592
593 d->timer.stop();
594 auto result = d->clearWriterPool();
596 if (toggleEnabled) {
597 Q_EMIT stopped();
598 }
599 return result;
600}
bool setUsed(int value)

References RecorderWriterManager::Private::clearWriterPool(), d, recorderThreads, ThreadCounter::setUsed(), stopped(), and RecorderWriterManager::Private::timer.

◆ stopped

void RecorderWriterManager::stopped ( )
signal

Member Data Documentation

◆ d

Private* const RecorderWriterManager::d
private

Definition at line 144 of file recorder_writer.h.

◆ exporterSettings

const RecorderExportSettings& RecorderWriterManager::exporterSettings
private

Definition at line 145 of file recorder_writer.h.

◆ recorderThreads

ThreadCounter RecorderWriterManager::recorderThreads {}

Definition at line 140 of file recorder_writer.h.

140{};

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