summaryrefslogtreecommitdiff
path: root/src/glitz.h
blob: 217c4908c69bd9dd9ea799f8f848938e808f7cda (plain)
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
/*
 * Copyright © 2004 David Reveman, Peter Nilsson
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without
 * fee, provided that the above copyright notice appear in all copies
 * and that both that copyright notice and this permission notice
 * appear in supporting documentation, and that the names of
 * David Reveman and Peter Nilsson not be used in advertising or
 * publicity pertaining to distribution of the software without
 * specific, written prior permission. David Reveman and Peter Nilsson
 * makes no representations about the suitability of this software for
 * any purpose. It is provided "as is" without express or implied warranty.
 *
 * DAVID REVEMAN AND PETER NILSSON DISCLAIMS ALL WARRANTIES WITH
 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DAVID REVEMAN AND
 * PETER NILSSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
 * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 *
 * Authors: David Reveman <c99drn@cs.umu.se>
 *          Peter Nilsson <c99pnn@cs.umu.se>
 */

#ifndef GLITZ_H_INCLUDED
#define GLITZ_H_INCLUDED

#if defined(__SVR4) && defined(__sun)
#  include <sys/int_types.h>
#else
#  if defined(__OpenBSD__)
#    include <inttypes.h>
#  else
#    include <stdint.h>
#  endif
#endif

/* NOTE: Must be manually synchronized with GLITZ_VERSION in configure.in */
#define GLITZ_MAJOR 0
#define GLITZ_MINOR 1
#define GLITZ_REVISION 5

#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif

typedef int glitz_bool_t;
typedef int glitz_fixed16_16_t;

typedef struct _glitz_point_fixed_t {
  glitz_fixed16_16_t x, y;
} glitz_point_fixed_t;

typedef struct _glitz_line_fixed_t {
  glitz_point_fixed_t p1, p2;
} glitz_line_fixed_t;

typedef struct _glitz_rectangle_t {
  short x, y;
  unsigned short width, height;
} glitz_rectangle_t;

typedef struct _glitz_triangle_t {
  glitz_point_fixed_t p1, p2, p3;
} glitz_triangle_t;

typedef struct _glitz_trapezoid_t {
  glitz_fixed16_16_t top, bottom;
  glitz_line_fixed_t left, right;
} glitz_trapezoid_t;

typedef struct _glitz_transform_t {
  glitz_fixed16_16_t matrix[3][3];
} glitz_transform_t;

typedef struct _glitz_convolution_t {
  glitz_fixed16_16_t matrix[3][3];
} glitz_convolution_t;

typedef struct {
  unsigned short red;
  unsigned short green;
  unsigned short blue;
  unsigned short alpha;
} glitz_color_t;
  
typedef struct _glitz_colorspan_t {
  glitz_fixed16_16_t left, right, y;
  glitz_color_t left_color;
  glitz_color_t right_color;
} glitz_colorspan_t;

typedef struct _glitz_colorpoint_t {
  glitz_point_fixed_t point;
  glitz_color_t color;
} glitz_colorpoint_t;

typedef struct _glitz_color_trapezoid_t {
  glitz_colorspan_t top, bottom;
} glitz_color_trapezoid_t;

typedef struct _glitz_color_triangle_t {
  glitz_colorpoint_t p1, p2, p3;
} glitz_color_triangle_t;

typedef enum {
  GLITZ_FILTER_FAST,
  GLITZ_FILTER_GOOD,
  GLITZ_FILTER_BEST,
  GLITZ_FILTER_NEAREST,
  GLITZ_FILTER_BILINEAR
} glitz_filter_t;

typedef enum {
  GLITZ_OPERATOR_CLEAR,
  GLITZ_OPERATOR_SRC,
  GLITZ_OPERATOR_DST,
  GLITZ_OPERATOR_OVER,
  GLITZ_OPERATOR_OVER_REVERSE,
  GLITZ_OPERATOR_IN,
  GLITZ_OPERATOR_IN_REVERSE,
  GLITZ_OPERATOR_OUT,
  GLITZ_OPERATOR_OUT_REVERSE,
  GLITZ_OPERATOR_ATOP,
  GLITZ_OPERATOR_ATOP_REVERSE,
  GLITZ_OPERATOR_XOR,
  GLITZ_OPERATOR_ADD,
  GLITZ_OPERATOR_SATURATE
} glitz_operator_t;

#define GLITZ_FEATURE_OFFSCREEN_DRAWING_MASK       (1L << 0)
#define GLITZ_FEATURE_CONVOLUTION_FILTER_MASK      (1L << 1)
#define GLITZ_FEATURE_TEXTURE_RECTANGLE_MASK       (1L << 2)
#define GLITZ_FEATURE_TEXTURE_NPOT_MASK            (1L << 3)
#define GLITZ_FEATURE_TEXTURE_MIRRORED_REPEAT_MASK (1L << 4)
#define GLITZ_FEATURE_MULTISAMPLE_MASK             (1L << 5)
#define GLITZ_FEATURE_OFFSCREEN_MULTISAMPLE_MASK   (1L << 6)
#define GLITZ_FEATURE_ARB_MULTITEXTURE_MASK        (1L << 7)
#define GLITZ_FEATURE_ARB_VERTEX_PROGRAM_MASK      (1L << 8)
#define GLITZ_FEATURE_ARB_FRAGMENT_PROGRAM_MASK    (1L << 9)

typedef enum {  
  GLITZ_STANDARD_ARGB32,
  GLITZ_STANDARD_RGB24,
  GLITZ_STANDARD_A8,
  GLITZ_STANDARD_A1
} glitz_format_name_t;
  
#define GLITZ_FORMAT_ID_MASK                  (1L <<  0)
#define GLITZ_FORMAT_RED_SIZE_MASK            (1L <<  6)
#define GLITZ_FORMAT_GREEN_SIZE_MASK          (1L <<  7)
#define GLITZ_FORMAT_BLUE_SIZE_MASK           (1L <<  8)
#define GLITZ_FORMAT_ALPHA_SIZE_MASK          (1L <<  9)
#define GLITZ_FORMAT_DEPTH_SIZE_MASK          (1L << 10)
#define GLITZ_FORMAT_STENCIL_SIZE_MASK        (1L << 11)
#define GLITZ_FORMAT_DOUBLEBUFFER_MASK        (1L << 12)
#define GLITZ_FORMAT_READ_ONSCREEN_MASK       (1L << 13)
#define GLITZ_FORMAT_READ_OFFSCREEN_MASK      (1L << 14)
#define GLITZ_FORMAT_DRAW_ONSCREEN_MASK       (1L << 15)
#define GLITZ_FORMAT_DRAW_OFFSCREEN_MASK      (1L << 16)
#define GLITZ_FORMAT_MULTISAMPLE_MASK         (1L << 17)
#define GLITZ_FORMAT_MULTISAMPLE_SAMPLES_MASK (1L << 18)

typedef unsigned long int glitz_format_id_t;

typedef struct _glitz_drawable_type_t {
  glitz_bool_t onscreen;
  glitz_bool_t offscreen;
} glitz_drawable_type_t;

typedef struct _glitz_multisample_format_t {
  glitz_bool_t supported;
  unsigned short samples;
} glitz_multisample_format_t;

typedef struct _glitz_format_t {
  glitz_format_id_t id;
  
  unsigned short red_size;
  unsigned short green_size;
  unsigned short blue_size;
  unsigned short alpha_size;
  unsigned short depth_size;
  unsigned short stencil_size;
  
  glitz_bool_t doublebuffer;
  glitz_drawable_type_t read;
  glitz_drawable_type_t draw;
  glitz_multisample_format_t multisample;
} glitz_format_t;

#define GLITZ_FORMAT_OPTION_DOUBLEBUFFER_MASK   (1L << 0)
#define GLITZ_FORMAT_OPTION_SINGLEBUFFER_MASK   (1L << 1)
#define GLITZ_FORMAT_OPTION_ONSCREEN_MASK       (1L << 2)
#define GLITZ_FORMAT_OPTION_OFFSCREEN_MASK      (1L << 3)
#define GLITZ_FORMAT_OPTION_MULTISAMPLE_MASK    (1L << 4)
#define GLITZ_FORMAT_OPTION_NO_MULTISAMPLE_MASK (1L << 5)
#define GLITZ_FORMAT_OPTION_READDRAW_MASK       (1L << 6)
#define GLITZ_FORMAT_OPTION_READONLY_MASK       (1L << 7)

/* glitz_status.c */
  
typedef enum {
    GLITZ_STATUS_SUCCESS = 0,
    GLITZ_STATUS_NO_MEMORY,
    GLITZ_STATUS_NULL_POINTER,
    GLITZ_STATUS_BAD_COORDINATE,
    GLITZ_STATUS_NOT_SUPPORTED,
    GLITZ_STATUS_INVALID_MATRIX
} glitz_status_t;

const char *
glitz_status_string (glitz_status_t status);

/* glitz_color_range.c */

typedef struct _glitz_color_range glitz_color_range_t;

typedef enum {
  GLITZ_EXTEND_PAD,
  GLITZ_EXTEND_REPEAT,
  GLITZ_EXTEND_REFLECT
} glitz_extend_t;
  
glitz_color_range_t *
glitz_color_range_create (unsigned int size);

void
glitz_color_range_destroy (glitz_color_range_t *color_range);

unsigned char *
glitz_color_range_get_data (glitz_color_range_t *color_range);

void
glitz_color_range_put_back_data (glitz_color_range_t *color_range);

void
glitz_color_range_set_filter (glitz_color_range_t *color_range,
                              glitz_filter_t filter);
  
void
glitz_color_range_set_extend (glitz_color_range_t *color_range,
                              glitz_extend_t extend);

  
/* glitz_surface.c */

typedef struct _glitz_surface glitz_surface_t;

typedef enum {
  GLITZ_POLYEDGE_SHARP,
  GLITZ_POLYEDGE_SMOOTH
} glitz_polyedge_t;

glitz_surface_t *
glitz_surface_create_solid (glitz_color_t *color);
  
glitz_surface_t *
glitz_surface_create_linear (glitz_point_fixed_t *start,
                             glitz_point_fixed_t *end,
                             glitz_color_range_t *color_range);

glitz_surface_t *
glitz_surface_create_radial (glitz_point_fixed_t *center,
                             glitz_fixed16_16_t radius0,
                             glitz_fixed16_16_t radius1,
                             glitz_color_range_t *color_range);
  
void
glitz_surface_destroy (glitz_surface_t *surface);

void
glitz_surface_set_transform (glitz_surface_t *surface,
                             glitz_transform_t *transform);

void
glitz_surface_set_convolution (glitz_surface_t *surface,
                               glitz_convolution_t *convolution);

void
glitz_surface_set_repeat (glitz_surface_t *surface,
                          glitz_bool_t repeat);

void
glitz_surface_set_filter (glitz_surface_t *surface,
                          glitz_filter_t filter);
  
void
glitz_surface_set_polyedge (glitz_surface_t *surface,
                            glitz_polyedge_t polyedge);

void
glitz_surface_set_polyopacity (glitz_surface_t *surface,
                               unsigned short polyopacity);

typedef enum {
  GLITZ_POLYEDGE_SMOOTH_HINT_FAST,
  GLITZ_POLYEDGE_SMOOTH_HINT_GOOD,
  GLITZ_POLYEDGE_SMOOTH_HINT_BEST
} glitz_polyedge_smooth_hint_t;

void
glitz_surface_set_polyedge_smooth_hint (glitz_surface_t *surface,
                                        glitz_polyedge_smooth_hint_t hint);

typedef enum {
  GLITZ_CLIP_OPERATOR_SET,
  GLITZ_CLIP_OPERATOR_UNION,
  GLITZ_CLIP_OPERATOR_INTERSECT
} glitz_clip_operator_t;
  
void
glitz_surface_clip_rectangles (glitz_surface_t *surface,
                               glitz_clip_operator_t op,
                               const glitz_rectangle_t *rects,
                               int n_rects);
  
void
glitz_surface_clip_trapezoids (glitz_surface_t *surface,
                               glitz_clip_operator_t op,
                               const glitz_trapezoid_t *traps,
                               int n_traps);

void
glitz_surface_clip_triangles (glitz_surface_t *surface,
                              glitz_clip_operator_t op,
                              const glitz_triangle_t *tris,
                              int n_tris);
  
int
glitz_surface_get_width (glitz_surface_t *surface);

int
glitz_surface_get_height (glitz_surface_t *surface);

void
glitz_surface_update_size (glitz_surface_t *surface);

typedef enum {
  GLITZ_BUFFER_FRONT,
  GLITZ_BUFFER_BACK
} glitz_buffer_t;

void
glitz_surface_set_read_buffer (glitz_surface_t *surface,
                               glitz_buffer_t buffer);

void
glitz_surface_set_draw_buffer (glitz_surface_t *surface,
                               glitz_buffer_t buffer);

void
glitz_surface_flush (glitz_surface_t *surface);
  
void
glitz_surface_swap_buffers (glitz_surface_t *surface);

void
glitz_surface_get_gl_texture (glitz_surface_t *surface,
                              unsigned int *name,
                              unsigned int *target,
                              double *texcoord_width,
                              double *texcoord_height,
                              glitz_bool_t *repeatable);  

void
glitz_surface_gl_begin (glitz_surface_t *surface);

void
glitz_surface_gl_end (glitz_surface_t *surface);

glitz_status_t
glitz_surface_get_status (glitz_surface_t *surface);

unsigned long
glitz_surface_get_features (glitz_surface_t *surface);

glitz_format_t *
glitz_surface_get_format (glitz_surface_t *surface);

glitz_format_t *
glitz_surface_find_similar_standard_format (glitz_surface_t *surface,
                                            unsigned long option_mask,
                                            glitz_format_name_t format_name);

glitz_format_t *
glitz_surface_find_similar_format (glitz_surface_t *surface,
                                   unsigned long mask,
                                   const glitz_format_t *templ,
                                   int count);

glitz_surface_t *
glitz_surface_create_similar (glitz_surface_t *templ,
                              glitz_format_t *format,
                              int width,
                              int height);

#define GLITZ_HINT_CLIPPING_MASK     (1L << 0)
#define GLITZ_HINT_OFFSCREEN_MASK    (1L << 1)
#define GLITZ_HINT_PROGRAMMATIC_MASK (1L << 2)
#define GLITZ_HINT_MULTISAMPLE_MASK  (1L << 3)

unsigned long
glitz_surface_get_hints (glitz_surface_t *surface);

  
/* glitz_pixel.c */
  
typedef enum {
  GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN,
  GLITZ_PIXEL_SCANLINE_ORDER_BOTTOM_UP
} glitz_pixel_scanline_order_t;

typedef struct _glitz_pixel_masks {
  int bpp;
  unsigned long alpha_mask;
  unsigned long red_mask;
  unsigned long green_mask;
  unsigned long blue_mask;
} glitz_pixel_masks_t;

typedef struct _glitz_pixel_format {
  glitz_pixel_masks_t masks;
  int xoffset;
  int bytes_per_line;
  glitz_pixel_scanline_order_t scanline_order;
} glitz_pixel_format_t;

void
glitz_put_pixels (glitz_surface_t *dst,
                  int x_dst,
                  int y_dst,
                  int width,
                  int height,
                  glitz_pixel_format_t *format,
                  char *pixels);

void
glitz_get_pixels (glitz_surface_t *src,
                  int x_src,
                  int y_src,
                  int width,
                  int height,
                  glitz_pixel_format_t *format,
                  char *pixels);

  
/* glitz_rect.c */

void
glitz_fill_rectangle (glitz_operator_t op,
                      glitz_surface_t *dst,
                      const glitz_color_t *color,
                      int x,
                      int y,
                      unsigned int width,
                      unsigned int height);
  
void
glitz_fill_rectangles (glitz_operator_t op,
                       glitz_surface_t *dst,
                       const glitz_color_t *color,
                       const glitz_rectangle_t *rects,
                       int n_rects);


/* glitz_trap.c */

void
glitz_fill_trapezoids (glitz_operator_t op,
                       glitz_surface_t *dst,
                       const glitz_color_t *color,
                       const glitz_trapezoid_t *traps,
                       int n_traps);

void
glitz_composite_trapezoids (glitz_operator_t op,
                            glitz_surface_t *src,
                            glitz_surface_t *dst,
                            int x_src,
                            int y_src,
                            const glitz_trapezoid_t *traps,
                            int n_traps);

void
glitz_color_trapezoids (glitz_operator_t op,
                        glitz_surface_t *dst,
                        const glitz_color_trapezoid_t *color_traps,
                        int n_color_traps);


/* glitz_tri.c */

void
glitz_fill_triangles (glitz_operator_t op,
                      glitz_surface_t *dst,
                      const glitz_color_t *color,
                      const glitz_triangle_t *tris,
                      int n_tris);
  
void
glitz_composite_triangles (glitz_operator_t op,
                           glitz_surface_t *src,
                           glitz_surface_t *dst,
                           int x_src,
                           int y_src,
                           const glitz_triangle_t *tris,
                           int n_tris);

void
glitz_composite_tri_strip (glitz_operator_t op,
                           glitz_surface_t *src,
                           glitz_surface_t *dst,
                           int x_src,
                           int y_src,
                           const glitz_point_fixed_t *points,
                           int n_points);

  void
glitz_composite_tri_fan (glitz_operator_t op,
                         glitz_surface_t *src,
                         glitz_surface_t *dst,
                         int x_src,
                         int y_src,
                         const glitz_point_fixed_t *points,
                         int n_points);
  
void
glitz_color_triangles (glitz_operator_t op,
                       glitz_surface_t *dst,
                       const glitz_color_triangle_t *color_tris,
                       int n_color_tris);
  

/* glitz.c */

void
glitz_composite (glitz_operator_t op,
                 glitz_surface_t *src,
                 glitz_surface_t *mask,
                 glitz_surface_t *dst,
                 int x_src,
                 int y_src,
                 int x_mask,
                 int y_mask,
                 int x_dst,
                 int y_dst,
                 int width,
                 int height);

void
glitz_copy_area (glitz_surface_t *src,
                 glitz_surface_t *dst,
                 int x_src,
                 int y_src,
                 int width,
                 int height,
                 int x_dst,
                 int y_dst);
  
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif

#endif /* GLITZ_H_INCLUDED */