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

Side by Side Diff: experimental/sk_surface.cpp

Issue 633183002: Implement C path functions (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Removed unused entry point 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') | gyp/experimental.gyp » ('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_surface.h" 8 #include "sk_surface.h"
9 9
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkImage.h" 11 #include "SkImage.h"
12 #include "SkMatrix.h" 12 #include "SkMatrix.h"
13 #include "SkPaint.h" 13 #include "SkPaint.h"
14 #include "SkPath.h" 14 #include "SkPath.h"
15 #include "SkSurface.h" 15 #include "SkSurface.h"
16 16
17 static SkImageInfo make(const sk_imageinfo_t& cinfo) { 17 static SkImageInfo make(const sk_imageinfo_t& cinfo) {
18 return SkImageInfo::Make(cinfo.width, cinfo.height, 18 return SkImageInfo::Make(cinfo.width, cinfo.height,
19 (SkColorType)cinfo.colorType, (SkAlphaType)cinfo.al phaType); 19 (SkColorType)cinfo.colorType, (SkAlphaType)cinfo.al phaType);
20 } 20 }
21 21
22 static const SkRect& AsRect(const sk_rect_t& crect) { 22 static const SkRect& AsRect(const sk_rect_t& crect) {
23 return reinterpret_cast<const SkRect&>(crect); 23 return reinterpret_cast<const SkRect&>(crect);
24 } 24 }
25 25
26 static const SkPath& AsPath(const sk_path_t& cpath) { 26 static const SkPath& AsPath(const sk_path_t& cpath) {
27 return reinterpret_cast<const SkPath&>(cpath); 27 return reinterpret_cast<const SkPath&>(cpath);
28 } 28 }
29 29
30 static SkPath* as_path(sk_path_t* cpath) {
31 return reinterpret_cast<SkPath*>(cpath);
32 }
33
30 static const SkImage* AsImage(const sk_image_t* cimage) { 34 static const SkImage* AsImage(const sk_image_t* cimage) {
31 return reinterpret_cast<const SkImage*>(cimage); 35 return reinterpret_cast<const SkImage*>(cimage);
32 } 36 }
33 37
34 static const SkPaint& AsPaint(const sk_paint_t& cpaint) { 38 static const SkPaint& AsPaint(const sk_paint_t& cpaint) {
35 return reinterpret_cast<const SkPaint&>(cpaint); 39 return reinterpret_cast<const SkPaint&>(cpaint);
36 } 40 }
37 41
38 static const SkPaint* AsPaint(const sk_paint_t* cpaint) { 42 static const SkPaint* AsPaint(const sk_paint_t* cpaint) {
39 return reinterpret_cast<const SkPaint*>(cpaint); 43 return reinterpret_cast<const SkPaint*>(cpaint);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 sk_color_t sk_paint_get_color(const sk_paint_t* cpaint) { 99 sk_color_t sk_paint_get_color(const sk_paint_t* cpaint) {
96 return AsPaint(*cpaint).getColor(); 100 return AsPaint(*cpaint).getColor();
97 } 101 }
98 102
99 void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) { 103 void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) {
100 AsPaint(cpaint)->setColor(c); 104 AsPaint(cpaint)->setColor(c);
101 } 105 }
102 106
103 //////////////////////////////////////////////////////////////////////////////// /////////// 107 //////////////////////////////////////////////////////////////////////////////// ///////////
104 108
109 sk_path_t* sk_path_new() {
110 return (sk_path_t*)SkNEW(SkPath);
111 }
112
113 void sk_path_delete(sk_path_t* cpath) {
114 SkDELETE(as_path(cpath));
115 }
116
117 void sk_path_move_to(sk_path_t* cpath, float x, float y) {
118 as_path(cpath)->moveTo(x, y);
119 }
120
121 void sk_path_line_to(sk_path_t* cpath, float x, float y) {
122 as_path(cpath)->lineTo(x, y);
123 }
124
125 void sk_path_quad_to(sk_path_t* cpath, float x0, float y0, float x1, float y1) {
126 as_path(cpath)->quadTo(x0, y0, x1, y1);
127 }
128
129 void sk_path_close(sk_path_t* cpath) {
130 as_path(cpath)->close();
131 }
132
133 //////////////////////////////////////////////////////////////////////////////// ///////////
134
105 void sk_canvas_save(sk_canvas_t* ccanvas) { 135 void sk_canvas_save(sk_canvas_t* ccanvas) {
106 AsCanvas(ccanvas)->save(); 136 AsCanvas(ccanvas)->save();
107 } 137 }
108 138
109 void sk_canvas_save_layer(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk _paint_t* cpaint) { 139 void sk_canvas_save_layer(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk _paint_t* cpaint) {
110 AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint)); 140 AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint));
111 } 141 }
112 142
113 void sk_canvas_restore(sk_canvas_t* ccanvas) { 143 void sk_canvas_restore(sk_canvas_t* ccanvas) {
114 AsCanvas(ccanvas)->restore(); 144 AsCanvas(ccanvas)->restore();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 sk_rect_t cr = { 5, 5, 95, 95 }; 219 sk_rect_t cr = { 5, 5, 95, 95 };
190 sk_canvas_draw_oval(ccanvas, &cr, cpaint); 220 sk_canvas_draw_oval(ccanvas, &cr, cpaint);
191 221
192 cr.left += 25; 222 cr.left += 25;
193 cr.top += 25; 223 cr.top += 25;
194 cr.right -= 25; 224 cr.right -= 25;
195 cr.bottom -= 25; 225 cr.bottom -= 25;
196 sk_paint_set_color(cpaint, 0xFF00FF00); 226 sk_paint_set_color(cpaint, 0xFF00FF00);
197 sk_canvas_draw_rect(ccanvas, &cr, cpaint); 227 sk_canvas_draw_rect(ccanvas, &cr, cpaint);
198 228
229 sk_path_t* cpath = sk_path_new();
230 sk_path_move_to(cpath, 50, 50);
231 sk_path_line_to(cpath, 100, 100);
232 sk_path_line_to(cpath, 50, 100);
233 sk_path_close(cpath);
234
235 sk_canvas_draw_path(ccanvas, cpath, cpaint);
236
199 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface); 237 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface);
200 238
201 // HERE WE CROSS THE C..C++ boundary 239 // HERE WE CROSS THE C..C++ boundary
202 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); 240 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL);
203 241
242 sk_path_delete(cpath);
204 sk_paint_delete(cpaint); 243 sk_paint_delete(cpaint);
205 sk_image_unref(cimage); 244 sk_image_unref(cimage);
206 sk_surface_delete(csurface); 245 sk_surface_delete(csurface);
207 } 246 }
OLDNEW
« no previous file with comments | « experimental/sk_surface.h ('k') | gyp/experimental.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698