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

Side by Side Diff: src/utils/SkLua.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 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 | « src/utils/SkLayer.cpp ('k') | src/utils/SkMeshUtils.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 2013 Google Inc. 2 * Copyright 2013 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 "SkLua.h" 8 #include "SkLua.h"
9 9
10 #if SK_SUPPORT_GPU 10 #if SK_SUPPORT_GPU
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 if (lua_isnumber(L, index)) { 495 if (lua_isnumber(L, index)) {
496 paint->setAlpha(SkScalarRoundToInt(lua2scalar(L, index) * 255)); 496 paint->setAlpha(SkScalarRoundToInt(lua2scalar(L, index) * 255));
497 return paint; 497 return paint;
498 } else if (lua_isuserdata(L, index)) { 498 } else if (lua_isuserdata(L, index)) {
499 const SkPaint* ptr = get_obj<SkPaint>(L, index); 499 const SkPaint* ptr = get_obj<SkPaint>(L, index);
500 if (ptr) { 500 if (ptr) {
501 *paint = *ptr; 501 *paint = *ptr;
502 return paint; 502 return paint;
503 } 503 }
504 } 504 }
505 return NULL; 505 return nullptr;
506 } 506 }
507 507
508 static int lcanvas_drawImage(lua_State* L) { 508 static int lcanvas_drawImage(lua_State* L) {
509 SkCanvas* canvas = get_ref<SkCanvas>(L, 1); 509 SkCanvas* canvas = get_ref<SkCanvas>(L, 1);
510 SkImage* image = get_ref<SkImage>(L, 2); 510 SkImage* image = get_ref<SkImage>(L, 2);
511 if (NULL == image) { 511 if (nullptr == image) {
512 return 0; 512 return 0;
513 } 513 }
514 SkScalar x = lua2scalar(L, 3); 514 SkScalar x = lua2scalar(L, 3);
515 SkScalar y = lua2scalar(L, 4); 515 SkScalar y = lua2scalar(L, 4);
516 516
517 SkPaint paint; 517 SkPaint paint;
518 canvas->drawImage(image, x, y, lua2OptionalPaint(L, 5, &paint)); 518 canvas->drawImage(image, x, y, lua2OptionalPaint(L, 5, &paint));
519 return 0; 519 return 0;
520 } 520 }
521 521
522 static int lcanvas_drawImageRect(lua_State* L) { 522 static int lcanvas_drawImageRect(lua_State* L) {
523 SkCanvas* canvas = get_ref<SkCanvas>(L, 1); 523 SkCanvas* canvas = get_ref<SkCanvas>(L, 1);
524 SkImage* image = get_ref<SkImage>(L, 2); 524 SkImage* image = get_ref<SkImage>(L, 2);
525 if (NULL == image) { 525 if (nullptr == image) {
526 return 0; 526 return 0;
527 } 527 }
528 528
529 SkRect srcR, dstR; 529 SkRect srcR, dstR;
530 SkRect* srcRPtr = NULL; 530 SkRect* srcRPtr = nullptr;
531 if (!lua_isnil(L, 3)) { 531 if (!lua_isnil(L, 3)) {
532 srcRPtr = lua2rect(L, 3, &srcR); 532 srcRPtr = lua2rect(L, 3, &srcR);
533 } 533 }
534 lua2rect(L, 4, &dstR); 534 lua2rect(L, 4, &dstR);
535 535
536 SkPaint paint; 536 SkPaint paint;
537 canvas->legacy_drawImageRect(image, srcRPtr, dstR, lua2OptionalPaint(L, 5, & paint)); 537 canvas->legacy_drawImageRect(image, srcRPtr, dstR, lua2OptionalPaint(L, 5, & paint));
538 return 0; 538 return 0;
539 } 539 }
540 540
541 static int lcanvas_drawPatch(lua_State* L) { 541 static int lcanvas_drawPatch(lua_State* L) {
542 SkPoint cubics[12]; 542 SkPoint cubics[12];
543 SkColor colorStorage[4]; 543 SkColor colorStorage[4];
544 SkPoint texStorage[4]; 544 SkPoint texStorage[4];
545 545
546 const SkColor* colors = NULL; 546 const SkColor* colors = nullptr;
547 const SkPoint* texs = NULL; 547 const SkPoint* texs = nullptr;
548 548
549 getarray_points(L, 2, cubics, 12); 549 getarray_points(L, 2, cubics, 12);
550 550
551 colorStorage[0] = SK_ColorRED; 551 colorStorage[0] = SK_ColorRED;
552 colorStorage[1] = SK_ColorGREEN; 552 colorStorage[1] = SK_ColorGREEN;
553 colorStorage[2] = SK_ColorBLUE; 553 colorStorage[2] = SK_ColorBLUE;
554 colorStorage[3] = SK_ColorGRAY; 554 colorStorage[3] = SK_ColorGRAY;
555 555
556 if (lua_isnil(L, 4)) { 556 if (lua_isnil(L, 4)) {
557 colors = colorStorage; 557 colors = colorStorage;
558 } else { 558 } else {
559 getarray_points(L, 4, texStorage, 4); 559 getarray_points(L, 4, texStorage, 4);
560 texs = texStorage; 560 texs = texStorage;
561 } 561 }
562 562
563 get_ref<SkCanvas>(L, 1)->drawPatch(cubics, colors, texs, NULL, *get_obj<SkPa int>(L, 5)); 563 get_ref<SkCanvas>(L, 1)->drawPatch(cubics, colors, texs, nullptr, *get_obj<S kPaint>(L, 5));
564 return 0; 564 return 0;
565 } 565 }
566 566
567 static int lcanvas_drawPath(lua_State* L) { 567 static int lcanvas_drawPath(lua_State* L) {
568 get_ref<SkCanvas>(L, 1)->drawPath(*get_obj<SkPath>(L, 2), 568 get_ref<SkCanvas>(L, 1)->drawPath(*get_obj<SkPath>(L, 2),
569 *get_obj<SkPaint>(L, 3)); 569 *get_obj<SkPaint>(L, 3));
570 return 0; 570 return 0;
571 } 571 }
572 572
573 // drawPicture(pic, x, y, paint) 573 // drawPicture(pic, x, y, paint)
574 static int lcanvas_drawPicture(lua_State* L) { 574 static int lcanvas_drawPicture(lua_State* L) {
575 SkCanvas* canvas = get_ref<SkCanvas>(L, 1); 575 SkCanvas* canvas = get_ref<SkCanvas>(L, 1);
576 SkPicture* picture = get_ref<SkPicture>(L, 2); 576 SkPicture* picture = get_ref<SkPicture>(L, 2);
577 SkScalar x = lua2scalar_def(L, 3, 0); 577 SkScalar x = lua2scalar_def(L, 3, 0);
578 SkScalar y = lua2scalar_def(L, 4, 0); 578 SkScalar y = lua2scalar_def(L, 4, 0);
579 SkMatrix matrix, *matrixPtr = NULL; 579 SkMatrix matrix, *matrixPtr = nullptr;
580 if (x || y) { 580 if (x || y) {
581 matrix.setTranslate(x, y); 581 matrix.setTranslate(x, y);
582 matrixPtr = &matrix; 582 matrixPtr = &matrix;
583 } 583 }
584 SkPaint paint; 584 SkPaint paint;
585 canvas->drawPicture(picture, matrixPtr, lua2OptionalPaint(L, 5, &paint)); 585 canvas->drawPicture(picture, matrixPtr, lua2OptionalPaint(L, 5, &paint));
586 return 0; 586 return 0;
587 } 587 }
588 588
589 static int lcanvas_drawText(lua_State* L) { 589 static int lcanvas_drawText(lua_State* L) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 SkIRect resultBounds; 639 SkIRect resultBounds;
640 640
641 const SkClipStack& stack = *canvas->getClipStack(); 641 const SkClipStack& stack = *canvas->getClipStack();
642 642
643 GrReducedClip::ReduceClipStack(stack, 643 GrReducedClip::ReduceClipStack(stack,
644 queryBounds, 644 queryBounds,
645 &elements, 645 &elements,
646 &genID, 646 &genID,
647 &initialState, 647 &initialState,
648 &resultBounds, 648 &resultBounds,
649 NULL); 649 nullptr);
650 650
651 GrReducedClip::ElementList::Iter iter(elements); 651 GrReducedClip::ElementList::Iter iter(elements);
652 int i = 0; 652 int i = 0;
653 lua_newtable(L); 653 lua_newtable(L);
654 while(iter.get()) { 654 while(iter.get()) {
655 SkLua(L).pushClipStackElement(*iter.get()); 655 SkLua(L).pushClipStackElement(*iter.get());
656 iter.next(); 656 iter.next();
657 lua_rawseti(L, -2, ++i); 657 lua_rawseti(L, -2, ++i);
658 } 658 }
659 // Currently this only returns the element list to lua, not the initial stat e or result bounds. 659 // Currently this only returns the element list to lua, not the initial stat e or result bounds.
660 // It could return these as additional items on the lua stack. 660 // It could return these as additional items on the lua stack.
661 return 1; 661 return 1;
662 #else 662 #else
663 return 0; 663 return 0;
664 #endif 664 #endif
665 } 665 }
666 666
667 static int lcanvas_save(lua_State* L) { 667 static int lcanvas_save(lua_State* L) {
668 lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->save()); 668 lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->save());
669 return 1; 669 return 1;
670 } 670 }
671 671
672 static int lcanvas_saveLayer(lua_State* L) { 672 static int lcanvas_saveLayer(lua_State* L) {
673 SkPaint paint; 673 SkPaint paint;
674 lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->saveLayer(NULL, lua2OptionalPain t(L, 2, &paint))); 674 lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->saveLayer(nullptr, lua2OptionalP aint(L, 2, &paint)));
675 return 1; 675 return 1;
676 } 676 }
677 677
678 static int lcanvas_restore(lua_State* L) { 678 static int lcanvas_restore(lua_State* L) {
679 get_ref<SkCanvas>(L, 1)->restore(); 679 get_ref<SkCanvas>(L, 1)->restore();
680 return 0; 680 return 0;
681 } 681 }
682 682
683 static int lcanvas_scale(lua_State* L) { 683 static int lcanvas_scale(lua_State* L) {
684 SkScalar sx = lua2scalar_def(L, 2, 1); 684 SkScalar sx = lua2scalar_def(L, 2, 1);
(...skipping 18 matching lines...) Expand all
703 static int lcanvas_concat(lua_State* L) { 703 static int lcanvas_concat(lua_State* L) {
704 get_ref<SkCanvas>(L, 1)->concat(*get_obj<SkMatrix>(L, 2)); 704 get_ref<SkCanvas>(L, 1)->concat(*get_obj<SkMatrix>(L, 2));
705 return 0; 705 return 0;
706 } 706 }
707 707
708 static int lcanvas_newSurface(lua_State* L) { 708 static int lcanvas_newSurface(lua_State* L) {
709 int width = lua2int_def(L, 2, 0); 709 int width = lua2int_def(L, 2, 0);
710 int height = lua2int_def(L, 3, 0); 710 int height = lua2int_def(L, 3, 0);
711 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); 711 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
712 SkSurface* surface = get_ref<SkCanvas>(L, 1)->newSurface(info); 712 SkSurface* surface = get_ref<SkCanvas>(L, 1)->newSurface(info);
713 if (NULL == surface) { 713 if (nullptr == surface) {
714 lua_pushnil(L); 714 lua_pushnil(L);
715 } else { 715 } else {
716 push_ref(L, surface)->unref(); 716 push_ref(L, surface)->unref();
717 } 717 }
718 return 1; 718 return 1;
719 } 719 }
720 720
721 static int lcanvas_gc(lua_State* L) { 721 static int lcanvas_gc(lua_State* L) {
722 get_ref<SkCanvas>(L, 1)->unref(); 722 get_ref<SkCanvas>(L, 1)->unref();
723 return 0; 723 return 0;
(...skipping 23 matching lines...) Expand all
747 { "saveLayer", lcanvas_saveLayer }, 747 { "saveLayer", lcanvas_saveLayer },
748 { "restore", lcanvas_restore }, 748 { "restore", lcanvas_restore },
749 { "scale", lcanvas_scale }, 749 { "scale", lcanvas_scale },
750 { "translate", lcanvas_translate }, 750 { "translate", lcanvas_translate },
751 { "rotate", lcanvas_rotate }, 751 { "rotate", lcanvas_rotate },
752 { "concat", lcanvas_concat }, 752 { "concat", lcanvas_concat },
753 753
754 { "newSurface", lcanvas_newSurface }, 754 { "newSurface", lcanvas_newSurface },
755 755
756 { "__gc", lcanvas_gc }, 756 { "__gc", lcanvas_gc },
757 { NULL, NULL } 757 { nullptr, nullptr }
758 }; 758 };
759 759
760 /////////////////////////////////////////////////////////////////////////////// 760 ///////////////////////////////////////////////////////////////////////////////
761 761
762 static int ldocument_beginPage(lua_State* L) { 762 static int ldocument_beginPage(lua_State* L) {
763 const SkRect* contentPtr = NULL; 763 const SkRect* contentPtr = nullptr;
764 push_ref(L, get_ref<SkDocument>(L, 1)->beginPage(lua2scalar(L, 2), 764 push_ref(L, get_ref<SkDocument>(L, 1)->beginPage(lua2scalar(L, 2),
765 lua2scalar(L, 3), 765 lua2scalar(L, 3),
766 contentPtr)); 766 contentPtr));
767 return 1; 767 return 1;
768 } 768 }
769 769
770 static int ldocument_endPage(lua_State* L) { 770 static int ldocument_endPage(lua_State* L) {
771 get_ref<SkDocument>(L, 1)->endPage(); 771 get_ref<SkDocument>(L, 1)->endPage();
772 return 0; 772 return 0;
773 } 773 }
774 774
775 static int ldocument_close(lua_State* L) { 775 static int ldocument_close(lua_State* L) {
776 get_ref<SkDocument>(L, 1)->close(); 776 get_ref<SkDocument>(L, 1)->close();
777 return 0; 777 return 0;
778 } 778 }
779 779
780 static int ldocument_gc(lua_State* L) { 780 static int ldocument_gc(lua_State* L) {
781 get_ref<SkDocument>(L, 1)->unref(); 781 get_ref<SkDocument>(L, 1)->unref();
782 return 0; 782 return 0;
783 } 783 }
784 784
785 static const struct luaL_Reg gSkDocument_Methods[] = { 785 static const struct luaL_Reg gSkDocument_Methods[] = {
786 { "beginPage", ldocument_beginPage }, 786 { "beginPage", ldocument_beginPage },
787 { "endPage", ldocument_endPage }, 787 { "endPage", ldocument_endPage },
788 { "close", ldocument_close }, 788 { "close", ldocument_close },
789 { "__gc", ldocument_gc }, 789 { "__gc", ldocument_gc },
790 { NULL, NULL } 790 { nullptr, nullptr }
791 }; 791 };
792 792
793 /////////////////////////////////////////////////////////////////////////////// 793 ///////////////////////////////////////////////////////////////////////////////
794 794
795 static int lpaint_isAntiAlias(lua_State* L) { 795 static int lpaint_isAntiAlias(lua_State* L) {
796 lua_pushboolean(L, get_obj<SkPaint>(L, 1)->isAntiAlias()); 796 lua_pushboolean(L, get_obj<SkPaint>(L, 1)->isAntiAlias());
797 return 1; 797 return 1;
798 } 798 }
799 799
800 static int lpaint_setAntiAlias(lua_State* L) { 800 static int lpaint_setAntiAlias(lua_State* L) {
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 { "getStrokeMiter", lpaint_getStrokeMiter }, 1169 { "getStrokeMiter", lpaint_getStrokeMiter },
1170 { "measureText", lpaint_measureText }, 1170 { "measureText", lpaint_measureText },
1171 { "getFontMetrics", lpaint_getFontMetrics }, 1171 { "getFontMetrics", lpaint_getFontMetrics },
1172 { "getEffects", lpaint_getEffects }, 1172 { "getEffects", lpaint_getEffects },
1173 { "getImageFilter", lpaint_getImageFilter }, 1173 { "getImageFilter", lpaint_getImageFilter },
1174 { "setImageFilter", lpaint_setImageFilter }, 1174 { "setImageFilter", lpaint_setImageFilter },
1175 { "getShader", lpaint_getShader }, 1175 { "getShader", lpaint_getShader },
1176 { "setShader", lpaint_setShader }, 1176 { "setShader", lpaint_setShader },
1177 { "getPathEffect", lpaint_getPathEffect }, 1177 { "getPathEffect", lpaint_getPathEffect },
1178 { "__gc", lpaint_gc }, 1178 { "__gc", lpaint_gc },
1179 { NULL, NULL } 1179 { nullptr, nullptr }
1180 }; 1180 };
1181 1181
1182 /////////////////////////////////////////////////////////////////////////////// 1182 ///////////////////////////////////////////////////////////////////////////////
1183 1183
1184 static const char* mode2string(SkShader::TileMode mode) { 1184 static const char* mode2string(SkShader::TileMode mode) {
1185 static const char* gNames[] = { "clamp", "repeat", "mirror" }; 1185 static const char* gNames[] = { "clamp", "repeat", "mirror" };
1186 SkASSERT((unsigned)mode < SK_ARRAY_COUNT(gNames)); 1186 SkASSERT((unsigned)mode < SK_ARRAY_COUNT(gNames));
1187 return gNames[mode]; 1187 return gNames[mode];
1188 } 1188 }
1189 1189
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 static int lshader_gc(lua_State* L) { 1253 static int lshader_gc(lua_State* L) {
1254 get_ref<SkShader>(L, 1)->unref(); 1254 get_ref<SkShader>(L, 1)->unref();
1255 return 0; 1255 return 0;
1256 } 1256 }
1257 1257
1258 static const struct luaL_Reg gSkShader_Methods[] = { 1258 static const struct luaL_Reg gSkShader_Methods[] = {
1259 { "isOpaque", lshader_isOpaque }, 1259 { "isOpaque", lshader_isOpaque },
1260 { "isABitmap", lshader_isABitmap }, 1260 { "isABitmap", lshader_isABitmap },
1261 { "asAGradient", lshader_asAGradient }, 1261 { "asAGradient", lshader_asAGradient },
1262 { "__gc", lshader_gc }, 1262 { "__gc", lshader_gc },
1263 { NULL, NULL } 1263 { nullptr, nullptr }
1264 }; 1264 };
1265 1265
1266 /////////////////////////////////////////////////////////////////////////////// 1266 ///////////////////////////////////////////////////////////////////////////////
1267 1267
1268 static int lpatheffect_asADash(lua_State* L) { 1268 static int lpatheffect_asADash(lua_State* L) {
1269 SkPathEffect* pe = get_ref<SkPathEffect>(L, 1); 1269 SkPathEffect* pe = get_ref<SkPathEffect>(L, 1);
1270 if (pe) { 1270 if (pe) {
1271 SkPathEffect::DashInfo info; 1271 SkPathEffect::DashInfo info;
1272 SkPathEffect::DashType dashType = pe->asADash(&info); 1272 SkPathEffect::DashType dashType = pe->asADash(&info);
1273 if (SkPathEffect::kDash_DashType == dashType) { 1273 if (SkPathEffect::kDash_DashType == dashType) {
1274 SkAutoTArray<SkScalar> intervals(info.fCount); 1274 SkAutoTArray<SkScalar> intervals(info.fCount);
1275 info.fIntervals = intervals.get(); 1275 info.fIntervals = intervals.get();
1276 pe->asADash(&info); 1276 pe->asADash(&info);
1277 SkLua(L).pushDash(info); 1277 SkLua(L).pushDash(info);
1278 return 1; 1278 return 1;
1279 } 1279 }
1280 } 1280 }
1281 return 0; 1281 return 0;
1282 } 1282 }
1283 1283
1284 static int lpatheffect_gc(lua_State* L) { 1284 static int lpatheffect_gc(lua_State* L) {
1285 get_ref<SkPathEffect>(L, 1)->unref(); 1285 get_ref<SkPathEffect>(L, 1)->unref();
1286 return 0; 1286 return 0;
1287 } 1287 }
1288 1288
1289 static const struct luaL_Reg gSkPathEffect_Methods[] = { 1289 static const struct luaL_Reg gSkPathEffect_Methods[] = {
1290 { "asADash", lpatheffect_asADash }, 1290 { "asADash", lpatheffect_asADash },
1291 { "__gc", lpatheffect_gc }, 1291 { "__gc", lpatheffect_gc },
1292 { NULL, NULL } 1292 { nullptr, nullptr }
1293 }; 1293 };
1294 1294
1295 /////////////////////////////////////////////////////////////////////////////// 1295 ///////////////////////////////////////////////////////////////////////////////
1296 1296
1297 static int lpimagefilter_gc(lua_State* L) { 1297 static int lpimagefilter_gc(lua_State* L) {
1298 get_ref<SkImageFilter>(L, 1)->unref(); 1298 get_ref<SkImageFilter>(L, 1)->unref();
1299 return 0; 1299 return 0;
1300 } 1300 }
1301 1301
1302 static const struct luaL_Reg gSkImageFilter_Methods[] = { 1302 static const struct luaL_Reg gSkImageFilter_Methods[] = {
1303 { "__gc", lpimagefilter_gc }, 1303 { "__gc", lpimagefilter_gc },
1304 { NULL, NULL } 1304 { nullptr, nullptr }
1305 }; 1305 };
1306 1306
1307 /////////////////////////////////////////////////////////////////////////////// 1307 ///////////////////////////////////////////////////////////////////////////////
1308 1308
1309 static int lmatrix_getType(lua_State* L) { 1309 static int lmatrix_getType(lua_State* L) {
1310 SkMatrix::TypeMask mask = get_obj<SkMatrix>(L, 1)->getType(); 1310 SkMatrix::TypeMask mask = get_obj<SkMatrix>(L, 1)->getType();
1311 1311
1312 lua_newtable(L); 1312 lua_newtable(L);
1313 setfield_boolean(L, "translate", SkToBool(mask & SkMatrix::kTranslate_Mask )); 1313 setfield_boolean(L, "translate", SkToBool(mask & SkMatrix::kTranslate_Mask ));
1314 setfield_boolean(L, "scale", SkToBool(mask & SkMatrix::kScale_Mask)); 1314 setfield_boolean(L, "scale", SkToBool(mask & SkMatrix::kScale_Mask));
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 1383
1384 static const struct luaL_Reg gSkMatrix_Methods[] = { 1384 static const struct luaL_Reg gSkMatrix_Methods[] = {
1385 { "getType", lmatrix_getType }, 1385 { "getType", lmatrix_getType },
1386 { "getScaleX", lmatrix_getScaleX }, 1386 { "getScaleX", lmatrix_getScaleX },
1387 { "getScaleY", lmatrix_getScaleY }, 1387 { "getScaleY", lmatrix_getScaleY },
1388 { "getTranslateX", lmatrix_getTranslateX }, 1388 { "getTranslateX", lmatrix_getTranslateX },
1389 { "getTranslateY", lmatrix_getTranslateY }, 1389 { "getTranslateY", lmatrix_getTranslateY },
1390 { "setRectToRect", lmatrix_setRectToRect }, 1390 { "setRectToRect", lmatrix_setRectToRect },
1391 { "invert", lmatrix_invert }, 1391 { "invert", lmatrix_invert },
1392 { "mapXY", lmatrix_mapXY }, 1392 { "mapXY", lmatrix_mapXY },
1393 { NULL, NULL } 1393 { nullptr, nullptr }
1394 }; 1394 };
1395 1395
1396 /////////////////////////////////////////////////////////////////////////////// 1396 ///////////////////////////////////////////////////////////////////////////////
1397 1397
1398 static int lpath_getBounds(lua_State* L) { 1398 static int lpath_getBounds(lua_State* L) {
1399 SkLua(L).pushRect(get_obj<SkPath>(L, 1)->getBounds()); 1399 SkLua(L).pushRect(get_obj<SkPath>(L, 1)->getBounds());
1400 return 1; 1400 return 1;
1401 } 1401 }
1402 1402
1403 static const char* fill_type_to_str(SkPath::FillType fill) { 1403 static const char* fill_type_to_str(SkPath::FillType fill) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 { "isRect", lpath_isRect }, 1561 { "isRect", lpath_isRect },
1562 { "isNestedFillRects", lpath_isNestedFillRects }, 1562 { "isNestedFillRects", lpath_isNestedFillRects },
1563 { "countPoints", lpath_countPoints }, 1563 { "countPoints", lpath_countPoints },
1564 { "reset", lpath_reset }, 1564 { "reset", lpath_reset },
1565 { "moveTo", lpath_moveTo }, 1565 { "moveTo", lpath_moveTo },
1566 { "lineTo", lpath_lineTo }, 1566 { "lineTo", lpath_lineTo },
1567 { "quadTo", lpath_quadTo }, 1567 { "quadTo", lpath_quadTo },
1568 { "cubicTo", lpath_cubicTo }, 1568 { "cubicTo", lpath_cubicTo },
1569 { "close", lpath_close }, 1569 { "close", lpath_close },
1570 { "__gc", lpath_gc }, 1570 { "__gc", lpath_gc },
1571 { NULL, NULL } 1571 { nullptr, nullptr }
1572 }; 1572 };
1573 1573
1574 /////////////////////////////////////////////////////////////////////////////// 1574 ///////////////////////////////////////////////////////////////////////////////
1575 1575
1576 static const char* rrect_type(const SkRRect& rr) { 1576 static const char* rrect_type(const SkRRect& rr) {
1577 switch (rr.getType()) { 1577 switch (rr.getType()) {
1578 case SkRRect::kEmpty_Type: return "empty"; 1578 case SkRRect::kEmpty_Type: return "empty";
1579 case SkRRect::kRect_Type: return "rect"; 1579 case SkRRect::kRect_Type: return "rect";
1580 case SkRRect::kOval_Type: return "oval"; 1580 case SkRRect::kOval_Type: return "oval";
1581 case SkRRect::kSimple_Type: return "simple"; 1581 case SkRRect::kSimple_Type: return "simple";
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 static int lrrect_gc(lua_State* L) { 1613 static int lrrect_gc(lua_State* L) {
1614 get_obj<SkRRect>(L, 1)->~SkRRect(); 1614 get_obj<SkRRect>(L, 1)->~SkRRect();
1615 return 0; 1615 return 0;
1616 } 1616 }
1617 1617
1618 static const struct luaL_Reg gSkRRect_Methods[] = { 1618 static const struct luaL_Reg gSkRRect_Methods[] = {
1619 { "rect", lrrect_rect }, 1619 { "rect", lrrect_rect },
1620 { "type", lrrect_type }, 1620 { "type", lrrect_type },
1621 { "radii", lrrect_radii }, 1621 { "radii", lrrect_radii },
1622 { "__gc", lrrect_gc }, 1622 { "__gc", lrrect_gc },
1623 { NULL, NULL } 1623 { nullptr, nullptr }
1624 }; 1624 };
1625 1625
1626 /////////////////////////////////////////////////////////////////////////////// 1626 ///////////////////////////////////////////////////////////////////////////////
1627 1627
1628 static int limage_width(lua_State* L) { 1628 static int limage_width(lua_State* L) {
1629 lua_pushinteger(L, get_ref<SkImage>(L, 1)->width()); 1629 lua_pushinteger(L, get_ref<SkImage>(L, 1)->width());
1630 return 1; 1630 return 1;
1631 } 1631 }
1632 1632
1633 static int limage_height(lua_State* L) { 1633 static int limage_height(lua_State* L) {
1634 lua_pushinteger(L, get_ref<SkImage>(L, 1)->height()); 1634 lua_pushinteger(L, get_ref<SkImage>(L, 1)->height());
1635 return 1; 1635 return 1;
1636 } 1636 }
1637 1637
1638 static int limage_newShader(lua_State* L) { 1638 static int limage_newShader(lua_State* L) {
1639 SkShader::TileMode tmode = SkShader::kClamp_TileMode; 1639 SkShader::TileMode tmode = SkShader::kClamp_TileMode;
1640 const SkMatrix* localM = NULL; 1640 const SkMatrix* localM = nullptr;
1641 SkAutoTUnref<SkShader> shader(get_ref<SkImage>(L, 1)->newShader(tmode, tmode , localM)); 1641 SkAutoTUnref<SkShader> shader(get_ref<SkImage>(L, 1)->newShader(tmode, tmode , localM));
1642 push_ref(L, shader.get()); 1642 push_ref(L, shader.get());
1643 return 1; 1643 return 1;
1644 } 1644 }
1645 1645
1646 static int limage_gc(lua_State* L) { 1646 static int limage_gc(lua_State* L) {
1647 get_ref<SkImage>(L, 1)->unref(); 1647 get_ref<SkImage>(L, 1)->unref();
1648 return 0; 1648 return 0;
1649 } 1649 }
1650 1650
1651 static const struct luaL_Reg gSkImage_Methods[] = { 1651 static const struct luaL_Reg gSkImage_Methods[] = {
1652 { "width", limage_width }, 1652 { "width", limage_width },
1653 { "height", limage_height }, 1653 { "height", limage_height },
1654 { "newShader", limage_newShader }, 1654 { "newShader", limage_newShader },
1655 { "__gc", limage_gc }, 1655 { "__gc", limage_gc },
1656 { NULL, NULL } 1656 { nullptr, nullptr }
1657 }; 1657 };
1658 1658
1659 /////////////////////////////////////////////////////////////////////////////// 1659 ///////////////////////////////////////////////////////////////////////////////
1660 1660
1661 static int lsurface_width(lua_State* L) { 1661 static int lsurface_width(lua_State* L) {
1662 lua_pushinteger(L, get_ref<SkSurface>(L, 1)->width()); 1662 lua_pushinteger(L, get_ref<SkSurface>(L, 1)->width());
1663 return 1; 1663 return 1;
1664 } 1664 }
1665 1665
1666 static int lsurface_height(lua_State* L) { 1666 static int lsurface_height(lua_State* L) {
1667 lua_pushinteger(L, get_ref<SkSurface>(L, 1)->height()); 1667 lua_pushinteger(L, get_ref<SkSurface>(L, 1)->height());
1668 return 1; 1668 return 1;
1669 } 1669 }
1670 1670
1671 static int lsurface_getCanvas(lua_State* L) { 1671 static int lsurface_getCanvas(lua_State* L) {
1672 SkCanvas* canvas = get_ref<SkSurface>(L, 1)->getCanvas(); 1672 SkCanvas* canvas = get_ref<SkSurface>(L, 1)->getCanvas();
1673 if (NULL == canvas) { 1673 if (nullptr == canvas) {
1674 lua_pushnil(L); 1674 lua_pushnil(L);
1675 } else { 1675 } else {
1676 push_ref(L, canvas); 1676 push_ref(L, canvas);
1677 // note: we don't unref canvas, since getCanvas did not ref it. 1677 // note: we don't unref canvas, since getCanvas did not ref it.
1678 // warning: this is weird: now Lua owns a ref on this canvas, but what i f they let 1678 // warning: this is weird: now Lua owns a ref on this canvas, but what i f they let
1679 // the real owner (the surface) go away, but still hold onto the canvas? 1679 // the real owner (the surface) go away, but still hold onto the canvas?
1680 // *really* we want to sort of ref the surface again, but have the nativ e object 1680 // *really* we want to sort of ref the surface again, but have the nativ e object
1681 // know that it is supposed to be treated as a canvas... 1681 // know that it is supposed to be treated as a canvas...
1682 } 1682 }
1683 return 1; 1683 return 1;
1684 } 1684 }
1685 1685
1686 static int lsurface_newImageSnapshot(lua_State* L) { 1686 static int lsurface_newImageSnapshot(lua_State* L) {
1687 SkImage* image = get_ref<SkSurface>(L, 1)->newImageSnapshot(); 1687 SkImage* image = get_ref<SkSurface>(L, 1)->newImageSnapshot();
1688 if (NULL == image) { 1688 if (nullptr == image) {
1689 lua_pushnil(L); 1689 lua_pushnil(L);
1690 } else { 1690 } else {
1691 push_ref(L, image)->unref(); 1691 push_ref(L, image)->unref();
1692 } 1692 }
1693 return 1; 1693 return 1;
1694 } 1694 }
1695 1695
1696 static int lsurface_newSurface(lua_State* L) { 1696 static int lsurface_newSurface(lua_State* L) {
1697 int width = lua2int_def(L, 2, 0); 1697 int width = lua2int_def(L, 2, 0);
1698 int height = lua2int_def(L, 3, 0); 1698 int height = lua2int_def(L, 3, 0);
1699 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); 1699 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
1700 SkSurface* surface = get_ref<SkSurface>(L, 1)->newSurface(info); 1700 SkSurface* surface = get_ref<SkSurface>(L, 1)->newSurface(info);
1701 if (NULL == surface) { 1701 if (nullptr == surface) {
1702 lua_pushnil(L); 1702 lua_pushnil(L);
1703 } else { 1703 } else {
1704 push_ref(L, surface)->unref(); 1704 push_ref(L, surface)->unref();
1705 } 1705 }
1706 return 1; 1706 return 1;
1707 } 1707 }
1708 1708
1709 static int lsurface_gc(lua_State* L) { 1709 static int lsurface_gc(lua_State* L) {
1710 get_ref<SkSurface>(L, 1)->unref(); 1710 get_ref<SkSurface>(L, 1)->unref();
1711 return 0; 1711 return 0;
1712 } 1712 }
1713 1713
1714 static const struct luaL_Reg gSkSurface_Methods[] = { 1714 static const struct luaL_Reg gSkSurface_Methods[] = {
1715 { "width", lsurface_width }, 1715 { "width", lsurface_width },
1716 { "height", lsurface_height }, 1716 { "height", lsurface_height },
1717 { "getCanvas", lsurface_getCanvas }, 1717 { "getCanvas", lsurface_getCanvas },
1718 { "newImageSnapshot", lsurface_newImageSnapshot }, 1718 { "newImageSnapshot", lsurface_newImageSnapshot },
1719 { "newSurface", lsurface_newSurface }, 1719 { "newSurface", lsurface_newSurface },
1720 { "__gc", lsurface_gc }, 1720 { "__gc", lsurface_gc },
1721 { NULL, NULL } 1721 { nullptr, nullptr }
1722 }; 1722 };
1723 1723
1724 /////////////////////////////////////////////////////////////////////////////// 1724 ///////////////////////////////////////////////////////////////////////////////
1725 1725
1726 static int lpicturerecorder_beginRecording(lua_State* L) { 1726 static int lpicturerecorder_beginRecording(lua_State* L) {
1727 const SkScalar w = lua2scalar_def(L, 2, -1); 1727 const SkScalar w = lua2scalar_def(L, 2, -1);
1728 const SkScalar h = lua2scalar_def(L, 3, -1); 1728 const SkScalar h = lua2scalar_def(L, 3, -1);
1729 if (w <= 0 || h <= 0) { 1729 if (w <= 0 || h <= 0) {
1730 lua_pushnil(L); 1730 lua_pushnil(L);
1731 return 1; 1731 return 1;
1732 } 1732 }
1733 1733
1734 SkCanvas* canvas = get_obj<SkPictureRecorder>(L, 1)->beginRecording(w, h); 1734 SkCanvas* canvas = get_obj<SkPictureRecorder>(L, 1)->beginRecording(w, h);
1735 if (NULL == canvas) { 1735 if (nullptr == canvas) {
1736 lua_pushnil(L); 1736 lua_pushnil(L);
1737 return 1; 1737 return 1;
1738 } 1738 }
1739 1739
1740 push_ref(L, canvas); 1740 push_ref(L, canvas);
1741 return 1; 1741 return 1;
1742 } 1742 }
1743 1743
1744 static int lpicturerecorder_getCanvas(lua_State* L) { 1744 static int lpicturerecorder_getCanvas(lua_State* L) {
1745 SkCanvas* canvas = get_obj<SkPictureRecorder>(L, 1)->getRecordingCanvas(); 1745 SkCanvas* canvas = get_obj<SkPictureRecorder>(L, 1)->getRecordingCanvas();
1746 if (NULL == canvas) { 1746 if (nullptr == canvas) {
1747 lua_pushnil(L); 1747 lua_pushnil(L);
1748 return 1; 1748 return 1;
1749 } 1749 }
1750 push_ref(L, canvas); 1750 push_ref(L, canvas);
1751 return 1; 1751 return 1;
1752 } 1752 }
1753 1753
1754 static int lpicturerecorder_endRecording(lua_State* L) { 1754 static int lpicturerecorder_endRecording(lua_State* L) {
1755 SkPicture* pic = get_obj<SkPictureRecorder>(L, 1)->endRecording(); 1755 SkPicture* pic = get_obj<SkPictureRecorder>(L, 1)->endRecording();
1756 if (NULL == pic) { 1756 if (nullptr == pic) {
1757 lua_pushnil(L); 1757 lua_pushnil(L);
1758 return 1; 1758 return 1;
1759 } 1759 }
1760 push_ref(L, pic)->unref(); 1760 push_ref(L, pic)->unref();
1761 return 1; 1761 return 1;
1762 } 1762 }
1763 1763
1764 static int lpicturerecorder_gc(lua_State* L) { 1764 static int lpicturerecorder_gc(lua_State* L) {
1765 get_obj<SkPictureRecorder>(L, 1)->~SkPictureRecorder(); 1765 get_obj<SkPictureRecorder>(L, 1)->~SkPictureRecorder();
1766 return 0; 1766 return 0;
1767 } 1767 }
1768 1768
1769 static const struct luaL_Reg gSkPictureRecorder_Methods[] = { 1769 static const struct luaL_Reg gSkPictureRecorder_Methods[] = {
1770 { "beginRecording", lpicturerecorder_beginRecording }, 1770 { "beginRecording", lpicturerecorder_beginRecording },
1771 { "getCanvas", lpicturerecorder_getCanvas }, 1771 { "getCanvas", lpicturerecorder_getCanvas },
1772 { "endRecording", lpicturerecorder_endRecording }, 1772 { "endRecording", lpicturerecorder_endRecording },
1773 { "__gc", lpicturerecorder_gc }, 1773 { "__gc", lpicturerecorder_gc },
1774 { NULL, NULL } 1774 { nullptr, nullptr }
1775 }; 1775 };
1776 1776
1777 /////////////////////////////////////////////////////////////////////////////// 1777 ///////////////////////////////////////////////////////////////////////////////
1778 1778
1779 static int lpicture_width(lua_State* L) { 1779 static int lpicture_width(lua_State* L) {
1780 lua_pushnumber(L, get_ref<SkPicture>(L, 1)->cullRect().width()); 1780 lua_pushnumber(L, get_ref<SkPicture>(L, 1)->cullRect().width());
1781 return 1; 1781 return 1;
1782 } 1782 }
1783 1783
1784 static int lpicture_height(lua_State* L) { 1784 static int lpicture_height(lua_State* L) {
1785 lua_pushnumber(L, get_ref<SkPicture>(L, 1)->cullRect().height()); 1785 lua_pushnumber(L, get_ref<SkPicture>(L, 1)->cullRect().height());
1786 return 1; 1786 return 1;
1787 } 1787 }
1788 1788
1789 static int lpicture_gc(lua_State* L) { 1789 static int lpicture_gc(lua_State* L) {
1790 get_ref<SkPicture>(L, 1)->unref(); 1790 get_ref<SkPicture>(L, 1)->unref();
1791 return 0; 1791 return 0;
1792 } 1792 }
1793 1793
1794 static const struct luaL_Reg gSkPicture_Methods[] = { 1794 static const struct luaL_Reg gSkPicture_Methods[] = {
1795 { "width", lpicture_width }, 1795 { "width", lpicture_width },
1796 { "height", lpicture_height }, 1796 { "height", lpicture_height },
1797 { "__gc", lpicture_gc }, 1797 { "__gc", lpicture_gc },
1798 { NULL, NULL } 1798 { nullptr, nullptr }
1799 }; 1799 };
1800 1800
1801 /////////////////////////////////////////////////////////////////////////////// 1801 ///////////////////////////////////////////////////////////////////////////////
1802 1802
1803 static int ltextblob_bounds(lua_State* L) { 1803 static int ltextblob_bounds(lua_State* L) {
1804 SkLua(L).pushRect(get_ref<SkTextBlob>(L, 1)->bounds()); 1804 SkLua(L).pushRect(get_ref<SkTextBlob>(L, 1)->bounds());
1805 return 1; 1805 return 1;
1806 } 1806 }
1807 1807
1808 static int ltextblob_gc(lua_State* L) { 1808 static int ltextblob_gc(lua_State* L) {
1809 SkSafeUnref(get_ref<SkTextBlob>(L, 1)); 1809 SkSafeUnref(get_ref<SkTextBlob>(L, 1));
1810 return 0; 1810 return 0;
1811 } 1811 }
1812 1812
1813 static const struct luaL_Reg gSkTextBlob_Methods[] = { 1813 static const struct luaL_Reg gSkTextBlob_Methods[] = {
1814 { "bounds", ltextblob_bounds }, 1814 { "bounds", ltextblob_bounds },
1815 { "__gc", ltextblob_gc }, 1815 { "__gc", ltextblob_gc },
1816 { NULL, NULL } 1816 { nullptr, nullptr }
1817 }; 1817 };
1818 1818
1819 /////////////////////////////////////////////////////////////////////////////// 1819 ///////////////////////////////////////////////////////////////////////////////
1820 1820
1821 static int ltypeface_getFamilyName(lua_State* L) { 1821 static int ltypeface_getFamilyName(lua_State* L) {
1822 SkString str; 1822 SkString str;
1823 get_ref<SkTypeface>(L, 1)->getFamilyName(&str); 1823 get_ref<SkTypeface>(L, 1)->getFamilyName(&str);
1824 lua_pushstring(L, str.c_str()); 1824 lua_pushstring(L, str.c_str());
1825 return 1; 1825 return 1;
1826 } 1826 }
1827 1827
1828 static int ltypeface_getStyle(lua_State* L) { 1828 static int ltypeface_getStyle(lua_State* L) {
1829 lua_pushnumber(L, (double)get_ref<SkTypeface>(L, 1)->style()); 1829 lua_pushnumber(L, (double)get_ref<SkTypeface>(L, 1)->style());
1830 return 1; 1830 return 1;
1831 } 1831 }
1832 1832
1833 static int ltypeface_gc(lua_State* L) { 1833 static int ltypeface_gc(lua_State* L) {
1834 SkSafeUnref(get_ref<SkTypeface>(L, 1)); 1834 SkSafeUnref(get_ref<SkTypeface>(L, 1));
1835 return 0; 1835 return 0;
1836 } 1836 }
1837 1837
1838 static const struct luaL_Reg gSkTypeface_Methods[] = { 1838 static const struct luaL_Reg gSkTypeface_Methods[] = {
1839 { "getFamilyName", ltypeface_getFamilyName }, 1839 { "getFamilyName", ltypeface_getFamilyName },
1840 { "getStyle", ltypeface_getStyle }, 1840 { "getStyle", ltypeface_getStyle },
1841 { "__gc", ltypeface_gc }, 1841 { "__gc", ltypeface_gc },
1842 { NULL, NULL } 1842 { nullptr, nullptr }
1843 }; 1843 };
1844 1844
1845 /////////////////////////////////////////////////////////////////////////////// 1845 ///////////////////////////////////////////////////////////////////////////////
1846 1846
1847 class AutoCallLua { 1847 class AutoCallLua {
1848 public: 1848 public:
1849 AutoCallLua(lua_State* L, const char func[], const char verb[]) : fL(L) { 1849 AutoCallLua(lua_State* L, const char func[], const char verb[]) : fL(L) {
1850 lua_getglobal(L, func); 1850 lua_getglobal(L, func);
1851 if (!lua_isfunction(L, -1)) { 1851 if (!lua_isfunction(L, -1)) {
1852 int t = lua_type(L, -1); 1852 int t = lua_type(L, -1);
(...skipping 13 matching lines...) Expand all
1866 1866
1867 private: 1867 private:
1868 lua_State* fL; 1868 lua_State* fL;
1869 }; 1869 };
1870 1870
1871 #define AUTO_LUA(verb) AutoCallLua acl(fL, fFunc.c_str(), verb) 1871 #define AUTO_LUA(verb) AutoCallLua acl(fL, fFunc.c_str(), verb)
1872 1872
1873 /////////////////////////////////////////////////////////////////////////////// 1873 ///////////////////////////////////////////////////////////////////////////////
1874 1874
1875 static int lsk_newDocumentPDF(lua_State* L) { 1875 static int lsk_newDocumentPDF(lua_State* L) {
1876 const char* file = NULL; 1876 const char* file = nullptr;
1877 if (lua_gettop(L) > 0 && lua_isstring(L, 1)) { 1877 if (lua_gettop(L) > 0 && lua_isstring(L, 1)) {
1878 file = lua_tolstring(L, 1, NULL); 1878 file = lua_tolstring(L, 1, nullptr);
1879 } 1879 }
1880 1880
1881 SkDocument* doc = SkDocument::CreatePDF(file); 1881 SkDocument* doc = SkDocument::CreatePDF(file);
1882 if (NULL == doc) { 1882 if (nullptr == doc) {
1883 // do I need to push a nil on the stack and return 1? 1883 // do I need to push a nil on the stack and return 1?
1884 return 0; 1884 return 0;
1885 } else { 1885 } else {
1886 push_ref(L, doc)->unref(); 1886 push_ref(L, doc)->unref();
1887 return 1; 1887 return 1;
1888 } 1888 }
1889 } 1889 }
1890 1890
1891 static int lsk_newBlurImageFilter(lua_State* L) { 1891 static int lsk_newBlurImageFilter(lua_State* L) {
1892 SkScalar sigmaX = lua2scalar_def(L, 1, 0); 1892 SkScalar sigmaX = lua2scalar_def(L, 1, 0);
1893 SkScalar sigmaY = lua2scalar_def(L, 2, 0); 1893 SkScalar sigmaY = lua2scalar_def(L, 2, 0);
1894 SkImageFilter* imf = SkBlurImageFilter::Create(sigmaX, sigmaY); 1894 SkImageFilter* imf = SkBlurImageFilter::Create(sigmaX, sigmaY);
1895 if (NULL == imf) { 1895 if (nullptr == imf) {
1896 lua_pushnil(L); 1896 lua_pushnil(L);
1897 } else { 1897 } else {
1898 push_ref(L, imf)->unref(); 1898 push_ref(L, imf)->unref();
1899 } 1899 }
1900 return 1; 1900 return 1;
1901 } 1901 }
1902 1902
1903 static int lsk_newLinearGradient(lua_State* L) { 1903 static int lsk_newLinearGradient(lua_State* L) {
1904 SkScalar x0 = lua2scalar_def(L, 1, 0); 1904 SkScalar x0 = lua2scalar_def(L, 1, 0);
1905 SkScalar y0 = lua2scalar_def(L, 2, 0); 1905 SkScalar y0 = lua2scalar_def(L, 2, 0);
1906 SkColor c0 = lua2color(L, 3); 1906 SkColor c0 = lua2color(L, 3);
1907 SkScalar x1 = lua2scalar_def(L, 4, 0); 1907 SkScalar x1 = lua2scalar_def(L, 4, 0);
1908 SkScalar y1 = lua2scalar_def(L, 5, 0); 1908 SkScalar y1 = lua2scalar_def(L, 5, 0);
1909 SkColor c1 = lua2color(L, 6); 1909 SkColor c1 = lua2color(L, 6);
1910 1910
1911 SkPoint pts[] = { { x0, y0 }, { x1, y1 } }; 1911 SkPoint pts[] = { { x0, y0 }, { x1, y1 } };
1912 SkColor colors[] = { c0, c1 }; 1912 SkColor colors[] = { c0, c1 };
1913 SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader: :kClamp_TileMode); 1913 SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShad er::kClamp_TileMode);
1914 if (NULL == s) { 1914 if (nullptr == s) {
1915 lua_pushnil(L); 1915 lua_pushnil(L);
1916 } else { 1916 } else {
1917 push_ref(L, s)->unref(); 1917 push_ref(L, s)->unref();
1918 } 1918 }
1919 return 1; 1919 return 1;
1920 } 1920 }
1921 1921
1922 static int lsk_newMatrix(lua_State* L) { 1922 static int lsk_newMatrix(lua_State* L) {
1923 push_new<SkMatrix>(L)->reset(); 1923 push_new<SkMatrix>(L)->reset();
1924 return 1; 1924 return 1;
(...skipping 15 matching lines...) Expand all
1940 } 1940 }
1941 1941
1942 static int lsk_newRRect(lua_State* L) { 1942 static int lsk_newRRect(lua_State* L) {
1943 push_new<SkRRect>(L)->setEmpty(); 1943 push_new<SkRRect>(L)->setEmpty();
1944 return 1; 1944 return 1;
1945 } 1945 }
1946 1946
1947 #include "SkTextBox.h" 1947 #include "SkTextBox.h"
1948 // Sk.newTextBlob(text, rect, paint) 1948 // Sk.newTextBlob(text, rect, paint)
1949 static int lsk_newTextBlob(lua_State* L) { 1949 static int lsk_newTextBlob(lua_State* L) {
1950 const char* text = lua_tolstring(L, 1, NULL); 1950 const char* text = lua_tolstring(L, 1, nullptr);
1951 SkRect bounds; 1951 SkRect bounds;
1952 lua2rect(L, 2, &bounds); 1952 lua2rect(L, 2, &bounds);
1953 const SkPaint& paint = *get_obj<SkPaint>(L, 3); 1953 const SkPaint& paint = *get_obj<SkPaint>(L, 3);
1954 1954
1955 SkTextBox box; 1955 SkTextBox box;
1956 box.setMode(SkTextBox::kLineBreak_Mode); 1956 box.setMode(SkTextBox::kLineBreak_Mode);
1957 box.setBox(bounds); 1957 box.setBox(bounds);
1958 box.setText(text, strlen(text), paint); 1958 box.setText(text, strlen(text), paint);
1959 1959
1960 SkScalar newBottom; 1960 SkScalar newBottom;
1961 SkAutoTUnref<SkTextBlob> blob(box.snapshotTextBlob(&newBottom)); 1961 SkAutoTUnref<SkTextBlob> blob(box.snapshotTextBlob(&newBottom));
1962 push_ref<SkTextBlob>(L, blob); 1962 push_ref<SkTextBlob>(L, blob);
1963 SkLua(L).pushScalar(newBottom); 1963 SkLua(L).pushScalar(newBottom);
1964 return 2; 1964 return 2;
1965 } 1965 }
1966 1966
1967 static int lsk_newTypeface(lua_State* L) { 1967 static int lsk_newTypeface(lua_State* L) {
1968 const char* name = NULL; 1968 const char* name = nullptr;
1969 int style = SkTypeface::kNormal; 1969 int style = SkTypeface::kNormal;
1970 1970
1971 int count = lua_gettop(L); 1971 int count = lua_gettop(L);
1972 if (count > 0 && lua_isstring(L, 1)) { 1972 if (count > 0 && lua_isstring(L, 1)) {
1973 name = lua_tolstring(L, 1, NULL); 1973 name = lua_tolstring(L, 1, nullptr);
1974 if (count > 1 && lua_isnumber(L, 2)) { 1974 if (count > 1 && lua_isnumber(L, 2)) {
1975 style = lua_tointegerx(L, 2, NULL) & SkTypeface::kBoldItalic; 1975 style = lua_tointegerx(L, 2, nullptr) & SkTypeface::kBoldItalic;
1976 } 1976 }
1977 } 1977 }
1978 1978
1979 SkTypeface* face = SkTypeface::CreateFromName(name, 1979 SkTypeface* face = SkTypeface::CreateFromName(name,
1980 (SkTypeface::Style)style); 1980 (SkTypeface::Style)style);
1981 // SkDebugf("---- name <%s> style=%d, face=%p ref=%d\n", name, style, face, f ace->getRefCnt()); 1981 // SkDebugf("---- name <%s> style=%d, face=%p ref=%d\n", name, style, face, f ace->getRefCnt());
1982 if (NULL == face) { 1982 if (nullptr == face) {
1983 face = SkTypeface::RefDefault(); 1983 face = SkTypeface::RefDefault();
1984 } 1984 }
1985 push_ref(L, face)->unref(); 1985 push_ref(L, face)->unref();
1986 return 1; 1986 return 1;
1987 } 1987 }
1988 1988
1989 static int lsk_newRasterSurface(lua_State* L) { 1989 static int lsk_newRasterSurface(lua_State* L) {
1990 int width = lua2int_def(L, 1, 0); 1990 int width = lua2int_def(L, 1, 0);
1991 int height = lua2int_def(L, 2, 0); 1991 int height = lua2int_def(L, 2, 0);
1992 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); 1992 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
1993 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); 1993 SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
1994 SkSurface* surface = SkSurface::NewRaster(info, &props); 1994 SkSurface* surface = SkSurface::NewRaster(info, &props);
1995 if (NULL == surface) { 1995 if (nullptr == surface) {
1996 lua_pushnil(L); 1996 lua_pushnil(L);
1997 } else { 1997 } else {
1998 push_ref(L, surface)->unref(); 1998 push_ref(L, surface)->unref();
1999 } 1999 }
2000 return 1; 2000 return 1;
2001 } 2001 }
2002 2002
2003 static int lsk_loadImage(lua_State* L) { 2003 static int lsk_loadImage(lua_State* L) {
2004 if (lua_gettop(L) > 0 && lua_isstring(L, 1)) { 2004 if (lua_gettop(L) > 0 && lua_isstring(L, 1)) {
2005 const char* name = lua_tolstring(L, 1, NULL); 2005 const char* name = lua_tolstring(L, 1, nullptr);
2006 SkAutoDataUnref data(SkData::NewFromFileName(name)); 2006 SkAutoDataUnref data(SkData::NewFromFileName(name));
2007 if (data.get()) { 2007 if (data.get()) {
2008 SkImage* image = SkImage::NewFromEncoded(data); 2008 SkImage* image = SkImage::NewFromEncoded(data);
2009 if (image) { 2009 if (image) {
2010 push_ref(L, image)->unref(); 2010 push_ref(L, image)->unref();
2011 return 1; 2011 return 1;
2012 } 2012 }
2013 } 2013 }
2014 } 2014 }
2015 return 0; 2015 return 0;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 REG_CLASS(L, SkSurface); 2062 REG_CLASS(L, SkSurface);
2063 REG_CLASS(L, SkTextBlob); 2063 REG_CLASS(L, SkTextBlob);
2064 REG_CLASS(L, SkTypeface); 2064 REG_CLASS(L, SkTypeface);
2065 } 2065 }
2066 2066
2067 extern "C" int luaopen_skia(lua_State* L); 2067 extern "C" int luaopen_skia(lua_State* L);
2068 extern "C" int luaopen_skia(lua_State* L) { 2068 extern "C" int luaopen_skia(lua_State* L) {
2069 SkLua::Load(L); 2069 SkLua::Load(L);
2070 return 0; 2070 return 0;
2071 } 2071 }
OLDNEW
« no previous file with comments | « src/utils/SkLayer.cpp ('k') | src/utils/SkMeshUtils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698