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" |
11 #include "sk_path.h" | 11 #include "sk_path.h" |
12 #include "sk_surface.h" | 12 #include "sk_surface.h" |
13 | 13 |
14 #include "SkCanvas.h" | 14 #include "SkCanvas.h" |
15 #include "SkImage.h" | 15 #include "SkImage.h" |
| 16 #include "SkMaskFilter.h" |
16 #include "SkMatrix.h" | 17 #include "SkMatrix.h" |
17 #include "SkPaint.h" | 18 #include "SkPaint.h" |
18 #include "SkPath.h" | 19 #include "SkPath.h" |
19 #include "SkPictureRecorder.h" | 20 #include "SkPictureRecorder.h" |
20 #include "SkSurface.h" | 21 #include "SkSurface.h" |
21 | 22 |
22 const struct { | 23 const struct { |
23 sk_colortype_t fC; | 24 sk_colortype_t fC; |
24 SkColorType fSK; | 25 SkColorType fSK; |
25 } gColorTypeMap[] = { | 26 } gColorTypeMap[] = { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 156 } |
156 | 157 |
157 static sk_canvas_t* ToCanvas(SkCanvas* canvas) { | 158 static sk_canvas_t* ToCanvas(SkCanvas* canvas) { |
158 return reinterpret_cast<sk_canvas_t*>(canvas); | 159 return reinterpret_cast<sk_canvas_t*>(canvas); |
159 } | 160 } |
160 | 161 |
161 static SkCanvas* AsCanvas(sk_canvas_t* ccanvas) { | 162 static SkCanvas* AsCanvas(sk_canvas_t* ccanvas) { |
162 return reinterpret_cast<SkCanvas*>(ccanvas); | 163 return reinterpret_cast<SkCanvas*>(ccanvas); |
163 } | 164 } |
164 | 165 |
| 166 static SkMaskFilter* AsMaskFilter(sk_maskfilter_t* cfilter) { |
| 167 return reinterpret_cast<SkMaskFilter*>(cfilter); |
| 168 } |
| 169 |
| 170 static sk_maskfilter_t* ToMaskFilter(SkMaskFilter* filter) { |
| 171 return reinterpret_cast<sk_maskfilter_t*>(filter); |
| 172 } |
| 173 |
165 static SkShader* AsShader(sk_shader_t* cshader) { | 174 static SkShader* AsShader(sk_shader_t* cshader) { |
166 return reinterpret_cast<SkShader*>(cshader); | 175 return reinterpret_cast<SkShader*>(cshader); |
167 } | 176 } |
168 | 177 |
169 static SkPictureRecorder* AsPictureRecorder(sk_picture_recorder_t* crec) { | 178 static SkPictureRecorder* AsPictureRecorder(sk_picture_recorder_t* crec) { |
170 return reinterpret_cast<SkPictureRecorder*>(crec); | 179 return reinterpret_cast<SkPictureRecorder*>(crec); |
171 } | 180 } |
172 | 181 |
173 static sk_picture_recorder_t* ToPictureRecorder(SkPictureRecorder* rec) { | 182 static sk_picture_recorder_t* ToPictureRecorder(SkPictureRecorder* rec) { |
174 return reinterpret_cast<sk_picture_recorder_t*>(rec); | 183 return reinterpret_cast<sk_picture_recorder_t*>(rec); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 } | 259 } |
251 | 260 |
252 void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) { | 261 void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) { |
253 AsPaint(cpaint)->setColor(c); | 262 AsPaint(cpaint)->setColor(c); |
254 } | 263 } |
255 | 264 |
256 void sk_paint_set_shader(sk_paint_t* cpaint, sk_shader_t* cshader) { | 265 void sk_paint_set_shader(sk_paint_t* cpaint, sk_shader_t* cshader) { |
257 AsPaint(cpaint)->setShader(AsShader(cshader)); | 266 AsPaint(cpaint)->setShader(AsShader(cshader)); |
258 } | 267 } |
259 | 268 |
| 269 void sk_paint_set_maskfilter(sk_paint_t* cpaint, sk_maskfilter_t* cfilter) { |
| 270 AsPaint(cpaint)->setMaskFilter(AsMaskFilter(cfilter)); |
| 271 } |
| 272 |
260 ////////////////////////////////////////////////////////////////////////////////
/////////// | 273 ////////////////////////////////////////////////////////////////////////////////
/////////// |
261 | 274 |
262 sk_path_t* sk_path_new() { | 275 sk_path_t* sk_path_new() { |
263 return (sk_path_t*)SkNEW(SkPath); | 276 return (sk_path_t*)SkNEW(SkPath); |
264 } | 277 } |
265 | 278 |
266 void sk_path_delete(sk_path_t* cpath) { | 279 void sk_path_delete(sk_path_t* cpath) { |
267 SkDELETE(as_path(cpath)); | 280 SkDELETE(as_path(cpath)); |
268 } | 281 } |
269 | 282 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 } else { | 541 } else { |
529 matrix.setIdentity(); | 542 matrix.setIdentity(); |
530 } | 543 } |
531 SkShader* s = SkGradientShader::CreateLinear(reinterpret_cast<const SkPoint*
>(pts), | 544 SkShader* s = SkGradientShader::CreateLinear(reinterpret_cast<const SkPoint*
>(pts), |
532 reinterpret_cast<const SkColor*
>(colors), | 545 reinterpret_cast<const SkColor*
>(colors), |
533 colorPos, colorCount, mode, 0,
&matrix); | 546 colorPos, colorCount, mode, 0,
&matrix); |
534 return (sk_shader_t*)s; | 547 return (sk_shader_t*)s; |
535 } | 548 } |
536 | 549 |
537 ////////////////////////////////////////////////////////////////////////////////
/////////// | 550 ////////////////////////////////////////////////////////////////////////////////
/////////// |
| 551 |
| 552 #include "../../include/effects/SkBlurMaskFilter.h" |
| 553 #include "sk_maskfilter.h" |
| 554 |
| 555 const struct { |
| 556 sk_blurstyle_t fC; |
| 557 SkBlurStyle fSk; |
| 558 } gBlurStylePairs[] = { |
| 559 { NORMAL_SK_BLUR_STYLE, kNormal_SkBlurStyle }, |
| 560 { SOLID_SK_BLUR_STYLE, kSolid_SkBlurStyle }, |
| 561 { OUTER_SK_BLUR_STYLE, kOuter_SkBlurStyle }, |
| 562 { INNER_SK_BLUR_STYLE, kInner_SkBlurStyle }, |
| 563 }; |
| 564 |
| 565 static bool find_blurstyle(sk_blurstyle_t csrc, SkBlurStyle* dst) { |
| 566 for (size_t i = 0; i < SK_ARRAY_COUNT(gBlurStylePairs); ++i) { |
| 567 if (gBlurStylePairs[i].fC == csrc) { |
| 568 if (dst) { |
| 569 *dst = gBlurStylePairs[i].fSk; |
| 570 } |
| 571 return true; |
| 572 } |
| 573 } |
| 574 return false; |
| 575 } |
| 576 |
| 577 void sk_maskfilter_ref(sk_maskfilter_t* cfilter) { |
| 578 SkSafeRef(AsMaskFilter(cfilter)); |
| 579 } |
| 580 |
| 581 void sk_maskfilter_unref(sk_maskfilter_t* cfilter) { |
| 582 SkSafeUnref(AsMaskFilter(cfilter)); |
| 583 } |
| 584 |
| 585 sk_maskfilter_t* sk_maskfilter_new_blur(sk_blurstyle_t cstyle, float sigma) { |
| 586 SkBlurStyle style; |
| 587 if (!find_blurstyle(cstyle, &style)) { |
| 588 return NULL; |
| 589 } |
| 590 return ToMaskFilter(SkBlurMaskFilter::Create(style, sigma)); |
| 591 } |
| 592 |
| 593 ////////////////////////////////////////////////////////////////////////////////
/////////// |
538 ////////////////////////////////////////////////////////////////////////////////
/////////// | 594 ////////////////////////////////////////////////////////////////////////////////
/////////// |
539 | 595 |
540 void sk_test_capi(SkCanvas* canvas) { | 596 void sk_test_capi(SkCanvas* canvas) { |
541 sk_imageinfo_t cinfo; | 597 sk_imageinfo_t cinfo; |
542 cinfo.width = 100; | 598 cinfo.width = 100; |
543 cinfo.height = 100; | 599 cinfo.height = 100; |
544 cinfo.colorType = (sk_colortype_t)kN32_SkColorType; | 600 cinfo.colorType = (sk_colortype_t)kN32_SkColorType; |
545 cinfo.alphaType = (sk_alphatype_t)kPremul_SkAlphaType; | 601 cinfo.alphaType = (sk_alphatype_t)kPremul_SkAlphaType; |
546 | 602 |
547 sk_surface_t* csurface = sk_surface_new_raster(&cinfo); | 603 sk_surface_t* csurface = sk_surface_new_raster(&cinfo); |
(...skipping 24 matching lines...) Expand all Loading... |
572 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface); | 628 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface); |
573 | 629 |
574 // HERE WE CROSS THE C..C++ boundary | 630 // HERE WE CROSS THE C..C++ boundary |
575 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); | 631 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); |
576 | 632 |
577 sk_path_delete(cpath); | 633 sk_path_delete(cpath); |
578 sk_paint_delete(cpaint); | 634 sk_paint_delete(cpaint); |
579 sk_image_unref(cimage); | 635 sk_image_unref(cimage); |
580 sk_surface_unref(csurface); | 636 sk_surface_unref(csurface); |
581 } | 637 } |
OLD | NEW |