--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+// EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL
+// DO NOT USE -- FOR INTERNAL TESTING ONLY
+
+#include "sk_canvas.h"
+#include "sk_paint.h"
+#include "sk_shader.h"
+#include "sk_surface.h"
+
+extern void sk_test_c_api(sk_canvas_t*);
+
+#define W 256
+#define H 256
+
+static sk_shader_t* make_shader() {
+ sk_point_t pts[] = { { 0, 0 }, { W, H } };
+ sk_color_t colors[] = { 0xFF00FF00, 0xFF0000FF };
+ return sk_shader_new_linear_gradient(pts, colors, NULL, 2, CLAMP_SK_SHADER_TILEMODE, NULL);
+}
+
+void sk_test_c_api(sk_canvas_t* canvas) {
+ sk_paint_t* paint = sk_paint_new();
+ sk_paint_set_antialias(paint, true);
+
+ sk_paint_set_color(paint, 0xFFFFFFFF);
+ sk_canvas_draw_paint(canvas, paint);
+
+ sk_rect_t r = { 10, 10, W - 10, H - 10 };
+
+ sk_paint_set_color(paint, 0xFFFF0000);
+ sk_canvas_draw_rect(canvas, &r, paint);
+
+ sk_shader_t* shader = make_shader();
+ sk_paint_set_shader(paint, shader);
+ sk_shader_unref(shader);
+
+ sk_canvas_draw_oval(canvas, &r, paint);
+
+ sk_paint_delete(paint);
+}
+
+
--- /dev/null
+/*
+ * 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 "gm.h"
+#include "sk_types.h"
+
+extern "C" void sk_test_c_api(sk_canvas_t*);
+
+class C_GM : public skiagm::GM {
+public:
+ C_GM() {}
+
+protected:
+ SkString onShortName() SK_OVERRIDE {
+ return SkString("c_gms");
+ }
+
+ SkISize onISize() SK_OVERRIDE {
+ return SkISize::Make(640, 480);
+ }
+
+ void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ sk_test_c_api((sk_canvas_t*)canvas);
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+DEF_GM( return new C_GM; )
+
'../gm/circularclips.cpp',
'../gm/clip_strokerect.cpp',
'../gm/clippedbitmapshaders.cpp',
+ '../gm/cgms.cpp',
+ '../gm/cgm.c',
'../gm/colorcube.cpp',
'../gm/coloremoji.cpp',
'../gm/colorfilterimagefilter.cpp',
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+// EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL
+// DO NOT USE -- FOR INTERNAL TESTING ONLY
+
+#ifndef sk_matrix_DEFINED
+#define sk_matrix_DEFINED
+
+#include "sk_types.h"
+
+SK_C_PLUS_PLUS_BEGIN_GUARD
+
+void sk_matrix_set_identity(sk_matrix_t*);
+
+void sk_matrix_set_translate(sk_matrix_t*, float tx, float ty);
+void sk_matrix_pre_translate(sk_matrix_t*, float tx, float ty);
+void sk_matrix_post_translate(sk_matrix_t*, float tx, float ty);
+
+void sk_matrix_set_scale(sk_matrix_t*, float sx, float sy);
+void sk_matrix_pre_scale(sk_matrix_t*, float sx, float sy);
+void sk_matrix_post_scale(sk_matrix_t*, float sx, float sy);
+
+SK_C_PLUS_PLUS_END_GUARD
+
+#endif
sk_paint_t* sk_paint_new();
void sk_paint_delete(sk_paint_t*);
+
bool sk_paint_is_antialias(const sk_paint_t*);
void sk_paint_set_antialias(sk_paint_t*, bool);
+
sk_color_t sk_paint_get_color(const sk_paint_t*);
void sk_paint_set_color(sk_paint_t*, sk_color_t);
+/**
+ * Set the paint's shader to the specified parameter. This will automatically call unref() on
+ * any previous value, and call ref() on the new value.
+ */
+void sk_paint_set_shader(sk_paint_t*, sk_shader_t*);
+
SK_C_PLUS_PLUS_END_GUARD
#endif
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+// EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL
+// DO NOT USE -- FOR INTERNAL TESTING ONLY
+
+#ifndef sk_shader_DEFINED
+#define sk_shader_DEFINED
+
+#include "sk_types.h"
+
+SK_C_PLUS_PLUS_BEGIN_GUARD
+
+void sk_shader_ref(sk_shader_t*);
+void sk_shader_unref(sk_shader_t*);
+
+typedef enum {
+ CLAMP_SK_SHADER_TILEMODE,
+ REPEAT_SK_SHADER_TILEMODE,
+ MIRROR_SK_SHADER_TILEMODE,
+} sk_shader_tilemode_t;
+
+sk_shader_t* sk_shader_new_linear_gradient(const sk_point_t pts[2],
+ const sk_color_t colors[],
+ const float colorPos[],
+ int colorCount,
+ sk_shader_tilemode_t tileMode,
+ const sk_matrix_t* localMatrix);
+
+
+SK_C_PLUS_PLUS_END_GUARD
+
+#endif
sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t*);
sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t*, void* pixels, size_t rowBytes);
-void sk_surface_delete(sk_surface_t*);
+void sk_surface_unref(sk_surface_t*);
/**
* Return the canvas associated with this surface. Note: the canvas is owned by the surface,
sk_alphatype_t alphaType;
} sk_imageinfo_t;
+typedef struct {
+ float x;
+ float y;
+} sk_point_t;
+
typedef struct {
float left;
float top;
float bottom;
} sk_rect_t;
+typedef struct {
+ float mat[9];
+} sk_matrix_t;
+
typedef struct sk_canvas_t sk_canvas_t;
typedef struct sk_image_t sk_image_t;
typedef struct sk_paint_t sk_paint_t;
typedef struct sk_path_t sk_path_t;
+typedef struct sk_shader_t sk_shader_t;
typedef struct sk_surface_t sk_surface_t;
//////////////////////////////////////////////////////////////////////////////////////////
return reinterpret_cast<SkCanvas*>(ccanvas);
}
+static SkShader* AsShader(sk_shader_t* cshader) {
+ return reinterpret_cast<SkShader*>(cshader);
+}
+
///////////////////////////////////////////////////////////////////////////////////////////
sk_colortype_t sk_colortype_get_default_8888() {
AsPaint(cpaint)->setColor(c);
}
+void sk_paint_set_shader(sk_paint_t* cpaint, sk_shader_t* cshader) {
+ AsPaint(cpaint)->setShader(AsShader(cshader));
+}
+
///////////////////////////////////////////////////////////////////////////////////////////
sk_path_t* sk_path_new() {
return (sk_surface_t*)SkSurface::NewRasterDirect(info, pixels, rowBytes);
}
-void sk_surface_delete(sk_surface_t* csurf) {
- SkSurface* surf = (SkSurface*)csurf;
- SkSafeUnref(surf);
+void sk_surface_unref(sk_surface_t* csurf) {
+ SkSafeUnref((SkSurface*)csurf);
}
sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) {
return (sk_image_t*)surf->newImageSnapshot();
}
+///////////////////////////////////////////////////////////////////////////////////////////
+
+#include "../../include/effects/SkGradientShader.h"
+#include "sk_shader.h"
+
+const struct {
+ sk_shader_tilemode_t fC;
+ SkShader::TileMode fSK;
+} gTileModeMap[] = {
+ { CLAMP_SK_SHADER_TILEMODE, SkShader::kClamp_TileMode },
+ { REPEAT_SK_SHADER_TILEMODE, SkShader::kRepeat_TileMode },
+ { MIRROR_SK_SHADER_TILEMODE, SkShader::kMirror_TileMode },
+};
+
+static bool from_c_tilemode(sk_shader_tilemode_t cMode, SkShader::TileMode* skMode) {
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gTileModeMap); ++i) {
+ if (cMode == gTileModeMap[i].fC) {
+ if (skMode) {
+ *skMode = gTileModeMap[i].fSK;
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
+void sk_shader_ref(sk_shader_t* cshader) {
+ SkSafeRef(AsShader(cshader));
+}
+
+void sk_shader_unref(sk_shader_t* cshader) {
+ SkSafeUnref(AsShader(cshader));
+}
+
+sk_shader_t* sk_shader_new_linear_gradient(const sk_point_t pts[2],
+ const sk_color_t colors[],
+ const float colorPos[],
+ int colorCount,
+ sk_shader_tilemode_t cmode,
+ const sk_matrix_t* cmatrix) {
+ SkShader::TileMode mode;
+ if (!from_c_tilemode(cmode, &mode)) {
+ return NULL;
+ }
+ SkMatrix matrix;
+ if (cmatrix) {
+ matrix.setAll(cmatrix->mat[0], cmatrix->mat[1], cmatrix->mat[2],
+ cmatrix->mat[3], cmatrix->mat[4], cmatrix->mat[5],
+ cmatrix->mat[6], cmatrix->mat[7], cmatrix->mat[8]);
+ } else {
+ matrix.setIdentity();
+ }
+ SkShader* s = SkGradientShader::CreateLinear(reinterpret_cast<const SkPoint*>(pts),
+ reinterpret_cast<const SkColor*>(colors),
+ colorPos, colorCount, mode, 0, &matrix);
+ return (sk_shader_t*)s;
+}
-///////////////////
+///////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////
void sk_test_capi(SkCanvas* canvas) {
sk_imageinfo_t cinfo;
sk_path_delete(cpath);
sk_paint_delete(cpaint);
sk_image_unref(cimage);
- sk_surface_delete(csurface);
+ sk_surface_unref(csurface);
}
REPORTER_ASSERT(reporter, 0xFFFFFFFF == pixel[0]);
sk_paint_delete(paint);
- sk_surface_delete(surface);
+ sk_surface_unref(surface);
}
DEF_TEST(C_API, reporter) {