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

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: 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
34 static const SkPath* as_path(const sk_path_t* cpath) {
reed1 2014/10/08 12:12:46 do we need this one? if so, can it take/return a r
robertphillips 2014/10/08 12:56:18 Apparently it is not needed, I've removed it.
35 return reinterpret_cast<const SkPath*>(cpath);
36 }
37
30 static const SkImage* AsImage(const sk_image_t* cimage) { 38 static const SkImage* AsImage(const sk_image_t* cimage) {
31 return reinterpret_cast<const SkImage*>(cimage); 39 return reinterpret_cast<const SkImage*>(cimage);
32 } 40 }
33 41
34 static const SkPaint& AsPaint(const sk_paint_t& cpaint) { 42 static const SkPaint& AsPaint(const sk_paint_t& cpaint) {
35 return reinterpret_cast<const SkPaint&>(cpaint); 43 return reinterpret_cast<const SkPaint&>(cpaint);
36 } 44 }
37 45
38 static const SkPaint* AsPaint(const sk_paint_t* cpaint) { 46 static const SkPaint* AsPaint(const sk_paint_t* cpaint) {
39 return reinterpret_cast<const SkPaint*>(cpaint); 47 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) { 103 sk_color_t sk_paint_get_color(const sk_paint_t* cpaint) {
96 return AsPaint(*cpaint).getColor(); 104 return AsPaint(*cpaint).getColor();
97 } 105 }
98 106
99 void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) { 107 void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) {
100 AsPaint(cpaint)->setColor(c); 108 AsPaint(cpaint)->setColor(c);
101 } 109 }
102 110
103 //////////////////////////////////////////////////////////////////////////////// /////////// 111 //////////////////////////////////////////////////////////////////////////////// ///////////
104 112
113 sk_path_t* sk_path_new() {
114 return (sk_path_t*)SkNEW(SkPath);
115 }
116
117 void sk_path_delete(sk_path_t* cpath) {
118 SkDELETE(as_path(cpath));
119 }
120
121 void sk_path_move_to(sk_path_t* cpath, float x, float y) {
122 as_path(cpath)->moveTo(x, y);
123 }
124
125 void sk_path_line_to(sk_path_t* cpath, float x, float y) {
126 as_path(cpath)->lineTo(x, y);
127 }
128
129 void sk_path_quad_to(sk_path_t* cpath, float x0, float y0, float x1, float y1) {
130 as_path(cpath)->quadTo(x0, y0, x1, y1);
131 }
132
133 void sk_path_close(sk_path_t* cpath) {
134 as_path(cpath)->close();
135 }
136
137 //////////////////////////////////////////////////////////////////////////////// ///////////
138
105 void sk_canvas_save(sk_canvas_t* ccanvas) { 139 void sk_canvas_save(sk_canvas_t* ccanvas) {
106 AsCanvas(ccanvas)->save(); 140 AsCanvas(ccanvas)->save();
107 } 141 }
108 142
109 void sk_canvas_save_layer(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk _paint_t* cpaint) { 143 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)); 144 AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint));
111 } 145 }
112 146
113 void sk_canvas_restore(sk_canvas_t* ccanvas) { 147 void sk_canvas_restore(sk_canvas_t* ccanvas) {
114 AsCanvas(ccanvas)->restore(); 148 AsCanvas(ccanvas)->restore();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 //////////////////////////////////////////////////////////////////////////////// /////////// 180 //////////////////////////////////////////////////////////////////////////////// ///////////
147 181
148 sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t* cinfo) { 182 sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t* cinfo) {
149 return (sk_surface_t*)SkSurface::NewRaster(make(*cinfo)); 183 return (sk_surface_t*)SkSurface::NewRaster(make(*cinfo));
150 } 184 }
151 185
152 sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pi xels, 186 sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pi xels,
153 size_t rowBytes) { 187 size_t rowBytes) {
154 return (sk_surface_t*)SkSurface::NewRasterDirect(make(*cinfo), pixels, rowBy tes); 188 return (sk_surface_t*)SkSurface::NewRasterDirect(make(*cinfo), pixels, rowBy tes);
155 } 189 }
156 190
robertphillips 2014/10/07 18:20:09 It seems a bit funky to call this delete but unref
reed1 2014/10/08 12:12:46 Yea, trying to be conservative in exposing when so
157 void sk_surface_delete(sk_surface_t* csurf) { 191 void sk_surface_delete(sk_surface_t* csurf) {
158 SkSurface* surf = (SkSurface*)csurf; 192 SkSurface* surf = (SkSurface*)csurf;
159 SkSafeUnref(surf); 193 SkSafeUnref(surf);
160 } 194 }
161 195
162 sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) { 196 sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) {
163 SkSurface* surf = (SkSurface*)csurf; 197 SkSurface* surf = (SkSurface*)csurf;
164 return (sk_canvas_t*)surf->getCanvas(); 198 return (sk_canvas_t*)surf->getCanvas();
165 } 199 }
166 200
(...skipping 22 matching lines...) Expand all
189 sk_rect_t cr = { 5, 5, 95, 95 }; 223 sk_rect_t cr = { 5, 5, 95, 95 };
190 sk_canvas_draw_oval(ccanvas, &cr, cpaint); 224 sk_canvas_draw_oval(ccanvas, &cr, cpaint);
191 225
192 cr.left += 25; 226 cr.left += 25;
193 cr.top += 25; 227 cr.top += 25;
194 cr.right -= 25; 228 cr.right -= 25;
195 cr.bottom -= 25; 229 cr.bottom -= 25;
196 sk_paint_set_color(cpaint, 0xFF00FF00); 230 sk_paint_set_color(cpaint, 0xFF00FF00);
197 sk_canvas_draw_rect(ccanvas, &cr, cpaint); 231 sk_canvas_draw_rect(ccanvas, &cr, cpaint);
198 232
233 sk_path_t* cpath = sk_path_new();
234 sk_path_move_to(cpath, 50, 50);
235 sk_path_line_to(cpath, 100, 100);
236 sk_path_line_to(cpath, 50, 100);
237 sk_path_close(cpath);
238
239 sk_canvas_draw_path(ccanvas, cpath, cpaint);
240
199 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface); 241 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface);
200 242
201 // HERE WE CROSS THE C..C++ boundary 243 // HERE WE CROSS THE C..C++ boundary
202 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); 244 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL);
203 245
246 sk_path_delete(cpath);
204 sk_paint_delete(cpaint); 247 sk_paint_delete(cpaint);
205 sk_image_unref(cimage); 248 sk_image_unref(cimage);
206 sk_surface_delete(csurface); 249 sk_surface_delete(csurface);
207 } 250 }
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