C API: add sk_xfermode.h, impl, test
Review URL: https://codereview.chromium.org/1242403005
This commit is contained in:
parent
85cd78dd6c
commit
7568d0b15e
@ -65,6 +65,11 @@ void sk_paint_set_shader(sk_paint_t*, sk_shader_t*);
|
||||
*/
|
||||
void sk_paint_set_maskfilter(sk_paint_t*, sk_maskfilter_t*);
|
||||
|
||||
/**
|
||||
* Set the paint's xfermode to the specified parameter.
|
||||
*/
|
||||
void sk_paint_set_xfermode_mode(sk_paint_t*, sk_xfermode_mode_t);
|
||||
|
||||
SK_C_PLUS_PLUS_END_GUARD
|
||||
|
||||
#endif
|
||||
|
@ -108,6 +108,38 @@ typedef struct sk_picture_recorder_t sk_picture_recorder_t;
|
||||
typedef struct sk_shader_t sk_shader_t;
|
||||
typedef struct sk_surface_t sk_surface_t;
|
||||
|
||||
typedef enum {
|
||||
CLEAR_SK_XFERMODE_MODE,
|
||||
SRC_SK_XFERMODE_MODE,
|
||||
DST_SK_XFERMODE_MODE,
|
||||
SRCOVER_SK_XFERMODE_MODE,
|
||||
DSTOVER_SK_XFERMODE_MODE,
|
||||
SRCIN_SK_XFERMODE_MODE,
|
||||
DSTIN_SK_XFERMODE_MODE,
|
||||
SRCOUT_SK_XFERMODE_MODE,
|
||||
DSTOUT_SK_XFERMODE_MODE,
|
||||
SRCATOP_SK_XFERMODE_MODE,
|
||||
DSTATOP_SK_XFERMODE_MODE,
|
||||
XOR_SK_XFERMODE_MODE,
|
||||
PLUS_SK_XFERMODE_MODE,
|
||||
MODULATE_SK_XFERMODE_MODE,
|
||||
SCREEN_SK_XFERMODE_MODE,
|
||||
OVERLAY_SK_XFERMODE_MODE,
|
||||
DARKEN_SK_XFERMODE_MODE,
|
||||
LIGHTEN_SK_XFERMODE_MODE,
|
||||
COLORDODGE_SK_XFERMODE_MODE,
|
||||
COLORBURN_SK_XFERMODE_MODE,
|
||||
HARDLIGHT_SK_XFERMODE_MODE,
|
||||
SOFTLIGHT_SK_XFERMODE_MODE,
|
||||
DIFFERENCE_SK_XFERMODE_MODE,
|
||||
EXCLUSION_SK_XFERMODE_MODE,
|
||||
MULTIPLY_SK_XFERMODE_MODE,
|
||||
HUE_SK_XFERMODE_MODE,
|
||||
SATURATION_SK_XFERMODE_MODE,
|
||||
COLOR_SK_XFERMODE_MODE,
|
||||
LUMINOSITY_SK_XFERMODE_MODE,
|
||||
} sk_xfermode_mode_t;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -132,4 +132,43 @@ void sk_paint_set_stroke_join(sk_paint_t* cpaint, sk_stroke_join_t cjoin) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void sk_paint_set_xfermode_mode(sk_paint_t* paint, sk_xfermode_mode_t mode) {
|
||||
SkASSERT(paint);
|
||||
SkXfermode::Mode skmode;
|
||||
switch (mode) {
|
||||
#define MAP(X, Y) case (X): skmode = (Y); break
|
||||
MAP( CLEAR_SK_XFERMODE_MODE, SkXfermode::kClear_Mode );
|
||||
MAP( SRC_SK_XFERMODE_MODE, SkXfermode::kSrc_Mode );
|
||||
MAP( DST_SK_XFERMODE_MODE, SkXfermode::kDst_Mode );
|
||||
MAP( SRCOVER_SK_XFERMODE_MODE, SkXfermode::kSrcOver_Mode );
|
||||
MAP( DSTOVER_SK_XFERMODE_MODE, SkXfermode::kDstOver_Mode );
|
||||
MAP( SRCIN_SK_XFERMODE_MODE, SkXfermode::kSrcIn_Mode );
|
||||
MAP( DSTIN_SK_XFERMODE_MODE, SkXfermode::kDstIn_Mode );
|
||||
MAP( SRCOUT_SK_XFERMODE_MODE, SkXfermode::kSrcOut_Mode );
|
||||
MAP( DSTOUT_SK_XFERMODE_MODE, SkXfermode::kDstOut_Mode );
|
||||
MAP( SRCATOP_SK_XFERMODE_MODE, SkXfermode::kSrcATop_Mode );
|
||||
MAP( DSTATOP_SK_XFERMODE_MODE, SkXfermode::kDstATop_Mode );
|
||||
MAP( XOR_SK_XFERMODE_MODE, SkXfermode::kXor_Mode );
|
||||
MAP( PLUS_SK_XFERMODE_MODE, SkXfermode::kPlus_Mode );
|
||||
MAP( MODULATE_SK_XFERMODE_MODE, SkXfermode::kModulate_Mode );
|
||||
MAP( SCREEN_SK_XFERMODE_MODE, SkXfermode::kScreen_Mode );
|
||||
MAP( OVERLAY_SK_XFERMODE_MODE, SkXfermode::kOverlay_Mode );
|
||||
MAP( DARKEN_SK_XFERMODE_MODE, SkXfermode::kDarken_Mode );
|
||||
MAP( LIGHTEN_SK_XFERMODE_MODE, SkXfermode::kLighten_Mode );
|
||||
MAP( COLORDODGE_SK_XFERMODE_MODE, SkXfermode::kColorDodge_Mode );
|
||||
MAP( COLORBURN_SK_XFERMODE_MODE, SkXfermode::kColorBurn_Mode );
|
||||
MAP( HARDLIGHT_SK_XFERMODE_MODE, SkXfermode::kHardLight_Mode );
|
||||
MAP( SOFTLIGHT_SK_XFERMODE_MODE, SkXfermode::kSoftLight_Mode );
|
||||
MAP( DIFFERENCE_SK_XFERMODE_MODE, SkXfermode::kDifference_Mode );
|
||||
MAP( EXCLUSION_SK_XFERMODE_MODE, SkXfermode::kExclusion_Mode );
|
||||
MAP( MULTIPLY_SK_XFERMODE_MODE, SkXfermode::kMultiply_Mode );
|
||||
MAP( HUE_SK_XFERMODE_MODE, SkXfermode::kHue_Mode );
|
||||
MAP( SATURATION_SK_XFERMODE_MODE, SkXfermode::kSaturation_Mode );
|
||||
MAP( COLOR_SK_XFERMODE_MODE, SkXfermode::kColor_Mode );
|
||||
MAP( LUMINOSITY_SK_XFERMODE_MODE, SkXfermode::kLuminosity_Mode );
|
||||
#undef MAP
|
||||
default:
|
||||
return;
|
||||
}
|
||||
AsPaint(paint)->setXfermodeMode(skmode);
|
||||
}
|
||||
|
@ -32,6 +32,11 @@ static void test_c(skiatest::Reporter* reporter) {
|
||||
sk_canvas_draw_paint(canvas, paint);
|
||||
REPORTER_ASSERT(reporter, 0xFFFFFFFF == pixel[0]);
|
||||
|
||||
sk_paint_set_xfermode_mode(paint, SRC_SK_XFERMODE_MODE);
|
||||
sk_paint_set_color(paint, sk_color_set_argb(0x80, 0x80, 0x80, 0x80));
|
||||
sk_canvas_draw_paint(canvas, paint);
|
||||
REPORTER_ASSERT(reporter, 0x80404040 == pixel[0]);
|
||||
|
||||
sk_paint_delete(paint);
|
||||
sk_surface_unref(surface);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user