diff options
author | reed <reed@chromium.org> | 2014-11-17 06:15:42 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-17 06:15:42 -0800 |
commit | 73c250112026b84b38e6dc8c93e0cfc31918dc9d (patch) | |
tree | fc1f9610535d407c8d2d262549337b0c9c72a558 /src/c | |
parent | 1379b87ae463246e586b869f7457ce5befc4472c (diff) |
separate c headers
BUG=skia:
Review URL: https://codereview.chromium.org/728323002
Diffstat (limited to 'src/c')
-rw-r--r-- | src/c/sk_surface.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/c/sk_surface.cpp b/src/c/sk_surface.cpp index ec16fc27fb..45a1ef9c32 100644 --- a/src/c/sk_surface.cpp +++ b/src/c/sk_surface.cpp @@ -5,6 +5,10 @@ * found in the LICENSE file. */ +#include "sk_canvas.h" +#include "sk_image.h" +#include "sk_paint.h" +#include "sk_path.h" #include "sk_surface.h" #include "SkCanvas.h" @@ -87,10 +91,34 @@ static bool from_c_info(const sk_imageinfo_t& cinfo, SkImageInfo* info) { return true; } +const struct { + sk_path_direction_t fC; + SkPath::Direction fSk; +} gPathDirMap[] = { + { CW_SK_PATH_DIRECTION, SkPath::kCW_Direction }, + { CCW_SK_PATH_DIRECTION, SkPath::kCCW_Direction }, +}; + +static bool from_c_path_direction(sk_path_direction_t cdir, SkPath::Direction* dir) { + for (size_t i = 0; i < SK_ARRAY_COUNT(gPathDirMap); ++i) { + if (gPathDirMap[i].fC == cdir) { + if (dir) { + *dir = gPathDirMap[i].fSk; + } + return true; + } + } + return false; +} + static const SkRect& AsRect(const sk_rect_t& crect) { return reinterpret_cast<const SkRect&>(crect); } +static SkRect* as_rect(sk_rect_t* crect) { + return reinterpret_cast<SkRect*>(crect); +} + static const SkPath& AsPath(const sk_path_t& cpath) { return reinterpret_cast<const SkPath&>(cpath); } @@ -208,10 +236,48 @@ 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_conic_to(sk_path_t* cpath, float x0, float y0, float x1, float y1, float w) { + as_path(cpath)->conicTo(x0, y0, x1, y1, w); +} + +void sk_path_cubic_to(sk_path_t* cpath, float x0, float y0, float x1, float y1, float x2, float y2) { + as_path(cpath)->cubicTo(x0, y0, x1, y1, x2, y2); +} + void sk_path_close(sk_path_t* cpath) { as_path(cpath)->close(); } +void sk_path_add_rect(sk_path_t* cpath, const sk_rect_t* crect, sk_path_direction_t cdir) { + SkPath::Direction dir; + if (!from_c_path_direction(cdir, &dir)) { + return; + } + as_path(cpath)->addRect(AsRect(*crect), dir); +} + +void sk_path_add_oval(sk_path_t* cpath, const sk_rect_t* crect, sk_path_direction_t cdir) { + SkPath::Direction dir; + if (!from_c_path_direction(cdir, &dir)) { + return; + } + as_path(cpath)->addOval(AsRect(*crect), dir); +} + +bool sk_path_get_bounds(const sk_path_t* cpath, sk_rect_t* crect) { + const SkPath& path = AsPath(*cpath); + SkRect* rect = as_rect(crect); + + if (path.isEmpty()) { + if (rect) { + rect->setEmpty(); + } + return false; + } + *rect = path.getBounds(); + return true; +} + /////////////////////////////////////////////////////////////////////////////////////////// void sk_canvas_save(sk_canvas_t* ccanvas) { |