Permalink
Browse files

Use reference counting for ThumbnailPixmapCache everywhere to prevent…

… crashes on exit.
  • Loading branch information...
1 parent 3b0520c commit 881169b6ce8794365b1e405300a08c8cfdf05e21 @Tulon Tulon committed May 23, 2010
@@ -1,6 +1,6 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
- Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>
+ Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -30,8 +30,9 @@
QPainterPath IncompleteThumbnail::m_sCachedPath;
IncompleteThumbnail::IncompleteThumbnail(
- ThumbnailPixmapCache& thumbnail_cache, QSizeF const& max_size,
- ImageId const& image_id, ImageTransformation const& image_xform)
+ IntrusivePtr<ThumbnailPixmapCache> const& thumbnail_cache,
+ QSizeF const& max_size, ImageId const& image_id,
+ ImageTransformation const& image_xform)
: ThumbnailBase(thumbnail_cache, max_size, image_id, image_xform)
{
}
@@ -1,6 +1,6 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
- Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>
+ Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,8 +20,10 @@
#define INCOMPLETETHUMBNAIL_H_
#include "ThumbnailBase.h"
+#include "intrusivePtr.h"
#include <QPainterPath>
+class ThumbnailPixmapCache;
class QSizeF;
class QRectF;
@@ -41,8 +43,9 @@ class IncompleteThumbnail : public ThumbnailBase
{
public:
IncompleteThumbnail(
- ThumbnailPixmapCache& thumbnail_cache, QSizeF const& max_size,
- ImageId const& image_id, ImageTransformation const& image_xform);
+ IntrusivePtr<ThumbnailPixmapCache> const& thumbnail_cache,
+ QSizeF const& max_size, ImageId const& image_id,
+ ImageTransformation const& image_xform);
virtual ~IncompleteThumbnail();
View
@@ -56,11 +56,11 @@ class LoadFileTask::ErrorResult : public FilterResult
LoadFileTask::LoadFileTask(
Type type, PageInfo const& page,
- ThumbnailPixmapCache& thumbnail_cache,
+ IntrusivePtr<ThumbnailPixmapCache> const& thumbnail_cache,
IntrusivePtr<ProjectPages> const& pages,
IntrusivePtr<fix_orientation::Task> const& next_task)
: BackgroundTask(type),
- m_rThumbnailCache(thumbnail_cache),
+ m_ptrThumbnailCache(thumbnail_cache),
m_imageId(page.imageId()),
m_imageMetadata(page.metadata()),
m_ptrPages(pages),
@@ -86,7 +86,7 @@ LoadFileTask::operator()()
} else {
updateImageSizeIfChanged(image);
overrideDpi(image);
- m_rThumbnailCache.ensureThumbnailExists(m_imageId, image);
+ m_ptrThumbnailCache->ensureThumbnailExists(m_imageId, image);
return m_ptrNextTask->process(*this, FilterData(image));
}
} catch (CancelledException const&) {
View
@@ -41,7 +41,7 @@ class LoadFileTask : public BackgroundTask
DECLARE_NON_COPYABLE(LoadFileTask)
public:
LoadFileTask(Type type, PageInfo const& page,
- ThumbnailPixmapCache& thumbnail_cache,
+ IntrusivePtr<ThumbnailPixmapCache> const& thumbnail_cache,
IntrusivePtr<ProjectPages> const& pages,
IntrusivePtr<fix_orientation::Task> const& next_task);
@@ -55,7 +55,7 @@ class LoadFileTask : public BackgroundTask
void overrideDpi(QImage& image) const;
- ThumbnailPixmapCache& m_rThumbnailCache;
+ IntrusivePtr<ThumbnailPixmapCache> m_ptrThumbnailCache;
ImageId m_imageId;
ImageMetadata m_imageMetadata;
IntrusivePtr<ProjectPages> const m_ptrPages;
View
@@ -385,12 +385,12 @@ MainWindow::switchToNewProject(
updateMainArea();
}
-std::auto_ptr<ThumbnailPixmapCache>
+IntrusivePtr<ThumbnailPixmapCache>
MainWindow::createThumbnailCache()
{
QSize const max_pixmap_size(200, 200);
- return std::auto_ptr<ThumbnailPixmapCache>(
+ return IntrusivePtr<ThumbnailPixmapCache>(
new ThumbnailPixmapCache(
m_outFileNameGen.outDir()+"/cache/thumbs", max_pixmap_size, 40, 5
)
@@ -611,7 +611,7 @@ MainWindow::resetThumbSequence(
m_ptrThumbSequence->setThumbnailFactory(
IntrusivePtr<ThumbnailFactory>(
new ThumbnailFactory(
- *m_ptrThumbnailCache,
+ m_ptrThumbnailCache,
m_maxLogicalThumbSize, task
)
)
@@ -1799,7 +1799,7 @@ MainWindow::createCompositeTask(
if (last_filter_idx >= m_ptrStages->outputFilterIdx()) {
output_task = m_ptrStages->outputFilter()->createTask(
- page.id(), *m_ptrThumbnailCache, m_outFileNameGen, batch, debug
+ page.id(), m_ptrThumbnailCache, m_outFileNameGen, batch, debug
);
debug = false;
}
@@ -1838,7 +1838,7 @@ MainWindow::createCompositeTask(
return BackgroundTaskPtr(
new LoadFileTask(
batch ? BackgroundTask::BATCH : BackgroundTask::INTERACTIVE,
- page, *m_ptrThumbnailCache, m_ptrPages, fix_orientation_task
+ page, m_ptrThumbnailCache, m_ptrPages, fix_orientation_task
)
);
}
View
@@ -167,7 +167,7 @@ private slots:
QString const& project_file_path = QString(),
ProjectReader const* project_reader = 0);
- std::auto_ptr<ThumbnailPixmapCache> createThumbnailCache();
+ IntrusivePtr<ThumbnailPixmapCache> createThumbnailCache();
void setupThumbView();
@@ -249,7 +249,7 @@ private slots:
IntrusivePtr<StageSequence> m_ptrStages;
QString m_projectFile;
OutputFileNameGenerator m_outFileNameGen;
- std::auto_ptr<ThumbnailPixmapCache> m_ptrThumbnailCache;
+ IntrusivePtr<ThumbnailPixmapCache> m_ptrThumbnailCache;
std::auto_ptr<ThumbnailSequence> m_ptrThumbSequence;
std::auto_ptr<WorkerThread> m_ptrWorkerThread;
std::auto_ptr<ProcessingTaskQueue> m_ptrBatchQueue;
View
@@ -58,9 +58,10 @@ class ThumbnailBase::LoadCompletionHandler :
ThumbnailBase::ThumbnailBase(
- ThumbnailPixmapCache& thumbnail_cache, QSizeF const& max_size,
- ImageId const& image_id, ImageTransformation const& image_xform)
-: m_rThumbnailCache(thumbnail_cache),
+ IntrusivePtr<ThumbnailPixmapCache> const& thumbnail_cache,
+ QSizeF const& max_size, ImageId const& image_id,
+ ImageTransformation const& image_xform)
+: m_ptrThumbnailCache(thumbnail_cache),
m_maxSize(max_size),
m_imageId(image_id),
m_imageXform(image_xform),
@@ -90,7 +91,7 @@ ThumbnailBase::paint(QPainter* painter,
new LoadCompletionHandler(this)
);
ThumbnailPixmapCache::Status const status =
- m_rThumbnailCache.loadRequest(m_imageId, pixmap, handler);
+ m_ptrThumbnailCache->loadRequest(m_imageId, pixmap, handler);
if (status == ThumbnailPixmapCache::QUEUED) {
m_ptrCompletionHandler.swap(handler);
}
View
@@ -1,6 +1,6 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
- Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>
+ Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,23 +19,27 @@
#ifndef THUMBNAILBASE_H_
#define THUMBNAILBASE_H_
+#include "NonCopyable.h"
#include "ImageId.h"
#include "ImageTransformation.h"
+#include "IntrusivePtr.h"
+#include "ThumbnailPixmapCache.h"
#include <boost/shared_ptr.hpp>
#include <QTransform>
#include <QGraphicsItem>
#include <QSizeF>
#include <QRectF>
-class ThumbnailPixmapCache;
class ThumbnailLoadResult;
class ThumbnailBase : public QGraphicsItem
{
+ DECLARE_NON_COPYABLE(ThumbnailBase)
public:
ThumbnailBase(
- ThumbnailPixmapCache& thumbnail_cache, QSizeF const& max_size,
- ImageId const& image_id, ImageTransformation const& image_xform);
+ IntrusivePtr<ThumbnailPixmapCache> const& thumbnail_cache,
+ QSizeF const& max_size, ImageId const& image_id,
+ ImageTransformation const& image_xform);
virtual ~ThumbnailBase();
@@ -86,7 +90,7 @@ class ThumbnailBase : public QGraphicsItem
void handleLoadResult(ThumbnailLoadResult const& result);
- ThumbnailPixmapCache& m_rThumbnailCache;
+ IntrusivePtr<ThumbnailPixmapCache> m_ptrThumbnailCache;
QSizeF m_maxSize;
ImageId m_imageId;
ImageTransformation m_imageXform;
View
@@ -1,6 +1,6 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
- Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>
+ Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,26 +25,26 @@
class ThumbnailFactory::Collector : public ThumbnailCollector
{
public:
- Collector(ThumbnailPixmapCache& cache, QSizeF const& max_size);
+ Collector(IntrusivePtr<ThumbnailPixmapCache> const& cache, QSizeF const& max_size);
virtual void processThumbnail(std::auto_ptr<QGraphicsItem> thumbnail);
- virtual ThumbnailPixmapCache& thumbnailCache();
+ virtual IntrusivePtr<ThumbnailPixmapCache> thumbnailCache();
virtual QSizeF maxLogicalThumbSize() const;
std::auto_ptr<QGraphicsItem> retrieveThumbnail() { return m_ptrThumbnail; }
private:
- ThumbnailPixmapCache& m_rCache;
+ IntrusivePtr<ThumbnailPixmapCache> m_ptrCache;
QSizeF m_maxSize;
std::auto_ptr<QGraphicsItem> m_ptrThumbnail;
};
ThumbnailFactory::ThumbnailFactory(
- ThumbnailPixmapCache& pixmap_cache, QSizeF const& max_size,
- IntrusivePtr<CompositeCacheDrivenTask> const& task)
-: m_rPixmapCache(pixmap_cache),
+ IntrusivePtr<ThumbnailPixmapCache> const& pixmap_cache,
+ QSizeF const& max_size, IntrusivePtr<CompositeCacheDrivenTask> const& task)
+: m_ptrPixmapCache(pixmap_cache),
m_maxSize(max_size),
m_ptrTask(task)
{
@@ -57,7 +57,7 @@ ThumbnailFactory::~ThumbnailFactory()
std::auto_ptr<QGraphicsItem>
ThumbnailFactory::get(PageInfo const& page_info)
{
- Collector collector(m_rPixmapCache, m_maxSize);
+ Collector collector(m_ptrPixmapCache, m_maxSize);
m_ptrTask->process(page_info, &collector);
return collector.retrieveThumbnail();
}
@@ -66,8 +66,8 @@ ThumbnailFactory::get(PageInfo const& page_info)
/*======================= ThumbnailFactory::Collector ======================*/
ThumbnailFactory::Collector::Collector(
- ThumbnailPixmapCache& cache, QSizeF const& max_size)
-: m_rCache(cache),
+ IntrusivePtr<ThumbnailPixmapCache> const& cache, QSizeF const& max_size)
+: m_ptrCache(cache),
m_maxSize(max_size)
{
}
@@ -79,10 +79,10 @@ ThumbnailFactory::Collector::processThumbnail(
m_ptrThumbnail = thumbnail;
}
-ThumbnailPixmapCache&
+IntrusivePtr<ThumbnailPixmapCache>
ThumbnailFactory::Collector::thumbnailCache()
{
- return m_rCache;
+ return m_ptrCache;
}
QSizeF
View
@@ -1,6 +1,6 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
- Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>
+ Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,29 +22,29 @@
#include "NonCopyable.h"
#include "RefCountable.h"
#include "IntrusivePtr.h"
+#include "ThumbnailPixmapCache.h"
#include <QSizeF>
#include <memory>
class PageInfo;
class CompositeCacheDrivenTask;
-class ThumbnailPixmapCache;
class QGraphicsItem;
class ThumbnailFactory : public RefCountable
{
DECLARE_NON_COPYABLE(ThumbnailFactory)
public:
ThumbnailFactory(
- ThumbnailPixmapCache& pixmap_cache, QSizeF const& max_size,
- IntrusivePtr<CompositeCacheDrivenTask> const& task);
+ IntrusivePtr<ThumbnailPixmapCache> const& pixmap_cache,
+ QSizeF const& max_size, IntrusivePtr<CompositeCacheDrivenTask> const& task);
virtual ~ThumbnailFactory();
std::auto_ptr<QGraphicsItem> get(PageInfo const& page_info);
private:
class Collector;
- ThumbnailPixmapCache& m_rPixmapCache;
+ IntrusivePtr<ThumbnailPixmapCache> m_ptrPixmapCache;
QSizeF m_maxSize;
IntrusivePtr<CompositeCacheDrivenTask> m_ptrTask;
};
@@ -20,6 +20,7 @@
#define THUMBNAILPIXMAPCACHE_H_
#include "NonCopyable.h"
+#include "RefCountable.h"
#include "ThumbnailLoadResult.h"
#include "AbstractCommand.h"
#include <boost/weak_ptr.hpp>
@@ -31,7 +32,7 @@ class QPixmap;
class QString;
class QSize;
-class ThumbnailPixmapCache
+class ThumbnailPixmapCache : public RefCountable
{
DECLARE_NON_COPYABLE(ThumbnailPixmapCache)
public:
@@ -1,6 +1,6 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
- Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>
+ Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -31,7 +31,7 @@ class ThumbnailCollector : public AbstractFilterDataCollector
public:
virtual void processThumbnail(std::auto_ptr<QGraphicsItem>) = 0;
- virtual ThumbnailPixmapCache& thumbnailCache() = 0;
+ virtual IntrusivePtr<ThumbnailPixmapCache> thumbnailCache() = 0;
virtual QSizeF maxLogicalThumbSize() const = 0;
};
@@ -1,6 +1,6 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
- Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>
+ Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -31,8 +31,9 @@ namespace deskew
{
Thumbnail::Thumbnail(
- ThumbnailPixmapCache& thumbnail_cache, QSizeF const& max_size,
- ImageId const& image_id, ImageTransformation const& xform)
+ IntrusivePtr<ThumbnailPixmapCache> const& thumbnail_cache,
+ QSizeF const& max_size, ImageId const& image_id,
+ ImageTransformation const& xform)
: ThumbnailBase(thumbnail_cache, max_size, image_id, xform)
{
}
Oops, something went wrong.

0 comments on commit 881169b

Please sign in to comment.