Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: experimental/sk_surface.cpp

Issue 629903004: implement some so we can test it (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « experimental/sk_surface.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
1 #include "sk_surface.h" 8 #include "sk_surface.h"
2 9
3 #include "SkCanvas.h" 10 #include "SkCanvas.h"
4 #include "SkImage.h" 11 #include "SkImage.h"
5 #include "SkMatrix.h" 12 #include "SkMatrix.h"
6 #include "SkPaint.h" 13 #include "SkPaint.h"
7 #include "SkPath.h" 14 #include "SkPath.h"
8 #include "SkSurface.h" 15 #include "SkSurface.h"
9 16
10 void sk_matrix_set_identity(sk_matrix_t* cmatrix) { 17 static SkImageInfo make(const sk_imageinfo_t& cinfo) {
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, 18 return SkImageInfo::Make(cinfo.width, cinfo.height,
17 (SkColorType)cinfo.colorType, (SkAlphaType)cinfo.al phaType); 19 (SkColorType)cinfo.colorType, (SkAlphaType)cinfo.al phaType);
18 } 20 }
19 21
20 static const SkRect& AsRect(const sk_rect_t& crect) { return static_cast<const S kRect&>(crect); } 22 static const SkRect& AsRect(const sk_rect_t& crect) {
23 return reinterpret_cast<const SkRect&>(crect);
24 }
25
26 static const SkPath& AsPath(const sk_path_t& cpath) {
27 return reinterpret_cast<const SkPath&>(cpath);
28 }
29
30 static const SkImage* AsImage(const sk_image_t* cimage) {
31 return reinterpret_cast<const SkImage*>(cimage);
32 }
21 33
22 static const SkPaint& AsPaint(const sk_paint_t& cpaint) { 34 static const SkPaint& AsPaint(const sk_paint_t& cpaint) {
23 return static_cast<const SkPaint&>(cpaint); 35 return reinterpret_cast<const SkPaint&>(cpaint);
24 } 36 }
25 37
26 static const SkPaint* AsPaint(const sk_paint_t* cpaint) { 38 static const SkPaint* AsPaint(const sk_paint_t* cpaint) {
27 return static_cast<const SkPaint*>(cpaint); 39 return reinterpret_cast<const SkPaint*>(cpaint);
28 } 40 }
29 41
30 static SkCanvas* AsCanvas(sk_canvas_t* ccanvas) { return static_cast<SkCanvas*>( ccanvas); } 42 static SkPaint* AsPaint(sk_paint_t* cpaint) {
43 return reinterpret_cast<SkPaint*>(cpaint);
44 }
45
46 static SkCanvas* AsCanvas(sk_canvas_t* ccanvas) {
47 return reinterpret_cast<SkCanvas*>(ccanvas);
48 }
31 49
32 //////////////////////////////////////////////////////////////////////////////// /////////// 50 //////////////////////////////////////////////////////////////////////////////// ///////////
33 51
52 sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t* cinfo, const void* pi xels,
53 size_t rowBytes) {
54 return (sk_image_t*)SkImage::NewRasterCopy(make(*cinfo), pixels, rowBytes);
55 }
56
57 void sk_image_ref(const sk_image_t* cimage) {
58 AsImage(cimage)->ref();
59 }
60
61 void sk_image_unref(const sk_image_t* cimage) {
62 AsImage(cimage)->unref();
63 }
64
65 int sk_image_get_width(const sk_image_t* cimage) {
66 return AsImage(cimage)->width();
67 }
68
69 int sk_image_get_height(const sk_image_t* cimage) {
70 return AsImage(cimage)->height();
71 }
72
73 uint32_t sk_image_get_unique_id(const sk_image_t* cimage) {
74 return AsImage(cimage)->uniqueID();
75 }
76
77 //////////////////////////////////////////////////////////////////////////////// ///////////
78
79 sk_paint_t* sk_paint_new() {
80 return (sk_paint_t*)SkNEW(SkPaint);
81 }
82
83 void sk_paint_delete(sk_paint_t* cpaint) {
84 SkDELETE(AsPaint(cpaint));
85 }
86
87 bool sk_paint_is_antialias(const sk_paint_t* cpaint) {
88 return AsPaint(*cpaint).isAntiAlias();
89 }
90
91 void sk_paint_set_antialias(sk_paint_t* cpaint, bool aa) {
92 AsPaint(cpaint)->setAntiAlias(aa);
93 }
94
95 sk_color_t sk_paint_get_color(const sk_paint_t* cpaint) {
96 return AsPaint(*cpaint).getColor();
97 }
98
99 void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) {
100 AsPaint(cpaint)->setColor(c);
101 }
102
103 //////////////////////////////////////////////////////////////////////////////// ///////////
104
34 void sk_canvas_save(sk_canvas_t* ccanvas) { 105 void sk_canvas_save(sk_canvas_t* ccanvas) {
35 AsCanvas(ccanvas)->save(); 106 AsCanvas(ccanvas)->save();
36 } 107 }
37 108
38 void sk_canvas_save_layer(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk _paint_t* cpaint) { 109 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)); 110 AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint));
40 } 111 }
41 112
42 void sk_canvas_restore(sk_canvas_t* ccanvas) { 113 void sk_canvas_restore(sk_canvas_t* ccanvas) {
43 AsCanvas(ccanvas)->restore(); 114 AsCanvas(ccanvas)->restore();
44 } 115 }
45 116
46 void sk_canvas_translate(sk_canvas_t* ccanvas, float dx, float dy) { 117 void sk_canvas_translate(sk_canvas_t* ccanvas, float dx, float dy) {
47 AsCanvas(ccanvas)->translate(dx, dy); 118 AsCanvas(ccanvas)->translate(dx, dy);
48 } 119 }
49 120
50 void sk_canvas_scale(sk_canvas_t* ccanvas, float sx, float sy) { 121 void sk_canvas_scale(sk_canvas_t* ccanvas, float sx, float sy) {
51 AsCanvas(ccanvas)->scale(dx, dy); 122 AsCanvas(ccanvas)->scale(sx, sy);
52 }
53
54 void sk_canvas_concat(sk_canvas_t* ccanvas, const sk_matrix_t* cmatrix) {
55 AsCanvas(ccanvas)->concat(AsMatrix(*cmatrix));
56 } 123 }
57 124
58 void sk_canvas_draw_paint(sk_canvas_t* ccanvas, const sk_paint_t* cpaint) { 125 void sk_canvas_draw_paint(sk_canvas_t* ccanvas, const sk_paint_t* cpaint) {
59 AsCanvas(ccanvas)->drawPaint(AsPaint(*cpaint)); 126 AsCanvas(ccanvas)->drawPaint(AsPaint(*cpaint));
60 } 127 }
61 128
62 void sk_canvas_draw_rect(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_ paint_t* cpaint) { 129 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)); 130 AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint));
64 } 131 }
65 132
66 void sk_canvas_draw_oval(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_ paint_t* cpaint) { 133 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)); 134 AsCanvas(ccanvas)->drawOval(AsRect(*crect), AsPaint(*cpaint));
68 } 135 }
69 136
70 void sk_canvas_draw_path(sk_canvas_t* ccanvas, const sk_path_t* cpath, const sk_ paint_t* cpaint) { 137 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)); 138 AsCanvas(ccanvas)->drawPath(AsPath(*cpath), AsPaint(*cpaint));
72 } 139 }
73 140
74 void sk_canvas_draw_image(sk_canvas_t* ccanvas, const sk_image_t* cimage, float x, float y, 141 void sk_canvas_draw_image(sk_canvas_t* ccanvas, const sk_image_t* cimage, float x, float y,
75 const sk_paint_t* cpaint) { 142 const sk_paint_t* cpaint) {
76 AsCanvas(ccanvas)->drawImage(AsImage(cimage), x, y, AsPaint(cpaint)); 143 AsCanvas(ccanvas)->drawImage(AsImage(cimage), x, y, AsPaint(cpaint));
77 } 144 }
78 145
79 //////////////////////////////////////////////////////////////////////////////// /////////// 146 //////////////////////////////////////////////////////////////////////////////// ///////////
80 147
81 sk_image_t* sk_image_new_raster_copy(const sk_image_info_t* cinfo, const void* p ixels, 148 sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t* cinfo) {
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)); 149 return (sk_surface_t*)SkSurface::NewRaster(make(*cinfo));
102 } 150 }
103 151
104 sk_surface_t* sk_surface_new_raster_direct(const sk_image_info_t* cinfo, void* p ixels, 152 sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pi xels,
105 size_t rowBytes) { 153 size_t rowBytes) {
106 return (sk_surface_t*)SkSurface::NewRasterDirect(make(*cinfo), pixels, rowBy tes); 154 return (sk_surface_t*)SkSurface::NewRasterDirect(make(*cinfo), pixels, rowBy tes);
107 } 155 }
108 156
109 void sk_surface_delete(sk_surface_t* csurf) { 157 void sk_surface_delete(sk_surface_t* csurf) {
110 SkSurface* surf = (SkSurface*)csurf; 158 SkSurface* surf = (SkSurface*)csurf;
111 SkSafeUnref(surf); 159 SkSafeUnref(surf);
112 } 160 }
113 161
114 sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) { 162 sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) {
115 SkSurface* surf = (SkSurface*)csurf; 163 SkSurface* surf = (SkSurface*)csurf;
116 return surf->getCanvas(); 164 return (sk_canvas_t*)surf->getCanvas();
117 } 165 }
118 166
119 sk_image_t* sk_surface_new_image_snapshot(sk_surface_t* csurf) { 167 sk_image_t* sk_surface_new_image_snapshot(sk_surface_t* csurf) {
120 SkSurface* surf = (SkSurface*)csurf; 168 SkSurface* surf = (SkSurface*)csurf;
121 return surf->newImageSnapshot(); 169 return (sk_image_t*)surf->newImageSnapshot();
122 } 170 }
123 171
124 172
173 ///////////////////
174
175 void sk_test_capi(SkCanvas* canvas) {
176 sk_imageinfo_t cinfo;
177 cinfo.width = 100;
178 cinfo.height = 100;
179 cinfo.colorType = (sk_colortype_t)kN32_SkColorType;
180 cinfo.alphaType = (sk_alphatype_t)kPremul_SkAlphaType;
181
182 sk_surface_t* csurface = sk_surface_new_raster(&cinfo);
183 sk_canvas_t* ccanvas = sk_surface_get_canvas(csurface);
184
185 sk_paint_t* cpaint = sk_paint_new();
186 sk_paint_set_antialias(cpaint, true);
187 sk_paint_set_color(cpaint, 0xFFFF0000);
188
189 sk_rect_t cr = { 5, 5, 95, 95 };
190 sk_canvas_draw_oval(ccanvas, &cr, cpaint);
191
192 cr.left += 25;
193 cr.top += 25;
194 cr.right -= 25;
195 cr.bottom -= 25;
196 sk_paint_set_color(cpaint, 0xFF00FF00);
197 sk_canvas_draw_rect(ccanvas, &cr, cpaint);
198
199 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface);
200
201 // HERE WE CROSS THE C..C++ boundary
202 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL);
203
204 sk_paint_delete(cpaint);
205 sk_image_unref(cimage);
206 sk_surface_delete(csurface);
207 }
OLDNEW
« no previous file with comments | « experimental/sk_surface.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698