Added the path ops features
authorMatthew Leibowitz <mattleibow@live.com>
Tue, 13 Sep 2016 23:48:26 +0000 (01:48 +0200)
committerMatthew Leibowitz <mattleibow@live.com>
Tue, 13 Sep 2016 23:48:26 +0000 (01:48 +0200)
include/c/sk_path.h
include/c/sk_types.h
src/c/sk_enums.cpp
src/c/sk_path.cpp
src/c/sk_types_priv.h

index c4b5bec..1385e83 100644 (file)
@@ -217,6 +217,20 @@ SK_API bool sk_path_contains (const sk_path_t* cpath, float x, float y);
 
 SK_API bool sk_path_get_last_point (const sk_path_t* cpath, sk_point_t* point);
 
+SK_API bool sk_pathop_op(const sk_path_t* one, const sk_path_t* two, sk_pathop_t op, sk_path_t* result);
+
+SK_API bool sk_pathop_simplify(const sk_path_t* path, sk_path_t* result);
+
+SK_API bool sk_pathop_tight_bounds(const sk_path_t* path, sk_rect_t* result);
+
+SK_API sk_opbuilder_t* sk_opbuilder_new();
+
+SK_API void sk_opbuilder_destroy(sk_opbuilder_t* builder);
+
+SK_API void sk_opbuilder_add(sk_opbuilder_t* builder, const sk_path_t* path, sk_pathop_t op);
+
+SK_API bool sk_opbuilder_resolve(sk_opbuilder_t* builder, sk_path_t* result);
+
 SK_C_PLUS_PLUS_END_GUARD
 
 #endif
index 2bfa770..7c48bfa 100644 (file)
@@ -622,6 +622,16 @@ typedef struct gr_glinterface_t gr_glinterface_t;
 typedef void (*gr_gl_func_ptr)();
 typedef gr_gl_func_ptr (*gr_gl_get_proc)(void* ctx, const char* name);
 
+typedef enum {
+    DIFFERENCE_SK_PATHOP,
+    INTERSECT_SK_PATHOP,
+    UNION_SK_PATHOP,
+    XOR_SK_PATHOP,
+    REVERSE_DIFFERENCE_SK_PATHOP,
+} sk_pathop_t;
+
+typedef struct sk_opbuilder_t sk_opbuilder_t;
+
 SK_C_PLUS_PLUS_END_GUARD
 
 #endif
index 7914289..0b5426a 100644 (file)
@@ -5,9 +5,6 @@
  * found in the LICENSE file.
  */
 
-#include "SkTypeface.h"
-#include "SkFontStyle.h"
-
 #include "sk_types_priv.h"
 
 #if __cplusplus >= 199711L
@@ -294,4 +291,11 @@ static_assert ((bool)SkBudgeted::kYes   == (bool)true,    ASSERT_MSG(SkBudgeted,
 static_assert ((int)0                                         == (int)NONE_GR_CONTEXT_FLUSHBITS,      ASSERT_MSG(GrContext::FlushBits, gr_context_flushbits_t));
 static_assert ((int)GrContext::FlushBits::kDiscard_FlushBit   == (int)DISCARD_GR_CONTEXT_FLUSHBITS,   ASSERT_MSG(GrContext::FlushBits, gr_context_flushbits_t));
 
+// sk_pathop_t
+static_assert ((int)SkPathOp::kDifference_SkPathOp          == (int)DIFFERENCE_SK_PATHOP,           ASSERT_MSG(SkPathOp, sk_pathop_t));
+static_assert ((int)SkPathOp::kIntersect_SkPathOp           == (int)INTERSECT_SK_PATHOP,            ASSERT_MSG(SkPathOp, sk_pathop_t));
+static_assert ((int)SkPathOp::kUnion_SkPathOp               == (int)UNION_SK_PATHOP,                ASSERT_MSG(SkPathOp, sk_pathop_t));
+static_assert ((int)SkPathOp::kXOR_SkPathOp                 == (int)XOR_SK_PATHOP,                  ASSERT_MSG(SkPathOp, sk_pathop_t));
+static_assert ((int)SkPathOp::kReverseDifference_SkPathOp   == (int)REVERSE_DIFFERENCE_SK_PATHOP,   ASSERT_MSG(SkPathOp, sk_pathop_t));
+
 #endif
index ba938ee..c5128d3 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "SkPath.h"
+#include "SkPathOps.h"
 
 #include "sk_path.h"
 
@@ -253,3 +254,31 @@ bool sk_path_get_last_point (const sk_path_t* cpath, sk_point_t* point) {
         return false;
     }
 }
+
+bool sk_pathop_op(const sk_path_t* one, const sk_path_t* two, sk_pathop_t op, sk_path_t* result) {
+    return Op(AsPath(*one), AsPath(*two), (SkPathOp)op, AsPath(result));
+}
+
+bool sk_pathop_simplify(const sk_path_t* path, sk_path_t* result) {
+    return Simplify(AsPath(*path), AsPath(result));
+}
+
+bool sk_pathop_tight_bounds(const sk_path_t* path, sk_rect_t* result) {
+    return TightBounds(AsPath(*path), AsRect(result));
+}
+
+sk_opbuilder_t* sk_opbuilder_new() {
+    return ToOpBuilder(new SkOpBuilder());
+}
+
+void sk_opbuilder_destroy(sk_opbuilder_t* builder) {
+    delete AsOpBuilder(builder);
+}
+
+void sk_opbuilder_add(sk_opbuilder_t* builder, const sk_path_t* path, sk_pathop_t op) {
+    AsOpBuilder(builder)->add(AsPath(*path), (SkPathOp)op);
+}
+
+bool sk_opbuilder_resolve(sk_opbuilder_t* builder, sk_path_t* result) {
+    return AsOpBuilder(builder)->resolve(AsPath(result));
+}
index e77e809..5b452f4 100644 (file)
@@ -25,6 +25,8 @@
 #include "Sk1DPathEffect.h"
 #include "SkFontStyle.h"
 #include "GrContext.h"
+#include "SkPathOps.h"
+#include "SkTypeface.h"
 #include "gl/GrGLInterface.h"
 
 #include "sk_path.h"
@@ -486,6 +488,14 @@ static inline const GrGLInterface* AsGrGLInterface(const gr_glinterface_t* p) {
     return reinterpret_cast<const GrGLInterface*>(p);
 }
 
+static inline sk_opbuilder_t* ToOpBuilder(SkOpBuilder* p) {
+    return reinterpret_cast<sk_opbuilder_t*>(p);
+}
+
+static inline SkOpBuilder* AsOpBuilder(sk_opbuilder_t* p) {
+    return reinterpret_cast<SkOpBuilder*>(p);
+}
+
 static inline void from_c(const sk_matrix_t* cmatrix, SkMatrix* matrix) {
     matrix->setAll(
         cmatrix->mat[0], cmatrix->mat[1], cmatrix->mat[2],