aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed <reed@chromium.org>2014-12-23 14:11:11 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-12-23 14:11:11 -0800
commit0eafc9b06cbfd47e9c3471c82580790cef0fdae5 (patch)
treedeecffd9c2d96453dd8f4ba348762718ec61d077
parent0e9ab4e3db33d91c8c8ab4d1af5fb8e56602189f (diff)
add maskfilter to c api
BUG=skia: TBR= Review URL: https://codereview.chromium.org/822053002
-rw-r--r--include/c/sk_maskfilter.h32
-rw-r--r--include/c/sk_paint.h6
-rw-r--r--include/c/sk_types.h1
-rw-r--r--src/c/sk_surface.cpp56
4 files changed, 95 insertions, 0 deletions
diff --git a/include/c/sk_maskfilter.h b/include/c/sk_maskfilter.h
new file mode 100644
index 0000000000..ce38605a85
--- /dev/null
+++ b/include/c/sk_maskfilter.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+// EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL
+// DO NOT USE -- FOR INTERNAL TESTING ONLY
+
+#ifndef sk_maskfilter_DEFINED
+#define sk_maskfilter_DEFINED
+
+#include "sk_types.h"
+
+typedef enum {
+ NORMAL_SK_BLUR_STYLE, //!< fuzzy inside and outside
+ SOLID_SK_BLUR_STYLE, //!< solid inside, fuzzy outside
+ OUTER_SK_BLUR_STYLE, //!< nothing inside, fuzzy outside
+ INNER_SK_BLUR_STYLE, //!< fuzzy inside, nothing outside
+} sk_blurstyle_t;
+
+SK_C_PLUS_PLUS_BEGIN_GUARD
+
+void sk_maskfilter_ref(sk_maskfilter_t*);
+void sk_maskfilter_unref(sk_maskfilter_t*);
+
+sk_maskfilter_t* sk_maskfilter_new_blur(sk_blurstyle_t, float sigma);
+
+SK_C_PLUS_PLUS_END_GUARD
+
+#endif
diff --git a/include/c/sk_paint.h b/include/c/sk_paint.h
index 92ac5d57ba..e6b5cbdb82 100644
--- a/include/c/sk_paint.h
+++ b/include/c/sk_paint.h
@@ -30,6 +30,12 @@ void sk_paint_set_color(sk_paint_t*, sk_color_t);
*/
void sk_paint_set_shader(sk_paint_t*, sk_shader_t*);
+/**
+ * Set the paint's maskfilter to the specified parameter. This will automatically call unref() on
+ * any previous value, and call ref() on the new value.
+ */
+void sk_paint_set_maskfilter(sk_paint_t*, sk_maskfilter_t*);
+
SK_C_PLUS_PLUS_END_GUARD
#endif
diff --git a/include/c/sk_types.h b/include/c/sk_types.h
index f5f4b578fc..67a29dcb5e 100644
--- a/include/c/sk_types.h
+++ b/include/c/sk_types.h
@@ -80,6 +80,7 @@ typedef struct {
typedef struct sk_canvas_t sk_canvas_t;
typedef struct sk_image_t sk_image_t;
+typedef struct sk_maskfilter_t sk_maskfilter_t;
typedef struct sk_paint_t sk_paint_t;
typedef struct sk_picture_t sk_picture_t;
typedef struct sk_picture_recorder_t sk_picture_recorder_t;
diff --git a/src/c/sk_surface.cpp b/src/c/sk_surface.cpp
index 0a940022e8..6653a298c4 100644
--- a/src/c/sk_surface.cpp
+++ b/src/c/sk_surface.cpp
@@ -13,6 +13,7 @@
#include "SkCanvas.h"
#include "SkImage.h"
+#include "SkMaskFilter.h"
#include "SkMatrix.h"
#include "SkPaint.h"
#include "SkPath.h"
@@ -162,6 +163,14 @@ 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);
}
@@ -257,6 +266,10 @@ 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() {
@@ -535,6 +548,49 @@ sk_shader_t* sk_shader_new_linear_gradient(const sk_point_t pts[2],
}
///////////////////////////////////////////////////////////////////////////////////////////
+
+#include "../../include/effects/SkBlurMaskFilter.h"
+#include "sk_maskfilter.h"
+
+const struct {
+ sk_blurstyle_t fC;
+ SkBlurStyle fSk;
+} gBlurStylePairs[] = {
+ { NORMAL_SK_BLUR_STYLE, kNormal_SkBlurStyle },
+ { SOLID_SK_BLUR_STYLE, kSolid_SkBlurStyle },
+ { OUTER_SK_BLUR_STYLE, kOuter_SkBlurStyle },
+ { INNER_SK_BLUR_STYLE, kInner_SkBlurStyle },
+};
+
+static bool find_blurstyle(sk_blurstyle_t csrc, SkBlurStyle* dst) {
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gBlurStylePairs); ++i) {
+ if (gBlurStylePairs[i].fC == csrc) {
+ if (dst) {
+ *dst = gBlurStylePairs[i].fSk;
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
+void sk_maskfilter_ref(sk_maskfilter_t* cfilter) {
+ SkSafeRef(AsMaskFilter(cfilter));
+}
+
+void sk_maskfilter_unref(sk_maskfilter_t* cfilter) {
+ SkSafeUnref(AsMaskFilter(cfilter));
+}
+
+sk_maskfilter_t* sk_maskfilter_new_blur(sk_blurstyle_t cstyle, float sigma) {
+ SkBlurStyle style;
+ if (!find_blurstyle(cstyle, &style)) {
+ return NULL;
+ }
+ return ToMaskFilter(SkBlurMaskFilter::Create(style, sigma));
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
void sk_test_capi(SkCanvas* canvas) {