2 # error config.h must be included before pixman-private.h
5 #ifndef PIXMAN_PRIVATE_H
6 #define PIXMAN_PRIVATE_H
12 #include "pixman-compiler.h"
26 /* Memory allocation helpers */
27 void *pixman_malloc_ab (unsigned int n, unsigned int b);
28 void *pixman_malloc_abc (unsigned int a, unsigned int b, unsigned int c);
29 pixman_bool_t pixman_multiply_overflows_int (unsigned int a, unsigned int b);
30 pixman_bool_t pixman_addition_overflows_int (unsigned int a, unsigned int b);
34 #define return_if_fail(expr) \
39 fprintf(stderr, "In %s: %s failed\n", FUNC, #expr); \
45 #define return_val_if_fail(expr, retval) \
50 fprintf(stderr, "In %s: %s failed\n", FUNC, #expr); \
58 #define return_if_fail(expr) \
66 #define return_val_if_fail(expr, retval) \
76 typedef struct image_common image_common_t;
77 typedef struct source_image source_image_t;
78 typedef struct solid_fill solid_fill_t;
79 typedef struct gradient gradient_t;
80 typedef struct linear_gradient linear_gradient_t;
81 typedef struct horizontal_gradient horizontal_gradient_t;
82 typedef struct vertical_gradient vertical_gradient_t;
83 typedef struct conical_gradient conical_gradient_t;
84 typedef struct radial_gradient radial_gradient_t;
85 typedef struct bits_image bits_image_t;
86 typedef struct circle circle_t;
87 typedef struct point point_t;
89 /* FIXME - the types and structures below should be give proper names
92 typedef void (*fetchProc32)(bits_image_t *pict, int x, int y, int width,
94 typedef uint32_t (*fetchPixelProc32)(bits_image_t *pict, int offset, int line);
95 typedef void (*storeProc32)(pixman_image_t *, uint32_t *bits,
96 const uint32_t *values, int x, int width,
97 const pixman_indexed_t *);
99 typedef void (*fetchProc64)(bits_image_t *pict, int x, int y, int width,
101 typedef uint64_t (*fetchPixelProc64)(bits_image_t *pict, int offset, int line);
102 typedef void (*storeProc64)(pixman_image_t *, uint32_t *bits,
103 const uint64_t *values, int x, int width,
104 const pixman_indexed_t *);
106 typedef void (* fetch_pixels_32_t) (bits_image_t *image, uint32_t *buffer, int n_pixels);
107 typedef void (* fetch_pixels_64_t) (bits_image_t *image, uint64_t *buffer, int n_pixels);
109 void _pixman_bits_image_setup_raw_accessors (bits_image_t *image);
111 void pixman_expand(uint64_t *dst, const uint32_t *src, pixman_format_code_t, int width);
112 void pixman_contract(uint32_t *dst, const uint64_t *src, int width);
114 void _pixman_image_get_scanline_64_generic (pixman_image_t * pict, int x, int y, int width,
115 uint64_t *buffer, uint64_t *mask, uint32_t maskBits);
130 SOURCE_IMAGE_CLASS_UNKNOWN,
131 SOURCE_IMAGE_CLASS_HORIZONTAL,
132 SOURCE_IMAGE_CLASS_VERTICAL,
133 } source_pict_class_t;
135 typedef void (*scanStoreProc)(bits_image_t *img, int x, int y, int width, uint32_t *buffer);
136 typedef void (*scanFetchProc)(pixman_image_t *, int, int, int, uint32_t *,
137 uint32_t *, uint32_t);
140 _pixman_image_classify (pixman_image_t *image,
147 _pixman_image_get_scanline_32 (pixman_image_t *image, int x, int y, int width,
148 uint32_t *buffer, uint32_t *mask, uint32_t mask_bits);
150 /* Even thought the type of buffer is uint32_t *, the function actually expects
151 * a uint64_t *buffer.
154 _pixman_image_get_scanline_64 (pixman_image_t *image, int x, int y, int width,
155 uint32_t *buffer, uint32_t *unused, uint32_t unused2);
158 _pixman_image_store_scanline_32 (bits_image_t *image, int x, int y, int width,
161 _pixman_image_fetch_pixels (bits_image_t *image, uint32_t *buffer, int n_pixels);
163 /* Even thought the type of buffer is uint32_t *, the function actually expects
164 * a uint64_t *buffer.
167 _pixman_image_store_scanline_64 (bits_image_t *image, int x, int y, int width,
171 _pixman_image_allocate (void);
174 _pixman_init_gradient (gradient_t *gradient,
175 const pixman_gradient_stop_t *stops,
178 _pixman_image_reset_clip_region (pixman_image_t *image);
185 typedef source_pict_class_t (* classify_func_t) (pixman_image_t *image,
190 typedef void (* property_changed_func_t) (pixman_image_t *image);
196 pixman_region32_t clip_region;
197 pixman_bool_t have_clip_region; /* FALSE if there is no clip */
198 pixman_bool_t client_clip; /* Whether the source clip was set by a client */
199 pixman_bool_t clip_sources; /* Whether the clip applies when
200 * the image is used as a source
202 pixman_transform_t *transform;
203 pixman_repeat_t repeat;
204 pixman_filter_t filter;
205 pixman_fixed_t *filter_params;
207 bits_image_t *alpha_map;
208 point_t alpha_origin;
209 pixman_bool_t component_alpha;
210 pixman_read_memory_func_t read_func;
211 pixman_write_memory_func_t write_func;
212 classify_func_t classify;
213 property_changed_func_t property_changed;
214 scanFetchProc get_scanline_32;
215 scanFetchProc get_scanline_64;
217 pixman_image_destroy_func_t destroy_func;
223 image_common_t common;
224 source_pict_class_t class;
229 source_image_t common;
230 uint32_t color; /* FIXME: shouldn't this be a pixman_color_t? */
235 source_image_t common;
237 pixman_gradient_stop_t * stops;
239 uint32_t * color_table;
240 int color_table_size;
243 struct linear_gradient
246 pixman_point_fixed_t p1;
247 pixman_point_fixed_t p2;
254 pixman_fixed_t radius;
257 struct radial_gradient
269 struct conical_gradient
272 pixman_point_fixed_t center;
273 pixman_fixed_t angle;
278 image_common_t common;
279 pixman_format_code_t format;
280 const pixman_indexed_t *indexed;
285 int rowstride; /* in number of uint32_t's */
287 /* Fetch raw pixels, with no regard for transformations, alpha map etc. */
288 fetch_pixels_32_t fetch_pixels_raw_32;
289 fetch_pixels_64_t fetch_pixels_raw_64;
291 /* Fetch raw scanlines, with no regard for transformations, alpha maps etc. */
292 fetchProc32 fetch_scanline_raw_32;
293 fetchProc64 fetch_scanline_raw_64;
295 /* Store scanlines with no regard for alpha maps */
296 storeProc32 store_scanline_raw_32;
297 storeProc64 store_scanline_raw_64;
299 /* Store a scanline, taking alpha maps into account */
300 scanStoreProc store_scanline_32;
301 scanStoreProc store_scanline_64;
303 /* Used for indirect access to the bits */
304 pixman_read_memory_func_t read_func;
305 pixman_write_memory_func_t write_func;
311 image_common_t common;
313 source_image_t source;
315 linear_gradient_t linear;
316 conical_gradient_t conical;
317 radial_gradient_t radial;
334 pixman_gradient_stop_t *stops;
339 } pixman_gradient_walker_t;
342 _pixman_gradient_walker_init (pixman_gradient_walker_t *walker,
343 gradient_t *gradient,
344 unsigned int spread);
347 _pixman_gradient_walker_reset (pixman_gradient_walker_t *walker,
348 pixman_fixed_32_32_t pos);
351 _pixman_gradient_walker_pixel (pixman_gradient_walker_t *walker,
352 pixman_fixed_32_32_t x);
356 #ifdef WORDS_BIGENDIAN
357 #define Fetch24(img, a) ((unsigned long) (a) & 1 ? \
358 ((READ(img, a) << 16) | READ(img, (uint16_t *) ((a)+1))) : \
359 ((READ(img, (uint16_t *) (a)) << 8) | READ(img, (a)+2)))
360 #define Store24(img,a,v) ((unsigned long) (a) & 1 ? \
361 (WRITE(img, a, (uint8_t) ((v) >> 16)), \
362 WRITE(img, (uint16_t *) ((a)+1), (uint16_t) (v))) : \
363 (WRITE(img, (uint16_t *) (a), (uint16_t) ((v) >> 8)), \
364 WRITE(img, (a)+2, (uint8_t) (v))))
366 #define Fetch24(img,a) ((unsigned long) (a) & 1 ? \
367 (READ(img, a) | (READ(img, (uint16_t *) ((a)+1)) << 8)) : \
368 (READ(img, (uint16_t *) (a)) | (READ(img, (a)+2) << 16)))
369 #define Store24(img,a,v) ((unsigned long) (a) & 1 ? \
370 (WRITE(img, a, (uint8_t) (v)), \
371 WRITE(img, (uint16_t *) ((a)+1), (uint16_t) ((v) >> 8))) : \
372 (WRITE(img, (uint16_t *) (a), (uint16_t) (v)), \
373 WRITE(img, (a)+2, (uint8_t) ((v) >> 16))))
376 #define CvtR8G8B8toY15(s) (((((s) >> 16) & 0xff) * 153 + \
377 (((s) >> 8) & 0xff) * 301 + \
378 (((s) ) & 0xff) * 58) >> 2)
379 #define miCvtR8G8B8to15(s) ((((s) >> 3) & 0x001f) | \
380 (((s) >> 6) & 0x03e0) | \
381 (((s) >> 9) & 0x7c00))
382 #define miIndexToEnt15(mif,rgb15) ((mif)->ent[rgb15])
383 #define miIndexToEnt24(mif,rgb24) miIndexToEnt15(mif,miCvtR8G8B8to15(rgb24))
385 #define miIndexToEntY24(mif,rgb24) ((mif)->ent[CvtR8G8B8toY15(rgb24)])
388 #define FbIntMult(a,b,t) ( (t) = (a) * (b) + 0x80, ( ( ( (t)>>8 ) + (t) )>>8 ) )
389 #define FbIntDiv(a,b) (((uint16_t) (a) * 255) / (b))
391 #define FbGet8(v,i) ((uint16_t) (uint8_t) ((v) >> i))
394 #define cvt8888to0565(s) ((((s) >> 3) & 0x001f) | \
395 (((s) >> 5) & 0x07e0) | \
396 (((s) >> 8) & 0xf800))
397 #define cvt0565to0888(s) (((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7)) | \
398 ((((s) << 5) & 0xfc00) | (((s) >> 1) & 0x300)) | \
399 ((((s) << 8) & 0xf80000) | (((s) << 3) & 0x70000)))
402 * There are two ways of handling alpha -- either as a single unified value or
403 * a separate value for each component, hence each macro must have two
404 * versions. The unified alpha version has a 'U' at the end of the name,
405 * the component version has a 'C'. Similarly, functions which deal with
406 * this difference will have two versions using the same convention.
409 #define FbOverU(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),(a),(t)) + FbGet8(x,i), \
410 (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
412 #define FbOverC(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),FbGet8(a,i),(t)) + FbGet8(x,i), \
413 (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
415 #define FbInU(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),(a),(t)) << (i))
417 #define FbInC(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),FbGet8(a,i),(t)) << (i))
419 #define FbAdd(x,y,i,t) ((t) = FbGet8(x,i) + FbGet8(y,i), \
420 (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
422 #define div_255(x) (((x) + 0x80 + (((x) + 0x80) >> 8)) >> 8)
423 #define div_65535(x) (((x) + 0x8000 + (((x) + 0x8000) >> 16)) >> 16)
425 #define MOD(a,b) ((a) < 0 ? ((b) - ((-(a) - 1) % (b))) - 1 : (a) % (b))
427 /* Divides two fixed-point numbers and returns an integer */
428 #define DIV(a,b) ((((a) < 0) == ((b) < 0)) ? (a) / (b) : \
429 ((a) - (b) + 1 - (((b) < 0) << 1)) / (b))
431 #define CLIP(a,b,c) ((a) < (b) ? (b) : ((a) > (c) ? (c) : (a)))
434 # define MIN(a,b) ((a < b)? a : b)
438 # define MAX(a,b) ((a > b)? a : b)
441 /* FIXME: the (void)__read_func hides lots of warnings (which is what they
442 * are supposed to do), but some of them are real. For example the one
443 * where Fetch4 doesn't have a READ
446 #ifdef PIXMAN_FB_ACCESSORS
448 #define ACCESS(sym) sym##_accessors
450 #define READ(img, ptr) \
451 ((img)->common.read_func ((ptr), sizeof(*(ptr))))
452 #define WRITE(img, ptr,val) \
453 ((img)->common.write_func ((ptr), (val), sizeof (*(ptr))))
455 #define MEMCPY_WRAPPED(img, dst, src, size) \
458 uint8_t *_dst = (uint8_t*)(dst), *_src = (uint8_t*)(src); \
459 for(_i = 0; _i < size; _i++) { \
460 WRITE((img), _dst +_i, READ((img), _src + _i)); \
464 #define MEMSET_WRAPPED(img, dst, val, size) \
467 uint8_t *_dst = (uint8_t*)(dst); \
468 for(_i = 0; _i < (size_t) size; _i++) { \
469 WRITE((img), _dst +_i, (val)); \
475 #define ACCESS(sym) sym
477 #define READ(img, ptr) (*(ptr))
478 #define WRITE(img, ptr, val) (*(ptr) = (val))
479 #define MEMCPY_WRAPPED(img, dst, src, size) \
480 memcpy(dst, src, size)
481 #define MEMSET_WRAPPED(img, dst, val, size) \
482 memset(dst, val, size)
486 #define fbComposeGetStart(pict,x,y,type,out_stride,line,mul) do { \
487 uint32_t *__bits__; \
491 __bits__ = pict->bits.bits; \
492 __stride__ = pict->bits.rowstride; \
493 __bpp__ = PIXMAN_FORMAT_BPP(pict->bits.format); \
494 (out_stride) = __stride__ * (int) sizeof (uint32_t) / (int) sizeof (type); \
495 (line) = ((type *) __bits__) + \
496 (out_stride) * (y) + (mul) * (x); \
500 #define PIXMAN_FORMAT_16BPC(f) (PIXMAN_FORMAT_A(f) > 8 || \
501 PIXMAN_FORMAT_R(f) > 8 || \
502 PIXMAN_FORMAT_G(f) > 8 || \
503 PIXMAN_FORMAT_B(f) > 8)
508 #define MAX_ALPHA(n) ((1 << (n)) - 1)
509 #define N_Y_FRAC(n) ((n) == 1 ? 1 : (1 << ((n)/2)) - 1)
510 #define N_X_FRAC(n) ((n) == 1 ? 1 : (1 << ((n)/2)) + 1)
512 #define STEP_Y_SMALL(n) (pixman_fixed_1 / N_Y_FRAC(n))
513 #define STEP_Y_BIG(n) (pixman_fixed_1 - (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
515 #define Y_FRAC_FIRST(n) (STEP_Y_SMALL(n) / 2)
516 #define Y_FRAC_LAST(n) (Y_FRAC_FIRST(n) + (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
518 #define STEP_X_SMALL(n) (pixman_fixed_1 / N_X_FRAC(n))
519 #define STEP_X_BIG(n) (pixman_fixed_1 - (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
521 #define X_FRAC_FIRST(n) (STEP_X_SMALL(n) / 2)
522 #define X_FRAC_LAST(n) (X_FRAC_FIRST(n) + (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
524 #define RenderSamplesX(x,n) ((n) == 1 ? 0 : (pixman_fixed_frac (x) + X_FRAC_FIRST(n)) / STEP_X_SMALL(n))
527 * Step across a small sample grid gap
529 #define RenderEdgeStepSmall(edge) { \
530 edge->x += edge->stepx_small; \
531 edge->e += edge->dx_small; \
534 edge->e -= edge->dy; \
535 edge->x += edge->signdx; \
540 * Step across a large sample grid gap
542 #define RenderEdgeStepBig(edge) { \
543 edge->x += edge->stepx_big; \
544 edge->e += edge->dx_big; \
547 edge->e -= edge->dy; \
548 edge->x += edge->signdx; \
553 pixman_rasterize_edges_accessors (pixman_image_t *image,
560 pixman_image_is_opaque(pixman_image_t *image);
563 pixman_image_is_solid (pixman_image_t *image);
566 pixman_image_get_solid (pixman_image_t *image,
567 pixman_format_code_t format);
570 pixman_compute_composite_region32 (pixman_region32_t * pRegion,
571 pixman_image_t * pSrc,
572 pixman_image_t * pMask,
573 pixman_image_t * pDst,
584 pixman_bool_t pixman_region32_copy_from_region16 (pixman_region32_t *dst,
585 pixman_region16_t *src);
586 pixman_bool_t pixman_region16_copy_from_region32 (pixman_region16_t *dst,
587 pixman_region32_t *src);
592 static inline uint64_t
593 oil_profile_stamp_rdtsc (void)
596 __asm__ __volatile__("rdtsc\n" : "=A" (ts));
599 #define OIL_STAMP oil_profile_stamp_rdtsc
601 typedef struct pixman_timer_t pixman_timer_t;
603 struct pixman_timer_t
609 pixman_timer_t *next;
612 extern int timer_defined;
613 void pixman_timer_register (pixman_timer_t *timer);
615 #define TIMER_BEGIN(tname) \
617 static pixman_timer_t timer##tname; \
618 uint64_t begin##tname; \
620 if (!timer##tname.initialized) \
622 timer##tname.initialized = 1; \
623 timer##tname.name = #tname; \
624 pixman_timer_register (&timer##tname); \
627 timer##tname.n_times++; \
628 begin##tname = OIL_STAMP();
630 #define TIMER_END(tname) \
631 timer##tname.total += OIL_STAMP() - begin##tname; \
634 #endif /* PIXMAN_TIMERS */
636 typedef struct pixman_implementation_t pixman_implementation_t;
638 typedef void (* pixman_combine_32_func_t) (pixman_implementation_t * imp,
641 const uint32_t * src,
642 const uint32_t * mask,
645 typedef void (* pixman_combine_64_func_t) (pixman_implementation_t * imp,
648 const uint64_t * src,
649 const uint64_t * mask,
652 typedef void (* pixman_composite_func_t) (pixman_implementation_t * imp,
654 pixman_image_t * src,
655 pixman_image_t * mask,
656 pixman_image_t * dest,
665 typedef pixman_bool_t (* pixman_blt_func_t) (pixman_implementation_t * imp,
678 typedef pixman_bool_t (* pixman_fill_func_t) (pixman_implementation_t *imp,
689 _pixman_walk_composite_region (pixman_implementation_t *imp,
691 pixman_image_t * pSrc,
692 pixman_image_t * pMask,
693 pixman_image_t * pDst,
702 pixman_composite_func_t compositeRect);
704 void _pixman_setup_combiner_functions_32 (pixman_implementation_t *imp);
705 void _pixman_setup_combiner_functions_64 (pixman_implementation_t *imp);
707 /* These "formats" both have depth 0, so they
708 * will never clash with any real ones
710 #define PIXMAN_null PIXMAN_FORMAT(0,0,0,0,0,0)
711 #define PIXMAN_solid PIXMAN_FORMAT(0,1,0,0,0,0)
713 #define NEED_COMPONENT_ALPHA (1 << 0)
714 #define NEED_PIXBUF (1 << 1)
715 #define NEED_SOLID_MASK (1 << 2)
720 pixman_format_code_t src_format;
721 pixman_format_code_t mask_format;
722 pixman_format_code_t dest_format;
723 pixman_composite_func_t func;
725 } pixman_fast_path_t;
727 struct pixman_implementation_t
729 pixman_implementation_t * toplevel;
730 pixman_implementation_t * delegate;
732 pixman_composite_func_t composite;
733 pixman_blt_func_t blt;
734 pixman_fill_func_t fill;
736 pixman_combine_32_func_t combine_32[PIXMAN_OP_LAST];
737 pixman_combine_32_func_t combine_32_ca[PIXMAN_OP_LAST];
738 pixman_combine_64_func_t combine_64[PIXMAN_OP_LAST];
739 pixman_combine_64_func_t combine_64_ca[PIXMAN_OP_LAST];
742 pixman_implementation_t *
743 _pixman_implementation_create (pixman_implementation_t *delegate);
746 _pixman_implementation_combine_32 (pixman_implementation_t * imp,
749 const uint32_t * src,
750 const uint32_t * mask,
753 _pixman_implementation_combine_64 (pixman_implementation_t * imp,
756 const uint64_t * src,
757 const uint64_t * mask,
760 _pixman_implementation_combine_32_ca (pixman_implementation_t * imp,
763 const uint32_t * src,
764 const uint32_t * mask,
767 _pixman_implementation_combine_64_ca (pixman_implementation_t * imp,
770 const uint64_t * src,
771 const uint64_t * mask,
774 _pixman_implementation_composite (pixman_implementation_t * imp,
776 pixman_image_t * src,
777 pixman_image_t * mask,
778 pixman_image_t * dest,
789 _pixman_implementation_blt (pixman_implementation_t * imp,
803 _pixman_implementation_fill (pixman_implementation_t * imp,
813 /* Specific implementations */
814 pixman_implementation_t *
815 _pixman_implementation_create_general (void);
816 pixman_implementation_t *
817 _pixman_implementation_create_fast_path (void);
819 pixman_implementation_t *
820 _pixman_implementation_create_mmx (void);
823 pixman_implementation_t *
824 _pixman_implementation_create_sse2 (void);
827 pixman_implementation_t *
828 _pixman_implementation_create_arm_simd (void);
831 pixman_implementation_t *
832 _pixman_implementation_create_arm_neon (void);
835 pixman_implementation_t *
836 _pixman_implementation_create_vmx (void);
840 _pixman_run_fast_path (const pixman_fast_path_t *paths,
841 pixman_implementation_t *imp,
844 pixman_image_t *mask,
845 pixman_image_t *dest,
855 pixman_implementation_t *
856 _pixman_choose_implementation (void);
858 #endif /* PIXMAN_PRIVATE_H */