~ubuntu-branches/ubuntu/saucy/darktable/saucy

« back to all changes in this revision

Viewing changes to src/control/control.h

  • Committer: Bazaar Package Importer
  • Author(s): David Bremner
  • Date: 2011-04-14 23:42:12 UTC
  • Revision ID: james.westby@ubuntu.com-20110414234212-kuffcz5wiu18v6ra
Tags: upstream-0.8
ImportĀ upstreamĀ versionĀ 0.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of darktable,
 
3
    copyright (c) 2009--2010 johannes hanika.
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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/>.
 
17
*/
 
18
#ifndef DT_CONTROL_H
 
19
#define DT_CONTROL_H
 
20
 
 
21
#include <inttypes.h>
 
22
#ifdef _OPENMP
 
23
#  include <omp.h>
 
24
#endif
 
25
 
 
26
#include "common/dtpthread.h"
 
27
#include "control/settings.h"
 
28
#include <gtk/gtk.h>
 
29
#include "gui/background_jobs.h"
 
30
// #include "control/job.def"
 
31
 
 
32
#define DT_CONTROL_MAX_JOBS 30
 
33
#define DT_CONTROL_JOB_DEBUG
 
34
#define DT_CONTROL_DESCRIPTION_LEN 256
 
35
// reserved workers
 
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
 
43
 
 
44
// keycodes mapped to dvorak keyboard layout for easier usage
 
45
#if defined(__APPLE__) || defined(__MACH__)
 
46
#if 0
 
47
#define KEYCODE_a            8   // mac keycodes X11 :(
 
48
#define KEYCODE_o            9
 
49
#define KEYCODE_e           10
 
50
#define KEYCODE_z           0xff // TODO: should be z 
 
51
#define KEYCODE_apostrophe  20
 
52
#define KEYCODE_comma       21
 
53
#define KEYCODE_period      22
 
54
#define KEYCODE_1           26
 
55
#define KEYCODE_2           27
 
56
#define KEYCODE_3           28
 
57
#define KEYCODE_4           29
 
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
 
70
#else
 
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 :)
 
78
#define KEYCODE_1           18
 
79
#define KEYCODE_2           19
 
80
#define KEYCODE_3           20
 
81
#define KEYCODE_4           21
 
82
#define KEYCODE_Escape      53
 
83
#define KEYCODE_Caps        57
 
84
#define KEYCODE_F7        98
 
85
#define KEYCODE_F8        99
 
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
 
95
#endif
 
96
#else
 
97
#define KEYCODE_a           38
 
98
#define KEYCODE_o           39
 
99
#define KEYCODE_e           40
 
100
#define KEYCODE_z           52
 
101
#define KEYCODE_apostrophe  24
 
102
#define KEYCODE_comma       25
 
103
#define KEYCODE_period      26
 
104
#define KEYCODE_1           10
 
105
#define KEYCODE_2           11
 
106
#define KEYCODE_3           12
 
107
#define KEYCODE_4           13
 
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
 
121
#endif
 
122
 
 
123
typedef GdkCursorType dt_cursor_t;
 
124
 
 
125
// called from gui
 
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);
 
145
 
 
146
// called from core
 
147
void dt_control_add_history_item(int32_t num, const char *label);
 
148
void dt_control_clear_history_items(int32_t num);
 
149
 
 
150
// could be both
 
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);
 
155
 
 
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);
 
158
struct dt_control_t;
 
159
 
 
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);
 
164
 
 
165
int dt_control_is_key_accelerators_on(struct dt_control_t *s);
 
166
 
 
167
/**
 
168
 * smallest unit of work.
 
169
 */
 
170
struct dt_job_t;
 
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
 
179
{
 
180
  int32_t (*execute) (struct dt_job_t *job);
 
181
  int32_t result;
 
182
 
 
183
  dt_pthread_mutex_t state_mutex;
 
184
  dt_pthread_mutex_t wait_mutex;
 
185
 
 
186
  int32_t state;
 
187
  dt_job_state_change_callback state_changed_cb;
 
188
  void *user_data;
 
189
 
 
190
  int32_t param[32];
 
191
#ifdef DT_CONTROL_JOB_DEBUG
 
192
  char description[DT_CONTROL_DESCRIPTION_LEN];
 
193
#endif
 
194
}
 
195
dt_job_t;
 
196
 
 
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);
 
207
 
 
208
#define DT_CTL_LOG_SIZE 10
 
209
#define DT_CTL_LOG_MSG_SIZE 200
 
210
#define DT_CTL_LOG_TIMEOUT 20000
 
211
/**
 
212
 * this manages everything time-consuming.
 
213
 * distributes the jobs on all processors,
 
214
 * performs scheduling.
 
215
 */
 
216
typedef struct dt_control_t
 
217
{
 
218
  // gui related stuff
 
219
  double tabborder;
 
220
  int32_t width, height;
 
221
  float progress;
 
222
  pthread_t gui_thread;
 
223
  int button_down, button_down_which, button_type;
 
224
  double button_x, button_y;
 
225
  int history_start;
 
226
 
 
227
  // message log
 
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;
 
231
  int  log_busy;
 
232
  dt_pthread_mutex_t log_mutex;
 
233
 
 
234
  // gui settings
 
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;
 
239
 
 
240
  // xatom color profile:
 
241
  uint8_t *xprofile_data;
 
242
  int xprofile_size;
 
243
 
 
244
  // job management
 
245
  int32_t running;
 
246
  dt_pthread_mutex_t queue_mutex, cond_mutex, run_mutex;
 
247
  pthread_cond_t cond;
 
248
  int32_t num_threads;
 
249
  pthread_t *thread;
 
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];
 
257
}
 
258
dt_control_t;
 
259
 
 
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);
 
264
 
 
265
int dt_control_load_config(dt_control_t *c);
 
266
int dt_control_write_config(dt_control_t *c);
 
267
 
 
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);
 
273
 
 
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();
 
280
 
 
281
static inline int32_t dt_ctl_get_num_procs()
 
282
{
 
283
#ifdef _OPENMP
 
284
  return omp_get_num_procs();
 
285
#else
 
286
#ifdef _SC_NPROCESSORS_ONLN
 
287
  return sysconf (_SC_NPROCESSORS_ONLN);
 
288
#else
 
289
  return 1;
 
290
#endif
 
291
#endif
 
292
}
 
293
 
 
294
#endif