Added bindings for SkPixelSerializer
authorMatthew Leibowitz <mattleibow@live.com>
Mon, 21 Aug 2017 18:33:56 +0000 (20:33 +0200)
committerMatthew Leibowitz <mattleibow@live.com>
Mon, 21 Aug 2017 18:33:56 +0000 (20:33 +0200)
gn/core.gni
include/c/sk_image.h
include/c/sk_pixelserializer.h [new file with mode: 0644]
include/c/sk_types.h
src/c/sk_image.cpp
src/c/sk_pixelserializer.cpp [new file with mode: 0644]
src/c/sk_types_priv.h

index e6d6b3091b5c3caa53fd2ffceabfbfa445b61c32..a09e120a4add88e32126d2ec48f28a302d135227 100644 (file)
@@ -25,6 +25,7 @@ skia_core_sources = [
   "$_include/c/sk_patheffect.h",
   "$_include/c/sk_picture.h",
   "$_include/c/sk_pixmap.h",
+  "$_include/c/sk_pixelserializer.h",
   "$_include/c/sk_region.h",
   "$_include/c/sk_shader.h",
   "$_include/c/sk_stream.h",
@@ -55,6 +56,7 @@ skia_core_sources = [
   "$_src/c/sk_patheffect.cpp",
   "$_src/c/sk_picture.cpp",
   "$_src/c/sk_pixmap.cpp",
+  "$_src/c/sk_pixelserializer.cpp",
   "$_src/c/sk_region.cpp",
   "$_src/c/sk_shader.cpp",
   "$_src/c/sk_stream.cpp",
index c630cf7f3f336b437d348fa74da719c7679196ce..8408752f597b2c51a5a31aff051b5f09827b21ef 100644 (file)
@@ -39,6 +39,7 @@ SK_C_API bool sk_image_read_pixels(const sk_image_t* image, const sk_imageinfo_t
 SK_C_API bool sk_image_read_pixels_into_pixmap(const sk_image_t* image, const sk_pixmap_t* dst, int srcX, int srcY, sk_image_caching_hint_t cachingHint);
 SK_C_API bool sk_image_scale_pixels(const sk_image_t* image, const sk_pixmap_t* dst, sk_filter_quality_t quality, sk_image_caching_hint_t cachingHint);
 SK_C_API sk_data_t* sk_image_encode(const sk_image_t*);
+SK_C_API sk_data_t* sk_image_encode_with_serializer(const sk_image_t*, sk_pixelserializer_t* serializer);
 SK_C_API sk_data_t* sk_image_encode_specific(const sk_image_t* cimage, sk_encoded_image_format_t encoder, int quality);
 SK_C_API sk_image_t* sk_image_make_subset(const sk_image_t* cimage, const sk_irect_t* subset);
 SK_C_API sk_image_t* sk_image_make_non_texture_image(const sk_image_t* cimage);
diff --git a/include/c/sk_pixelserializer.h b/include/c/sk_pixelserializer.h
new file mode 100644 (file)
index 0000000..c97b3b8
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2017 Xamarin Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef sk_pixelserializer_DEFINED
+#define sk_pixelserializer_DEFINED
+
+#include "sk_types.h"
+
+SK_C_PLUS_PLUS_BEGIN_GUARD
+
+SK_C_API void sk_pixelserializer_unref(sk_pixelserializer_t* cserializer);
+SK_C_API bool sk_pixelserializer_use_encoded_data(sk_pixelserializer_t* cserializer, const void* data, size_t len);
+SK_C_API sk_data_t* sk_pixelserializer_encode(sk_pixelserializer_t* cserializer, const sk_pixmap_t* cpixmap);
+
+SK_C_PLUS_PLUS_END_GUARD
+
+#endif
index 71a8b68b4aaa3cc5f8eb1e8caa255cb2c396832a..61c1126157d9edf67153d46f7e603289fc3241fe 100644 (file)
@@ -329,6 +329,7 @@ typedef struct sk_string_t sk_string_t;
 */
 typedef struct sk_bitmap_t sk_bitmap_t;
 typedef struct sk_pixmap_t sk_pixmap_t;
+typedef struct sk_pixelserializer_t sk_pixelserializer_t;
 typedef struct sk_colorfilter_t sk_colorfilter_t;
 typedef struct sk_imagefilter_t sk_imagefilter_t;
 typedef struct sk_imagefilter_croprect_t sk_imagefilter_croprect_t;
index ef03f7d0b3511bcfdf40849bbdf861e865029b57..fb5b6627b049b4afc6c58d1287d836633b742626 100644 (file)
@@ -128,6 +128,10 @@ sk_data_t* sk_image_encode(const sk_image_t* cimage) {
     return ToData(AsImage(cimage)->encode());
 }
 
+sk_data_t* sk_image_encode_with_serializer(const sk_image_t* cimage, sk_pixelserializer_t* serializer) {
+    return ToData(AsImage(cimage)->encode(AsPixelSerializer(serializer)));
+}
+
 sk_data_t* sk_image_encode_specific(const sk_image_t* cimage, sk_encoded_image_format_t encoder, int quality) {
     return ToData(AsImage(cimage)->encode((SkEncodedImageFormat)encoder, quality));
 }
diff --git a/src/c/sk_pixelserializer.cpp b/src/c/sk_pixelserializer.cpp
new file mode 100644 (file)
index 0000000..6075960
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2017 Xamarin Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkPixelSerializer.h"
+
+#include "sk_pixelserializer.h"
+
+#include "sk_types_priv.h"
+
+void sk_pixelserializer_unref(sk_pixelserializer_t* cserializer)
+{
+    SkSafeUnref(AsPixelSerializer(cserializer));
+}
+
+bool sk_pixelserializer_use_encoded_data(sk_pixelserializer_t* cserializer, const void* data, size_t len)
+{
+    return AsPixelSerializer(cserializer)->useEncodedData(data, len);
+}
+
+sk_data_t* sk_pixelserializer_encode(sk_pixelserializer_t* cserializer, const sk_pixmap_t* cpixmap)
+{
+    return ToData(AsPixelSerializer(cserializer)->encode(AsPixmap(*cpixmap)));
+}
index 87df9abe8e54fda48b3ee647f79fb6803014d103..54cd006a82a6ab66b2c8f8848e794f044378e588 100644 (file)
@@ -159,10 +159,34 @@ static inline SkPixmap& AsPixmap(sk_pixmap_t& cpixmap) {
     return reinterpret_cast<SkPixmap&>(cpixmap);
 }
 
+static inline const sk_pixmap_t& ToPixmap(const SkPixmap& pixmap) {
+    return reinterpret_cast<const sk_pixmap_t&>(pixmap);
+}
+
 static inline sk_pixmap_t* ToPixmap(SkPixmap* pixmap) {
     return reinterpret_cast<sk_pixmap_t*>(pixmap);
 }
 
+static inline const SkPixelSerializer* AsPixelSerializer(const sk_pixelserializer_t* cpixelserializer) {
+    return reinterpret_cast<const SkPixelSerializer*>(cpixelserializer);
+}
+
+static inline const SkPixelSerializer& AsPixelSerializer(const sk_pixelserializer_t& cpixelserializer) {
+    return reinterpret_cast<const SkPixelSerializer&>(cpixelserializer);
+}
+
+static inline SkPixelSerializer* AsPixelSerializer(sk_pixelserializer_t* cpixelserializer) {
+    return reinterpret_cast<SkPixelSerializer*>(cpixelserializer);
+}
+
+static inline SkPixelSerializer& AsPixelSerializer(sk_pixelserializer_t& cpixelserializer) {
+    return reinterpret_cast<SkPixelSerializer&>(cpixelserializer);
+}
+
+static inline sk_pixelserializer_t* ToPixelSerializer(SkPixelSerializer* pixelserializer) {
+    return reinterpret_cast<sk_pixelserializer_t*>(pixelserializer);
+}
+
 static inline SkMask* AsMask(sk_mask_t* cmask) {
     return reinterpret_cast<SkMask*>(cmask);
 }