Chromium Code Reviews| 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; | |
|
reed1
2014/12/02 17:41:43
can probably move the null-check to here, rather t
abarth-chromium
2014/12/02 17:43:16
IMHO, we should crash/assert. It seems better for
| |
| 335 from_c_matrix(cmatrix, &matrix); | |
| 336 AsCanvas(ccanvas)->concat(matrix); | |
| 337 } | |
| 338 | |
| 323 void sk_canvas_draw_paint(sk_canvas_t* ccanvas, const sk_paint_t* cpaint) { | 339 void sk_canvas_draw_paint(sk_canvas_t* ccanvas, const sk_paint_t* cpaint) { |
| 324 AsCanvas(ccanvas)->drawPaint(AsPaint(*cpaint)); | 340 AsCanvas(ccanvas)->drawPaint(AsPaint(*cpaint)); |
| 325 } | 341 } |
| 326 | 342 |
| 327 void sk_canvas_draw_rect(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_ paint_t* cpaint) { | 343 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)); | 344 AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint)); |
| 329 } | 345 } |
| 330 | 346 |
| 331 void sk_canvas_draw_oval(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_ paint_t* cpaint) { | 347 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)); | 348 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[], | 428 const sk_color_t colors[], |
| 413 const float colorPos[], | 429 const float colorPos[], |
| 414 int colorCount, | 430 int colorCount, |
| 415 sk_shader_tilemode_t cmode, | 431 sk_shader_tilemode_t cmode, |
| 416 const sk_matrix_t* cmatrix) { | 432 const sk_matrix_t* cmatrix) { |
| 417 SkShader::TileMode mode; | 433 SkShader::TileMode mode; |
| 418 if (!from_c_tilemode(cmode, &mode)) { | 434 if (!from_c_tilemode(cmode, &mode)) { |
| 419 return NULL; | 435 return NULL; |
| 420 } | 436 } |
| 421 SkMatrix matrix; | 437 SkMatrix matrix; |
| 422 if (cmatrix) { | 438 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), | 439 SkShader* s = SkGradientShader::CreateLinear(reinterpret_cast<const SkPoint* >(pts), |
| 430 reinterpret_cast<const SkColor* >(colors), | 440 reinterpret_cast<const SkColor* >(colors), |
| 431 colorPos, colorCount, mode, 0, &matrix); | 441 colorPos, colorCount, mode, 0, &matrix); |
| 432 return (sk_shader_t*)s; | 442 return (sk_shader_t*)s; |
| 433 } | 443 } |
| 434 | 444 |
| 435 //////////////////////////////////////////////////////////////////////////////// /////////// | 445 //////////////////////////////////////////////////////////////////////////////// /////////// |
| 436 //////////////////////////////////////////////////////////////////////////////// /////////// | 446 //////////////////////////////////////////////////////////////////////////////// /////////// |
| 437 | 447 |
| 438 void sk_test_capi(SkCanvas* canvas) { | 448 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); | 480 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface); |
| 471 | 481 |
| 472 // HERE WE CROSS THE C..C++ boundary | 482 // HERE WE CROSS THE C..C++ boundary |
| 473 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); | 483 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); |
| 474 | 484 |
| 475 sk_path_delete(cpath); | 485 sk_path_delete(cpath); |
| 476 sk_paint_delete(cpaint); | 486 sk_paint_delete(cpaint); |
| 477 sk_image_unref(cimage); | 487 sk_image_unref(cimage); |
| 478 sk_surface_unref(csurface); | 488 sk_surface_unref(csurface); |
| 479 } | 489 } |
| OLD | NEW |