Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export sk_canvas_save_layer_rec to expose SkCanvas::SaveLayerRec functionality #130

Open
wants to merge 3 commits into
base: skiasharp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/c/sk_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SK_C_API bool sk_canvas_get_local_clip_bounds(sk_canvas_t* ccanvas, sk_rect_t* c
SK_C_API bool sk_canvas_get_device_clip_bounds(sk_canvas_t* ccanvas, sk_irect_t* cbounds);
SK_C_API int sk_canvas_save(sk_canvas_t* ccanvas);
SK_C_API int sk_canvas_save_layer(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_paint_t* cpaint);
SK_C_API int sk_canvas_save_layer_rec(sk_canvas_t* ccanvas, const sk_canvas_savelayerrec_t* crec);
SK_C_API void sk_canvas_restore(sk_canvas_t* ccanvas);
SK_C_API void sk_canvas_translate(sk_canvas_t* ccanvas, float dx, float dy);
SK_C_API void sk_canvas_scale(sk_canvas_t* ccanvas, float sx, float sy);
Expand Down
14 changes: 14 additions & 0 deletions include/c/sk_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,20 @@ typedef struct {
sk_mipmap_mode_t fMipmap;
} sk_sampling_options_t;

typedef enum {
NONE_SK_CANVAS_SAVELAYERREC_FLAGS = 0,
PRESERVE_LCD_TEXT_SK_CANVAS_SAVELAYERREC_FLAGS = 1 << 1,
INITIALIZE_WITH_PREVIOUS_SK_CANVAS_SAVELAYERREC_FLAGS = 1 << 2,
F16_COLOR_TYPE_SK_CANVAS_SAVELAYERREC_FLAGS = 1 << 4,
} sk_canvas_savelayerrec_flags_t;

typedef struct {
sk_rect_t* fBounds;
sk_paint_t* fPaint;
sk_imagefilter_t* fBackdrop;
sk_canvas_savelayerrec_flags_t fFlags;
} sk_canvas_savelayerrec_t;

/*
* Skottie Animation
*/
Expand Down
4 changes: 4 additions & 0 deletions src/c/sk_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ int sk_canvas_save_layer(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_
return AsCanvas(ccanvas)->saveLayer(AsRect(crect), AsPaint(cpaint));
}

int sk_canvas_save_layer_rec(sk_canvas_t* ccanvas, const sk_canvas_savelayerrec_t* crec) {
return AsCanvas(ccanvas)->saveLayer(AsCanvasSaveLayerRec(crec));
}

void sk_canvas_restore(sk_canvas_t* ccanvas) {
AsCanvas(ccanvas)->restore();
}
Expand Down
6 changes: 6 additions & 0 deletions src/c/sk_enums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@ static_assert ((int)SkRuntimeEffect::Uniform::Flags::kVertex_Flag == (i
static_assert ((int)SkRuntimeEffect::Uniform::Flags::kFragment_Flag == (int)FRAGMENT_SK_RUNTIMEEFFECT_UNIFORM_FLAGS, ASSERT_MSG(SkRuntimeEffect::Uniform::Flags, sk_runtimeeffect_uniform_flags_t));
static_assert ((int)SkRuntimeEffect::Uniform::Flags::kHalfPrecision_Flag == (int)HALF_PRECISION_SK_RUNTIMEEFFECT_UNIFORM_FLAGS, ASSERT_MSG(SkRuntimeEffect::Uniform::Flags, sk_runtimeeffect_uniform_flags_t));

// sk_canvas_savelayerrec_flags_t
static_assert ((int)0 == (int)NONE_SK_CANVAS_SAVELAYERREC_FLAGS, ASSERT_MSG(SkCanvas::SaveLayerFlagsSet, sk_canvas_savelayerrec_flags_t));
static_assert ((int)SkCanvas::SaveLayerFlagsSet::kPreserveLCDText_SaveLayerFlag == (int)PRESERVE_LCD_TEXT_SK_CANVAS_SAVELAYERREC_FLAGS, ASSERT_MSG(SkCanvas::SaveLayerFlagsSet, sk_canvas_savelayerrec_flags_t));
static_assert ((int)SkCanvas::SaveLayerFlagsSet::kInitWithPrevious_SaveLayerFlag == (int)INITIALIZE_WITH_PREVIOUS_SK_CANVAS_SAVELAYERREC_FLAGS, ASSERT_MSG(SkCanvas::SaveLayerFlagsSet, sk_canvas_savelayerrec_flags_t));
static_assert ((int)SkCanvas::SaveLayerFlagsSet::kF16ColorType == (int)F16_COLOR_TYPE_SK_CANVAS_SAVELAYERREC_FLAGS, ASSERT_MSG(SkCanvas::SaveLayerFlagsSet, sk_canvas_savelayerrec_flags_t));

#if defined(SK_GANESH)

// gr_surfaceorigin_t
Expand Down
8 changes: 8 additions & 0 deletions src/c/sk_types_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ DEF_MAP(SkRuntimeEffect::Child, sk_runtimeeffect_child_t, RuntimeEffectChild)
#include "include/core/SkCanvas.h"
DEF_MAP(SkCanvas::Lattice, sk_lattice_t, Lattice)

static inline SkCanvas::SaveLayerRec AsCanvasSaveLayerRec(const sk_canvas_savelayerrec_t* rec) {
return SkCanvas::SaveLayerRec(
AsRect(rec->fBounds),
AsPaint(rec->fPaint),
AsImageFilter(rec->fBackdrop),
(SkCanvas::SaveLayerFlags)rec->fFlags);
}

#include "include/codec/SkCodec.h"
DEF_MAP(SkCodec::FrameInfo, sk_codec_frameinfo_t, FrameInfo)
DEF_MAP(SkCodec::Options, sk_codec_options_t, CodecOptions)
Expand Down