summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2010-03-10 21:11:46 +0100
committerMarc-André Lureau <marcandre.lureau@gmail.com>2012-03-20 15:25:40 +0100
commit7653380e7e3ba4bf6593e473244b1d069f6ffbd3 (patch)
tree868e485d9b99296f598aa5f2bb3e131f4ed36fbd
parent59b330b4d2fbfd410bf5ade59a7939017e9e3659 (diff)
Use the spice allocator in common/
-rw-r--r--common/cairo_canvas.c4
-rw-r--r--common/canvas_base.c16
-rw-r--r--common/canvas_utils.c3
-rw-r--r--common/gdi_canvas.c6
-rw-r--r--common/gl_canvas.c10
-rw-r--r--common/glc.c128
-rw-r--r--common/lines.c5
-rw-r--r--common/pixman_utils.c3
-rw-r--r--common/region.c3
9 files changed, 62 insertions, 116 deletions
diff --git a/common/cairo_canvas.c b/common/cairo_canvas.c
index b66301d..9e29e17 100644
--- a/common/cairo_canvas.c
+++ b/common/cairo_canvas.c
@@ -812,10 +812,10 @@ SpiceCanvas *canvas_create(pixman_image_t *image, int bits
CairoCanvas *canvas;
int init_ok;
- if (need_init || !(canvas = (CairoCanvas *)malloc(sizeof(CairoCanvas)))) {
+ if (need_init) {
return NULL;
}
- memset(canvas, 0, sizeof(CairoCanvas));
+ canvas = spice_new0(CairoCanvas, 1);
init_ok = canvas_base_init(&canvas->base, &cairo_canvas_ops,
pixman_image_get_width (image),
pixman_image_get_height (image),
diff --git a/common/canvas_base.c b/common/canvas_base.c
index cbe37fe..beedae9 100644
--- a/common/canvas_base.c
+++ b/common/canvas_base.c
@@ -32,6 +32,7 @@
#include "rect.h"
#include "lines.h"
#include "rop3.h"
+#include "mem.h"
#include "mutex.h"
@@ -879,7 +880,7 @@ static pixman_image_t *canvas_get_bits(CanvasBase *canvas, SpiceBitmap *bitmap)
palette = (SpicePalette *)SPICE_GET_ADDRESS(bitmap->palette);
if (canvas->color_shift == 5) {
int size = sizeof(SpicePalette) + (palette->num_ents << 2);
- SpicePalette *local_palette = malloc(size);
+ SpicePalette *local_palette = spice_malloc(size);
pixman_image_t* surface;
memcpy(local_palette, palette, size);
@@ -1634,7 +1635,7 @@ static void quic_usr_warn(QuicUsrContext *usr, const char *fmt, ...)
static void *quic_usr_malloc(QuicUsrContext *usr, int size)
{
- return malloc(size);
+ return spice_malloc(size);
}
static void quic_usr_free(QuicUsrContext *usr, void *ptr)
@@ -1673,7 +1674,7 @@ static void lz_usr_error(LzUsrContext *usr, const char *fmt, ...)
static void *lz_usr_malloc(LzUsrContext *usr, int size)
{
- return malloc(size);
+ return spice_malloc(size);
}
static void lz_usr_free(LzUsrContext *usr, void *ptr)
@@ -2478,7 +2479,7 @@ static void stroke_fill_rects(lineGC * pGC,
/* TODO: We can optimize this for more common cases where
dest is one rect */
- boxes = (pixman_box32_t *)malloc(num_rects * sizeof(pixman_box32_t));
+ boxes = spice_new(pixman_box32_t, num_rects);
for (i = 0; i < num_rects; i++) {
boxes[i].x1 = rects[i].x;
boxes[i].y1 = rects[i].y;
@@ -2525,7 +2526,7 @@ typedef struct {
static void stroke_lines_init(StrokeLines *lines)
{
- lines->points = (SpicePoint *)malloc(10*sizeof(SpicePoint));
+ lines->points = spice_new(SpicePoint, 10);
lines->size = 10;
lines->num_points = 0;
}
@@ -2540,8 +2541,7 @@ static void stroke_lines_append(StrokeLines *lines,
{
if (lines->num_points == lines->size) {
lines->size *= 2;
- lines->points = (SpicePoint *)realloc(lines->points,
- lines->size * sizeof(SpicePoint));
+ lines->points = spice_renew(SpicePoint, lines->points, lines->size);
}
lines->points[lines->num_points].x = x;
lines->points[lines->num_points].y = y;
@@ -2723,7 +2723,7 @@ static void canvas_draw_stroke(SpiceCanvas *spice_canvas, SpiceRect *bbox,
not right either. The gl an gdi backend don't use back_mode
at all */
gc.base.lineStyle = LineOnOffDash;
- gc.base.dash = (unsigned char *)malloc(nseg);
+ gc.base.dash = (unsigned char *)spice_malloc(nseg);
gc.base.numInDashList = nseg;
access_test(canvas, style, nseg * sizeof(*style));
diff --git a/common/canvas_utils.c b/common/canvas_utils.c
index 2ab8f0b..95c168b 100644
--- a/common/canvas_utils.c
+++ b/common/canvas_utils.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <stdio.h>
#endif
+#include "mem.h"
#ifdef WIN32
extern int gdi_handlers;
@@ -89,7 +90,7 @@ static inline pixman_image_t *__surface_create_stride(pixman_format_code_t forma
pixman_image_t *surface;
PixmanData *pixman_data;
- data = (uint8_t *)malloc(abs(stride) * height);
+ data = (uint8_t *)spice_malloc_n(abs(stride), height);
if (stride < 0) {
stride_data = data + (-stride) * (height - 1);
} else {
diff --git a/common/gdi_canvas.c b/common/gdi_canvas.c
index cd7e87f..5eb31fe 100644
--- a/common/gdi_canvas.c
+++ b/common/gdi_canvas.c
@@ -1508,7 +1508,7 @@ static uint32_t *gdi_get_userstyle(GdiCanvas *canvas, uint8_t nseg, SPICE_ADDRES
if (nseg == 0) {
CANVAS_ERROR("bad nseg");
}
- local_style = (uint32_t *)malloc(nseg * sizeof(*local_style));
+ local_style = spice_new(uint32_t , nseg);
if (start_is_gap) {
offset = (uint32_t)fix_to_double(*style);
@@ -1730,10 +1730,10 @@ SpiceCanvas *gdi_canvas_create(int width, int height,
GdiCanvas *canvas;
int init_ok;
- if (need_init || !(canvas = (GdiCanvas *)malloc(sizeof(GdiCanvas)))) {
+ if (need_init) {
return NULL;
}
- memset(canvas, 0, sizeof(GdiCanvas));
+ canvas = spice_new0(GdiCanvas, 1);
init_ok = canvas_base_init(&canvas->base, &gdi_canvas_ops,
width, height, bits
#ifdef CAIRO_CANVAS_CACHE
diff --git a/common/gl_canvas.c b/common/gl_canvas.c
index c3c9388..f69c920 100644
--- a/common/gl_canvas.c
+++ b/common/gl_canvas.c
@@ -46,7 +46,7 @@ static inline uint8_t *copy_opposite_image(GLCanvas *canvas, void *data, int str
int i;
if (!canvas->private_data) {
- canvas->private_data = malloc(stride * height);
+ canvas->private_data = spice_malloc_n(height, stride);
if (!canvas->private_data) {
return ret_data;
}
@@ -55,7 +55,7 @@ static inline uint8_t *copy_opposite_image(GLCanvas *canvas, void *data, int str
if (canvas->private_data_size < (stride * height)) {
free(canvas->private_data);
- canvas->private_data = malloc(stride * height);
+ canvas->private_data = spice_malloc_n(height, stride);
if (!canvas->private_data) {
return ret_data;
}
@@ -742,7 +742,7 @@ static void gl_canvas_group_start(SpiceCanvas *spice_canvas, QRegion *region)
rects = pixman_region32_rectangles(region, &num_rect);
- glc_rects = (GLCRect *)malloc(num_rect * sizeof(GLCRect));
+ glc_rects = spice_new(GLCRect, num_rect);
now = glc_rects;
end = glc_rects + num_rect;
@@ -837,10 +837,10 @@ SpiceCanvas *gl_canvas_create(int width, int height, int depth
GLCanvas *canvas;
int init_ok;
- if (need_init || !(canvas = (GLCanvas *)malloc(sizeof(GLCanvas)))) {
+ if (need_init) {
return NULL;
}
- memset(canvas, 0, sizeof(GLCanvas));
+ canvas = spice_new0(GLCanvas, 1);
if (!(canvas->glc = glc_create(width, height))) {
goto error_1;
diff --git a/common/glc.c b/common/glc.c
index 2d71c42..2972b39 100644
--- a/common/glc.c
+++ b/common/glc.c
@@ -33,6 +33,7 @@
#include "wglext.h"
#endif
+#include "mem.h"
#include "glc.h"
#include "gl_utils.h"
@@ -169,11 +170,6 @@ static void fill_mask(InternaCtx *ctx, int x_dest, int y_dest, int width, int he
const uint8_t *bitmap);
static void set_pat(InternaCtx *ctx, InternalPat *pat);
-static inline void *zmalloc(size_t size)
-{
- return calloc(1, size);
-}
-
static inline void set_raster_pos(InternaCtx *ctx, int x, int y)
{
if (x >= 0 && y >= 0 && x < ctx->width && y < ctx->height) {
@@ -192,11 +188,8 @@ static TassVertex *alloc_tess_vertex(InternaCtx *ctx)
TassVertexBuf *buf;
int i;
- if (!(buf = (TassVertexBuf *)malloc(sizeof(TassVertexBuf) +
- sizeof(TassVertex) * TESS_VERTEX_ALLOC_BUNCH))) {
- //warn
- return NULL;
- }
+ buf = (TassVertexBuf *)spice_malloc(sizeof(TassVertexBuf) +
+ sizeof(TassVertex) * TESS_VERTEX_ALLOC_BUNCH);
buf->next = ctx->vertex_bufs;
ctx->vertex_bufs = buf;
for (i = 0; i < TESS_VERTEX_ALLOC_BUNCH; i++) {
@@ -250,10 +243,7 @@ static TassVertex *bezier_flattener(InternaCtx *ctx, PathPoint *points)
for (i = 0; i < num_points - 2; i++) {
TassVertex *vertex;
- if (!(vertex = alloc_tess_vertex(ctx))) {
- //warn
- return NULL;
- }
+ vertex = alloc_tess_vertex(ctx);
vertex->list_link = vertex_list;
vertex_list = vertex;
}
@@ -288,27 +278,24 @@ static TassVertex *bezier_flattener(InternaCtx *ctx, PathPoint *points)
#define MORE_X(path, Type, name) { \
Type *name; \
\
- if (!(name = (Type *)zmalloc(sizeof(*name) * path->name##_size * 2))) { \
- return FALSE; \
- } \
+ name = spice_new0(Type, path->name##_size * 2); \
memcpy(name, path->name, sizeof(*name) * path->name##_size); \
free(path->name); \
path->name = name; \
path->name##_size *= 2; \
- return TRUE; \
}
-static int more_points(InternalPath *path)
+static void more_points(InternalPath *path)
{
MORE_X(path, PathPoint, points);
}
-static int more_segments(InternalPath *path)
+static void more_segments(InternalPath *path)
{
MORE_X(path, PathSegment, segments);
}
-static int more_paths(InternalPath *path)
+static void more_paths(InternalPath *path)
{
MORE_X(path, Path, paths);
}
@@ -329,9 +316,8 @@ void glc_path_move_to(GLCPath path, double x, double y)
if (internal->current_segment) {
internal->current_segment = NULL;
internal->current_path = NULL;
- if (internal->points_pos == internal->points_size && !more_points(internal)) {
- //warn
- return;
+ if (internal->points_pos == internal->points_size) {
+ more_points(internal);
}
internal->points_pos++;
}
@@ -340,37 +326,33 @@ void glc_path_move_to(GLCPath path, double x, double y)
internal->points[internal->points_pos - 1].z = 0;
}
-static int add_segment_common(InternalPath *internal, int type, int num_points)
+static void add_segment_common(InternalPath *internal, int type, int num_points)
{
- if (internal->points_size - internal->points_pos < num_points && !more_points(internal)) {
- //warn
- return FALSE;
+ if (internal->points_size - internal->points_pos < num_points) {
+ more_points(internal);
}
if (internal->current_segment) {
if (internal->current_segment->type == type) {
internal->current_segment->count++;
- return TRUE;
+ return;
}
- if (internal->segments_pos == internal->segments_size && !more_segments(internal)) {
- //warn
- return FALSE;
+ if (internal->segments_pos == internal->segments_size) {
+ more_segments(internal);
}
internal->current_segment = &internal->segments[internal->segments_pos++];
internal->current_segment->type = type;
internal->current_segment->count = 1;
internal->current_path->num_segments++;
- return TRUE;
+ return;
}
- if (internal->paths_pos == internal->paths_size && !more_paths(internal)) {
- //warn
- return FALSE;
+ if (internal->paths_pos == internal->paths_size) {
+ more_paths(internal);
}
- if (internal->segments_pos == internal->segments_size && !more_segments(internal)) {
- //warn
- return FALSE;
+ if (internal->segments_pos == internal->segments_size) {
+ more_segments(internal);
}
internal->current_path = &internal->paths[internal->paths_pos++];
@@ -379,7 +361,6 @@ static int add_segment_common(InternalPath *internal, int type, int num_points)
internal->current_segment = &internal->segments[internal->segments_pos++];
internal->current_segment->type = type;
internal->current_segment->count = 1;
- return TRUE;
}
void glc_path_line_to(GLCPath path, double x, double y)
@@ -388,9 +369,7 @@ void glc_path_line_to(GLCPath path, double x, double y)
ASSERT(internal);
- if (!add_segment_common(internal, GLC_PATH_SEG_LINES, 1)) {
- return;
- }
+ add_segment_common(internal, GLC_PATH_SEG_LINES, 1);
put_point(internal, x, y);
}
@@ -401,9 +380,7 @@ void glc_path_curve_to(GLCPath path, double p1_x, double p1_y, double p2_x, doub
ASSERT(internal);
- if (!add_segment_common(internal, GLC_PATH_SEG_BEIZER, 3)) {
- return;
- }
+ add_segment_common(internal, GLC_PATH_SEG_BEIZER, 3);
put_point(internal, p1_x, p1_y);
put_point(internal, p2_x, p2_y);
put_point(internal, p3_x, p3_y);
@@ -442,39 +419,19 @@ GLCPath glc_path_create(GLCCtx glc)
InternalPath *path;
ASSERT(ctx);
- if (!(path = (InternalPath *)zmalloc(sizeof(*path)))) {
- return NULL;
- }
+ path = spice_new0(InternalPath, 1);
+ path->paths_size = 2;
+ path->paths = spice_new(Path, path->paths_size);
- path->paths = (Path *)malloc(sizeof(*path->paths) * (path->paths_size = 2));
- if (!path->paths) {
- goto error_1;
- }
+ path->segments_size = 4;
+ path->segments = spice_new(PathSegment, path->segments_size);
- path->segments = (PathSegment *)malloc(sizeof(*path->segments) * (path->segments_size = 4));
- if (!path->segments) {
- goto error_2;
- }
-
- path->points = (PathPoint *)malloc(sizeof(*path->points) * (path->points_size = 20));
- if (!path->points) {
- goto error_3;
- }
+ path->points_size = 20;
+ path->points = spice_new(PathPoint, path->points_size);
path->owner = ctx;
path->points_pos = 1;
return path;
-
-error_3:
- free(path->segments);
-
-error_2:
- free(path->paths);
-
-error_1:
- free(path);
-
- return NULL;
}
void glc_path_destroy(GLCPath path)
@@ -559,10 +516,7 @@ static inline void init_pattern(InternalPat *pat, int x_orign, int y_orign, cons
ASSERT(height > 0 && height <= pat->owner->max_texture_size);
if (width2 != width || height2 != height) {
- if (!(tmp_pixmap = (uint32_t *)malloc(width2 * height2 * sizeof(uint32_t)))) {
- //warn
- return;
- }
+ tmp_pixmap = (uint32_t *)spice_malloc(width2 * height2 * sizeof(uint32_t));
scale(tmp_pixmap, width2, height2, (uint32_t *)image->pixels, width, height, image->stride);
}
@@ -607,9 +561,7 @@ GLCPattern glc_pattern_create(GLCCtx glc, int x_orign, int y_orign, const GLCIma
ASSERT(ctx && image);
- if (!(pat = (InternalPat *)zmalloc(sizeof(*pat)))) {
- return NULL;
- }
+ pat = spice_new0(InternalPat, 1);
pat->refs = 1;
pat->owner = ctx;
glGenTextures(1, &pat->texture);
@@ -704,11 +656,7 @@ void glc_set_line_dash(GLCCtx glc, const double *dashes, int num_dashes, double
ASSERT(ctx);
if (dashes && num_dashes >= 0 && offset >= 0) {
- ctx->line_dash.dashes = (double *)malloc(sizeof(double) * num_dashes);
- if (!ctx->line_dash.dashes) {
- // FIXME: error
- return;
- }
+ ctx->line_dash.dashes = spice_new(double, num_dashes);
memcpy(ctx->line_dash.dashes, dashes, sizeof(double) * num_dashes);
ctx->line_dash.num_dashes = num_dashes;
ctx->line_dash.offset = offset;
@@ -1420,10 +1368,7 @@ static void tessellation_combine(GLdouble coords[3], GLdouble *vertex_data[4], G
{
TassVertex *vertex;
- if (!(vertex = alloc_tess_vertex((InternaCtx *)usr_data))) {
- *data_out = NULL;
- return;
- }
+ vertex = alloc_tess_vertex((InternaCtx *)usr_data);
vertex->point.x = coords[0];
vertex->point.y = coords[1];
//vertex->point.z = coords[2];
@@ -1522,10 +1467,7 @@ GLCCtx glc_create(int width, int height)
ASSERT(sizeof(PathPoint) == sizeof(Vertex));
- if (!(ctx = (InternaCtx *)zmalloc(sizeof(*ctx)))) {
- return NULL;
- }
-
+ ctx = spice_new0(InternaCtx, 1);
if (!init(ctx, width, height)) {
free(ctx);
return NULL;
diff --git a/common/lines.c b/common/lines.c
index 5c07744..d2e997e 100644
--- a/common/lines.c
+++ b/common/lines.c
@@ -57,9 +57,10 @@ SOFTWARE.
#undef _XOPEN_SOURCE
#endif
#include "lines.h"
+#include "mem.h"
-#define xalloc(i) malloc(i)
-#define xrealloc(a,b) realloc(a,b)
+#define xalloc(i) spice_malloc(i)
+#define xrealloc(a,b) spice_realloc(a,b)
#define xfree(i) free(i)
typedef unsigned int CARD32;
diff --git a/common/pixman_utils.c b/common/pixman_utils.c
index 05ac03d..b946a1c 100644
--- a/common/pixman_utils.c
+++ b/common/pixman_utils.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include "mem.h"
#ifndef ASSERT
#define ASSERT(x) if (!(x)) { \
@@ -909,7 +910,7 @@ pixman_bool_t spice_pixman_region32_init_rects (pixman_region32_t *region,
if (count < 10) {
boxes = boxes_array;
} else {
- boxes = (pixman_box32_t *)malloc(sizeof(pixman_box32_t) * count);
+ boxes = spice_new(pixman_box32_t, count);
if (boxes == NULL) {
return FALSE;
}
diff --git a/common/region.c b/common/region.c
index 7edcb5a..95ac8ca 100644
--- a/common/region.c
+++ b/common/region.c
@@ -23,6 +23,7 @@
#include "region.h"
#include "rect.h"
+#include "mem.h"
#define ASSERT(x) if (!(x)) { \
printf("%s: ASSERT %s failed\n", __FUNCTION__, #x); \
@@ -352,7 +353,7 @@ SpiceRect *region_dup_rects(const QRegion *rgn, uint32_t *num_rects)
if (num_rects) {
*num_rects = n;
}
- rects = (SpiceRect *)malloc(sizeof(SpiceRect)*n);
+ rects = spice_new(SpiceRect, n);
for (i = 0; i < n; i++) {
rects[i].left = boxes[i].x1;
rects[i].top = boxes[i].y1;