blob: 0236270b152ce05a3e0b269d982b25a03cedf2d0 [file] [log] [blame]
reedf5872d22015-01-10 17:59:31 -08001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkBlendMode.h"
9#include "include/core/SkMaskFilter.h"
10#include "include/core/SkPaint.h"
11#include "include/core/SkShader.h"
halcanary219f18f2015-09-01 10:01:38 -070012
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/c/sk_paint.h"
14#include "src/c/sk_types_priv.h"
reedf5872d22015-01-10 17:59:31 -080015
reedf5872d22015-01-10 17:59:31 -080016#define MAKE_FROM_TO_NAME(FROM) g_ ## FROM ## _map
17
18const struct {
19 sk_stroke_cap_t fC;
20 SkPaint::Cap fSK;
21} MAKE_FROM_TO_NAME(sk_stroke_cap_t)[] = {
22 { BUTT_SK_STROKE_CAP, SkPaint::kButt_Cap },
23 { ROUND_SK_STROKE_CAP, SkPaint::kRound_Cap },
24 { SQUARE_SK_STROKE_CAP, SkPaint::kSquare_Cap },
25};
26
27const struct {
28 sk_stroke_join_t fC;
29 SkPaint::Join fSK;
30} MAKE_FROM_TO_NAME(sk_stroke_join_t)[] = {
31 { MITER_SK_STROKE_JOIN, SkPaint::kMiter_Join },
32 { ROUND_SK_STROKE_JOIN, SkPaint::kRound_Join },
33 { BEVEL_SK_STROKE_JOIN, SkPaint::kBevel_Join },
34};
35
36#define CType sk_stroke_cap_t
37#define SKType SkPaint::Cap
38#define CTypeSkTypeMap MAKE_FROM_TO_NAME(sk_stroke_cap_t)
Mike Kleinc0bd9f92019-04-23 12:05:21 -050039#include "src/c/sk_c_from_to.h"
reedf5872d22015-01-10 17:59:31 -080040
41#define CType sk_stroke_join_t
42#define SKType SkPaint::Join
43#define CTypeSkTypeMap MAKE_FROM_TO_NAME(sk_stroke_join_t)
Mike Kleinc0bd9f92019-04-23 12:05:21 -050044#include "src/c/sk_c_from_to.h"
reedf5872d22015-01-10 17:59:31 -080045
46//////////////////////////////////////////////////////////////////////////////////////////////////
47
halcanary385fe4d2015-08-26 13:07:48 -070048sk_paint_t* sk_paint_new() { return (sk_paint_t*)new SkPaint; }
reedf5872d22015-01-10 17:59:31 -080049
halcanary385fe4d2015-08-26 13:07:48 -070050void sk_paint_delete(sk_paint_t* cpaint) { delete AsPaint(cpaint); }
reedf5872d22015-01-10 17:59:31 -080051
52bool sk_paint_is_antialias(const sk_paint_t* cpaint) {
53 return AsPaint(*cpaint).isAntiAlias();
54}
55
56void sk_paint_set_antialias(sk_paint_t* cpaint, bool aa) {
57 AsPaint(cpaint)->setAntiAlias(aa);
58}
59
60sk_color_t sk_paint_get_color(const sk_paint_t* cpaint) {
61 return AsPaint(*cpaint).getColor();
62}
63
64void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) {
65 AsPaint(cpaint)->setColor(c);
66}
67
68void sk_paint_set_shader(sk_paint_t* cpaint, sk_shader_t* cshader) {
reedfe630452016-03-25 09:08:00 -070069 AsPaint(cpaint)->setShader(sk_ref_sp(AsShader(cshader)));
reedf5872d22015-01-10 17:59:31 -080070}
71
72void sk_paint_set_maskfilter(sk_paint_t* cpaint, sk_maskfilter_t* cfilter) {
reedefdfd512016-04-04 10:02:58 -070073 AsPaint(cpaint)->setMaskFilter(sk_ref_sp(AsMaskFilter(cfilter)));
reedf5872d22015-01-10 17:59:31 -080074}
75
76bool sk_paint_is_stroke(const sk_paint_t* cpaint) {
77 return AsPaint(*cpaint).getStyle() != SkPaint::kFill_Style;
78}
79
80void sk_paint_set_stroke(sk_paint_t* cpaint, bool doStroke) {
81 AsPaint(cpaint)->setStyle(doStroke ? SkPaint::kStroke_Style : SkPaint::kFill_Style);
82}
83
84float sk_paint_get_stroke_width(const sk_paint_t* cpaint) {
85 return AsPaint(*cpaint).getStrokeWidth();
86}
87
88void sk_paint_set_stroke_width(sk_paint_t* cpaint, float width) {
89 AsPaint(cpaint)->setStrokeWidth(width);
90}
91
92float sk_paint_get_stroke_miter(const sk_paint_t* cpaint) {
93 return AsPaint(*cpaint).getStrokeMiter();
94}
95
96void sk_paint_set_stroke_miter(sk_paint_t* cpaint, float miter) {
97 AsPaint(cpaint)->setStrokeMiter(miter);
98}
99
100sk_stroke_cap_t sk_paint_get_stroke_cap(const sk_paint_t* cpaint) {
101 sk_stroke_cap_t ccap;
102 if (find_c(AsPaint(*cpaint).getStrokeCap(), &ccap)) {
103 ccap = BUTT_SK_STROKE_CAP;
104 }
105 return ccap;
106}
107
108void sk_paint_set_stroke_cap(sk_paint_t* cpaint, sk_stroke_cap_t ccap) {
109 SkPaint::Cap skcap;
110 if (find_sk(ccap, &skcap)) {
111 AsPaint(cpaint)->setStrokeCap(skcap);
112 } else {
113 // unknown ccap
114 }
115}
116
117sk_stroke_join_t sk_paint_get_stroke_join(const sk_paint_t* cpaint) {
118 sk_stroke_join_t cjoin;
119 if (find_c(AsPaint(*cpaint).getStrokeJoin(), &cjoin)) {
120 cjoin = MITER_SK_STROKE_JOIN;
121 }
122 return cjoin;
123}
124
125void sk_paint_set_stroke_join(sk_paint_t* cpaint, sk_stroke_join_t cjoin) {
126 SkPaint::Join skjoin;
127 if (find_sk(cjoin, &skjoin)) {
128 AsPaint(cpaint)->setStrokeJoin(skjoin);
129 } else {
130 // unknown cjoin
131 }
132}
133
halcanary7568d0b2015-07-31 13:38:06 -0700134void sk_paint_set_xfermode_mode(sk_paint_t* paint, sk_xfermode_mode_t mode) {
135 SkASSERT(paint);
reed374772b2016-10-05 17:33:02 -0700136 SkBlendMode skmode;
halcanary7568d0b2015-07-31 13:38:06 -0700137 switch (mode) {
138 #define MAP(X, Y) case (X): skmode = (Y); break
reed374772b2016-10-05 17:33:02 -0700139 MAP( CLEAR_SK_XFERMODE_MODE, SkBlendMode::kClear );
140 MAP( SRC_SK_XFERMODE_MODE, SkBlendMode::kSrc );
141 MAP( DST_SK_XFERMODE_MODE, SkBlendMode::kDst );
142 MAP( SRCOVER_SK_XFERMODE_MODE, SkBlendMode::kSrcOver );
143 MAP( DSTOVER_SK_XFERMODE_MODE, SkBlendMode::kDstOver );
144 MAP( SRCIN_SK_XFERMODE_MODE, SkBlendMode::kSrcIn );
145 MAP( DSTIN_SK_XFERMODE_MODE, SkBlendMode::kDstIn );
146 MAP( SRCOUT_SK_XFERMODE_MODE, SkBlendMode::kSrcOut );
147 MAP( DSTOUT_SK_XFERMODE_MODE, SkBlendMode::kDstOut );
148 MAP( SRCATOP_SK_XFERMODE_MODE, SkBlendMode::kSrcATop );
149 MAP( DSTATOP_SK_XFERMODE_MODE, SkBlendMode::kDstATop );
150 MAP( XOR_SK_XFERMODE_MODE, SkBlendMode::kXor );
151 MAP( PLUS_SK_XFERMODE_MODE, SkBlendMode::kPlus );
152 MAP( MODULATE_SK_XFERMODE_MODE, SkBlendMode::kModulate );
153 MAP( SCREEN_SK_XFERMODE_MODE, SkBlendMode::kScreen );
154 MAP( OVERLAY_SK_XFERMODE_MODE, SkBlendMode::kOverlay );
155 MAP( DARKEN_SK_XFERMODE_MODE, SkBlendMode::kDarken );
156 MAP( LIGHTEN_SK_XFERMODE_MODE, SkBlendMode::kLighten );
157 MAP( COLORDODGE_SK_XFERMODE_MODE, SkBlendMode::kColorDodge );
158 MAP( COLORBURN_SK_XFERMODE_MODE, SkBlendMode::kColorBurn );
159 MAP( HARDLIGHT_SK_XFERMODE_MODE, SkBlendMode::kHardLight );
160 MAP( SOFTLIGHT_SK_XFERMODE_MODE, SkBlendMode::kSoftLight );
161 MAP( DIFFERENCE_SK_XFERMODE_MODE, SkBlendMode::kDifference );
162 MAP( EXCLUSION_SK_XFERMODE_MODE, SkBlendMode::kExclusion );
163 MAP( MULTIPLY_SK_XFERMODE_MODE, SkBlendMode::kMultiply );
164 MAP( HUE_SK_XFERMODE_MODE, SkBlendMode::kHue );
165 MAP( SATURATION_SK_XFERMODE_MODE, SkBlendMode::kSaturation );
166 MAP( COLOR_SK_XFERMODE_MODE, SkBlendMode::kColor );
167 MAP( LUMINOSITY_SK_XFERMODE_MODE, SkBlendMode::kLuminosity );
halcanary7568d0b2015-07-31 13:38:06 -0700168 #undef MAP
169 default:
170 return;
171 }
reed374772b2016-10-05 17:33:02 -0700172 AsPaint(paint)->setBlendMode(skmode);
halcanary7568d0b2015-07-31 13:38:06 -0700173}