• Home
  • Raw
  • Download

Lines Matching +full:- +full:l

4  * Use of this source code is governed by a BSD-style license that can be
75 template <typename T, typename... Args> T* push_new(lua_State* L, Args&&... args) { in DEF_MTNAME()
76 T* addr = (T*)lua_newuserdata(L, sizeof(T)); in DEF_MTNAME()
78 luaL_getmetatable(L, get_mtname<T>()); in DEF_MTNAME()
79 lua_setmetatable(L, -2); in DEF_MTNAME()
83 template <typename T> void push_obj(lua_State* L, const T& obj) { in push_obj() argument
84 new (lua_newuserdata(L, sizeof(T))) T(obj); in push_obj()
85 luaL_getmetatable(L, get_mtname<T>()); in push_obj()
86 lua_setmetatable(L, -2); in push_obj()
89 template <typename T> T* push_ptr(lua_State* L, T* ptr) { in push_ptr() argument
90 *(T**)lua_newuserdata(L, sizeof(T*)) = ptr; in push_ptr()
91 luaL_getmetatable(L, get_mtname<T>()); in push_ptr()
92 lua_setmetatable(L, -2); in push_ptr()
96 template <typename T> T* push_ref(lua_State* L, T* ref) { in push_ref() argument
97 *(T**)lua_newuserdata(L, sizeof(T*)) = SkSafeRef(ref); in push_ref()
98 luaL_getmetatable(L, get_mtname<T>()); in push_ref()
99 lua_setmetatable(L, -2); in push_ref()
103 template <typename T> void push_ref(lua_State* L, sk_sp<T> sp) { in push_ref() argument
104 *(T**)lua_newuserdata(L, sizeof(T*)) = sp.release(); in push_ref()
105 luaL_getmetatable(L, get_mtname<T>()); in push_ref()
106 lua_setmetatable(L, -2); in push_ref()
109 template <typename T> T* get_ref(lua_State* L, int index) { in get_ref() argument
110 return *(T**)luaL_checkudata(L, index, get_mtname<T>()); in get_ref()
113 template <typename T> T* get_obj(lua_State* L, int index) { in get_obj() argument
114 return (T*)luaL_checkudata(L, index, get_mtname<T>()); in get_obj()
117 static bool lua2bool(lua_State* L, int index) { in lua2bool() argument
118 return !!lua_toboolean(L, index); in lua2bool()
129 SkLua::SkLua(lua_State* L) : fL(L), fWeOwnL(false) {} in SkLua() argument
136 SkDebugf("lua err: %s\n", lua_tostring(fL, -1)); in ~SkLua()
146 SkDebugf("--- lua failed: %s\n", lua_tostring(fL, -1)); in runCode()
154 return this->runCode(str.c_str()); in runCode()
159 #define CHECK_SETFIELD(key) do if (key) lua_setfield(fL, -2, key); while (0)
161 static void setfield_bool_if(lua_State* L, const char key[], bool pred) { in setfield_bool_if() argument
163 lua_pushboolean(L, true); in setfield_bool_if()
164 lua_setfield(L, -2, key); in setfield_bool_if()
168 static void setfield_string(lua_State* L, const char key[], const char value[]) { in setfield_string() argument
169 lua_pushstring(L, value); in setfield_string()
170 lua_setfield(L, -2, key); in setfield_string()
173 static void setfield_number(lua_State* L, const char key[], double value) { in setfield_number() argument
174 lua_pushnumber(L, value); in setfield_number()
175 lua_setfield(L, -2, key); in setfield_number()
178 static void setfield_boolean(lua_State* L, const char key[], bool value) { in setfield_boolean() argument
179 lua_pushboolean(L, value); in setfield_boolean()
180 lua_setfield(L, -2, key); in setfield_boolean()
183 static void setfield_scalar(lua_State* L, const char key[], SkScalar value) { in setfield_scalar() argument
184 setfield_number(L, key, SkScalarToLua(value)); in setfield_scalar()
187 static void setfield_function(lua_State* L, in setfield_function() argument
189 lua_pushcfunction(L, value); in setfield_function()
190 lua_setfield(L, -2, key); in setfield_function()
193 static int lua2int_def(lua_State* L, int index, int defaultValue) { in lua2int_def() argument
194 if (lua_isnumber(L, index)) { in lua2int_def()
195 return (int)lua_tonumber(L, index); in lua2int_def()
201 static SkScalar lua2scalar(lua_State* L, int index) { in lua2scalar() argument
202 SkASSERT(lua_isnumber(L, index)); in lua2scalar()
203 return SkLuaToScalar(lua_tonumber(L, index)); in lua2scalar()
206 static SkScalar lua2scalar_def(lua_State* L, int index, SkScalar defaultValue) { in lua2scalar_def() argument
207 if (lua_isnumber(L, index)) { in lua2scalar_def()
208 return SkLuaToScalar(lua_tonumber(L, index)); in lua2scalar_def()
214 static SkScalar getarray_scalar(lua_State* L, int stackIndex, int arrayIndex) { in getarray_scalar() argument
215 SkASSERT(lua_istable(L, stackIndex)); in getarray_scalar()
216 lua_rawgeti(L, stackIndex, arrayIndex); in getarray_scalar()
218 SkScalar value = lua2scalar(L, -1); in getarray_scalar()
219 lua_pop(L, 1); in getarray_scalar()
223 static void getarray_scalars(lua_State* L, int stackIndex, SkScalar dst[], int count) { in getarray_scalars() argument
225 dst[i] = getarray_scalar(L, stackIndex, i + 1); in getarray_scalars()
229 static void getarray_points(lua_State* L, int stackIndex, SkPoint pts[], int count) { in getarray_points() argument
230 getarray_scalars(L, stackIndex, &pts[0].fX, count * 2); in getarray_points()
233 static void setarray_number(lua_State* L, int index, double value) { in setarray_number() argument
234 lua_pushnumber(L, value); in setarray_number()
235 lua_rawseti(L, -2, index); in setarray_number()
238 static void setarray_scalar(lua_State* L, int index, SkScalar value) { in setarray_scalar() argument
239 setarray_number(L, index, SkScalarToLua(value)); in setarray_scalar()
242 static void setarray_string(lua_State* L, int index, const char str[]) { in setarray_string() argument
243 lua_pushstring(L, str); in setarray_string()
244 lua_rawseti(L, -2, index); in setarray_string()
291 // make it base-1 to match lua convention in pushArrayU16()
300 // make it base-1 to match lua convention in pushArrayPoint()
302 this->pushScalar(array[i].fX, "x"); in pushArrayPoint()
303 this->pushScalar(array[i].fY, "y"); in pushArrayPoint()
304 lua_rawseti(fL, -2, i + 1); in pushArrayPoint()
312 // make it base-1 to match lua convention in pushArrayScalar()
335 this->pushArrayScalar(info.fIntervals, info.fCount, "intervals"); in pushDash()
368 static SkScalar getfield_scalar(lua_State* L, int index, const char key[]) { in getfield_scalar() argument
369 SkASSERT(lua_istable(L, index)); in getfield_scalar()
370 lua_pushstring(L, key); in getfield_scalar()
371 lua_gettable(L, index); in getfield_scalar()
373 SkScalar value = lua2scalar(L, -1); in getfield_scalar()
374 lua_pop(L, 1); in getfield_scalar()
378 static SkScalar getfield_scalar_default(lua_State* L, int index, const char key[], SkScalar def) { in getfield_scalar_default() argument
379 SkASSERT(lua_istable(L, index)); in getfield_scalar_default()
380 lua_pushstring(L, key); in getfield_scalar_default()
381 lua_gettable(L, index); in getfield_scalar_default()
384 if (lua_isnil(L, -1)) { in getfield_scalar_default()
387 value = lua2scalar(L, -1); in getfield_scalar_default()
389 lua_pop(L, 1); in getfield_scalar_default()
407 static SkColor lua2color(lua_State* L, int index) { in lua2color() argument
408 return SkColorSetARGB(unit2byte(getfield_scalar_default(L, index, "a", 1)), in lua2color()
409 unit2byte(getfield_scalar_default(L, index, "r", 0)), in lua2color()
410 unit2byte(getfield_scalar_default(L, index, "g", 0)), in lua2color()
411 unit2byte(getfield_scalar_default(L, index, "b", 0))); in lua2color()
414 static SkRect* lua2rect(lua_State* L, int index, SkRect* rect) { in lua2rect() argument
415 rect->set(getfield_scalar_default(L, index, "left", 0), in lua2rect()
416 getfield_scalar_default(L, index, "top", 0), in lua2rect()
417 getfield_scalar(L, index, "right"), in lua2rect()
418 getfield_scalar(L, index, "bottom")); in lua2rect()
422 static int lcanvas_clear(lua_State* L) { in lcanvas_clear() argument
423 get_ref<SkCanvas>(L, 1)->clear(0); in lcanvas_clear()
427 static int lcanvas_drawColor(lua_State* L) { in lcanvas_drawColor() argument
428 get_ref<SkCanvas>(L, 1)->drawColor(lua2color(L, 2)); in lcanvas_drawColor()
432 static int lcanvas_drawPaint(lua_State* L) { in lcanvas_drawPaint() argument
433 get_ref<SkCanvas>(L, 1)->drawPaint(*get_obj<SkPaint>(L, 2)); in lcanvas_drawPaint()
437 static int lcanvas_drawRect(lua_State* L) { in lcanvas_drawRect() argument
439 lua2rect(L, 2, &rect); in lcanvas_drawRect()
440 const SkPaint* paint = get_obj<SkPaint>(L, 3); in lcanvas_drawRect()
441 get_ref<SkCanvas>(L, 1)->drawRect(rect, *paint); in lcanvas_drawRect()
445 static int lcanvas_drawOval(lua_State* L) { in lcanvas_drawOval() argument
447 get_ref<SkCanvas>(L, 1)->drawOval(*lua2rect(L, 2, &rect), in lcanvas_drawOval()
448 *get_obj<SkPaint>(L, 3)); in lcanvas_drawOval()
452 static int lcanvas_drawCircle(lua_State* L) { in lcanvas_drawCircle() argument
453 get_ref<SkCanvas>(L, 1)->drawCircle(lua2scalar(L, 2), in lcanvas_drawCircle()
454 lua2scalar(L, 3), in lcanvas_drawCircle()
455 lua2scalar(L, 4), in lcanvas_drawCircle()
456 *get_obj<SkPaint>(L, 5)); in lcanvas_drawCircle()
460 static SkPaint* lua2OptionalPaint(lua_State* L, int index, SkPaint* paint) { in lua2OptionalPaint() argument
461 if (lua_isnumber(L, index)) { in lua2OptionalPaint()
462 paint->setAlpha(SkScalarRoundToInt(lua2scalar(L, index) * 255)); in lua2OptionalPaint()
464 } else if (lua_isuserdata(L, index)) { in lua2OptionalPaint()
465 const SkPaint* ptr = get_obj<SkPaint>(L, index); in lua2OptionalPaint()
474 static int lcanvas_drawImage(lua_State* L) { in lcanvas_drawImage() argument
475 SkCanvas* canvas = get_ref<SkCanvas>(L, 1); in lcanvas_drawImage()
476 SkImage* image = get_ref<SkImage>(L, 2); in lcanvas_drawImage()
480 SkScalar x = lua2scalar(L, 3); in lcanvas_drawImage()
481 SkScalar y = lua2scalar(L, 4); in lcanvas_drawImage()
484 canvas->drawImage(image, x, y, lua2OptionalPaint(L, 5, &paint)); in lcanvas_drawImage()
488 static int lcanvas_drawImageRect(lua_State* L) { in lcanvas_drawImageRect() argument
489 SkCanvas* canvas = get_ref<SkCanvas>(L, 1); in lcanvas_drawImageRect()
490 SkImage* image = get_ref<SkImage>(L, 2); in lcanvas_drawImageRect()
497 if (!lua_isnil(L, 3)) { in lcanvas_drawImageRect()
498 srcRPtr = lua2rect(L, 3, &srcR); in lcanvas_drawImageRect()
500 lua2rect(L, 4, &dstR); in lcanvas_drawImageRect()
503 canvas->legacy_drawImageRect(image, srcRPtr, dstR, lua2OptionalPaint(L, 5, &paint)); in lcanvas_drawImageRect()
507 static int lcanvas_drawPatch(lua_State* L) { in lcanvas_drawPatch() argument
515 getarray_points(L, 2, cubics, 12); in lcanvas_drawPatch()
522 if (lua_isnil(L, 4)) { in lcanvas_drawPatch()
525 getarray_points(L, 4, texStorage, 4); in lcanvas_drawPatch()
529 get_ref<SkCanvas>(L, 1)->drawPatch(cubics, colors, texs, *get_obj<SkPaint>(L, 5)); in lcanvas_drawPatch()
533 static int lcanvas_drawPath(lua_State* L) { in lcanvas_drawPath() argument
534 get_ref<SkCanvas>(L, 1)->drawPath(*get_obj<SkPath>(L, 2), in lcanvas_drawPath()
535 *get_obj<SkPaint>(L, 3)); in lcanvas_drawPath()
540 static int lcanvas_drawPicture(lua_State* L) { in lcanvas_drawPicture() argument
541 SkCanvas* canvas = get_ref<SkCanvas>(L, 1); in lcanvas_drawPicture()
542 SkPicture* picture = get_ref<SkPicture>(L, 2); in lcanvas_drawPicture()
543 SkScalar x = lua2scalar_def(L, 3, 0); in lcanvas_drawPicture()
544 SkScalar y = lua2scalar_def(L, 4, 0); in lcanvas_drawPicture()
551 canvas->drawPicture(picture, matrixPtr, lua2OptionalPaint(L, 5, &paint)); in lcanvas_drawPicture()
555 static int lcanvas_drawText(lua_State* L) { in lcanvas_drawText() argument
556 if (lua_gettop(L) < 5) { in lcanvas_drawText()
562 if (lua_isstring(L, 2) && lua_isnumber(L, 3) && lua_isnumber(L, 4)) { in lcanvas_drawText()
564 const char* text = lua_tolstring(L, 2, &len); in lcanvas_drawText()
565 get_ref<SkCanvas>(L, 1)->drawSimpleText( in lcanvas_drawText()
567 lua2scalar(L, 3), lua2scalar(L, 4), in lcanvas_drawText()
568 SkFont::LEGACY_ExtractFromPaint(*get_obj<SkPaint>(L, 5)), in lcanvas_drawText()
569 *get_obj<SkPaint>(L, 5)); in lcanvas_drawText()
575 static int lcanvas_drawTextBlob(lua_State* L) { in lcanvas_drawTextBlob() argument
576 const SkTextBlob* blob = get_ref<SkTextBlob>(L, 2); in lcanvas_drawTextBlob()
577 SkScalar x = lua2scalar(L, 3); in lcanvas_drawTextBlob()
578 SkScalar y = lua2scalar(L, 4); in lcanvas_drawTextBlob()
579 const SkPaint& paint = *get_obj<SkPaint>(L, 5); in lcanvas_drawTextBlob()
580 get_ref<SkCanvas>(L, 1)->drawTextBlob(blob, x, y, paint); in lcanvas_drawTextBlob()
584 static int lcanvas_getSaveCount(lua_State* L) { in lcanvas_getSaveCount() argument
585 lua_pushnumber(L, get_ref<SkCanvas>(L, 1)->getSaveCount()); in lcanvas_getSaveCount()
589 static int lcanvas_getTotalMatrix(lua_State* L) { in lcanvas_getTotalMatrix() argument
590 SkLua(L).pushMatrix(get_ref<SkCanvas>(L, 1)->getTotalMatrix()); in lcanvas_getTotalMatrix()
594 static int lcanvas_save(lua_State* L) { in lcanvas_save() argument
595 lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->save()); in lcanvas_save()
599 static int lcanvas_saveLayer(lua_State* L) { in lcanvas_saveLayer() argument
601 … lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->saveLayer(nullptr, lua2OptionalPaint(L, 2, &paint))); in lcanvas_saveLayer()
605 static int lcanvas_restore(lua_State* L) { in lcanvas_restore() argument
606 get_ref<SkCanvas>(L, 1)->restore(); in lcanvas_restore()
610 static int lcanvas_scale(lua_State* L) { in lcanvas_scale() argument
611 SkScalar sx = lua2scalar_def(L, 2, 1); in lcanvas_scale()
612 SkScalar sy = lua2scalar_def(L, 3, sx); in lcanvas_scale()
613 get_ref<SkCanvas>(L, 1)->scale(sx, sy); in lcanvas_scale()
617 static int lcanvas_translate(lua_State* L) { in lcanvas_translate() argument
618 SkScalar tx = lua2scalar_def(L, 2, 0); in lcanvas_translate()
619 SkScalar ty = lua2scalar_def(L, 3, 0); in lcanvas_translate()
620 get_ref<SkCanvas>(L, 1)->translate(tx, ty); in lcanvas_translate()
624 static int lcanvas_rotate(lua_State* L) { in lcanvas_rotate() argument
625 SkScalar degrees = lua2scalar_def(L, 2, 0); in lcanvas_rotate()
626 get_ref<SkCanvas>(L, 1)->rotate(degrees); in lcanvas_rotate()
630 static int lcanvas_concat(lua_State* L) { in lcanvas_concat() argument
631 get_ref<SkCanvas>(L, 1)->concat(*get_obj<SkMatrix>(L, 2)); in lcanvas_concat()
635 static int lcanvas_newSurface(lua_State* L) { in lcanvas_newSurface() argument
636 int width = lua2int_def(L, 2, 0); in lcanvas_newSurface()
637 int height = lua2int_def(L, 3, 0); in lcanvas_newSurface()
639 auto surface = get_ref<SkCanvas>(L, 1)->makeSurface(info); in lcanvas_newSurface()
641 lua_pushnil(L); in lcanvas_newSurface()
643 push_ref(L, surface); in lcanvas_newSurface()
648 static int lcanvas_gc(lua_State* L) { in lcanvas_gc() argument
685 static int ldocument_beginPage(lua_State* L) { in ldocument_beginPage() argument
687 push_ptr(L, get_obj<DocHolder>(L, 1)->fDoc->beginPage(lua2scalar(L, 2), in ldocument_beginPage()
688 lua2scalar(L, 3), in ldocument_beginPage()
693 static int ldocument_endPage(lua_State* L) { in ldocument_endPage() argument
694 get_obj<DocHolder>(L, 1)->fDoc->endPage(); in ldocument_endPage()
698 static int ldocument_close(lua_State* L) { in ldocument_close() argument
699 get_obj<DocHolder>(L, 1)->fDoc->close(); in ldocument_close()
703 static int ldocument_gc(lua_State* L) { in ldocument_gc() argument
704 get_obj<DocHolder>(L, 1)->~DocHolder(); in ldocument_gc()
718 static int lpaint_isAntiAlias(lua_State* L) { in lpaint_isAntiAlias() argument
719 lua_pushboolean(L, get_obj<SkPaint>(L, 1)->isAntiAlias()); in lpaint_isAntiAlias()
723 static int lpaint_setAntiAlias(lua_State* L) { in lpaint_setAntiAlias() argument
724 get_obj<SkPaint>(L, 1)->setAntiAlias(lua2bool(L, 2)); in lpaint_setAntiAlias()
728 static int lpaint_isDither(lua_State* L) { in lpaint_isDither() argument
729 lua_pushboolean(L, get_obj<SkPaint>(L, 1)->isDither()); in lpaint_isDither()
733 static int lpaint_setDither(lua_State* L) { in lpaint_setDither() argument
734 get_obj<SkPaint>(L, 1)->setDither(lua2bool(L, 2)); in lpaint_setDither()
738 static int lpaint_getAlpha(lua_State* L) { in lpaint_getAlpha() argument
739 SkLua(L).pushScalar(byte2unit(get_obj<SkPaint>(L, 1)->getAlpha())); in lpaint_getAlpha()
743 static int lpaint_setAlpha(lua_State* L) { in lpaint_setAlpha() argument
744 get_obj<SkPaint>(L, 1)->setAlpha(unit2byte(lua2scalar(L, 2))); in lpaint_setAlpha()
748 static int lpaint_getColor(lua_State* L) { in lpaint_getColor() argument
749 SkLua(L).pushColor(get_obj<SkPaint>(L, 1)->getColor()); in lpaint_getColor()
753 static int lpaint_setColor(lua_State* L) { in lpaint_setColor() argument
754 get_obj<SkPaint>(L, 1)->setColor(lua2color(L, 2)); in lpaint_setColor()
758 static int lpaint_getFilterQuality(lua_State* L) { in lpaint_getFilterQuality() argument
759 SkLua(L).pushU32(get_obj<SkPaint>(L, 1)->getFilterQuality()); in lpaint_getFilterQuality()
763 static int lpaint_setFilterQuality(lua_State* L) { in lpaint_setFilterQuality() argument
764 int level = lua2int_def(L, 2, -1); in lpaint_setFilterQuality()
766 get_obj<SkPaint>(L, 1)->setFilterQuality((SkFilterQuality)level); in lpaint_setFilterQuality()
771 static int lpaint_getStroke(lua_State* L) { in lpaint_getStroke() argument
772 lua_pushboolean(L, SkPaint::kStroke_Style == get_obj<SkPaint>(L, 1)->getStyle()); in lpaint_getStroke()
776 static int lpaint_setStroke(lua_State* L) { in lpaint_setStroke() argument
779 if (lua_toboolean(L, 2)) { in lpaint_setStroke()
784 get_obj<SkPaint>(L, 1)->setStyle(style); in lpaint_setStroke()
788 static int lpaint_getStrokeCap(lua_State* L) { in lpaint_getStrokeCap() argument
789 SkLua(L).pushU32(get_obj<SkPaint>(L, 1)->getStrokeCap()); in lpaint_getStrokeCap()
793 static int lpaint_getStrokeJoin(lua_State* L) { in lpaint_getStrokeJoin() argument
794 SkLua(L).pushU32(get_obj<SkPaint>(L, 1)->getStrokeJoin()); in lpaint_getStrokeJoin()
798 static int lpaint_getStrokeWidth(lua_State* L) { in lpaint_getStrokeWidth() argument
799 SkLua(L).pushScalar(get_obj<SkPaint>(L, 1)->getStrokeWidth()); in lpaint_getStrokeWidth()
803 static int lpaint_setStrokeWidth(lua_State* L) { in lpaint_setStrokeWidth() argument
804 get_obj<SkPaint>(L, 1)->setStrokeWidth(lua2scalar(L, 2)); in lpaint_setStrokeWidth()
808 static int lpaint_getStrokeMiter(lua_State* L) { in lpaint_getStrokeMiter() argument
809 SkLua(L).pushScalar(get_obj<SkPaint>(L, 1)->getStrokeMiter()); in lpaint_getStrokeMiter()
813 static int lpaint_getEffects(lua_State* L) { in lpaint_getEffects() argument
814 const SkPaint* paint = get_obj<SkPaint>(L, 1); in lpaint_getEffects()
816 lua_newtable(L); in lpaint_getEffects()
817 setfield_bool_if(L, "looper", !!paint->getLooper()); in lpaint_getEffects()
818 setfield_bool_if(L, "pathEffect", !!paint->getPathEffect()); in lpaint_getEffects()
819 setfield_bool_if(L, "maskFilter", !!paint->getMaskFilter()); in lpaint_getEffects()
820 setfield_bool_if(L, "shader", !!paint->getShader()); in lpaint_getEffects()
821 setfield_bool_if(L, "colorFilter", !!paint->getColorFilter()); in lpaint_getEffects()
822 setfield_bool_if(L, "imageFilter", !!paint->getImageFilter()); in lpaint_getEffects()
826 static int lpaint_getColorFilter(lua_State* L) { in lpaint_getColorFilter() argument
827 const SkPaint* paint = get_obj<SkPaint>(L, 1); in lpaint_getColorFilter()
828 SkColorFilter* cf = paint->getColorFilter(); in lpaint_getColorFilter()
830 push_ref(L, cf); in lpaint_getColorFilter()
836 static int lpaint_setColorFilter(lua_State* L) { in lpaint_setColorFilter() argument
837 SkPaint* paint = get_obj<SkPaint>(L, 1); in lpaint_setColorFilter()
838 paint->setColorFilter(sk_ref_sp(get_ref<SkColorFilter>(L, 2))); in lpaint_setColorFilter()
842 static int lpaint_getImageFilter(lua_State* L) { in lpaint_getImageFilter() argument
843 const SkPaint* paint = get_obj<SkPaint>(L, 1); in lpaint_getImageFilter()
844 SkImageFilter* imf = paint->getImageFilter(); in lpaint_getImageFilter()
846 push_ref(L, imf); in lpaint_getImageFilter()
852 static int lpaint_setImageFilter(lua_State* L) { in lpaint_setImageFilter() argument
853 SkPaint* paint = get_obj<SkPaint>(L, 1); in lpaint_setImageFilter()
854 paint->setImageFilter(sk_ref_sp(get_ref<SkImageFilter>(L, 2))); in lpaint_setImageFilter()
858 static int lpaint_getShader(lua_State* L) { in lpaint_getShader() argument
859 const SkPaint* paint = get_obj<SkPaint>(L, 1); in lpaint_getShader()
860 SkShader* shader = paint->getShader(); in lpaint_getShader()
862 push_ref(L, shader); in lpaint_getShader()
868 static int lpaint_setShader(lua_State* L) { in lpaint_setShader() argument
869 SkPaint* paint = get_obj<SkPaint>(L, 1); in lpaint_setShader()
870 paint->setShader(sk_ref_sp(get_ref<SkShader>(L, 2))); in lpaint_setShader()
874 static int lpaint_getPathEffect(lua_State* L) { in lpaint_getPathEffect() argument
875 const SkPaint* paint = get_obj<SkPaint>(L, 1); in lpaint_getPathEffect()
876 SkPathEffect* pe = paint->getPathEffect(); in lpaint_getPathEffect()
878 push_ref(L, pe); in lpaint_getPathEffect()
884 static int lpaint_getFillPath(lua_State* L) { in lpaint_getFillPath() argument
885 const SkPaint* paint = get_obj<SkPaint>(L, 1); in lpaint_getFillPath()
886 const SkPath* path = get_obj<SkPath>(L, 2); in lpaint_getFillPath()
889 paint->getFillPath(*path, &fillpath); in lpaint_getFillPath()
891 SkLua lua(L); in lpaint_getFillPath()
897 static int lpaint_gc(lua_State* L) { in lpaint_gc() argument
898 get_obj<SkPaint>(L, 1)->~SkPaint(); in lpaint_gc()
935 static int lfont_getSize(lua_State* L) { in lfont_getSize() argument
936 SkLua(L).pushScalar(get_obj<SkFont>(L, 1)->getSize()); in lfont_getSize()
940 static int lfont_getScaleX(lua_State* L) { in lfont_getScaleX() argument
941 SkLua(L).pushScalar(get_obj<SkFont>(L, 1)->getScaleX()); in lfont_getScaleX()
945 static int lfont_getSkewX(lua_State* L) { in lfont_getSkewX() argument
946 SkLua(L).pushScalar(get_obj<SkFont>(L, 1)->getSkewX()); in lfont_getSkewX()
950 static int lfont_setSize(lua_State* L) { in lfont_setSize() argument
951 get_obj<SkFont>(L, 1)->setSize(lua2scalar(L, 2)); in lfont_setSize()
955 static int lfont_getTypeface(lua_State* L) { in lfont_getTypeface() argument
956 push_ref(L, get_obj<SkFont>(L, 1)->getTypefaceOrDefault()); in lfont_getTypeface()
960 static int lfont_setTypeface(lua_State* L) { in lfont_setTypeface() argument
961 get_obj<SkFont>(L, 1)->setTypeface(sk_ref_sp(get_ref<SkTypeface>(L, 2))); in lfont_setTypeface()
965 static int lfont_getHinting(lua_State* L) { in lfont_getHinting() argument
966 SkLua(L).pushU32((unsigned)get_obj<SkFont>(L, 1)->getHinting()); in lfont_getHinting()
970 static int lfont_getFontID(lua_State* L) { in lfont_getFontID() argument
971 SkTypeface* face = get_obj<SkFont>(L, 1)->getTypefaceOrDefault(); in lfont_getFontID()
972 SkLua(L).pushU32(SkTypeface::UniqueID(face)); in lfont_getFontID()
976 static int lfont_measureText(lua_State* L) { in lfont_measureText() argument
977 if (lua_isstring(L, 2)) { in lfont_measureText()
979 const char* text = lua_tolstring(L, 2, &len); in lfont_measureText()
980 SkLua(L).pushScalar(get_obj<SkFont>(L, 1)->measureText(text, len, kUTF8_SkTextEncoding)); in lfont_measureText()
986 static int lfont_getMetrics(lua_State* L) { in lfont_getMetrics() argument
988 SkScalar height = get_obj<SkFont>(L, 1)->getMetrics(&fm); in lfont_getMetrics()
990 lua_newtable(L); in lfont_getMetrics()
991 setfield_scalar(L, "top", fm.fTop); in lfont_getMetrics()
992 setfield_scalar(L, "ascent", fm.fAscent); in lfont_getMetrics()
993 setfield_scalar(L, "descent", fm.fDescent); in lfont_getMetrics()
994 setfield_scalar(L, "bottom", fm.fBottom); in lfont_getMetrics()
995 setfield_scalar(L, "leading", fm.fLeading); in lfont_getMetrics()
996 SkLua(L).pushScalar(height); in lfont_getMetrics()
1000 static int lfont_gc(lua_State* L) { in lfont_gc() argument
1001 get_obj<SkFont>(L, 1)->~SkFont(); in lfont_gc()
1036 static int lshader_isOpaque(lua_State* L) { in lshader_isOpaque() argument
1037 SkShader* shader = get_ref<SkShader>(L, 1); in lshader_isOpaque()
1038 return shader && shader->isOpaque(); in lshader_isOpaque()
1041 static int lshader_isAImage(lua_State* L) { in lshader_isAImage() argument
1042 SkShader* shader = get_ref<SkShader>(L, 1); in lshader_isAImage()
1046 if (SkImage* image = shader->isAImage(&matrix, modes)) { in lshader_isAImage()
1047 lua_newtable(L); in lshader_isAImage()
1048 setfield_number(L, "id", image->uniqueID()); in lshader_isAImage()
1049 setfield_number(L, "width", image->width()); in lshader_isAImage()
1050 setfield_number(L, "height", image->height()); in lshader_isAImage()
1051 setfield_string(L, "tileX", mode2string(modes[0])); in lshader_isAImage()
1052 setfield_string(L, "tileY", mode2string(modes[1])); in lshader_isAImage()
1059 static int lshader_asAGradient(lua_State* L) { in lshader_asAGradient() argument
1060 SkShader* shader = get_ref<SkShader>(L, 1); in lshader_asAGradient()
1065 SkShader::GradientType t = shader->asAGradient(&info); in lshader_asAGradient()
1070 shader->asAGradient(&info); in lshader_asAGradient()
1072 lua_newtable(L); in lshader_asAGradient()
1073 setfield_string(L, "type", gradtype2string(t)); in lshader_asAGradient()
1074 setfield_string(L, "tile", mode2string(info.fTileMode)); in lshader_asAGradient()
1075 setfield_number(L, "colorCount", info.fColorCount); in lshader_asAGradient()
1077 lua_newtable(L); in lshader_asAGradient()
1079 // Lua uses 1-based indexing in lshader_asAGradient()
1080 setarray_scalar(L, i+1, pos[i]); in lshader_asAGradient()
1082 lua_setfield(L, -2, "positions"); in lshader_asAGradient()
1090 static int lshader_gc(lua_State* L) { in lshader_gc() argument
1091 get_ref<SkShader>(L, 1)->unref(); in lshader_gc()
1105 static int lpatheffect_asADash(lua_State* L) { in lpatheffect_asADash() argument
1106 SkPathEffect* pe = get_ref<SkPathEffect>(L, 1); in lpatheffect_asADash()
1109 SkPathEffect::DashType dashType = pe->asADash(&info); in lpatheffect_asADash()
1113 pe->asADash(&info); in lpatheffect_asADash()
1114 SkLua(L).pushDash(info); in lpatheffect_asADash()
1121 static int lpatheffect_gc(lua_State* L) { in lpatheffect_gc() argument
1122 get_ref<SkPathEffect>(L, 1)->unref(); in lpatheffect_gc()
1134 static int lpcolorfilter_gc(lua_State* L) { in lpcolorfilter_gc() argument
1135 get_ref<SkColorFilter>(L, 1)->unref(); in lpcolorfilter_gc()
1146 static int lpimagefilter_gc(lua_State* L) { in lpimagefilter_gc() argument
1147 get_ref<SkImageFilter>(L, 1)->unref(); in lpimagefilter_gc()
1158 static int lmatrix_getType(lua_State* L) { in lmatrix_getType() argument
1159 SkMatrix::TypeMask mask = get_obj<SkMatrix>(L, 1)->getType(); in lmatrix_getType()
1161 lua_newtable(L); in lmatrix_getType()
1162 setfield_boolean(L, "translate", SkToBool(mask & SkMatrix::kTranslate_Mask)); in lmatrix_getType()
1163 setfield_boolean(L, "scale", SkToBool(mask & SkMatrix::kScale_Mask)); in lmatrix_getType()
1164 setfield_boolean(L, "affine", SkToBool(mask & SkMatrix::kAffine_Mask)); in lmatrix_getType()
1165 setfield_boolean(L, "perspective", SkToBool(mask & SkMatrix::kPerspective_Mask)); in lmatrix_getType()
1169 static int lmatrix_getScaleX(lua_State* L) { in lmatrix_getScaleX() argument
1170 lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getScaleX()); in lmatrix_getScaleX()
1174 static int lmatrix_getScaleY(lua_State* L) { in lmatrix_getScaleY() argument
1175 lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getScaleY()); in lmatrix_getScaleY()
1179 static int lmatrix_getTranslateX(lua_State* L) { in lmatrix_getTranslateX() argument
1180 lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getTranslateX()); in lmatrix_getTranslateX()
1184 static int lmatrix_getTranslateY(lua_State* L) { in lmatrix_getTranslateY() argument
1185 lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getTranslateY()); in lmatrix_getTranslateY()
1189 static int lmatrix_invert(lua_State* L) { in lmatrix_invert() argument
1190 lua_pushboolean(L, get_obj<SkMatrix>(L, 1)->invert(get_obj<SkMatrix>(L, 2))); in lmatrix_invert()
1194 static int lmatrix_mapXY(lua_State* L) { in lmatrix_mapXY() argument
1195 SkPoint pt = { lua2scalar(L, 2), lua2scalar(L, 3) }; in lmatrix_mapXY()
1196 get_obj<SkMatrix>(L, 1)->mapPoints(&pt, &pt, 1); in lmatrix_mapXY()
1197 lua_pushnumber(L, pt.x()); in lmatrix_mapXY()
1198 lua_pushnumber(L, pt.y()); in lmatrix_mapXY()
1202 static int lmatrix_setRectToRect(lua_State* L) { in lmatrix_setRectToRect() argument
1203 SkMatrix* matrix = get_obj<SkMatrix>(L, 1); in lmatrix_setRectToRect()
1205 lua2rect(L, 2, &srcR); in lmatrix_setRectToRect()
1206 lua2rect(L, 3, &dstR); in lmatrix_setRectToRect()
1207 const char* scaleToFitStr = lua_tostring(L, 4); in lmatrix_setRectToRect()
1229 matrix->setRectToRect(srcR, dstR, scaleToFit); in lmatrix_setRectToRect()
1247 static int lpath_getBounds(lua_State* L) { in lpath_getBounds() argument
1248 SkLua(L).pushRect(get_obj<SkPath>(L, 1)->getBounds()); in lpath_getBounds()
1255 return "even-odd"; in fill_type_to_str()
1259 return "inverse-even-odd"; in fill_type_to_str()
1261 return "inverse-winding"; in fill_type_to_str()
1266 static int lpath_getFillType(lua_State* L) { in lpath_getFillType() argument
1267 SkPath::FillType fill = get_obj<SkPath>(L, 1)->getFillType(); in lpath_getFillType()
1268 SkLua(L).pushString(fill_type_to_str(fill)); in lpath_getFillType()
1307 static int lpath_getSegmentTypes(lua_State* L) { in lpath_getSegmentTypes() argument
1308 uint32_t segMasks = get_obj<SkPath>(L, 1)->getSegmentMasks(); in lpath_getSegmentTypes()
1309 SkLua(L).pushString(segment_masks_to_str(segMasks)); in lpath_getSegmentTypes()
1313 static int lpath_isConvex(lua_State* L) { in lpath_isConvex() argument
1314 bool isConvex = SkPath::kConvex_Convexity == get_obj<SkPath>(L, 1)->getConvexity(); in lpath_isConvex()
1315 SkLua(L).pushBool(isConvex); in lpath_isConvex()
1319 static int lpath_isEmpty(lua_State* L) { in lpath_isEmpty() argument
1320 lua_pushboolean(L, get_obj<SkPath>(L, 1)->isEmpty()); in lpath_isEmpty()
1324 static int lpath_isRect(lua_State* L) { in lpath_isRect() argument
1326 bool pred = get_obj<SkPath>(L, 1)->isRect(&r); in lpath_isRect()
1328 lua_pushboolean(L, pred); in lpath_isRect()
1330 SkLua(L).pushRect(r); in lpath_isRect()
1344 static int lpath_isNestedFillRects(lua_State* L) { in lpath_isNestedFillRects() argument
1347 bool pred = get_obj<SkPath>(L, 1)->isNestedFillRects(rects, dirs); in lpath_isNestedFillRects()
1349 lua_pushboolean(L, pred); in lpath_isNestedFillRects()
1351 SkLua lua(L); in lpath_isNestedFillRects()
1354 lua_pushstring(L, dir2string(dirs[0])); in lpath_isNestedFillRects()
1355 lua_pushstring(L, dir2string(dirs[0])); in lpath_isNestedFillRects()
1361 static int lpath_countPoints(lua_State* L) { in lpath_countPoints() argument
1362 lua_pushinteger(L, get_obj<SkPath>(L, 1)->countPoints()); in lpath_countPoints()
1366 static int lpath_getVerbs(lua_State* L) { in lpath_getVerbs() argument
1367 const SkPath* path = get_obj<SkPath>(L, 1); in lpath_getVerbs()
1371 lua_newtable(L); in lpath_getVerbs()
1378 setarray_string(L, ++i, "move"); in lpath_getVerbs()
1381 setarray_string(L, ++i, "close"); in lpath_getVerbs()
1384 setarray_string(L, ++i, "line"); in lpath_getVerbs()
1387 setarray_string(L, ++i, "quad"); in lpath_getVerbs()
1390 setarray_string(L, ++i, "conic"); in lpath_getVerbs()
1393 setarray_string(L, ++i, "cubic"); in lpath_getVerbs()
1396 setarray_string(L, ++i, "done"); in lpath_getVerbs()
1405 static int lpath_reset(lua_State* L) { in lpath_reset() argument
1406 get_obj<SkPath>(L, 1)->reset(); in lpath_reset()
1410 static int lpath_moveTo(lua_State* L) { in lpath_moveTo() argument
1411 get_obj<SkPath>(L, 1)->moveTo(lua2scalar(L, 2), lua2scalar(L, 3)); in lpath_moveTo()
1415 static int lpath_lineTo(lua_State* L) { in lpath_lineTo() argument
1416 get_obj<SkPath>(L, 1)->lineTo(lua2scalar(L, 2), lua2scalar(L, 3)); in lpath_lineTo()
1420 static int lpath_quadTo(lua_State* L) { in lpath_quadTo() argument
1421 get_obj<SkPath>(L, 1)->quadTo(lua2scalar(L, 2), lua2scalar(L, 3), in lpath_quadTo()
1422 lua2scalar(L, 4), lua2scalar(L, 5)); in lpath_quadTo()
1426 static int lpath_cubicTo(lua_State* L) { in lpath_cubicTo() argument
1427 get_obj<SkPath>(L, 1)->cubicTo(lua2scalar(L, 2), lua2scalar(L, 3), in lpath_cubicTo()
1428 lua2scalar(L, 4), lua2scalar(L, 5), in lpath_cubicTo()
1429 lua2scalar(L, 6), lua2scalar(L, 7)); in lpath_cubicTo()
1433 static int lpath_close(lua_State* L) { in lpath_close() argument
1434 get_obj<SkPath>(L, 1)->close(); in lpath_close()
1438 static int lpath_gc(lua_State* L) { in lpath_gc() argument
1439 get_obj<SkPath>(L, 1)->~SkPath(); in lpath_gc()
1471 case SkRRect::kNinePatch_Type: return "nine-patch"; in rrect_type()
1478 static int lrrect_rect(lua_State* L) { in lrrect_rect() argument
1479 SkLua(L).pushRect(get_obj<SkRRect>(L, 1)->rect()); in lrrect_rect()
1483 static int lrrect_type(lua_State* L) { in lrrect_type() argument
1484 lua_pushstring(L, rrect_type(*get_obj<SkRRect>(L, 1))); in lrrect_type()
1488 static int lrrect_radii(lua_State* L) { in lrrect_radii() argument
1489 int corner = SkToInt(lua_tointeger(L, 2)); in lrrect_radii()
1495 v = get_obj<SkRRect>(L, 1)->radii((SkRRect::Corner)corner); in lrrect_radii()
1497 lua_pushnumber(L, v.fX); in lrrect_radii()
1498 lua_pushnumber(L, v.fY); in lrrect_radii()
1502 static int lrrect_gc(lua_State* L) { in lrrect_gc() argument
1503 get_obj<SkRRect>(L, 1)->~SkRRect(); in lrrect_gc()
1517 static int limage_width(lua_State* L) { in limage_width() argument
1518 lua_pushinteger(L, get_ref<SkImage>(L, 1)->width()); in limage_width()
1522 static int limage_height(lua_State* L) { in limage_height() argument
1523 lua_pushinteger(L, get_ref<SkImage>(L, 1)->height()); in limage_height()
1527 static int limage_newShader(lua_State* L) { in limage_newShader() argument
1530 push_ref(L, get_ref<SkImage>(L, 1)->makeShader(tmode, tmode, localM)); in limage_newShader()
1534 static int limage_gc(lua_State* L) { in limage_gc() argument
1535 get_ref<SkImage>(L, 1)->unref(); in limage_gc()
1549 static int lsurface_width(lua_State* L) { in lsurface_width() argument
1550 lua_pushinteger(L, get_ref<SkSurface>(L, 1)->width()); in lsurface_width()
1554 static int lsurface_height(lua_State* L) { in lsurface_height() argument
1555 lua_pushinteger(L, get_ref<SkSurface>(L, 1)->height()); in lsurface_height()
1559 static int lsurface_getCanvas(lua_State* L) { in lsurface_getCanvas() argument
1560 SkCanvas* canvas = get_ref<SkSurface>(L, 1)->getCanvas(); in lsurface_getCanvas()
1562 lua_pushnil(L); in lsurface_getCanvas()
1564 push_ptr(L, canvas); in lsurface_getCanvas()
1574 static int lsurface_newImageSnapshot(lua_State* L) { in lsurface_newImageSnapshot() argument
1575 sk_sp<SkImage> image = get_ref<SkSurface>(L, 1)->makeImageSnapshot(); in lsurface_newImageSnapshot()
1577 lua_pushnil(L); in lsurface_newImageSnapshot()
1579 push_ref(L, image); in lsurface_newImageSnapshot()
1584 static int lsurface_newSurface(lua_State* L) { in lsurface_newSurface() argument
1585 int width = lua2int_def(L, 2, 0); in lsurface_newSurface()
1586 int height = lua2int_def(L, 3, 0); in lsurface_newSurface()
1588 auto surface = get_ref<SkSurface>(L, 1)->makeSurface(info); in lsurface_newSurface()
1590 lua_pushnil(L); in lsurface_newSurface()
1592 push_ref(L, surface); in lsurface_newSurface()
1597 static int lsurface_gc(lua_State* L) { in lsurface_gc() argument
1598 get_ref<SkSurface>(L, 1)->unref(); in lsurface_gc()
1614 static int lpicturerecorder_beginRecording(lua_State* L) { in lpicturerecorder_beginRecording() argument
1615 const SkScalar w = lua2scalar_def(L, 2, -1); in lpicturerecorder_beginRecording()
1616 const SkScalar h = lua2scalar_def(L, 3, -1); in lpicturerecorder_beginRecording()
1618 lua_pushnil(L); in lpicturerecorder_beginRecording()
1622 SkCanvas* canvas = get_obj<SkPictureRecorder>(L, 1)->beginRecording(w, h); in lpicturerecorder_beginRecording()
1624 lua_pushnil(L); in lpicturerecorder_beginRecording()
1628 push_ptr(L, canvas); in lpicturerecorder_beginRecording()
1632 static int lpicturerecorder_getCanvas(lua_State* L) { in lpicturerecorder_getCanvas() argument
1633 SkCanvas* canvas = get_obj<SkPictureRecorder>(L, 1)->getRecordingCanvas(); in lpicturerecorder_getCanvas()
1635 lua_pushnil(L); in lpicturerecorder_getCanvas()
1638 push_ptr(L, canvas); in lpicturerecorder_getCanvas()
1642 static int lpicturerecorder_endRecording(lua_State* L) { in lpicturerecorder_endRecording() argument
1643 sk_sp<SkPicture> pic = get_obj<SkPictureRecorder>(L, 1)->finishRecordingAsPicture(); in lpicturerecorder_endRecording()
1645 lua_pushnil(L); in lpicturerecorder_endRecording()
1648 push_ref(L, std::move(pic)); in lpicturerecorder_endRecording()
1652 static int lpicturerecorder_gc(lua_State* L) { in lpicturerecorder_gc() argument
1653 get_obj<SkPictureRecorder>(L, 1)->~SkPictureRecorder(); in lpicturerecorder_gc()
1667 static int lpicture_width(lua_State* L) { in lpicture_width() argument
1668 lua_pushnumber(L, get_ref<SkPicture>(L, 1)->cullRect().width()); in lpicture_width()
1672 static int lpicture_height(lua_State* L) { in lpicture_height() argument
1673 lua_pushnumber(L, get_ref<SkPicture>(L, 1)->cullRect().height()); in lpicture_height()
1677 static int lpicture_gc(lua_State* L) { in lpicture_gc() argument
1678 get_ref<SkPicture>(L, 1)->unref(); in lpicture_gc()
1691 static int ltextblob_bounds(lua_State* L) { in ltextblob_bounds() argument
1692 SkLua(L).pushRect(get_ref<SkTextBlob>(L, 1)->bounds()); in ltextblob_bounds()
1696 static int ltextblob_gc(lua_State* L) { in ltextblob_gc() argument
1697 SkSafeUnref(get_ref<SkTextBlob>(L, 1)); in ltextblob_gc()
1709 static int ltypeface_getFamilyName(lua_State* L) { in ltypeface_getFamilyName() argument
1711 get_ref<SkTypeface>(L, 1)->getFamilyName(&str); in ltypeface_getFamilyName()
1712 lua_pushstring(L, str.c_str()); in ltypeface_getFamilyName()
1716 static int ltypeface_getStyle(lua_State* L) { in ltypeface_getStyle() argument
1717 push_obj(L, get_ref<SkTypeface>(L, 1)->fontStyle()); in ltypeface_getStyle()
1721 static int ltypeface_gc(lua_State* L) { in ltypeface_gc() argument
1722 SkSafeUnref(get_ref<SkTypeface>(L, 1)); in ltypeface_gc()
1735 static int lfontstyle_weight(lua_State* L) { in lfontstyle_weight() argument
1736 lua_pushnumber(L, get_ref<SkFontStyle>(L, 1)->weight()); in lfontstyle_weight()
1740 static int lfontstyle_width(lua_State* L) { in lfontstyle_width() argument
1741 lua_pushnumber(L, get_ref<SkFontStyle>(L, 1)->width()); in lfontstyle_width()
1745 static int lfontstyle_slant(lua_State* L) { in lfontstyle_slant() argument
1746 lua_pushnumber(L, get_ref<SkFontStyle>(L, 1)->slant()); in lfontstyle_slant()
1750 static int lfontstyle_gc(lua_State* L) { in lfontstyle_gc() argument
1751 get_obj<SkFontStyle>(L, 1)->~SkFontStyle(); in lfontstyle_gc()
1767 AutoCallLua(lua_State* L, const char func[], const char verb[]) : fL(L) { in AutoCallLua() argument
1768 lua_getglobal(L, func); in AutoCallLua()
1769 if (!lua_isfunction(L, -1)) { in AutoCallLua()
1770 int t = lua_type(L, -1); in AutoCallLua()
1771 SkDebugf("--- expected function %d\n", t); in AutoCallLua()
1774 lua_newtable(L); in AutoCallLua()
1775 setfield_string(L, "verb", verb); in AutoCallLua()
1780 SkDebugf("lua err: %s\n", lua_tostring(fL, -1)); in ~AutoCallLua()
1782 lua_settop(fL, -1); in ~AutoCallLua()
1793 static int lsk_newDocumentPDF(lua_State* L) { in lsk_newDocumentPDF() argument
1795 if (lua_gettop(L) > 0 && lua_isstring(L, 1)) { in lsk_newDocumentPDF()
1796 filename = lua_tolstring(L, 1, nullptr); in lsk_newDocumentPDF()
1802 if (!file->isValid()) { in lsk_newDocumentPDF()
1809 push_ptr(L, new DocHolder{std::move(doc), std::move(file)}); in lsk_newDocumentPDF()
1813 static int lsk_newBlurImageFilter(lua_State* L) { in lsk_newBlurImageFilter() argument
1814 SkScalar sigmaX = lua2scalar_def(L, 1, 0); in lsk_newBlurImageFilter()
1815 SkScalar sigmaY = lua2scalar_def(L, 2, 0); in lsk_newBlurImageFilter()
1818 lua_pushnil(L); in lsk_newBlurImageFilter()
1820 push_ref(L, std::move(imf)); in lsk_newBlurImageFilter()
1825 static int lsk_newLinearGradient(lua_State* L) { in lsk_newLinearGradient() argument
1826 SkScalar x0 = lua2scalar_def(L, 1, 0); in lsk_newLinearGradient()
1827 SkScalar y0 = lua2scalar_def(L, 2, 0); in lsk_newLinearGradient()
1828 SkColor c0 = lua2color(L, 3); in lsk_newLinearGradient()
1829 SkScalar x1 = lua2scalar_def(L, 4, 0); in lsk_newLinearGradient()
1830 SkScalar y1 = lua2scalar_def(L, 5, 0); in lsk_newLinearGradient()
1831 SkColor c1 = lua2color(L, 6); in lsk_newLinearGradient()
1838 lua_pushnil(L); in lsk_newLinearGradient()
1840 push_ref(L, std::move(s)); in lsk_newLinearGradient()
1845 static int lsk_newMatrix(lua_State* L) { in lsk_newMatrix() argument
1846 push_new<SkMatrix>(L)->reset(); in lsk_newMatrix()
1850 static int lsk_newPaint(lua_State* L) { in lsk_newPaint() argument
1851 push_new<SkPaint>(L); in lsk_newPaint()
1855 static int lsk_newPath(lua_State* L) { in lsk_newPath() argument
1856 push_new<SkPath>(L); in lsk_newPath()
1860 static int lsk_newPictureRecorder(lua_State* L) { in lsk_newPictureRecorder() argument
1861 push_new<SkPictureRecorder>(L); in lsk_newPictureRecorder()
1865 static int lsk_newRRect(lua_State* L) { in lsk_newRRect() argument
1866 push_new<SkRRect>(L)->setEmpty(); in lsk_newRRect()
1871 static int lsk_newTextBlob(lua_State* L) { in lsk_newTextBlob() argument
1872 const char* text = lua_tolstring(L, 1, nullptr); in lsk_newTextBlob()
1874 lua2rect(L, 2, &bounds); in lsk_newTextBlob()
1880 const SkPaint& paint = *get_obj<SkPaint>(L, 3); in lsk_newTextBlob()
1889 push_ref<SkTextBlob>(L, builder.makeBlob()); in lsk_newTextBlob()
1890 SkLua(L).pushScalar(end.fY); in lsk_newTextBlob()
1894 static int lsk_newTypeface(lua_State* L) { in lsk_newTypeface() argument
1898 int count = lua_gettop(L); in lsk_newTypeface()
1899 if (count > 0 && lua_isstring(L, 1)) { in lsk_newTypeface()
1900 name = lua_tolstring(L, 1, nullptr); in lsk_newTypeface()
1902 SkFontStyle* passedStyle = get_obj<SkFontStyle>(L, 2); in lsk_newTypeface()
1910 // SkDebugf("---- name <%s> style=%d, face=%p ref=%d\n", name, style, face, face->getRefCnt()); in lsk_newTypeface()
1914 push_ref(L, std::move(face)); in lsk_newTypeface()
1918 static int lsk_newFontStyle(lua_State* L) { in lsk_newFontStyle() argument
1919 int count = lua_gettop(L); in lsk_newFontStyle()
1923 if (count >= 1 && lua_isnumber(L, 1)) { in lsk_newFontStyle()
1924 weight = lua_tointegerx(L, 1, nullptr); in lsk_newFontStyle()
1926 if (count >= 2 && lua_isnumber(L, 2)) { in lsk_newFontStyle()
1927 width = lua_tointegerx(L, 2, nullptr); in lsk_newFontStyle()
1929 if (count >= 3 && lua_isnumber(L, 3)) { in lsk_newFontStyle()
1930 slant = static_cast<SkFontStyle::Slant>(lua_tointegerx(L, 3, nullptr)); in lsk_newFontStyle()
1932 push_new<SkFontStyle>(L, weight, width, slant); in lsk_newFontStyle()
1936 static int lsk_newRasterSurface(lua_State* L) { in lsk_newRasterSurface() argument
1937 int width = lua2int_def(L, 1, 0); in lsk_newRasterSurface()
1938 int height = lua2int_def(L, 2, 0); in lsk_newRasterSurface()
1943 lua_pushnil(L); in lsk_newRasterSurface()
1945 push_ref(L, surface); in lsk_newRasterSurface()
1950 static int lsk_loadImage(lua_State* L) { in lsk_loadImage() argument
1951 if (lua_gettop(L) > 0 && lua_isstring(L, 1)) { in lsk_loadImage()
1952 const char* name = lua_tolstring(L, 1, nullptr); in lsk_loadImage()
1957 push_ref(L, std::move(image)); in lsk_loadImage()
1965 static void register_Sk(lua_State* L) { in register_Sk() argument
1966 lua_newtable(L); in register_Sk()
1967 lua_pushvalue(L, -1); in register_Sk()
1968 lua_setglobal(L, "Sk"); in register_Sk()
1971 setfield_function(L, "newDocumentPDF", lsk_newDocumentPDF); in register_Sk()
1972 setfield_function(L, "loadImage", lsk_loadImage); in register_Sk()
1973 setfield_function(L, "newBlurImageFilter", lsk_newBlurImageFilter); in register_Sk()
1974 setfield_function(L, "newLinearGradient", lsk_newLinearGradient); in register_Sk()
1975 setfield_function(L, "newMatrix", lsk_newMatrix); in register_Sk()
1976 setfield_function(L, "newPaint", lsk_newPaint); in register_Sk()
1977 setfield_function(L, "newPath", lsk_newPath); in register_Sk()
1978 setfield_function(L, "newPictureRecorder", lsk_newPictureRecorder); in register_Sk()
1979 setfield_function(L, "newRRect", lsk_newRRect); in register_Sk()
1980 setfield_function(L, "newRasterSurface", lsk_newRasterSurface); in register_Sk()
1981 setfield_function(L, "newTextBlob", lsk_newTextBlob); in register_Sk()
1982 setfield_function(L, "newTypeface", lsk_newTypeface); in register_Sk()
1983 setfield_function(L, "newFontStyle", lsk_newFontStyle); in register_Sk()
1984 lua_pop(L, 1); // pop off the Sk table in register_Sk()
1987 #define REG_CLASS(L, C) \ argument
1989 luaL_newmetatable(L, get_mtname<C>()); \
1990 lua_pushvalue(L, -1); \
1991 lua_setfield(L, -2, "__index"); \
1992 luaL_setfuncs(L, g##C##_Methods, 0); \
1993 lua_pop(L, 1); /* pop off the meta-table */ \
1996 void SkLua::Load(lua_State* L) { in Load() argument
1997 register_Sk(L); in Load()
1998 REG_CLASS(L, SkCanvas); in Load()
1999 REG_CLASS(L, SkColorFilter); in Load()
2000 REG_CLASS(L, DocHolder); in Load()
2001 REG_CLASS(L, SkFont); in Load()
2002 REG_CLASS(L, SkImage); in Load()
2003 REG_CLASS(L, SkImageFilter); in Load()
2004 REG_CLASS(L, SkMatrix); in Load()
2005 REG_CLASS(L, SkPaint); in Load()
2006 REG_CLASS(L, SkPath); in Load()
2007 REG_CLASS(L, SkPathEffect); in Load()
2008 REG_CLASS(L, SkPicture); in Load()
2009 REG_CLASS(L, SkPictureRecorder); in Load()
2010 REG_CLASS(L, SkRRect); in Load()
2011 REG_CLASS(L, SkShader); in Load()
2012 REG_CLASS(L, SkSurface); in Load()
2013 REG_CLASS(L, SkTextBlob); in Load()
2014 REG_CLASS(L, SkTypeface); in Load()
2015 REG_CLASS(L, SkFontStyle); in Load()
2018 extern "C" int luaopen_skia(lua_State* L);
2019 extern "C" int luaopen_skia(lua_State* L) { in luaopen_skia() argument
2020 SkLua::Load(L); in luaopen_skia()