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_image.h" | 10 #include "sk_image.h" |
10 #include "sk_paint.h" | 11 #include "sk_paint.h" |
11 #include "sk_path.h" | 12 #include "sk_path.h" |
12 #include "sk_surface.h" | 13 #include "sk_surface.h" |
13 | 14 |
14 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
| 16 #include "SkData.h" |
15 #include "SkImage.h" | 17 #include "SkImage.h" |
16 #include "SkMaskFilter.h" | 18 #include "SkMaskFilter.h" |
17 #include "SkMatrix.h" | 19 #include "SkMatrix.h" |
18 #include "SkPaint.h" | 20 #include "SkPaint.h" |
19 #include "SkPath.h" | 21 #include "SkPath.h" |
20 #include "SkPictureRecorder.h" | 22 #include "SkPictureRecorder.h" |
21 #include "SkSurface.h" | 23 #include "SkSurface.h" |
22 | 24 |
23 const struct { | 25 const struct { |
24 sk_colortype_t fC; | 26 sk_colortype_t fC; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 if (gPathDirMap[i].fC == cdir) { | 114 if (gPathDirMap[i].fC == cdir) { |
113 if (dir) { | 115 if (dir) { |
114 *dir = gPathDirMap[i].fSk; | 116 *dir = gPathDirMap[i].fSk; |
115 } | 117 } |
116 return true; | 118 return true; |
117 } | 119 } |
118 } | 120 } |
119 return false; | 121 return false; |
120 } | 122 } |
121 | 123 |
| 124 static SkData* AsData(const sk_data_t* cdata) { |
| 125 return reinterpret_cast<SkData*>(const_cast<sk_data_t*>(cdata)); |
| 126 } |
| 127 |
| 128 static sk_data_t* ToData(SkData* data) { |
| 129 return reinterpret_cast<sk_data_t*>(data); |
| 130 } |
| 131 |
122 static sk_rect_t ToRect(const SkRect& rect) { | 132 static sk_rect_t ToRect(const SkRect& rect) { |
123 return reinterpret_cast<const sk_rect_t&>(rect); | 133 return reinterpret_cast<const sk_rect_t&>(rect); |
124 } | 134 } |
125 | 135 |
126 static const SkRect& AsRect(const sk_rect_t& crect) { | 136 static const SkRect& AsRect(const sk_rect_t& crect) { |
127 return reinterpret_cast<const SkRect&>(crect); | 137 return reinterpret_cast<const SkRect&>(crect); |
128 } | 138 } |
129 | 139 |
130 static const SkRect* AsRect(const sk_rect_t* crect) { | 140 static const SkRect* AsRect(const sk_rect_t* crect) { |
131 return reinterpret_cast<const SkRect*>(crect); | 141 return reinterpret_cast<const SkRect*>(crect); |
132 } | 142 } |
133 | 143 |
134 static const SkPath& AsPath(const sk_path_t& cpath) { | 144 static const SkPath& AsPath(const sk_path_t& cpath) { |
135 return reinterpret_cast<const SkPath&>(cpath); | 145 return reinterpret_cast<const SkPath&>(cpath); |
136 } | 146 } |
137 | 147 |
138 static SkPath* as_path(sk_path_t* cpath) { | 148 static SkPath* as_path(sk_path_t* cpath) { |
139 return reinterpret_cast<SkPath*>(cpath); | 149 return reinterpret_cast<SkPath*>(cpath); |
140 } | 150 } |
141 | 151 |
142 static const SkImage* AsImage(const sk_image_t* cimage) { | 152 static const SkImage* AsImage(const sk_image_t* cimage) { |
143 return reinterpret_cast<const SkImage*>(cimage); | 153 return reinterpret_cast<const SkImage*>(cimage); |
144 } | 154 } |
145 | 155 |
| 156 static sk_image_t* ToImage(SkImage* cimage) { |
| 157 return reinterpret_cast<sk_image_t*>(cimage); |
| 158 } |
| 159 |
146 static const SkPaint& AsPaint(const sk_paint_t& cpaint) { | 160 static const SkPaint& AsPaint(const sk_paint_t& cpaint) { |
147 return reinterpret_cast<const SkPaint&>(cpaint); | 161 return reinterpret_cast<const SkPaint&>(cpaint); |
148 } | 162 } |
149 | 163 |
150 static const SkPaint* AsPaint(const sk_paint_t* cpaint) { | 164 static const SkPaint* AsPaint(const sk_paint_t* cpaint) { |
151 return reinterpret_cast<const SkPaint*>(cpaint); | 165 return reinterpret_cast<const SkPaint*>(cpaint); |
152 } | 166 } |
153 | 167 |
154 static SkPaint* AsPaint(sk_paint_t* cpaint) { | 168 static SkPaint* AsPaint(sk_paint_t* cpaint) { |
155 return reinterpret_cast<SkPaint*>(cpaint); | 169 return reinterpret_cast<SkPaint*>(cpaint); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 223 |
210 sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t* cinfo, const void* pi
xels, | 224 sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t* cinfo, const void* pi
xels, |
211 size_t rowBytes) { | 225 size_t rowBytes) { |
212 SkImageInfo info; | 226 SkImageInfo info; |
213 if (!from_c_info(*cinfo, &info)) { | 227 if (!from_c_info(*cinfo, &info)) { |
214 return NULL; | 228 return NULL; |
215 } | 229 } |
216 return (sk_image_t*)SkImage::NewRasterCopy(info, pixels, rowBytes); | 230 return (sk_image_t*)SkImage::NewRasterCopy(info, pixels, rowBytes); |
217 } | 231 } |
218 | 232 |
| 233 #include "SkDecodingImageGenerator.h" |
| 234 |
| 235 sk_image_t* sk_image_new_from_data(const sk_data_t* cdata) { |
| 236 SkImageGenerator* gen = SkDecodingImageGenerator::Create(AsData(cdata), |
| 237 SkDecodingImageGene
rator::Options()); |
| 238 if (NULL == gen) { |
| 239 return NULL; |
| 240 } |
| 241 return ToImage(SkImage::NewFromGenerator(gen)); |
| 242 } |
| 243 |
| 244 sk_data_t* sk_image_encode(const sk_image_t* cimage) { |
| 245 return ToData(AsImage(cimage)->encode()); |
| 246 } |
| 247 |
219 void sk_image_ref(const sk_image_t* cimage) { | 248 void sk_image_ref(const sk_image_t* cimage) { |
220 AsImage(cimage)->ref(); | 249 AsImage(cimage)->ref(); |
221 } | 250 } |
222 | 251 |
223 void sk_image_unref(const sk_image_t* cimage) { | 252 void sk_image_unref(const sk_image_t* cimage) { |
224 AsImage(cimage)->unref(); | 253 AsImage(cimage)->unref(); |
225 } | 254 } |
226 | 255 |
227 int sk_image_get_width(const sk_image_t* cimage) { | 256 int sk_image_get_width(const sk_image_t* cimage) { |
228 return AsImage(cimage)->width(); | 257 return AsImage(cimage)->width(); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 | 613 |
585 sk_maskfilter_t* sk_maskfilter_new_blur(sk_blurstyle_t cstyle, float sigma) { | 614 sk_maskfilter_t* sk_maskfilter_new_blur(sk_blurstyle_t cstyle, float sigma) { |
586 SkBlurStyle style; | 615 SkBlurStyle style; |
587 if (!find_blurstyle(cstyle, &style)) { | 616 if (!find_blurstyle(cstyle, &style)) { |
588 return NULL; | 617 return NULL; |
589 } | 618 } |
590 return ToMaskFilter(SkBlurMaskFilter::Create(style, sigma)); | 619 return ToMaskFilter(SkBlurMaskFilter::Create(style, sigma)); |
591 } | 620 } |
592 | 621 |
593 ////////////////////////////////////////////////////////////////////////////////
/////////// | 622 ////////////////////////////////////////////////////////////////////////////////
/////////// |
| 623 |
| 624 sk_data_t* sk_data_new_with_copy(const void* src, size_t length) { |
| 625 return ToData(SkData::NewWithCopy(src, length)); |
| 626 } |
| 627 |
| 628 sk_data_t* sk_data_new_from_malloc(const void* memory, size_t length) { |
| 629 return ToData(SkData::NewFromMalloc(memory, length)); |
| 630 } |
| 631 |
| 632 sk_data_t* sk_data_new_subset(const sk_data_t* csrc, size_t offset, size_t lengt
h) { |
| 633 return ToData(SkData::NewSubset(AsData(csrc), offset, length)); |
| 634 } |
| 635 |
| 636 void sk_data_ref(const sk_data_t* cdata) { |
| 637 SkSafeRef(AsData(cdata)); |
| 638 } |
| 639 |
| 640 void sk_data_unref(const sk_data_t* cdata) { |
| 641 SkSafeUnref(AsData(cdata)); |
| 642 } |
| 643 |
| 644 size_t sk_data_get_size(const sk_data_t* cdata) { |
| 645 return AsData(cdata)->size(); |
| 646 } |
| 647 |
| 648 const void* sk_data_get_data(const sk_data_t* cdata) { |
| 649 return AsData(cdata)->data(); |
| 650 } |
| 651 |
| 652 ////////////////////////////////////////////////////////////////////////////////
/////////// |
594 ////////////////////////////////////////////////////////////////////////////////
/////////// | 653 ////////////////////////////////////////////////////////////////////////////////
/////////// |
595 | 654 |
596 void sk_test_capi(SkCanvas* canvas) { | 655 void sk_test_capi(SkCanvas* canvas) { |
597 sk_imageinfo_t cinfo; | 656 sk_imageinfo_t cinfo; |
598 cinfo.width = 100; | 657 cinfo.width = 100; |
599 cinfo.height = 100; | 658 cinfo.height = 100; |
600 cinfo.colorType = (sk_colortype_t)kN32_SkColorType; | 659 cinfo.colorType = (sk_colortype_t)kN32_SkColorType; |
601 cinfo.alphaType = (sk_alphatype_t)kPremul_SkAlphaType; | 660 cinfo.alphaType = (sk_alphatype_t)kPremul_SkAlphaType; |
602 | 661 |
603 sk_surface_t* csurface = sk_surface_new_raster(&cinfo); | 662 sk_surface_t* csurface = sk_surface_new_raster(&cinfo); |
(...skipping 24 matching lines...) Expand all Loading... |
628 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface); | 687 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface); |
629 | 688 |
630 // HERE WE CROSS THE C..C++ boundary | 689 // HERE WE CROSS THE C..C++ boundary |
631 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); | 690 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); |
632 | 691 |
633 sk_path_delete(cpath); | 692 sk_path_delete(cpath); |
634 sk_paint_delete(cpaint); | 693 sk_paint_delete(cpaint); |
635 sk_image_unref(cimage); | 694 sk_image_unref(cimage); |
636 sk_surface_unref(csurface); | 695 sk_surface_unref(csurface); |
637 } | 696 } |
OLD | NEW |