Index: experimental/sk_surface.cpp |
diff --git a/experimental/sk_surface.cpp b/experimental/sk_surface.cpp |
index 0fb4ca7d02624608c4c04902012c483059372ad6..1158b42cdcc81e3c59ea5cd36a672b4aa65a8ff7 100644 |
--- a/experimental/sk_surface.cpp |
+++ b/experimental/sk_surface.cpp |
@@ -1,3 +1,10 @@ |
+/* |
+ * Copyright 2014 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
#include "sk_surface.h" |
#include "SkCanvas.h" |
@@ -7,27 +14,91 @@ |
#include "SkPath.h" |
#include "SkSurface.h" |
-void sk_matrix_set_identity(sk_matrix_t* cmatrix) { |
- sk_bzero(cmatrix->mat, sizeof(9 * sizeof(float))); |
- cmatrix->mat[0] = cmatrix->mat[4] = cmatrix->mat[8] = 1; |
-} |
- |
-static SkImageInfo make(const sk_image_info& cinfo) { |
+static SkImageInfo make(const sk_imageinfo_t& cinfo) { |
return SkImageInfo::Make(cinfo.width, cinfo.height, |
(SkColorType)cinfo.colorType, (SkAlphaType)cinfo.alphaType); |
} |
-static const SkRect& AsRect(const sk_rect_t& crect) { return static_cast<const SkRect&>(crect); } |
+static const SkRect& AsRect(const sk_rect_t& crect) { |
+ return reinterpret_cast<const SkRect&>(crect); |
+} |
+ |
+static const SkPath& AsPath(const sk_path_t& cpath) { |
+ return reinterpret_cast<const SkPath&>(cpath); |
+} |
+ |
+static const SkImage* AsImage(const sk_image_t* cimage) { |
+ return reinterpret_cast<const SkImage*>(cimage); |
+} |
static const SkPaint& AsPaint(const sk_paint_t& cpaint) { |
- return static_cast<const SkPaint&>(cpaint); |
+ return reinterpret_cast<const SkPaint&>(cpaint); |
} |
static const SkPaint* AsPaint(const sk_paint_t* cpaint) { |
- return static_cast<const SkPaint*>(cpaint); |
+ return reinterpret_cast<const SkPaint*>(cpaint); |
+} |
+ |
+static SkPaint* AsPaint(sk_paint_t* cpaint) { |
+ return reinterpret_cast<SkPaint*>(cpaint); |
+} |
+ |
+static SkCanvas* AsCanvas(sk_canvas_t* ccanvas) { |
+ return reinterpret_cast<SkCanvas*>(ccanvas); |
+} |
+ |
+/////////////////////////////////////////////////////////////////////////////////////////// |
+ |
+sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t* cinfo, const void* pixels, |
+ size_t rowBytes) { |
+ return (sk_image_t*)SkImage::NewRasterCopy(make(*cinfo), pixels, rowBytes); |
+} |
+ |
+void sk_image_ref(const sk_image_t* cimage) { |
+ AsImage(cimage)->ref(); |
+} |
+ |
+void sk_image_unref(const sk_image_t* cimage) { |
+ AsImage(cimage)->unref(); |
+} |
+ |
+int sk_image_get_width(const sk_image_t* cimage) { |
+ return AsImage(cimage)->width(); |
+} |
+ |
+int sk_image_get_height(const sk_image_t* cimage) { |
+ return AsImage(cimage)->height(); |
} |
-static SkCanvas* AsCanvas(sk_canvas_t* ccanvas) { return static_cast<SkCanvas*>(ccanvas); } |
+uint32_t sk_image_get_unique_id(const sk_image_t* cimage) { |
+ return AsImage(cimage)->uniqueID(); |
+} |
+ |
+/////////////////////////////////////////////////////////////////////////////////////////// |
+ |
+sk_paint_t* sk_paint_new() { |
+ return (sk_paint_t*)SkNEW(SkPaint); |
+} |
+ |
+void sk_paint_delete(sk_paint_t* cpaint) { |
+ SkDELETE(AsPaint(cpaint)); |
+} |
+ |
+bool sk_paint_is_antialias(const sk_paint_t* cpaint) { |
+ return AsPaint(*cpaint).isAntiAlias(); |
+} |
+ |
+void sk_paint_set_antialias(sk_paint_t* cpaint, bool aa) { |
+ AsPaint(cpaint)->setAntiAlias(aa); |
+} |
+ |
+sk_color_t sk_paint_get_color(const sk_paint_t* cpaint) { |
+ return AsPaint(*cpaint).getColor(); |
+} |
+ |
+void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) { |
+ AsPaint(cpaint)->setColor(c); |
+} |
/////////////////////////////////////////////////////////////////////////////////////////// |
@@ -48,11 +119,7 @@ void sk_canvas_translate(sk_canvas_t* ccanvas, float dx, float dy) { |
} |
void sk_canvas_scale(sk_canvas_t* ccanvas, float sx, float sy) { |
- AsCanvas(ccanvas)->scale(dx, dy); |
-} |
- |
-void sk_canvas_concat(sk_canvas_t* ccanvas, const sk_matrix_t* cmatrix) { |
- AsCanvas(ccanvas)->concat(AsMatrix(*cmatrix)); |
+ AsCanvas(ccanvas)->scale(sx, sy); |
} |
void sk_canvas_draw_paint(sk_canvas_t* ccanvas, const sk_paint_t* cpaint) { |
@@ -78,30 +145,11 @@ void sk_canvas_draw_image(sk_canvas_t* ccanvas, const sk_image_t* cimage, float |
/////////////////////////////////////////////////////////////////////////////////////////// |
-sk_image_t* sk_image_new_raster_copy(const sk_image_info_t* cinfo, const void* pixels, |
- size_t rowBytes) { |
- return (sk_image_t*)SkImage::NewRasterCopy(make(*cinfo), pixels, rowBytes); |
-} |
- |
-int sk_image_get_width(const sk_image_t* cimage) { |
- return ((const SkImage*)cimage)->width(); |
-} |
- |
-int sk_image_get_height(const sk_image_t* cimage) { |
- return ((const SkImage*)cimage)->height(); |
-} |
- |
-uint32_t sk_image_get_unique_id(const sk_image_t* cimage) { |
- return ((const SkImage*)cimage)->uniqueID(); |
-} |
- |
-/////////////////////////////////////////////////////////////////////////////////////////// |
- |
-sk_surface_t* sk_surface_new_raster(const sk_image_info_t* cinfo) { |
+sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t* cinfo) { |
return (sk_surface_t*)SkSurface::NewRaster(make(*cinfo)); |
} |
-sk_surface_t* sk_surface_new_raster_direct(const sk_image_info_t* cinfo, void* pixels, |
+sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pixels, |
size_t rowBytes) { |
return (sk_surface_t*)SkSurface::NewRasterDirect(make(*cinfo), pixels, rowBytes); |
} |
@@ -113,12 +161,47 @@ void sk_surface_delete(sk_surface_t* csurf) { |
sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) { |
SkSurface* surf = (SkSurface*)csurf; |
- return surf->getCanvas(); |
+ return (sk_canvas_t*)surf->getCanvas(); |
} |
sk_image_t* sk_surface_new_image_snapshot(sk_surface_t* csurf) { |
SkSurface* surf = (SkSurface*)csurf; |
- return surf->newImageSnapshot(); |
+ return (sk_image_t*)surf->newImageSnapshot(); |
+} |
+ |
+ |
+/////////////////// |
+ |
+void sk_test_capi(SkCanvas* canvas) { |
+ sk_imageinfo_t cinfo; |
+ cinfo.width = 100; |
+ cinfo.height = 100; |
+ cinfo.colorType = (sk_colortype_t)kN32_SkColorType; |
+ cinfo.alphaType = (sk_alphatype_t)kPremul_SkAlphaType; |
+ |
+ sk_surface_t* csurface = sk_surface_new_raster(&cinfo); |
+ sk_canvas_t* ccanvas = sk_surface_get_canvas(csurface); |
+ |
+ sk_paint_t* cpaint = sk_paint_new(); |
+ sk_paint_set_antialias(cpaint, true); |
+ sk_paint_set_color(cpaint, 0xFFFF0000); |
+ |
+ sk_rect_t cr = { 5, 5, 95, 95 }; |
+ sk_canvas_draw_oval(ccanvas, &cr, cpaint); |
+ |
+ cr.left += 25; |
+ cr.top += 25; |
+ cr.right -= 25; |
+ cr.bottom -= 25; |
+ sk_paint_set_color(cpaint, 0xFF00FF00); |
+ sk_canvas_draw_rect(ccanvas, &cr, cpaint); |
+ |
+ sk_image_t* cimage = sk_surface_new_image_snapshot(csurface); |
+ |
+ // HERE WE CROSS THE C..C++ boundary |
+ canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); |
+ |
+ sk_paint_delete(cpaint); |
+ sk_image_unref(cimage); |
+ sk_surface_delete(csurface); |
} |
- |
- |