From 84542ff11495bdf5ead30821bdf8b04564a9571e Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Sun, 3 Jul 2016 00:10:18 -0400 Subject: [PATCH] [C API] Add sk_path's iterators, and add the missing sk_matrix methods that I lost --- include/c/xamarin/sk_x_matrix.h | 1 + include/c/xamarin/sk_x_path.h | 11 ++++ include/c/xamarin/sk_x_types.h | 13 +++++ src/c/xamarin/sk_x_matrix.cpp | 100 ++++++++++++++++++++++++++++++++ src/c/xamarin/sk_x_path.cpp | 39 +++++++++++++ src/c/xamarin/sk_x_types_priv.h | 14 +++++ 6 files changed, 178 insertions(+) create mode 100644 include/c/xamarin/sk_x_matrix.h create mode 100644 src/c/xamarin/sk_x_matrix.cpp diff --git a/include/c/xamarin/sk_x_matrix.h b/include/c/xamarin/sk_x_matrix.h new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/include/c/xamarin/sk_x_matrix.h @@ -0,0 +1 @@ + diff --git a/include/c/xamarin/sk_x_path.h b/include/c/xamarin/sk_x_path.h index 5ffc788e3a..d8363ade3b 100644 --- a/include/c/xamarin/sk_x_path.h +++ b/include/c/xamarin/sk_x_path.h @@ -75,6 +75,17 @@ SK_API void sk_path_transform(sk_path_t* cpath, const sk_matrix_t* cmatrix); Creates a copy of the path */ SK_API sk_path_t* sk_path_clone(const sk_path_t* cpath); + +SK_API sk_path_iterator_t* sk_path_create_iter (sk_path_t *cpath, int forceClose); + +SK_API sk_path_verb_t sk_path_iter_next (sk_path_iterator_t *iterator, sk_point_t points [4], int doConsumeDegenerates, int exact); + +SK_API float sk_path_iter_conic_weight (sk_path_iterator_t *iterator); + +SK_API int sk_path_iter_is_close_line (sk_path_iterator_t *iterator); + +SK_API int sk_path_iter_is_closed_contour (sk_path_iterator_t *iterator); + SK_C_PLUS_PLUS_END_GUARD #endif diff --git a/include/c/xamarin/sk_x_types.h b/include/c/xamarin/sk_x_types.h index 8d4e7f0f0b..e3a9c69ff5 100644 --- a/include/c/xamarin/sk_x_types.h +++ b/include/c/xamarin/sk_x_types.h @@ -222,6 +222,19 @@ typedef enum { REPLACE_SK_REGION_OP, //!< replace the dst region with the op region } sk_region_op_t; +// The verbs that can be foudn on a path +typedef enum { + MOVE_PATH_VERB, + LINE_PATH_VERB, + QUAD_PATH_VERB, + CONIC_PATH_VERB, + CUBIC_PATH_VERB, + CLOSE_PATH_VERB, + DONE_PATH_VERB +} sk_path_verb_t; + +typedef struct sk_path_iterator_t sk_path_iterator_t; + SK_C_PLUS_PLUS_END_GUARD #endif diff --git a/src/c/xamarin/sk_x_matrix.cpp b/src/c/xamarin/sk_x_matrix.cpp new file mode 100644 index 0000000000..85c05f5b50 --- /dev/null +++ b/src/c/xamarin/sk_x_matrix.cpp @@ -0,0 +1,100 @@ +/* + * Copyright 2016 Xamarin Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkStream.h" + +#include "xamarin/sk_x_matrix.h" + +#include "../sk_types_priv.h" +#include "sk_x_types_priv.h" + +int sk_matrix_try_invert (sk_matrix_t *matrix, sk_matrix_t *result) +{ + SkMatrix copy, inverse; + from_c (matrix, ©); + if (copy.invert (&inverse)){ + from_sk (&inverse, result); + return 1; + } + return 0; +} + +void sk_matrix_concat (sk_matrix_t *matrix, sk_matrix_t *first, sk_matrix_t *second) +{ + SkMatrix target, skfirst, sksecond; + + from_c (matrix, &target); + from_c (first, &skfirst); + from_c (second, &sksecond); + target.setConcat (skfirst, sksecond); + from_sk (&target, matrix); +} + +void sk_matrix_pre_concat (sk_matrix_t *target, sk_matrix_t *matrix) +{ + SkMatrix sktarget, skmatrix; + from_c (target, &sktarget); + from_c (matrix, &skmatrix); + sktarget.preConcat (skmatrix); + from_sk (&sktarget, target); +} + +void sk_matrix_post_concat (sk_matrix_t *target, sk_matrix_t *matrix) +{ + SkMatrix sktarget, skmatrix; + from_c (target, &sktarget); + from_c (matrix, &skmatrix); + sktarget.postConcat (skmatrix); + from_sk (&sktarget, target); +} + +void sk_matrix_map_rect (sk_matrix_t *matrix, sk_rect_t *dest, sk_rect_t *source) +{ + SkMatrix skmatrix; + from_c (matrix, &skmatrix); + skmatrix.mapRect (AsRect (dest), *AsRect(source)); +} + +void sk_matrix_map_points (sk_matrix_t *matrix, sk_point_t *dst, sk_point_t *src, int count) +{ + SkMatrix skmatrix; + from_c (matrix, &skmatrix); + skmatrix.mapPoints (AsPoint (dst), AsPoint (src), count); +} + +void sk_matrix_map_vectors (sk_matrix_t *matrix, sk_point_t *dst, sk_point_t *src, int count) +{ + SkMatrix skmatrix; + from_c (matrix, &skmatrix); + skmatrix.mapVectors (AsPoint (dst), AsPoint (src), count); +} + +sk_point_t sk_matrix_map_xy (sk_matrix_t *matrix, float x, float y) +{ + SkMatrix skmatrix; + SkPoint result; + from_c (matrix, &skmatrix); + skmatrix.mapXY (x, y, &result); + return *ToPoint(&result); +} + +sk_point_t sk_matrix_map_vector (sk_matrix_t *matrix, float x, float y) +{ + SkMatrix skmatrix; + SkPoint result; + from_c (matrix, &skmatrix); + skmatrix.mapVector (x, y, &result); + return *ToPoint(&result); +} + +float sk_matrix_map_radius (sk_matrix_t *matrix, float radius) +{ + SkMatrix skmatrix; + from_c (matrix, &skmatrix); + return skmatrix.mapRadius (radius); +} + diff --git a/src/c/xamarin/sk_x_path.cpp b/src/c/xamarin/sk_x_path.cpp index 93f6066ca2..c36d2d1531 100644 --- a/src/c/xamarin/sk_x_path.cpp +++ b/src/c/xamarin/sk_x_path.cpp @@ -83,3 +83,42 @@ void sk_path_reset (sk_path_t* cpath) { as_path (cpath)->reset (); } + +sk_path_iterator_t* sk_path_create_iter (sk_path_t *cpath, int forceClose) +{ + SkPath::Iter* iter = new SkPath::Iter(AsPath(*cpath), forceClose); + return ToPathIter(iter); +} + +#if __cplusplus >= 199711L +static_assert (SkPath::kMove_Verb == MOVE_PATH_VERB, "ABI changed, you must write a enumeration mapper for SkPath::Verb to sk_path_verb_t"); +static_assert (SkPath::kLine_Verb == LINE_PATH_VERB, "ABI changed, you must write a enumeration mapper for SkPath::Verb to sk_path_verb_t"); +static_assert (SkPath::kQuad_Verb == QUAD_PATH_VERB, "ABI changed, you must write a enumeration mapper for SkPath::Verb to sk_path_verb_t"); +static_assert (SkPath::kConic_Verb == CONIC_PATH_VERB, "ABI changed, you must write a enumeration mapper for SkPath::Verb to sk_path_verb_t"); +static_assert (SkPath::kCubic_Verb == CUBIC_PATH_VERB, "ABI changed, you must write a enumeration mapper for SkPath::Verb to sk_path_verb_t"); +static_assert (SkPath::kClose_Verb == CLOSE_PATH_VERB, "ABI changed, you must write a enumeration mapper for SkPath::Verb to sk_path_verb_t"); +static_assert (SkPath::kDone_Verb == DONE_PATH_VERB, "ABI changed, you must write a enumeration mapper for SkPath::Verb to sk_path_verb_t"); +#endif + +sk_path_verb_t sk_path_iter_next (sk_path_iterator_t *iterator, sk_point_t points [4], int doConsumeDegenerates, int exact) +{ + SkPath::Iter *iter = AsPathIter(iterator); + SkPoint *pts = AsPoint(points); + SkPath::Verb verb = iter->next(pts, doConsumeDegenerates, exact); + return (sk_path_verb_t)verb; +} + +float sk_path_iter_conic_weight (sk_path_iterator_t *iterator) +{ + return AsPathIter(iterator)->conicWeight (); +} + +int sk_path_iter_is_close_line (sk_path_iterator_t *iterator) +{ + return AsPathIter(iterator)->isCloseLine (); +} + +int sk_path_iter_is_closed_contour (sk_path_iterator_t *iterator) +{ + return AsPathIter(iterator)->isClosedContour (); +} diff --git a/src/c/xamarin/sk_x_types_priv.h b/src/c/xamarin/sk_x_types_priv.h index 8a2e0334e0..f0ef81183d 100644 --- a/src/c/xamarin/sk_x_types_priv.h +++ b/src/c/xamarin/sk_x_types_priv.h @@ -650,6 +650,14 @@ static inline const SkPoint* AsPoint(const sk_point_t* p) { return reinterpret_cast(p); } +static inline SkPoint* AsPoint(sk_point_t* p) { + return reinterpret_cast(p); +} + +static inline sk_point_t* ToPoint(SkPoint *p) { + return reinterpret_cast(p); +} + static inline const SkIPoint& AsIPoint(const sk_ipoint_t& p) { return reinterpret_cast(p); } @@ -714,5 +722,11 @@ static inline sk_document_t* ToDocument(SkDocument* document) { return reinterpret_cast(document); } +static inline SkPath::Iter* AsPathIter(sk_path_iterator_t* iter) { + return reinterpret_cast(iter); +} +static inline sk_path_iterator_t* ToPathIter(SkPath::Iter* iter) { + return reinterpret_cast(iter); +} #endif -- 2.34.1