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

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

Issue 712613002: add patch and clicktracking to lua (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 | « samplecode/SampleLua.cpp ('k') | no next file » | 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 static void setfield_scalar(lua_State* L, const char key[], SkScalar value) { 156 static void setfield_scalar(lua_State* L, const char key[], SkScalar value) {
157 setfield_number(L, key, SkScalarToLua(value)); 157 setfield_number(L, key, SkScalarToLua(value));
158 } 158 }
159 159
160 static void setfield_function(lua_State* L, 160 static void setfield_function(lua_State* L,
161 const char key[], lua_CFunction value) { 161 const char key[], lua_CFunction value) {
162 lua_pushcfunction(L, value); 162 lua_pushcfunction(L, value);
163 lua_setfield(L, -2, key); 163 lua_setfield(L, -2, key);
164 } 164 }
165 165
166 static int lua2int_def(lua_State* L, int index, int defaultValue) {
167 if (lua_isnumber(L, index)) {
168 return (int)lua_tonumber(L, index);
169 } else {
170 return defaultValue;
171 }
172 }
173
174 static SkScalar lua2scalar(lua_State* L, int index) {
175 SkASSERT(lua_isnumber(L, index));
176 return SkLuaToScalar(lua_tonumber(L, index));
177 }
178
179 static SkScalar lua2scalar_def(lua_State* L, int index, SkScalar defaultValue) {
180 if (lua_isnumber(L, index)) {
181 return SkLuaToScalar(lua_tonumber(L, index));
182 } else {
183 return defaultValue;
184 }
185 }
186
187 static SkScalar getarray_scalar(lua_State* L, int stackIndex, int arrayIndex) {
188 SkASSERT(lua_istable(L, stackIndex));
189 lua_rawgeti(L, stackIndex, arrayIndex);
190
191 SkScalar value = lua2scalar(L, -1);
192 lua_pop(L, 1);
193 return value;
194 }
195
196 static void getarray_scalars(lua_State* L, int stackIndex, SkScalar dst[], int c ount) {
197 for (int i = 0; i < count; ++i) {
198 dst[i] = getarray_scalar(L, stackIndex, i + 1);
199 }
200 }
201
202 static void getarray_points(lua_State* L, int stackIndex, SkPoint pts[], int cou nt) {
203 getarray_scalars(L, stackIndex, &pts[0].fX, count * 2);
204 }
205
166 static void setarray_number(lua_State* L, int index, double value) { 206 static void setarray_number(lua_State* L, int index, double value) {
167 lua_pushnumber(L, value); 207 lua_pushnumber(L, value);
168 lua_rawseti(L, -2, index); 208 lua_rawseti(L, -2, index);
169 } 209 }
170 210
171 static void setarray_scalar(lua_State* L, int index, SkScalar value) { 211 static void setarray_scalar(lua_State* L, int index, SkScalar value) {
172 setarray_number(L, index, SkScalarToLua(value)); 212 setarray_number(L, index, SkScalarToLua(value));
173 } 213 }
174 214
175 void SkLua::pushBool(bool value, const char key[]) { 215 void SkLua::pushBool(bool value, const char key[]) {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } 393 }
354 this->pushString(region_op(element.getOp()), "op"); 394 this->pushString(region_op(element.getOp()), "op");
355 this->pushBool(element.isAA(), "aa"); 395 this->pushBool(element.isAA(), "aa");
356 CHECK_SETFIELD(key); 396 CHECK_SETFIELD(key);
357 } 397 }
358 398
359 399
360 /////////////////////////////////////////////////////////////////////////////// 400 ///////////////////////////////////////////////////////////////////////////////
361 /////////////////////////////////////////////////////////////////////////////// 401 ///////////////////////////////////////////////////////////////////////////////
362 402
363 static int lua2int_def(lua_State* L, int index, int defaultValue) {
364 if (lua_isnumber(L, index)) {
365 return (int)lua_tonumber(L, index);
366 } else {
367 return defaultValue;
368 }
369 }
370
371 static SkScalar lua2scalar(lua_State* L, int index) {
372 SkASSERT(lua_isnumber(L, index));
373 return SkLuaToScalar(lua_tonumber(L, index));
374 }
375
376 static SkScalar lua2scalar_def(lua_State* L, int index, SkScalar defaultValue) {
377 if (lua_isnumber(L, index)) {
378 return SkLuaToScalar(lua_tonumber(L, index));
379 } else {
380 return defaultValue;
381 }
382 }
383
384 static SkScalar getfield_scalar(lua_State* L, int index, const char key[]) { 403 static SkScalar getfield_scalar(lua_State* L, int index, const char key[]) {
385 SkASSERT(lua_istable(L, index)); 404 SkASSERT(lua_istable(L, index));
386 lua_pushstring(L, key); 405 lua_pushstring(L, key);
387 lua_gettable(L, index); 406 lua_gettable(L, index);
388 407
389 SkScalar value = lua2scalar(L, -1); 408 SkScalar value = lua2scalar(L, -1);
390 lua_pop(L, 1); 409 lua_pop(L, 1);
391 return value; 410 return value;
392 } 411 }
393 412
394 static SkScalar getfield_scalar_default(lua_State* L, int index, const char key[ ], SkScalar def) { 413 static SkScalar getfield_scalar_default(lua_State* L, int index, const char key[ ], SkScalar def) {
395 SkASSERT(lua_istable(L, index)); 414 SkASSERT(lua_istable(L, index));
396 lua_pushstring(L, key); 415 lua_pushstring(L, key);
397 lua_gettable(L, index); 416 lua_gettable(L, index);
398 417
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 return 0; 464 return 0;
446 } 465 }
447 466
448 static int lcanvas_drawPaint(lua_State* L) { 467 static int lcanvas_drawPaint(lua_State* L) {
449 get_ref<SkCanvas>(L, 1)->drawPaint(*get_obj<SkPaint>(L, 2)); 468 get_ref<SkCanvas>(L, 1)->drawPaint(*get_obj<SkPaint>(L, 2));
450 return 0; 469 return 0;
451 } 470 }
452 471
453 static int lcanvas_drawRect(lua_State* L) { 472 static int lcanvas_drawRect(lua_State* L) {
454 SkRect rect; 473 SkRect rect;
455 get_ref<SkCanvas>(L, 1)->drawRect(*lua2rect(L, 2, &rect), 474 lua2rect(L, 2, &rect);
456 *get_obj<SkPaint>(L, 3)); 475 const SkPaint* paint = get_obj<SkPaint>(L, 3);
476 get_ref<SkCanvas>(L, 1)->drawRect(rect, *paint);
457 return 0; 477 return 0;
458 } 478 }
459 479
460 static int lcanvas_drawOval(lua_State* L) { 480 static int lcanvas_drawOval(lua_State* L) {
461 SkRect rect; 481 SkRect rect;
462 get_ref<SkCanvas>(L, 1)->drawOval(*lua2rect(L, 2, &rect), 482 get_ref<SkCanvas>(L, 1)->drawOval(*lua2rect(L, 2, &rect),
463 *get_obj<SkPaint>(L, 3)); 483 *get_obj<SkPaint>(L, 3));
464 return 0; 484 return 0;
465 } 485 }
466 486
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 if (!lua_isnil(L, 3)) { 532 if (!lua_isnil(L, 3)) {
513 srcRPtr = lua2rect(L, 3, &srcR); 533 srcRPtr = lua2rect(L, 3, &srcR);
514 } 534 }
515 lua2rect(L, 4, &dstR); 535 lua2rect(L, 4, &dstR);
516 536
517 SkPaint paint; 537 SkPaint paint;
518 canvas->drawImageRect(image, srcRPtr, dstR, lua2OptionalPaint(L, 5, &paint)) ; 538 canvas->drawImageRect(image, srcRPtr, dstR, lua2OptionalPaint(L, 5, &paint)) ;
519 return 0; 539 return 0;
520 } 540 }
521 541
542 static int lcanvas_drawPatch(lua_State* L) {
543 SkPoint cubics[12];
544 SkColor colorStorage[4];
545 SkPoint texStorage[4];
546
547 const SkColor* colors = NULL;
548 const SkPoint* texs = NULL;
549
550 getarray_points(L, 2, cubics, 12);
551
552 colorStorage[0] = SK_ColorRED;
553 colorStorage[1] = SK_ColorGREEN;
554 colorStorage[2] = SK_ColorBLUE;
555 colorStorage[3] = SK_ColorGRAY;
556
557 if (lua_isnil(L, 4)) {
558 colors = colorStorage;
559 } else {
560 getarray_points(L, 4, texStorage, 4);
561 texs = texStorage;
562 }
563
564 get_ref<SkCanvas>(L, 1)->drawPatch(cubics, colors, texs, NULL, *get_obj<SkPa int>(L, 5));
565 return 0;
566 }
567
522 static int lcanvas_drawPath(lua_State* L) { 568 static int lcanvas_drawPath(lua_State* L) {
523 get_ref<SkCanvas>(L, 1)->drawPath(*get_obj<SkPath>(L, 2), 569 get_ref<SkCanvas>(L, 1)->drawPath(*get_obj<SkPath>(L, 2),
524 *get_obj<SkPaint>(L, 3)); 570 *get_obj<SkPaint>(L, 3));
525 return 0; 571 return 0;
526 } 572 }
527 573
528 // drawPicture(pic, x, y, paint) 574 // drawPicture(pic, x, y, paint)
529 static int lcanvas_drawPicture(lua_State* L) { 575 static int lcanvas_drawPicture(lua_State* L) {
530 SkCanvas* canvas = get_ref<SkCanvas>(L, 1); 576 SkCanvas* canvas = get_ref<SkCanvas>(L, 1);
531 SkPicture* picture = get_ref<SkPicture>(L, 2); 577 SkPicture* picture = get_ref<SkPicture>(L, 2);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 return 0; 701 return 0;
656 } 702 }
657 703
658 static int lcanvas_concat(lua_State* L) { 704 static int lcanvas_concat(lua_State* L) {
659 get_ref<SkCanvas>(L, 1)->concat(*get_obj<SkMatrix>(L, 2)); 705 get_ref<SkCanvas>(L, 1)->concat(*get_obj<SkMatrix>(L, 2));
660 return 0; 706 return 0;
661 } 707 }
662 708
663 static int lcanvas_newSurface(lua_State* L) { 709 static int lcanvas_newSurface(lua_State* L) {
664 int width = lua2int_def(L, 2, 0); 710 int width = lua2int_def(L, 2, 0);
665 int height = lua2int_def(L, 2, 0); 711 int height = lua2int_def(L, 3, 0);
666 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); 712 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
667 SkSurface* surface = get_ref<SkCanvas>(L, 1)->newSurface(info); 713 SkSurface* surface = get_ref<SkCanvas>(L, 1)->newSurface(info);
668 if (NULL == surface) { 714 if (NULL == surface) {
669 lua_pushnil(L); 715 lua_pushnil(L);
670 } else { 716 } else {
671 push_ref(L, surface)->unref(); 717 push_ref(L, surface)->unref();
672 } 718 }
673 return 1; 719 return 1;
674 } 720 }
675 721
676 static int lcanvas_gc(lua_State* L) { 722 static int lcanvas_gc(lua_State* L) {
677 get_ref<SkCanvas>(L, 1)->unref(); 723 get_ref<SkCanvas>(L, 1)->unref();
678 return 0; 724 return 0;
679 } 725 }
680 726
681 const struct luaL_Reg gSkCanvas_Methods[] = { 727 const struct luaL_Reg gSkCanvas_Methods[] = {
682 { "clear", lcanvas_clear }, 728 { "clear", lcanvas_clear },
683 { "drawColor", lcanvas_drawColor }, 729 { "drawColor", lcanvas_drawColor },
684 { "drawPaint", lcanvas_drawPaint }, 730 { "drawPaint", lcanvas_drawPaint },
685 { "drawRect", lcanvas_drawRect }, 731 { "drawRect", lcanvas_drawRect },
686 { "drawOval", lcanvas_drawOval }, 732 { "drawOval", lcanvas_drawOval },
687 { "drawCircle", lcanvas_drawCircle }, 733 { "drawCircle", lcanvas_drawCircle },
688 { "drawImage", lcanvas_drawImage }, 734 { "drawImage", lcanvas_drawImage },
689 { "drawImageRect", lcanvas_drawImageRect }, 735 { "drawImageRect", lcanvas_drawImageRect },
736 { "drawPatch", lcanvas_drawPatch },
690 { "drawPath", lcanvas_drawPath }, 737 { "drawPath", lcanvas_drawPath },
691 { "drawPicture", lcanvas_drawPicture }, 738 { "drawPicture", lcanvas_drawPicture },
692 { "drawText", lcanvas_drawText }, 739 { "drawText", lcanvas_drawText },
693 { "drawTextBlob", lcanvas_drawTextBlob }, 740 { "drawTextBlob", lcanvas_drawTextBlob },
694 { "getSaveCount", lcanvas_getSaveCount }, 741 { "getSaveCount", lcanvas_getSaveCount },
695 { "getTotalMatrix", lcanvas_getTotalMatrix }, 742 { "getTotalMatrix", lcanvas_getTotalMatrix },
696 { "getClipStack", lcanvas_getClipStack }, 743 { "getClipStack", lcanvas_getClipStack },
697 #if SK_SUPPORT_GPU 744 #if SK_SUPPORT_GPU
698 { "getReducedClipStack", SkLua::lcanvas_getReducedClipStack }, 745 { "getReducedClipStack", SkLua::lcanvas_getReducedClipStack },
699 #endif 746 #endif
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 static int lpaint_setTypeface(lua_State* L) { 921 static int lpaint_setTypeface(lua_State* L) {
875 get_obj<SkPaint>(L, 1)->setTypeface(get_ref<SkTypeface>(L, 2)); 922 get_obj<SkPaint>(L, 1)->setTypeface(get_ref<SkTypeface>(L, 2));
876 return 0; 923 return 0;
877 } 924 }
878 925
879 static int lpaint_getHinting(lua_State* L) { 926 static int lpaint_getHinting(lua_State* L) {
880 SkLua(L).pushU32(get_obj<SkPaint>(L, 1)->getHinting()); 927 SkLua(L).pushU32(get_obj<SkPaint>(L, 1)->getHinting());
881 return 1; 928 return 1;
882 } 929 }
883 930
931 static int lpaint_getFilterLevel(lua_State* L) {
932 SkLua(L).pushU32(get_obj<SkPaint>(L, 1)->getFilterLevel());
933 return 1;
934 }
935
936 static int lpaint_setFilterLevel(lua_State* L) {
937 int level = lua2int_def(L, 2, -1);
938 if (level >= 0 && level <= 3) {
939 get_obj<SkPaint>(L, 1)->setFilterLevel((SkPaint::FilterLevel)level);
940 }
941 return 0;
942 }
943
884 static int lpaint_getFontID(lua_State* L) { 944 static int lpaint_getFontID(lua_State* L) {
885 SkTypeface* face = get_obj<SkPaint>(L, 1)->getTypeface(); 945 SkTypeface* face = get_obj<SkPaint>(L, 1)->getTypeface();
886 SkLua(L).pushU32(SkTypeface::UniqueID(face)); 946 SkLua(L).pushU32(SkTypeface::UniqueID(face));
887 return 1; 947 return 1;
888 } 948 }
889 949
890 static const struct { 950 static const struct {
891 const char* fLabel; 951 const char* fLabel;
892 SkPaint::Align fAlign; 952 SkPaint::Align fAlign;
893 } gAlignRec[] = { 953 } gAlignRec[] = {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 static int lpaint_gc(lua_State* L) { 1125 static int lpaint_gc(lua_State* L) {
1066 get_obj<SkPaint>(L, 1)->~SkPaint(); 1126 get_obj<SkPaint>(L, 1)->~SkPaint();
1067 return 0; 1127 return 0;
1068 } 1128 }
1069 1129
1070 static const struct luaL_Reg gSkPaint_Methods[] = { 1130 static const struct luaL_Reg gSkPaint_Methods[] = {
1071 { "isAntiAlias", lpaint_isAntiAlias }, 1131 { "isAntiAlias", lpaint_isAntiAlias },
1072 { "setAntiAlias", lpaint_setAntiAlias }, 1132 { "setAntiAlias", lpaint_setAntiAlias },
1073 { "isDither", lpaint_isDither }, 1133 { "isDither", lpaint_isDither },
1074 { "setDither", lpaint_setDither }, 1134 { "setDither", lpaint_setDither },
1135 { "getFilterLevel", lpaint_getFilterLevel },
1136 { "setFilterLevel", lpaint_setFilterLevel },
1075 { "isUnderlineText", lpaint_isUnderlineText }, 1137 { "isUnderlineText", lpaint_isUnderlineText },
1076 { "isStrikeThruText", lpaint_isStrikeThruText }, 1138 { "isStrikeThruText", lpaint_isStrikeThruText },
1077 { "isFakeBoldText", lpaint_isFakeBoldText }, 1139 { "isFakeBoldText", lpaint_isFakeBoldText },
1078 { "isLinearText", lpaint_isLinearText }, 1140 { "isLinearText", lpaint_isLinearText },
1079 { "isSubpixelText", lpaint_isSubpixelText }, 1141 { "isSubpixelText", lpaint_isSubpixelText },
1080 { "setSubpixelText", lpaint_setSubpixelText }, 1142 { "setSubpixelText", lpaint_setSubpixelText },
1081 { "isDevKernText", lpaint_isDevKernText }, 1143 { "isDevKernText", lpaint_isDevKernText },
1082 { "isLCDRenderText", lpaint_isLCDRenderText }, 1144 { "isLCDRenderText", lpaint_isLCDRenderText },
1083 { "setLCDRenderText", lpaint_setLCDRenderText }, 1145 { "setLCDRenderText", lpaint_setLCDRenderText },
1084 { "isEmbeddedBitmapText", lpaint_isEmbeddedBitmapText }, 1146 { "isEmbeddedBitmapText", lpaint_isEmbeddedBitmapText },
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 static int lmatrix_getTranslateX(lua_State* L) { 1334 static int lmatrix_getTranslateX(lua_State* L) {
1273 lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getTranslateX()); 1335 lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getTranslateX());
1274 return 1; 1336 return 1;
1275 } 1337 }
1276 1338
1277 static int lmatrix_getTranslateY(lua_State* L) { 1339 static int lmatrix_getTranslateY(lua_State* L) {
1278 lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getTranslateY()); 1340 lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getTranslateY());
1279 return 1; 1341 return 1;
1280 } 1342 }
1281 1343
1344 static int lmatrix_invert(lua_State* L) {
1345 lua_pushboolean(L, get_obj<SkMatrix>(L, 1)->invert(get_obj<SkMatrix>(L, 2))) ;
1346 return 1;
1347 }
1348
1349 static int lmatrix_mapXY(lua_State* L) {
1350 SkPoint pt = { lua2scalar(L, 2), lua2scalar(L, 3) };
1351 get_obj<SkMatrix>(L, 1)->mapPoints(&pt, &pt, 1);
1352 lua_pushnumber(L, pt.x());
1353 lua_pushnumber(L, pt.y());
1354 return 2;
1355 }
1356
1282 static int lmatrix_setRectToRect(lua_State* L) { 1357 static int lmatrix_setRectToRect(lua_State* L) {
1283 SkMatrix* matrix = get_obj<SkMatrix>(L, 1); 1358 SkMatrix* matrix = get_obj<SkMatrix>(L, 1);
1284 SkRect srcR, dstR; 1359 SkRect srcR, dstR;
1285 lua2rect(L, 2, &srcR); 1360 lua2rect(L, 2, &srcR);
1286 lua2rect(L, 3, &dstR); 1361 lua2rect(L, 3, &dstR);
1287 const char* scaleToFitStr = lua_tostring(L, 4); 1362 const char* scaleToFitStr = lua_tostring(L, 4);
1288 SkMatrix::ScaleToFit scaleToFit = SkMatrix::kFill_ScaleToFit; 1363 SkMatrix::ScaleToFit scaleToFit = SkMatrix::kFill_ScaleToFit;
1289 1364
1290 if (scaleToFitStr) { 1365 if (scaleToFitStr) {
1291 const struct { 1366 const struct {
(...skipping 18 matching lines...) Expand all
1310 return 0; 1385 return 0;
1311 } 1386 }
1312 1387
1313 static const struct luaL_Reg gSkMatrix_Methods[] = { 1388 static const struct luaL_Reg gSkMatrix_Methods[] = {
1314 { "getType", lmatrix_getType }, 1389 { "getType", lmatrix_getType },
1315 { "getScaleX", lmatrix_getScaleX }, 1390 { "getScaleX", lmatrix_getScaleX },
1316 { "getScaleY", lmatrix_getScaleY }, 1391 { "getScaleY", lmatrix_getScaleY },
1317 { "getTranslateX", lmatrix_getTranslateX }, 1392 { "getTranslateX", lmatrix_getTranslateX },
1318 { "getTranslateY", lmatrix_getTranslateY }, 1393 { "getTranslateY", lmatrix_getTranslateY },
1319 { "setRectToRect", lmatrix_setRectToRect }, 1394 { "setRectToRect", lmatrix_setRectToRect },
1395 { "invert", lmatrix_invert },
1396 { "mapXY", lmatrix_mapXY },
1320 { NULL, NULL } 1397 { NULL, NULL }
1321 }; 1398 };
1322 1399
1323 /////////////////////////////////////////////////////////////////////////////// 1400 ///////////////////////////////////////////////////////////////////////////////
1324 1401
1325 static int lpath_getBounds(lua_State* L) { 1402 static int lpath_getBounds(lua_State* L) {
1326 SkLua(L).pushRect(get_obj<SkPath>(L, 1)->getBounds()); 1403 SkLua(L).pushRect(get_obj<SkPath>(L, 1)->getBounds());
1327 return 1; 1404 return 1;
1328 } 1405 }
1329 1406
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1556 static int limage_width(lua_State* L) { 1633 static int limage_width(lua_State* L) {
1557 lua_pushinteger(L, get_ref<SkImage>(L, 1)->width()); 1634 lua_pushinteger(L, get_ref<SkImage>(L, 1)->width());
1558 return 1; 1635 return 1;
1559 } 1636 }
1560 1637
1561 static int limage_height(lua_State* L) { 1638 static int limage_height(lua_State* L) {
1562 lua_pushinteger(L, get_ref<SkImage>(L, 1)->height()); 1639 lua_pushinteger(L, get_ref<SkImage>(L, 1)->height());
1563 return 1; 1640 return 1;
1564 } 1641 }
1565 1642
1643 static int limage_newShader(lua_State* L) {
1644 SkShader::TileMode tmode = SkShader::kClamp_TileMode;
1645 const SkMatrix* localM = NULL;
1646 SkAutoTUnref<SkShader> shader(get_ref<SkImage>(L, 1)->newShader(tmode, tmode , localM));
1647 push_ref(L, shader.get());
1648 return 1;
1649 }
1650
1566 static int limage_gc(lua_State* L) { 1651 static int limage_gc(lua_State* L) {
1567 get_ref<SkImage>(L, 1)->unref(); 1652 get_ref<SkImage>(L, 1)->unref();
1568 return 0; 1653 return 0;
1569 } 1654 }
1570 1655
1571 static const struct luaL_Reg gSkImage_Methods[] = { 1656 static const struct luaL_Reg gSkImage_Methods[] = {
1572 { "width", limage_width }, 1657 { "width", limage_width },
1573 { "height", limage_height }, 1658 { "height", limage_height },
1659 { "newShader", limage_newShader },
1574 { "__gc", limage_gc }, 1660 { "__gc", limage_gc },
1575 { NULL, NULL } 1661 { NULL, NULL }
1576 }; 1662 };
1577 1663
1578 /////////////////////////////////////////////////////////////////////////////// 1664 ///////////////////////////////////////////////////////////////////////////////
1579 1665
1580 static int lsurface_width(lua_State* L) { 1666 static int lsurface_width(lua_State* L) {
1581 lua_pushinteger(L, get_ref<SkSurface>(L, 1)->width()); 1667 lua_pushinteger(L, get_ref<SkSurface>(L, 1)->width());
1582 return 1; 1668 return 1;
1583 } 1669 }
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 REG_CLASS(L, SkSurface); 2068 REG_CLASS(L, SkSurface);
1983 REG_CLASS(L, SkTextBlob); 2069 REG_CLASS(L, SkTextBlob);
1984 REG_CLASS(L, SkTypeface); 2070 REG_CLASS(L, SkTypeface);
1985 } 2071 }
1986 2072
1987 extern "C" int luaopen_skia(lua_State* L); 2073 extern "C" int luaopen_skia(lua_State* L);
1988 extern "C" int luaopen_skia(lua_State* L) { 2074 extern "C" int luaopen_skia(lua_State* L) {
1989 SkLua::Load(L); 2075 SkLua::Load(L);
1990 return 0; 2076 return 0;
1991 } 2077 }
OLDNEW
« no previous file with comments | « samplecode/SampleLua.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698