| 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_data.h" | 9 #include "sk_data.h" |
| 10 #include "sk_image.h" | 10 #include "sk_image.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 if (!from_c_alphatype(cinfo.alphaType, &at)) { | 89 if (!from_c_alphatype(cinfo.alphaType, &at)) { |
| 90 // optionally report error to client? | 90 // optionally report error to client? |
| 91 return false; | 91 return false; |
| 92 } | 92 } |
| 93 if (info) { | 93 if (info) { |
| 94 *info = SkImageInfo::Make(cinfo.width, cinfo.height, ct, at); | 94 *info = SkImageInfo::Make(cinfo.width, cinfo.height, ct, at); |
| 95 } | 95 } |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 const struct { |
| 100 sk_pixelgeometry_t fC; |
| 101 SkPixelGeometry fSK; |
| 102 } gPixelGeometryMap[] = { |
| 103 { UNKNOWN_SK_PIXELGEOMETRY, kUnknown_SkPixelGeometry }, |
| 104 { RGB_H_SK_PIXELGEOMETRY, kRGB_H_SkPixelGeometry }, |
| 105 { BGR_H_SK_PIXELGEOMETRY, kBGR_H_SkPixelGeometry }, |
| 106 { RGB_V_SK_PIXELGEOMETRY, kRGB_V_SkPixelGeometry }, |
| 107 { BGR_V_SK_PIXELGEOMETRY, kBGR_V_SkPixelGeometry }, |
| 108 }; |
| 109 |
| 110 |
| 111 static bool from_c_pixelgeometry(sk_pixelgeometry_t cGeom, SkPixelGeometry* skGe
om) { |
| 112 for (size_t i = 0; i < SK_ARRAY_COUNT(gPixelGeometryMap); ++i) { |
| 113 if (gPixelGeometryMap[i].fC == cGeom) { |
| 114 if (skGeom) { |
| 115 *skGeom = gPixelGeometryMap[i].fSK; |
| 116 } |
| 117 return true; |
| 118 } |
| 119 } |
| 120 return false; |
| 121 } |
| 122 |
| 99 static void from_c_matrix(const sk_matrix_t* cmatrix, SkMatrix* matrix) { | 123 static void from_c_matrix(const sk_matrix_t* cmatrix, SkMatrix* matrix) { |
| 100 matrix->setAll(cmatrix->mat[0], cmatrix->mat[1], cmatrix->mat[2], | 124 matrix->setAll(cmatrix->mat[0], cmatrix->mat[1], cmatrix->mat[2], |
| 101 cmatrix->mat[3], cmatrix->mat[4], cmatrix->mat[5], | 125 cmatrix->mat[3], cmatrix->mat[4], cmatrix->mat[5], |
| 102 cmatrix->mat[6], cmatrix->mat[7], cmatrix->mat[8]); | 126 cmatrix->mat[6], cmatrix->mat[7], cmatrix->mat[8]); |
| 103 } | 127 } |
| 104 | 128 |
| 105 const struct { | 129 const struct { |
| 106 sk_path_direction_t fC; | 130 sk_path_direction_t fC; |
| 107 SkPath::Direction fSk; | 131 SkPath::Direction fSk; |
| 108 } gPathDirMap[] = { | 132 } gPathDirMap[] = { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 SkMatrix matrix; | 407 SkMatrix matrix; |
| 384 if (cmatrix) { | 408 if (cmatrix) { |
| 385 from_c_matrix(cmatrix, &matrix); | 409 from_c_matrix(cmatrix, &matrix); |
| 386 matrixPtr = &matrix; | 410 matrixPtr = &matrix; |
| 387 } | 411 } |
| 388 AsCanvas(ccanvas)->drawPicture(AsPicture(cpicture), matrixPtr, AsPaint(cpain
t)); | 412 AsCanvas(ccanvas)->drawPicture(AsPicture(cpicture), matrixPtr, AsPaint(cpain
t)); |
| 389 } | 413 } |
| 390 | 414 |
| 391 ////////////////////////////////////////////////////////////////////////////////
/////////// | 415 ////////////////////////////////////////////////////////////////////////////////
/////////// |
| 392 | 416 |
| 393 sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t* cinfo) { | 417 sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t* cinfo, |
| 418 const sk_surfaceprops_t* props) { |
| 394 SkImageInfo info; | 419 SkImageInfo info; |
| 395 if (!from_c_info(*cinfo, &info)) { | 420 if (!from_c_info(*cinfo, &info)) { |
| 396 return NULL; | 421 return NULL; |
| 397 } | 422 } |
| 398 return (sk_surface_t*)SkSurface::NewRaster(info); | 423 SkPixelGeometry geo = kUnknown_SkPixelGeometry; |
| 424 if (props && !from_c_pixelgeometry(props->pixelGeometry, &geo)) { |
| 425 return NULL; |
| 426 } |
| 427 |
| 428 SkSurfaceProps surfProps(0, geo); |
| 429 return (sk_surface_t*)SkSurface::NewRaster(info, &surfProps); |
| 399 } | 430 } |
| 400 | 431 |
| 401 sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pi
xels, | 432 sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pi
xels, |
| 402 size_t rowBytes) { | 433 size_t rowBytes, |
| 434 const sk_surfaceprops_t* props) { |
| 403 SkImageInfo info; | 435 SkImageInfo info; |
| 404 if (!from_c_info(*cinfo, &info)) { | 436 if (!from_c_info(*cinfo, &info)) { |
| 405 return NULL; | 437 return NULL; |
| 406 } | 438 } |
| 407 return (sk_surface_t*)SkSurface::NewRasterDirect(info, pixels, rowBytes); | 439 SkPixelGeometry geo = kUnknown_SkPixelGeometry; |
| 440 if (props && !from_c_pixelgeometry(props->pixelGeometry, &geo)) { |
| 441 return NULL; |
| 442 } |
| 443 |
| 444 SkSurfaceProps surfProps(0, geo); |
| 445 return (sk_surface_t*)SkSurface::NewRasterDirect(info, pixels, rowBytes, &su
rfProps); |
| 408 } | 446 } |
| 409 | 447 |
| 410 void sk_surface_unref(sk_surface_t* csurf) { | 448 void sk_surface_unref(sk_surface_t* csurf) { |
| 411 SkSafeUnref((SkSurface*)csurf); | 449 SkSafeUnref((SkSurface*)csurf); |
| 412 } | 450 } |
| 413 | 451 |
| 414 sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) { | 452 sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) { |
| 415 SkSurface* surf = (SkSurface*)csurf; | 453 SkSurface* surf = (SkSurface*)csurf; |
| 416 return (sk_canvas_t*)surf->getCanvas(); | 454 return (sk_canvas_t*)surf->getCanvas(); |
| 417 } | 455 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 ////////////////////////////////////////////////////////////////////////////////
/////////// | 626 ////////////////////////////////////////////////////////////////////////////////
/////////// |
| 589 ////////////////////////////////////////////////////////////////////////////////
/////////// | 627 ////////////////////////////////////////////////////////////////////////////////
/////////// |
| 590 | 628 |
| 591 void sk_test_capi(SkCanvas* canvas) { | 629 void sk_test_capi(SkCanvas* canvas) { |
| 592 sk_imageinfo_t cinfo; | 630 sk_imageinfo_t cinfo; |
| 593 cinfo.width = 100; | 631 cinfo.width = 100; |
| 594 cinfo.height = 100; | 632 cinfo.height = 100; |
| 595 cinfo.colorType = (sk_colortype_t)kN32_SkColorType; | 633 cinfo.colorType = (sk_colortype_t)kN32_SkColorType; |
| 596 cinfo.alphaType = (sk_alphatype_t)kPremul_SkAlphaType; | 634 cinfo.alphaType = (sk_alphatype_t)kPremul_SkAlphaType; |
| 597 | 635 |
| 598 sk_surface_t* csurface = sk_surface_new_raster(&cinfo); | 636 sk_surfaceprops_t surfaceprops; |
| 637 surfaceprops.pixelGeometry = UNKNOWN_SK_PIXELGEOMETRY; |
| 638 |
| 639 sk_surface_t* csurface = sk_surface_new_raster(&cinfo, &surfaceprops); |
| 599 sk_canvas_t* ccanvas = sk_surface_get_canvas(csurface); | 640 sk_canvas_t* ccanvas = sk_surface_get_canvas(csurface); |
| 600 | 641 |
| 601 sk_paint_t* cpaint = sk_paint_new(); | 642 sk_paint_t* cpaint = sk_paint_new(); |
| 602 sk_paint_set_antialias(cpaint, true); | 643 sk_paint_set_antialias(cpaint, true); |
| 603 sk_paint_set_color(cpaint, 0xFFFF0000); | 644 sk_paint_set_color(cpaint, 0xFFFF0000); |
| 604 | 645 |
| 605 sk_rect_t cr = { 5, 5, 95, 95 }; | 646 sk_rect_t cr = { 5, 5, 95, 95 }; |
| 606 sk_canvas_draw_oval(ccanvas, &cr, cpaint); | 647 sk_canvas_draw_oval(ccanvas, &cr, cpaint); |
| 607 | 648 |
| 608 cr.left += 25; | 649 cr.left += 25; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 623 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface); | 664 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface); |
| 624 | 665 |
| 625 // HERE WE CROSS THE C..C++ boundary | 666 // HERE WE CROSS THE C..C++ boundary |
| 626 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); | 667 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); |
| 627 | 668 |
| 628 sk_path_delete(cpath); | 669 sk_path_delete(cpath); |
| 629 sk_paint_delete(cpaint); | 670 sk_paint_delete(cpaint); |
| 630 sk_image_unref(cimage); | 671 sk_image_unref(cimage); |
| 631 sk_surface_unref(csurface); | 672 sk_surface_unref(csurface); |
| 632 } | 673 } |
| OLD | NEW |