~ubuntu-branches/ubuntu/karmic/moon/karmic

« back to all changes in this revision

Viewing changes to pixman/pixman/pixman-private.h

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-14 12:01:08 UTC
  • Revision ID: james.westby@ubuntu.com-20090214120108-06539vb25vhbd8bn
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef PACKAGE
 
2
#  error config.h must be included before pixman-private.h
 
3
#endif
 
4
 
 
5
#ifndef PIXMAN_PRIVATE_H
 
6
#define PIXMAN_PRIVATE_H
 
7
 
 
8
#include "pixman.h"
 
9
#include <time.h>
 
10
 
 
11
#ifndef FALSE
 
12
#define FALSE 0
 
13
#endif
 
14
 
 
15
#ifndef TRUE
 
16
#define TRUE 1
 
17
#endif
 
18
 
 
19
#define MSBFirst 0
 
20
#define LSBFirst 1
 
21
 
 
22
#ifdef WORDS_BIGENDIAN
 
23
#  define IMAGE_BYTE_ORDER MSBFirst
 
24
#  define BITMAP_BIT_ORDER MSBFirst
 
25
#else
 
26
#  define IMAGE_BYTE_ORDER LSBFirst
 
27
#  define BITMAP_BIT_ORDER LSBFirst
 
28
#endif
 
29
 
 
30
#undef DEBUG
 
31
#define DEBUG 0
 
32
 
 
33
#if defined (__GNUC__)
 
34
#  define FUNC     ((const char*) (__PRETTY_FUNCTION__))
 
35
#elif defined (__sun) || (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
 
36
#  define FUNC     ((const char*) (__func__))
 
37
#else
 
38
#  define FUNC     ((const char*) ("???"))
 
39
#endif
 
40
 
 
41
#ifndef INT16_MIN
 
42
# define INT16_MIN              (-32767-1)
 
43
#endif
 
44
 
 
45
#ifndef INT16_MAX
 
46
# define INT16_MAX              (32767)
 
47
#endif
 
48
 
 
49
#ifndef INT32_MIN
 
50
# define INT32_MIN              (-2147483647-1)
 
51
#endif
 
52
 
 
53
#ifndef INT32_MAX
 
54
# define INT32_MAX              (2147483647)
 
55
#endif
 
56
 
 
57
#ifndef UINT32_MIN
 
58
# define UINT32_MIN             (0)
 
59
#endif
 
60
 
 
61
#ifndef UINT32_MAX
 
62
# define UINT32_MAX             (4294967295U)
 
63
#endif
 
64
 
 
65
#ifndef M_PI
 
66
# define M_PI                   3.14159265358979323846
 
67
#endif
 
68
 
 
69
#ifdef _MSC_VER
 
70
#define inline __inline
 
71
#endif
 
72
 
 
73
#define FB_SHIFT    5
 
74
#define FB_UNIT     (1 << FB_SHIFT)
 
75
#define FB_HALFUNIT (1 << (FB_SHIFT-1))
 
76
#define FB_MASK     (FB_UNIT - 1)
 
77
#define FB_ALLONES  ((uint32_t) -1)
 
78
 
 
79
/* Memory allocation helpers */
 
80
void *pixman_malloc_ab (unsigned int n, unsigned int b);
 
81
void *pixman_malloc_abc (unsigned int a, unsigned int b, unsigned int c);
 
82
pixman_bool_t pixman_multiply_overflows_int (unsigned int a, unsigned int b);
 
83
pixman_bool_t pixman_addition_overflows_int (unsigned int a, unsigned int b);
 
84
 
 
85
#if DEBUG
 
86
 
 
87
#define return_if_fail(expr)                                            \
 
88
    do                                                                  \
 
89
    {                                                                   \
 
90
        if (!(expr))                                                    \
 
91
        {                                                               \
 
92
            fprintf(stderr, "In %s: %s failed\n", FUNC, #expr);         \
 
93
            return;                                                     \
 
94
        }                                                               \
 
95
    }                                                                   \
 
96
    while (0)
 
97
 
 
98
#define return_val_if_fail(expr, retval)                                \
 
99
    do                                                                  \
 
100
    {                                                                   \
 
101
        if (!(expr))                                                    \
 
102
        {                                                               \
 
103
            fprintf(stderr, "In %s: %s failed\n", FUNC, #expr);         \
 
104
            return (retval);                                            \
 
105
        }                                                               \
 
106
    }                                                                   \
 
107
    while (0)
 
108
 
 
109
#else
 
110
 
 
111
#define return_if_fail(expr)                                            \
 
112
    do                                                                  \
 
113
    {                                                                   \
 
114
        if (!(expr))                                                    \
 
115
            return;                                                     \
 
116
    }                                                                   \
 
117
    while (0)
 
118
 
 
119
#define return_val_if_fail(expr, retval)                                \
 
120
    do                                                                  \
 
121
    {                                                                   \
 
122
        if (!(expr))                                                    \
 
123
            return (retval);                                            \
 
124
    }                                                                   \
 
125
    while (0)
 
126
 
 
127
#endif
 
128
 
 
129
typedef struct image_common image_common_t;
 
130
typedef struct source_image source_image_t;
 
131
typedef struct solid_fill solid_fill_t;
 
132
typedef struct gradient gradient_t;
 
133
typedef struct linear_gradient linear_gradient_t;
 
134
typedef struct horizontal_gradient horizontal_gradient_t;
 
135
typedef struct vertical_gradient vertical_gradient_t;
 
136
typedef struct conical_gradient conical_gradient_t;
 
137
typedef struct radial_gradient radial_gradient_t;
 
138
typedef struct bits_image bits_image_t;
 
139
typedef struct circle circle_t;
 
140
typedef struct point point_t;
 
141
 
 
142
/* FIXME - the types and structures below should be give proper names
 
143
 */
 
144
 
 
145
#define FASTCALL
 
146
typedef FASTCALL void (*CombineMaskU32) (uint32_t *src, const uint32_t *mask, int width);
 
147
typedef FASTCALL void (*CombineFuncU32) (uint32_t *dest, const uint32_t *src, int width);
 
148
typedef FASTCALL void (*CombineFuncC32) (uint32_t *dest, uint32_t *src, uint32_t *mask, int width);
 
149
typedef FASTCALL void (*fetchProc32)(bits_image_t *pict, int x, int y, int width,
 
150
                                     uint32_t *buffer);
 
151
typedef FASTCALL uint32_t (*fetchPixelProc32)(bits_image_t *pict, int offset, int line);
 
152
typedef FASTCALL void (*storeProc32)(pixman_image_t *, uint32_t *bits,
 
153
                                     const uint32_t *values, int x, int width,
 
154
                                     const pixman_indexed_t *);
 
155
 
 
156
typedef FASTCALL void (*CombineMaskU64) (uint64_t *src, const uint64_t *mask, int width);
 
157
typedef FASTCALL void (*CombineFuncU64) (uint64_t *dest, const uint64_t *src, int width);
 
158
typedef FASTCALL void (*CombineFuncC64) (uint64_t *dest, uint64_t *src, uint64_t *mask, int width);
 
159
typedef FASTCALL void (*fetchProc64)(bits_image_t *pict, int x, int y, int width,
 
160
                                     uint64_t *buffer);
 
161
typedef FASTCALL uint64_t (*fetchPixelProc64)(bits_image_t *pict, int offset, int line);
 
162
typedef FASTCALL void (*storeProc64)(pixman_image_t *, uint32_t *bits,
 
163
                                     const uint64_t *values, int x, int width,
 
164
                                     const pixman_indexed_t *);
 
165
 
 
166
typedef struct _FbComposeData {
 
167
    uint8_t      op;
 
168
    pixman_image_t      *src;
 
169
    pixman_image_t      *mask;
 
170
    pixman_image_t      *dest;
 
171
    int16_t      xSrc;
 
172
    int16_t      ySrc;
 
173
    int16_t      xMask;
 
174
    int16_t      yMask;
 
175
    int16_t      xDest;
 
176
    int16_t      yDest;
 
177
    uint16_t     width;
 
178
    uint16_t     height;
 
179
} FbComposeData;
 
180
 
 
181
typedef struct _FbComposeFunctions32 {
 
182
    CombineFuncU32 *combineU;
 
183
    CombineFuncC32 *combineC;
 
184
    CombineMaskU32 combineMaskU;
 
185
} FbComposeFunctions32;
 
186
 
 
187
typedef struct _FbComposeFunctions64 {
 
188
    CombineFuncU64 *combineU;
 
189
    CombineFuncC64 *combineC;
 
190
    CombineMaskU64 combineMaskU;
 
191
} FbComposeFunctions64;
 
192
 
 
193
extern FbComposeFunctions32 pixman_composeFunctions;
 
194
extern FbComposeFunctions64 pixman_composeFunctions64;
 
195
 
 
196
void pixman_composite_rect_general_accessors (const FbComposeData *data,
 
197
                                              void *src_buffer,
 
198
                                              void *mask_buffer,
 
199
                                              void *dest_buffer,
 
200
                                              const int wide);
 
201
void pixman_composite_rect_general (const FbComposeData *data);
 
202
 
 
203
fetchProc32 pixman_fetchProcForPicture32 (bits_image_t *);
 
204
fetchPixelProc32 pixman_fetchPixelProcForPicture32 (bits_image_t *);
 
205
storeProc32 pixman_storeProcForPicture32 (bits_image_t *);
 
206
fetchProc32 pixman_fetchProcForPicture32_accessors (bits_image_t *);
 
207
fetchPixelProc32 pixman_fetchPixelProcForPicture32_accessors (bits_image_t *);
 
208
storeProc32 pixman_storeProcForPicture32_accessors (bits_image_t *);
 
209
 
 
210
fetchProc64 pixman_fetchProcForPicture64 (bits_image_t *);
 
211
fetchPixelProc64 pixman_fetchPixelProcForPicture64 (bits_image_t *);
 
212
storeProc64 pixman_storeProcForPicture64 (bits_image_t *);
 
213
fetchProc64 pixman_fetchProcForPicture64_accessors (bits_image_t *);
 
214
fetchPixelProc64 pixman_fetchPixelProcForPicture64_accessors (bits_image_t *);
 
215
storeProc64 pixman_storeProcForPicture64_accessors (bits_image_t *);
 
216
 
 
217
void pixman_expand(uint64_t *dst, const uint32_t *src, pixman_format_code_t, int width);
 
218
void pixman_contract(uint32_t *dst, const uint64_t *src, int width);
 
219
 
 
220
void pixmanFetchSourcePict(source_image_t *, int x, int y, int width,
 
221
                           uint32_t *buffer, uint32_t *mask, uint32_t maskBits);
 
222
void pixmanFetchSourcePict64(source_image_t *, int x, int y, int width,
 
223
                             uint64_t *buffer, uint64_t *mask, uint32_t maskBits);
 
224
 
 
225
void fbFetchTransformed(bits_image_t *, int x, int y, int width,
 
226
                        uint32_t *buffer, uint32_t *mask, uint32_t maskBits);
 
227
void fbStoreExternalAlpha(bits_image_t *, int x, int y, int width,
 
228
                          uint32_t *buffer);
 
229
void fbFetchExternalAlpha(bits_image_t *, int x, int y, int width,
 
230
                          uint32_t *buffer, uint32_t *mask, uint32_t maskBits);
 
231
 
 
232
void fbFetchTransformed_accessors(bits_image_t *, int x, int y, int width,
 
233
                                  uint32_t *buffer, uint32_t *mask,
 
234
                                  uint32_t maskBits);
 
235
void fbStoreExternalAlpha_accessors(bits_image_t *, int x, int y, int width,
 
236
                                    uint32_t *buffer);
 
237
void fbFetchExternalAlpha_accessors(bits_image_t *, int x, int y, int width,
 
238
                                    uint32_t *buffer, uint32_t *mask,
 
239
                                    uint32_t maskBits);
 
240
 
 
241
void fbFetchTransformed64(bits_image_t *, int x, int y, int width,
 
242
                          uint64_t *buffer, uint64_t *mask, uint32_t maskBits);
 
243
void fbStoreExternalAlpha64(bits_image_t *, int x, int y, int width,
 
244
                            uint64_t *buffer);
 
245
void fbFetchExternalAlpha64(bits_image_t *, int x, int y, int width,
 
246
                            uint64_t *buffer, uint64_t *mask, uint32_t maskBits);
 
247
 
 
248
void fbFetchTransformed64_accessors(bits_image_t *, int x, int y, int width,
 
249
                                    uint64_t *buffer, uint64_t *mask,
 
250
                                    uint32_t maskBits);
 
251
void fbStoreExternalAlpha64_accessors(bits_image_t *, int x, int y, int width,
 
252
                                      uint64_t *buffer);
 
253
void fbFetchExternalAlpha64_accessors(bits_image_t *, int x, int y, int width,
 
254
                                      uint64_t *buffer, uint64_t *mask,
 
255
                                      uint32_t maskBits);
 
256
 
 
257
/* end */
 
258
 
 
259
typedef enum
 
260
{
 
261
    BITS,
 
262
    LINEAR,
 
263
    CONICAL,
 
264
    RADIAL,
 
265
    SOLID
 
266
} image_type_t;
 
267
 
 
268
#define IS_SOURCE_IMAGE(img)     (((image_common_t *)img)->type > BITS)
 
269
 
 
270
typedef enum
 
271
{
 
272
    SOURCE_IMAGE_CLASS_UNKNOWN,
 
273
    SOURCE_IMAGE_CLASS_HORIZONTAL,
 
274
    SOURCE_IMAGE_CLASS_VERTICAL
 
275
} source_pict_class_t;
 
276
 
 
277
struct point
 
278
{
 
279
    int16_t x, y;
 
280
};
 
281
 
 
282
struct image_common
 
283
{
 
284
    image_type_t                type;
 
285
    int32_t                     ref_count;
 
286
    pixman_region32_t           full_region;
 
287
    pixman_region32_t           clip_region;
 
288
    pixman_region32_t          *src_clip;
 
289
    pixman_bool_t               has_client_clip;
 
290
    pixman_transform_t         *transform;
 
291
    pixman_repeat_t             repeat;
 
292
    pixman_filter_t             filter;
 
293
    pixman_fixed_t             *filter_params;
 
294
    int                         n_filter_params;
 
295
    bits_image_t               *alpha_map;
 
296
    point_t                     alpha_origin;
 
297
    pixman_bool_t               component_alpha;
 
298
    pixman_read_memory_func_t   read_func;
 
299
    pixman_write_memory_func_t  write_func;
 
300
};
 
301
 
 
302
struct source_image
 
303
{
 
304
    image_common_t      common;
 
305
    source_pict_class_t class;
 
306
};
 
307
 
 
308
struct solid_fill
 
309
{
 
310
    source_image_t      common;
 
311
    uint32_t            color;          /* FIXME: shouldn't this be a pixman_color_t? */
 
312
};
 
313
 
 
314
struct gradient
 
315
{
 
316
    source_image_t              common;
 
317
    int                         n_stops;
 
318
    pixman_gradient_stop_t *    stops;
 
319
    int                         stop_range;
 
320
    uint32_t *                  color_table;
 
321
    int                         color_table_size;
 
322
};
 
323
 
 
324
struct linear_gradient
 
325
{
 
326
    gradient_t                  common;
 
327
    pixman_point_fixed_t        p1;
 
328
    pixman_point_fixed_t        p2;
 
329
};
 
330
 
 
331
struct circle
 
332
{
 
333
    pixman_fixed_t x;
 
334
    pixman_fixed_t y;
 
335
    pixman_fixed_t radius;
 
336
};
 
337
 
 
338
struct radial_gradient
 
339
{
 
340
    gradient_t  common;
 
341
 
 
342
    circle_t    c1;
 
343
    circle_t    c2;
 
344
    double      cdx;
 
345
    double      cdy;
 
346
    double      dr;
 
347
    double      A;
 
348
};
 
349
 
 
350
struct conical_gradient
 
351
{
 
352
    gradient_t                  common;
 
353
    pixman_point_fixed_t        center;
 
354
    pixman_fixed_t              angle;
 
355
};
 
356
 
 
357
struct bits_image
 
358
{
 
359
    image_common_t              common;
 
360
    pixman_format_code_t        format;
 
361
    const pixman_indexed_t     *indexed;
 
362
    int                         width;
 
363
    int                         height;
 
364
    uint32_t *                  bits;
 
365
    uint32_t *                  free_me;
 
366
    int                         rowstride; /* in number of uint32_t's */
 
367
};
 
368
 
 
369
union pixman_image
 
370
{
 
371
    image_type_t                type;
 
372
    image_common_t              common;
 
373
    bits_image_t                bits;
 
374
    gradient_t                  gradient;
 
375
    linear_gradient_t           linear;
 
376
    conical_gradient_t          conical;
 
377
    radial_gradient_t           radial;
 
378
    solid_fill_t                solid;
 
379
};
 
380
 
 
381
 
 
382
#define LOG2_BITMAP_PAD 5
 
383
#define FB_STIP_SHIFT   LOG2_BITMAP_PAD
 
384
#define FB_STIP_UNIT    (1 << FB_STIP_SHIFT)
 
385
#define FB_STIP_MASK    (FB_STIP_UNIT - 1)
 
386
#define FB_STIP_ALLONES ((uint32_t) -1)
 
387
 
 
388
#if BITMAP_BIT_ORDER == LSBFirst
 
389
#define FbScrLeft(x,n)  ((x) >> (n))
 
390
#define FbScrRight(x,n) ((x) << (n))
 
391
#define FbLeftStipBits(x,n) ((x) & ((((uint32_t) 1) << (n)) - 1))
 
392
#else
 
393
#define FbScrLeft(x,n)  ((x) << (n))
 
394
#define FbScrRight(x,n) ((x) >> (n))
 
395
#define FbLeftStipBits(x,n) ((x) >> (FB_STIP_UNIT - (n)))
 
396
#endif
 
397
 
 
398
#define FbStipLeft(x,n) FbScrLeft(x,n)
 
399
#define FbStipRight(x,n) FbScrRight(x,n)
 
400
#define FbStipMask(x,w) (FbStipRight(FB_STIP_ALLONES,(x) & FB_STIP_MASK) & \
 
401
                         FbStipLeft(FB_STIP_ALLONES,(FB_STIP_UNIT - ((x)+(w))) & FB_STIP_MASK))
 
402
 
 
403
#define FbLeftMask(x)       ( ((x) & FB_MASK) ? \
 
404
                              FbScrRight(FB_ALLONES,(x) & FB_MASK) : 0)
 
405
#define FbRightMask(x)      ( ((FB_UNIT - (x)) & FB_MASK) ? \
 
406
                              FbScrLeft(FB_ALLONES,(FB_UNIT - (x)) & FB_MASK) : 0)
 
407
 
 
408
#define FbMaskBits(x,w,l,n,r) {                                         \
 
409
        n = (w); \
 
410
        r = FbRightMask((x)+n); \
 
411
        l = FbLeftMask(x); \
 
412
        if (l) { \
 
413
            n -= FB_UNIT - ((x) & FB_MASK); \
 
414
            if (n < 0) { \
 
415
                n = 0; \
 
416
                l &= r; \
 
417
                r = 0; \
 
418
            } \
 
419
        } \
 
420
        n >>= FB_SHIFT; \
 
421
    }
 
422
 
 
423
#if IMAGE_BYTE_ORDER == MSBFirst
 
424
#define Fetch24(img, a)  ((unsigned long) (a) & 1 ?           \
 
425
    ((READ(img, a) << 16) | READ(img, (uint16_t *) ((a)+1))) : \
 
426
    ((READ(img, (uint16_t *) (a)) << 8) | READ(img, (a)+2)))
 
427
#define Store24(img,a,v) ((unsigned long) (a) & 1 ? \
 
428
    (WRITE(img, a, (uint8_t) ((v) >> 16)),                \
 
429
     WRITE(img, (uint16_t *) ((a)+1), (uint16_t) (v))) :  \
 
430
    (WRITE(img, (uint16_t *) (a), (uint16_t) ((v) >> 8)), \
 
431
     WRITE(img, (a)+2, (uint8_t) (v))))
 
432
#else
 
433
#define Fetch24(img,a)  ((unsigned long) (a) & 1 ?                           \
 
434
    (READ(img, a) | (READ(img, (uint16_t *) ((a)+1)) << 8)) : \
 
435
    (READ(img, (uint16_t *) (a)) | (READ(img, (a)+2) << 16)))
 
436
#define Store24(img,a,v) ((unsigned long) (a) & 1 ? \
 
437
    (WRITE(img, a, (uint8_t) (v)),                              \
 
438
     WRITE(img, (uint16_t *) ((a)+1), (uint16_t) ((v) >> 8))) : \
 
439
    (WRITE(img, (uint16_t *) (a), (uint16_t) (v)),              \
 
440
     WRITE(img, (a)+2, (uint8_t) ((v) >> 16))))
 
441
#endif
 
442
 
 
443
#define CvtR8G8B8toY15(s)       (((((s) >> 16) & 0xff) * 153 + \
 
444
                                  (((s) >>  8) & 0xff) * 301 +          \
 
445
                                  (((s)      ) & 0xff) * 58) >> 2)
 
446
#define miCvtR8G8B8to15(s) ((((s) >> 3) & 0x001f) |  \
 
447
                            (((s) >> 6) & 0x03e0) |  \
 
448
                            (((s) >> 9) & 0x7c00))
 
449
#define miIndexToEnt15(mif,rgb15) ((mif)->ent[rgb15])
 
450
#define miIndexToEnt24(mif,rgb24) miIndexToEnt15(mif,miCvtR8G8B8to15(rgb24))
 
451
 
 
452
#define miIndexToEntY24(mif,rgb24) ((mif)->ent[CvtR8G8B8toY15(rgb24)])
 
453
 
 
454
 
 
455
#define FbIntMult(a,b,t) ( (t) = (a) * (b) + 0x80, ( ( ( (t)>>8 ) + (t) )>>8 ) )
 
456
#define FbIntDiv(a,b)    (((uint16_t) (a) * 255) / (b))
 
457
 
 
458
#define FbGet8(v,i)   ((uint16_t) (uint8_t) ((v) >> i))
 
459
 
 
460
 
 
461
#define cvt8888to0565(s)    ((((s) >> 3) & 0x001f) | \
 
462
                             (((s) >> 5) & 0x07e0) | \
 
463
                             (((s) >> 8) & 0xf800))
 
464
#define cvt0565to0888(s)    (((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7)) | \
 
465
                             ((((s) << 5) & 0xfc00) | (((s) >> 1) & 0x300)) | \
 
466
                             ((((s) << 8) & 0xf80000) | (((s) << 3) & 0x70000)))
 
467
 
 
468
/*
 
469
 * There are two ways of handling alpha -- either as a single unified value or
 
470
 * a separate value for each component, hence each macro must have two
 
471
 * versions.  The unified alpha version has a 'U' at the end of the name,
 
472
 * the component version has a 'C'.  Similarly, functions which deal with
 
473
 * this difference will have two versions using the same convention.
 
474
 */
 
475
 
 
476
#define FbOverU(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),(a),(t)) + FbGet8(x,i), \
 
477
                            (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
 
478
 
 
479
#define FbOverC(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),FbGet8(a,i),(t)) + FbGet8(x,i), \
 
480
                            (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
 
481
 
 
482
#define FbInU(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),(a),(t)) << (i))
 
483
 
 
484
#define FbInC(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),FbGet8(a,i),(t)) << (i))
 
485
 
 
486
#define FbAdd(x,y,i,t)  ((t) = FbGet8(x,i) + FbGet8(y,i),               \
 
487
                         (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
 
488
 
 
489
#define div_255(x) (((x) + 0x80 + (((x) + 0x80) >> 8)) >> 8)
 
490
#define div_65535(x) (((x) + 0x8000 + (((x) + 0x8000) >> 16)) >> 16)
 
491
 
 
492
#define MOD(a,b) ((a) < 0 ? ((b) - ((-(a) - 1) % (b))) - 1 : (a) % (b))
 
493
 
 
494
#define DIV(a,b) ((((a) < 0) == ((b) < 0)) ? (a) / (b) :                \
 
495
                  ((a) - (b) + 1 - (((b) < 0) << 1)) / (b))
 
496
 
 
497
#define CLIP(a,b,c) ((a) < (b) ? (b) : ((a) > (c) ? (c) : (a)))
 
498
 
 
499
#if 0
 
500
/* FIXME: the MOD macro above is equivalent, but faster I think */
 
501
#define mod(a,b) ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-a) % (b))
 
502
#endif
 
503
 
 
504
/* FIXME: the (void)__read_func hides lots of warnings (which is what they
 
505
 * are supposed to do), but some of them are real. For example the one
 
506
 * where Fetch4 doesn't have a READ
 
507
 */
 
508
 
 
509
#if 0
 
510
/* Framebuffer access support macros */
 
511
#define ACCESS_MEM(code)                                                \
 
512
    do {                                                                \
 
513
        const image_common_t *const com__ =                             \
 
514
            (image_common_t *)image;                                    \
 
515
                                                                        \
 
516
        if (!com__->read_func && !com__->write_func)                    \
 
517
        {                                                               \
 
518
            const int do_access__ = 0;                                  \
 
519
            const pixman_read_memory_func_t read_func__ = NULL;         \
 
520
            const pixman_write_memory_func_t write_func__ = NULL;       \
 
521
            (void)read_func__;                                          \
 
522
            (void)write_func__;                                         \
 
523
            (void)do_access__;                                          \
 
524
                                                                        \
 
525
            {code}                                                      \
 
526
        }                                                               \
 
527
        else                                                            \
 
528
        {                                                               \
 
529
            const int do_access__ = 1;                                  \
 
530
            const pixman_read_memory_func_t read_func__ =               \
 
531
                com__->read_func;                                       \
 
532
            const pixman_write_memory_func_t write_func__ =             \
 
533
                com__->write_func;                                      \
 
534
            (void)read_func__;                                          \
 
535
            (void)write_func__;                                         \
 
536
            (void)do_access__;                                          \
 
537
                                                                        \
 
538
            {code}                                                      \
 
539
        }                                                               \
 
540
    } while (0)
 
541
#endif
 
542
 
 
543
#ifdef PIXMAN_FB_ACCESSORS
 
544
 
 
545
#define ACCESS(sym) sym##_accessors
 
546
 
 
547
#define READ(img, ptr)                                                  \
 
548
    ((img)->common.read_func ((ptr), sizeof(*(ptr))))
 
549
#define WRITE(img, ptr,val)                                             \
 
550
    ((img)->common.write_func ((ptr), (val), sizeof (*(ptr))))
 
551
 
 
552
#define MEMCPY_WRAPPED(img, dst, src, size)                             \
 
553
    do {                                                                \
 
554
        size_t _i;                                                      \
 
555
        uint8_t *_dst = (uint8_t*)(dst), *_src = (uint8_t*)(src);       \
 
556
        for(_i = 0; _i < size; _i++) {                                  \
 
557
            WRITE((img), _dst +_i, READ((img), _src + _i));             \
 
558
        }                                                               \
 
559
    } while (0)
 
560
 
 
561
#define MEMSET_WRAPPED(img, dst, val, size)                             \
 
562
    do {                                                                \
 
563
        size_t _i;                                                      \
 
564
        uint8_t *_dst = (uint8_t*)(dst);                                \
 
565
        for(_i = 0; _i < (size_t) size; _i++) {                         \
 
566
            WRITE((img), _dst +_i, (val));                              \
 
567
        }                                                               \
 
568
    } while (0)
 
569
 
 
570
#else
 
571
 
 
572
#define ACCESS(sym) sym
 
573
 
 
574
#define READ(img, ptr)          (*(ptr))
 
575
#define WRITE(img, ptr, val)    (*(ptr) = (val))
 
576
#define MEMCPY_WRAPPED(img, dst, src, size)                                     \
 
577
    memcpy(dst, src, size)
 
578
#define MEMSET_WRAPPED(img, dst, val, size)                                     \
 
579
    memset(dst, val, size)
 
580
 
 
581
#endif
 
582
 
 
583
#define fbComposeGetSolid(img, res, fmt)                                \
 
584
    do                                                                  \
 
585
    {                                                                   \
 
586
        pixman_format_code_t format__;                                  \
 
587
        if (img->type == SOLID)                                         \
 
588
        {                                                               \
 
589
            format__ = PIXMAN_a8r8g8b8;                                 \
 
590
            (res) = img->solid.color;                                   \
 
591
        }                                                               \
 
592
        else                                                            \
 
593
        {                                                               \
 
594
            uint32_t           *bits__   = (img)->bits.bits;            \
 
595
            format__ = (img)->bits.format;                              \
 
596
                                                                        \
 
597
            switch (PIXMAN_FORMAT_BPP((img)->bits.format))              \
 
598
            {                                                           \
 
599
            case 32:                                                    \
 
600
                (res) = READ(img, (uint32_t *)bits__);                  \
 
601
                break;                                                  \
 
602
            case 24:                                                    \
 
603
                (res) = Fetch24(img, (uint8_t *) bits__);                       \
 
604
                break;                                                  \
 
605
            case 16:                                                    \
 
606
                (res) = READ(img, (uint16_t *) bits__);                 \
 
607
                (res) = cvt0565to0888(res);                             \
 
608
                break;                                                  \
 
609
            case 8:                                                     \
 
610
                (res) = READ(img, (uint8_t *) bits__);                  \
 
611
                (res) = (res) << 24;                                    \
 
612
                break;                                                  \
 
613
            case 1:                                                     \
 
614
                (res) = READ(img, (uint32_t *) bits__);                 \
 
615
                (res) = FbLeftStipBits((res),1) ? 0xff000000 : 0x00000000; \
 
616
                break;                                                  \
 
617
            default:                                                    \
 
618
                return;                                                 \
 
619
            }                                                           \
 
620
            /* manage missing src alpha */                              \
 
621
            if (!PIXMAN_FORMAT_A((img)->bits.format))                   \
 
622
                (res) |= 0xff000000;                                    \
 
623
        }                                                               \
 
624
                                                                        \
 
625
        /* If necessary, convert RGB <--> BGR. */                       \
 
626
        if (PIXMAN_FORMAT_TYPE (format__) != PIXMAN_FORMAT_TYPE(fmt))   \
 
627
        {                                                               \
 
628
            (res) = ((((res) & 0xff000000) >>  0) |                     \
 
629
                     (((res) & 0x00ff0000) >> 16) |                     \
 
630
                     (((res) & 0x0000ff00) >>  0) |                     \
 
631
                     (((res) & 0x000000ff) << 16));                     \
 
632
        }                                                               \
 
633
    }                                                                   \
 
634
    while (0)
 
635
 
 
636
#define fbComposeGetStart(pict,x,y,type,out_stride,line,mul) do {       \
 
637
        uint32_t        *__bits__;                                      \
 
638
        int             __stride__;                                     \
 
639
        int             __bpp__;                                        \
 
640
                                                                        \
 
641
        __bits__ = pict->bits.bits;                                     \
 
642
        __stride__ = pict->bits.rowstride;                              \
 
643
        __bpp__ = PIXMAN_FORMAT_BPP(pict->bits.format);                 \
 
644
        (out_stride) = __stride__ * (int) sizeof (uint32_t) / (int) sizeof (type);      \
 
645
        (line) = ((type *) __bits__) +                                  \
 
646
            (out_stride) * (y) + (mul) * (x);                           \
 
647
    } while (0)
 
648
 
 
649
 
 
650
#define PIXMAN_FORMAT_16BPC(f)  (PIXMAN_FORMAT_A(f) > 8 || \
 
651
                                 PIXMAN_FORMAT_R(f) > 8 || \
 
652
                                 PIXMAN_FORMAT_G(f) > 8 || \
 
653
                                 PIXMAN_FORMAT_B(f) > 8)
 
654
/*
 
655
 * Edges
 
656
 */
 
657
 
 
658
#define MAX_ALPHA(n)    ((1 << (n)) - 1)
 
659
#define N_Y_FRAC(n)     ((n) == 1 ? 1 : (1 << ((n)/2)) - 1)
 
660
#define N_X_FRAC(n)     ((n) == 1 ? 1 : (1 << ((n)/2)) + 1)
 
661
 
 
662
#define STEP_Y_SMALL(n) (pixman_fixed_1 / N_Y_FRAC(n))
 
663
#define STEP_Y_BIG(n)   (pixman_fixed_1 - (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
 
664
 
 
665
#define Y_FRAC_FIRST(n) (STEP_Y_SMALL(n) / 2)
 
666
#define Y_FRAC_LAST(n)  (Y_FRAC_FIRST(n) + (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
 
667
 
 
668
#define STEP_X_SMALL(n) (pixman_fixed_1 / N_X_FRAC(n))
 
669
#define STEP_X_BIG(n)   (pixman_fixed_1 - (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
 
670
 
 
671
#define X_FRAC_FIRST(n) (STEP_X_SMALL(n) / 2)
 
672
#define X_FRAC_LAST(n)  (X_FRAC_FIRST(n) + (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
 
673
 
 
674
#define RenderSamplesX(x,n)     ((n) == 1 ? 0 : (pixman_fixed_frac (x) + X_FRAC_FIRST(n)) / STEP_X_SMALL(n))
 
675
 
 
676
/*
 
677
 * Step across a small sample grid gap
 
678
 */
 
679
#define RenderEdgeStepSmall(edge) { \
 
680
    edge->x += edge->stepx_small;   \
 
681
    edge->e += edge->dx_small;      \
 
682
    if (edge->e > 0)                \
 
683
    {                               \
 
684
        edge->e -= edge->dy;        \
 
685
        edge->x += edge->signdx;    \
 
686
    }                               \
 
687
}
 
688
 
 
689
/*
 
690
 * Step across a large sample grid gap
 
691
 */
 
692
#define RenderEdgeStepBig(edge) {   \
 
693
    edge->x += edge->stepx_big;     \
 
694
    edge->e += edge->dx_big;        \
 
695
    if (edge->e > 0)                \
 
696
    {                               \
 
697
        edge->e -= edge->dy;        \
 
698
        edge->x += edge->signdx;    \
 
699
    }                               \
 
700
}
 
701
 
 
702
void
 
703
pixman_rasterize_edges_accessors (pixman_image_t *image,
 
704
                                  pixman_edge_t *l,
 
705
                                  pixman_edge_t *r,
 
706
                                  pixman_fixed_t        t,
 
707
                                  pixman_fixed_t        b);
 
708
 
 
709
pixman_bool_t
 
710
pixman_image_is_opaque(pixman_image_t *image);
 
711
 
 
712
pixman_bool_t
 
713
pixman_image_can_get_solid (pixman_image_t *image);
 
714
 
 
715
pixman_bool_t
 
716
pixman_compute_composite_region32 (pixman_region32_t *  pRegion,
 
717
                                   pixman_image_t *     pSrc,
 
718
                                   pixman_image_t *     pMask,
 
719
                                   pixman_image_t *     pDst,
 
720
                                   int16_t              xSrc,
 
721
                                   int16_t              ySrc,
 
722
                                   int16_t              xMask,
 
723
                                   int16_t              yMask,
 
724
                                   int16_t              xDst,
 
725
                                   int16_t              yDst,
 
726
                                   uint16_t             width,
 
727
                                   uint16_t             height);
 
728
 
 
729
/* GCC visibility */
 
730
#if defined(__GNUC__) && __GNUC__ >= 4
 
731
#define PIXMAN_EXPORT __attribute__ ((visibility("default")))
 
732
/* Sun Studio 8 visibility */
 
733
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
 
734
#define PIXMAN_EXPORT __global
 
735
#else
 
736
#define PIXMAN_EXPORT
 
737
#endif
 
738
 
 
739
/* Region Helpers */
 
740
pixman_bool_t pixman_region32_copy_from_region16 (pixman_region32_t *dst,
 
741
                                                  pixman_region16_t *src);
 
742
pixman_bool_t pixman_region16_copy_from_region32 (pixman_region16_t *dst,
 
743
                                                  pixman_region32_t *src);
 
744
void pixman_region_internal_set_static_pointers (pixman_box16_t *empty_box,
 
745
                                                 pixman_region16_data_t *empty_data,
 
746
                                                 pixman_region16_data_t *broken_data);
 
747
 
 
748
#ifdef PIXMAN_TIMING
 
749
 
 
750
/* Timing */
 
751
static inline uint64_t
 
752
oil_profile_stamp_rdtsc (void)
 
753
{
 
754
    uint64_t ts;
 
755
    __asm__ __volatile__("rdtsc\n" : "=A" (ts));
 
756
    return ts;
 
757
}
 
758
#define OIL_STAMP oil_profile_stamp_rdtsc
 
759
 
 
760
typedef struct PixmanTimer PixmanTimer;
 
761
 
 
762
struct PixmanTimer
 
763
{
 
764
    int initialized;
 
765
    const char *name;
 
766
    uint64_t n_times;
 
767
    uint64_t total;
 
768
    PixmanTimer *next;
 
769
};
 
770
 
 
771
extern int timer_defined;
 
772
void pixman_timer_register (PixmanTimer *timer);
 
773
 
 
774
#define TIMER_BEGIN(tname)                                              \
 
775
    {                                                                   \
 
776
        static PixmanTimer      timer##tname;                           \
 
777
        uint64_t                begin##tname;                           \
 
778
                                                                        \
 
779
        if (!timer##tname.initialized)                                  \
 
780
        {                                                               \
 
781
            timer##tname.initialized = 1;                               \
 
782
            timer##tname.name = #tname;                                 \
 
783
            pixman_timer_register (&timer##tname);                      \
 
784
        }                                                               \
 
785
                                                                        \
 
786
        timer##tname.n_times++;                                         \
 
787
        begin##tname = OIL_STAMP();
 
788
 
 
789
#define TIMER_END(tname)                                                \
 
790
        timer##tname.total += OIL_STAMP() - begin##tname;               \
 
791
    }
 
792
 
 
793
#endif /* PIXMAN_TIMING */
 
794
 
 
795
#endif /* PIXMAN_PRIVATE_H */