2 # error config.h must be included before pixman-private.h
5 #ifndef PIXMAN_PRIVATE_H
6 #define PIXMAN_PRIVATE_H
22 #ifdef WORDS_BIGENDIAN
23 # define IMAGE_BYTE_ORDER MSBFirst
24 # define BITMAP_BIT_ORDER MSBFirst
26 # define IMAGE_BYTE_ORDER LSBFirst
27 # define BITMAP_BIT_ORDER LSBFirst
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__))
38 # define FUNC ((const char*) ("???"))
42 # define INT16_MIN (-32767-1)
46 # define INT16_MAX (32767)
50 # define INT32_MIN (-2147483647-1)
54 # define INT32_MAX (2147483647)
58 # define UINT32_MIN (0)
62 # define UINT32_MAX (4294967295U)
66 # define M_PI 3.14159265358979323846
70 #define inline __inline
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)
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);
87 #define return_if_fail(expr) \
92 fprintf(stderr, "In %s: %s failed\n", FUNC, #expr); \
98 #define return_val_if_fail(expr, retval) \
103 fprintf(stderr, "In %s: %s failed\n", FUNC, #expr); \
111 #define return_if_fail(expr) \
119 #define return_val_if_fail(expr, retval) \
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;
142 /* FIXME - the types and structures below should be give proper names
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,
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 *);
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,
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 *);
166 typedef struct _FbComposeData {
169 pixman_image_t *mask;
170 pixman_image_t *dest;
181 typedef struct _FbComposeFunctions32 {
182 CombineFuncU32 *combineU;
183 CombineFuncC32 *combineC;
184 CombineMaskU32 combineMaskU;
185 } FbComposeFunctions32;
187 typedef struct _FbComposeFunctions64 {
188 CombineFuncU64 *combineU;
189 CombineFuncC64 *combineC;
190 CombineMaskU64 combineMaskU;
191 } FbComposeFunctions64;
193 extern FbComposeFunctions32 pixman_composeFunctions;
194 extern FbComposeFunctions64 pixman_composeFunctions64;
196 void pixman_composite_rect_general_accessors (const FbComposeData *data,
201 void pixman_composite_rect_general (const FbComposeData *data);
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 *);
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 *);
217 void pixmanFetchSourcePict(source_image_t *, int x, int y, int width,
218 uint32_t *buffer, uint32_t *mask, uint32_t maskBits);
220 void fbFetchTransformed(bits_image_t *, int x, int y, int width,
221 uint32_t *buffer, uint32_t *mask, uint32_t maskBits);
222 void fbStoreExternalAlpha(bits_image_t *, int x, int y, int width,
224 void fbFetchExternalAlpha(bits_image_t *, int x, int y, int width,
225 uint32_t *buffer, uint32_t *mask, uint32_t maskBits);
227 void fbFetchTransformed_accessors(bits_image_t *, int x, int y, int width,
228 uint32_t *buffer, uint32_t *mask,
230 void fbStoreExternalAlpha_accessors(bits_image_t *, int x, int y, int width,
232 void fbFetchExternalAlpha_accessors(bits_image_t *, int x, int y, int width,
233 uint32_t *buffer, uint32_t *mask,
247 #define IS_SOURCE_IMAGE(img) (((image_common_t *)img)->type > BITS)
251 SOURCE_IMAGE_CLASS_UNKNOWN,
252 SOURCE_IMAGE_CLASS_HORIZONTAL,
253 SOURCE_IMAGE_CLASS_VERTICAL
254 } source_pict_class_t;
265 pixman_region32_t full_region;
266 pixman_region32_t clip_region;
267 pixman_region32_t *src_clip;
268 pixman_bool_t has_client_clip;
269 pixman_transform_t *transform;
270 pixman_repeat_t repeat;
271 pixman_filter_t filter;
272 pixman_fixed_t *filter_params;
274 bits_image_t *alpha_map;
275 point_t alpha_origin;
276 pixman_bool_t component_alpha;
277 pixman_read_memory_func_t read_func;
278 pixman_write_memory_func_t write_func;
283 image_common_t common;
284 source_pict_class_t class;
289 source_image_t common;
290 uint32_t color; /* FIXME: shouldn't this be a pixman_color_t? */
295 source_image_t common;
297 pixman_gradient_stop_t * stops;
299 uint32_t * color_table;
300 int color_table_size;
303 struct linear_gradient
306 pixman_point_fixed_t p1;
307 pixman_point_fixed_t p2;
314 pixman_fixed_t radius;
317 struct radial_gradient
329 struct conical_gradient
332 pixman_point_fixed_t center;
333 pixman_fixed_t angle;
338 image_common_t common;
339 pixman_format_code_t format;
340 const pixman_indexed_t *indexed;
345 int rowstride; /* in number of uint32_t's */
351 image_common_t common;
354 linear_gradient_t linear;
355 conical_gradient_t conical;
356 radial_gradient_t radial;
361 #define LOG2_BITMAP_PAD 5
362 #define FB_STIP_SHIFT LOG2_BITMAP_PAD
363 #define FB_STIP_UNIT (1 << FB_STIP_SHIFT)
364 #define FB_STIP_MASK (FB_STIP_UNIT - 1)
365 #define FB_STIP_ALLONES ((uint32_t) -1)
367 #if BITMAP_BIT_ORDER == LSBFirst
368 #define FbScrLeft(x,n) ((x) >> (n))
369 #define FbScrRight(x,n) ((x) << (n))
370 #define FbLeftStipBits(x,n) ((x) & ((((uint32_t) 1) << (n)) - 1))
372 #define FbScrLeft(x,n) ((x) << (n))
373 #define FbScrRight(x,n) ((x) >> (n))
374 #define FbLeftStipBits(x,n) ((x) >> (FB_STIP_UNIT - (n)))
377 #define FbStipLeft(x,n) FbScrLeft(x,n)
378 #define FbStipRight(x,n) FbScrRight(x,n)
379 #define FbStipMask(x,w) (FbStipRight(FB_STIP_ALLONES,(x) & FB_STIP_MASK) & \
380 FbStipLeft(FB_STIP_ALLONES,(FB_STIP_UNIT - ((x)+(w))) & FB_STIP_MASK))
382 #define FbLeftMask(x) ( ((x) & FB_MASK) ? \
383 FbScrRight(FB_ALLONES,(x) & FB_MASK) : 0)
384 #define FbRightMask(x) ( ((FB_UNIT - (x)) & FB_MASK) ? \
385 FbScrLeft(FB_ALLONES,(FB_UNIT - (x)) & FB_MASK) : 0)
387 #define FbMaskBits(x,w,l,n,r) { \
389 r = FbRightMask((x)+n); \
392 n -= FB_UNIT - ((x) & FB_MASK); \
402 #if IMAGE_BYTE_ORDER == MSBFirst
403 #define Fetch24(img, a) ((unsigned long) (a) & 1 ? \
404 ((READ(img, a) << 16) | READ(img, (uint16_t *) ((a)+1))) : \
405 ((READ(img, (uint16_t *) (a)) << 8) | READ(img, (a)+2)))
406 #define Store24(img,a,v) ((unsigned long) (a) & 1 ? \
407 (WRITE(img, a, (uint8_t) ((v) >> 16)), \
408 WRITE(img, (uint16_t *) ((a)+1), (uint16_t) (v))) : \
409 (WRITE(img, (uint16_t *) (a), (uint16_t) ((v) >> 8)), \
410 WRITE(img, (a)+2, (uint8_t) (v))))
412 #define Fetch24(img,a) ((unsigned long) (a) & 1 ? \
413 (READ(img, a) | (READ(img, (uint16_t *) ((a)+1)) << 8)) : \
414 (READ(img, (uint16_t *) (a)) | (READ(img, (a)+2) << 16)))
415 #define Store24(img,a,v) ((unsigned long) (a) & 1 ? \
416 (WRITE(img, a, (uint8_t) (v)), \
417 WRITE(img, (uint16_t *) ((a)+1), (uint16_t) ((v) >> 8))) : \
418 (WRITE(img, (uint16_t *) (a), (uint16_t) (v)), \
419 WRITE(img, (a)+2, (uint8_t) ((v) >> 16))))
422 #define CvtR8G8B8toY15(s) (((((s) >> 16) & 0xff) * 153 + \
423 (((s) >> 8) & 0xff) * 301 + \
424 (((s) ) & 0xff) * 58) >> 2)
425 #define miCvtR8G8B8to15(s) ((((s) >> 3) & 0x001f) | \
426 (((s) >> 6) & 0x03e0) | \
427 (((s) >> 9) & 0x7c00))
428 #define miIndexToEnt15(mif,rgb15) ((mif)->ent[rgb15])
429 #define miIndexToEnt24(mif,rgb24) miIndexToEnt15(mif,miCvtR8G8B8to15(rgb24))
431 #define miIndexToEntY24(mif,rgb24) ((mif)->ent[CvtR8G8B8toY15(rgb24)])
434 #define FbIntMult(a,b,t) ( (t) = (a) * (b) + 0x80, ( ( ( (t)>>8 ) + (t) )>>8 ) )
435 #define FbIntDiv(a,b) (((uint16_t) (a) * 255) / (b))
437 #define FbGet8(v,i) ((uint16_t) (uint8_t) ((v) >> i))
440 #define cvt8888to0565(s) ((((s) >> 3) & 0x001f) | \
441 (((s) >> 5) & 0x07e0) | \
442 (((s) >> 8) & 0xf800))
443 #define cvt0565to0888(s) (((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7)) | \
444 ((((s) << 5) & 0xfc00) | (((s) >> 1) & 0x300)) | \
445 ((((s) << 8) & 0xf80000) | (((s) << 3) & 0x70000)))
448 * There are two ways of handling alpha -- either as a single unified value or
449 * a separate value for each component, hence each macro must have two
450 * versions. The unified alpha version has a 'U' at the end of the name,
451 * the component version has a 'C'. Similarly, functions which deal with
452 * this difference will have two versions using the same convention.
455 #define FbOverU(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),(a),(t)) + FbGet8(x,i), \
456 (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
458 #define FbOverC(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),FbGet8(a,i),(t)) + FbGet8(x,i), \
459 (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
461 #define FbInU(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),(a),(t)) << (i))
463 #define FbInC(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),FbGet8(a,i),(t)) << (i))
465 #define FbAdd(x,y,i,t) ((t) = FbGet8(x,i) + FbGet8(y,i), \
466 (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
468 #define div_255(x) (((x) + 0x80 + (((x) + 0x80) >> 8)) >> 8)
470 #define MOD(a,b) ((a) < 0 ? ((b) - ((-(a) - 1) % (b))) - 1 : (a) % (b))
472 #define DIV(a,b) ((((a) < 0) == ((b) < 0)) ? (a) / (b) : \
473 ((a) - (b) + 1 - (((b) < 0) << 1)) / (b))
475 #define CLIP(a,b,c) ((a) < (b) ? (b) : ((a) > (c) ? (c) : (a)))
478 /* FIXME: the MOD macro above is equivalent, but faster I think */
479 #define mod(a,b) ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-a) % (b))
482 /* FIXME: the (void)__read_func hides lots of warnings (which is what they
483 * are supposed to do), but some of them are real. For example the one
484 * where Fetch4 doesn't have a READ
488 /* Framebuffer access support macros */
489 #define ACCESS_MEM(code) \
491 const image_common_t *const com__ = \
492 (image_common_t *)image; \
494 if (!com__->read_func && !com__->write_func) \
496 const int do_access__ = 0; \
497 const pixman_read_memory_func_t read_func__ = NULL; \
498 const pixman_write_memory_func_t write_func__ = NULL; \
500 (void)write_func__; \
507 const int do_access__ = 1; \
508 const pixman_read_memory_func_t read_func__ = \
510 const pixman_write_memory_func_t write_func__ = \
513 (void)write_func__; \
521 #ifdef PIXMAN_FB_ACCESSORS
523 #define ACCESS(sym) sym##_accessors
525 #define READ(img, ptr) \
526 ((img)->common.read_func ((ptr), sizeof(*(ptr))))
527 #define WRITE(img, ptr,val) \
528 ((img)->common.write_func ((ptr), (val), sizeof (*(ptr))))
530 #define MEMCPY_WRAPPED(img, dst, src, size) \
533 uint8_t *_dst = (uint8_t*)(dst), *_src = (uint8_t*)(src); \
534 for(_i = 0; _i < size; _i++) { \
535 WRITE((img), _dst +_i, READ((img), _src + _i)); \
539 #define MEMSET_WRAPPED(img, dst, val, size) \
542 uint8_t *_dst = (uint8_t*)(dst); \
543 for(_i = 0; _i < (size_t) size; _i++) { \
544 WRITE((img), _dst +_i, (val)); \
550 #define ACCESS(sym) sym
552 #define READ(img, ptr) (*(ptr))
553 #define WRITE(img, ptr, val) (*(ptr) = (val))
554 #define MEMCPY_WRAPPED(img, dst, src, size) \
555 memcpy(dst, src, size)
556 #define MEMSET_WRAPPED(img, dst, val, size) \
557 memset(dst, val, size)
561 #define fbComposeGetSolid(img, res, fmt) \
564 pixman_format_code_t format__; \
565 if (img->type == SOLID) \
567 format__ = PIXMAN_a8r8g8b8; \
568 (res) = img->solid.color; \
572 uint32_t *bits__ = (img)->bits.bits; \
573 format__ = (img)->bits.format; \
575 switch (PIXMAN_FORMAT_BPP((img)->bits.format)) \
578 (res) = READ(img, (uint32_t *)bits__); \
581 (res) = Fetch24(img, (uint8_t *) bits__); \
584 (res) = READ(img, (uint16_t *) bits__); \
585 (res) = cvt0565to0888(res); \
588 (res) = READ(img, (uint8_t *) bits__); \
589 (res) = (res) << 24; \
592 (res) = READ(img, (uint32_t *) bits__); \
593 (res) = FbLeftStipBits((res),1) ? 0xff000000 : 0x00000000; \
598 /* manage missing src alpha */ \
599 if (!PIXMAN_FORMAT_A((img)->bits.format)) \
600 (res) |= 0xff000000; \
603 /* If necessary, convert RGB <--> BGR. */ \
604 if (PIXMAN_FORMAT_TYPE (format__) != PIXMAN_FORMAT_TYPE(fmt)) \
606 (res) = ((((res) & 0xff000000) >> 0) | \
607 (((res) & 0x00ff0000) >> 16) | \
608 (((res) & 0x0000ff00) >> 0) | \
609 (((res) & 0x000000ff) << 16)); \
614 #define fbComposeGetStart(pict,x,y,type,out_stride,line,mul) do { \
615 uint32_t *__bits__; \
619 __bits__ = pict->bits.bits; \
620 __stride__ = pict->bits.rowstride; \
621 __bpp__ = PIXMAN_FORMAT_BPP(pict->bits.format); \
622 (out_stride) = __stride__ * (int) sizeof (uint32_t) / (int) sizeof (type); \
623 (line) = ((type *) __bits__) + \
624 (out_stride) * (y) + (mul) * (x); \
632 #define MAX_ALPHA(n) ((1 << (n)) - 1)
633 #define N_Y_FRAC(n) ((n) == 1 ? 1 : (1 << ((n)/2)) - 1)
634 #define N_X_FRAC(n) ((n) == 1 ? 1 : (1 << ((n)/2)) + 1)
636 #define STEP_Y_SMALL(n) (pixman_fixed_1 / N_Y_FRAC(n))
637 #define STEP_Y_BIG(n) (pixman_fixed_1 - (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
639 #define Y_FRAC_FIRST(n) (STEP_Y_SMALL(n) / 2)
640 #define Y_FRAC_LAST(n) (Y_FRAC_FIRST(n) + (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
642 #define STEP_X_SMALL(n) (pixman_fixed_1 / N_X_FRAC(n))
643 #define STEP_X_BIG(n) (pixman_fixed_1 - (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
645 #define X_FRAC_FIRST(n) (STEP_X_SMALL(n) / 2)
646 #define X_FRAC_LAST(n) (X_FRAC_FIRST(n) + (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
648 #define RenderSamplesX(x,n) ((n) == 1 ? 0 : (pixman_fixed_frac (x) + X_FRAC_FIRST(n)) / STEP_X_SMALL(n))
651 * Step across a small sample grid gap
653 #define RenderEdgeStepSmall(edge) { \
654 edge->x += edge->stepx_small; \
655 edge->e += edge->dx_small; \
658 edge->e -= edge->dy; \
659 edge->x += edge->signdx; \
664 * Step across a large sample grid gap
666 #define RenderEdgeStepBig(edge) { \
667 edge->x += edge->stepx_big; \
668 edge->e += edge->dx_big; \
671 edge->e -= edge->dy; \
672 edge->x += edge->signdx; \
677 pixman_rasterize_edges_accessors (pixman_image_t *image,
684 pixman_image_is_opaque(pixman_image_t *image);
687 pixman_image_can_get_solid (pixman_image_t *image);
691 #if defined(__GNUC__) && __GNUC__ >= 4
692 #define PIXMAN_EXPORT __attribute__ ((visibility("default")))
694 #define PIXMAN_EXPORT
697 /* Helper for 32 bit regions */
699 pixman_region32_copy_from_region16 (pixman_region32_t *dst,
700 pixman_region16_t *src);
705 static inline uint64_t
706 oil_profile_stamp_rdtsc (void)
709 __asm__ __volatile__("rdtsc\n" : "=A" (ts));
712 #define OIL_STAMP oil_profile_stamp_rdtsc
714 typedef struct PixmanTimer PixmanTimer;
725 extern int timer_defined;
726 void pixman_timer_register (PixmanTimer *timer);
728 #define TIMER_BEGIN(tname) \
730 static PixmanTimer timer##tname; \
731 uint64_t begin##tname; \
733 if (!timer##tname.initialized) \
735 timer##tname.initialized = 1; \
736 timer##tname.name = #tname; \
737 pixman_timer_register (&timer##tname); \
740 timer##tname.n_times++; \
741 begin##tname = OIL_STAMP();
743 #define TIMER_END(tname) \
744 timer##tname.total += OIL_STAMP() - begin##tname; \
747 #endif /* PIXMAN_TIMING */
749 #endif /* PIXMAN_PRIVATE_H */