diff options
author | robertphillips <robertphillips@google.com> | 2014-10-08 06:04:35 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-08 06:04:35 -0700 |
commit | a624e87e8e10fd9dc3a34e498dd30804ceee5228 (patch) | |
tree | 6ff34095e2b07f8b36325e9c617281b21a1cf7b8 /experimental/sk_surface.cpp | |
parent | 7663d66681a8b695b36701c6885935c60c0531c3 (diff) |
Implement C path functions
Mainly just to familiarize myself with this code.
Review URL: https://codereview.chromium.org/633183002
Diffstat (limited to 'experimental/sk_surface.cpp')
-rw-r--r-- | experimental/sk_surface.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/experimental/sk_surface.cpp b/experimental/sk_surface.cpp index 1158b42cdc..ae37c464b2 100644 --- a/experimental/sk_surface.cpp +++ b/experimental/sk_surface.cpp @@ -27,6 +27,10 @@ static const SkPath& AsPath(const sk_path_t& 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) { 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) { AsCanvas(ccanvas)->save(); } @@ -196,11 +226,20 @@ void sk_test_capi(SkCanvas* canvas) { sk_paint_set_color(cpaint, 0xFF00FF00); 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); // HERE WE CROSS THE C..C++ boundary canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); + sk_path_delete(cpath); sk_paint_delete(cpaint); sk_image_unref(cimage); sk_surface_delete(csurface); |