Exemple #1
0
int
sk_test_circle(caskbench_context_t *ctx)
{
    int w = ctx->canvas_width;
    int h = ctx->canvas_height;

    shapes_t shape;
    shape_copy(&ctx->shape_defaults, &shape);
    for (int i=0; i<ctx->size; i++) {
        shape.x = (double)rnd()/RAND_MAX * w;
        shape.y = (double)rnd()/RAND_MAX * h;
        shape.radius = (double)rnd()/RAND_MAX * MIN(
            MIN(shape.x, w-shape.x), MIN(shape.y, h-shape.y));

        if (ctx->shape_defaults.fill_type == CB_FILL_RANDOM) {
            shape.fill_type = generate_random_fill_type();
        }
        sk_set_fill_style(ctx, &shape);

        shape.shape_type = CB_SHAPE_CIRCLE;
        skiaDrawRandomizedShape(ctx,&shape);
    }

    return 1;
}
Exemple #2
0
int
sk_test_roundrect(caskbench_context_t *ctx)
{
    int i;
    double line_width, x, y, radius;

    for (i=0; i<ctx->size; i++) {
        shapes_t shape;
        shape_copy(&ctx->shape_defaults, &shape);

        skiaRandomizePaintColor(ctx);

        shape.x = trunc( (((double)ctx->canvas_width-20)*rnd())/RAND_MAX ) + 10;
        shape.y = trunc( (((double)ctx->canvas_height-20)*rnd())/RAND_MAX ) + 10;

        /* vary radius upto half of MIN(X,Y) */
        shape.radius = (double)rnd()/RAND_MAX * 20;
        shape.width = 100;
        shape.height = 40;

        /* line_width cannot be more than twice of radius due to skia limitation - Issue #4 in skia https://github.com/Samsung/skia/issues/4 */
        shape.stroke_width = (double)rnd()/RAND_MAX * (2*shape.radius);

        ctx->skia_paint->setStrokeWidth(shape.stroke_width);

        skiaDrawRoundedRectangle (ctx, &shape);
    }

    return 1;
}
Exemple #3
0
// reproject shape
shape_t*
shape_proj(
    const shape_t* shape,
    const char*    from,
    const char*    to   ){

    shape_t* projected = shape_copy(shape);
    projPJ old_prj = pj_init_plus(from);
    projPJ new_prj = pj_init_plus(to);

    for(uint32_t i=0; i<kv_size(projected->points); i++) {
        point_t* p = &kv_A(projected->points, i);
        p->x *= DEG_TO_RAD;
        p->y *= DEG_TO_RAD;
        int32_t err = pj_transform(old_prj, new_prj, 1, 0, &p->x, &p->y, NULL);
        if (err)
            fprintf(stderr, "ERR%d %s\n", err, pj_strerrno(err));
        assert(err == 0);
    }

    for(uint32_t i=0; i<kv_size(projected->hull); i++) {
        point_t* p = &kv_A(projected->hull, i);
        p->x *= DEG_TO_RAD;
        p->y *= DEG_TO_RAD;
        int32_t err = pj_transform(old_prj, new_prj, 1, 0, &p->x, &p->y, NULL);
        if (err)
            fprintf(stderr, "ERR%d %s\n", err, pj_strerrno(err));
        assert(err == 0);
    }

    pj_free(old_prj);
    pj_free(new_prj);

    return projected;
}
int
sk_test_linear_gradient(caskbench_context_t *ctx)
{
    int w = ctx->canvas_width;
    int h = ctx->canvas_height;
    int stops = 10;

    SkPoint pts[2];
    pts[0].iset(0, 0);
    pts[1].iset(100, 100);
    SkColor colors[10];
    SkScalar pos[10];

    for (int i = 0; i < stops; i++) {
        pos[i] = i / SkIntToScalar(stops - 1);
        colors[i] = skiaRandomColor();
    }

    SkShader *shader = SkGradientShader::CreateLinear(pts, colors, pos, stops,
                                          SkShader::kClamp_TileMode);
    ctx->skia_paint->setShader(shader);

    shapes_t shape;
    shape_copy(&ctx->shape_defaults, &shape);
    for (int i=0; i<ctx->size; i++) {
        double x1 = (double)rnd()/RAND_MAX * w;
        double x2 = (double)rnd()/RAND_MAX * w;
        double y1 = (double)rnd()/RAND_MAX * h;
        double y2 = (double)rnd()/RAND_MAX * h;

        double xx = MIN(x1, x2);
        double yy = MIN(x1, x2);
        double ww = abs(x2 - x1);
        double hh = abs(y2 - y1);

        ctx->skia_canvas->save();
        ctx->skia_canvas->translate(SkDoubleToScalar(xx), SkDoubleToScalar(yy));
        ctx->skia_canvas->scale(SkDoubleToScalar(ww/100), SkDoubleToScalar(hh/100));

        // transform(shape.width/100, 0, 0, shape.height/100, 0, 0)
        shape.x = 0;
        shape.y = 0;
        shape.width = 100;
        shape.height = 100;
        shape.fill_type = CB_FILL_LINEAR_GRADIENT;

        ctx->skia_paint->setStyle(SkPaint::kFill_Style);
        ctx->skia_paint->setShader(shader);

        skiaDrawRectangle(ctx, &shape);

        ctx->skia_canvas->restore();
    }
    if (shader)
        shader->unref();

    return 1;
}
Exemple #5
0
int
sk_test_vline(caskbench_context_t *ctx)
{
    int w = ctx->canvas_width;
    int h = ctx->canvas_height;

    shapes_t shape;
    shape_copy(&ctx->shape_defaults, &shape);
    for (int i=0; i<ctx->size; i++) {
        double x = (double)rnd()/RAND_MAX * w;
        double y1 = (double)rnd()/RAND_MAX * h;
        double y2 = (double)rnd()/RAND_MAX * h;

        shape.x = x;
        shape.y = y1;
        shape.width = 0;
        shape.height = y1 - y2;

        skiaRandomizePaintColor(ctx);
        skiaDrawLine(ctx, &shape);
    }

    return 1;
}