diff options
| author | Bryce Harrington <b.harrington@samsung.com> | 2014-04-24 15:30:10 -0700 |
|---|---|---|
| committer | Bryce Harrington <b.harrington@samsung.com> | 2014-04-24 15:30:10 -0700 |
| commit | 7dad0e570968a3da8625c54c03b2f5ded616e3a7 (patch) | |
| tree | ba8f33ec7b92cef2716f5cea10e158274b2f591f /src/cairo-shapes.cpp | |
| parent | d1f7a30fe297bd1346dfe38a801ffd52fcde4b54 (diff) | |
shapes: Avoid using malloc in performance sensitive drawing code
Also, fixes crash due to double-free
Diffstat (limited to 'src/cairo-shapes.cpp')
| -rw-r--r-- | src/cairo-shapes.cpp | 54 |
1 files changed, 19 insertions, 35 deletions
diff --git a/src/cairo-shapes.cpp b/src/cairo-shapes.cpp index 6f7cbfe..5d8673a 100644 --- a/src/cairo-shapes.cpp +++ b/src/cairo-shapes.cpp @@ -20,6 +20,7 @@ static int star_points[11][2] = { { 0, 85 } }; + void cairoRandomizeColor(caskbench_context_t *ctx) { @@ -38,52 +39,35 @@ void cairoDrawCircle(caskbench_context_t *ctx, shapes_t *args) cairo_arc (ctx->cairo_cr, args->centre_x, args->centre_y, args->radius, 0, 2*M_PI); } -void cairoDrawRectangle(caskbench_context_t *ctx, shapes_t *args) +void +cairoDrawRectangle(caskbench_context_t *ctx, shapes_t *args) { cairo_rectangle (ctx->cairo_cr, args->centre_x, args->centre_y, args->width, args->height); } -void cairoDrawTriangle(caskbench_context_t *ctx, shapes_t *args) -{ - ctx->shape_args.numpoints = 3; - ctx->shape_args.points = (double (*)[2]) malloc(ctx->shape_args.numpoints*2*(sizeof(double))); - ctx->shape_args.points[0][0] = ctx->shape_args.centre_x; - ctx->shape_args.points[0][1] = ctx->shape_args.centre_y+2*ctx->shape_args.radius; - ctx->shape_args.points[1][0] = 2*ctx->shape_args.radius; - ctx->shape_args.points[1][1] = 0; - ctx->shape_args.points[2][0] = -ctx->shape_args.radius; - ctx->shape_args.points[2][1] = -2*ctx->shape_args.radius; - - for (int p = 0; p < 3; p++ ) { - if(p == 0) - cairo_move_to (ctx->cairo_cr, args->points[p][0], args->points[0][1]); - else - cairo_rel_line_to (ctx->cairo_cr, args->points[p][0], args->points[p][1]); - } - free (ctx->shape_args.points); +void +cairoDrawTriangle(caskbench_context_t *ctx, shapes_t *args) +{ + cairo_move_to (ctx->cairo_cr, args->centre_x, args->centre_y+2*args->radius); + cairo_rel_line_to (ctx->cairo_cr, 2*args->radius, 0); + cairo_rel_line_to (ctx->cairo_cr, -args->radius, -2*args->radius); } -void cairoDrawStar(caskbench_context_t *ctx, shapes_t *args) -{ - ctx->shape_args.numpoints = 10; - ctx->shape_args.points = (double (*)[2]) malloc(ctx->shape_args.numpoints*2*(sizeof(double))); - for (int p = 0; p < 10; p++ ) { - int px = ctx->shape_args.centre_x + 2*ctx->shape_args.radius * star_points[p][0]/200.0; - int py = ctx->shape_args.centre_y + 2*ctx->shape_args.radius * star_points[p][1]/200.0; - ctx->shape_args.points[p][0] = px; - ctx->shape_args.points[p][1] = py; - } +void +cairoDrawStar(caskbench_context_t *ctx, shapes_t *args) +{ + int px = args->centre_x + 2*args->radius * star_points[0][0]/200.0; + int py = args->centre_y + 2*args->radius * star_points[0][1]/200.0; + cairo_move_to (ctx->cairo_cr, px, py); - for (int p = 0; p < args->numpoints; p++ ) { - if(p == 0) - cairo_move_to (ctx->cairo_cr, args->points[p][0], args->points[0][1]); - else - cairo_line_to (ctx->cairo_cr, args->points[p][0], args->points[p][1]); + for (int p = 1; p < 10; p++ ) { + px = args->centre_x + 2*args->radius * star_points[p][0]/200.0; + py = args->centre_y + 2*args->radius * star_points[p][1]/200.0; + cairo_line_to (ctx->cairo_cr, px, py); } cairo_close_path(ctx->cairo_cr); - free (ctx->shape_args.points); } |