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

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

Issue 736133006: more c (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years 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
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" 8 #include "sk_canvas.h"
9 #include "sk_image.h" 9 #include "sk_image.h"
10 #include "sk_paint.h" 10 #include "sk_paint.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 140 }
141 141
142 static SkPaint* AsPaint(sk_paint_t* cpaint) { 142 static SkPaint* AsPaint(sk_paint_t* cpaint) {
143 return reinterpret_cast<SkPaint*>(cpaint); 143 return reinterpret_cast<SkPaint*>(cpaint);
144 } 144 }
145 145
146 static SkCanvas* AsCanvas(sk_canvas_t* ccanvas) { 146 static SkCanvas* AsCanvas(sk_canvas_t* ccanvas) {
147 return reinterpret_cast<SkCanvas*>(ccanvas); 147 return reinterpret_cast<SkCanvas*>(ccanvas);
148 } 148 }
149 149
150 static SkShader* AsShader(sk_shader_t* cshader) {
151 return reinterpret_cast<SkShader*>(cshader);
152 }
153
150 //////////////////////////////////////////////////////////////////////////////// /////////// 154 //////////////////////////////////////////////////////////////////////////////// ///////////
151 155
152 sk_colortype_t sk_colortype_get_default_8888() { 156 sk_colortype_t sk_colortype_get_default_8888() {
153 sk_colortype_t ct; 157 sk_colortype_t ct;
154 if (!to_c_colortype(kN32_SkColorType, &ct)) { 158 if (!to_c_colortype(kN32_SkColorType, &ct)) {
155 ct = UNKNOWN_SK_COLORTYPE; 159 ct = UNKNOWN_SK_COLORTYPE;
156 } 160 }
157 return ct; 161 return ct;
158 } 162 }
159 163
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 211 }
208 212
209 sk_color_t sk_paint_get_color(const sk_paint_t* cpaint) { 213 sk_color_t sk_paint_get_color(const sk_paint_t* cpaint) {
210 return AsPaint(*cpaint).getColor(); 214 return AsPaint(*cpaint).getColor();
211 } 215 }
212 216
213 void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) { 217 void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) {
214 AsPaint(cpaint)->setColor(c); 218 AsPaint(cpaint)->setColor(c);
215 } 219 }
216 220
221 void sk_paint_set_shader(sk_paint_t* cpaint, sk_shader_t* cshader) {
222 AsPaint(cpaint)->setShader(AsShader(cshader));
223 }
224
217 //////////////////////////////////////////////////////////////////////////////// /////////// 225 //////////////////////////////////////////////////////////////////////////////// ///////////
218 226
219 sk_path_t* sk_path_new() { 227 sk_path_t* sk_path_new() {
220 return (sk_path_t*)SkNEW(SkPath); 228 return (sk_path_t*)SkNEW(SkPath);
221 } 229 }
222 230
223 void sk_path_delete(sk_path_t* cpath) { 231 void sk_path_delete(sk_path_t* cpath) {
224 SkDELETE(as_path(cpath)); 232 SkDELETE(as_path(cpath));
225 } 233 }
226 234
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 341
334 sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pi xels, 342 sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pi xels,
335 size_t rowBytes) { 343 size_t rowBytes) {
336 SkImageInfo info; 344 SkImageInfo info;
337 if (!from_c_info(*cinfo, &info)) { 345 if (!from_c_info(*cinfo, &info)) {
338 return NULL; 346 return NULL;
339 } 347 }
340 return (sk_surface_t*)SkSurface::NewRasterDirect(info, pixels, rowBytes); 348 return (sk_surface_t*)SkSurface::NewRasterDirect(info, pixels, rowBytes);
341 } 349 }
342 350
343 void sk_surface_delete(sk_surface_t* csurf) { 351 void sk_surface_unref(sk_surface_t* csurf) {
344 SkSurface* surf = (SkSurface*)csurf; 352 SkSafeUnref((SkSurface*)csurf);
345 SkSafeUnref(surf);
346 } 353 }
347 354
348 sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) { 355 sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) {
349 SkSurface* surf = (SkSurface*)csurf; 356 SkSurface* surf = (SkSurface*)csurf;
350 return (sk_canvas_t*)surf->getCanvas(); 357 return (sk_canvas_t*)surf->getCanvas();
351 } 358 }
352 359
353 sk_image_t* sk_surface_new_image_snapshot(sk_surface_t* csurf) { 360 sk_image_t* sk_surface_new_image_snapshot(sk_surface_t* csurf) {
354 SkSurface* surf = (SkSurface*)csurf; 361 SkSurface* surf = (SkSurface*)csurf;
355 return (sk_image_t*)surf->newImageSnapshot(); 362 return (sk_image_t*)surf->newImageSnapshot();
356 } 363 }
357 364
365 //////////////////////////////////////////////////////////////////////////////// ///////////
358 366
359 /////////////////// 367 #include "../../include/effects/SkGradientShader.h"
368 #include "sk_shader.h"
369
370 const struct {
371 sk_shader_tilemode_t fC;
372 SkShader::TileMode fSK;
373 } gTileModeMap[] = {
374 { CLAMP_SK_SHADER_TILEMODE, SkShader::kClamp_TileMode },
375 { REPEAT_SK_SHADER_TILEMODE, SkShader::kRepeat_TileMode },
376 { MIRROR_SK_SHADER_TILEMODE, SkShader::kMirror_TileMode },
377 };
378
379 static bool from_c_tilemode(sk_shader_tilemode_t cMode, SkShader::TileMode* skMo de) {
380 for (size_t i = 0; i < SK_ARRAY_COUNT(gTileModeMap); ++i) {
381 if (cMode == gTileModeMap[i].fC) {
382 if (skMode) {
383 *skMode = gTileModeMap[i].fSK;
384 }
385 return true;
386 }
387 }
388 return false;
389 }
390
391 void sk_shader_ref(sk_shader_t* cshader) {
392 SkSafeRef(AsShader(cshader));
393 }
394
395 void sk_shader_unref(sk_shader_t* cshader) {
396 SkSafeUnref(AsShader(cshader));
397 }
398
399 sk_shader_t* sk_shader_new_linear_gradient(const sk_point_t pts[2],
400 const sk_color_t colors[],
401 const float colorPos[],
402 int colorCount,
403 sk_shader_tilemode_t cmode,
404 const sk_matrix_t* cmatrix) {
405 SkShader::TileMode mode;
406 if (!from_c_tilemode(cmode, &mode)) {
407 return NULL;
408 }
409 SkMatrix matrix;
410 if (cmatrix) {
411 matrix.setAll(cmatrix->mat[0], cmatrix->mat[1], cmatrix->mat[2],
412 cmatrix->mat[3], cmatrix->mat[4], cmatrix->mat[5],
413 cmatrix->mat[6], cmatrix->mat[7], cmatrix->mat[8]);
414 } else {
415 matrix.setIdentity();
416 }
417 SkShader* s = SkGradientShader::CreateLinear(reinterpret_cast<const SkPoint* >(pts),
418 reinterpret_cast<const SkColor* >(colors),
419 colorPos, colorCount, mode, 0, &matrix);
420 return (sk_shader_t*)s;
421 }
422
423 //////////////////////////////////////////////////////////////////////////////// ///////////
424 //////////////////////////////////////////////////////////////////////////////// ///////////
360 425
361 void sk_test_capi(SkCanvas* canvas) { 426 void sk_test_capi(SkCanvas* canvas) {
362 sk_imageinfo_t cinfo; 427 sk_imageinfo_t cinfo;
363 cinfo.width = 100; 428 cinfo.width = 100;
364 cinfo.height = 100; 429 cinfo.height = 100;
365 cinfo.colorType = (sk_colortype_t)kN32_SkColorType; 430 cinfo.colorType = (sk_colortype_t)kN32_SkColorType;
366 cinfo.alphaType = (sk_alphatype_t)kPremul_SkAlphaType; 431 cinfo.alphaType = (sk_alphatype_t)kPremul_SkAlphaType;
367 432
368 sk_surface_t* csurface = sk_surface_new_raster(&cinfo); 433 sk_surface_t* csurface = sk_surface_new_raster(&cinfo);
369 sk_canvas_t* ccanvas = sk_surface_get_canvas(csurface); 434 sk_canvas_t* ccanvas = sk_surface_get_canvas(csurface);
(...skipping 21 matching lines...) Expand all
391 sk_canvas_draw_path(ccanvas, cpath, cpaint); 456 sk_canvas_draw_path(ccanvas, cpath, cpaint);
392 457
393 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface); 458 sk_image_t* cimage = sk_surface_new_image_snapshot(csurface);
394 459
395 // HERE WE CROSS THE C..C++ boundary 460 // HERE WE CROSS THE C..C++ boundary
396 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL); 461 canvas->drawImage((const SkImage*)cimage, 20, 20, NULL);
397 462
398 sk_path_delete(cpath); 463 sk_path_delete(cpath);
399 sk_paint_delete(cpaint); 464 sk_paint_delete(cpaint);
400 sk_image_unref(cimage); 465 sk_image_unref(cimage);
401 sk_surface_delete(csurface); 466 sk_surface_unref(csurface);
402 } 467 }
OLDNEW
« include/c/sk_matrix.h ('K') | « include/c/sk_types.h ('k') | tests/CTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698