2
This file is part of darktable,
3
copyright (c) 2009--2010 johannes hanika.
5
darktable is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
10
darktable is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with darktable. If not, see <http://www.gnu.org/licenses/>.
26
#include "common/dtpthread.h"
27
#include "control/settings.h"
29
#include "gui/background_jobs.h"
30
// #include "control/job.def"
32
#define DT_CONTROL_MAX_JOBS 30
33
#define DT_CONTROL_JOB_DEBUG
34
#define DT_CONTROL_DESCRIPTION_LEN 256
36
#define DT_CTL_WORKER_RESERVED 6
37
#define DT_CTL_WORKER_1 0 // dev load raw
38
#define DT_CTL_WORKER_2 1 // dev zoom 1
39
#define DT_CTL_WORKER_3 2 // dev zoom fill
40
#define DT_CTL_WORKER_4 3 // dev zoom fit
41
#define DT_CTL_WORKER_5 4 // dev small prev
42
#define DT_CTL_WORKER_6 5 // dev prefetch
44
// keycodes mapped to dvorak keyboard layout for easier usage
45
#if defined(__APPLE__) || defined(__MACH__)
47
#define KEYCODE_a 8 // mac keycodes X11 :(
50
#define KEYCODE_z 0xff // TODO: should be z
51
#define KEYCODE_apostrophe 20
52
#define KEYCODE_comma 21
53
#define KEYCODE_period 22
58
#define KEYCODE_Escape 61
59
#define KEYCODE_Caps -1
60
#define KEYCODE_F7 107
61
#define KEYCODE_F8 108
62
#define KEYCODE_F11 111
63
#define KEYCODE_Up 134
64
#define KEYCODE_Down 133
65
#define KEYCODE_Left 78
66
#define KEYCODE_Right 74
67
#define KEYCODE_Tab 56
68
#define KEYCODE_Return 36
69
#define KEYCODE_BackSpace 22
71
#define KEYCODE_a 0 // mac keycodes carbon :)
72
#define KEYCODE_o 1 // s
73
#define KEYCODE_e 2 // d
74
#define KEYCODE_z 0xff // TODO: should be z
75
#define KEYCODE_apostrophe 12 // q
76
#define KEYCODE_comma 13 // w
77
#define KEYCODE_period 14 // e .. in qwerty :)
82
#define KEYCODE_Escape 53
83
#define KEYCODE_Caps 57
86
#define KEYCODE_F11 103
87
#define KEYCODE_Up 126
88
#define KEYCODE_Down 125
89
#define KEYCODE_Left 123
90
#define KEYCODE_Right 124
91
#define KEYCODE_Tab 48
92
#define KEYCODE_Space 49
93
#define KEYCODE_Return 36
94
#define KEYCODE_BackSpace 22
101
#define KEYCODE_apostrophe 24
102
#define KEYCODE_comma 25
103
#define KEYCODE_period 26
108
#define KEYCODE_Escape 9
109
#define KEYCODE_Caps 66
110
#define KEYCODE_F7 73
111
#define KEYCODE_F8 74
112
#define KEYCODE_F11 95
113
#define KEYCODE_Up 111
114
#define KEYCODE_Down 116
115
#define KEYCODE_Left 113
116
#define KEYCODE_Right 114
117
#define KEYCODE_Tab 23
118
#define KEYCODE_Space 65
119
#define KEYCODE_Return 36
120
#define KEYCODE_BackSpace 22
123
typedef GdkCursorType dt_cursor_t;
126
void *dt_control_expose(void *voidptr);
127
gboolean dt_control_expose_endmarker(GtkWidget *widget, GdkEventExpose *event, gpointer user_data);
128
void dt_control_button_pressed(double x, double y, int which, int type, uint32_t state);
129
void dt_control_button_released(double x, double y, int which, uint32_t state);
130
void dt_control_mouse_moved(double x, double y, int which);
131
void dt_control_mouse_leave();
132
void dt_control_mouse_enter();
133
int dt_control_key_pressed(uint16_t which);
134
int dt_control_key_released(uint16_t which);
135
int dt_control_key_pressed_override(uint16_t which);
136
gboolean dt_control_configure (GtkWidget *da, GdkEventConfigure *event, gpointer user_data);
137
void dt_control_gui_queue_draw();
138
void dt_control_log(const char* msg, ...);
139
void dt_control_log_busy_enter();
140
void dt_control_log_busy_leave();
141
void dt_control_change_cursor(dt_cursor_t cursor);
142
void dt_control_write_sidecar_files();
143
void dt_control_delete_images();
144
void dt_ctl_get_display_profile(GtkWidget *widget, guint8 **buffer, gint *buffer_size);
147
void dt_control_add_history_item(int32_t num, const char *label);
148
void dt_control_clear_history_items(int32_t num);
151
void dt_control_queue_draw_all();
152
void dt_control_queue_draw(GtkWidget *widget);
153
void dt_ctl_switch_mode();
154
void dt_ctl_switch_mode_to(dt_ctl_gui_mode_t mode);
156
void dt_control_save_gui_settings(dt_ctl_gui_mode_t mode);
157
void dt_control_restore_gui_settings(dt_ctl_gui_mode_t mode);
160
/** turn the use of key accelerators on */
161
void dt_control_key_accelerators_on(struct dt_control_t *s);
162
/** turn the use of key accelerators on */
163
void dt_control_key_accelerators_off(struct dt_control_t *s);
165
int dt_control_is_key_accelerators_on(struct dt_control_t *s);
168
* smallest unit of work.
171
typedef void (*dt_job_state_change_callback)(struct dt_job_t*,int state);
172
#define DT_JOB_STATE_INITIALIZED 0
173
#define DT_JOB_STATE_QUEUED 1
174
#define DT_JOB_STATE_RUNNING 2
175
#define DT_JOB_STATE_FINISHED 3
176
#define DT_JOB_STATE_CANCELLED 4
177
#define DT_JOB_STATE_DISCARDED 5
178
typedef struct dt_job_t
180
int32_t (*execute) (struct dt_job_t *job);
183
dt_pthread_mutex_t state_mutex;
184
dt_pthread_mutex_t wait_mutex;
187
dt_job_state_change_callback state_changed_cb;
191
#ifdef DT_CONTROL_JOB_DEBUG
192
char description[DT_CONTROL_DESCRIPTION_LEN];
197
/** intializes a job */
198
void dt_control_job_init(dt_job_t *j, const char *msg, ...);
199
/** setup a state callback for job. */
200
void dt_control_job_set_state_callback(dt_job_t *j,dt_job_state_change_callback cb,void *user_data);
201
void dt_control_job_print(dt_job_t *j);
202
/** cancel a job, running or in queue. */
203
void dt_control_job_cancel(dt_job_t *j);
204
int dt_control_job_get_state(dt_job_t *j);
205
/** wait for a job to finish execution. */
206
void dt_control_job_wait(dt_job_t *j);
208
#define DT_CTL_LOG_SIZE 10
209
#define DT_CTL_LOG_MSG_SIZE 200
210
#define DT_CTL_LOG_TIMEOUT 20000
212
* this manages everything time-consuming.
213
* distributes the jobs on all processors,
214
* performs scheduling.
216
typedef struct dt_control_t
220
int32_t width, height;
222
pthread_t gui_thread;
223
int button_down, button_down_which, button_type;
224
double button_x, button_y;
228
int log_pos, log_ack;
229
char log_message[DT_CTL_LOG_SIZE][DT_CTL_LOG_MSG_SIZE];
230
guint log_message_timeout_id;
232
dt_pthread_mutex_t log_mutex;
235
dt_ctl_settings_t global_settings, global_defaults;
236
dt_pthread_mutex_t global_mutex, image_mutex;
237
double last_expose_time;
238
int key_accelerators_on;
240
// xatom color profile:
241
uint8_t *xprofile_data;
246
dt_pthread_mutex_t queue_mutex, cond_mutex, run_mutex;
250
dt_job_t job[DT_CONTROL_MAX_JOBS];
251
int32_t idle[DT_CONTROL_MAX_JOBS];
252
int32_t queued[DT_CONTROL_MAX_JOBS];
253
int32_t idle_top, queued_top;
254
dt_job_t job_res[DT_CTL_WORKER_RESERVED];
255
uint8_t new_res[DT_CTL_WORKER_RESERVED];
256
pthread_t thread_res[DT_CTL_WORKER_RESERVED];
260
void dt_control_init(dt_control_t *s);
261
// join all worker threads.
262
void dt_control_shutdown(dt_control_t *s);
263
void dt_control_cleanup(dt_control_t *s);
265
int dt_control_load_config(dt_control_t *c);
266
int dt_control_write_config(dt_control_t *c);
268
int32_t dt_control_run_job(dt_control_t *s);
269
int32_t dt_control_add_job(dt_control_t *s, dt_job_t *job);
270
int32_t dt_control_revive_job(dt_control_t *s, dt_job_t *job);
271
int32_t dt_control_run_job_res(dt_control_t *s, int32_t res);
272
int32_t dt_control_add_job_res(dt_control_t *s, dt_job_t *job, int32_t res);
274
/** get threadsafe running state. */
275
int dt_control_running();
276
void *dt_control_work(void *ptr);
277
void *dt_control_work_res(void *ptr);
278
int32_t dt_control_get_threadid();
279
int32_t dt_control_get_threadid_res();
281
static inline int32_t dt_ctl_get_num_procs()
284
return omp_get_num_procs();
286
#ifdef _SC_NPROCESSORS_ONLN
287
return sysconf (_SC_NPROCESSORS_ONLN);