Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IdleRegister to deal with destruction while idle func is queued #3677

Merged
merged 2 commits into from Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions rtgui/batchqueue.cc
Expand Up @@ -85,6 +85,8 @@ BatchQueue::BatchQueue (FileCatalog* aFileCatalog) : processing(nullptr), fileCa

BatchQueue::~BatchQueue ()
{
idle_register.destroy();

MYWRITERLOCK(l, entryRW);

// The listener merges parameters with old values, so delete afterwards
Expand Down Expand Up @@ -937,7 +939,7 @@ void BatchQueue::notifyListener (bool queueEmptied)
}
params->queueEmptied = queueEmptied;
params->queueError = false;
add_idle (bqnotifylistenerUI, params);
idle_register.add(bqnotifylistenerUI, params);
}
}

Expand Down Expand Up @@ -967,6 +969,6 @@ void BatchQueue::error (Glib::ustring msg)
params->queueEmptied = false;
params->queueError = true;
params->queueErrorMessage = msg;
add_idle (bqnotifylistenerUI, params);
idle_register.add(bqnotifylistenerUI, params);
}
}
59 changes: 31 additions & 28 deletions rtgui/batchqueue.h
Expand Up @@ -36,37 +36,12 @@ class BatchQueueListener
};

class FileCatalog;
class BatchQueue : public ThumbBrowserBase,

class BatchQueue final :
public ThumbBrowserBase,
public rtengine::BatchProcessingListener,
public LWButtonListener
{

protected:
int getMaxThumbnailHeight() const;
void saveThumbnailHeight (int height);
int getThumbnailHeight ();

BatchQueueEntry* processing; // holds the currently processed image
FileCatalog* fileCatalog;
int sequence; // holds the current sequence index

Glib::ustring nameTemplate;

MyImageMenuItem* cancel;
MyImageMenuItem* head;
MyImageMenuItem* tail;
Gtk::MenuItem* selall;
Gtk::MenuItem* open;
Glib::RefPtr<Gtk::AccelGroup> pmaccelgroup;
Gtk::Menu pmenu;

BatchQueueListener* listener;

Glib::ustring autoCompleteFileName (const Glib::ustring& fileName, const Glib::ustring& format);
Glib::ustring getTempFilenameForParams( const Glib::ustring &filename );
bool saveBatchQueue ();
void notifyListener (bool queueEmptied);

public:
explicit BatchQueue (FileCatalog* aFileCatalog);
~BatchQueue ();
Expand Down Expand Up @@ -106,6 +81,34 @@ class BatchQueue : public ThumbBrowserBase,

static Glib::ustring calcAutoFileNameBase (const Glib::ustring& origFileName, int sequence = 0);
static int calcMaxThumbnailHeight();

protected:
int getMaxThumbnailHeight() const;
void saveThumbnailHeight (int height);
int getThumbnailHeight ();

Glib::ustring autoCompleteFileName (const Glib::ustring& fileName, const Glib::ustring& format);
Glib::ustring getTempFilenameForParams( const Glib::ustring &filename );
bool saveBatchQueue ();
void notifyListener (bool queueEmptied);

BatchQueueEntry* processing; // holds the currently processed image
FileCatalog* fileCatalog;
int sequence; // holds the current sequence index

Glib::ustring nameTemplate;

MyImageMenuItem* cancel;
MyImageMenuItem* head;
MyImageMenuItem* tail;
Gtk::MenuItem* selall;
Gtk::MenuItem* open;
Glib::RefPtr<Gtk::AccelGroup> pmaccelgroup;
Gtk::Menu pmenu;

BatchQueueListener* listener;

IdleRegister idle_register;
};

#endif
16 changes: 9 additions & 7 deletions rtgui/blackwhite.cc
Expand Up @@ -364,23 +364,25 @@ BlackWhite::BlackWhite (): FoldableToolPanel(this, "blackwhite", M("TP_BWMIX_LAB
}
BlackWhite::~BlackWhite ()
{
idle_register.destroy();

delete luminanceCEG;
delete beforeCurveCEG;
delete afterCurveCEG;
}

int BWChangedUI (void* data)
{
(static_cast<BlackWhite*>(data))->BWComputed_ ();
return 0;
}

void BlackWhite::BWChanged (double redbw, double greenbw, double bluebw)
{
nextredbw = redbw;
nextgreenbw = greenbw;
nextbluebw = bluebw;
add_idle (BWChangedUI, this);

const auto func = [](gpointer data) -> gboolean {
static_cast<BlackWhite*>(data)->BWComputed_();
return FALSE;
};

idle_register.add(func, this);
}

bool BlackWhite::BWComputed_ ()
Expand Down
108 changes: 57 additions & 51 deletions rtgui/blackwhite.h
Expand Up @@ -28,10 +28,64 @@
#include "mycurve.h"
#include "colorprovider.h"

class BlackWhite : public ToolParamBlock, public AdjusterListener, public FoldableToolPanel, public rtengine::AutoBWListener, public CurveListener, public ColorProvider
class BlackWhite final :
public ToolParamBlock,
public AdjusterListener,
public FoldableToolPanel,
public rtengine::AutoBWListener,
public CurveListener,
public ColorProvider
{
public:

BlackWhite ();
~BlackWhite ();

void read (const rtengine::procparams::ProcParams* pp, const ParamsEdited* pedited = nullptr);
void write (rtengine::procparams::ProcParams* pp, ParamsEdited* pedited = nullptr);
void setDefaults (const rtengine::procparams::ProcParams* defParams, const ParamsEdited* pedited = nullptr);
void setBatchMode (bool batchMode);
void autoOpenCurve ();
void setEditProvider (EditDataProvider *provider);

void autoch_toggled ();
void neutral_pressed ();

void updateRGBLabel ();
void adjusterChanged (Adjuster* a, double newval);
void setAdjusterBehavior (bool bwadd, bool bwgadd);
void trimValues (rtengine::procparams::ProcParams* pp);
void enabledcc_toggled ();
void enabledChanged ();
void methodChanged ();
void filterChanged ();
void settingChanged ();
virtual void colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller* caller);
void BWChanged (double redbw, double greenbw, double bluebw);
bool BWComputed_ ();
void curveChanged (CurveEditor* ce);
void curveMode1Changed ();
bool curveMode1Changed_ ();
void curveMode1Changed2 ();
bool curveMode1Changed2_ ();
void algoChanged ();

Glib::ustring getSettingString ();
Glib::ustring getFilterString ();
Glib::ustring getalgoString ();

private:
void showLuminance();
void hideLuminance();
void showFilter();
void hideFilter();
void showEnabledCC();
void hideEnabledCC();
void showMixer(int nChannels, bool RGBIsSensitive = true);
void hideMixer();
void showGamma();
void hideGamma();

protected:
FlatCurveEditor* luminanceCurve;
Gtk::HSeparator* luminanceSep;
CurveEditorGroup* luminanceCEG;
Expand Down Expand Up @@ -85,55 +139,7 @@ class BlackWhite : public ToolParamBlock, public AdjusterListener, public Foldab
double nextgreenbw;
double nextbluebw;

void showLuminance();
void hideLuminance();
void showFilter();
void hideFilter();
void showEnabledCC();
void hideEnabledCC();
void showMixer(int nChannels, bool RGBIsSensitive = true);
void hideMixer();
void showGamma();
void hideGamma();

public:

BlackWhite ();
~BlackWhite ();

void read (const rtengine::procparams::ProcParams* pp, const ParamsEdited* pedited = nullptr);
void write (rtengine::procparams::ProcParams* pp, ParamsEdited* pedited = nullptr);
void setDefaults (const rtengine::procparams::ProcParams* defParams, const ParamsEdited* pedited = nullptr);
void setBatchMode (bool batchMode);
void autoOpenCurve ();
void setEditProvider (EditDataProvider *provider);

void autoch_toggled ();
void neutral_pressed ();

void updateRGBLabel ();
void adjusterChanged (Adjuster* a, double newval);
void setAdjusterBehavior (bool bwadd, bool bwgadd);
void trimValues (rtengine::procparams::ProcParams* pp);
void enabledcc_toggled ();
void enabledChanged ();
void methodChanged ();
void filterChanged ();
void settingChanged ();
virtual void colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller* caller);
void BWChanged (double redbw, double greenbw, double bluebw);
bool BWComputed_ ();
void curveChanged (CurveEditor* ce);
void curveMode1Changed ();
bool curveMode1Changed_ ();
void curveMode1Changed2 ();
bool curveMode1Changed2_ ();
void algoChanged ();

Glib::ustring getSettingString ();
Glib::ustring getFilterString ();
Glib::ustring getalgoString ();

IdleRegister idle_register;
};

#endif
1 change: 1 addition & 0 deletions rtgui/cachemanager.cc
Expand Up @@ -19,6 +19,7 @@
#include "cachemanager.h"

#include <memory>
#include <iostream>

#include <glib/gstdio.h>
#include <giomm.h>
Expand Down
30 changes: 18 additions & 12 deletions rtgui/colorappearance.cc
Expand Up @@ -424,6 +424,8 @@ ColorAppearance::ColorAppearance () : FoldableToolPanel(this, "colorappearance",

ColorAppearance::~ColorAppearance ()
{
idle_register.destroy();

delete curveEditorG;
delete curveEditorG2;
delete curveEditorG3;
Expand Down Expand Up @@ -1002,15 +1004,17 @@ void ColorAppearance::setDefaults (const ProcParams* defParams, const ParamsEdit

}
}
int autoCamChangedUI (void* data)
{
(static_cast<ColorAppearance*>(data))->autoCamComputed_ ();
return 0;
}

void ColorAppearance::autoCamChanged (double ccam)
{
nextCcam = ccam;
add_idle (autoCamChangedUI, this);

const auto func = [](gpointer data) -> gboolean {
static_cast<ColorAppearance*>(data)->autoCamComputed_();
return FALSE;
};

idle_register.add(func, this);
}

bool ColorAppearance::autoCamComputed_ ()
Expand All @@ -1023,15 +1027,17 @@ bool ColorAppearance::autoCamComputed_ ()

return false;
}
int adapCamChangedUI (void* data)
{
(static_cast<ColorAppearance*>(data))->adapCamComputed_ ();
return 0;
}

void ColorAppearance::adapCamChanged (double cadap)
{
nextCadap = cadap;
add_idle (adapCamChangedUI, this);

const auto func = [](gpointer data) -> gboolean {
static_cast<ColorAppearance*>(data)->adapCamComputed_();
return FALSE;
};

idle_register.add(func, this);
}

bool ColorAppearance::adapCamComputed_ ()
Expand Down