Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #ifndef PIXMAN_PRIVATE_H
  3. #define PIXMAN_PRIVATE_H
  4.  
  5. #define PIXMAN_DISABLE_DEPRECATED
  6. #define PIXMAN_USE_INTERNAL_API
  7.  
  8. #include "pixman.h"
  9. #include <time.h>
  10. #include <assert.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. #include "pixman-compiler.h"
  15.  
  16. /*
  17.  * Images
  18.  */
  19. typedef struct image_common image_common_t;
  20. typedef struct source_image source_image_t;
  21. typedef struct solid_fill solid_fill_t;
  22. typedef struct gradient gradient_t;
  23. typedef struct linear_gradient linear_gradient_t;
  24. typedef struct horizontal_gradient horizontal_gradient_t;
  25. typedef struct vertical_gradient vertical_gradient_t;
  26. typedef struct conical_gradient conical_gradient_t;
  27. typedef struct radial_gradient radial_gradient_t;
  28. typedef struct bits_image bits_image_t;
  29. typedef struct circle circle_t;
  30.  
  31. typedef void (*fetch_scanline_t) (pixman_image_t *image,
  32.                                   int             x,
  33.                                   int             y,
  34.                                   int             width,
  35.                                   uint32_t       *buffer,
  36.                                   const uint32_t *mask);
  37.  
  38. typedef uint32_t (*fetch_pixel_32_t) (bits_image_t *image,
  39.                                       int           x,
  40.                                       int           y);
  41.  
  42. typedef uint64_t (*fetch_pixel_64_t) (bits_image_t *image,
  43.                                       int           x,
  44.                                       int           y);
  45.  
  46. typedef void (*store_scanline_t) (bits_image_t *  image,
  47.                                   int             x,
  48.                                   int             y,
  49.                                   int             width,
  50.                                   const uint32_t *values);
  51.  
  52. typedef enum
  53. {
  54.     BITS,
  55.     LINEAR,
  56.     CONICAL,
  57.     RADIAL,
  58.     SOLID
  59. } image_type_t;
  60.  
  61. typedef enum
  62. {
  63.     SOURCE_IMAGE_CLASS_UNKNOWN,
  64.     SOURCE_IMAGE_CLASS_HORIZONTAL,
  65. } source_image_class_t;
  66.  
  67. typedef source_image_class_t (*classify_func_t) (pixman_image_t *image,
  68.                                                 int             x,
  69.                                                 int             y,
  70.                                                 int             width,
  71.                                                 int             height);
  72. typedef void (*property_changed_func_t) (pixman_image_t *image);
  73.  
  74. struct image_common
  75. {
  76.     image_type_t                type;
  77.     int32_t                     ref_count;
  78.     pixman_region32_t           clip_region;
  79.     int32_t                     alpha_count;        /* How many times this image is being used as an alpha map */
  80.     pixman_bool_t               have_clip_region;   /* FALSE if there is no clip */
  81.     pixman_bool_t               client_clip;        /* Whether the source clip was
  82.                                                        set by a client */
  83.     pixman_bool_t               clip_sources;       /* Whether the clip applies when
  84.                                                      * the image is used as a source
  85.                                                      */
  86.     pixman_bool_t               dirty;
  87.     pixman_transform_t *        transform;
  88.     pixman_repeat_t             repeat;
  89.     pixman_filter_t             filter;
  90.     pixman_fixed_t *            filter_params;
  91.     int                         n_filter_params;
  92.     bits_image_t *              alpha_map;
  93.     int                         alpha_origin_x;
  94.     int                         alpha_origin_y;
  95.     pixman_bool_t               component_alpha;
  96.     classify_func_t             classify;
  97.     property_changed_func_t     property_changed;
  98.     fetch_scanline_t            get_scanline_32;
  99.     fetch_scanline_t            get_scanline_64;
  100.  
  101.     pixman_image_destroy_func_t destroy_func;
  102.     void *                      destroy_data;
  103.  
  104.     uint32_t                    flags;
  105.     pixman_format_code_t        extended_format_code;
  106. };
  107.  
  108. struct source_image
  109. {
  110.     image_common_t common;
  111. };
  112.  
  113. struct solid_fill
  114. {
  115.     source_image_t common;
  116.     pixman_color_t color;
  117.  
  118.     uint32_t       color_32;
  119.     uint64_t       color_64;
  120. };
  121.  
  122. struct gradient
  123. {
  124.     source_image_t          common;
  125.     int                     n_stops;
  126.     pixman_gradient_stop_t *stops;
  127.     int                     stop_range;
  128. };
  129.  
  130. struct linear_gradient
  131. {
  132.     gradient_t           common;
  133.     pixman_point_fixed_t p1;
  134.     pixman_point_fixed_t p2;
  135. };
  136.  
  137. struct circle
  138. {
  139.     pixman_fixed_t x;
  140.     pixman_fixed_t y;
  141.     pixman_fixed_t radius;
  142. };
  143.  
  144. struct radial_gradient
  145. {
  146.     gradient_t common;
  147.  
  148.     circle_t   c1;
  149.     circle_t   c2;
  150.  
  151.     circle_t   delta;
  152.     double     a;
  153.     double     inva;
  154.     double     mindr;
  155. };
  156.  
  157. struct conical_gradient
  158. {
  159.     gradient_t           common;
  160.     pixman_point_fixed_t center;
  161.     double               angle;
  162. };
  163.  
  164. struct bits_image
  165. {
  166.     image_common_t             common;
  167.     pixman_format_code_t       format;
  168.     const pixman_indexed_t *   indexed;
  169.     int                        width;
  170.     int                        height;
  171.     uint32_t *                 bits;
  172.     uint32_t *                 free_me;
  173.     int                        rowstride;  /* in number of uint32_t's */
  174.  
  175.     fetch_scanline_t           fetch_scanline_32;
  176.     fetch_pixel_32_t           fetch_pixel_32;
  177.     store_scanline_t           store_scanline_32;
  178.  
  179.     fetch_scanline_t           fetch_scanline_64;
  180.     fetch_pixel_64_t           fetch_pixel_64;
  181.     store_scanline_t           store_scanline_64;
  182.  
  183.     /* Used for indirect access to the bits */
  184.     pixman_read_memory_func_t  read_func;
  185.     pixman_write_memory_func_t write_func;
  186. };
  187.  
  188. union pixman_image
  189. {
  190.     image_type_t       type;
  191.     image_common_t     common;
  192.     bits_image_t       bits;
  193.     source_image_t     source;
  194.     gradient_t         gradient;
  195.     linear_gradient_t  linear;
  196.     conical_gradient_t conical;
  197.     radial_gradient_t  radial;
  198.     solid_fill_t       solid;
  199. };
  200.  
  201. void
  202. _pixman_bits_image_setup_accessors (bits_image_t *image);
  203.  
  204. void
  205. _pixman_image_get_scanline_generic_64  (pixman_image_t *image,
  206.                                         int             x,
  207.                                         int             y,
  208.                                         int             width,
  209.                                         uint32_t *      buffer,
  210.                                         const uint32_t *mask);
  211.  
  212. source_image_class_t
  213. _pixman_image_classify (pixman_image_t *image,
  214.                         int             x,
  215.                         int             y,
  216.                         int             width,
  217.                         int             height);
  218.  
  219. void
  220. _pixman_image_get_scanline_32 (pixman_image_t *image,
  221.                                int             x,
  222.                                int             y,
  223.                                int             width,
  224.                                uint32_t *      buffer,
  225.                                const uint32_t *mask);
  226.  
  227. /* Even thought the type of buffer is uint32_t *, the function actually expects
  228.  * a uint64_t *buffer.
  229.  */
  230. void
  231. _pixman_image_get_scanline_64 (pixman_image_t *image,
  232.                                int             x,
  233.                                int             y,
  234.                                int             width,
  235.                                uint32_t *      buffer,
  236.                                const uint32_t *unused);
  237.  
  238. void
  239. _pixman_image_store_scanline_32 (bits_image_t *  image,
  240.                                  int             x,
  241.                                  int             y,
  242.                                  int             width,
  243.                                  const uint32_t *buffer);
  244.  
  245. /* Even though the type of buffer is uint32_t *, the function
  246.  * actually expects a uint64_t *buffer.
  247.  */
  248. void
  249. _pixman_image_store_scanline_64 (bits_image_t *  image,
  250.                                  int             x,
  251.                                  int             y,
  252.                                  int             width,
  253.                                  const uint32_t *buffer);
  254.  
  255. pixman_image_t *
  256. _pixman_image_allocate (void);
  257.  
  258. pixman_bool_t
  259. _pixman_init_gradient (gradient_t *                  gradient,
  260.                        const pixman_gradient_stop_t *stops,
  261.                        int                           n_stops);
  262. void
  263. _pixman_image_reset_clip_region (pixman_image_t *image);
  264.  
  265. void
  266. _pixman_image_validate (pixman_image_t *image);
  267.  
  268. uint32_t
  269. _pixman_image_get_solid (pixman_image_t *     image,
  270.                          pixman_format_code_t format);
  271.  
  272. #define PIXMAN_IMAGE_GET_LINE(image, x, y, type, out_stride, line, mul) \
  273.     do                                                                  \
  274.     {                                                                   \
  275.         uint32_t *__bits__;                                             \
  276.         int       __stride__;                                           \
  277.                                                                         \
  278.         __bits__ = image->bits.bits;                                    \
  279.         __stride__ = image->bits.rowstride;                             \
  280.         (out_stride) =                                                  \
  281.             __stride__ * (int) sizeof (uint32_t) / (int) sizeof (type); \
  282.         (line) =                                                        \
  283.             ((type *) __bits__) + (out_stride) * (y) + (mul) * (x);     \
  284.     } while (0)
  285.  
  286. /*
  287.  * Gradient walker
  288.  */
  289. typedef struct
  290. {
  291.     uint32_t                left_ag;
  292.     uint32_t                left_rb;
  293.     uint32_t                right_ag;
  294.     uint32_t                right_rb;
  295.     int32_t                 left_x;
  296.     int32_t                 right_x;
  297.     int32_t                 stepper;
  298.  
  299.     pixman_gradient_stop_t *stops;
  300.     int                     num_stops;
  301.     unsigned int            spread;
  302.  
  303.     int                     need_reset;
  304. } pixman_gradient_walker_t;
  305.  
  306. void
  307. _pixman_gradient_walker_init (pixman_gradient_walker_t *walker,
  308.                               gradient_t *              gradient,
  309.                               unsigned int              spread);
  310.  
  311. void
  312. _pixman_gradient_walker_reset (pixman_gradient_walker_t *walker,
  313.                                pixman_fixed_32_32_t      pos);
  314.  
  315. uint32_t
  316. _pixman_gradient_walker_pixel (pixman_gradient_walker_t *walker,
  317.                                pixman_fixed_32_32_t      x);
  318.  
  319. /*
  320.  * Edges
  321.  */
  322.  
  323. #define MAX_ALPHA(n)    ((1 << (n)) - 1)
  324. #define N_Y_FRAC(n)     ((n) == 1 ? 1 : (1 << ((n) / 2)) - 1)
  325. #define N_X_FRAC(n)     ((n) == 1 ? 1 : (1 << ((n) / 2)) + 1)
  326.  
  327. #define STEP_Y_SMALL(n) (pixman_fixed_1 / N_Y_FRAC (n))
  328. #define STEP_Y_BIG(n)   (pixman_fixed_1 - (N_Y_FRAC (n) - 1) * STEP_Y_SMALL (n))
  329.  
  330. #define Y_FRAC_FIRST(n) (STEP_Y_BIG (n) / 2)
  331. #define Y_FRAC_LAST(n)  (Y_FRAC_FIRST (n) + (N_Y_FRAC (n) - 1) * STEP_Y_SMALL (n))
  332.  
  333. #define STEP_X_SMALL(n) (pixman_fixed_1 / N_X_FRAC (n))
  334. #define STEP_X_BIG(n)   (pixman_fixed_1 - (N_X_FRAC (n) - 1) * STEP_X_SMALL (n))
  335.  
  336. #define X_FRAC_FIRST(n) (STEP_X_BIG (n) / 2)
  337. #define X_FRAC_LAST(n)  (X_FRAC_FIRST (n) + (N_X_FRAC (n) - 1) * STEP_X_SMALL (n))
  338.  
  339. #define RENDER_SAMPLES_X(x, n)                                          \
  340.     ((n) == 1? 0 : (pixman_fixed_frac (x) +                             \
  341.                     X_FRAC_FIRST (n)) / STEP_X_SMALL (n))
  342.  
  343. void
  344. pixman_rasterize_edges_accessors (pixman_image_t *image,
  345.                                   pixman_edge_t * l,
  346.                                   pixman_edge_t * r,
  347.                                   pixman_fixed_t  t,
  348.                                   pixman_fixed_t  b);
  349.  
  350. /*
  351.  * Implementations
  352.  */
  353. typedef struct pixman_implementation_t pixman_implementation_t;
  354.  
  355. typedef void (*pixman_combine_32_func_t) (pixman_implementation_t *imp,
  356.                                           pixman_op_t              op,
  357.                                           uint32_t *               dest,
  358.                                           const uint32_t *         src,
  359.                                           const uint32_t *         mask,
  360.                                           int                      width);
  361.  
  362. typedef void (*pixman_combine_64_func_t) (pixman_implementation_t *imp,
  363.                                           pixman_op_t              op,
  364.                                           uint64_t *               dest,
  365.                                           const uint64_t *         src,
  366.                                           const uint64_t *         mask,
  367.                                           int                      width);
  368.  
  369. typedef void (*pixman_composite_func_t) (pixman_implementation_t *imp,
  370.                                          pixman_op_t              op,
  371.                                          pixman_image_t *         src,
  372.                                          pixman_image_t *         mask,
  373.                                          pixman_image_t *         dest,
  374.                                          int32_t                  src_x,
  375.                                          int32_t                  src_y,
  376.                                          int32_t                  mask_x,
  377.                                          int32_t                  mask_y,
  378.                                          int32_t                  dest_x,
  379.                                          int32_t                  dest_y,
  380.                                          int32_t                  width,
  381.                                          int32_t                  height);
  382. typedef pixman_bool_t (*pixman_blt_func_t) (pixman_implementation_t *imp,
  383.                                             uint32_t *               src_bits,
  384.                                             uint32_t *               dst_bits,
  385.                                             int                      src_stride,
  386.                                             int                      dst_stride,
  387.                                             int                      src_bpp,
  388.                                             int                      dst_bpp,
  389.                                             int                      src_x,
  390.                                             int                      src_y,
  391.                                             int                      dst_x,
  392.                                             int                      dst_y,
  393.                                             int                      width,
  394.                                             int                      height);
  395. typedef pixman_bool_t (*pixman_fill_func_t) (pixman_implementation_t *imp,
  396.                                              uint32_t *               bits,
  397.                                              int                      stride,
  398.                                              int                      bpp,
  399.                                              int                      x,
  400.                                              int                      y,
  401.                                              int                      width,
  402.                                              int                      height,
  403.                                              uint32_t                 xor);
  404.  
  405. void _pixman_setup_combiner_functions_32 (pixman_implementation_t *imp);
  406. void _pixman_setup_combiner_functions_64 (pixman_implementation_t *imp);
  407.  
  408. typedef struct
  409. {
  410.     pixman_op_t             op;
  411.     pixman_format_code_t    src_format;
  412.     uint32_t                src_flags;
  413.     pixman_format_code_t    mask_format;
  414.     uint32_t                mask_flags;
  415.     pixman_format_code_t    dest_format;
  416.     uint32_t                dest_flags;
  417.     pixman_composite_func_t func;
  418. } pixman_fast_path_t;
  419.  
  420. struct pixman_implementation_t
  421. {
  422.     pixman_implementation_t *   toplevel;
  423.     pixman_implementation_t *   delegate;
  424.     const pixman_fast_path_t *  fast_paths;
  425.  
  426.     pixman_blt_func_t           blt;
  427.     pixman_fill_func_t          fill;
  428.  
  429.     pixman_combine_32_func_t    combine_32[PIXMAN_N_OPERATORS];
  430.     pixman_combine_32_func_t    combine_32_ca[PIXMAN_N_OPERATORS];
  431.     pixman_combine_64_func_t    combine_64[PIXMAN_N_OPERATORS];
  432.     pixman_combine_64_func_t    combine_64_ca[PIXMAN_N_OPERATORS];
  433. };
  434.  
  435. pixman_implementation_t *
  436. _pixman_implementation_create (pixman_implementation_t *delegate,
  437.                                const pixman_fast_path_t *fast_paths);
  438.  
  439. void
  440. _pixman_implementation_combine_32 (pixman_implementation_t *imp,
  441.                                    pixman_op_t              op,
  442.                                    uint32_t *               dest,
  443.                                    const uint32_t *         src,
  444.                                    const uint32_t *         mask,
  445.                                    int                      width);
  446. void
  447. _pixman_implementation_combine_64 (pixman_implementation_t *imp,
  448.                                    pixman_op_t              op,
  449.                                    uint64_t *               dest,
  450.                                    const uint64_t *         src,
  451.                                    const uint64_t *         mask,
  452.                                    int                      width);
  453. void
  454. _pixman_implementation_combine_32_ca (pixman_implementation_t *imp,
  455.                                       pixman_op_t              op,
  456.                                       uint32_t *               dest,
  457.                                       const uint32_t *         src,
  458.                                       const uint32_t *         mask,
  459.                                       int                      width);
  460. void
  461. _pixman_implementation_combine_64_ca (pixman_implementation_t *imp,
  462.                                       pixman_op_t              op,
  463.                                       uint64_t *               dest,
  464.                                       const uint64_t *         src,
  465.                                       const uint64_t *         mask,
  466.                                       int                      width);
  467.  
  468. pixman_bool_t
  469. _pixman_implementation_blt (pixman_implementation_t *imp,
  470.                             uint32_t *               src_bits,
  471.                             uint32_t *               dst_bits,
  472.                             int                      src_stride,
  473.                             int                      dst_stride,
  474.                             int                      src_bpp,
  475.                             int                      dst_bpp,
  476.                             int                      src_x,
  477.                             int                      src_y,
  478.                             int                      dst_x,
  479.                             int                      dst_y,
  480.                             int                      width,
  481.                             int                      height);
  482.  
  483. pixman_bool_t
  484. _pixman_implementation_fill (pixman_implementation_t *imp,
  485.                              uint32_t *               bits,
  486.                              int                      stride,
  487.                              int                      bpp,
  488.                              int                      x,
  489.                              int                      y,
  490.                              int                      width,
  491.                              int                      height,
  492.                              uint32_t                 xor);
  493.  
  494. /* Specific implementations */
  495. pixman_implementation_t *
  496. _pixman_implementation_create_general (void);
  497.  
  498. pixman_implementation_t *
  499. _pixman_implementation_create_fast_path (void);
  500.  
  501. #ifdef USE_MMX
  502. pixman_implementation_t *
  503. _pixman_implementation_create_mmx (void);
  504. #endif
  505.  
  506. #ifdef USE_SSE2
  507. pixman_implementation_t *
  508. _pixman_implementation_create_sse2 (void);
  509. #endif
  510.  
  511. #ifdef USE_ARM_SIMD
  512. pixman_implementation_t *
  513. _pixman_implementation_create_arm_simd (void);
  514. #endif
  515.  
  516. #ifdef USE_ARM_NEON
  517. pixman_implementation_t *
  518. _pixman_implementation_create_arm_neon (void);
  519. #endif
  520.  
  521. #ifdef USE_VMX
  522. pixman_implementation_t *
  523. _pixman_implementation_create_vmx (void);
  524. #endif
  525.  
  526. pixman_implementation_t *
  527. _pixman_choose_implementation (void);
  528.  
  529.  
  530.  
  531. /*
  532.  * Utilities
  533.  */
  534.  
  535. /* These "formats" all have depth 0, so they
  536.  * will never clash with any real ones
  537.  */
  538. #define PIXMAN_null             PIXMAN_FORMAT (0, 0, 0, 0, 0, 0)
  539. #define PIXMAN_solid            PIXMAN_FORMAT (0, 1, 0, 0, 0, 0)
  540. #define PIXMAN_pixbuf           PIXMAN_FORMAT (0, 2, 0, 0, 0, 0)
  541. #define PIXMAN_rpixbuf          PIXMAN_FORMAT (0, 3, 0, 0, 0, 0)
  542. #define PIXMAN_unknown          PIXMAN_FORMAT (0, 4, 0, 0, 0, 0)
  543. #define PIXMAN_any              PIXMAN_FORMAT (0, 5, 0, 0, 0, 0)
  544.  
  545. #define PIXMAN_OP_any           (PIXMAN_N_OPERATORS + 1)
  546.  
  547. #define FAST_PATH_ID_TRANSFORM                  (1 <<  0)
  548. #define FAST_PATH_NO_ALPHA_MAP                  (1 <<  1)
  549. #define FAST_PATH_NO_CONVOLUTION_FILTER         (1 <<  2)
  550. #define FAST_PATH_NO_PAD_REPEAT                 (1 <<  3)
  551. #define FAST_PATH_NO_REFLECT_REPEAT             (1 <<  4)
  552. #define FAST_PATH_NO_ACCESSORS                  (1 <<  5)
  553. #define FAST_PATH_NARROW_FORMAT                 (1 <<  6)
  554. #define FAST_PATH_COMPONENT_ALPHA               (1 <<  8)
  555. #define FAST_PATH_SAMPLES_OPAQUE                (1 <<  7)
  556. #define FAST_PATH_UNIFIED_ALPHA                 (1 <<  9)
  557. #define FAST_PATH_SCALE_TRANSFORM               (1 << 10)
  558. #define FAST_PATH_NEAREST_FILTER                (1 << 11)
  559. #define FAST_PATH_HAS_TRANSFORM                 (1 << 12)
  560. #define FAST_PATH_IS_OPAQUE                     (1 << 13)
  561. #define FAST_PATH_NEEDS_WORKAROUND              (1 << 14)
  562. #define FAST_PATH_NO_NONE_REPEAT                (1 << 15)
  563. #define FAST_PATH_SAMPLES_COVER_CLIP            (1 << 16)
  564. #define FAST_PATH_X_UNIT_POSITIVE               (1 << 17)
  565. #define FAST_PATH_AFFINE_TRANSFORM              (1 << 18)
  566. #define FAST_PATH_Y_UNIT_ZERO                   (1 << 19)
  567. #define FAST_PATH_BILINEAR_FILTER               (1 << 20)
  568. #define FAST_PATH_NO_NORMAL_REPEAT              (1 << 21)
  569.  
  570. #define FAST_PATH_PAD_REPEAT                                            \
  571.     (FAST_PATH_NO_NONE_REPEAT           |                               \
  572.      FAST_PATH_NO_NORMAL_REPEAT         |                               \
  573.      FAST_PATH_NO_REFLECT_REPEAT)
  574.  
  575. #define FAST_PATH_NORMAL_REPEAT                                         \
  576.     (FAST_PATH_NO_NONE_REPEAT           |                               \
  577.      FAST_PATH_NO_PAD_REPEAT            |                               \
  578.      FAST_PATH_NO_REFLECT_REPEAT)
  579.  
  580. #define FAST_PATH_NONE_REPEAT                                           \
  581.     (FAST_PATH_NO_NORMAL_REPEAT         |                               \
  582.      FAST_PATH_NO_PAD_REPEAT            |                               \
  583.      FAST_PATH_NO_REFLECT_REPEAT)
  584.  
  585. #define FAST_PATH_REFLECT_REPEAT                                        \
  586.     (FAST_PATH_NO_NONE_REPEAT           |                               \
  587.      FAST_PATH_NO_NORMAL_REPEAT         |                               \
  588.      FAST_PATH_NO_PAD_REPEAT)
  589.  
  590. #define FAST_PATH_STANDARD_FLAGS                                        \
  591.     (FAST_PATH_NO_CONVOLUTION_FILTER    |                               \
  592.      FAST_PATH_NO_ACCESSORS             |                               \
  593.      FAST_PATH_NO_ALPHA_MAP             |                               \
  594.      FAST_PATH_NARROW_FORMAT)
  595.  
  596. #define FAST_PATH_STD_DEST_FLAGS                                        \
  597.     (FAST_PATH_NO_ACCESSORS             |                               \
  598.      FAST_PATH_NO_ALPHA_MAP             |                               \
  599.      FAST_PATH_NARROW_FORMAT)
  600.  
  601. #define SOURCE_FLAGS(format)                                            \
  602.     (FAST_PATH_STANDARD_FLAGS |                                         \
  603.      ((PIXMAN_ ## format == PIXMAN_solid) ?                             \
  604.       0 : (FAST_PATH_SAMPLES_COVER_CLIP | FAST_PATH_ID_TRANSFORM)))
  605.  
  606. #define MASK_FLAGS(format, extra)                                       \
  607.     ((PIXMAN_ ## format == PIXMAN_null) ? 0 : (SOURCE_FLAGS (format) | extra))
  608.  
  609. #define FAST_PATH(op, src, src_flags, mask, mask_flags, dest, dest_flags, func) \
  610.     PIXMAN_OP_ ## op,                                                   \
  611.     PIXMAN_ ## src,                                                     \
  612.     src_flags,                                                          \
  613.     PIXMAN_ ## mask,                                                    \
  614.     mask_flags,                                                         \
  615.     PIXMAN_ ## dest,                                                    \
  616.     dest_flags,                                                         \
  617.     func
  618.  
  619. #define PIXMAN_STD_FAST_PATH(op, src, mask, dest, func)                 \
  620.     { FAST_PATH (                                                       \
  621.             op,                                                         \
  622.             src,  SOURCE_FLAGS (src),                                   \
  623.             mask, MASK_FLAGS (mask, FAST_PATH_UNIFIED_ALPHA),           \
  624.             dest, FAST_PATH_STD_DEST_FLAGS,                             \
  625.             func) }
  626.  
  627. #define PIXMAN_STD_FAST_PATH_CA(op, src, mask, dest, func)              \
  628.     { FAST_PATH (                                                       \
  629.             op,                                                         \
  630.             src,  SOURCE_FLAGS (src),                                   \
  631.             mask, MASK_FLAGS (mask, FAST_PATH_COMPONENT_ALPHA),         \
  632.             dest, FAST_PATH_STD_DEST_FLAGS,                             \
  633.             func) }
  634.  
  635. /* Memory allocation helpers */
  636. void *
  637. pixman_malloc_ab (unsigned int n, unsigned int b);
  638.  
  639. void *
  640. pixman_malloc_abc (unsigned int a, unsigned int b, unsigned int c);
  641.  
  642. pixman_bool_t
  643. pixman_multiply_overflows_int (unsigned int a, unsigned int b);
  644.  
  645. pixman_bool_t
  646. pixman_addition_overflows_int (unsigned int a, unsigned int b);
  647.  
  648. /* Compositing utilities */
  649. void
  650. pixman_expand (uint64_t *           dst,
  651.                const uint32_t *     src,
  652.                pixman_format_code_t format,
  653.                int                  width);
  654.  
  655. void
  656. pixman_contract (uint32_t *      dst,
  657.                  const uint64_t *src,
  658.                  int             width);
  659.  
  660.  
  661. /* Region Helpers */
  662. pixman_bool_t
  663. pixman_region32_copy_from_region16 (pixman_region32_t *dst,
  664.                                     pixman_region16_t *src);
  665.  
  666. pixman_bool_t
  667. pixman_region16_copy_from_region32 (pixman_region16_t *dst,
  668.                                     pixman_region32_t *src);
  669.  
  670.  
  671. /* Misc macros */
  672.  
  673. #ifndef FALSE
  674. #   define FALSE 0
  675. #endif
  676.  
  677. #ifndef TRUE
  678. #   define TRUE 1
  679. #endif
  680.  
  681. #ifndef MIN
  682. #  define MIN(a, b) ((a < b) ? a : b)
  683. #endif
  684.  
  685. #ifndef MAX
  686. #  define MAX(a, b) ((a > b) ? a : b)
  687. #endif
  688.  
  689. /* Integer division that rounds towards -infinity */
  690. #define DIV(a, b)                                          \
  691.     ((((a) < 0) == ((b) < 0)) ? (a) / (b) :                \
  692.      ((a) - (b) + 1 - (((b) < 0) << 1)) / (b))
  693.  
  694. /* Modulus that produces the remainder wrt. DIV */
  695. #define MOD(a, b) ((a) < 0 ? ((b) - ((-(a) - 1) % (b))) - 1 : (a) % (b))
  696.  
  697. #define CLIP(v, low, high) ((v) < (low) ? (low) : ((v) > (high) ? (high) : (v)))
  698.  
  699. /* Conversion between 8888 and 0565 */
  700.  
  701. #define CONVERT_8888_TO_0565(s)                                         \
  702.     ((((s) >> 3) & 0x001f) |                                            \
  703.      (((s) >> 5) & 0x07e0) |                                            \
  704.      (((s) >> 8) & 0xf800))
  705.  
  706. #define CONVERT_0565_TO_0888(s)                                         \
  707.     (((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7)) |                       \
  708.      ((((s) << 5) & 0xfc00) | (((s) >> 1) & 0x300)) |                   \
  709.      ((((s) << 8) & 0xf80000) | (((s) << 3) & 0x70000)))
  710.  
  711. #define CONVERT_0565_TO_8888(s) (CONVERT_0565_TO_0888(s) | 0xff000000)
  712.  
  713. /* Trivial versions that are useful in macros */
  714. #define CONVERT_8888_TO_8888(s) (s)
  715. #define CONVERT_0565_TO_0565(s) (s)
  716.  
  717. #define PIXMAN_FORMAT_IS_WIDE(f)                                        \
  718.     (PIXMAN_FORMAT_A (f) > 8 ||                                         \
  719.      PIXMAN_FORMAT_R (f) > 8 ||                                         \
  720.      PIXMAN_FORMAT_G (f) > 8 ||                                         \
  721.      PIXMAN_FORMAT_B (f) > 8)
  722.  
  723. #ifdef WORDS_BIGENDIAN
  724. #   define SCREEN_SHIFT_LEFT(x,n)       ((x) << (n))
  725. #   define SCREEN_SHIFT_RIGHT(x,n)      ((x) >> (n))
  726. #else
  727. #   define SCREEN_SHIFT_LEFT(x,n)       ((x) >> (n))
  728. #   define SCREEN_SHIFT_RIGHT(x,n)      ((x) << (n))
  729. #endif
  730.  
  731. /*
  732.  * Various debugging code
  733.  */
  734.  
  735. #undef DEBUG
  736.  
  737. #define COMPILE_TIME_ASSERT(x)                                          \
  738.     do { typedef int compile_time_assertion [(x)?1:-1]; } while (0)
  739.  
  740. /* Turn on debugging depending on what type of release this is
  741.  */
  742. #if (((PIXMAN_VERSION_MICRO % 2) == 0) && ((PIXMAN_VERSION_MINOR % 2) == 1))
  743.  
  744. /* Debugging gets turned on for development releases because these
  745.  * are the things that end up in bleeding edge distributions such
  746.  * as Rawhide etc.
  747.  *
  748.  * For performance reasons we don't turn it on for stable releases or
  749.  * random git checkouts. (Random git checkouts are often used for
  750.  * performance work).
  751.  */
  752.  
  753. #    define DEBUG
  754.  
  755. #endif
  756.  
  757. #ifdef DEBUG
  758.  
  759. void
  760. _pixman_log_error (const char *function, const char *message);
  761.  
  762. #define return_if_fail(expr)                                            \
  763.     do                                                                  \
  764.     {                                                                   \
  765.         if (!(expr))                                                    \
  766.         {                                                               \
  767.             _pixman_log_error (FUNC, "The expression " # expr " was false"); \
  768.             return;                                                     \
  769.         }                                                               \
  770.     }                                                                   \
  771.     while (0)
  772.  
  773. #define return_val_if_fail(expr, retval)                                \
  774.     do                                                                  \
  775.     {                                                                   \
  776.         if (!(expr))                                                    \
  777.         {                                                               \
  778.             _pixman_log_error (FUNC, "The expression " # expr " was false"); \
  779.             return (retval);                                            \
  780.         }                                                               \
  781.     }                                                                   \
  782.     while (0)
  783.  
  784. #define critical_if_fail(expr)                                          \
  785.     do                                                                  \
  786.     {                                                                   \
  787.         if (!(expr))                                                    \
  788.             _pixman_log_error (FUNC, "The expression " # expr " was false"); \
  789.     }                                                                   \
  790.     while (0)
  791.  
  792.  
  793. #else
  794.  
  795. #define _pixman_log_error(f,m) do { } while (0)                         \
  796.  
  797. #define return_if_fail(expr)                                            \
  798.     do                                                                  \
  799.     {                                                                   \
  800.         if (!(expr))                                                    \
  801.             return;                                                     \
  802.     }                                                                   \
  803.     while (0)
  804.  
  805. #define return_val_if_fail(expr, retval)                                \
  806.     do                                                                  \
  807.     {                                                                   \
  808.         if (!(expr))                                                    \
  809.             return (retval);                                            \
  810.     }                                                                   \
  811.     while (0)
  812.  
  813. #define critical_if_fail(expr)                                          \
  814.     do                                                                  \
  815.     {                                                                   \
  816.     }                                                                   \
  817.     while (0)
  818. #endif
  819.  
  820. /*
  821.  * Timers
  822.  */
  823.  
  824. #ifdef PIXMAN_TIMERS
  825.  
  826. static inline uint64_t
  827. oil_profile_stamp_rdtsc (void)
  828. {
  829.     uint64_t ts;
  830.  
  831.     __asm__ __volatile__ ("rdtsc\n" : "=A" (ts));
  832.     return ts;
  833. }
  834.  
  835. #define OIL_STAMP oil_profile_stamp_rdtsc
  836.  
  837. typedef struct pixman_timer_t pixman_timer_t;
  838.  
  839. struct pixman_timer_t
  840. {
  841.     int             initialized;
  842.     const char *    name;
  843.     uint64_t        n_times;
  844.     uint64_t        total;
  845.     pixman_timer_t *next;
  846. };
  847.  
  848. extern int timer_defined;
  849.  
  850. void pixman_timer_register (pixman_timer_t *timer);
  851.  
  852. #define TIMER_BEGIN(tname)                                              \
  853.     {                                                                   \
  854.         static pixman_timer_t timer ## tname;                           \
  855.         uint64_t              begin ## tname;                           \
  856.                                                                         \
  857.         if (!timer ## tname.initialized)                                \
  858.         {                                                               \
  859.             timer ## tname.initialized = 1;                             \
  860.             timer ## tname.name = # tname;                              \
  861.             pixman_timer_register (&timer ## tname);                    \
  862.         }                                                               \
  863.                                                                         \
  864.         timer ## tname.n_times++;                                       \
  865.         begin ## tname = OIL_STAMP ();
  866.  
  867. #define TIMER_END(tname)                                                \
  868.     timer ## tname.total += OIL_STAMP () - begin ## tname;              \
  869.     }
  870.  
  871. #endif /* PIXMAN_TIMERS */
  872.  
  873. #endif /* PIXMAN_PRIVATE_H */
  874.