Skip to content

Commit

Permalink
Darkroom: wait for pipe threads to finish before carrying on for styl…
Browse files Browse the repository at this point in the history
…es and leaving
  • Loading branch information
aurelienpierre committed Jan 17, 2025
1 parent d5c1af7 commit bb2c114
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
1 change: 0 additions & 1 deletion src/common/styles.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,6 @@ void dt_styles_apply_to_image(const char *name, const gboolean duplicate, const

/* remove old obsolete thumbnails */
dt_mipmap_cache_remove(darktable.mipmap_cache, newimgid);
dt_image_update_final_size(newimgid);

/* update the aspect ratio. recompute only if really needed for performance reasons */
if(darktable.collection->params.sort == DT_COLLECTION_SORT_ASPECT_RATIO)
Expand Down
17 changes: 5 additions & 12 deletions src/develop/develop.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ void dt_dev_process_preview_job(dt_develop_t *dev)

if(buffer) dt_free_align(buffer);
pipe->running = 0;
dt_print(DT_DEBUG_DEV, "[pixelpipe] exiting preview pipe thread\n");
}


Expand Down Expand Up @@ -578,6 +579,7 @@ void dt_dev_process_image_job(dt_develop_t *dev)

if(buffer) dt_free_align(buffer);
pipe->running = 0;
dt_print(DT_DEBUG_DEV, "[pixelpipe] exiting main image pipe thread\n");
}


Expand Down Expand Up @@ -616,11 +618,6 @@ static inline int _dt_dev_load_raw(dt_develop_t *dev, const uint32_t imgid)
return (no_valid_image || no_valid_thumb);
}

void dt_dev_reload_image(dt_develop_t *dev, const uint32_t imgid)
{
dt_dev_load_image(dev, imgid);
}

float dt_dev_get_zoom_scale(dt_develop_t *dev, dt_dev_zoom_t zoom, int closeup_factor, int preview)
{
float zoom_scale;
Expand Down Expand Up @@ -654,16 +651,12 @@ float dt_dev_get_zoom_scale(dt_develop_t *dev, dt_dev_zoom_t zoom, int closeup_f

int dt_dev_load_image(dt_develop_t *dev, const uint32_t imgid)
{
dt_pthread_mutex_lock(&dev->history_mutex);

if(_dt_dev_load_raw(dev, imgid))
{
dt_pthread_mutex_unlock(&dev->history_mutex);
return 1;
}
if(_dt_dev_load_raw(dev, imgid)) return 1;

// we need a global lock as the dev->iop set must not be changed until read history is terminated
dt_pthread_mutex_lock(&dev->history_mutex);
dev->iop = dt_iop_load_modules(dev);

dt_dev_read_history_ext(dev, dev->image_storage.id, FALSE);

if(dev->pipe)
Expand Down
1 change: 0 additions & 1 deletion src/develop/develop.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ void dt_dev_refresh_ui_images_real(dt_develop_t *dev);
#define dt_dev_refresh_ui_images(dev) DT_DEBUG_TRACE_WRAPPER(DT_DEBUG_DEV, dt_dev_refresh_ui_images_real, (dev))

int dt_dev_load_image(dt_develop_t *dev, const uint32_t imgid);
void dt_dev_reload_image(dt_develop_t *dev, const uint32_t imgid);
/** checks if provided imgid is the image currently in develop */
int dt_dev_is_current_image(dt_develop_t *dev, uint32_t imgid);

Expand Down
7 changes: 0 additions & 7 deletions src/iop/demosaic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1536,13 +1536,6 @@ void gui_changed(dt_iop_module_t *self, GtkWidget *w, void *previous)
const int mask_bw = dt_image_monochrome_flags(img);
changed ^= img->flags & DT_IMAGE_MONOCHROME_BAYER;
dt_image_cache_write_release(darktable.image_cache, img, DT_IMAGE_CACHE_RELAXED);
if(changed)
{
dt_imageio_update_monochrome_workflow_tag(self->dev->image_storage.id, mask_bw);
// only done if one of the passthrough monochrome demosaicers has changed
// we reload the image so all modules respect this setting
dt_dev_reload_image(self->dev, self->dev->image_storage.id);
}
}
void gui_update(struct dt_iop_module_t *self)
{
Expand Down
25 changes: 21 additions & 4 deletions src/views/darkroom.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,22 +828,32 @@ static void _darkroom_ui_apply_style_activate_callback(gchar *name)
{
dt_control_log(_("applied style `%s' on current image"), name);

darktable.develop->exit = 1;

// Wait for pipelines to return
dt_pthread_mutex_lock(&darktable.develop->preview_pipe->busy_mutex);
dt_pthread_mutex_unlock(&darktable.develop->preview_pipe->busy_mutex);

dt_pthread_mutex_lock(&darktable.develop->pipe->busy_mutex);
dt_pthread_mutex_unlock(&darktable.develop->pipe->busy_mutex);

/* write current history changes so nothing gets lost */
dt_dev_write_history(darktable.develop);

dt_dev_undo_start_record(darktable.develop);

/* apply style on image and reload*/
dt_styles_apply_to_image(name, FALSE, FALSE, darktable.develop->image_storage.id);
dt_dev_reload_image(darktable.develop, darktable.develop->image_storage.id);

DT_DEBUG_CONTROL_SIGNAL_RAISE(darktable.signals, DT_SIGNAL_TAG_CHANGED);

/* record current history state : after change (needed for undo) */
dt_dev_undo_end_record(darktable.develop);

// rebuild the accelerators (style might have changed order)
dt_iop_connect_accels_all();

darktable.develop->exit = 0;

// Recompute the view
dt_dev_refresh_ui_images(darktable.develop);
}

static void _darkroom_ui_apply_style_popupmenu(GtkWidget *w, gpointer user_data)
Expand Down Expand Up @@ -2348,6 +2358,13 @@ void leave(dt_view_t *self)
dt_develop_t *dev = (dt_develop_t *)self->data;
dev->exit = 1;

// Wait for pipelines to return
dt_pthread_mutex_lock(&dev->preview_pipe->busy_mutex);
dt_pthread_mutex_unlock(&dev->preview_pipe->busy_mutex);

dt_pthread_mutex_lock(&dev->pipe->busy_mutex);
dt_pthread_mutex_unlock(&dev->pipe->busy_mutex);

dt_iop_color_picker_cleanup();
if(darktable.lib->proxy.colorpicker.picker_proxy)
dt_iop_color_picker_reset(darktable.lib->proxy.colorpicker.picker_proxy->module, FALSE);
Expand Down

0 comments on commit bb2c114

Please sign in to comment.