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

Side by Side Diff: src/c/sk_surface.cpp

Issue 728323002: separate c headers (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month 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 | « include/c/sk_types.h ('k') | tests/CTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
9 #include "sk_image.h"
10 #include "sk_paint.h"
11 #include "sk_path.h"
8 #include "sk_surface.h" 12 #include "sk_surface.h"
9 13
10 #include "SkCanvas.h" 14 #include "SkCanvas.h"
11 #include "SkImage.h" 15 #include "SkImage.h"
12 #include "SkMatrix.h" 16 #include "SkMatrix.h"
13 #include "SkPaint.h" 17 #include "SkPaint.h"
14 #include "SkPath.h" 18 #include "SkPath.h"
15 #include "SkSurface.h" 19 #include "SkSurface.h"
16 20
17 const struct { 21 const struct {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 if (!from_c_alphatype(cinfo.alphaType, &at)) { 84 if (!from_c_alphatype(cinfo.alphaType, &at)) {
81 // optionally report error to client? 85 // optionally report error to client?
82 return false; 86 return false;
83 } 87 }
84 if (info) { 88 if (info) {
85 *info = SkImageInfo::Make(cinfo.width, cinfo.height, ct, at); 89 *info = SkImageInfo::Make(cinfo.width, cinfo.height, ct, at);
86 } 90 }
87 return true; 91 return true;
88 } 92 }
89 93
94 const struct {
95 sk_path_direction_t fC;
96 SkPath::Direction fSk;
97 } gPathDirMap[] = {
98 { CW_SK_PATH_DIRECTION, SkPath::kCW_Direction },
99 { CCW_SK_PATH_DIRECTION, SkPath::kCCW_Direction },
100 };
101
102 static bool from_c_path_direction(sk_path_direction_t cdir, SkPath::Direction* d ir) {
103 for (size_t i = 0; i < SK_ARRAY_COUNT(gPathDirMap); ++i) {
104 if (gPathDirMap[i].fC == cdir) {
105 if (dir) {
106 *dir = gPathDirMap[i].fSk;
107 }
108 return true;
109 }
110 }
111 return false;
112 }
113
90 static const SkRect& AsRect(const sk_rect_t& crect) { 114 static const SkRect& AsRect(const sk_rect_t& crect) {
91 return reinterpret_cast<const SkRect&>(crect); 115 return reinterpret_cast<const SkRect&>(crect);
92 } 116 }
93 117
118 static SkRect* as_rect(sk_rect_t* crect) {
119 return reinterpret_cast<SkRect*>(crect);
120 }
121
94 static const SkPath& AsPath(const sk_path_t& cpath) { 122 static const SkPath& AsPath(const sk_path_t& cpath) {
95 return reinterpret_cast<const SkPath&>(cpath); 123 return reinterpret_cast<const SkPath&>(cpath);
96 } 124 }
97 125
98 static SkPath* as_path(sk_path_t* cpath) { 126 static SkPath* as_path(sk_path_t* cpath) {
99 return reinterpret_cast<SkPath*>(cpath); 127 return reinterpret_cast<SkPath*>(cpath);
100 } 128 }
101 129
102 static const SkImage* AsImage(const sk_image_t* cimage) { 130 static const SkImage* AsImage(const sk_image_t* cimage) {
103 return reinterpret_cast<const SkImage*>(cimage); 131 return reinterpret_cast<const SkImage*>(cimage);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } 229 }
202 230
203 void sk_path_line_to(sk_path_t* cpath, float x, float y) { 231 void sk_path_line_to(sk_path_t* cpath, float x, float y) {
204 as_path(cpath)->lineTo(x, y); 232 as_path(cpath)->lineTo(x, y);
205 } 233 }
206 234
207 void sk_path_quad_to(sk_path_t* cpath, float x0, float y0, float x1, float y1) { 235 void sk_path_quad_to(sk_path_t* cpath, float x0, float y0, float x1, float y1) {
208 as_path(cpath)->quadTo(x0, y0, x1, y1); 236 as_path(cpath)->quadTo(x0, y0, x1, y1);
209 } 237 }
210 238
239 void sk_path_conic_to(sk_path_t* cpath, float x0, float y0, float x1, float y1, float w) {
240 as_path(cpath)->conicTo(x0, y0, x1, y1, w);
241 }
242
243 void sk_path_cubic_to(sk_path_t* cpath, float x0, float y0, float x1, float y1, float x2, float y2) {
244 as_path(cpath)->cubicTo(x0, y0, x1, y1, x2, y2);
245 }
246
211 void sk_path_close(sk_path_t* cpath) { 247 void sk_path_close(sk_path_t* cpath) {
212 as_path(cpath)->close(); 248 as_path(cpath)->close();
213 } 249 }
214 250
251 void sk_path_add_rect(sk_path_t* cpath, const sk_rect_t* crect, sk_path_directio n_t cdir) {
252 SkPath::Direction dir;
253 if (!from_c_path_direction(cdir, &dir)) {
254 return;
255 }
256 as_path(cpath)->addRect(AsRect(*crect), dir);
257 }
258
259 void sk_path_add_oval(sk_path_t* cpath, const sk_rect_t* crect, sk_path_directio n_t cdir) {
260 SkPath::Direction dir;
261 if (!from_c_path_direction(cdir, &dir)) {
262 return;
263 }
264 as_path(cpath)->addOval(AsRect(*crect), dir);
265 }
266
267 bool sk_path_get_bounds(const sk_path_t* cpath, sk_rect_t* crect) {
268 const SkPath& path = AsPath(*cpath);
269 SkRect* rect = as_rect(crect);
270
271 if (path.isEmpty()) {
272 if (rect) {
273 rect->setEmpty();
274 }
275 return false;
276 }
277 *rect = path.getBounds();
278 return true;
279 }
280
215 //////////////////////////////////////////////////////////////////////////////// /////////// 281 //////////////////////////////////////////////////////////////////////////////// ///////////
216 282
217 void sk_canvas_save(sk_canvas_t* ccanvas) { 283 void sk_canvas_save(sk_canvas_t* ccanvas) {
218 AsCanvas(ccanvas)->save(); 284 AsCanvas(ccanvas)->save();
219 } 285 }
220 286
221 void sk_canvas_save_layer(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk _paint_t* cpaint) { 287 void sk_canvas_save_layer(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk _paint_t* cpaint) {
222 AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint)); 288 AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint));
223 } 289 }
224 290
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface); 393 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface);
328 394
329 // HERE WE CROSS THE C..C++ boundary 395 // HERE WE CROSS THE C..C++ boundary
330 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); 396 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL);
331 397
332 sk_path_delete(cpath); 398 sk_path_delete(cpath);
333 sk_paint_delete(cpaint); 399 sk_paint_delete(cpaint);
334 sk_image_unref(cimage); 400 sk_image_unref(cimage);
335 sk_surface_delete(csurface); 401 sk_surface_delete(csurface);
336 } 402 }
OLDNEW
« no previous file with comments | « include/c/sk_types.h ('k') | tests/CTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698