aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed <reed@chromium.org>2015-01-10 17:59:31 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-01-10 17:59:31 -0800
commitf5872d2f416b17db405f501a910ca0a4bd96f6e2 (patch)
treeeb378d3961ab547651074820d620698e3275c987
parent9e398f79c95640359847a153f53f30a2823be40c (diff)
add stroke params to c api
BUG=skia: TBR= Review URL: https://codereview.chromium.org/848553002
-rw-r--r--gyp/core.gypi3
-rw-r--r--include/c/sk_paint.h29
-rw-r--r--src/c/sk_c_from_to.h34
-rw-r--r--src/c/sk_paint.cpp135
-rw-r--r--src/c/sk_surface.cpp59
-rw-r--r--src/c/sk_types_priv.h41
6 files changed, 242 insertions, 59 deletions
diff --git a/gyp/core.gypi b/gyp/core.gypi
index 7d05cbde09..c5cecb666e 100644
--- a/gyp/core.gypi
+++ b/gyp/core.gypi
@@ -7,8 +7,9 @@
#
{
'sources': [
+ '<(skia_src_path)/c/sk_paint.cpp',
'<(skia_src_path)/c/sk_surface.cpp',
- '<(skia_include_path)/c/sk_surface.h',
+ '<(skia_src_path)/c/sk_types_priv.h',
'<(skia_src_path)/core/SkAAClip.cpp',
'<(skia_src_path)/core/SkAnnotation.cpp',
diff --git a/include/c/sk_paint.h b/include/c/sk_paint.h
index e6b5cbdb82..481147f1e5 100644
--- a/include/c/sk_paint.h
+++ b/include/c/sk_paint.h
@@ -24,6 +24,35 @@ void sk_paint_set_antialias(sk_paint_t*, bool);
sk_color_t sk_paint_get_color(const sk_paint_t*);
void sk_paint_set_color(sk_paint_t*, sk_color_t);
+/* stroke settings */
+
+bool sk_paint_is_stroke(const sk_paint_t*);
+void sk_paint_set_stroke(sk_paint_t*, bool);
+
+float sk_paint_get_stroke_width(const sk_paint_t*);
+void sk_paint_set_stroke_width(sk_paint_t*, float width);
+
+float sk_paint_get_stroke_miter(const sk_paint_t*);
+void sk_paint_set_stroke_miter(sk_paint_t*, float miter);
+
+typedef enum {
+ BUTT_SK_STROKE_CAP,
+ ROUND_SK_STROKE_CAP,
+ SQUARE_SK_STROKE_CAP
+} sk_stroke_cap_t;
+
+sk_stroke_cap_t sk_paint_get_stroke_cap(const sk_paint_t*);
+void sk_paint_set_stroke_cap(sk_paint_t*, sk_stroke_cap_t);
+
+typedef enum {
+ MITER_SK_STROKE_JOIN,
+ ROUND_SK_STROKE_JOIN,
+ BEVEL_SK_STROKE_JOIN
+} sk_stroke_join_t;
+
+sk_stroke_join_t sk_paint_get_stroke_join(const sk_paint_t*);
+void sk_paint_set_stroke_join(sk_paint_t*, sk_stroke_join_t);
+
/**
* Set the paint's shader to the specified parameter. This will automatically call unref() on
* any previous value, and call ref() on the new value.
diff --git a/src/c/sk_c_from_to.h b/src/c/sk_c_from_to.h
new file mode 100644
index 0000000000..19fda37a26
--- /dev/null
+++ b/src/c/sk_c_from_to.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+static bool find_sk(CType from, SKType* to) {
+ for (size_t i = 0; i < SK_ARRAY_COUNT(CTypeSkTypeMap); ++i) {
+ if (CTypeSkTypeMap[i].fC == from) {
+ if (to) {
+ *to = CTypeSkTypeMap[i].fSK;
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
+static bool find_c(SKType from, CType* to) {
+ for (size_t i = 0; i < SK_ARRAY_COUNT(CTypeSkTypeMap); ++i) {
+ if (CTypeSkTypeMap[i].fSK == from) {
+ if (to) {
+ *to = CTypeSkTypeMap[i].fC;
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
+#undef CType
+#undef SKType
+#undef CTypeSkTypeMap
diff --git a/src/c/sk_paint.cpp b/src/c/sk_paint.cpp
new file mode 100644
index 0000000000..e71285d4d5
--- /dev/null
+++ b/src/c/sk_paint.cpp
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "sk_paint.h"
+#include "sk_types_priv.h"
+
+#include "SkPaint.h"
+
+#define MAKE_FROM_TO_NAME(FROM) g_ ## FROM ## _map
+
+const struct {
+ sk_stroke_cap_t fC;
+ SkPaint::Cap fSK;
+} MAKE_FROM_TO_NAME(sk_stroke_cap_t)[] = {
+ { BUTT_SK_STROKE_CAP, SkPaint::kButt_Cap },
+ { ROUND_SK_STROKE_CAP, SkPaint::kRound_Cap },
+ { SQUARE_SK_STROKE_CAP, SkPaint::kSquare_Cap },
+};
+
+const struct {
+ sk_stroke_join_t fC;
+ SkPaint::Join fSK;
+} MAKE_FROM_TO_NAME(sk_stroke_join_t)[] = {
+ { MITER_SK_STROKE_JOIN, SkPaint::kMiter_Join },
+ { ROUND_SK_STROKE_JOIN, SkPaint::kRound_Join },
+ { BEVEL_SK_STROKE_JOIN, SkPaint::kBevel_Join },
+};
+
+#define CType sk_stroke_cap_t
+#define SKType SkPaint::Cap
+#define CTypeSkTypeMap MAKE_FROM_TO_NAME(sk_stroke_cap_t)
+#include "sk_c_from_to.h"
+
+#define CType sk_stroke_join_t
+#define SKType SkPaint::Join
+#define CTypeSkTypeMap MAKE_FROM_TO_NAME(sk_stroke_join_t)
+#include "sk_c_from_to.h"
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+sk_paint_t* sk_paint_new() {
+ return (sk_paint_t*)SkNEW(SkPaint);
+}
+
+void sk_paint_delete(sk_paint_t* cpaint) {
+ SkDELETE(AsPaint(cpaint));
+}
+
+bool sk_paint_is_antialias(const sk_paint_t* cpaint) {
+ return AsPaint(*cpaint).isAntiAlias();
+}
+
+void sk_paint_set_antialias(sk_paint_t* cpaint, bool aa) {
+ AsPaint(cpaint)->setAntiAlias(aa);
+}
+
+sk_color_t sk_paint_get_color(const sk_paint_t* cpaint) {
+ return AsPaint(*cpaint).getColor();
+}
+
+void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) {
+ AsPaint(cpaint)->setColor(c);
+}
+
+void sk_paint_set_shader(sk_paint_t* cpaint, sk_shader_t* cshader) {
+ AsPaint(cpaint)->setShader(AsShader(cshader));
+}
+
+void sk_paint_set_maskfilter(sk_paint_t* cpaint, sk_maskfilter_t* cfilter) {
+ AsPaint(cpaint)->setMaskFilter(AsMaskFilter(cfilter));
+}
+
+bool sk_paint_is_stroke(const sk_paint_t* cpaint) {
+ return AsPaint(*cpaint).getStyle() != SkPaint::kFill_Style;
+}
+
+void sk_paint_set_stroke(sk_paint_t* cpaint, bool doStroke) {
+ AsPaint(cpaint)->setStyle(doStroke ? SkPaint::kStroke_Style : SkPaint::kFill_Style);
+}
+
+float sk_paint_get_stroke_width(const sk_paint_t* cpaint) {
+ return AsPaint(*cpaint).getStrokeWidth();
+}
+
+void sk_paint_set_stroke_width(sk_paint_t* cpaint, float width) {
+ AsPaint(cpaint)->setStrokeWidth(width);
+}
+
+float sk_paint_get_stroke_miter(const sk_paint_t* cpaint) {
+ return AsPaint(*cpaint).getStrokeMiter();
+}
+
+void sk_paint_set_stroke_miter(sk_paint_t* cpaint, float miter) {
+ AsPaint(cpaint)->setStrokeMiter(miter);
+}
+
+sk_stroke_cap_t sk_paint_get_stroke_cap(const sk_paint_t* cpaint) {
+ sk_stroke_cap_t ccap;
+ if (find_c(AsPaint(*cpaint).getStrokeCap(), &ccap)) {
+ ccap = BUTT_SK_STROKE_CAP;
+ }
+ return ccap;
+}
+
+void sk_paint_set_stroke_cap(sk_paint_t* cpaint, sk_stroke_cap_t ccap) {
+ SkPaint::Cap skcap;
+ if (find_sk(ccap, &skcap)) {
+ AsPaint(cpaint)->setStrokeCap(skcap);
+ } else {
+ // unknown ccap
+ }
+}
+
+sk_stroke_join_t sk_paint_get_stroke_join(const sk_paint_t* cpaint) {
+ sk_stroke_join_t cjoin;
+ if (find_c(AsPaint(*cpaint).getStrokeJoin(), &cjoin)) {
+ cjoin = MITER_SK_STROKE_JOIN;
+ }
+ return cjoin;
+}
+
+void sk_paint_set_stroke_join(sk_paint_t* cpaint, sk_stroke_join_t cjoin) {
+ SkPaint::Join skjoin;
+ if (find_sk(cjoin, &skjoin)) {
+ AsPaint(cpaint)->setStrokeJoin(skjoin);
+ } else {
+ // unknown cjoin
+ }
+}
+
+
diff --git a/src/c/sk_surface.cpp b/src/c/sk_surface.cpp
index 89b53d0a0e..15f68dba11 100644
--- a/src/c/sk_surface.cpp
+++ b/src/c/sk_surface.cpp
@@ -11,6 +11,7 @@
#include "sk_paint.h"
#include "sk_path.h"
#include "sk_surface.h"
+#include "sk_types_priv.h"
#include "SkCanvas.h"
#include "SkData.h"
@@ -157,18 +158,6 @@ static sk_image_t* ToImage(SkImage* cimage) {
return reinterpret_cast<sk_image_t*>(cimage);
}
-static const SkPaint& AsPaint(const sk_paint_t& cpaint) {
- return reinterpret_cast<const SkPaint&>(cpaint);
-}
-
-static const SkPaint* AsPaint(const sk_paint_t* cpaint) {
- return reinterpret_cast<const SkPaint*>(cpaint);
-}
-
-static SkPaint* AsPaint(sk_paint_t* cpaint) {
- return reinterpret_cast<SkPaint*>(cpaint);
-}
-
static sk_canvas_t* ToCanvas(SkCanvas* canvas) {
return reinterpret_cast<sk_canvas_t*>(canvas);
}
@@ -177,18 +166,6 @@ static SkCanvas* AsCanvas(sk_canvas_t* ccanvas) {
return reinterpret_cast<SkCanvas*>(ccanvas);
}
-static SkMaskFilter* AsMaskFilter(sk_maskfilter_t* cfilter) {
- return reinterpret_cast<SkMaskFilter*>(cfilter);
-}
-
-static sk_maskfilter_t* ToMaskFilter(SkMaskFilter* filter) {
- return reinterpret_cast<sk_maskfilter_t*>(filter);
-}
-
-static SkShader* AsShader(sk_shader_t* cshader) {
- return reinterpret_cast<SkShader*>(cshader);
-}
-
static SkPictureRecorder* AsPictureRecorder(sk_picture_recorder_t* crec) {
return reinterpret_cast<SkPictureRecorder*>(crec);
}
@@ -260,40 +237,6 @@ uint32_t sk_image_get_unique_id(const sk_image_t* cimage) {
///////////////////////////////////////////////////////////////////////////////////////////
-sk_paint_t* sk_paint_new() {
- return (sk_paint_t*)SkNEW(SkPaint);
-}
-
-void sk_paint_delete(sk_paint_t* cpaint) {
- SkDELETE(AsPaint(cpaint));
-}
-
-bool sk_paint_is_antialias(const sk_paint_t* cpaint) {
- return AsPaint(*cpaint).isAntiAlias();
-}
-
-void sk_paint_set_antialias(sk_paint_t* cpaint, bool aa) {
- AsPaint(cpaint)->setAntiAlias(aa);
-}
-
-sk_color_t sk_paint_get_color(const sk_paint_t* cpaint) {
- return AsPaint(*cpaint).getColor();
-}
-
-void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) {
- AsPaint(cpaint)->setColor(c);
-}
-
-void sk_paint_set_shader(sk_paint_t* cpaint, sk_shader_t* cshader) {
- AsPaint(cpaint)->setShader(AsShader(cshader));
-}
-
-void sk_paint_set_maskfilter(sk_paint_t* cpaint, sk_maskfilter_t* cfilter) {
- AsPaint(cpaint)->setMaskFilter(AsMaskFilter(cfilter));
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-
sk_path_t* sk_path_new() {
return (sk_path_t*)SkNEW(SkPath);
}
diff --git a/src/c/sk_types_priv.h b/src/c/sk_types_priv.h
new file mode 100644
index 0000000000..92089d7266
--- /dev/null
+++ b/src/c/sk_types_priv.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef sk_types_priv_DEFINED
+#define sk_types_priv_DEFINED
+
+#include "sk_types.h"
+
+class SkMaskFilter;
+class SkPaint;
+class SkShader;
+
+static inline const SkPaint& AsPaint(const sk_paint_t& cpaint) {
+ return reinterpret_cast<const SkPaint&>(cpaint);
+}
+
+static inline const SkPaint* AsPaint(const sk_paint_t* cpaint) {
+ return reinterpret_cast<const SkPaint*>(cpaint);
+}
+
+static inline SkPaint* AsPaint(sk_paint_t* cpaint) {
+ return reinterpret_cast<SkPaint*>(cpaint);
+}
+
+static inline SkMaskFilter* AsMaskFilter(sk_maskfilter_t* cfilter) {
+ return reinterpret_cast<SkMaskFilter*>(cfilter);
+}
+
+static inline sk_maskfilter_t* ToMaskFilter(SkMaskFilter* filter) {
+ return reinterpret_cast<sk_maskfilter_t*>(filter);
+}
+
+static inline SkShader* AsShader(sk_shader_t* cshader) {
+ return reinterpret_cast<SkShader*>(cshader);
+}
+
+#endif