Implement C path functions

Mainly just to familiarize myself with this code.

Review URL: https://codereview.chromium.org/633183002
This commit is contained in:
robertphillips 2014-10-08 06:04:35 -07:00 committed by Commit bot
parent 7663d66681
commit a624e87e8e
3 changed files with 44 additions and 2 deletions

View File

@ -27,6 +27,10 @@ static const SkPath& AsPath(const sk_path_t& cpath) {
return reinterpret_cast<const SkPath&>(cpath); return reinterpret_cast<const SkPath&>(cpath);
} }
static SkPath* as_path(sk_path_t* cpath) {
return reinterpret_cast<SkPath*>(cpath);
}
static const SkImage* AsImage(const sk_image_t* cimage) { static const SkImage* AsImage(const sk_image_t* cimage) {
return reinterpret_cast<const SkImage*>(cimage); return reinterpret_cast<const SkImage*>(cimage);
} }
@ -102,6 +106,32 @@ void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
sk_path_t* sk_path_new() {
return (sk_path_t*)SkNEW(SkPath);
}
void sk_path_delete(sk_path_t* cpath) {
SkDELETE(as_path(cpath));
}
void sk_path_move_to(sk_path_t* cpath, float x, float y) {
as_path(cpath)->moveTo(x, y);
}
void sk_path_line_to(sk_path_t* cpath, float x, float y) {
as_path(cpath)->lineTo(x, y);
}
void sk_path_quad_to(sk_path_t* cpath, float x0, float y0, float x1, float y1) {
as_path(cpath)->quadTo(x0, y0, x1, y1);
}
void sk_path_close(sk_path_t* cpath) {
as_path(cpath)->close();
}
///////////////////////////////////////////////////////////////////////////////////////////
void sk_canvas_save(sk_canvas_t* ccanvas) { void sk_canvas_save(sk_canvas_t* ccanvas) {
AsCanvas(ccanvas)->save(); AsCanvas(ccanvas)->save();
} }
@ -196,11 +226,20 @@ void sk_test_capi(SkCanvas* canvas) {
sk_paint_set_color(cpaint, 0xFF00FF00); sk_paint_set_color(cpaint, 0xFF00FF00);
sk_canvas_draw_rect(ccanvas, &cr, cpaint); sk_canvas_draw_rect(ccanvas, &cr, cpaint);
sk_path_t* cpath = sk_path_new();
sk_path_move_to(cpath, 50, 50);
sk_path_line_to(cpath, 100, 100);
sk_path_line_to(cpath, 50, 100);
sk_path_close(cpath);
sk_canvas_draw_path(ccanvas, cpath, cpaint);
sk_image_t* cimage = sk_surface_new_image_snapshot(csurface); sk_image_t* cimage = sk_surface_new_image_snapshot(csurface);
// HERE WE CROSS THE C..C++ boundary // HERE WE CROSS THE C..C++ boundary
canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); canvas->drawImage((const SkImage*)cimage, 20, 20, NULL);
sk_path_delete(cpath);
sk_paint_delete(cpaint); sk_paint_delete(cpaint);
sk_image_unref(cimage); sk_image_unref(cimage);
sk_surface_delete(csurface); sk_surface_delete(csurface);

View File

@ -52,16 +52,17 @@ typedef struct {
typedef struct sk_path_t sk_path_t; typedef struct sk_path_t sk_path_t;
sk_path_t* sk_path_new(); sk_path_t* sk_path_new();
void sk_path_delete(sk_path_t*);
void sk_path_move_to(sk_path_t*, float x, float y); void sk_path_move_to(sk_path_t*, float x, float y);
void sk_path_line_to(sk_path_t*, float x, float y); void sk_path_line_to(sk_path_t*, float x, float y);
void sk_path_quad_to(sk_path_t*, float x0, float y0, float x1, float y1); void sk_path_quad_to(sk_path_t*, float x0, float y0, float x1, float y1);
void sk_path_get_bounds(const sk_path_t*, sk_rect_t*); void sk_path_close(sk_path_t*);
typedef struct sk_paint_t sk_paint_t; typedef struct sk_paint_t sk_paint_t;
sk_paint_t* sk_paint_new(); sk_paint_t* sk_paint_new();
void sk_paint_delete(sk_paint_t*); void sk_paint_delete(sk_paint_t*);
bool sk_paint_is_antialias(sk_paint_t*); bool sk_paint_is_antialias(const sk_paint_t*);
void sk_paint_set_antialias(sk_paint_t*, bool); void sk_paint_set_antialias(sk_paint_t*, bool);
sk_color_t sk_paint_get_color(const sk_paint_t*); sk_color_t sk_paint_get_color(const sk_paint_t*);
void sk_paint_set_color(sk_paint_t*, sk_color_t); void sk_paint_set_color(sk_paint_t*, sk_color_t);

View File

@ -12,6 +12,8 @@
'../experimental/SkSetPoly3To3.cpp', '../experimental/SkSetPoly3To3.cpp',
'../experimental/SkSetPoly3To3_A.cpp', '../experimental/SkSetPoly3To3_A.cpp',
'../experimental/SkSetPoly3To3_D.cpp', '../experimental/SkSetPoly3To3_D.cpp',
'../experimental/sk_surface.h',
'../experimental/sk_surface.cpp',
], ],
'direct_dependent_settings': { 'direct_dependent_settings': {
'include_dirs': [ 'include_dirs': [