Replace all g_idle_adds with IdleRegister (#3767)

This commit is contained in:
Flössie
2017-03-26 22:03:33 +02:00
parent 39ca290ca9
commit 91b44dbd08
25 changed files with 419 additions and 403 deletions

View File

@@ -385,16 +385,6 @@ Glib::ustring BatchQueue::getTempFilenameForParams( const Glib::ustring &filenam
return savedParamPath;
}
int cancelItemUI (void* data)
{
const auto bqe = static_cast<BatchQueueEntry*>(data);
g_remove (bqe->savedParamsFile.c_str ());
delete bqe;
return 0;
}
void BatchQueue::cancelItems (const std::vector<ThumbBrowserEntryBase*>& items)
{
{
@@ -419,7 +409,16 @@ void BatchQueue::cancelItems (const std::vector<ThumbBrowserEntryBase*>& items)
if (entry->thumbnail)
entry->thumbnail->imageRemovedFromQueue ();
g_idle_add (cancelItemUI, entry);
const auto func = [](gpointer data) -> gboolean {
const BatchQueueEntry* const bqe = static_cast<BatchQueueEntry*>(data);
::g_remove(bqe->savedParamsFile.c_str());
delete bqe;
return FALSE;
};
idle_register.add(func, entry);
}
for (const auto entry : fd)
@@ -879,12 +878,6 @@ Glib::ustring BatchQueue::autoCompleteFileName (const Glib::ustring& fileName, c
return "";
}
int setProgressUI (void* p)
{
(static_cast<BatchQueue*>(p))->redraw();
return 0;
}
void BatchQueue::setProgress (double p)
{
@@ -893,7 +886,12 @@ void BatchQueue::setProgress (double p)
}
// No need to acquire the GUI, setProgressUI will do it
g_idle_add (setProgressUI, this);
const auto func = [](gpointer data) -> gboolean {
static_cast<BatchQueue*>(data)->redraw();
return FALSE;
};
idle_register.add(func, this);
}
void BatchQueue::buttonPressed (LWButton* button, int actionCode, void* actionData)

View File

@@ -100,6 +100,11 @@ DirBrowser::DirBrowser () : dirTreeModel(),
scrolledwindow4->show ();
}
DirBrowser::~DirBrowser()
{
idle_register.destroy();
}
void DirBrowser::fillDirTree ()
{
@@ -227,16 +232,16 @@ int updateVolumesUI (void* br)
(static_cast<DirBrowser*>(br))->updateVolumes ();
return 1;
}
int updateDirTreeUI (void* br)
{
(static_cast<DirBrowser*>(br))->updateDirTreeRoot ();
return 0;
}
void DirBrowser::winDirChanged ()
{
const auto func = [](gpointer data) -> gboolean {
static_cast<DirBrowser*>(data)->updateDirTreeRoot();
g_idle_add (updateDirTreeUI, this);
return FALSE;
};
idle_register.add(func, this);
}
#endif

View File

@@ -25,6 +25,8 @@
#include "windirmonitor.h"
#endif
#include "guiutils.h"
class DirBrowser : public Gtk::VBox
#ifdef WIN32
, public WinDirChangeListener
@@ -95,8 +97,11 @@ private:
Gtk::TreePath expandToDir (const Glib::ustring& dirName);
void updateDir (const Gtk::TreeModel::iterator& iter);
IdleRegister idle_register;
public:
DirBrowser ();
~DirBrowser();
void fillDirTree ();
void on_sort_column_changed() const;

View File

@@ -1016,44 +1016,42 @@ void EditorPanel::procParamsChanged (rtengine::procparams::ProcParams* params, r
// saveLabel->set_markup (Glib::ustring("<span foreground=\"#AA0000\" weight=\"bold\">") + M("MAIN_BUTTON_SAVE") + "</span>");
}
struct spsparams {
bool inProcessing;
EditorPanelIdleHelper* epih;
};
int setProgressStateUIThread (void* data)
{
spsparams* p = static_cast<spsparams*> (data);
if (p->epih->destroyed) {
if (p->epih->pending == 1) {
delete p->epih;
} else {
p->epih->pending--;
}
delete p;
return 0;
}
p->epih->epanel->refreshProcessingState (p->inProcessing);
p->epih->pending--;
delete p;
return 0;
}
void EditorPanel::setProgressState (bool inProcessing)
{
struct spsparams {
bool inProcessing;
EditorPanelIdleHelper* epih;
};
epih->pending++;
spsparams* p = new spsparams;
p->inProcessing = inProcessing;
p->epih = epih;
g_idle_add (setProgressStateUIThread, p);
const auto func = [](gpointer data) -> gboolean {
spsparams* const p = static_cast<spsparams*>(data);
if (p->epih->destroyed) {
if (p->epih->pending == 1) {
delete p->epih;
} else {
p->epih->pending--;
}
delete p;
return 0;
}
p->epih->epanel->refreshProcessingState (p->inProcessing);
p->epih->pending--;
delete p;
return FALSE;
};
idle_register.add(func, p);
}
void EditorPanel::setProgress (double p)
@@ -1125,12 +1123,6 @@ void EditorPanel::refreshProcessingState (bool inProcessingP)
setprogressStrUI (s);
}
struct errparams {
Glib::ustring descr;
Glib::ustring title;
EditorPanelIdleHelper* epih;
};
void EditorPanel::displayError (Glib::ustring title, Glib::ustring descr)
{
GtkWidget* msgd = gtk_message_dialog_new_with_markup (nullptr,
@@ -1146,38 +1138,43 @@ void EditorPanel::displayError (Glib::ustring title, Glib::ustring descr)
gtk_widget_show_all (msgd);
}
int disperrorUI (void* data)
{
errparams* p = static_cast<errparams*> (data);
if (p->epih->destroyed) {
if (p->epih->pending == 1) {
delete p->epih;
} else {
p->epih->pending--;
}
delete p;
return 0;
}
p->epih->epanel->displayError (p->title, p->descr);
p->epih->pending--;
delete p;
return 0;
}
void EditorPanel::error (Glib::ustring title, Glib::ustring descr)
{
struct errparams {
Glib::ustring descr;
Glib::ustring title;
EditorPanelIdleHelper* epih;
};
epih->pending++;
errparams* p = new errparams;
errparams* const p = new errparams;
p->descr = descr;
p->title = title;
p->epih = epih;
g_idle_add (disperrorUI, p);
const auto func = [](gpointer data) -> gboolean {
errparams* const p = static_cast<errparams*> (data);
if (p->epih->destroyed) {
if (p->epih->pending == 1) {
delete p->epih;
} else {
p->epih->pending--;
}
delete p;
return 0;
}
p->epih->epanel->displayError (p->title, p->descr);
p->epih->pending--;
delete p;
return FALSE;
};
idle_register.add(func, p);
}
void EditorPanel::info_toggled ()

View File

@@ -455,6 +455,8 @@ FileBrowser::FileBrowser ()
FileBrowser::~FileBrowser ()
{
idle_register.destroy();
profileStore.removeListener(this);
delete pmenu;
delete pmenuColorLabels;
@@ -541,46 +543,44 @@ void FileBrowser::doubleClicked (ThumbBrowserEntryBase* entry)
}
}
struct addparams {
FileBrowserIdleHelper* fbih;
FileBrowserEntry* entry;
};
int AddEntryUIThread (void* data)
{
addparams* ap = static_cast<addparams*>(data);
FileBrowserIdleHelper* fbih = ap->fbih;
if (fbih->destroyed) {
if (fbih->pending == 1) {
delete fbih;
} else {
fbih->pending--;
}
delete ap->entry;
delete ap;
return 0;
}
ap->fbih->fbrowser->addEntry_ (ap->entry);
delete ap;
fbih->pending--;
return 0;
}
void FileBrowser::addEntry (FileBrowserEntry* entry)
{
struct addparams {
FileBrowserIdleHelper* fbih;
FileBrowserEntry* entry;
};
fbih->pending++;
entry->setParent (this);
addparams* ap = new addparams;
addparams* const ap = new addparams;
ap->fbih = fbih;
ap->entry = entry;
g_idle_add (AddEntryUIThread, ap);
const auto func = [](gpointer data) -> gboolean {
addparams* const ap = static_cast<addparams*>(data);
FileBrowserIdleHelper* fbih = ap->fbih;
if (fbih->destroyed) {
if (fbih->pending == 1) {
delete fbih;
} else {
fbih->pending--;
}
delete ap->entry;
delete ap;
return 0;
}
ap->fbih->fbrowser->addEntry_ (ap->entry);
delete ap;
fbih->pending--;
return FALSE;
};
idle_register.add(func, ap);
}
void FileBrowser::addEntry_ (FileBrowserEntry* entry)
@@ -1905,12 +1905,6 @@ void FileBrowser::openNextPreviousEditorImage (Glib::ustring fname, eRTNav nextP
}
}
int refreshThumbImagesUI (void* data)
{
(static_cast<FileBrowser*>(data))->_thumbRearrangementNeeded ();
return 0;
}
void FileBrowser::_thumbRearrangementNeeded ()
{
refreshThumbImages (); // arrangeFiles is NOT enough
@@ -1918,8 +1912,13 @@ void FileBrowser::_thumbRearrangementNeeded ()
void FileBrowser::thumbRearrangementNeeded ()
{
// refreshThumbImagesUI will handle thread safety itself
g_idle_add (refreshThumbImagesUI, this);
const auto func = [](gpointer data) -> gboolean {
static_cast<FileBrowser*>(data)->_thumbRearrangementNeeded();
return FALSE;
};
idle_register.add(func, this);
}
void FileBrowser::selectionChanged ()

View File

@@ -67,11 +67,12 @@ class FileBrowser : public ThumbBrowserBase,
public ExportPanelListener,
public ProfileStoreListener
{
private:
typedef sigc::signal<void> type_trash_changed;
protected:
IdleRegister idle_register;
protected:
Gtk::MenuItem* rank[6];
MyImageMenuItem* colorlabel[6];
Gtk::MenuItem* trash;
@@ -143,7 +144,6 @@ protected:
type_trash_changed m_trash_changed;
public:
FileBrowser ();
~FileBrowser ();

View File

@@ -435,6 +435,8 @@ FileCatalog::FileCatalog (CoarsePanel* cp, ToolBar* tb, FilePanel* filepanel) :
FileCatalog::~FileCatalog()
{
idle_register.destroy();
for (int i = 0; i < 5; i++) {
delete iranked[i];
delete igranked[i];
@@ -702,15 +704,15 @@ void FileCatalog::_refreshProgressBar ()
}
}
int refreshProgressBarUI (void* data)
{
(static_cast<FileCatalog*>(data))->_refreshProgressBar ();
return 0;
}
void FileCatalog::filterApplied()
{
g_idle_add (refreshProgressBarUI, this);
const auto func = [](gpointer data) -> gboolean {
static_cast<FileCatalog*>(data)->_refreshProgressBar();
return FALSE;
};
idle_register.add(func, this);
}
@@ -776,12 +778,6 @@ void FileCatalog::previewReady (int dir_id, FileBrowserEntry* fdn)
_refreshProgressBar();
}
int prevfinished (void* data)
{
(static_cast<FileCatalog*>(data))->previewsFinishedUI ();
return 0;
}
// Called within GTK UI thread
void FileCatalog::previewsFinishedUI ()
{
@@ -838,7 +834,13 @@ void FileCatalog::previewsFinished (int dir_id)
currentEFS = dirEFS;
}
g_idle_add (prevfinished, this);
const auto func = [](gpointer data) -> gboolean {
static_cast<FileCatalog*>(data)->previewsFinishedUI();
return FALSE;
};
idle_register.add(func, this);
}
void FileCatalog::setEnabled (bool e)
@@ -920,7 +922,7 @@ void FileCatalog::openRequested (std::vector<Thumbnail*> tmb)
tmb[i]->increaseRef ();
}
g_idle_add (openRequestedUI, params);
idle_register.add(openRequestedUI, params);
}
void FileCatalog::deleteRequested (std::vector<FileBrowserEntry*> tbe, bool inclBatchProcessed)
@@ -1744,15 +1746,16 @@ void FileCatalog::reparseDirectory ()
}
#ifdef WIN32
int winDirChangedUITread (void* cat)
{
(static_cast<FileCatalog*>(cat))->reparseDirectory ();
return 0;
}
void FileCatalog::winDirChanged ()
{
g_idle_add(winDirChangedUITread, this);
const auto func = [](gpointer data) -> gboolean {
static_cast<FileCatalog*>(data)->reparseDirectory();
return FALSE;
};
idle_register.add(func, this);
}
#else
@@ -1857,7 +1860,7 @@ void FileCatalog::addAndOpenFile (const Glib::ustring& fname)
params->catalog = this;
params->tmb.push_back (tmb);
tmb->increaseRef ();
g_idle_add (openRequestedUI, params);
idle_register.add(openRequestedUI, params);
} catch(Gio::Error&) {}
}

View File

@@ -161,6 +161,8 @@ private:
WinDirMonitor* wdMonitor;
#endif
IdleRegister idle_register;
void addAndOpenFile (const Glib::ustring& fname);
void checkAndAddFile (Glib::RefPtr<Gio::File> info);
std::vector<Glib::ustring> getFileList ();

View File

@@ -412,6 +412,7 @@ HistogramRGBArea::HistogramRGBArea () ://needChroma unactive by default
HistogramRGBArea::~HistogramRGBArea ()
{
idle_register.destroy();
if (harih->pending) {
harih->destroyed = true;
@@ -703,30 +704,6 @@ void HistogramRGBArea::rgb2lab (Glib::ustring profile, Glib::ustring profileW, i
}
int histrgbupdate (void* data)
{
HistogramRGBAreaIdleHelper* harih = static_cast<HistogramRGBAreaIdleHelper*>(data);
if (harih->destroyed) {
if (harih->pending == 1) {
delete harih;
} else {
harih->pending--;
}
return 0;
}
harih->harea->updateBackBuffer(-1, -1, -1);
harih->harea->queue_draw ();
harih->pending--;
return 0;
}
void HistogramRGBArea::update (int valh, int rh, int gh, int bh)
{
@@ -741,7 +718,29 @@ void HistogramRGBArea::update (int valh, int rh, int gh, int bh)
}
harih->pending++;
g_idle_add (histrgbupdate, harih);
const auto func = [](gpointer data) -> gboolean {
HistogramRGBAreaIdleHelper* const harih = static_cast<HistogramRGBAreaIdleHelper*>(data);
if (harih->destroyed) {
if (harih->pending == 1) {
delete harih;
} else {
harih->pending--;
}
return 0;
}
harih->harea->updateBackBuffer(-1, -1, -1);
harih->harea->queue_draw ();
harih->pending--;
return FALSE;
};
idle_register.add(func, harih);
}
void HistogramRGBArea::updateOptions (bool r, bool g, bool b, bool l, bool raw, bool bar, bool c)
@@ -840,13 +839,13 @@ HistogramArea::HistogramArea (FullModeListener *fml) : //needChroma unactive by
HistogramArea::~HistogramArea ()
{
idle_register.destroy();
if (haih->pending) {
haih->destroyed = true;
} else {
delete haih;
}
}
Gtk::SizeRequestMode HistogramArea::get_request_mode_vfunc () const
@@ -901,33 +900,8 @@ void HistogramArea::updateOptions (bool r, bool g, bool b, bool l, bool raw, boo
updateBackBuffer ();
}
int histupdateUI (void* data)
{
HistogramAreaIdleHelper* haih = static_cast<HistogramAreaIdleHelper*>(data);
if (haih->destroyed) {
if (haih->pending == 1) {
delete haih;
} else {
haih->pending--;
}
return 0;
}
haih->harea->setDirty (true);
haih->harea->updateBackBuffer ();
haih->harea->queue_draw ();
haih->pending--;
return 0;
}
void HistogramArea::update (LUTu &histRed, LUTu &histGreen, LUTu &histBlue, LUTu &histLuma, LUTu &histRedRaw, LUTu &histGreenRaw, LUTu &histBlueRaw, LUTu &histChroma)
{
if (histRed) {
lhist = histLuma;
chist = histChroma;
@@ -945,7 +919,29 @@ void HistogramArea::update (LUTu &histRed, LUTu &histGreen, LUTu &histBlue, LUTu
haih->pending++;
// Can be done outside of the GUI thread
g_idle_add (histupdateUI, haih);
const auto func = [](gpointer data) -> gboolean {
HistogramAreaIdleHelper* const haih = static_cast<HistogramAreaIdleHelper*>(data);
if (haih->destroyed) {
if (haih->pending == 1) {
delete haih;
} else {
haih->pending--;
}
return 0;
}
haih->harea->setDirty (true);
haih->harea->updateBackBuffer ();
haih->harea->queue_draw ();
haih->pending--;
return FALSE;
};
idle_register.add(func, haih);
}
SSEFUNCTION void HistogramArea::updateBackBuffer ()

View File

@@ -45,11 +45,12 @@ struct HistogramRGBAreaIdleHelper {
class HistogramRGBArea : public Gtk::DrawingArea, public BackBuffer
{
private:
typedef const double (*TMatrix)[3];
protected:
IdleRegister idle_register;
protected:
int val;
int r;
int g;
@@ -72,7 +73,6 @@ protected:
HistogramRGBAreaIdleHelper* harih;
public:
HistogramRGBArea();
~HistogramRGBArea();
@@ -111,9 +111,10 @@ public:
class HistogramArea : public Gtk::DrawingArea, public BackBuffer
{
private:
IdleRegister idle_register;
protected:
LUTu lhist, rhist, ghist, bhist, chist;
LUTu lhistRaw, rhistRaw, ghistRaw, bhistRaw;
@@ -127,7 +128,6 @@ protected:
HistogramAreaIdleHelper* haih;
public:
explicit HistogramArea(FullModeListener *fml = nullptr);
~HistogramArea();

View File

@@ -45,7 +45,7 @@ LensGeometry::LensGeometry () : FoldableToolPanel(this, "lensgeom", M("TP_LENSGE
LensGeometry::~LensGeometry ()
{
g_idle_remove_by_data(this);
idle_register.destroy();
}
void LensGeometry::read (const ProcParams* pp, const ParamsEdited* pedited)
@@ -121,27 +121,26 @@ void LensGeometry::setBatchMode (bool batchMode)
void LensGeometry::disableAutoFillIfActive ()
{
g_idle_add(doDisableAutoFillIfActive, this);
}
const auto func = [](gpointer data) -> gboolean {
GThreadLock lock; // Is this really needed?
int LensGeometry::doDisableAutoFillIfActive (void* data)
{
GThreadLock lock; // Is this really needed?
LensGeometry* const instance = static_cast<LensGeometry*>(data);
LensGeometry* const instance = static_cast<LensGeometry*>(data);
if (!instance->batchMode) {
if (instance->fill->get_active()) {
instance->fillConn.block(true);
instance->fill->set_active(false);
if (!instance->batchMode) {
if (instance->fill->get_active()) {
instance->fillConn.block (true);
instance->fill->set_active(false);
if (instance->listener) {
instance->listener->panelChanged (EvTransAutoFill, M("GENERAL_DISABLED"));
}
if (instance->listener) {
instance->listener->panelChanged (EvTransAutoFill, M("GENERAL_DISABLED"));
instance->fillConn.block(false);
}
instance->fillConn.block (false);
}
}
return 0;
return FALSE;
};
idle_register.add(func, this);
}

View File

@@ -57,8 +57,7 @@ public:
void disableAutoFillIfActive ();
private:
static int doDisableAutoFillIfActive (void* data);
IdleRegister idle_register;
};
#endif

View File

@@ -48,7 +48,6 @@ MyCurve::MyCurve () : pipetteR(-1.f), pipetteG(-1.f), pipetteB(-1.f), pipetteVal
MyCurve::~MyCurve ()
{
if (mcih->pending) {
mcih->destroyed = true;
} else {

View File

@@ -57,7 +57,6 @@ class CurveEditor;
class MyCurve : public Gtk::DrawingArea, public BackBuffer, public ColorCaller, public CoordinateProvider
{
friend class MyCurveIdleHelper;
protected:

View File

@@ -49,6 +49,7 @@ MyDiagonalCurve::MyDiagonalCurve () : activeParam(-1), bghistvalid(false)
MyDiagonalCurve::~MyDiagonalCurve ()
{
idle_register.destroy();
delete [] bghist;
}
@@ -1492,38 +1493,13 @@ void MyDiagonalCurve::setType (DiagonalCurveType t)
void MyDiagonalCurve::setActiveParam (int ac)
{
activeParam = ac;
setDirty(true);
queue_draw ();
}
int diagonalmchistupdateUI (void* data)
{
MyCurveIdleHelper* mcih = static_cast<MyCurveIdleHelper*>(data);
if (mcih->destroyed) {
if (mcih->pending == 1) {
delete mcih;
} else {
mcih->pending--;
}
return 0;
}
mcih->clearPixmap ();
mcih->myCurve->queue_draw ();
mcih->pending--;
return 0;
}
void MyDiagonalCurve::updateBackgroundHistogram (LUTu & hist)
{
if (hist) {
//memcpy (bghist, hist, 256*sizeof(unsigned int));
for (int i = 0; i < 256; i++) {
@@ -1537,14 +1513,33 @@ void MyDiagonalCurve::updateBackgroundHistogram (LUTu & hist)
}
mcih->pending++;
// Can be done outside of the GUI thread, so we're using g_idle_add instead of add_idle
g_idle_add (diagonalmchistupdateUI, mcih);
const auto func = [](gpointer data) -> gboolean {
MyCurveIdleHelper* const mcih = static_cast<MyCurveIdleHelper*>(data);
if (mcih->destroyed) {
if (mcih->pending == 1) {
delete mcih;
} else {
mcih->pending--;
}
return 0;
}
mcih->clearPixmap ();
mcih->myCurve->queue_draw ();
mcih->pending--;
return FALSE;
};
idle_register.add(func, mcih);
}
void MyDiagonalCurve::reset(const std::vector<double> &resetCurve, double identityValue)
{
stopNumericalAdjustment();
if (!resetCurve.empty()) {

View File

@@ -48,6 +48,8 @@ public:
class MyDiagonalCurve : public MyCurve
{
private:
IdleRegister idle_register;
protected:
DiagonalCurveDescr curve;

View File

@@ -23,6 +23,18 @@
using namespace rtengine;
using namespace rtengine::procparams;
namespace
{
struct iaimgpar {
IImage8* image;
PreviewHandlerIdleHelper* pih;
double scale;
CropParams cp;
};
}
PreviewHandler::PreviewHandler () : image(nullptr), previewScale(1.)
{
@@ -34,6 +46,7 @@ PreviewHandler::PreviewHandler () : image(nullptr), previewScale(1.)
PreviewHandler::~PreviewHandler ()
{
idle_register.destroy();
if (pih->pending) {
pih->destroyed = true;
@@ -44,50 +57,8 @@ PreviewHandler::~PreviewHandler ()
//----------------previewimagelistener functions--------------------
struct iaimgpar {
IImage8* image;
PreviewHandlerIdleHelper* pih;
double scale;
CropParams cp;
};
int setImageUI (void* data)
{
iaimgpar* iap = static_cast<iaimgpar*>(data);
PreviewHandlerIdleHelper* pih = iap->pih;
if (pih->destroyed) {
if (pih->pending == 1) {
delete pih;
} else {
pih->pending--;
}
delete iap;
return 0;
}
if (pih->phandler->image) {
IImage8* oldImg = pih->phandler->image;
oldImg->getMutex().lock ();
pih->phandler->image = iap->image;
oldImg->getMutex().unlock ();
} else {
pih->phandler->image = iap->image;
}
pih->phandler->cropParams = iap->cp;
pih->phandler->previewScale = iap->scale;
pih->pending--;
delete iap;
return 0;
}
void PreviewHandler::setImage (rtengine::IImage8* i, double scale, rtengine::procparams::CropParams cp)
{
pih->pending++;
iaimgpar* iap = new iaimgpar;
@@ -96,95 +67,123 @@ void PreviewHandler::setImage (rtengine::IImage8* i, double scale, rtengine::pro
iap->scale = scale;
iap->cp = cp;
g_idle_add (setImageUI, iap);
}
const auto func = [](gpointer data) -> gboolean {
iaimgpar* const iap = static_cast<iaimgpar*>(data);
PreviewHandlerIdleHelper* const pih = iap->pih;
if (pih->destroyed) {
if (pih->pending == 1) {
delete pih;
} else {
pih->pending--;
}
int delImageUI (void* data)
{
delete iap;
iaimgpar* iap = static_cast<iaimgpar*>(data);
PreviewHandlerIdleHelper* pih = iap->pih;
if (pih->destroyed) {
if (pih->pending == 1) {
delete pih;
} else {
pih->pending--;
return FALSE;
}
if (pih->phandler->image) {
IImage8* const oldImg = pih->phandler->image;
oldImg->getMutex().lock ();
pih->phandler->image = iap->image;
oldImg->getMutex().unlock ();
} else {
pih->phandler->image = iap->image;
}
pih->phandler->cropParams = iap->cp;
pih->phandler->previewScale = iap->scale;
pih->pending--;
delete iap;
return 0;
}
return FALSE;
};
if (pih->phandler->image) {
IImage8* oldImg = pih->phandler->image;
oldImg->getMutex().lock ();
pih->phandler->image = nullptr;
oldImg->getMutex().unlock ();
}
iap->image->free ();
pih->phandler->previewImgMutex.lock ();
pih->phandler->previewImg.clear ();
pih->phandler->previewImgMutex.unlock ();
pih->pending--;
delete iap;
return 0;
idle_register.add(func, iap);
}
void PreviewHandler::delImage (IImage8* i)
{
pih->pending++;
iaimgpar* iap = new iaimgpar;
iap->image = i;
iap->pih = pih;
g_idle_add (delImageUI, iap);
}
const auto func = [](gpointer data) -> gboolean {
iaimgpar* iap = static_cast<iaimgpar*>(data);
PreviewHandlerIdleHelper* pih = iap->pih;
int imageReadyUI (void* data)
{
if (pih->destroyed) {
if (pih->pending == 1) {
delete pih;
} else {
pih->pending--;
}
iaimgpar* iap = static_cast<iaimgpar*>(data);
PreviewHandlerIdleHelper* pih = iap->pih;
delete iap;
if (pih->destroyed) {
if (pih->pending == 1) {
delete pih;
} else {
pih->pending--;
return FALSE;
}
if (pih->phandler->image) {
IImage8* oldImg = pih->phandler->image;
oldImg->getMutex().lock ();
pih->phandler->image = nullptr;
oldImg->getMutex().unlock ();
}
iap->image->free ();
pih->phandler->previewImgMutex.lock ();
pih->phandler->previewImg.clear ();
pih->phandler->previewImgMutex.unlock ();
pih->pending--;
delete iap;
return 0;
}
return FALSE;
};
pih->phandler->previewImgMutex.lock ();
pih->phandler->previewImg = Gdk::Pixbuf::create_from_data (pih->phandler->image->getData(), Gdk::COLORSPACE_RGB, false, 8, pih->phandler->image->getWidth(), pih->phandler->image->getHeight(), 3 * pih->phandler->image->getWidth());
pih->phandler->previewImgMutex.unlock ();
pih->phandler->cropParams = iap->cp;
pih->phandler->previewImageChanged ();
pih->pending--;
delete iap;
return 0;
idle_register.add(func, iap);
}
void PreviewHandler::imageReady (CropParams cp)
{
pih->pending++;
iaimgpar* iap = new iaimgpar;
iap->pih = pih;
iap->cp = cp;
g_idle_add (imageReadyUI, iap);
const auto func = [](gpointer data) -> gboolean {
iaimgpar* const iap = static_cast<iaimgpar*>(data);
PreviewHandlerIdleHelper* pih = iap->pih;
if (pih->destroyed) {
if (pih->pending == 1) {
delete pih;
} else {
pih->pending--;
}
delete iap;
return FALSE;
}
pih->phandler->previewImgMutex.lock ();
pih->phandler->previewImg = Gdk::Pixbuf::create_from_data (pih->phandler->image->getData(), Gdk::COLORSPACE_RGB, false, 8, pih->phandler->image->getWidth(), pih->phandler->image->getHeight(), 3 * pih->phandler->image->getWidth());
pih->phandler->previewImgMutex.unlock ();
pih->phandler->cropParams = iap->cp;
pih->phandler->previewImageChanged ();
pih->pending--;
delete iap;
return FALSE;
};
idle_register.add(func, iap);
}
Glib::RefPtr<Gdk::Pixbuf> PreviewHandler::getRoughImage (int x, int y, int w, int h, double zoom)

View File

@@ -19,11 +19,15 @@
#ifndef _PREVIEWHANDLER_
#define _PREVIEWHANDLER_
#include "../rtengine/rtengine.h"
#include "threadutils.h"
#include <gtkmm.h>
#include <list>
#include <gtkmm.h>
#include "threadutils.h"
#include "guiutils.h"
#include "../rtengine/rtengine.h"
class PreviewListener
{
@@ -41,11 +45,13 @@ struct PreviewHandlerIdleHelper {
class PreviewHandler : public rtengine::PreviewImageListener
{
private:
friend int setImageUI (void* data);
friend int delImageUI (void* data);
friend int imageReadyUI (void* data);
IdleRegister idle_register;
protected:
rtengine::IImage8* image;
rtengine::procparams::CropParams cropParams;

View File

@@ -65,32 +65,36 @@ public:
template<class T>
class ProgressConnector
{
private:
sigc::signal0<T> opStart;
sigc::signal0<bool> opEnd;
T retval;
Glib::Thread *workThread;
static int emitEndSignalUI (void* data)
{
sigc::signal0<bool>* opEnd = (sigc::signal0<bool>*) data;
int r = opEnd->emit ();
delete opEnd;
return r;
}
IdleRegister idle_register;
void workingThread ()
{
retval = opStart.emit ();
g_idle_add (ProgressConnector<T>::emitEndSignalUI, new sigc::signal0<bool> (opEnd));
retval = opStart.emit();
const auto func = [](gpointer data) -> gboolean {
sigc::signal0<bool>* const opEnd = static_cast<sigc::signal0<bool>*>(data);
const gboolean res = opEnd->emit();
delete opEnd;
return res;
};
idle_register.add(func, new sigc::signal0<bool>(opEnd));
workThread = nullptr;
}
public:
ProgressConnector (): retval( 0 ), workThread( nullptr ) { }
~ProgressConnector()
{
idle_register.destroy();
}
void startFunc (const sigc::slot0<T>& startHandler, const sigc::slot0<bool>& endHandler )
{

View File

@@ -634,6 +634,8 @@ Retinex::Retinex () : FoldableToolPanel(this, "retinex", M("TP_RETINEX_LABEL"),
Retinex::~Retinex()
{
idle_register.destroy();
delete curveEditorGD;
delete curveEditorGDH;
delete transmissionCurveEditorG;
@@ -695,17 +697,6 @@ void Retinex::updateToolState(std::vector<int> &tpOpen)
}
}
int minmaxChangedUI (void* data)
{
GThreadLock lock; // All GUI access from idle_add callbacks or separate thread HAVE to be protected
(static_cast<Retinex*>(data))->minmaxComputed_ ();
return 0;
}
void Retinex::minmaxChanged (double cdma, double cdmin, double mini, double maxi, double Tmean, double Tsigma, double Tmin, double Tmax)
{
nextmin = cdmin;
@@ -716,8 +707,15 @@ void Retinex::minmaxChanged (double cdma, double cdmin, double mini, double maxi
nextsigma = Tsigma;
nextminT = Tmin;
nextmaxT = Tmax;
g_idle_add (minmaxChangedUI, this);
const auto func = [](gpointer data) -> gboolean {
GThreadLock lock; // All GUI access from idle_add callbacks or separate thread HAVE to be protected
static_cast<Retinex*>(data)->minmaxComputed_();
return FALSE;
};
idle_register.add(func, this);
}
bool Retinex::minmaxComputed_ ()

View File

@@ -17,6 +17,8 @@ class Retinex : public ToolParamBlock, public FoldableToolPanel, public rtengin
public AdjusterListener, public ColorProvider
{
private:
IdleRegister idle_register;
protected:
CurveEditorGroup* curveEditorGD;

View File

@@ -188,6 +188,8 @@ ToneCurve::ToneCurve () : FoldableToolPanel(this, "tonecurve", M("TP_EXPOSURE_LA
ToneCurve::~ToneCurve ()
{
idle_register.destroy();
delete curveEditorG;
delete curveEditorG2;
}
@@ -727,15 +729,8 @@ void ToneCurve::waitForAutoExp ()
method->set_sensitive(false);
}
int autoExpChangedUI (void* data)
{
(static_cast<ToneCurve*>(data))->autoExpComputed_ ();
return 0;
}
void ToneCurve::autoExpChanged (double expcomp, int bright, int contr, int black, int hlcompr, int hlcomprthresh, bool hlrecons)
{
nextBlack = black;
nextExpcomp = expcomp;
nextBrightness = bright;
@@ -743,7 +738,14 @@ void ToneCurve::autoExpChanged (double expcomp, int bright, int contr, int black
nextHlcompr = hlcompr;
nextHlcomprthresh = hlcomprthresh;
nextHLRecons = hlrecons;
g_idle_add (autoExpChangedUI, this);
const auto func = [](gpointer data) -> gboolean {
static_cast<ToneCurve*>(data)->autoExpComputed_();
return FALSE;
};
idle_register.add(func, this);
}
void ToneCurve::enableAll ()

View File

@@ -29,6 +29,8 @@
class ToneCurve : public ToolParamBlock, public AdjusterListener, public FoldableToolPanel, public rtengine::AutoExpListener, public CurveListener
{
private:
IdleRegister idle_register;
protected:
// from HLRecovery
@@ -73,7 +75,6 @@ protected:
bool nextHLRecons;
public:
ToneCurve ();
~ToneCurve ();

View File

@@ -877,6 +877,8 @@ Wavelet::Wavelet() :
Wavelet::~Wavelet ()
{
idle_register.destroy();
delete opaCurveEditorG;
delete opacityCurveEditorG;
delete CCWcurveEditorG;
@@ -887,26 +889,28 @@ Wavelet::~Wavelet ()
delete opacityCurveEditorWL;
}
int wavUpdateUI (void* data)
{
GThreadLock lock; // All GUI acces from idle_add callbacks or separate thread HAVE to be protected
(static_cast<Wavelet*>(data))->wavComputed_ ();
return 0;
}
void Wavelet::wavChanged (double nlevel)
{
nextnlevel = nlevel;
g_idle_add (wavUpdateUI, this);
const auto func = [](gpointer data) -> gboolean {
GThreadLock lock; // All GUI acces from idle_add callbacks or separate thread HAVE to be protected
static_cast<Wavelet*>(data)->wavComputed_();
return FALSE;
};
idle_register.add(func, this);
}
bool Wavelet::wavComputed_ ()
{
disableListener ();
enableListener ();
updatewavLabel ();
return false;
}
void Wavelet::updatewavLabel ()
{
if (!batchMode) {

View File

@@ -40,7 +40,7 @@ class Wavelet :
{
public:
Wavelet ();
virtual ~Wavelet ();
~Wavelet ();
bool wavComputed_ ();
void adjusterChanged (ThresholdAdjuster* a, double newBottom, double newTop);
@@ -248,4 +248,6 @@ private:
bool lastmedian, lastmedianlev, lastlinkedg, lastavoid, lastlipst, lasttmr, lastcbenab;
int nextnlevel;
IdleRegister idle_register;
};