Added some more surface members
authorMatthew Leibowitz <mattleibow@live.com>
Thu, 23 Mar 2017 14:47:04 +0000 (10:47 -0400)
committerMatthew Leibowitz <mattleibow@live.com>
Thu, 23 Mar 2017 14:47:04 +0000 (10:47 -0400)
include/c/sk_surface.h
src/c/sk_surface.cpp
src/c/sk_types_priv.h

index c7eb115..3d00c89 100644 (file)
@@ -98,6 +98,14 @@ SK_C_API sk_surface_t* sk_surface_new_backend_texture_as_render_target(gr_contex
 
 SK_C_API sk_surface_t* sk_surface_new_render_target(gr_context_t* context, bool budgeted, const sk_imageinfo_t* info, int sampleCount, const sk_surfaceprops_t* props);
 
+SK_C_API void sk_surface_draw(sk_surface_t* surface, sk_canvas_t* canvas, float x, float y, const sk_paint_t* paint);
+
+SK_C_API bool sk_surface_peek_pixels(sk_surface_t* surface, sk_pixmap_t* pixmap);
+
+SK_C_API bool sk_surface_read_pixels(sk_surface_t* surface, sk_imageinfo_t* dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY);
+
+SK_C_API void sk_surface_get_props(sk_surface_t* surface, sk_surfaceprops_t* props);
+
 SK_C_PLUS_PLUS_END_GUARD
 
 #endif
index 71cfc53..b97ae25 100644 (file)
@@ -94,3 +94,22 @@ sk_surface_t* sk_surface_new_render_target(gr_context_t* context, bool budgeted,
     }
     return ToSurface(SkSurface::MakeRenderTarget(AsGrContext(context), (SkBudgeted)budgeted, info, sampleCount, surfProps).release());
 }
+
+void sk_surface_draw(sk_surface_t* surface, sk_canvas_t* canvas, float x, float y, const sk_paint_t* paint) {
+    AsSurface(surface)->draw(AsCanvas(canvas), x, y, AsPaint(paint));
+}
+
+bool sk_surface_peek_pixels(sk_surface_t* surface, sk_pixmap_t* pixmap) {
+    return AsSurface(surface)->peekPixels(AsPixmap(pixmap));
+}
+
+bool sk_surface_read_pixels(sk_surface_t* surface, sk_imageinfo_t* dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY) {
+    SkImageInfo info;
+    from_c(*dstInfo, &info);
+    return AsSurface(surface)->readPixels(info, dstPixels, dstRowBytes, srcX, srcY);
+}
+
+void sk_surface_get_props(sk_surface_t* surface, sk_surfaceprops_t* props) {
+    SkSurfaceProps skProps = AsSurface(surface)->props();
+    from_sk(&skProps, props);
+}
index 1a82429..43eb05e 100644 (file)
@@ -781,4 +781,11 @@ static inline void from_c(const sk_surfaceprops_t* cprops, SkSurfaceProps* props
     *props = SkSurfaceProps(cprops->flags, (SkPixelGeometry)cprops->pixelGeometry);
 }
 
+static inline void from_sk(const SkSurfaceProps* props, sk_surfaceprops_t* cprops) {
+    *cprops = {
+        (sk_pixelgeometry_t)props->pixelGeometry(),
+        (sk_surfaceprops_flags_t)props->flags()
+    };
+}
+
 #endif