File: mypaint-tiled-surface.h

package info (click to toggle)
libmypaint 1.6.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 5,904 kB
  • sloc: ansic: 5,953; sh: 4,418; makefile: 292; python: 210
file content (299 lines) | stat: -rw-r--r-- 9,811 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#ifndef MYPAINTTILEDSURFACE_H
#define MYPAINTTILEDSURFACE_H

#include <stdint.h>
#include "mypaint-surface.h"
#include "mypaint-symmetry.h"
#include "mypaint-config.h"

G_BEGIN_DECLS

typedef struct MyPaintTiledSurface MyPaintTiledSurface;
typedef struct MyPaintTiledSurface2 MyPaintTiledSurface2;

/*!
 * Tile request used by MyPaintTiledSurface and MyPaintTiledSurface2
 *
 * Request for tile data for a given tile coordinate (tx, ty), also acting
 * as the response by defining fields to be populated by the receiver of
 * the request.
 *
 */
typedef struct {
    /*! The x-coordinate of the requested tile */
    int tx;
    /*! The y-coordinate of the requested tile */
    int ty;
    /*! Whether the tile data should be considered read-only */
    gboolean readonly;
    /*! Pointer to the tile buffer, set by receiver of the request */
    guint16 *buffer;
    /*! Additional data to be used by surface implementations __(unused)__.*/
    gpointer context; /* Only to be used by the surface implementations. */
    /*! Identifier of the thread from which the request is made.*/
    int thread_id;
    /*! The mipmap level for which to fetch the tile __(unused)__.*/
    int mipmap_level;
} MyPaintTileRequest;

/*!
 * Initiatilze a tile request
 *
 * @memberof MyPaintTileRequest
 */
void
mypaint_tile_request_init(MyPaintTileRequest *data, int level,
                          int tx, int ty, gboolean readonly);

/*!
 * Function for beginning a tile request from the surface backend
 *
 * @memberof MyPaintTiledSurface
 * @sa MyPaintTileRequest, MyPaintTileRequestEndFunction
 */
typedef void (*MyPaintTileRequestStartFunction) (MyPaintTiledSurface *self, MyPaintTileRequest *request);

/*!
 * Function for ending a tile request from the surface backend
 *
 * @memberof MyPaintTiledSurface
 * @sa MyPaintTileRequest, MyPaintTileRequestStartFunction
 */
typedef void (*MyPaintTileRequestEndFunction) (MyPaintTiledSurface *self, MyPaintTileRequest *request);

/*!
 * Tile-backed implementation of MyPaintSurface
 *
 * Interface and convenience class for implementing a MyPaintSurface backed by
 * a tile store.
 *
 * The size of the surface is infinite, and consumers only need to provide
 * implementations for #tile_request_start and #tile_request_end
 *
 * @sa MyPaintTiledSurface2
 */
struct MyPaintTiledSurface {
    /*! Surface interface */
    MyPaintSurface parent;
    /* "private": */
    /*! See #MyPaintTileRequestStartFunction */
    MyPaintTileRequestStartFunction tile_request_start;
    /*! See #MyPaintTileRequestEndFunction */
    MyPaintTileRequestEndFunction tile_request_end;
    /*! Whether vertical-line symmetry is enabled or not */
    gboolean surface_do_symmetry;
    /*! The x-coordinate of the vertical symmetry line */
    float surface_center_x;
    /*! Per-tile queue of pending dab operations */
    struct OperationQueue *operation_queue;
    /*!
     * Invalidation rectangle recording areas changed between the calls to
     * #parent%'s MyPaintSurface::begin_atomic and MyPaintSurface::end_atomic
     */
    MyPaintRectangle dirty_bbox;
    /*! Whether tile requests shuold be considered thread-safe or not */
    gboolean threadsafe_tile_requests;
    /*! The side length of the (square) tiles */
    int tile_size;
};

/*!
 * Initialize the surface by providing the tile request implementations.
 *
 * Allocates the resources necessary for the surface to function.
 * @sa mypaint_tiled_surface_destroy
 *
 * @memberof MyPaintTiledSurface
 */
void
mypaint_tiled_surface_init(MyPaintTiledSurface *self,
                           MyPaintTileRequestStartFunction tile_request_start,
                           MyPaintTileRequestEndFunction tile_request_end);


/*!
 * Free the resources used by the surface, and the surface itself
 *
 * Frees up the resources allocated in mypaint_tiled_surface_init.
 * @sa mypaint_tiled_surface_init
 *
 * @memberof MyPaintTiledSurface
 */
void
mypaint_tiled_surface_destroy(MyPaintTiledSurface *self);


/*!
 * Set the symmetry state of the surface.
 *
 * When the symmetry is active, for each dab drawn with
 * ::mypaint_surface_draw_dab, reflected horizontally across the
 * vertical line defined by MyPaintTiledSurface.surface_center_x.
 *
 * @param active Whether symmetry should be used or not.
 * @param center_x The x-coordinate of the vertical line to reflect the dabs across
 *
 * @memberof MyPaintTiledSurface
 */
void
mypaint_tiled_surface_set_symmetry_state(MyPaintTiledSurface *self, gboolean active, float center_x);

/*!
 * Get the average alpha value of pixels covered by a standard dab.
 *
 * Equivalent to ::mypaint_surface_get_alpha
 * (this function should probably not have been made public).
 *
 * @memberof MyPaintTiledSurface
 */
float
mypaint_tiled_surface_get_alpha (MyPaintTiledSurface *self, float x, float y, float radius);

/*!
 * Fetch a tile out from the underlying tile store.
 *
 * When successful, request->data will be set to point to the fetched tile.
 * Consumers must *always* call mypaint_tiled_surface_tile_request_end with the same
 * request to complete the transaction.
 *
 * @memberof MyPaintTiledSurface
 */
void mypaint_tiled_surface_tile_request_start(MyPaintTiledSurface *self, MyPaintTileRequest *request);

/*!
 * Put a (potentially modified) tile back into the underlying tile store.
 *
 * Consumers must *always* call mypaint_tiled_surface_tile_request_start() with the same
 * request to start the transaction before calling this function.
 *
 * @memberof MyPaintTiledSurface
 */
void mypaint_tiled_surface_tile_request_end(MyPaintTiledSurface *self, MyPaintTileRequest *request);

/*!
 * Implementation of MyPaintSurface::begin_atomic
 * Note: Only intended to be used from MyPaintTiledSurface subclasses,
 * which should chain up to this if overriding MyPaintSurface::begin_atomic.
 * Application code should only use #mypaint_surface_begin_atomic
 *
 * @memberof MyPaintTiledSurface
 */
void mypaint_tiled_surface_begin_atomic(MyPaintTiledSurface *self);
void mypaint_tiled_surface_end_atomic(MyPaintTiledSurface *self, MyPaintRectangle *roi);


/* -- Extended interface -- */

/*! Functionally equivalent to #MyPaintTileRequestStartFunction
 * @memberof MyPaintTiledSurface2
 */
typedef void (*MyPaintTileRequestStartFunction2) (MyPaintTiledSurface2 *self, MyPaintTileRequest *request);
/*! Functionally equivalent to #MyPaintTileRequestEndFunction
 * @memberof MyPaintTiledSurface2
 */
typedef void (*MyPaintTileRequestEndFunction2) (MyPaintTiledSurface2 *self, MyPaintTileRequest *request);

/*!
  * Tile-backed implementation of MyPaintSurface2
  *
  * Apart from the additional calls of MyPaintSurface2, this implementation
  * supports additional symmetry types, and the ability to adjust the symmetry
  * angle - it is otherwise identical to MyPaintTiledSurface.
  *
  * @sa MyPaintTiledSurface
  */
struct MyPaintTiledSurface2 {
  /*! Parent interface */
  MyPaintSurface2 parent;
  /*! See #MyPaintTileRequestStartFunction2 */
  MyPaintTileRequestStartFunction2 tile_request_start;
  /*! See #MyPaintTileRequestEndFunction2 */
  MyPaintTileRequestEndFunction2 tile_request_end;
  /*! Per-tile queue of pending dab operations */
  struct OperationQueue *operation_queue;
  /*! Whether tile requests shuold be considered thread-safe or not */
  gboolean threadsafe_tile_requests;
  int tile_size;
  /*! The symmetry data used
   *
   * See MyPaintSymmetryData for details.
   */
  MyPaintSymmetryData symmetry_data;
  /*! Length of #bboxes */
  int num_bboxes;
  /*! The number of #bboxes that have been modified since they were last reset */
  int num_bboxes_dirtied;
  /*! Pointer to an array of invalidation rectangles
   *
   * Records multiple invalidation rectangles when symmetry is enabled.
   */
  MyPaintRectangle* bboxes;
};

/*!
 * Initialize the surface by providing the tile request implementations.
 *
 * Allocates the resources necessary for the surface to function.
 * @sa mypaint_tiled_surface2_destroy
 *
 * @memberof MyPaintTiledSurface2
 */
void
mypaint_tiled_surface2_init(
  MyPaintTiledSurface2 *self,
  MyPaintTileRequestStartFunction2 tile_request_start,
  MyPaintTileRequestEndFunction2 tile_request_end
  );

/*!
 * Prepare the surface for handling a set of dab operations.
 *
 * @memberof MyPaintTiledSurface2
 */
void mypaint_tiled_surface2_begin_atomic(MyPaintTiledSurface2 *self);

/*!
 * Finalize any pending dab operations and set the resulting invalidation rectangles.
 *
 * @memberof MyPaintTiledSurface2
 */
void mypaint_tiled_surface2_end_atomic(MyPaintTiledSurface2 *self, MyPaintRectangles *roi);

/*!
 * Finalize any pending dab operations and set the resulting invalidation rectangles.
 *
 * @memberof MyPaintTiledSurface2
 */
void mypaint_tiled_surface2_tile_request_start(MyPaintTiledSurface2 *self, MyPaintTileRequest *request);

/*!
 * Finalize any pending dab operations and set the resulting invalidation rectangles.
 *
 * @memberof MyPaintTiledSurface2
 */
void mypaint_tiled_surface2_tile_request_end(MyPaintTiledSurface2 *self, MyPaintTileRequest *request);

/*!
 * Deallocate all resources used by the surface struct, and the struct itself.
 *
 * @memberof MyPaintTiledSurface2
 */
void
mypaint_tiled_surface2_destroy(MyPaintTiledSurface2 *self);

/*!
 * Set new #symmetry_data values and mark it for update
 *
 * @memberof MyPaintTiledSurface2
 * @sa MyPaintSymmetryData, MyPaintSymmetryState
 */
void
mypaint_tiled_surface2_set_symmetry_state(MyPaintTiledSurface2 *self, gboolean active,
                                         float center_x, float center_y,
                                         float symmetry_angle,
                                         MyPaintSymmetryType symmetry_type,
                                         int rot_symmetry_lines);

G_END_DECLS

#endif // MYPAINTTILEDSURFACE_H