Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
worker.c File Reference

Drawlayer realtime worker thread and FIFO event queue. More...

+ Include dependency graph for worker.c:

Go to the source code of this file.

Data Structures

struct  drawlayer_rt_callbacks_t
 Per-worker callback vtable. More...
 
struct  drawlayer_rt_worker_t
 One worker thread runtime including event ring buffer. More...
 
struct  dt_drawlayer_worker_t
 Drawlayer worker global state shared with drawlayer module. More...
 
struct  drawlayer_paint_backend_ctx_t
 
struct  drawlayer_rt_thread_ctx_t
 

Macros

#define DRAWLAYER_BATCH_TILE_SIZE   128
 
#define DRAWLAYER_HEARTBEAT_PATCH_NAME   "drawlayer heartbeat patch"
 
#define DRAWLAYER_HEARTBEAT_MASK_NAME   "drawlayer heartbeat stroke mask"
 
#define DRAWLAYER_OUTER_LIVE_BATCH_MULTIPLIER   2u
 

Typedefs

typedef enum drawlayer_rt_worker_kind_t drawlayer_rt_worker_kind_t
 Internal worker slot kinds (currently backend only).
 
typedef void(* drawlayer_rt_sample_cb) (dt_iop_module_t *self, dt_drawlayer_worker_t *rt, const dt_drawlayer_paint_raw_input_t *input)
 Callback signature for one raw-input event processing.
 
typedef void(* drawlayer_rt_stroke_end_cb) (dt_iop_module_t *self, dt_drawlayer_worker_t *rt)
 Callback signature for stroke-end event processing.
 
typedef void(* drawlayer_rt_idle_cb) (dt_iop_module_t *self, dt_drawlayer_worker_t *rt)
 Callback signature for idle transitions inside worker loop.
 
typedef struct drawlayer_rt_callbacks_t drawlayer_rt_callbacks_t
 Per-worker callback vtable.
 
typedef struct drawlayer_rt_worker_t drawlayer_rt_worker_t
 One worker thread runtime including event ring buffer.
 
typedef struct drawlayer_paint_backend_ctx_t drawlayer_paint_backend_ctx_t
 
typedef struct drawlayer_rt_thread_ctx_t drawlayer_rt_thread_ctx_t
 

Enumerations

enum  drawlayer_rt_worker_kind_t {
  DRAWLAYER_RT_WORKER_BACKEND = 0 ,
  DRAWLAYER_RT_WORKER_COUNT = 1
}
 Internal worker slot kinds (currently backend only). More...
 

Functions

static gboolean _paint_build_dab_cb (void *user_data, dt_drawlayer_paint_stroke_t *state, const dt_drawlayer_paint_raw_input_t *input, dt_drawlayer_brush_dab_t *out_dab)
 
static void _paint_stroke_seed_cb (void *user_data, uint64_t stroke_seed)
 
static void _publish_backend_progress (drawlayer_paint_backend_ctx_t *ctx, gboolean flush_pending)
 
static gboolean _commit_dabs_on_gui_thread (gpointer user_data)
 Run the stroke-end commit on the GUI thread.
 
static void _cancel_pending_gui_commit (dt_drawlayer_worker_t *rt)
 Drop a queued GUI-thread commit request. GUI thread only.
 
static void _process_backend_input (dt_iop_module_t *self, const dt_drawlayer_paint_raw_input_t *input, dt_drawlayer_paint_stroke_t *stroke)
 
static gboolean _process_backend_dab (const dt_drawlayer_brush_dab_t *dab, drawlayer_paint_backend_ctx_t *ctx, const dt_drawlayer_cache_patch_t *sample_patch, dt_drawlayer_cache_patch_t *patch, dt_drawlayer_cache_patch_t *stroke_mask, dt_drawlayer_damaged_rect_t *batch_damage)
 
static drawlayer_rt_worker_t * _backend_worker (dt_drawlayer_worker_t *rt)
 
static const drawlayer_rt_worker_t * _backend_worker_const (const dt_drawlayer_worker_t *rt)
 
static gint64 _live_publish_interval_us (void)
 
static gboolean _live_publish_deadline_reached (const dt_drawlayer_worker_t *rt, const gint64 input_ts, const gint64 interval_us)
 
static drawlayer_paint_backend_ctx_t _make_backend_ctx (dt_iop_module_t *self, dt_drawlayer_worker_t *worker, dt_drawlayer_paint_stroke_t *stroke)
 
static guint _rasterize_pending_dab_batch (drawlayer_paint_backend_ctx_t *ctx, gint64 budget_us)
 
static gboolean _rt_queue_pop_locked (dt_drawlayer_worker_t *rt, dt_drawlayer_paint_raw_input_t *event)
 Pop one event from ring queue (lock must be held).
 
static guint _worker_batch_min_size (void)
 
static void _log_worker_batch_timing (const char *tag, guint processed_dabs, guint thread_count, double elapsed_ms, gboolean outer_loop)
 
static gboolean _dab_bounds_in_patch (const dt_drawlayer_cache_patch_t *patch, float scale, const dt_drawlayer_brush_dab_t *dab, dt_drawlayer_damaged_rect_t *bounds)
 
gboolean dt_drawlayer_build_worker_input_dab (dt_iop_module_t *self, dt_drawlayer_paint_stroke_t *state, const dt_drawlayer_paint_raw_input_t *input, dt_drawlayer_brush_dab_t *dab)
 
void dt_drawlayer_worker_publish_backend_stroke_damage (dt_iop_module_t *self)
 Publish accumulated backend stroke damage into drawlayer process/runtime state.
 
static void _stop_worker (dt_iop_module_t *self, dt_drawlayer_worker_t *rt)
 Stop worker thread and clear transient state.
 
static void _stroke_destroy (dt_drawlayer_worker_t *rt)
 Destroy stroke runtime and owned dab window.
 
static gboolean _stroke_create (dt_drawlayer_worker_t *rt)
 Create stroke runtime if missing.
 
static gboolean _stroke_begin (dt_drawlayer_worker_t *rt)
 Start new stroke runtime and reset history/path state.
 
static void _stroke_clear (dt_drawlayer_worker_t *rt)
 Clear current stroke state while preserving allocations.
 
static void _reset_backend_path (dt_drawlayer_worker_t *rt)
 
static void _reset_live_publish (dt_drawlayer_worker_t *rt)
 
static gboolean _collect_batch_bounds (const GArray *dabs, const guint max_dabs, const dt_drawlayer_cache_patch_t *patch, dt_drawlayer_damaged_rect_t *batch_bounds)
 Build the scratch patch bounds that cover the next heartbeat dab batch.
 
static gboolean _ensure_heartbeat_batch_buffers (dt_drawlayer_worker_t *rt, const dt_drawlayer_damaged_rect_t *batch_bounds)
 Ensure worker-private heartbeat scratch buffers match the requested batch bounds.
 
static void _copy_rgba_batch_from_locked_patch (const dt_drawlayer_cache_patch_t *src, dt_drawlayer_cache_patch_t *dst)
 Copy one locked RGBA source region into the heartbeat scratch patch.
 
static void _copy_mask_batch_from_locked_patch (const dt_drawlayer_cache_patch_t *src, dt_drawlayer_cache_patch_t *dst)
 Copy one locked alpha-mask source region into the heartbeat scratch mask.
 
static gboolean _translate_batch_damage (const dt_drawlayer_cache_patch_t *patch, const dt_drawlayer_damaged_rect_t *local_damage, dt_drawlayer_damaged_rect_t *absolute_damage)
 Translate scratch-local damage coordinates back into base-patch coordinates.
 
static void _copy_rgba_damage_to_locked_patch (const dt_drawlayer_cache_patch_t *src, const dt_drawlayer_damaged_rect_t *local_damage, dt_drawlayer_cache_patch_t *dst)
 Copy the written scratch sub-rectangle back into the locked base patch.
 
static void _copy_mask_damage_to_locked_patch (const dt_drawlayer_cache_patch_t *src, const dt_drawlayer_damaged_rect_t *local_damage, dt_drawlayer_cache_patch_t *dst)
 Copy the written scratch mask sub-rectangle back into the locked base stroke mask.
 
static void _clear_rgba_damage_in_patch (dt_drawlayer_cache_patch_t *patch, const dt_drawlayer_damaged_rect_t *local_damage)
 Clear only the flushed RGBA sub-rectangle in the heartbeat scratch patch.
 
static void _clear_mask_damage_in_patch (dt_drawlayer_cache_patch_t *patch, const dt_drawlayer_damaged_rect_t *local_damage)
 Clear only the flushed alpha-mask sub-rectangle in the heartbeat scratch mask.
 
static void _rt_queue_clear_locked (dt_drawlayer_worker_t *rt)
 Clear queued events (lock must be held).
 
static gboolean _rt_queue_empty (const dt_drawlayer_worker_t *rt)
 Test whether event queue is empty.
 
static gboolean _rt_queue_full (const dt_drawlayer_worker_t *rt)
 Test whether event queue is full.
 
static gboolean _rt_queue_push_locked (dt_drawlayer_worker_t *rt, const dt_drawlayer_paint_raw_input_t *event)
 Push one event in ring queue (lock must be held).
 
static gboolean _worker_is_started (const drawlayer_rt_worker_t *worker)
 
static gboolean _worker_is_busy (const drawlayer_rt_worker_t *worker)
 
static gboolean _worker_pause_requested (const drawlayer_rt_worker_t *worker)
 
static gboolean _backend_pending_dabs_locked (const dt_drawlayer_worker_t *rt)
 
static void _rt_set_worker_state (dt_drawlayer_worker_t *rt, const dt_drawlayer_worker_state_t state)
 Set worker state atomically under caller synchronization.
 
static void _set_current_thread_realtime_best_effort (void)
 Try elevating current thread scheduling policy for lower-latency input.
 
static gboolean _workers_active_locked (const dt_drawlayer_worker_t *rt)
 Check whether workers still have pending activity (lock must be held).
 
static gboolean _workers_any_active_locked (const dt_drawlayer_worker_t *rt)
 Check whether any worker activity remains.
 
static gboolean _workers_ready_for_commit_locked (const dt_drawlayer_worker_t *rt)
 Check if workers are idle and commit can be safely scheduled.
 
static gboolean _rt_workers_active (dt_drawlayer_worker_t *rt)
 Thread-safe wrapper for active-workers status.
 
static gboolean _rt_workers_any_active (dt_drawlayer_worker_t *rt)
 Thread-safe wrapper for any worker activity.
 
static void _backend_worker_on_idle (dt_iop_module_t *self, dt_drawlayer_worker_t *rt)
 Backend-worker idle hook.
 
static void _backend_worker_process_sample (dt_iop_module_t *self, dt_drawlayer_worker_t *rt, const dt_drawlayer_paint_raw_input_t *input)
 Process one backend raw input event.
 
static void _backend_worker_process_stroke_end (dt_iop_module_t *self, dt_drawlayer_worker_t *rt)
 Handle backend stroke end: flush, reset, and request commit.
 
static void _rt_destroy_state (dt_iop_module_t *self, dt_drawlayer_worker_t **rt_out)
 Stop and free an existing worker state object.
 
static void _rt_init_state (dt_iop_module_t *self, dt_drawlayer_worker_t **rt_out, gboolean *painting, gboolean *finish_commit_pending, guint *stroke_sample_count, uint32_t *current_stroke_batch)
 Allocate and initialize worker state object and buffers.
 
static void _rt_cleanup_state (dt_drawlayer_worker_t **rt_out)
 Destroy worker state object and all owned resources.
 
gboolean dt_drawlayer_worker_wait_idle (dt_iop_module_t *self, dt_drawlayer_worker_t *rt)
 Wait until worker queue is drained and not busy.
 
static void * _drawlayer_worker_main (void *user_data)
 Worker main loop: FIFO dequeue, process, and idle scheduling.
 
static gboolean _start_worker (dt_iop_module_t *self, dt_drawlayer_worker_t *rt)
 Start backend worker thread if not running.
 
void dt_drawlayer_worker_cancel_async_commit (dt_drawlayer_worker_t *rt)
 Cancel deferred commit request state if any.
 
void dt_drawlayer_worker_pause (dt_iop_module_t *self, dt_drawlayer_worker_t *rt)
 Pause worker processing after current callback returns.
 
void dt_drawlayer_worker_resume (dt_iop_module_t *self, dt_drawlayer_worker_t *rt)
 Resume worker processing and wake sleeping thread.
 
static gboolean _enqueue_event (dt_iop_module_t *self, dt_drawlayer_worker_t *rt, const dt_drawlayer_paint_raw_input_t *event)
 Generic enqueue helper ensuring worker startup.
 
static gboolean _enqueue_input (dt_iop_module_t *self, dt_drawlayer_worker_t *rt, const dt_drawlayer_paint_raw_input_t *input)
 Enqueue raw input with saturation policy and stroke-abort fallback.
 
static gboolean _enqueue_stroke_end (dt_iop_module_t *self, dt_drawlayer_worker_t *rt, const dt_drawlayer_paint_raw_input_t *input)
 Enqueue explicit stroke-end event (with optional raw release sample).
 
void dt_drawlayer_worker_init (dt_iop_module_t *self, dt_drawlayer_worker_t **worker, gboolean *painting, gboolean *finish_commit_pending, guint *stroke_sample_count, uint32_t *current_stroke_batch)
 Public worker initialization entry point.
 
void dt_drawlayer_worker_cleanup (dt_drawlayer_worker_t **worker)
 Public worker cleanup entry point.
 
gboolean dt_drawlayer_worker_active (const dt_drawlayer_worker_t *worker)
 Public status query: TRUE when worker has pending activity.
 
gboolean dt_drawlayer_worker_any_active (const dt_drawlayer_worker_t *worker)
 Public status query: TRUE when any worker still has pending activity.
 
gboolean dt_drawlayer_worker_ensure_running (dt_iop_module_t *self, dt_drawlayer_worker_t *rt)
 Ensure realtime/backend worker threads are started.
 
void dt_drawlayer_worker_stop (dt_iop_module_t *self, dt_drawlayer_worker_t *rt)
 Stop realtime and full-resolution worker threads.
 
void dt_drawlayer_worker_get_snapshot (const dt_drawlayer_worker_t *worker, dt_drawlayer_worker_snapshot_t *snapshot)
 Return a thread-safe worker snapshot for runtime scheduling.
 
void dt_drawlayer_worker_request_commit (dt_drawlayer_worker_t *worker)
 Public commit request helper.
 
void dt_drawlayer_worker_snapshot_params (dt_drawlayer_worker_t *worker, const dt_iop_drawlayer_params_t *params)
 Seed the worker's private params blob for the stroke about to start. GUI thread only.
 
void dt_drawlayer_worker_seal_for_commit (dt_drawlayer_worker_t *worker)
 Seal current stroke for synchronous commit.
 
void dt_drawlayer_worker_reset_backend_path (dt_drawlayer_worker_t *worker)
 Reset worker-owned backend damage accumulator.
 
void dt_drawlayer_worker_reset_live_publish (dt_drawlayer_worker_t *worker)
 Reset worker-owned transient live-publish state.
 
void dt_drawlayer_worker_reset_stroke (dt_drawlayer_worker_t *worker)
 Clear preserved stroke runtime/history after commit completed.
 
GArray * dt_drawlayer_worker_raw_inputs (dt_drawlayer_worker_t *worker)
 Read-only access to preserved raw input history.
 
gboolean dt_drawlayer_worker_enqueue_input (dt_drawlayer_worker_t *worker, const dt_drawlayer_paint_raw_input_t *input)
 Public FIFO enqueue for one raw input event.
 
gboolean dt_drawlayer_worker_enqueue_stroke_end (dt_drawlayer_worker_t *worker, const dt_drawlayer_paint_raw_input_t *input)
 Public FIFO enqueue for stroke-end event.
 

Variables

static const drawlayer_rt_callbacks_t _rt_callbacks [DRAWLAYER_RT_WORKER_COUNT]
 

Detailed Description

Drawlayer realtime worker thread and FIFO event queue.

Definition in file worker.c.

Macro Definition Documentation

◆ DRAWLAYER_BATCH_TILE_SIZE

#define DRAWLAYER_BATCH_TILE_SIZE   128

Definition at line 179 of file worker.c.

◆ DRAWLAYER_HEARTBEAT_MASK_NAME

#define DRAWLAYER_HEARTBEAT_MASK_NAME   "drawlayer heartbeat stroke mask"

Definition at line 181 of file worker.c.

◆ DRAWLAYER_HEARTBEAT_PATCH_NAME

#define DRAWLAYER_HEARTBEAT_PATCH_NAME   "drawlayer heartbeat patch"

Definition at line 180 of file worker.c.

◆ DRAWLAYER_OUTER_LIVE_BATCH_MULTIPLIER

#define DRAWLAYER_OUTER_LIVE_BATCH_MULTIPLIER   2u

Definition at line 182 of file worker.c.

Typedef Documentation

◆ drawlayer_paint_backend_ctx_t

◆ drawlayer_rt_callbacks_t

Per-worker callback vtable.

◆ drawlayer_rt_idle_cb

typedef void(* drawlayer_rt_idle_cb) (dt_iop_module_t *self, dt_drawlayer_worker_t *rt)

Callback signature for idle transitions inside worker loop.

Definition at line 67 of file worker.c.

◆ drawlayer_rt_sample_cb

typedef void(* drawlayer_rt_sample_cb) (dt_iop_module_t *self, dt_drawlayer_worker_t *rt, const dt_drawlayer_paint_raw_input_t *input)

Callback signature for one raw-input event processing.

Definition at line 62 of file worker.c.

◆ drawlayer_rt_stroke_end_cb

typedef void(* drawlayer_rt_stroke_end_cb) (dt_iop_module_t *self, dt_drawlayer_worker_t *rt)

Callback signature for stroke-end event processing.

Definition at line 65 of file worker.c.

◆ drawlayer_rt_thread_ctx_t

◆ drawlayer_rt_worker_kind_t

Internal worker slot kinds (currently backend only).

◆ drawlayer_rt_worker_t

One worker thread runtime including event ring buffer.

Enumeration Type Documentation

◆ drawlayer_rt_worker_kind_t

Internal worker slot kinds (currently backend only).

Enumerator
DRAWLAYER_RT_WORKER_BACKEND 
DRAWLAYER_RT_WORKER_COUNT 

Definition at line 55 of file worker.c.

Function Documentation

◆ _backend_pending_dabs_locked()

static gboolean _backend_pending_dabs_locked ( const dt_drawlayer_worker_t *  rt)
inlinestatic

◆ _backend_worker()

◆ _backend_worker_const()

◆ _backend_worker_on_idle()

◆ _backend_worker_process_sample()

static void _backend_worker_process_sample ( dt_iop_module_t *  self,
dt_drawlayer_worker_t *  rt,
const dt_drawlayer_paint_raw_input_t *  input 
)
static

◆ _backend_worker_process_stroke_end()

static void _backend_worker_process_stroke_end ( dt_iop_module_t *  self,
dt_drawlayer_worker_t *  rt 
)
static

◆ _cancel_pending_gui_commit()

static void _cancel_pending_gui_commit ( dt_drawlayer_worker_t *  rt)
static

Drop a queued GUI-thread commit request. GUI thread only.

Definition at line 1239 of file worker.c.

References dt_drawlayer_worker_t::commit_idle_id, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), IS_NULL_PTR, and dt_drawlayer_worker_t::worker_mutex.

Referenced by _stop_worker().

◆ _clear_mask_damage_in_patch()

static void _clear_mask_damage_in_patch ( dt_drawlayer_cache_patch_t *  patch,
const dt_drawlayer_damaged_rect_t *  local_damage 
)
static

Clear only the flushed alpha-mask sub-rectangle in the heartbeat scratch mask.

Definition at line 774 of file worker.c.

References IS_NULL_PTR, dt_drawlayer_damaged_rect_t::nw, dt_drawlayer_cache_patch_t::pixels, row, dt_drawlayer_damaged_rect_t::se, dt_drawlayer_damaged_rect_t::valid, and dt_drawlayer_cache_patch_t::width.

Referenced by _rasterize_pending_dab_batch().

◆ _clear_rgba_damage_in_patch()

static void _clear_rgba_damage_in_patch ( dt_drawlayer_cache_patch_t *  patch,
const dt_drawlayer_damaged_rect_t *  local_damage 
)
static

Clear only the flushed RGBA sub-rectangle in the heartbeat scratch patch.

Definition at line 757 of file worker.c.

References IS_NULL_PTR, dt_drawlayer_damaged_rect_t::nw, dt_drawlayer_cache_patch_t::pixels, row, dt_drawlayer_damaged_rect_t::se, dt_drawlayer_damaged_rect_t::valid, and dt_drawlayer_cache_patch_t::width.

Referenced by _rasterize_pending_dab_batch().

◆ _collect_batch_bounds()

static gboolean _collect_batch_bounds ( const GArray *  dabs,
const guint  max_dabs,
const dt_drawlayer_cache_patch_t *  patch,
dt_drawlayer_damaged_rect_t *  batch_bounds 
)
static

Build the scratch patch bounds that cover the next heartbeat dab batch.

Definition at line 593 of file worker.c.

References _dab_bounds_in_patch(), dt_drawlayer_paint_runtime_note_dab_damage(), FALSE, i, IS_NULL_PTR, and dt_drawlayer_damaged_rect_t::valid.

Referenced by _rasterize_pending_dab_batch().

◆ _commit_dabs_on_gui_thread()

static gboolean _commit_dabs_on_gui_thread ( gpointer  user_data)
static

Run the stroke-end commit on the GUI thread.

The commit must not run on the worker thread. dt_drawlayer_commit_dabs calls dt_drawlayer_worker_wait_idle, which blocks while ring_count > 0, and the ring's only consumer is the worker itself — so a worker-side commit that raced a GUI push parked the worker forever in dt_pthread_cond_wait. The only escape, worker->stop, is set by _stop_worker after it calls dt_drawlayer_worker_wait_idle too, so the next GUI-side commit (a layer operation, focus loss, image change, module removal, quit) hung the GUI thread on the same predicate. The commit also writes self->params and the history stack, both of which belong to the GUI thread.

Definition at line 1220 of file worker.c.

References dt_drawlayer_worker_t::commit_idle_id, dt_drawlayer_commit_dabs(), dt_iop_gui_data(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), g, IS_NULL_PTR, dt_drawlayer_worker_t::stroke, TRUE, and dt_drawlayer_worker_t::worker_mutex.

Referenced by _backend_worker_on_idle().

◆ _copy_mask_batch_from_locked_patch()

static void _copy_mask_batch_from_locked_patch ( const dt_drawlayer_cache_patch_t *  src,
dt_drawlayer_cache_patch_t *  dst 
)
static

Copy one locked alpha-mask source region into the heartbeat scratch mask.

Definition at line 668 of file worker.c.

References dt_drawlayer_cache_patch_t::height, IS_NULL_PTR, dt_drawlayer_cache_patch_t::pixels, width, dt_drawlayer_cache_patch_t::width, dt_drawlayer_cache_patch_t::x, and dt_drawlayer_cache_patch_t::y.

Referenced by _rasterize_pending_dab_batch().

◆ _copy_mask_damage_to_locked_patch()

static void _copy_mask_damage_to_locked_patch ( const dt_drawlayer_cache_patch_t *  src,
const dt_drawlayer_damaged_rect_t *  local_damage,
dt_drawlayer_cache_patch_t *  dst 
)
static

◆ _copy_rgba_batch_from_locked_patch()

static void _copy_rgba_batch_from_locked_patch ( const dt_drawlayer_cache_patch_t *  src,
dt_drawlayer_cache_patch_t *  dst 
)
static

Copy one locked RGBA source region into the heartbeat scratch patch.

Definition at line 650 of file worker.c.

References dt_drawlayer_cache_patch_t::height, IS_NULL_PTR, dt_drawlayer_cache_patch_t::pixels, width, dt_drawlayer_cache_patch_t::width, dt_drawlayer_cache_patch_t::x, and dt_drawlayer_cache_patch_t::y.

Referenced by _rasterize_pending_dab_batch().

◆ _copy_rgba_damage_to_locked_patch()

◆ _dab_bounds_in_patch()

◆ _drawlayer_worker_main()

◆ _enqueue_event()

static gboolean _enqueue_event ( dt_iop_module_t *  self,
dt_drawlayer_worker_t *  rt,
const dt_drawlayer_paint_raw_input_t *  event 
)
static

◆ _enqueue_input()

◆ _enqueue_stroke_end()

static gboolean _enqueue_stroke_end ( dt_iop_module_t *  self,
dt_drawlayer_worker_t *  rt,
const dt_drawlayer_paint_raw_input_t *  input 
)
static

◆ _ensure_heartbeat_batch_buffers()

◆ _live_publish_deadline_reached()

static gboolean _live_publish_deadline_reached ( const dt_drawlayer_worker_t *  rt,
const gint64  input_ts,
const gint64  interval_us 
)
inlinestatic

Definition at line 559 of file worker.c.

References dt_drawlayer_worker_t::live_publish_ts.

Referenced by _backend_worker_on_idle(), and _process_backend_input().

◆ _live_publish_interval_us()

static gint64 _live_publish_interval_us ( void  )
inlinestatic

◆ _log_worker_batch_timing()

static void _log_worker_batch_timing ( const char *  tag,
guint  processed_dabs,
guint  thread_count,
double  elapsed_ms,
gboolean  outer_loop 
)
static

Definition at line 551 of file worker.c.

References DT_DEBUG_PERF, dt_get_debug_flags(), and dt_print().

Referenced by _rasterize_pending_dab_batch().

◆ _make_backend_ctx()

static drawlayer_paint_backend_ctx_t _make_backend_ctx ( dt_iop_module_t *  self,
dt_drawlayer_worker_t *  worker,
dt_drawlayer_paint_stroke_t *  stroke 
)
inlinestatic

◆ _paint_build_dab_cb()

static gboolean _paint_build_dab_cb ( void *  user_data,
dt_drawlayer_paint_stroke_t *  state,
const dt_drawlayer_paint_raw_input_t *  input,
dt_drawlayer_brush_dab_t *  out_dab 
)
static

◆ _paint_stroke_seed_cb()

static void _paint_stroke_seed_cb ( void *  user_data,
uint64_t  stroke_seed 
)
static

◆ _process_backend_dab()

◆ _process_backend_input()

◆ _publish_backend_progress()

◆ _rasterize_pending_dab_batch()

static guint _rasterize_pending_dab_batch ( drawlayer_paint_backend_ctx_t *  ctx,
gint64  budget_us 
)
static

Definition at line 934 of file worker.c.

References _clamp01(), _clear_mask_damage_in_patch(), _clear_rgba_damage_in_patch(), _collect_batch_bounds(), _copy_mask_batch_from_locked_patch(), _copy_mask_damage_to_locked_patch(), _copy_rgba_batch_from_locked_patch(), _copy_rgba_damage_to_locked_patch(), _ensure_heartbeat_batch_buffers(), _log_worker_batch_timing(), _process_backend_dab(), _translate_batch_damage(), _worker_batch_min_size(), dt_drawlayer_worker_t::backend_path, dt_drawlayer_paint_stroke_t::dab_window, dt_drawlayer_paint_stroke_t::distance_percent, DRAWLAYER_OUTER_LIVE_BATCH_MULTIPLIER, dt_dev_pixelpipe_cache_flush_host_pinned_image(), dt_drawlayer_brush_batch_is_uniform(), dt_drawlayer_brush_rasterize_batch(), dt_drawlayer_cache_patch_rdlock(), dt_drawlayer_cache_patch_rdunlock(), dt_drawlayer_cache_patch_wrlock(), dt_drawlayer_cache_patch_wrunlock(), dt_drawlayer_paint_runtime_note_dab_damage(), dt_get_wtime(), dt_iop_gui_data(), FALSE, g, dt_drawlayer_worker_t::heartbeat_noise, dt_drawlayer_worker_t::heartbeat_patch, dt_drawlayer_worker_t::heartbeat_stroke_mask, dt_drawlayer_worker_t::heartbeat_transmittance, IS_NULL_PTR, dt_drawlayer_worker_t::live_publish_damage, MIN, dt_drawlayer_paint_stroke_t::pending_dabs, drawlayer_paint_backend_ctx_t::self, drawlayer_paint_backend_ctx_t::stroke, TRUE, dt_drawlayer_damaged_rect_t::valid, drawlayer_paint_backend_ctx_t::worker, dt_drawlayer_brush_dab_t::x, and dt_drawlayer_brush_dab_t::y.

Referenced by _backend_worker_on_idle(), and _process_backend_input().

◆ _reset_backend_path()

static void _reset_backend_path ( dt_drawlayer_worker_t *  rt)
static

◆ _reset_live_publish()

◆ _rt_cleanup_state()

static void _rt_cleanup_state ( dt_drawlayer_worker_t **  rt_out)
static

Destroy worker state object and all owned resources.

Definition at line 1409 of file worker.c.

References _rt_destroy_state().

Referenced by dt_drawlayer_worker_cleanup().

◆ _rt_destroy_state()

◆ _rt_init_state()

◆ _rt_queue_clear_locked()

static void _rt_queue_clear_locked ( dt_drawlayer_worker_t *  rt)
static

Clear queued events (lock must be held).

Definition at line 1071 of file worker.c.

References _backend_worker(), IS_NULL_PTR, drawlayer_rt_worker_t::ring_count, drawlayer_rt_worker_t::ring_head, and drawlayer_rt_worker_t::ring_tail.

Referenced by _stop_worker().

◆ _rt_queue_empty()

static gboolean _rt_queue_empty ( const dt_drawlayer_worker_t *  rt)
static

Test whether event queue is empty.

Definition at line 1081 of file worker.c.

References _backend_worker_const(), and drawlayer_rt_worker_t::ring_count.

Referenced by _rt_queue_pop_locked().

◆ _rt_queue_full()

static gboolean _rt_queue_full ( const dt_drawlayer_worker_t *  rt)
static

Test whether event queue is full.

Definition at line 1088 of file worker.c.

References _backend_worker_const(), drawlayer_rt_worker_t::ring_capacity, and drawlayer_rt_worker_t::ring_count.

Referenced by _enqueue_input(), and _rt_queue_push_locked().

◆ _rt_queue_pop_locked()

static gboolean _rt_queue_pop_locked ( dt_drawlayer_worker_t *  rt,
dt_drawlayer_paint_raw_input_t *  event 
)
static

◆ _rt_queue_push_locked()

static gboolean _rt_queue_push_locked ( dt_drawlayer_worker_t *  rt,
const dt_drawlayer_paint_raw_input_t *  event 
)
static

◆ _rt_set_worker_state()

static void _rt_set_worker_state ( dt_drawlayer_worker_t *  rt,
const dt_drawlayer_worker_state_t  state 
)
static

Set worker state atomically under caller synchronization.

Definition at line 1141 of file worker.c.

References _backend_worker(), IS_NULL_PTR, drawlayer_rt_worker_t::state, and state.

Referenced by _drawlayer_worker_main().

◆ _rt_workers_active()

static gboolean _rt_workers_active ( dt_drawlayer_worker_t *  rt)
static

Thread-safe wrapper for active-workers status.

Definition at line 1187 of file worker.c.

References _workers_active_locked(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, IS_NULL_PTR, and dt_drawlayer_worker_t::worker_mutex.

Referenced by dt_drawlayer_worker_active().

◆ _rt_workers_any_active()

static gboolean _rt_workers_any_active ( dt_drawlayer_worker_t *  rt)
static

Thread-safe wrapper for any worker activity.

Definition at line 1198 of file worker.c.

References _workers_any_active_locked(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, IS_NULL_PTR, and dt_drawlayer_worker_t::worker_mutex.

Referenced by dt_drawlayer_worker_any_active().

◆ _set_current_thread_realtime_best_effort()

static void _set_current_thread_realtime_best_effort ( void  )
static

Try elevating current thread scheduling policy for lower-latency input.

Definition at line 1148 of file worker.c.

References MIN, and param.

Referenced by _drawlayer_worker_main().

◆ _start_worker()

◆ _stop_worker()

◆ _stroke_begin()

◆ _stroke_clear()

◆ _stroke_create()

◆ _stroke_destroy()

static void _stroke_destroy ( dt_drawlayer_worker_t *  rt)
static

◆ _translate_batch_damage()

static gboolean _translate_batch_damage ( const dt_drawlayer_cache_patch_t *  patch,
const dt_drawlayer_damaged_rect_t *  local_damage,
dt_drawlayer_damaged_rect_t *  absolute_damage 
)
static

Translate scratch-local damage coordinates back into base-patch coordinates.

Definition at line 695 of file worker.c.

References FALSE, IS_NULL_PTR, dt_drawlayer_damaged_rect_t::nw, dt_drawlayer_damaged_rect_t::se, TRUE, dt_drawlayer_damaged_rect_t::valid, dt_drawlayer_cache_patch_t::x, and dt_drawlayer_cache_patch_t::y.

Referenced by _rasterize_pending_dab_batch().

◆ _worker_batch_min_size()

static guint _worker_batch_min_size ( void  )
static

Definition at line 529 of file worker.c.

References MAX, and omp_get_max_threads.

Referenced by _rasterize_pending_dab_batch().

◆ _worker_is_busy()

static gboolean _worker_is_busy ( const drawlayer_rt_worker_t *  worker)
inlinestatic

◆ _worker_is_started()

static gboolean _worker_is_started ( const drawlayer_rt_worker_t *  worker)
inlinestatic

◆ _worker_pause_requested()

static gboolean _worker_pause_requested ( const drawlayer_rt_worker_t *  worker)
inlinestatic

◆ _workers_active_locked()

static gboolean _workers_active_locked ( const dt_drawlayer_worker_t *  rt)
static

Check whether workers still have pending activity (lock must be held).

Definition at line 1162 of file worker.c.

References _backend_pending_dabs_locked(), _backend_worker_const(), _worker_is_busy(), dt_drawlayer_worker_t::finish_commit_pending, and drawlayer_rt_worker_t::ring_count.

Referenced by _rt_workers_active(), and _workers_any_active_locked().

◆ _workers_any_active_locked()

static gboolean _workers_any_active_locked ( const dt_drawlayer_worker_t *  rt)
static

Check whether any worker activity remains.

Definition at line 1171 of file worker.c.

References _workers_active_locked().

Referenced by _rt_workers_any_active().

◆ _workers_ready_for_commit_locked()

static gboolean _workers_ready_for_commit_locked ( const dt_drawlayer_worker_t *  rt)
static

◆ dt_drawlayer_build_worker_input_dab()

gboolean dt_drawlayer_build_worker_input_dab ( dt_iop_module_t *  self,
dt_drawlayer_paint_stroke_t *  state,
const dt_drawlayer_paint_raw_input_t *  input,
dt_drawlayer_brush_dab_t *  dab 
)

Definition at line 184 of file worker.c.

References _clamp01(), _mapping_profile_value(), dt_drawlayer_paint_raw_input_t::accel_profile, dt_drawlayer_paint_raw_input_t::acceleration, dt_drawlayer_paint_raw_input_t::brush_flow, dt_drawlayer_paint_raw_input_t::brush_hardness, dt_drawlayer_paint_raw_input_t::brush_mode, dt_drawlayer_paint_raw_input_t::brush_opacity, dt_drawlayer_paint_raw_input_t::brush_radius, dt_drawlayer_paint_raw_input_t::brush_shape, dt_drawlayer_paint_raw_input_t::brush_sprinkle_coarseness, dt_drawlayer_paint_raw_input_t::brush_sprinkle_size, dt_drawlayer_paint_raw_input_t::brush_sprinkles, dt_drawlayer_paint_raw_input_t::color, dt_drawlayer_paint_raw_input_t::display_color, DRAWLAYER_INPUT_MAP_ACCEL_FLOW, DRAWLAYER_INPUT_MAP_ACCEL_OPACITY, DRAWLAYER_INPUT_MAP_ACCEL_SIZE, DRAWLAYER_INPUT_MAP_ACCEL_SOFTNESS, DRAWLAYER_INPUT_MAP_PRESSURE_FLOW, DRAWLAYER_INPUT_MAP_PRESSURE_OPACITY, DRAWLAYER_INPUT_MAP_PRESSURE_SIZE, DRAWLAYER_INPUT_MAP_PRESSURE_SOFTNESS, DRAWLAYER_INPUT_MAP_TILT_FLOW, DRAWLAYER_INPUT_MAP_TILT_OPACITY, DRAWLAYER_INPUT_MAP_TILT_SIZE, DRAWLAYER_INPUT_MAP_TILT_SOFTNESS, DRAWLAYER_PROFILE_INV_QUADRATIC, DRAWLAYER_PROFILE_LINEAR, DT_DEBUG_INPUT, DT_DRAWLAYER_PAINT_STROKE_MIDDLE, dt_drawlayer_widget_to_layer_coords(), dt_print(), FALSE, dt_drawlayer_paint_raw_input_t::have_layer_coords, IS_NULL_PTR, dt_drawlayer_paint_raw_input_t::lx, dt_drawlayer_paint_raw_input_t::ly, dt_drawlayer_paint_raw_input_t::map_flags, dt_drawlayer_paint_raw_input_t::pressure, dt_drawlayer_paint_raw_input_t::pressure_profile, state, dt_drawlayer_paint_raw_input_t::stroke_batch, dt_drawlayer_paint_raw_input_t::stroke_pos, dt_drawlayer_paint_raw_input_t::tilt, dt_drawlayer_paint_raw_input_t::tilt_profile, TRUE, dt_drawlayer_paint_raw_input_t::wx, dt_drawlayer_paint_raw_input_t::wy, and dt_drawlayer_brush_dab_t::x.

Referenced by _paint_build_dab_cb().

◆ dt_drawlayer_worker_active()

gboolean dt_drawlayer_worker_active ( const dt_drawlayer_worker_t *  worker)

Public status query: TRUE when worker has pending activity.

Query whether realtime/backend worker still has pending activity.

Definition at line 1716 of file worker.c.

References _rt_workers_active().

Referenced by dt_drawlayer_begin_gui_stroke_capture().

◆ dt_drawlayer_worker_any_active()

gboolean dt_drawlayer_worker_any_active ( const dt_drawlayer_worker_t *  worker)

Public status query: TRUE when any worker still has pending activity.

Query whether any worker still has pending activity.

Definition at line 1722 of file worker.c.

References _rt_workers_any_active().

Referenced by _drawlayer_modal_wait_tick(), dt_drawlayer_flush_layer_cache(), and dt_drawlayer_wait_for_rasterization_modal().

◆ dt_drawlayer_worker_cancel_async_commit()

void dt_drawlayer_worker_cancel_async_commit ( dt_drawlayer_worker_t *  rt)

Cancel deferred commit request state if any.

Cancel the deferred commit request state, if any.

Definition at line 1560 of file worker.c.

References dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, dt_drawlayer_worker_t::finish_commit_pending, IS_NULL_PTR, and dt_drawlayer_worker_t::worker_mutex.

Referenced by _stop_worker(), and dt_drawlayer_commit_dabs().

◆ dt_drawlayer_worker_cleanup()

void dt_drawlayer_worker_cleanup ( dt_drawlayer_worker_t **  worker)

Public worker cleanup entry point.

Stop worker and release all resources.

Definition at line 1710 of file worker.c.

References _rt_cleanup_state().

Referenced by gui_cleanup().

◆ dt_drawlayer_worker_enqueue_input()

gboolean dt_drawlayer_worker_enqueue_input ( dt_drawlayer_worker_t *  worker,
const dt_drawlayer_paint_raw_input_t *  input 
)

Public FIFO enqueue for one raw input event.

Enqueue one raw input event (FIFO, no coalescing).

Definition at line 1817 of file worker.c.

References _enqueue_input(), and dt_drawlayer_worker_t::self.

Referenced by dt_drawlayer_runtime_manager_update().

◆ dt_drawlayer_worker_enqueue_stroke_end()

gboolean dt_drawlayer_worker_enqueue_stroke_end ( dt_drawlayer_worker_t *  worker,
const dt_drawlayer_paint_raw_input_t *  input 
)

Public FIFO enqueue for stroke-end event.

Enqueue stroke-end marker carrying final raw input sample.

Definition at line 1824 of file worker.c.

References _enqueue_stroke_end(), and dt_drawlayer_worker_t::self.

Referenced by dt_drawlayer_runtime_manager_update().

◆ dt_drawlayer_worker_ensure_running()

gboolean dt_drawlayer_worker_ensure_running ( dt_iop_module_t *  self,
dt_drawlayer_worker_t *  rt 
)

Ensure realtime/backend worker threads are started.

Definition at line 1727 of file worker.c.

References _start_worker().

Referenced by dt_drawlayer_runtime_manager_update().

◆ dt_drawlayer_worker_get_snapshot()

void dt_drawlayer_worker_get_snapshot ( const dt_drawlayer_worker_t *  worker,
dt_drawlayer_worker_snapshot_t *  snapshot 
)

◆ dt_drawlayer_worker_init()

void dt_drawlayer_worker_init ( dt_iop_module_t *  self,
dt_drawlayer_worker_t **  worker,
gboolean *  painting,
gboolean *  finish_commit_pending,
guint *  stroke_sample_count,
uint32_t *  current_stroke_batch 
)

Public worker initialization entry point.

Initialize worker and bind external state mirrors.

Definition at line 1702 of file worker.c.

References _rt_init_state().

Referenced by gui_init().

◆ dt_drawlayer_worker_pause()

◆ dt_drawlayer_worker_publish_backend_stroke_damage()

void dt_drawlayer_worker_publish_backend_stroke_damage ( dt_iop_module_t *  self)

Publish accumulated backend stroke damage into drawlayer process/runtime state.

Definition at line 389 of file worker.c.

References dt_drawlayer_paint_merge_runtime_stroke_damage(), dt_drawlayer_paint_runtime_note_dab_damage(), dt_iop_gui_data(), g, IS_NULL_PTR, and TRUE.

Referenced by dt_drawlayer_commit_dabs().

◆ dt_drawlayer_worker_raw_inputs()

GArray * dt_drawlayer_worker_raw_inputs ( dt_drawlayer_worker_t *  worker)

Read-only access to preserved raw input history.

Read-only access to preserved raw input queue for current stroke (valid only while worker is idle).

Definition at line 1811 of file worker.c.

References dt_drawlayer_worker_t::stroke_raw_inputs.

◆ dt_drawlayer_worker_request_commit()

void dt_drawlayer_worker_request_commit ( dt_drawlayer_worker_t *  worker)

◆ dt_drawlayer_worker_reset_backend_path()

void dt_drawlayer_worker_reset_backend_path ( dt_drawlayer_worker_t *  worker)

◆ dt_drawlayer_worker_reset_live_publish()

void dt_drawlayer_worker_reset_live_publish ( dt_drawlayer_worker_t *  worker)

◆ dt_drawlayer_worker_reset_stroke()

void dt_drawlayer_worker_reset_stroke ( dt_drawlayer_worker_t *  worker)

Clear preserved stroke runtime/history after commit completed.

Clear preserved stroke runtime/history after a completed commit.

Definition at line 1801 of file worker.c.

References _reset_live_publish(), _stroke_clear(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), IS_NULL_PTR, and dt_drawlayer_worker_t::worker_mutex.

Referenced by dt_drawlayer_commit_dabs().

◆ dt_drawlayer_worker_resume()

void dt_drawlayer_worker_resume ( dt_iop_module_t *  self,
dt_drawlayer_worker_t *  rt 
)

Resume worker processing and wake sleeping thread.

Resume worker processing and wake the sleeping thread.

Definition at line 1615 of file worker.c.

References _backend_worker(), _worker_is_started(), DT_DRAWLAYER_WORKER_STATE_IDLE, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), IS_NULL_PTR, drawlayer_rt_worker_t::state, void(), dt_drawlayer_worker_t::worker_cond, and dt_drawlayer_worker_t::worker_mutex.

Referenced by dt_drawlayer_sync_widget_cache().

◆ dt_drawlayer_worker_seal_for_commit()

void dt_drawlayer_worker_seal_for_commit ( dt_drawlayer_worker_t *  worker)

Seal current stroke for synchronous commit.

Definition at line 1779 of file worker.c.

References void().

Referenced by dt_drawlayer_commit_dabs().

◆ dt_drawlayer_worker_snapshot_params()

void dt_drawlayer_worker_snapshot_params ( dt_drawlayer_worker_t *  worker,
const dt_iop_drawlayer_params_t *  params 
)

Seed the worker's private params blob for the stroke about to start. GUI thread only.

Flush pending events and force commit transition.

dt_drawlayer_touch_stroke_commit_hash is an ACCUMULATOR — it chains from whatever the blob already holds and keeps the field non-zero so "never updated" stays distinguishable. So the private copy is seeded, never zeroed, or the heartbeat would restart the chain from the 5381 seed and the commit would observe a different invariant than the one drawlayer.c documents.

Definition at line 1770 of file worker.c.

References dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), IS_NULL_PTR, params, dt_drawlayer_worker_t::publish_params, and dt_drawlayer_worker_t::worker_mutex.

Referenced by dt_drawlayer_begin_gui_stroke_capture().

◆ dt_drawlayer_worker_stop()

void dt_drawlayer_worker_stop ( dt_iop_module_t *  self,
dt_drawlayer_worker_t *  rt 
)

Stop realtime and full-resolution worker threads.

Definition at line 1732 of file worker.c.

References _stop_worker().

Referenced by dt_drawlayer_runtime_manager_update(), and quiesce().

◆ dt_drawlayer_worker_wait_idle()

Variable Documentation

◆ _rt_callbacks

static const drawlayer_rt_callbacks_t _rt_callbacks
static
Initial value:
= {
.thread_name = "draw-back",
.process_sample = _backend_worker_process_sample,
.process_stroke_end = _backend_worker_process_stroke_end,
},
}
static void _backend_worker_on_idle(dt_iop_module_t *self, dt_drawlayer_worker_t *rt)
Backend-worker idle hook.
Definition worker.c:1250
static void _backend_worker_process_stroke_end(dt_iop_module_t *self, dt_drawlayer_worker_t *rt)
Handle backend stroke end: flush, reset, and request commit.
Definition worker.c:1326
@ DRAWLAYER_RT_WORKER_BACKEND
Definition worker.c:57
static void _backend_worker_process_sample(dt_iop_module_t *self, dt_drawlayer_worker_t *rt, const dt_drawlayer_paint_raw_input_t *input)
Process one backend raw input event.
Definition worker.c:1311

Definition at line 424 of file worker.c.

Referenced by _drawlayer_worker_main().