2 * Copyright 2016 Xamarin Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "sk_canvas.h"
12 #include "sk_types_priv.h"
14 void sk_canvas_clear(sk_canvas_t* ccanvas, sk_color_t color) {
15 AsCanvas(ccanvas)->clear(color);
18 void sk_canvas_discard(sk_canvas_t* ccanvas) {
19 AsCanvas(ccanvas)->discard();
22 int sk_canvas_get_save_count(sk_canvas_t* ccanvas) {
23 return AsCanvas(ccanvas)->getSaveCount();
26 void sk_canvas_restore_to_count(sk_canvas_t* ccanvas, int saveCount) {
27 AsCanvas(ccanvas)->restoreToCount(saveCount);
30 void sk_canvas_draw_color(sk_canvas_t* ccanvas, sk_color_t color, sk_xfermode_mode_t cmode) {
31 AsCanvas(ccanvas)->drawColor(color, (SkXfermode::Mode)cmode);
34 void sk_canvas_draw_points(sk_canvas_t* ccanvas, sk_point_mode_t pointMode, size_t count, const sk_point_t points [], const sk_paint_t* cpaint)
36 AsCanvas(ccanvas)->drawPoints ((SkCanvas::PointMode)pointMode, count, AsPoint(points), *AsPaint(cpaint));
39 void sk_canvas_draw_point(sk_canvas_t* ccanvas, float x, float y, const sk_paint_t* cpaint)
41 AsCanvas(ccanvas)->drawPoint (x, y, *AsPaint(cpaint));
44 void sk_canvas_draw_point_color(sk_canvas_t* ccanvas, float x, float y, sk_color_t color)
46 AsCanvas(ccanvas)->drawPoint (x, y, color);
49 void sk_canvas_draw_line(sk_canvas_t* ccanvas, float x0, float y0, float x1, float y1, sk_paint_t* cpaint)
51 AsCanvas(ccanvas)->drawLine(x0, y0, x1, y1, *AsPaint(cpaint));
54 void sk_canvas_draw_text (sk_canvas_t* ccanvas, const char *text, size_t byteLength, float x, float y, const sk_paint_t* cpaint)
56 AsCanvas(ccanvas)->drawText(text, byteLength, x, y, *AsPaint(cpaint));
59 void sk_canvas_draw_pos_text (sk_canvas_t* ccanvas, const char *text, size_t byteLength, const sk_point_t pos[], const sk_paint_t* cpaint)
61 AsCanvas(ccanvas)->drawPosText(text, byteLength, AsPoint(pos), *AsPaint(cpaint));
64 void sk_canvas_draw_text_on_path (sk_canvas_t* ccanvas, const char *text, size_t byteLength, const sk_path_t* path,
65 float hOffset, float vOffset, const sk_paint_t* cpaint)
67 AsCanvas(ccanvas)->drawTextOnPathHV(text, byteLength, AsPath(*path), hOffset, vOffset, *AsPaint(cpaint));
70 void sk_canvas_draw_bitmap(sk_canvas_t* ccanvas, const sk_bitmap_t* cbitmap, float x, float y, const sk_paint_t* cpaint)
72 AsCanvas(ccanvas)->drawBitmap(*AsBitmap(cbitmap), x, y, AsPaint(cpaint));
75 void sk_canvas_draw_bitmap_rect(sk_canvas_t* ccanvas, const sk_bitmap_t* cbitmap, const sk_rect_t* csrcR, const sk_rect_t* cdstR, const sk_paint_t* cpaint)
77 SkCanvas* canvas = AsCanvas(ccanvas);
78 const SkBitmap& bitmap = *AsBitmap(cbitmap);
79 const SkRect& dst = AsRect(*cdstR);
80 const SkPaint* paint = AsPaint(cpaint);
83 canvas->drawBitmapRect(bitmap, AsRect(*csrcR), dst, paint);
86 canvas->drawBitmapRect(bitmap, dst, paint);
90 void sk_canvas_reset_matrix(sk_canvas_t* ccanvas)
92 AsCanvas(ccanvas)->resetMatrix();
95 void sk_canvas_set_matrix(sk_canvas_t* ccanvas, const sk_matrix_t* cmatrix)
99 from_c(cmatrix, &matrix);
101 AsCanvas(ccanvas)->setMatrix(matrix);
104 void sk_canvas_get_total_matrix(sk_canvas_t* ccanvas, sk_matrix_t* cmatrix)
106 SkMatrix matrix = AsCanvas(ccanvas)->getTotalMatrix();
107 from_sk(&matrix, cmatrix);
110 void sk_canvas_draw_round_rect(sk_canvas_t* ccanvas, const sk_rect_t* crect, float rx, float ry, const sk_paint_t* cpaint) {
111 AsCanvas(ccanvas)->drawRoundRect(AsRect(*crect), rx, ry, AsPaint(*cpaint));
114 void sk_canvas_clip_rect_with_operation(sk_canvas_t* ccanvas, const sk_rect_t* crect, sk_region_op_t op, bool doAA) {
115 AsCanvas(ccanvas)->clipRect(AsRect(*crect), (SkRegion::Op)op, doAA);
118 void sk_canvas_clip_path_with_operation(sk_canvas_t* ccanvas, const sk_path_t* cpath, sk_region_op_t op, bool doAA) {
119 AsCanvas(ccanvas)->clipPath(AsPath(*cpath), (SkRegion::Op)op, doAA);
122 bool sk_canvas_get_clip_bounds(sk_canvas_t* ccanvas, sk_rect_t* cbounds) {
123 return AsCanvas(ccanvas)->getClipBounds(AsRect(cbounds));
126 bool sk_canvas_get_clip_device_bounds(sk_canvas_t* ccanvas, sk_irect_t* cbounds) {
127 return AsCanvas(ccanvas)->getClipDeviceBounds(AsIRect(cbounds));
130 int sk_canvas_save(sk_canvas_t* ccanvas) {
131 return AsCanvas(ccanvas)->save();
134 int sk_canvas_save_layer(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_paint_t* cpaint) {
135 return AsCanvas(ccanvas)->saveLayer(AsRect(crect), AsPaint(cpaint));
138 void sk_canvas_restore(sk_canvas_t* ccanvas) {
139 AsCanvas(ccanvas)->restore();
142 void sk_canvas_translate(sk_canvas_t* ccanvas, float dx, float dy) {
143 AsCanvas(ccanvas)->translate(dx, dy);
146 void sk_canvas_scale(sk_canvas_t* ccanvas, float sx, float sy) {
147 AsCanvas(ccanvas)->scale(sx, sy);
150 void sk_canvas_rotate_degrees(sk_canvas_t* ccanvas, float degrees) {
151 AsCanvas(ccanvas)->rotate(degrees);
154 void sk_canvas_rotate_radians(sk_canvas_t* ccanvas, float radians) {
155 AsCanvas(ccanvas)->rotate(SkRadiansToDegrees(radians));
158 void sk_canvas_skew(sk_canvas_t* ccanvas, float sx, float sy) {
159 AsCanvas(ccanvas)->skew(sx, sy);
162 void sk_canvas_concat(sk_canvas_t* ccanvas, const sk_matrix_t* cmatrix) {
165 from_c(cmatrix, &matrix);
166 AsCanvas(ccanvas)->concat(matrix);
169 void sk_canvas_clip_rect(sk_canvas_t* ccanvas, const sk_rect_t* crect) {
170 AsCanvas(ccanvas)->clipRect(AsRect(*crect));
173 void sk_canvas_clip_path(sk_canvas_t* ccanvas, const sk_path_t* cpath) {
174 AsCanvas(ccanvas)->clipPath(AsPath(*cpath));
177 void sk_canvas_draw_paint(sk_canvas_t* ccanvas, const sk_paint_t* cpaint) {
178 AsCanvas(ccanvas)->drawPaint(AsPaint(*cpaint));
181 void sk_canvas_draw_rect(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_paint_t* cpaint) {
182 AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint));
185 void sk_canvas_draw_circle(sk_canvas_t* ccanvas, float cx, float cy, float rad,
186 const sk_paint_t* cpaint) {
187 AsCanvas(ccanvas)->drawCircle(cx, cy, rad, AsPaint(*cpaint));
190 void sk_canvas_draw_oval(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_paint_t* cpaint) {
191 AsCanvas(ccanvas)->drawOval(AsRect(*crect), AsPaint(*cpaint));
194 void sk_canvas_draw_path(sk_canvas_t* ccanvas, const sk_path_t* cpath, const sk_paint_t* cpaint) {
195 AsCanvas(ccanvas)->drawPath(AsPath(*cpath), AsPaint(*cpaint));
198 void sk_canvas_draw_image(sk_canvas_t* ccanvas, const sk_image_t* cimage, float x, float y,
199 const sk_paint_t* cpaint) {
200 AsCanvas(ccanvas)->drawImage(AsImage(cimage), x, y, AsPaint(cpaint));
203 void sk_canvas_draw_image_rect(sk_canvas_t* ccanvas, const sk_image_t* cimage,
204 const sk_rect_t* csrcR, const sk_rect_t* cdstR,
205 const sk_paint_t* cpaint) {
206 SkCanvas* canvas = AsCanvas(ccanvas);
207 const SkImage* image = AsImage(cimage);
208 const SkRect& dst = AsRect(*cdstR);
209 const SkPaint* paint = AsPaint(cpaint);
212 canvas->drawImageRect(image, AsRect(*csrcR), dst, paint);
214 canvas->drawImageRect(image, dst, paint);
218 void sk_canvas_draw_picture(sk_canvas_t* ccanvas, const sk_picture_t* cpicture,
219 const sk_matrix_t* cmatrix, const sk_paint_t* cpaint) {
220 const SkMatrix* matrixPtr = NULL;
223 from_c(cmatrix, &matrix);
226 AsCanvas(ccanvas)->drawPicture(AsPicture(cpicture), matrixPtr, AsPaint(cpaint));
229 void sk_canvas_flush(sk_canvas_t* ccanvas) {
230 AsCanvas(ccanvas)->flush();
233 sk_canvas_t* sk_canvas_new_from_bitmap(const sk_bitmap_t* bitmap) {
234 return ToCanvas(new SkCanvas(AsBitmap(*bitmap)));
237 void sk_canvas_draw_bitmap_lattice(sk_canvas_t* ccanvas,
238 const sk_bitmap_t* bitmap,
239 const int* xDivs, int xCount, const int* yDivs, int yCount,
240 const sk_rect_t* dst,
241 const sk_paint_t* paint) {
242 SkCanvas::Lattice lattice = { xDivs, xCount, yDivs, yCount };
243 AsCanvas(ccanvas)->drawBitmapLattice(AsBitmap(*bitmap), lattice, AsRect(*dst), AsPaint(paint));
246 void sk_canvas_draw_image_lattice(sk_canvas_t* ccanvas,
247 const sk_image_t* image,
248 const int* xDivs, int xCount, const int* yDivs, int yCount,
249 const sk_rect_t* dst,
250 const sk_paint_t* paint) {
251 SkCanvas::Lattice lattice = { xDivs, xCount, yDivs, yCount };
252 AsCanvas(ccanvas)->drawImageLattice(AsImage(image), lattice, AsRect(*dst), AsPaint(paint));