OLD | NEW |
---|---|
(Empty) | |
1 #include "sk_surface.h" | |
2 | |
3 #include "SkCanvas.h" | |
4 #include "SkImage.h" | |
5 #include "SkMatrix.h" | |
6 #include "SkPaint.h" | |
7 #include "SkPath.h" | |
8 #include "SkSurface.h" | |
9 | |
10 void sk_matrix_set_identity(sk_matrix_t* cmatrix) { | |
11 sk_bzero(cmatrix->mat, sizeof(9 * sizeof(float))); | |
12 cmatrix->mat[0] = cmatrix->mat[4] = cmatrix->mat[8] = 1; | |
13 } | |
14 | |
15 static SkImageInfo make(const sk_image_info& cinfo) { | |
16 return SkImageInfo::Make(cinfo.width, cinfo.height, | |
17 (SkColorType)cinfo.colorType, (SkAlphaType)cinfo.al phaType); | |
18 } | |
19 | |
robertphillips
2014/10/07 16:26:43
Shouldn't these be as_rect, etc. ?
| |
20 static const SkRect& AsRect(const sk_rect_t& crect) { return static_cast<const S kRect&>(crect); } | |
21 | |
22 static const SkPaint& AsPaint(const sk_paint_t& cpaint) { | |
23 return static_cast<const SkPaint&>(cpaint); | |
24 } | |
25 | |
26 static const SkPaint* AsPaint(const sk_paint_t* cpaint) { | |
27 return static_cast<const SkPaint*>(cpaint); | |
28 } | |
29 | |
30 static SkCanvas* AsCanvas(sk_canvas_t* ccanvas) { return static_cast<SkCanvas*>( ccanvas); } | |
31 | |
32 //////////////////////////////////////////////////////////////////////////////// /////////// | |
33 | |
34 void sk_canvas_save(sk_canvas_t* ccanvas) { | |
35 AsCanvas(ccanvas)->save(); | |
36 } | |
37 | |
38 void sk_canvas_save_layer(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk _paint_t* cpaint) { | |
39 AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint)); | |
40 } | |
41 | |
42 void sk_canvas_restore(sk_canvas_t* ccanvas) { | |
43 AsCanvas(ccanvas)->restore(); | |
44 } | |
45 | |
46 void sk_canvas_translate(sk_canvas_t* ccanvas, float dx, float dy) { | |
47 AsCanvas(ccanvas)->translate(dx, dy); | |
48 } | |
49 | |
50 void sk_canvas_scale(sk_canvas_t* ccanvas, float sx, float sy) { | |
51 AsCanvas(ccanvas)->scale(dx, dy); | |
52 } | |
53 | |
54 void sk_canvas_concat(sk_canvas_t* ccanvas, const sk_matrix_t* cmatrix) { | |
55 AsCanvas(ccanvas)->concat(AsMatrix(*cmatrix)); | |
56 } | |
57 | |
58 void sk_canvas_draw_paint(sk_canvas_t* ccanvas, const sk_paint_t* cpaint) { | |
59 AsCanvas(ccanvas)->drawPaint(AsPaint(*cpaint)); | |
60 } | |
61 | |
62 void sk_canvas_draw_rect(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_ paint_t* cpaint) { | |
63 AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint)); | |
64 } | |
65 | |
66 void sk_canvas_draw_oval(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_ paint_t* cpaint) { | |
67 AsCanvas(ccanvas)->drawOval(AsRect(*crect), AsPaint(*cpaint)); | |
68 } | |
69 | |
70 void sk_canvas_draw_path(sk_canvas_t* ccanvas, const sk_path_t* cpath, const sk_ paint_t* cpaint) { | |
71 AsCanvas(ccanvas)->drawPath(AsPath(*cpath), AsPaint(*cpaint)); | |
72 } | |
73 | |
74 void sk_canvas_draw_image(sk_canvas_t* ccanvas, const sk_image_t* cimage, float x, float y, | |
75 const sk_paint_t* cpaint) { | |
76 AsCanvas(ccanvas)->drawImage(AsImage(cimage), x, y, AsPaint(cpaint)); | |
77 } | |
78 | |
79 //////////////////////////////////////////////////////////////////////////////// /////////// | |
80 | |
81 sk_image_t* sk_image_new_raster_copy(const sk_image_info_t* cinfo, const void* p ixels, | |
82 size_t rowBytes) { | |
83 return (sk_image_t*)SkImage::NewRasterCopy(make(*cinfo), pixels, rowBytes); | |
84 } | |
85 | |
86 int sk_image_get_width(const sk_image_t* cimage) { | |
87 return ((const SkImage*)cimage)->width(); | |
88 } | |
89 | |
90 int sk_image_get_height(const sk_image_t* cimage) { | |
91 return ((const SkImage*)cimage)->height(); | |
92 } | |
93 | |
94 uint32_t sk_image_get_unique_id(const sk_image_t* cimage) { | |
95 return ((const SkImage*)cimage)->uniqueID(); | |
96 } | |
97 | |
98 //////////////////////////////////////////////////////////////////////////////// /////////// | |
99 | |
100 sk_surface_t* sk_surface_new_raster(const sk_image_info_t* cinfo) { | |
101 return (sk_surface_t*)SkSurface::NewRaster(make(*cinfo)); | |
102 } | |
103 | |
104 sk_surface_t* sk_surface_new_raster_direct(const sk_image_info_t* cinfo, void* p ixels, | |
105 size_t rowBytes) { | |
106 return (sk_surface_t*)SkSurface::NewRasterDirect(make(*cinfo), pixels, rowBy tes); | |
107 } | |
108 | |
109 void sk_surface_delete(sk_surface_t* csurf) { | |
110 SkSurface* surf = (SkSurface*)csurf; | |
111 SkSafeUnref(surf); | |
112 } | |
113 | |
114 sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) { | |
115 SkSurface* surf = (SkSurface*)csurf; | |
116 return surf->getCanvas(); | |
117 } | |
118 | |
119 sk_image_t* sk_surface_new_image_snapshot(sk_surface_t* csurf) { | |
120 SkSurface* surf = (SkSurface*)csurf; | |
121 return surf->newImageSnapshot(); | |
122 } | |
123 | |
124 | |
OLD | NEW |