From d92e277d9849c0fdaf63e72ee7b86d36d08f7c89 Mon Sep 17 00:00:00 2001 From: Tyler Hoeflicker Date: Mon, 24 Oct 2016 14:45:17 -0700 Subject: [PATCH] add SkRegion bindings to C API --- include/c/sk_region.h | 29 ++++++++++++++++++++++++++ include/c/sk_types.h | 6 ++++++ src/c/sk_region.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/c/sk_types_priv.h | 19 +++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100755 include/c/sk_region.h create mode 100644 src/c/sk_region.cpp diff --git a/include/c/sk_region.h b/include/c/sk_region.h new file mode 100755 index 0000000..0705c38 --- /dev/null +++ b/include/c/sk_region.h @@ -0,0 +1,29 @@ +/* + * Copyright 2016 Bluebeam Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef sk_region_DEFINED +#define sk_region_DEFINED + +#include "sk_types.h" + +SK_C_PLUS_PLUS_BEGIN_GUARD + +SK_API sk_region_t* sk_region_new(); +SK_API sk_region_t* sk_region_new2(const sk_region_t* region); +SK_API void sk_region_delete(sk_region_t* cpath); +SK_API void sk_region_contains(sk_region_t* r, const sk_region_t* region); +SK_API void sk_region_contains2(sk_region_t* r, int x, int y); +SK_API bool sk_region_intersects(sk_region_t* r, const sk_region_t* src); +SK_API bool sk_region_set_path(sk_region_t* dst, const sk_path_t* t); +SK_API bool sk_region_set_rect(sk_region_t* dst, const sk_irect_t* rect); +SK_API bool sk_region_op(sk_region_t* dst, int left, int top, int right, int bottom, sk_region_op_t* op); +SK_API bool sk_region_op2(sk_region_t* dst, sk_region_t* src, sk_region_op_t* op); +SK_API sk_irect_t sk_region_get_bounds(sk_region_t* r); + +SK_C_PLUS_PLUS_END_GUARD + +#endif diff --git a/include/c/sk_types.h b/include/c/sk_types.h index cff0f25..2edf542 100644 --- a/include/c/sk_types.h +++ b/include/c/sk_types.h @@ -183,6 +183,12 @@ typedef struct sk_shader_t sk_shader_t; For GPU drawing, the destination is a texture or a framebuffer. */ typedef struct sk_surface_t sk_surface_t; +/** + The sk_region encapsulates the geometric region used to specify + clipping areas for drawing. +*/ +typedef struct sk_region_t sk_region_t; + typedef enum { CLEAR_SK_XFERMODE_MODE, diff --git a/src/c/sk_region.cpp b/src/c/sk_region.cpp new file mode 100644 index 0000000..db640ac --- /dev/null +++ b/src/c/sk_region.cpp @@ -0,0 +1,57 @@ +/* + * Copyright 2016 Bluebeam Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkRegion.h" +#include "sk_region.h" +#include "sk_types_priv.h" + + +sk_region_t *sk_region_new() { return (sk_region_t *)new SkRegion(); } + +sk_region_t *sk_region_new2(const sk_region_t *region) { + return (sk_region_t *)new SkRegion(*AsRegion(region)); +} + +void sk_region_delete(sk_region_t *cpath) { delete AsRegion(cpath); } + +void sk_region_contains(sk_region_t *r, const sk_region_t *region) { + AsRegion(r)->contains(*AsRegion(region)); +} + +void sk_region_contains2(sk_region_t *r, int x, int y) { + AsRegion(r)->contains(x, y); +} + +bool sk_region_intersects(sk_region_t *r, const sk_region_t *src) { + return AsRegion(r)->intersects(*AsRegion(src)); +} + +bool sk_region_set_path(sk_region_t *dst, const sk_path_t *t) { + SkRegion region = *AsRegion(dst); + return region.setPath(AsPath(*t), region); +} + +bool sk_region_set_rect(sk_region_t *dst, const sk_irect_t *rect) { + SkRegion region = *AsRegion(dst); + return region.setRect(AsIRect(*rect)); +} + +bool sk_region_op(sk_region_t *dst, int left, int top, int right, int bottom, + sk_region_op_t* op) { + SkRegion region = *AsRegion(dst); + return region.op(left, top, right, bottom, (SkRegion::Op)op); +} + +bool sk_region_op2(sk_region_t *dst, sk_region_t *src, sk_region_op_t* op) { + SkRegion region = *AsRegion(dst); + return region.op(*AsRegion(src), (SkRegion::Op)op); +} + +sk_irect_t sk_region_get_bounds(sk_region_t *r) { + SkRegion region = *AsRegion(r); + return ToIRect(AsRegion(r)->getBounds()); +} \ No newline at end of file diff --git a/src/c/sk_types_priv.h b/src/c/sk_types_priv.h index 5b452f4..cb64f0f 100644 --- a/src/c/sk_types_priv.h +++ b/src/c/sk_types_priv.h @@ -26,6 +26,7 @@ #include "SkFontStyle.h" #include "GrContext.h" #include "SkPathOps.h" +#include "SkRegion.h" #include "SkTypeface.h" #include "gl/GrGLInterface.h" @@ -92,6 +93,24 @@ static inline const SkIRect& AsIRect(const sk_irect_t& crect) { return reinterpret_cast(crect); } +/* SkRegion */ +static inline SkRegion* AsRegion(sk_region_t* creg) { + return reinterpret_cast(creg); +} + +static inline const SkRegion* AsRegion(const sk_region_t* creg) { + return reinterpret_cast(creg); +} + +static inline const SkRegion& AsRegion(const sk_region_t& creg) { + return reinterpret_cast(creg); +} + +static inline sk_region_t* ToRegion(SkRegion* reg) { + return reinterpret_cast(reg); +} +/* End SkRegion */ + static inline const SkBitmap* AsBitmap(const sk_bitmap_t* cbitmap) { return reinterpret_cast(cbitmap); } -- 2.7.4