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"
15 * Various useful macros
25 /* Integer division that rounds towards -infinity */
26 #define DIV(a,b) ((((a) < 0) == ((b) < 0)) ? (a) / (b) : \
27 ((a) - (b) + 1 - (((b) < 0) << 1)) / (b))
29 /* Modulus that produces the remainder wrt. DIV */
30 #define MOD(a,b) ((a) < 0 ? ((b) - ((-(a) - 1) % (b))) - 1 : (a) % (b))
32 #define CLIP(a,b,c) ((a) < (b) ? (b) : ((a) > (c) ? (c) : (a)))
35 # define MIN(a,b) ((a < b)? a : b)
39 # define MAX(a,b) ((a > b)? a : b)
49 /* Memory allocation helpers */
50 void *pixman_malloc_ab (unsigned int n, unsigned int b);
51 void *pixman_malloc_abc (unsigned int a, unsigned int b, unsigned int c);
52 pixman_bool_t pixman_multiply_overflows_int (unsigned int a, unsigned int b);
53 pixman_bool_t pixman_addition_overflows_int (unsigned int a, unsigned int b);
55 /* Compositing utilities */
57 _pixman_run_fast_path (const pixman_fast_path_t *paths,
58 pixman_implementation_t *imp,
73 _pixman_walk_composite_region (pixman_implementation_t *imp,
75 pixman_image_t * pSrc,
76 pixman_image_t * pMask,
77 pixman_image_t * pDst,
86 pixman_composite_func_t compositeRect);
90 #define return_if_fail(expr) \
95 fprintf(stderr, "In %s: %s failed\n", FUNC, #expr); \
101 #define return_val_if_fail(expr, retval) \
106 fprintf(stderr, "In %s: %s failed\n", FUNC, #expr); \
114 #define return_if_fail(expr) \
122 #define return_val_if_fail(expr, retval) \
134 typedef struct image_common image_common_t;
135 typedef struct source_image source_image_t;
136 typedef struct solid_fill solid_fill_t;
137 typedef struct gradient gradient_t;
138 typedef struct linear_gradient linear_gradient_t;
139 typedef struct horizontal_gradient horizontal_gradient_t;
140 typedef struct vertical_gradient vertical_gradient_t;
141 typedef struct conical_gradient conical_gradient_t;
142 typedef struct radial_gradient radial_gradient_t;
143 typedef struct bits_image bits_image_t;
144 typedef struct circle circle_t;
145 typedef struct point point_t;
147 /* FIXME - the types and structures below should be give proper names
150 typedef void (*fetchProc32)(bits_image_t *pict, int x, int y, int width,
152 typedef uint32_t (*fetchPixelProc32)(bits_image_t *pict, int offset, int line);
153 typedef void (*storeProc32)(pixman_image_t *, uint32_t *bits,
154 const uint32_t *values, int x, int width);
156 typedef void (*fetchProc64)(bits_image_t *pict, int x, int y, int width,
158 typedef uint64_t (*fetchPixelProc64)(bits_image_t *pict, int offset, int line);
159 typedef void (*storeProc64)(pixman_image_t *, uint32_t *bits,
160 const uint64_t *values, int x, int width);
162 typedef void (* fetch_pixels_32_t) (bits_image_t *image, uint32_t *buffer, int n_pixels);
163 typedef void (* fetch_pixels_64_t) (bits_image_t *image, uint64_t *buffer, int n_pixels);
165 void _pixman_bits_image_setup_raw_accessors (bits_image_t *image);
167 void pixman_expand(uint64_t *dst, const uint32_t *src, pixman_format_code_t, int width);
168 void pixman_contract(uint32_t *dst, const uint64_t *src, int width);
170 void _pixman_image_get_scanline_64_generic (pixman_image_t * pict, int x, int y, int width,
171 uint64_t *buffer, uint64_t *mask, uint32_t maskBits);
186 SOURCE_IMAGE_CLASS_UNKNOWN,
187 SOURCE_IMAGE_CLASS_HORIZONTAL,
188 SOURCE_IMAGE_CLASS_VERTICAL,
189 } source_pict_class_t;
191 typedef void (*scanStoreProc)(bits_image_t *img, int x, int y, int width, uint32_t *buffer);
192 typedef void (*scanFetchProc)(pixman_image_t *, int, int, int, uint32_t *,
193 uint32_t *, uint32_t);
196 _pixman_image_classify (pixman_image_t *image,
203 _pixman_image_get_scanline_32 (pixman_image_t *image, int x, int y, int width,
204 uint32_t *buffer, uint32_t *mask, uint32_t mask_bits);
206 /* Even thought the type of buffer is uint32_t *, the function actually expects
207 * a uint64_t *buffer.
210 _pixman_image_get_scanline_64 (pixman_image_t *image, int x, int y, int width,
211 uint32_t *buffer, uint32_t *unused, uint32_t unused2);
214 _pixman_image_store_scanline_32 (bits_image_t *image, int x, int y, int width,
217 _pixman_image_fetch_pixels (bits_image_t *image, uint32_t *buffer, int n_pixels);
219 /* Even thought the type of buffer is uint32_t *, the function actually expects
220 * a uint64_t *buffer.
223 _pixman_image_store_scanline_64 (bits_image_t *image, int x, int y, int width,
227 _pixman_image_allocate (void);
230 _pixman_init_gradient (gradient_t *gradient,
231 const pixman_gradient_stop_t *stops,
234 _pixman_image_reset_clip_region (pixman_image_t *image);
241 typedef source_pict_class_t (* classify_func_t) (pixman_image_t *image,
246 typedef void (* property_changed_func_t) (pixman_image_t *image);
252 pixman_region32_t clip_region;
253 pixman_bool_t have_clip_region; /* FALSE if there is no clip */
254 pixman_bool_t client_clip; /* Whether the source clip was set by a client */
255 pixman_bool_t clip_sources; /* Whether the clip applies when
256 * the image is used as a source
258 pixman_transform_t *transform;
259 pixman_repeat_t repeat;
260 pixman_filter_t filter;
261 pixman_fixed_t *filter_params;
263 bits_image_t *alpha_map;
264 point_t alpha_origin;
265 pixman_bool_t component_alpha;
266 pixman_read_memory_func_t read_func;
267 pixman_write_memory_func_t write_func;
268 classify_func_t classify;
269 property_changed_func_t property_changed;
270 scanFetchProc get_scanline_32;
271 scanFetchProc get_scanline_64;
273 pixman_image_destroy_func_t destroy_func;
279 image_common_t common;
280 source_pict_class_t class;
285 source_image_t common;
286 uint32_t color; /* FIXME: shouldn't this be a pixman_color_t? */
291 source_image_t common;
293 pixman_gradient_stop_t * stops;
295 uint32_t * color_table;
296 int color_table_size;
299 struct linear_gradient
302 pixman_point_fixed_t p1;
303 pixman_point_fixed_t p2;
310 pixman_fixed_t radius;
313 struct radial_gradient
325 struct conical_gradient
328 pixman_point_fixed_t center;
329 pixman_fixed_t angle;
334 image_common_t common;
335 pixman_format_code_t format;
336 const pixman_indexed_t *indexed;
341 int rowstride; /* in number of uint32_t's */
343 /* Fetch raw pixels, with no regard for transformations, alpha map etc. */
344 fetch_pixels_32_t fetch_pixels_raw_32;
345 fetch_pixels_64_t fetch_pixels_raw_64;
347 /* Fetch raw scanlines, with no regard for transformations, alpha maps etc. */
348 fetchProc32 fetch_scanline_raw_32;
349 fetchProc64 fetch_scanline_raw_64;
351 /* Store scanlines with no regard for alpha maps */
352 storeProc32 store_scanline_raw_32;
353 storeProc64 store_scanline_raw_64;
355 /* Store a scanline, taking alpha maps into account */
356 scanStoreProc store_scanline_32;
357 scanStoreProc store_scanline_64;
359 /* Used for indirect access to the bits */
360 pixman_read_memory_func_t read_func;
361 pixman_write_memory_func_t write_func;
367 image_common_t common;
369 source_image_t source;
371 linear_gradient_t linear;
372 conical_gradient_t conical;
373 radial_gradient_t radial;
390 pixman_gradient_stop_t *stops;
395 } pixman_gradient_walker_t;
398 _pixman_gradient_walker_init (pixman_gradient_walker_t *walker,
399 gradient_t *gradient,
400 unsigned int spread);
403 _pixman_gradient_walker_reset (pixman_gradient_walker_t *walker,
404 pixman_fixed_32_32_t pos);
407 _pixman_gradient_walker_pixel (pixman_gradient_walker_t *walker,
408 pixman_fixed_32_32_t x);
412 #ifdef WORDS_BIGENDIAN
413 #define Fetch24(img, a) ((unsigned long) (a) & 1 ? \
414 ((READ(img, a) << 16) | READ(img, (uint16_t *) ((a)+1))) : \
415 ((READ(img, (uint16_t *) (a)) << 8) | READ(img, (a)+2)))
416 #define Store24(img,a,v) ((unsigned long) (a) & 1 ? \
417 (WRITE(img, a, (uint8_t) ((v) >> 16)), \
418 WRITE(img, (uint16_t *) ((a)+1), (uint16_t) (v))) : \
419 (WRITE(img, (uint16_t *) (a), (uint16_t) ((v) >> 8)), \
420 WRITE(img, (a)+2, (uint8_t) (v))))
422 #define Fetch24(img,a) ((unsigned long) (a) & 1 ? \
423 (READ(img, a) | (READ(img, (uint16_t *) ((a)+1)) << 8)) : \
424 (READ(img, (uint16_t *) (a)) | (READ(img, (a)+2) << 16)))
425 #define Store24(img,a,v) ((unsigned long) (a) & 1 ? \
426 (WRITE(img, a, (uint8_t) (v)), \
427 WRITE(img, (uint16_t *) ((a)+1), (uint16_t) ((v) >> 8))) : \
428 (WRITE(img, (uint16_t *) (a), (uint16_t) (v)), \
429 WRITE(img, (a)+2, (uint8_t) ((v) >> 16))))
432 #define FbIntMult(a,b,t) ( (t) = (a) * (b) + 0x80, ( ( ( (t)>>8 ) + (t) )>>8 ) )
433 #define FbIntDiv(a,b) (((uint16_t) (a) * 255) / (b))
435 #define FbGet8(v,i) ((uint16_t) (uint8_t) ((v) >> i))
438 #define cvt8888to0565(s) ((((s) >> 3) & 0x001f) | \
439 (((s) >> 5) & 0x07e0) | \
440 (((s) >> 8) & 0xf800))
441 #define cvt0565to0888(s) (((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7)) | \
442 ((((s) << 5) & 0xfc00) | (((s) >> 1) & 0x300)) | \
443 ((((s) << 8) & 0xf80000) | (((s) << 3) & 0x70000)))
446 * There are two ways of handling alpha -- either as a single unified value or
447 * a separate value for each component, hence each macro must have two
448 * versions. The unified alpha version has a 'U' at the end of the name,
449 * the component version has a 'C'. Similarly, functions which deal with
450 * this difference will have two versions using the same convention.
453 #define FbOverU(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),(a),(t)) + FbGet8(x,i), \
454 (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
456 #define FbOverC(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),FbGet8(a,i),(t)) + FbGet8(x,i), \
457 (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
459 #define FbInU(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),(a),(t)) << (i))
461 #define FbInC(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),FbGet8(a,i),(t)) << (i))
463 #define FbAdd(x,y,i,t) ((t) = FbGet8(x,i) + FbGet8(y,i), \
464 (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
466 #define div_255(x) (((x) + 0x80 + (((x) + 0x80) >> 8)) >> 8)
467 #define div_65535(x) (((x) + 0x8000 + (((x) + 0x8000) >> 16)) >> 16)
469 #ifdef PIXMAN_FB_ACCESSORS
471 #define ACCESS(sym) sym##_accessors
473 #define READ(img, ptr) \
474 ((img)->common.read_func ((ptr), sizeof(*(ptr))))
475 #define WRITE(img, ptr,val) \
476 ((img)->common.write_func ((ptr), (val), sizeof (*(ptr))))
478 #define MEMCPY_WRAPPED(img, dst, src, size) \
481 uint8_t *_dst = (uint8_t*)(dst), *_src = (uint8_t*)(src); \
482 for(_i = 0; _i < size; _i++) { \
483 WRITE((img), _dst +_i, READ((img), _src + _i)); \
487 #define MEMSET_WRAPPED(img, dst, val, size) \
490 uint8_t *_dst = (uint8_t*)(dst); \
491 for(_i = 0; _i < (size_t) size; _i++) { \
492 WRITE((img), _dst +_i, (val)); \
498 #define ACCESS(sym) sym
500 #define READ(img, ptr) (*(ptr))
501 #define WRITE(img, ptr, val) (*(ptr) = (val))
502 #define MEMCPY_WRAPPED(img, dst, src, size) \
503 memcpy(dst, src, size)
504 #define MEMSET_WRAPPED(img, dst, val, size) \
505 memset(dst, val, size)
509 #define fbComposeGetStart(pict,x,y,type,out_stride,line,mul) do { \
510 uint32_t *__bits__; \
514 __bits__ = pict->bits.bits; \
515 __stride__ = pict->bits.rowstride; \
516 __bpp__ = PIXMAN_FORMAT_BPP(pict->bits.format); \
517 (out_stride) = __stride__ * (int) sizeof (uint32_t) / (int) sizeof (type); \
518 (line) = ((type *) __bits__) + \
519 (out_stride) * (y) + (mul) * (x); \
523 #define PIXMAN_FORMAT_16BPC(f) (PIXMAN_FORMAT_A(f) > 8 || \
524 PIXMAN_FORMAT_R(f) > 8 || \
525 PIXMAN_FORMAT_G(f) > 8 || \
526 PIXMAN_FORMAT_B(f) > 8)
531 #define MAX_ALPHA(n) ((1 << (n)) - 1)
532 #define N_Y_FRAC(n) ((n) == 1 ? 1 : (1 << ((n)/2)) - 1)
533 #define N_X_FRAC(n) ((n) == 1 ? 1 : (1 << ((n)/2)) + 1)
535 #define STEP_Y_SMALL(n) (pixman_fixed_1 / N_Y_FRAC(n))
536 #define STEP_Y_BIG(n) (pixman_fixed_1 - (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
538 #define Y_FRAC_FIRST(n) (STEP_Y_SMALL(n) / 2)
539 #define Y_FRAC_LAST(n) (Y_FRAC_FIRST(n) + (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
541 #define STEP_X_SMALL(n) (pixman_fixed_1 / N_X_FRAC(n))
542 #define STEP_X_BIG(n) (pixman_fixed_1 - (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
544 #define X_FRAC_FIRST(n) (STEP_X_SMALL(n) / 2)
545 #define X_FRAC_LAST(n) (X_FRAC_FIRST(n) + (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
547 #define RenderSamplesX(x,n) ((n) == 1 ? 0 : (pixman_fixed_frac (x) + X_FRAC_FIRST(n)) / STEP_X_SMALL(n))
550 * Step across a small sample grid gap
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_bool_t pixman_region32_copy_from_region16 (pixman_region32_t *dst,
571 pixman_region16_t *src);
572 pixman_bool_t pixman_region16_copy_from_region32 (pixman_region16_t *dst,
573 pixman_region32_t *src);
579 typedef struct pixman_implementation_t pixman_implementation_t;
581 typedef void (* pixman_combine_32_func_t) (pixman_implementation_t * imp,
584 const uint32_t * src,
585 const uint32_t * mask,
588 typedef void (* pixman_combine_64_func_t) (pixman_implementation_t * imp,
591 const uint64_t * src,
592 const uint64_t * mask,
595 typedef void (* pixman_composite_func_t) (pixman_implementation_t * imp,
597 pixman_image_t * src,
598 pixman_image_t * mask,
599 pixman_image_t * dest,
608 typedef pixman_bool_t (* pixman_blt_func_t) (pixman_implementation_t * imp,
621 typedef pixman_bool_t (* pixman_fill_func_t) (pixman_implementation_t *imp,
631 void _pixman_setup_combiner_functions_32 (pixman_implementation_t *imp);
632 void _pixman_setup_combiner_functions_64 (pixman_implementation_t *imp);
634 /* These "formats" both have depth 0, so they
635 * will never clash with any real ones
637 #define PIXMAN_null PIXMAN_FORMAT(0,0,0,0,0,0)
638 #define PIXMAN_solid PIXMAN_FORMAT(0,1,0,0,0,0)
640 #define NEED_COMPONENT_ALPHA (1 << 0)
641 #define NEED_PIXBUF (1 << 1)
642 #define NEED_SOLID_MASK (1 << 2)
647 pixman_format_code_t src_format;
648 pixman_format_code_t mask_format;
649 pixman_format_code_t dest_format;
650 pixman_composite_func_t func;
652 } pixman_fast_path_t;
654 struct pixman_implementation_t
656 pixman_implementation_t * toplevel;
657 pixman_implementation_t * delegate;
659 pixman_composite_func_t composite;
660 pixman_blt_func_t blt;
661 pixman_fill_func_t fill;
663 pixman_combine_32_func_t combine_32[PIXMAN_OP_LAST];
664 pixman_combine_32_func_t combine_32_ca[PIXMAN_OP_LAST];
665 pixman_combine_64_func_t combine_64[PIXMAN_OP_LAST];
666 pixman_combine_64_func_t combine_64_ca[PIXMAN_OP_LAST];
669 pixman_implementation_t *
670 _pixman_implementation_create (pixman_implementation_t *delegate);
673 _pixman_implementation_combine_32 (pixman_implementation_t * imp,
676 const uint32_t * src,
677 const uint32_t * mask,
680 _pixman_implementation_combine_64 (pixman_implementation_t * imp,
683 const uint64_t * src,
684 const uint64_t * mask,
687 _pixman_implementation_combine_32_ca (pixman_implementation_t * imp,
690 const uint32_t * src,
691 const uint32_t * mask,
694 _pixman_implementation_combine_64_ca (pixman_implementation_t * imp,
697 const uint64_t * src,
698 const uint64_t * mask,
701 _pixman_implementation_composite (pixman_implementation_t * imp,
703 pixman_image_t * src,
704 pixman_image_t * mask,
705 pixman_image_t * dest,
716 _pixman_implementation_blt (pixman_implementation_t * imp,
730 _pixman_implementation_fill (pixman_implementation_t * imp,
740 /* Specific implementations */
741 pixman_implementation_t *
742 _pixman_implementation_create_general (void);
743 pixman_implementation_t *
744 _pixman_implementation_create_fast_path (void);
746 pixman_implementation_t *
747 _pixman_implementation_create_mmx (void);
750 pixman_implementation_t *
751 _pixman_implementation_create_sse2 (void);
754 pixman_implementation_t *
755 _pixman_implementation_create_arm_simd (void);
758 pixman_implementation_t *
759 _pixman_implementation_create_arm_neon (void);
762 pixman_implementation_t *
763 _pixman_implementation_create_vmx (void);
766 pixman_implementation_t *
767 _pixman_choose_implementation (void);
776 static inline uint64_t
777 oil_profile_stamp_rdtsc (void)
780 __asm__ __volatile__("rdtsc\n" : "=A" (ts));
783 #define OIL_STAMP oil_profile_stamp_rdtsc
785 typedef struct pixman_timer_t pixman_timer_t;
787 struct pixman_timer_t
793 pixman_timer_t *next;
796 extern int timer_defined;
797 void pixman_timer_register (pixman_timer_t *timer);
799 #define TIMER_BEGIN(tname) \
801 static pixman_timer_t timer##tname; \
802 uint64_t begin##tname; \
804 if (!timer##tname.initialized) \
806 timer##tname.initialized = 1; \
807 timer##tname.name = #tname; \
808 pixman_timer_register (&timer##tname); \
811 timer##tname.n_times++; \
812 begin##tname = OIL_STAMP();
814 #define TIMER_END(tname) \
815 timer##tname.total += OIL_STAMP() - begin##tname; \
818 #endif /* PIXMAN_TIMERS */
820 #endif /* PIXMAN_PRIVATE_H */