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 #define FB_MASK (0x1f)
27 #define FB_ALLONES ((uint32_t) -1)
29 /* Memory allocation helpers */
30 void *pixman_malloc_ab (unsigned int n, unsigned int b);
31 void *pixman_malloc_abc (unsigned int a, unsigned int b, unsigned int c);
32 pixman_bool_t pixman_multiply_overflows_int (unsigned int a, unsigned int b);
33 pixman_bool_t pixman_addition_overflows_int (unsigned int a, unsigned int b);
37 #define return_if_fail(expr) \
42 fprintf(stderr, "In %s: %s failed\n", FUNC, #expr); \
48 #define return_val_if_fail(expr, retval) \
53 fprintf(stderr, "In %s: %s failed\n", FUNC, #expr); \
61 #define return_if_fail(expr) \
69 #define return_val_if_fail(expr, retval) \
79 typedef struct image_common image_common_t;
80 typedef struct source_image source_image_t;
81 typedef struct solid_fill solid_fill_t;
82 typedef struct gradient gradient_t;
83 typedef struct linear_gradient linear_gradient_t;
84 typedef struct horizontal_gradient horizontal_gradient_t;
85 typedef struct vertical_gradient vertical_gradient_t;
86 typedef struct conical_gradient conical_gradient_t;
87 typedef struct radial_gradient radial_gradient_t;
88 typedef struct bits_image bits_image_t;
89 typedef struct circle circle_t;
90 typedef struct point point_t;
92 /* FIXME - the types and structures below should be give proper names
95 typedef void (*fetchProc32)(bits_image_t *pict, int x, int y, int width,
97 typedef uint32_t (*fetchPixelProc32)(bits_image_t *pict, int offset, int line);
98 typedef void (*storeProc32)(pixman_image_t *, uint32_t *bits,
99 const uint32_t *values, int x, int width,
100 const pixman_indexed_t *);
102 typedef void (*fetchProc64)(bits_image_t *pict, int x, int y, int width,
104 typedef uint64_t (*fetchPixelProc64)(bits_image_t *pict, int offset, int line);
105 typedef void (*storeProc64)(pixman_image_t *, uint32_t *bits,
106 const uint64_t *values, int x, int width,
107 const pixman_indexed_t *);
109 typedef void (* fetch_pixels_32_t) (bits_image_t *image, uint32_t *buffer, int n_pixels);
110 typedef void (* fetch_pixels_64_t) (bits_image_t *image, uint64_t *buffer, int n_pixels);
112 fetchProc32 pixman_fetchProcForPicture32 (bits_image_t *);
113 fetch_pixels_32_t pixman_fetchPixelProcForPicture32 (bits_image_t *);
114 storeProc32 pixman_storeProcForPicture32 (bits_image_t *);
115 fetchProc32 pixman_fetchProcForPicture32_accessors (bits_image_t *);
116 fetch_pixels_32_t pixman_fetchPixelProcForPicture32_accessors (bits_image_t *);
117 storeProc32 pixman_storeProcForPicture32_accessors (bits_image_t *);
119 fetchProc64 pixman_fetchProcForPicture64 (bits_image_t *);
120 fetch_pixels_64_t pixman_fetchPixelProcForPicture64 (bits_image_t *);
121 storeProc64 pixman_storeProcForPicture64 (bits_image_t *);
122 fetchProc64 pixman_fetchProcForPicture64_accessors (bits_image_t *);
123 fetch_pixels_64_t pixman_fetchPixelProcForPicture64_accessors (bits_image_t *);
124 storeProc64 pixman_storeProcForPicture64_accessors (bits_image_t *);
126 void pixman_expand(uint64_t *dst, const uint32_t *src, pixman_format_code_t, int width);
127 void pixman_contract(uint32_t *dst, const uint64_t *src, int width);
129 void _pixman_image_get_scanline_64_generic (pixman_image_t * pict, int x, int y, int width,
130 uint64_t *buffer, uint64_t *mask, uint32_t maskBits);
145 SOURCE_IMAGE_CLASS_UNKNOWN,
146 SOURCE_IMAGE_CLASS_HORIZONTAL,
147 SOURCE_IMAGE_CLASS_VERTICAL,
148 } source_pict_class_t;
150 typedef void (*scanStoreProc)(bits_image_t *img, int x, int y, int width, uint32_t *buffer);
151 typedef void (*scanFetchProc)(pixman_image_t *, int, int, int, uint32_t *,
152 uint32_t *, uint32_t);
154 source_pict_class_t _pixman_image_classify (pixman_image_t *image,
161 _pixman_image_get_scanline_32 (pixman_image_t *image, int x, int y, int width,
162 uint32_t *buffer, uint32_t *mask, uint32_t mask_bits);
164 /* Even thought the type of buffer is uint32_t *, the function actually expects
165 * a uint64_t *buffer.
168 _pixman_image_get_scanline_64 (pixman_image_t *image, int x, int y, int width,
169 uint32_t *buffer, uint32_t *unused, uint32_t unused2);
172 _pixman_image_store_scanline_32 (bits_image_t *image, int x, int y, int width,
175 _pixman_image_fetch_pixels (bits_image_t *image, uint32_t *buffer, int n_pixels);
177 /* Even thought the type of buffer is uint32_t *, the function actually expects
178 * a uint64_t *buffer.
181 _pixman_image_store_scanline_64 (bits_image_t *image, int x, int y, int width,
185 _pixman_image_allocate (void);
188 _pixman_init_gradient (gradient_t *gradient,
189 const pixman_gradient_stop_t *stops,
192 _pixman_image_reset_clip_region (pixman_image_t *image);
199 typedef source_pict_class_t (* classify_func_t) (pixman_image_t *image,
204 typedef void (* property_changed_func_t) (pixman_image_t *image);
210 pixman_region32_t clip_region;
211 pixman_bool_t have_clip_region; /* FALSE if there is no clip */
212 pixman_bool_t client_clip; /* Whether the source clip was set by a client */
213 pixman_bool_t clip_sources; /* Whether the clip applies when
214 * the image is used as a source
216 pixman_transform_t *transform;
217 pixman_repeat_t repeat;
218 pixman_filter_t filter;
219 pixman_fixed_t *filter_params;
221 bits_image_t *alpha_map;
222 point_t alpha_origin;
223 pixman_bool_t component_alpha;
224 pixman_read_memory_func_t read_func;
225 pixman_write_memory_func_t write_func;
226 classify_func_t classify;
227 property_changed_func_t property_changed;
228 scanFetchProc get_scanline_32;
229 scanFetchProc get_scanline_64;
231 pixman_image_destroy_func_t destroy_func;
237 image_common_t common;
238 source_pict_class_t class;
243 source_image_t common;
244 uint32_t color; /* FIXME: shouldn't this be a pixman_color_t? */
249 source_image_t common;
251 pixman_gradient_stop_t * stops;
253 uint32_t * color_table;
254 int color_table_size;
257 struct linear_gradient
260 pixman_point_fixed_t p1;
261 pixman_point_fixed_t p2;
268 pixman_fixed_t radius;
271 struct radial_gradient
283 struct conical_gradient
286 pixman_point_fixed_t center;
287 pixman_fixed_t angle;
292 image_common_t common;
293 pixman_format_code_t format;
294 const pixman_indexed_t *indexed;
299 int rowstride; /* in number of uint32_t's */
301 /* Fetch raw pixels, with no regard for transformations, alpha map etc. */
302 fetch_pixels_32_t fetch_pixels_raw_32;
303 fetch_pixels_64_t fetch_pixels_raw_64;
305 /* Fetch raw scanlines, with no regard for transformations, alpha maps etc. */
306 fetchProc32 fetch_scanline_raw_32;
307 fetchProc64 fetch_scanline_raw_64;
309 /* Store scanlines with no regard for alpha maps */
310 storeProc32 store_scanline_raw_32;
311 storeProc64 store_scanline_raw_64;
313 /* Store a scanline, taking alpha maps into account */
314 scanStoreProc store_scanline_32;
315 scanStoreProc store_scanline_64;
317 /* Used for indirect access to the bits */
318 pixman_read_memory_func_t read_func;
319 pixman_write_memory_func_t write_func;
321 void * orig_data; /* Stores pointer to original
322 * data, when the image is
330 image_common_t common;
332 source_image_t source;
334 linear_gradient_t linear;
335 conical_gradient_t conical;
336 radial_gradient_t radial;
353 pixman_gradient_stop_t *stops;
358 } pixman_gradient_walker_t;
361 _pixman_gradient_walker_init (pixman_gradient_walker_t *walker,
362 gradient_t *gradient,
363 unsigned int spread);
366 _pixman_gradient_walker_reset (pixman_gradient_walker_t *walker,
367 pixman_fixed_32_32_t pos);
370 _pixman_gradient_walker_pixel (pixman_gradient_walker_t *walker,
371 pixman_fixed_32_32_t x);
375 #ifdef WORDS_BIGENDIAN
376 #define Fetch24(img, a) ((unsigned long) (a) & 1 ? \
377 ((READ(img, a) << 16) | READ(img, (uint16_t *) ((a)+1))) : \
378 ((READ(img, (uint16_t *) (a)) << 8) | READ(img, (a)+2)))
379 #define Store24(img,a,v) ((unsigned long) (a) & 1 ? \
380 (WRITE(img, a, (uint8_t) ((v) >> 16)), \
381 WRITE(img, (uint16_t *) ((a)+1), (uint16_t) (v))) : \
382 (WRITE(img, (uint16_t *) (a), (uint16_t) ((v) >> 8)), \
383 WRITE(img, (a)+2, (uint8_t) (v))))
385 #define Fetch24(img,a) ((unsigned long) (a) & 1 ? \
386 (READ(img, a) | (READ(img, (uint16_t *) ((a)+1)) << 8)) : \
387 (READ(img, (uint16_t *) (a)) | (READ(img, (a)+2) << 16)))
388 #define Store24(img,a,v) ((unsigned long) (a) & 1 ? \
389 (WRITE(img, a, (uint8_t) (v)), \
390 WRITE(img, (uint16_t *) ((a)+1), (uint16_t) ((v) >> 8))) : \
391 (WRITE(img, (uint16_t *) (a), (uint16_t) (v)), \
392 WRITE(img, (a)+2, (uint8_t) ((v) >> 16))))
395 #define CvtR8G8B8toY15(s) (((((s) >> 16) & 0xff) * 153 + \
396 (((s) >> 8) & 0xff) * 301 + \
397 (((s) ) & 0xff) * 58) >> 2)
398 #define miCvtR8G8B8to15(s) ((((s) >> 3) & 0x001f) | \
399 (((s) >> 6) & 0x03e0) | \
400 (((s) >> 9) & 0x7c00))
401 #define miIndexToEnt15(mif,rgb15) ((mif)->ent[rgb15])
402 #define miIndexToEnt24(mif,rgb24) miIndexToEnt15(mif,miCvtR8G8B8to15(rgb24))
404 #define miIndexToEntY24(mif,rgb24) ((mif)->ent[CvtR8G8B8toY15(rgb24)])
407 #define FbIntMult(a,b,t) ( (t) = (a) * (b) + 0x80, ( ( ( (t)>>8 ) + (t) )>>8 ) )
408 #define FbIntDiv(a,b) (((uint16_t) (a) * 255) / (b))
410 #define FbGet8(v,i) ((uint16_t) (uint8_t) ((v) >> i))
413 #define cvt8888to0565(s) ((((s) >> 3) & 0x001f) | \
414 (((s) >> 5) & 0x07e0) | \
415 (((s) >> 8) & 0xf800))
416 #define cvt0565to0888(s) (((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7)) | \
417 ((((s) << 5) & 0xfc00) | (((s) >> 1) & 0x300)) | \
418 ((((s) << 8) & 0xf80000) | (((s) << 3) & 0x70000)))
421 * There are two ways of handling alpha -- either as a single unified value or
422 * a separate value for each component, hence each macro must have two
423 * versions. The unified alpha version has a 'U' at the end of the name,
424 * the component version has a 'C'. Similarly, functions which deal with
425 * this difference will have two versions using the same convention.
428 #define FbOverU(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),(a),(t)) + FbGet8(x,i), \
429 (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
431 #define FbOverC(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),FbGet8(a,i),(t)) + FbGet8(x,i), \
432 (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
434 #define FbInU(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),(a),(t)) << (i))
436 #define FbInC(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),FbGet8(a,i),(t)) << (i))
438 #define FbAdd(x,y,i,t) ((t) = FbGet8(x,i) + FbGet8(y,i), \
439 (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
441 #define div_255(x) (((x) + 0x80 + (((x) + 0x80) >> 8)) >> 8)
442 #define div_65535(x) (((x) + 0x8000 + (((x) + 0x8000) >> 16)) >> 16)
444 #define MOD(a,b) ((a) < 0 ? ((b) - ((-(a) - 1) % (b))) - 1 : (a) % (b))
446 /* Divides two fixed-point numbers and returns an integer */
447 #define DIV(a,b) ((((a) < 0) == ((b) < 0)) ? (a) / (b) : \
448 ((a) - (b) + 1 - (((b) < 0) << 1)) / (b))
450 #define CLIP(a,b,c) ((a) < (b) ? (b) : ((a) > (c) ? (c) : (a)))
453 # define MIN(a,b) ((a < b)? a : b)
457 # define MAX(a,b) ((a > b)? a : b)
460 /* FIXME: the (void)__read_func hides lots of warnings (which is what they
461 * are supposed to do), but some of them are real. For example the one
462 * where Fetch4 doesn't have a READ
465 #ifdef PIXMAN_FB_ACCESSORS
467 #define ACCESS(sym) sym##_accessors
469 #define READ(img, ptr) \
470 ((img)->common.read_func ((ptr), sizeof(*(ptr))))
471 #define WRITE(img, ptr,val) \
472 ((img)->common.write_func ((ptr), (val), sizeof (*(ptr))))
474 #define MEMCPY_WRAPPED(img, dst, src, size) \
477 uint8_t *_dst = (uint8_t*)(dst), *_src = (uint8_t*)(src); \
478 for(_i = 0; _i < size; _i++) { \
479 WRITE((img), _dst +_i, READ((img), _src + _i)); \
483 #define MEMSET_WRAPPED(img, dst, val, size) \
486 uint8_t *_dst = (uint8_t*)(dst); \
487 for(_i = 0; _i < (size_t) size; _i++) { \
488 WRITE((img), _dst +_i, (val)); \
494 #define ACCESS(sym) sym
496 #define READ(img, ptr) (*(ptr))
497 #define WRITE(img, ptr, val) (*(ptr) = (val))
498 #define MEMCPY_WRAPPED(img, dst, src, size) \
499 memcpy(dst, src, size)
500 #define MEMSET_WRAPPED(img, dst, val, size) \
501 memset(dst, val, size)
505 #define fbComposeGetStart(pict,x,y,type,out_stride,line,mul) do { \
506 uint32_t *__bits__; \
510 __bits__ = pict->bits.bits; \
511 __stride__ = pict->bits.rowstride; \
512 __bpp__ = PIXMAN_FORMAT_BPP(pict->bits.format); \
513 (out_stride) = __stride__ * (int) sizeof (uint32_t) / (int) sizeof (type); \
514 (line) = ((type *) __bits__) + \
515 (out_stride) * (y) + (mul) * (x); \
519 #define PIXMAN_FORMAT_16BPC(f) (PIXMAN_FORMAT_A(f) > 8 || \
520 PIXMAN_FORMAT_R(f) > 8 || \
521 PIXMAN_FORMAT_G(f) > 8 || \
522 PIXMAN_FORMAT_B(f) > 8)
527 #define MAX_ALPHA(n) ((1 << (n)) - 1)
528 #define N_Y_FRAC(n) ((n) == 1 ? 1 : (1 << ((n)/2)) - 1)
529 #define N_X_FRAC(n) ((n) == 1 ? 1 : (1 << ((n)/2)) + 1)
531 #define STEP_Y_SMALL(n) (pixman_fixed_1 / N_Y_FRAC(n))
532 #define STEP_Y_BIG(n) (pixman_fixed_1 - (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
534 #define Y_FRAC_FIRST(n) (STEP_Y_SMALL(n) / 2)
535 #define Y_FRAC_LAST(n) (Y_FRAC_FIRST(n) + (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
537 #define STEP_X_SMALL(n) (pixman_fixed_1 / N_X_FRAC(n))
538 #define STEP_X_BIG(n) (pixman_fixed_1 - (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
540 #define X_FRAC_FIRST(n) (STEP_X_SMALL(n) / 2)
541 #define X_FRAC_LAST(n) (X_FRAC_FIRST(n) + (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
543 #define RenderSamplesX(x,n) ((n) == 1 ? 0 : (pixman_fixed_frac (x) + X_FRAC_FIRST(n)) / STEP_X_SMALL(n))
546 * Step across a small sample grid gap
548 #define RenderEdgeStepSmall(edge) { \
549 edge->x += edge->stepx_small; \
550 edge->e += edge->dx_small; \
553 edge->e -= edge->dy; \
554 edge->x += edge->signdx; \
559 * Step across a large sample grid gap
561 #define RenderEdgeStepBig(edge) { \
562 edge->x += edge->stepx_big; \
563 edge->e += edge->dx_big; \
566 edge->e -= edge->dy; \
567 edge->x += edge->signdx; \
572 pixman_rasterize_edges_accessors (pixman_image_t *image,
579 pixman_image_is_opaque(pixman_image_t *image);
582 pixman_image_is_solid (pixman_image_t *image);
585 pixman_image_get_solid (pixman_image_t *image,
586 pixman_format_code_t format);
589 pixman_compute_composite_region32 (pixman_region32_t * pRegion,
590 pixman_image_t * pSrc,
591 pixman_image_t * pMask,
592 pixman_image_t * pDst,
603 pixman_bool_t pixman_region32_copy_from_region16 (pixman_region32_t *dst,
604 pixman_region16_t *src);
605 pixman_bool_t pixman_region16_copy_from_region32 (pixman_region16_t *dst,
606 pixman_region32_t *src);
611 static inline uint64_t
612 oil_profile_stamp_rdtsc (void)
615 __asm__ __volatile__("rdtsc\n" : "=A" (ts));
618 #define OIL_STAMP oil_profile_stamp_rdtsc
620 typedef struct pixman_timer_t pixman_timer_t;
622 struct pixman_timer_t
628 pixman_timer_t *next;
631 extern int timer_defined;
632 void pixman_timer_register (pixman_timer_t *timer);
634 #define TIMER_BEGIN(tname) \
636 static pixman_timer_t timer##tname; \
637 uint64_t begin##tname; \
639 if (!timer##tname.initialized) \
641 timer##tname.initialized = 1; \
642 timer##tname.name = #tname; \
643 pixman_timer_register (&timer##tname); \
646 timer##tname.n_times++; \
647 begin##tname = OIL_STAMP();
649 #define TIMER_END(tname) \
650 timer##tname.total += OIL_STAMP() - begin##tname; \
653 #endif /* PIXMAN_TIMERS */
655 typedef struct pixman_implementation_t pixman_implementation_t;
657 typedef void (* pixman_combine_32_func_t) (pixman_implementation_t * imp,
660 const uint32_t * src,
661 const uint32_t * mask,
664 typedef void (* pixman_combine_64_func_t) (pixman_implementation_t * imp,
667 const uint64_t * src,
668 const uint64_t * mask,
671 typedef void (* pixman_composite_func_t) (pixman_implementation_t * imp,
673 pixman_image_t * src,
674 pixman_image_t * mask,
675 pixman_image_t * dest,
684 typedef pixman_bool_t (* pixman_blt_func_t) (pixman_implementation_t * imp,
697 typedef pixman_bool_t (* pixman_fill_func_t) (pixman_implementation_t *imp,
708 _pixman_walk_composite_region (pixman_implementation_t *imp,
710 pixman_image_t * pSrc,
711 pixman_image_t * pMask,
712 pixman_image_t * pDst,
721 pixman_composite_func_t compositeRect);
723 void _pixman_setup_combiner_functions_32 (pixman_implementation_t *imp);
724 void _pixman_setup_combiner_functions_64 (pixman_implementation_t *imp);
726 /* These "formats" both have depth 0, so they
727 * will never clash with any real ones
729 #define PIXMAN_null PIXMAN_FORMAT(0,0,0,0,0,0)
730 #define PIXMAN_solid PIXMAN_FORMAT(0,1,0,0,0,0)
732 #define NEED_COMPONENT_ALPHA (1 << 0)
733 #define NEED_PIXBUF (1 << 1)
734 #define NEED_SOLID_MASK (1 << 2)
739 pixman_format_code_t src_format;
740 pixman_format_code_t mask_format;
741 pixman_format_code_t dest_format;
742 pixman_composite_func_t func;
744 } pixman_fast_path_t;
746 struct pixman_implementation_t
748 pixman_implementation_t * toplevel;
749 pixman_implementation_t * delegate;
751 pixman_composite_func_t composite;
752 pixman_blt_func_t blt;
753 pixman_fill_func_t fill;
755 pixman_combine_32_func_t combine_32[PIXMAN_OP_LAST];
756 pixman_combine_32_func_t combine_32_ca[PIXMAN_OP_LAST];
757 pixman_combine_64_func_t combine_64[PIXMAN_OP_LAST];
758 pixman_combine_64_func_t combine_64_ca[PIXMAN_OP_LAST];
761 pixman_implementation_t *
762 _pixman_implementation_create (pixman_implementation_t *delegate);
765 _pixman_implementation_combine_32 (pixman_implementation_t * imp,
768 const uint32_t * src,
769 const uint32_t * mask,
772 _pixman_implementation_combine_64 (pixman_implementation_t * imp,
775 const uint64_t * src,
776 const uint64_t * mask,
779 _pixman_implementation_combine_32_ca (pixman_implementation_t * imp,
782 const uint32_t * src,
783 const uint32_t * mask,
786 _pixman_implementation_combine_64_ca (pixman_implementation_t * imp,
789 const uint64_t * src,
790 const uint64_t * mask,
793 _pixman_implementation_composite (pixman_implementation_t * imp,
795 pixman_image_t * src,
796 pixman_image_t * mask,
797 pixman_image_t * dest,
808 _pixman_implementation_blt (pixman_implementation_t * imp,
822 _pixman_implementation_fill (pixman_implementation_t * imp,
832 /* Specific implementations */
833 pixman_implementation_t *
834 _pixman_implementation_create_general (void);
835 pixman_implementation_t *
836 _pixman_implementation_create_fast_path (void);
838 pixman_implementation_t *
839 _pixman_implementation_create_mmx (void);
842 pixman_implementation_t *
843 _pixman_implementation_create_sse2 (void);
846 pixman_implementation_t *
847 _pixman_implementation_create_arm_simd (void);
850 pixman_implementation_t *
851 _pixman_implementation_create_arm_neon (void);
854 pixman_implementation_t *
855 _pixman_implementation_create_vmx (void);
859 _pixman_run_fast_path (const pixman_fast_path_t *paths,
860 pixman_implementation_t *imp,
863 pixman_image_t *mask,
864 pixman_image_t *dest,
874 pixman_implementation_t *
875 _pixman_choose_implementation (void);
877 #endif /* PIXMAN_PRIVATE_H */