Change to use malloced image instead of stack allocated
authorSoren Sandmann Pedersen <ssp@dhcp83-218.boston.redhat.com>
Wed, 9 May 2007 12:20:43 +0000 (08:20 -0400)
committerSoren Sandmann Pedersen <ssp@dhcp83-218.boston.redhat.com>
Wed, 9 May 2007 12:20:43 +0000 (08:20 -0400)
pixman/pixman-compose.c
pixman/pixman-image.c
pixman/pixman-private.h
pixman/pixman.h
test/composite-test.c

index 0232ec6..3ab418a 100644 (file)
@@ -4377,8 +4377,9 @@ static void fbStoreExternalAlpha(bits_image_t * pict, int x, int y, int width, u
     fbFinishAccess (pict->pDrawable);
 }
 
-typedef void (*scanStoreProc)(image_t * , int , int , int , uint32_t *);
-typedef void (*scanFetchProc)(image_t * , int , int , int , uint32_t * , uint32_t *, uint32_t);
+typedef void (*scanStoreProc)(pixman_image_t *, int, int, int, uint32_t *);
+typedef void (*scanFetchProc)(pixman_image_t *, int, int, int, uint32_t *,
+                             uint32_t *, uint32_t);
 
 void
 fbCompositeRect (const FbComposeData *data, uint32_t *scanline_buffer)
index 9a9c1ba..72115b2 100644 (file)
@@ -111,35 +111,58 @@ color_to_uint32 (const pixman_color_t *color)
        (color->blue >> 8);
 }
 
+static pixman_image_t *
+allocate_image (void)
+{
+    return malloc (sizeof (pixman_image_t *));
+}
+
+/* Destructor */
 void
-pixman_image_init_solid_fill (pixman_image_t *image,
-                             pixman_color_t *color,
-                             int            *error)
+pixman_image_destroy (pixman_image_t *image)
 {
-    image_t *priv = (image_t *)image;
     
-    init_source_image (&priv->solid.common);
+}
+
+/* Constructors */
+
+pixman_image_t *
+pixman_image_create_solid_fill (pixman_color_t *color,
+                               int            *error)
+{
+    pixman_image_t *img = allocate_image();
+    if (!img)
+       return NULL;
+    
+    init_source_image (&img->solid.common);
     
-    priv->type = SOLID;
-    priv->solid.color = color_to_uint32 (color);
+    img->type = SOLID;
+    img->solid.color = color_to_uint32 (color);
+
+    return img;
 }
 
-void
-pixman_image_init_linear_gradient (pixman_image_t       *image,
-                                  pixman_point_fixed_t *p1,
-                                  pixman_point_fixed_t *p2,
-                                  int                   n_stops,
-                                  pixman_fixed_t       *stops,
-                                  pixman_color_t       *colors,
-                                  int                  *error)
+pixman_image_t *
+pixman_image_create_linear_gradient (pixman_point_fixed_t *p1,
+                                    pixman_point_fixed_t *p2,
+                                    int                   n_stops,
+                                    pixman_fixed_t       *stops,
+                                    pixman_color_t       *colors,
+                                    int                  *error)
 {
-    image_t *priv = (image_t *)image;
-    linear_gradient_t *linear = &priv->linear;
+    pixman_image_t *image = allocate_image();
+    linear_gradient_t *linear = &image->linear;
+
+    if (!image)
+    {
+       *error = PIXMAN_BAD_ALLOC;
+       return NULL;
+    }
     
     if (n_stops < 2)
     {
         *error = PIXMAN_BAD_VALUE;
-        return;
+        return NULL;
     }
     
     init_gradient (&linear->common, n_stops, stops, colors, error);
@@ -147,33 +170,40 @@ pixman_image_init_linear_gradient (pixman_image_t       *image,
     linear->p1 = *p1;
     linear->p2 = *p2;
 
-    priv->type = LINEAR;
+    image->type = LINEAR;
+
+    return image;
 }
 
 
-void
-pixman_image_init_radial_gradient (pixman_image_t *image,
-                                  pixman_point_fixed_t *inner,
-                                  pixman_point_fixed_t *outer,
-                                  pixman_fixed_t inner_radius,
-                                  pixman_fixed_t outer_radius,
-                                  int             n_stops,
-                                  pixman_fixed_t *stops,
-                                  pixman_color_t *colors,
-                                  int            *error)
+pixman_image_t *
+pixman_image_create_radial_gradient (pixman_point_fixed_t *inner,
+                                    pixman_point_fixed_t *outer,
+                                    pixman_fixed_t inner_radius,
+                                    pixman_fixed_t outer_radius,
+                                    int             n_stops,
+                                    pixman_fixed_t *stops,
+                                    pixman_color_t *colors,
+                                    int            *error)
 {
-    image_t *priv = (image_t *)image;
-    radial_gradient_t *radial = &priv->radial;
+    pixman_image_t *image = allocate_image();
+    radial_gradient_t *radial = &image->radial;
 
+    if (!image)
+    {
+       *error = PIXMAN_BAD_ALLOC;
+       return NULL;
+    }
+    
     if (n_stops < 2)
     {
         *error = PIXMAN_BAD_VALUE;
-       return;
+       return NULL;
     }
 
     init_gradient (&radial->common, n_stops, stops, colors, error);
 
-    priv->type = RADIAL;
+    image->type = RADIAL;
     
     radial->c1.x = inner->x;
     radial->c1.y = inner->y;
@@ -187,105 +217,102 @@ pixman_image_init_radial_gradient (pixman_image_t *image,
     radial->A = (  radial->cdx * radial->cdx
                   + radial->cdy * radial->cdy
                   - radial->dr  * radial->dr);
+
+    return image;
 }
 
-void
-pixman_image_init_conical_gradient (pixman_image_t *image,
-                                   pixman_point_fixed_t *center,
-                                   pixman_fixed_t angle,
-                                   int n_stops,
-                                   pixman_fixed_t *stops,
-                                   pixman_color_t *colors,
-                                   int *error)
+pixman_image_t *
+pixman_image_create_conical_gradient (pixman_point_fixed_t *center,
+                                     pixman_fixed_t angle,
+                                     int n_stops,
+                                     pixman_fixed_t *stops,
+                                     pixman_color_t *colors,
+                                     int            *error)
 {
-    image_t *priv = (image_t *)image;
-    conical_gradient_t *conical = &priv->conical;
+    pixman_image_t *image = allocate_image();
+    conical_gradient_t *conical = &image->conical;
 
+    if (!image)
+    {
+       *error = PIXMAN_BAD_ALLOC;
+       return NULL;
+    }
+    
     if (n_stops < 2)
     {
        *error = PIXMAN_BAD_VALUE;
-       return;
+       return NULL;
     }
 
     init_gradient (&conical->common, n_stops, stops, colors, error);
 
-    priv->type = CONICAL;
+    image->type = CONICAL;
     conical->center = *center;
     conical->angle = angle;
+
+    return image;
 }
 
-void
-pixman_image_init_bits (pixman_image_t         *image,
-                       pixman_format_code_t    format,
-                       int                     width,
-                       int                     height,
-                       uint32_t               *bits,
-                       int                     rowstride)
+pixman_image_t *
+pixman_image_create_bits (pixman_format_code_t    format,
+                         int                     width,
+                         int                     height,
+                         uint32_t             *bits,
+                         int                   rowstride,
+                         int                  *error)
 {
-    image_t *img = (image_t *)image;
+    pixman_image_t *image = allocate_image();
 
-    init_common (&img->common);
-
-    if (rowstride & 0x3)
+    if (!image)
     {
-       /* we should probably spew some warning here */
+       *error = PIXMAN_BAD_ALLOC;
+       return NULL;
     }
     
-    img->type = BITS;
-    img->bits.format = format;
-    img->bits.width = width;
-    img->bits.height = height;
-    img->bits.bits = bits;
-    img->bits.rowstride = rowstride / 4; /* we store it in number of uint32_t's */
-    img->bits.indexed = NULL;
-
-    if (sizeof (pixman_image_t) < sizeof (image_t))
-    {
-       fprintf (stderr, "BUG in pixman: sizeof pixman_image_t < sizeof (image_t)\n");
-       exit (1);
-    }
-    else
+    init_common (&image->common);
+
+    if (rowstride & 0x3)
     {
-       fprintf (stderr, "sizeof pixman_image_t: %d\n", sizeof (pixman_image_t));
-       fprintf (stderr, "sizeof image_t: %d\n", sizeof (image_t));
+       /* we should probably spew some warning here */
     }
     
+    image->type = BITS;
+    image->bits.format = format;
+    image->bits.width = width;
+    image->bits.height = height;
+    image->bits.bits = bits;
+    image->bits.rowstride = rowstride / 4; /* we store it in number of uint32_t's */
+    image->bits.indexed = NULL;
+
+    return image;
 }
 
 void
 pixman_image_set_clip_region (pixman_image_t    *image,
                              pixman_region16_t *region)
 {
-    image_t *priv = (image_t *)image;
-
-    priv->common.clip_region = region;
+    image->common.clip_region = region;
 }
 
 void
 pixman_image_set_transform         (pixman_image_t       *image,
                                    pixman_transform_t   *transform)
 {
-    image_t *priv = (image_t *)image;
-
-    priv->common.transform = transform;
+    image->common.transform = transform;
 }
 
 void
 pixman_image_set_repeat            (pixman_image_t       *image,
                                    pixman_repeat_t       repeat)
 {
-    image_t *priv = (image_t *)image;
-
-    priv->common.repeat = repeat;
+    image->common.repeat = repeat;
 }
 
 void
 pixman_image_set_filter            (pixman_image_t       *image,
                                    pixman_filter_t       filter)
 {
-    image_t *priv = (image_t *)image;
-
-    priv->common.filter = filter;
+    image->common.filter = filter;
 }
 
 void
@@ -293,10 +320,8 @@ pixman_image_set_filter_params     (pixman_image_t       *image,
                                    pixman_fixed_t       *params,
                                    int                   n_params)
 {
-    image_t *priv = (image_t *)image;
-
-    priv->common.filter_params = params;
-    priv->common.n_filter_params = n_params;
+    image->common.filter_params = params;
+    image->common.n_filter_params = n_params;
 }
 
 void
@@ -305,27 +330,22 @@ pixman_image_set_alpha_map         (pixman_image_t       *image,
                                    int16_t               x,
                                    int16_t               y)
 {
-    image_t *priv = (image_t *)image;
-    image_t *alpha_priv = (image_t *)alpha_map;
-
-    if (alpha_priv && alpha_priv->type != BITS)
+    if (alpha_map && alpha_map->type != BITS)
     {
-       priv->common.alpha_map = NULL;
+       image->common.alpha_map = NULL;
        return;
     }
     
-    priv->common.alpha_map = (bits_image_t *)alpha_map;
-    priv->common.alpha_origin.x = x;
-    priv->common.alpha_origin.y = y;
+    image->common.alpha_map = (bits_image_t *)alpha_map;
+    image->common.alpha_origin.x = x;
+    image->common.alpha_origin.y = y;
 }
 
 void
 pixman_image_set_component_alpha   (pixman_image_t       *image,
                                    pixman_bool_t         component_alpha)
 {
-    image_t *priv = (image_t *)image;
-
-    priv->common.component_alpha = component_alpha;
+    image->common.component_alpha = component_alpha;
 }
 
 
@@ -358,9 +378,9 @@ pixman_image_composite (pixman_op_t  op,
     }
     
     compose_data.op = op;
-    compose_data.src = (image_t *)src_img;
-    compose_data.mask = (image_t *)mask_img;
-    compose_data.dest = (image_t *)dest_img;
+    compose_data.src = src_img;
+    compose_data.mask = mask_img;
+    compose_data.dest = dest_img;
     compose_data.xSrc = src_x;
     compose_data.ySrc = src_y;
     compose_data.xMask = mask_x;
index caea500..f63b2b7 100644 (file)
@@ -8,7 +8,6 @@
 #define TRUE 1
 #endif
 
-typedef union  image image_t;
 typedef struct image_common image_common_t;
 typedef struct source_image source_image_t;
 typedef struct solid_fill solid_fill_t;
@@ -39,9 +38,9 @@ typedef struct _FbComposeFunctions {
 
 typedef struct _FbComposeData {
     uint8_t     op;
-    image_t    *src;
-    image_t    *mask;
-    image_t    *dest;
+    pixman_image_t     *src;
+    pixman_image_t     *mask;
+    pixman_image_t     *dest;
     int16_t     xSrc;
     int16_t     ySrc;
     int16_t     xMask;
@@ -166,7 +165,7 @@ struct bits_image
     int                                rowstride; /* in bytes */
 };
 
-union image
+union pixman_image
 {
     image_type_t               type;
     image_common_t             common;
index a7ac127..5f5cba0 100644 (file)
@@ -272,8 +272,10 @@ const pixman_box16_t *  pixman_region_rectangles (pixman_region16_t *region,
 /*
  * Images
  */
+typedef union pixman_image pixman_image_t;
 typedef struct pixman_indexed  pixman_indexed_t;
 
+
 #define PIXMAN_MAX_INDEXED  256 /* XXX depth must be <= 8 */
 
 #if PIXMAN_MAX_INDEXED <= 256
@@ -372,77 +374,73 @@ typedef enum {
     PIXMAN_g1 =                PIXMAN_FORMAT(1,PIXMAN_TYPE_GRAY,0,0,0,0),
 } pixman_format_code_t;
 
-typedef struct
-{
-    /* All of this struct is considered private to libcomp */
-    unsigned char      reserved [128];
-} pixman_image_t;
-
-/* Initialize */
-void pixman_image_init_solid_fill       (pixman_image_t       *image,
-                                        pixman_color_t       *color,
-                                        int                  *error);
-void pixman_image_init_linear_gradient  (pixman_image_t       *image,
-                                        pixman_point_fixed_t *p1,
-                                        pixman_point_fixed_t *p2,
-                                        int                   n_stops,
-                                        pixman_fixed_t       *stops,
-                                        pixman_color_t       *colors,
-                                        int                  *error);
-void pixman_image_init_radial_gradient  (pixman_image_t       *image,
-                                        pixman_point_fixed_t *inner,
-                                        pixman_point_fixed_t *outer,
-                                        pixman_fixed_t        inner_radius,
-                                        pixman_fixed_t        outer_radius,
-                                        int                   n_stops,
-                                        pixman_fixed_t       *stops,
-                                        pixman_color_t       *colors,
-                                        int                  *error);
-void pixman_image_init_conical_gradient (pixman_image_t       *image,
-                                        pixman_point_fixed_t *center,
-                                        pixman_fixed_t        angle,
-                                        int                   n_stops,
-                                        pixman_fixed_t       *stops,
-                                        pixman_color_t       *colors,
-                                        int                  *error);
-void pixman_image_init_bits             (pixman_image_t       *image,
-                                        pixman_format_code_t  format,
-                                        int                   width,
-                                        int                   height,
-                                        uint32_t             *bits,
-                                        int                   rowstride_bytes);
+/* Constructors */
+pixman_image_t *pixman_image_create_solid_fill       (pixman_color_t       *color,
+                                                     int                  *error);
+pixman_image_t *pixman_image_create_linear_gradient  (pixman_point_fixed_t *p1,
+                                                     pixman_point_fixed_t *p2,
+                                                     int                   n_stops,
+                                                     pixman_fixed_t       *stops,
+                                                     pixman_color_t       *colors,
+                                                     int                  *error);
+pixman_image_t *pixman_image_create_radial_gradient  (pixman_point_fixed_t *inner,
+                                                     pixman_point_fixed_t *outer,
+                                                     pixman_fixed_t        inner_radius,
+                                                     pixman_fixed_t        outer_radius,
+                                                     int                   n_stops,
+                                                     pixman_fixed_t       *stops,
+                                                     pixman_color_t       *colors,
+                                                     int                  *error);
+pixman_image_t *pixman_image_create_conical_gradient (pixman_point_fixed_t *center,
+                                                     pixman_fixed_t        angle,
+                                                     int                   n_stops,
+                                                     pixman_fixed_t       *stops,
+                                                     pixman_color_t       *colors,
+                                                     int                  *error);
+pixman_image_t *pixman_image_create_bits             (pixman_format_code_t  format,
+                                                     int                   width,
+                                                     int                   height,
+                                                     uint32_t             *bits,
+                                                     int                   rowstride_bytes,
+                                                     int                  *error);
+
+/* Destructor */
+void           pixman_image_destroy                 (pixman_image_t       *image);
+
 /* Set properties */
-void pixman_image_set_clip_region       (pixman_image_t       *image,
-                                        pixman_region16_t    *region);
-void pixman_image_set_transform         (pixman_image_t       *image,
-                                        pixman_transform_t   *transform);
-void pixman_image_set_repeat            (pixman_image_t       *image,
-                                        pixman_repeat_t       repeat);
-void pixman_image_set_filter            (pixman_image_t       *image,
-                                        pixman_filter_t       filter);
-void pixman_image_set_filter_params     (pixman_image_t       *image,
-                                        pixman_fixed_t       *params,
-                                        int                   n_params);
-void pixman_image_set_alpha_map         (pixman_image_t       *image,
-                                        pixman_image_t       *alpha_map,
-                                        int16_t               x,
-                                        int16_t               y);
-void pixman_image_set_component_alpha   (pixman_image_t       *image,
-                                        pixman_bool_t         component_alpha);
+void            pixman_image_set_clip_region         (pixman_image_t       *image,
+                                                     pixman_region16_t    *region);
+void            pixman_image_set_transform           (pixman_image_t       *image,
+                                                     pixman_transform_t   *transform);
+void            pixman_image_set_repeat              (pixman_image_t       *image,
+                                                     pixman_repeat_t       repeat);
+void            pixman_image_set_filter              (pixman_image_t       *image,
+                                                     pixman_filter_t       filter);
+void            pixman_image_set_filter_params       (pixman_image_t       *image,
+                                                     pixman_fixed_t       *params,
+                                                     int                   n_params);
+void            pixman_image_set_alpha_map           (pixman_image_t       *image,
+                                                     pixman_image_t       *alpha_map,
+                                                     int16_t               x,
+                                                     int16_t               y);
+void            pixman_image_set_component_alpha     (pixman_image_t       *image,
+                                                     pixman_bool_t         component_alpha);
 
 /* Composite */
-void pixman_image_composite            (pixman_op_t           op,
-                                        pixman_image_t       *src,
-                                        pixman_image_t       *mask,
-                                        pixman_image_t       *dest,
-                                        int                   src_x,
-                                        int                   src_y,
-                                        int                   mask_x,
-                                        int                   mask_y,
-                                        int                    dest_x,
-                                        int                    dest_y,
-                                        int                    width,
-                                        int                    height);
+void            pixman_image_composite               (pixman_op_t           op,
+                                                     pixman_image_t       *src,
+                                                     pixman_image_t       *mask,
+                                                     pixman_image_t       *dest,
+                                                     int                   src_x,
+                                                     int                   src_y,
+                                                     int                   mask_x,
+                                                     int                   mask_y,
+                                                     int                   dest_x,
+                                                     int                   dest_y,
+                                                     int                   width,
+                                                     int                   height);
+
+
 
 
 
index 4e5ca57..2aecd54 100644 (file)
@@ -7,8 +7,8 @@ main ()
 {
     uint32_t *src = malloc (10 * 10 * 4);
     uint32_t *dest = malloc (10 * 10 * 4);
-    pixman_image_t src_img;
-    pixman_image_t dest_img;
+    pixman_image_t *src_img;
+    pixman_image_t *dest_img;
     uint32_t real;
 
     int i;
@@ -19,19 +19,17 @@ main ()
     for (i = 0; i < 10 * 10; ++i)
        dest[i] = 0x7f0000ff; /* blue */
     
-    pixman_image_init_bits (&src_img,
-                           PIXMAN_a8r8g8b8,
-                           10, 10,
-                           src,
-                           10 * 4);
-
-    pixman_image_init_bits (&dest_img,
-                           PIXMAN_a8r8g8b8,
-                           10, 10,
-                           dest,
-                           10 * 4);
+    src_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
+                                       10, 10,
+                                       src,
+                                       10 * 4, NULL);
+    
+    dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
+                                      10, 10,
+                                      dest,
+                                      10 * 4, NULL);
 
-    pixman_image_composite (PIXMAN_OP_OVER, &src_img, NULL, &dest_img,
+    pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img,
                            0, 0, 0, 0, 0, 0, 10, 10);
 
     return 0;