OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "sk_canvas.h" | 8 #include "sk_canvas.h" |
9 #include "sk_image.h" | 9 #include "sk_image.h" |
10 #include "sk_paint.h" | 10 #include "sk_paint.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 if (!from_c_alphatype(cinfo.alphaType, &at)) { | 84 if (!from_c_alphatype(cinfo.alphaType, &at)) { |
85 // optionally report error to client? | 85 // optionally report error to client? |
86 return false; | 86 return false; |
87 } | 87 } |
88 if (info) { | 88 if (info) { |
89 *info = SkImageInfo::Make(cinfo.width, cinfo.height, ct, at); | 89 *info = SkImageInfo::Make(cinfo.width, cinfo.height, ct, at); |
90 } | 90 } |
91 return true; | 91 return true; |
92 } | 92 } |
93 | 93 |
| 94 static void from_c_matrix(const sk_matrix_t* cmatrix, SkMatrix* matrix) { |
| 95 if (cmatrix) { |
| 96 matrix->setAll(cmatrix->mat[0], cmatrix->mat[1], cmatrix->mat[2], |
| 97 cmatrix->mat[3], cmatrix->mat[4], cmatrix->mat[5], |
| 98 cmatrix->mat[6], cmatrix->mat[7], cmatrix->mat[8]); |
| 99 } else { |
| 100 matrix->setIdentity(); |
| 101 } |
| 102 } |
| 103 |
94 const struct { | 104 const struct { |
95 sk_path_direction_t fC; | 105 sk_path_direction_t fC; |
96 SkPath::Direction fSk; | 106 SkPath::Direction fSk; |
97 } gPathDirMap[] = { | 107 } gPathDirMap[] = { |
98 { CW_SK_PATH_DIRECTION, SkPath::kCW_Direction }, | 108 { CW_SK_PATH_DIRECTION, SkPath::kCW_Direction }, |
99 { CCW_SK_PATH_DIRECTION, SkPath::kCCW_Direction }, | 109 { CCW_SK_PATH_DIRECTION, SkPath::kCCW_Direction }, |
100 }; | 110 }; |
101 | 111 |
102 static bool from_c_path_direction(sk_path_direction_t cdir, SkPath::Direction* d
ir) { | 112 static bool from_c_path_direction(sk_path_direction_t cdir, SkPath::Direction* d
ir) { |
103 for (size_t i = 0; i < SK_ARRAY_COUNT(gPathDirMap); ++i) { | 113 for (size_t i = 0; i < SK_ARRAY_COUNT(gPathDirMap); ++i) { |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 } | 323 } |
314 | 324 |
315 void sk_canvas_rotate_radians(sk_canvas_t* ccanvas, float radians) { | 325 void sk_canvas_rotate_radians(sk_canvas_t* ccanvas, float radians) { |
316 AsCanvas(ccanvas)->rotate(SkRadiansToDegrees(radians)); | 326 AsCanvas(ccanvas)->rotate(SkRadiansToDegrees(radians)); |
317 } | 327 } |
318 | 328 |
319 void sk_canvas_skew(sk_canvas_t* ccanvas, float sx, float sy) { | 329 void sk_canvas_skew(sk_canvas_t* ccanvas, float sx, float sy) { |
320 AsCanvas(ccanvas)->skew(sx, sy); | 330 AsCanvas(ccanvas)->skew(sx, sy); |
321 } | 331 } |
322 | 332 |
| 333 void sk_canvas_concat_matrix(sk_canvas_t* ccanvas, const sk_matrix_t* cmatrix) { |
| 334 SkMatrix matrix; |
| 335 from_c_matrix(cmatrix, &matrix); |
| 336 AsCanvas(ccanvas)->concat(matrix); |
| 337 } |
| 338 |
| 339 void sk_canvas_set_matrix(sk_canvas_t* ccanvas, const sk_matrix_t* cmatrix) { |
| 340 SkMatrix matrix; |
| 341 from_c_matrix(cmatrix, &matrix); |
| 342 AsCanvas(ccanvas)->setMatrix(matrix); |
| 343 } |
| 344 |
| 345 void sk_canvas_reset_matrix(sk_canvas_t* ccanvas) { |
| 346 AsCanvas(ccanvas)->resetMatrix(); |
| 347 } |
| 348 |
323 void sk_canvas_draw_paint(sk_canvas_t* ccanvas, const sk_paint_t* cpaint) { | 349 void sk_canvas_draw_paint(sk_canvas_t* ccanvas, const sk_paint_t* cpaint) { |
324 AsCanvas(ccanvas)->drawPaint(AsPaint(*cpaint)); | 350 AsCanvas(ccanvas)->drawPaint(AsPaint(*cpaint)); |
325 } | 351 } |
326 | 352 |
327 void sk_canvas_draw_rect(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_
paint_t* cpaint) { | 353 void sk_canvas_draw_rect(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_
paint_t* cpaint) { |
328 AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint)); | 354 AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint)); |
329 } | 355 } |
330 | 356 |
331 void sk_canvas_draw_oval(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_
paint_t* cpaint) { | 357 void sk_canvas_draw_oval(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_
paint_t* cpaint) { |
332 AsCanvas(ccanvas)->drawOval(AsRect(*crect), AsPaint(*cpaint)); | 358 AsCanvas(ccanvas)->drawOval(AsRect(*crect), AsPaint(*cpaint)); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 const sk_color_t colors[], | 438 const sk_color_t colors[], |
413 const float colorPos[], | 439 const float colorPos[], |
414 int colorCount, | 440 int colorCount, |
415 sk_shader_tilemode_t cmode, | 441 sk_shader_tilemode_t cmode, |
416 const sk_matrix_t* cmatrix) { | 442 const sk_matrix_t* cmatrix) { |
417 SkShader::TileMode mode; | 443 SkShader::TileMode mode; |
418 if (!from_c_tilemode(cmode, &mode)) { | 444 if (!from_c_tilemode(cmode, &mode)) { |
419 return NULL; | 445 return NULL; |
420 } | 446 } |
421 SkMatrix matrix; | 447 SkMatrix matrix; |
422 if (cmatrix) { | 448 from_c_matrix(cmatrix, &matrix); |
423 matrix.setAll(cmatrix->mat[0], cmatrix->mat[1], cmatrix->mat[2], | |
424 cmatrix->mat[3], cmatrix->mat[4], cmatrix->mat[5], | |
425 cmatrix->mat[6], cmatrix->mat[7], cmatrix->mat[8]); | |
426 } else { | |
427 matrix.setIdentity(); | |
428 } | |
429 SkShader* s = SkGradientShader::CreateLinear(reinterpret_cast<const SkPoint*
>(pts), | 449 SkShader* s = SkGradientShader::CreateLinear(reinterpret_cast<const SkPoint*
>(pts), |
430 reinterpret_cast<const SkColor*
>(colors), | 450 reinterpret_cast<const SkColor*
>(colors), |
431 colorPos, colorCount, mode, 0,
&matrix); | 451 colorPos, colorCount, mode, 0,
&matrix); |
432 return (sk_shader_t*)s; | 452 return (sk_shader_t*)s; |
433 } | 453 } |
434 | 454 |
435 ////////////////////////////////////////////////////////////////////////////////
/////////// | 455 ////////////////////////////////////////////////////////////////////////////////
/////////// |
436 ////////////////////////////////////////////////////////////////////////////////
/////////// | 456 ////////////////////////////////////////////////////////////////////////////////
/////////// |
437 | 457 |
438 void sk_test_capi(SkCanvas* canvas) { | 458 void sk_test_capi(SkCanvas* canvas) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface); | 490 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface); |
471 | 491 |
472 // HERE WE CROSS THE C..C++ boundary | 492 // HERE WE CROSS THE C..C++ boundary |
473 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); | 493 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); |
474 | 494 |
475 sk_path_delete(cpath); | 495 sk_path_delete(cpath); |
476 sk_paint_delete(cpaint); | 496 sk_paint_delete(cpaint); |
477 sk_image_unref(cimage); | 497 sk_image_unref(cimage); |
478 sk_surface_unref(csurface); | 498 sk_surface_unref(csurface); |
479 } | 499 } |
OLD | NEW |