mirror of
https://bitbucket.org/smil3y/kde-extraapps.git
synced 2025-02-23 18:32:53 +00:00
gwenview: do not thread document jobs
threading it does not help when an image requires gigabytes of memory to store to begin with (such as when the image is resized to 30000x20000, it requires a bit less than 2GB of memory and that's because its ARGB), the document jobs were not thread-safe either Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
c33d81a38f
commit
5d77471e5b
10 changed files with 18 additions and 83 deletions
|
@ -36,14 +36,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
namespace Gwenview
|
||||
{
|
||||
|
||||
class CropJob : public ThreadedDocumentJob
|
||||
class CropJob : public DocumentJob
|
||||
{
|
||||
public:
|
||||
CropJob(const QRect& rect)
|
||||
: mRect(rect)
|
||||
{}
|
||||
|
||||
virtual void threadedStart()
|
||||
virtual void doStart()
|
||||
{
|
||||
if (!checkDocumentEditor()) {
|
||||
return;
|
||||
|
@ -52,6 +52,7 @@ public:
|
|||
const QImage dst = src.copy(mRect);
|
||||
document()->editor()->setImage(dst);
|
||||
setError(NoError);
|
||||
emitResult();
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -105,36 +105,6 @@ bool DocumentJob::checkDocumentEditor()
|
|||
return true;
|
||||
}
|
||||
|
||||
ThreadedDocumentJob::ThreadedDocumentJob()
|
||||
: DocumentJob(),
|
||||
mThreadedJob(nullptr)
|
||||
{
|
||||
mThreadedJob = new VoidThread(this, std::bind(&ThreadedDocumentJob::threadedStart, this));
|
||||
connect(mThreadedJob, SIGNAL(finished()), this, SLOT(slotFinished()));
|
||||
}
|
||||
|
||||
ThreadedDocumentJob::~ThreadedDocumentJob()
|
||||
{
|
||||
if (!mThreadedJob->isFinished()) {
|
||||
mThreadedJob->wait();
|
||||
}
|
||||
}
|
||||
|
||||
void ThreadedDocumentJob::doStart()
|
||||
{
|
||||
mThreadedJob->start();
|
||||
}
|
||||
|
||||
void ThreadedDocumentJob::threadedFinish()
|
||||
{
|
||||
emitResult();
|
||||
}
|
||||
|
||||
void ThreadedDocumentJob::slotFinished()
|
||||
{
|
||||
threadedFinish();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#include "moc_documentjob.cpp"
|
||||
|
|
|
@ -130,38 +130,6 @@ private:
|
|||
friend class Document;
|
||||
};
|
||||
|
||||
/**
|
||||
* A document job whose action is started in a separate thread
|
||||
*/
|
||||
class ThreadedDocumentJob : public DocumentJob
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ThreadedDocumentJob();
|
||||
~ThreadedDocumentJob();
|
||||
|
||||
/**
|
||||
* Must be reimplemented to apply the action to the document.
|
||||
* This method is never called from the GUI thread.
|
||||
*/
|
||||
virtual void threadedStart() = 0;
|
||||
/**
|
||||
* Reimplement to do more stuff at the end of the job such
|
||||
* as adding sub-jobs, by default this method will call
|
||||
* emitResult().
|
||||
*/
|
||||
virtual void threadedFinish();
|
||||
|
||||
protected:
|
||||
virtual void doStart();
|
||||
|
||||
private Q_SLOTS:
|
||||
void slotFinished();
|
||||
|
||||
private:
|
||||
VoidThread* mThreadedJob;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif /* DOCUMENTJOB_H */
|
||||
|
|
|
@ -109,9 +109,8 @@ void DocumentLoadedImpl::setImage(const QImage& image)
|
|||
|
||||
void DocumentLoadedImpl::applyTransformation(Orientation orientation)
|
||||
{
|
||||
QImage image = document()->image();
|
||||
QMatrix matrix = ImageUtils::transformMatrix(orientation);
|
||||
image = image.transformed(matrix);
|
||||
QImage image = document()->image().transformed(matrix);
|
||||
setDocumentImage(image);
|
||||
imageRectUpdated(image.rect());
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ SaveJob::~SaveJob()
|
|||
delete d;
|
||||
}
|
||||
|
||||
void SaveJob::threadedStart()
|
||||
void SaveJob::doStart()
|
||||
{
|
||||
setError(NoError);
|
||||
{
|
||||
|
@ -87,10 +87,6 @@ void SaveJob::threadedStart()
|
|||
setErrorText(d->mImpl->document()->errorString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SaveJob::threadedFinish()
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO << error() << d->mTemporaryFile << d->mNewUrl;
|
||||
emitResult(); // nope, this does not sunder the sub-job
|
||||
if (!error()) {
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace Gwenview
|
|||
class DocumentLoadedImpl;
|
||||
|
||||
struct SaveJobPrivate;
|
||||
class GWENVIEWLIB_EXPORT SaveJob : public ThreadedDocumentJob
|
||||
class GWENVIEWLIB_EXPORT SaveJob : public DocumentJob
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -49,8 +49,7 @@ public:
|
|||
KUrl oldUrl() const;
|
||||
KUrl newUrl() const;
|
||||
|
||||
virtual void threadedStart();
|
||||
virtual void threadedFinish();
|
||||
virtual void doStart();
|
||||
|
||||
private:
|
||||
SaveJobPrivate* const d;
|
||||
|
|
|
@ -42,14 +42,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
namespace Gwenview
|
||||
{
|
||||
|
||||
class RedEyeReductionJob : public ThreadedDocumentJob
|
||||
class RedEyeReductionJob : public DocumentJob
|
||||
{
|
||||
public:
|
||||
RedEyeReductionJob(const QRectF& rectF)
|
||||
: mRectF(rectF)
|
||||
{}
|
||||
|
||||
void threadedStart()
|
||||
void doStart()
|
||||
{
|
||||
if (!checkDocumentEditor()) {
|
||||
return;
|
||||
|
@ -58,6 +58,7 @@ public:
|
|||
RedEyeReductionImageOperation::apply(&img, mRectF);
|
||||
document()->editor()->setImage(img);
|
||||
setError(NoError);
|
||||
emitResult();
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -42,22 +42,22 @@ struct ResizeImageOperationPrivate
|
|||
QImage mOriginalImage;
|
||||
};
|
||||
|
||||
class ResizeJob : public ThreadedDocumentJob
|
||||
class ResizeJob : public DocumentJob
|
||||
{
|
||||
public:
|
||||
ResizeJob(const QSize& size)
|
||||
: mSize(size)
|
||||
{}
|
||||
|
||||
virtual void threadedStart()
|
||||
virtual void doStart()
|
||||
{
|
||||
if (!checkDocumentEditor()) {
|
||||
return;
|
||||
}
|
||||
QImage image = document()->image();
|
||||
image = image.scaled(mSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
QImage image = document()->image().scaled(mSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
document()->editor()->setImage(image);
|
||||
setError(NoError);
|
||||
emitResult();
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -44,13 +44,14 @@ TransformJob::TransformJob(Orientation orientation)
|
|||
|
||||
}
|
||||
|
||||
void TransformJob::threadedStart()
|
||||
void TransformJob::doStart()
|
||||
{
|
||||
if (!checkDocumentEditor()) {
|
||||
return;
|
||||
}
|
||||
document()->editor()->applyTransformation(mOrientation);
|
||||
setError(NoError);
|
||||
emitResult();
|
||||
}
|
||||
|
||||
TransformImageOperation::TransformImageOperation(Orientation orientation)
|
||||
|
|
|
@ -36,12 +36,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
namespace Gwenview
|
||||
{
|
||||
|
||||
class TransformJob : public ThreadedDocumentJob
|
||||
class TransformJob : public DocumentJob
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TransformJob(Orientation orientation);
|
||||
void threadedStart(); // reimp
|
||||
void doStart(); // reimp
|
||||
|
||||
private:
|
||||
Orientation mOrientation;
|
||||
|
|
Loading…
Add table
Reference in a new issue