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

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

Issue 642353005: add drawImageRect to lua, update sample (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 | « 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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 SkPaint paint; 453 SkPaint paint;
454 const SkPaint* paintPtr = NULL; 454 const SkPaint* paintPtr = NULL;
455 if (lua_isnumber(L, 5)) { 455 if (lua_isnumber(L, 5)) {
456 paint.setAlpha(SkScalarRoundToInt(lua2scalar(L, 5) * 255)); 456 paint.setAlpha(SkScalarRoundToInt(lua2scalar(L, 5) * 255));
457 paintPtr = &paint; 457 paintPtr = &paint;
458 } 458 }
459 canvas->drawImage(image, x, y, paintPtr); 459 canvas->drawImage(image, x, y, paintPtr);
460 return 0; 460 return 0;
461 } 461 }
462 462
463 static int lcanvas_drawImageRect(lua_State* L) {
464 SkCanvas* canvas = get_ref<SkCanvas>(L, 1);
465 SkImage* image = get_ref<SkImage>(L, 2);
466 if (NULL == image) {
467 return 0;
468 }
469
470 SkRect srcR, dstR;
471 SkRect* srcRPtr = NULL;
472 if (!lua_isnil(L, 3)) {
473 srcRPtr = lua2rect(L, 3, &srcR);
474 }
475 lua2rect(L, 4, &dstR);
476
477 SkPaint paint;
478 const SkPaint* paintPtr = NULL;
479 if (lua_isnumber(L, 5)) {
480 paint.setAlpha(SkScalarRoundToInt(lua2scalar(L, 5) * 255));
481 paintPtr = &paint;
482 }
483 canvas->drawImageRect(image, srcRPtr, dstR, paintPtr);
484 return 0;
485 }
486
463 static int lcanvas_drawPath(lua_State* L) { 487 static int lcanvas_drawPath(lua_State* L) {
464 get_ref<SkCanvas>(L, 1)->drawPath(*get_obj<SkPath>(L, 2), 488 get_ref<SkCanvas>(L, 1)->drawPath(*get_obj<SkPath>(L, 2),
465 *get_obj<SkPaint>(L, 3)); 489 *get_obj<SkPaint>(L, 3));
466 return 0; 490 return 0;
467 } 491 }
468 492
469 static int lcanvas_drawText(lua_State* L) { 493 static int lcanvas_drawText(lua_State* L) {
470 if (lua_gettop(L) < 5) { 494 if (lua_gettop(L) < 5) {
471 return 0; 495 return 0;
472 } 496 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 get_ref<SkCanvas>(L, 1)->unref(); 593 get_ref<SkCanvas>(L, 1)->unref();
570 return 0; 594 return 0;
571 } 595 }
572 596
573 const struct luaL_Reg gSkCanvas_Methods[] = { 597 const struct luaL_Reg gSkCanvas_Methods[] = {
574 { "drawColor", lcanvas_drawColor }, 598 { "drawColor", lcanvas_drawColor },
575 { "drawRect", lcanvas_drawRect }, 599 { "drawRect", lcanvas_drawRect },
576 { "drawOval", lcanvas_drawOval }, 600 { "drawOval", lcanvas_drawOval },
577 { "drawCircle", lcanvas_drawCircle }, 601 { "drawCircle", lcanvas_drawCircle },
578 { "drawImage", lcanvas_drawImage }, 602 { "drawImage", lcanvas_drawImage },
603 { "drawImageRect", lcanvas_drawImageRect },
579 { "drawPath", lcanvas_drawPath }, 604 { "drawPath", lcanvas_drawPath },
580 { "drawText", lcanvas_drawText }, 605 { "drawText", lcanvas_drawText },
581 { "getSaveCount", lcanvas_getSaveCount }, 606 { "getSaveCount", lcanvas_getSaveCount },
582 { "getTotalMatrix", lcanvas_getTotalMatrix }, 607 { "getTotalMatrix", lcanvas_getTotalMatrix },
583 { "getClipStack", lcanvas_getClipStack }, 608 { "getClipStack", lcanvas_getClipStack },
584 #if SK_SUPPORT_GPU 609 #if SK_SUPPORT_GPU
585 { "getReducedClipStack", SkLua::lcanvas_getReducedClipStack }, 610 { "getReducedClipStack", SkLua::lcanvas_getReducedClipStack },
586 #endif 611 #endif
587 { "save", lcanvas_save }, 612 { "save", lcanvas_save },
588 { "restore", lcanvas_restore }, 613 { "restore", lcanvas_restore },
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 REG_CLASS(L, SkShader); 1535 REG_CLASS(L, SkShader);
1511 REG_CLASS(L, SkTypeface); 1536 REG_CLASS(L, SkTypeface);
1512 REG_CLASS(L, SkMatrix); 1537 REG_CLASS(L, SkMatrix);
1513 } 1538 }
1514 1539
1515 extern "C" int luaopen_skia(lua_State* L); 1540 extern "C" int luaopen_skia(lua_State* L);
1516 extern "C" int luaopen_skia(lua_State* L) { 1541 extern "C" int luaopen_skia(lua_State* L) {
1517 SkLua::Load(L); 1542 SkLua::Load(L);
1518 return 0; 1543 return 0;
1519 } 1544 }
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