123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022 |
- /*
- * Copyright 2013 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
- #include "include/utils/SkLua.h"
- #if SK_SUPPORT_GPU
- //#include "src/gpu/GrReducedClip.h"
- #endif
- #include "include/core/SkCanvas.h"
- #include "include/core/SkColorFilter.h"
- #include "include/core/SkData.h"
- #include "include/core/SkFont.h"
- #include "include/core/SkFontMetrics.h"
- #include "include/core/SkFontStyle.h"
- #include "include/core/SkImage.h"
- #include "include/core/SkMatrix.h"
- #include "include/core/SkPaint.h"
- #include "include/core/SkPath.h"
- #include "include/core/SkPictureRecorder.h"
- #include "include/core/SkRRect.h"
- #include "include/core/SkString.h"
- #include "include/core/SkSurface.h"
- #include "include/core/SkTextBlob.h"
- #include "include/core/SkTypeface.h"
- #include "include/docs/SkPDFDocument.h"
- #include "include/effects/SkBlurImageFilter.h"
- #include "include/effects/SkGradientShader.h"
- #include "include/private/SkTo.h"
- #include "modules/skshaper/include/SkShaper.h"
- #include "src/core/SkMakeUnique.h"
- #include <new>
- extern "C" {
- #include "lua.h"
- #include "lualib.h"
- #include "lauxlib.h"
- }
- struct DocHolder {
- sk_sp<SkDocument> fDoc;
- std::unique_ptr<SkWStream> fStream;
- };
- // return the metatable name for a given class
- template <typename T> const char* get_mtname();
- #define DEF_MTNAME(T) \
- template <> const char* get_mtname<T>() { \
- return #T "_LuaMetaTableName"; \
- }
- DEF_MTNAME(SkCanvas)
- DEF_MTNAME(SkColorFilter)
- DEF_MTNAME(DocHolder)
- DEF_MTNAME(SkFont)
- DEF_MTNAME(SkImage)
- DEF_MTNAME(SkImageFilter)
- DEF_MTNAME(SkMatrix)
- DEF_MTNAME(SkRRect)
- DEF_MTNAME(SkPath)
- DEF_MTNAME(SkPaint)
- DEF_MTNAME(SkPathEffect)
- DEF_MTNAME(SkPicture)
- DEF_MTNAME(SkPictureRecorder)
- DEF_MTNAME(SkShader)
- DEF_MTNAME(SkSurface)
- DEF_MTNAME(SkTextBlob)
- DEF_MTNAME(SkTypeface)
- DEF_MTNAME(SkFontStyle)
- template <typename T, typename... Args> T* push_new(lua_State* L, Args&&... args) {
- T* addr = (T*)lua_newuserdata(L, sizeof(T));
- new (addr) T(std::forward<Args>(args)...);
- luaL_getmetatable(L, get_mtname<T>());
- lua_setmetatable(L, -2);
- return addr;
- }
- template <typename T> void push_obj(lua_State* L, const T& obj) {
- new (lua_newuserdata(L, sizeof(T))) T(obj);
- luaL_getmetatable(L, get_mtname<T>());
- lua_setmetatable(L, -2);
- }
- template <typename T> T* push_ptr(lua_State* L, T* ptr) {
- *(T**)lua_newuserdata(L, sizeof(T*)) = ptr;
- luaL_getmetatable(L, get_mtname<T>());
- lua_setmetatable(L, -2);
- return ptr;
- }
- template <typename T> T* push_ref(lua_State* L, T* ref) {
- *(T**)lua_newuserdata(L, sizeof(T*)) = SkSafeRef(ref);
- luaL_getmetatable(L, get_mtname<T>());
- lua_setmetatable(L, -2);
- return ref;
- }
- template <typename T> void push_ref(lua_State* L, sk_sp<T> sp) {
- *(T**)lua_newuserdata(L, sizeof(T*)) = sp.release();
- luaL_getmetatable(L, get_mtname<T>());
- lua_setmetatable(L, -2);
- }
- template <typename T> T* get_ref(lua_State* L, int index) {
- return *(T**)luaL_checkudata(L, index, get_mtname<T>());
- }
- template <typename T> T* get_obj(lua_State* L, int index) {
- return (T*)luaL_checkudata(L, index, get_mtname<T>());
- }
- static bool lua2bool(lua_State* L, int index) {
- return !!lua_toboolean(L, index);
- }
- ///////////////////////////////////////////////////////////////////////////////
- SkLua::SkLua(const char termCode[]) : fTermCode(termCode), fWeOwnL(true) {
- fL = luaL_newstate();
- luaL_openlibs(fL);
- SkLua::Load(fL);
- }
- SkLua::SkLua(lua_State* L) : fL(L), fWeOwnL(false) {}
- SkLua::~SkLua() {
- if (fWeOwnL) {
- if (fTermCode.size() > 0) {
- lua_getglobal(fL, fTermCode.c_str());
- if (lua_pcall(fL, 0, 0, 0) != LUA_OK) {
- SkDebugf("lua err: %s\n", lua_tostring(fL, -1));
- }
- }
- lua_close(fL);
- }
- }
- bool SkLua::runCode(const char code[]) {
- int err = luaL_loadstring(fL, code) || lua_pcall(fL, 0, 0, 0);
- if (err) {
- SkDebugf("--- lua failed: %s\n", lua_tostring(fL, -1));
- return false;
- }
- return true;
- }
- bool SkLua::runCode(const void* code, size_t size) {
- SkString str((const char*)code, size);
- return this->runCode(str.c_str());
- }
- ///////////////////////////////////////////////////////////////////////////////
- #define CHECK_SETFIELD(key) do if (key) lua_setfield(fL, -2, key); while (0)
- static void setfield_bool_if(lua_State* L, const char key[], bool pred) {
- if (pred) {
- lua_pushboolean(L, true);
- lua_setfield(L, -2, key);
- }
- }
- static void setfield_string(lua_State* L, const char key[], const char value[]) {
- lua_pushstring(L, value);
- lua_setfield(L, -2, key);
- }
- static void setfield_number(lua_State* L, const char key[], double value) {
- lua_pushnumber(L, value);
- lua_setfield(L, -2, key);
- }
- static void setfield_boolean(lua_State* L, const char key[], bool value) {
- lua_pushboolean(L, value);
- lua_setfield(L, -2, key);
- }
- static void setfield_scalar(lua_State* L, const char key[], SkScalar value) {
- setfield_number(L, key, SkScalarToLua(value));
- }
- static void setfield_function(lua_State* L,
- const char key[], lua_CFunction value) {
- lua_pushcfunction(L, value);
- lua_setfield(L, -2, key);
- }
- static int lua2int_def(lua_State* L, int index, int defaultValue) {
- if (lua_isnumber(L, index)) {
- return (int)lua_tonumber(L, index);
- } else {
- return defaultValue;
- }
- }
- static SkScalar lua2scalar(lua_State* L, int index) {
- SkASSERT(lua_isnumber(L, index));
- return SkLuaToScalar(lua_tonumber(L, index));
- }
- static SkScalar lua2scalar_def(lua_State* L, int index, SkScalar defaultValue) {
- if (lua_isnumber(L, index)) {
- return SkLuaToScalar(lua_tonumber(L, index));
- } else {
- return defaultValue;
- }
- }
- static SkScalar getarray_scalar(lua_State* L, int stackIndex, int arrayIndex) {
- SkASSERT(lua_istable(L, stackIndex));
- lua_rawgeti(L, stackIndex, arrayIndex);
- SkScalar value = lua2scalar(L, -1);
- lua_pop(L, 1);
- return value;
- }
- static void getarray_scalars(lua_State* L, int stackIndex, SkScalar dst[], int count) {
- for (int i = 0; i < count; ++i) {
- dst[i] = getarray_scalar(L, stackIndex, i + 1);
- }
- }
- static void getarray_points(lua_State* L, int stackIndex, SkPoint pts[], int count) {
- getarray_scalars(L, stackIndex, &pts[0].fX, count * 2);
- }
- static void setarray_number(lua_State* L, int index, double value) {
- lua_pushnumber(L, value);
- lua_rawseti(L, -2, index);
- }
- static void setarray_scalar(lua_State* L, int index, SkScalar value) {
- setarray_number(L, index, SkScalarToLua(value));
- }
- static void setarray_string(lua_State* L, int index, const char str[]) {
- lua_pushstring(L, str);
- lua_rawseti(L, -2, index);
- }
- void SkLua::pushBool(bool value, const char key[]) {
- lua_pushboolean(fL, value);
- CHECK_SETFIELD(key);
- }
- void SkLua::pushString(const char str[], const char key[]) {
- lua_pushstring(fL, str);
- CHECK_SETFIELD(key);
- }
- void SkLua::pushString(const char str[], size_t length, const char key[]) {
- // TODO: how to do this w/o making a copy?
- SkString s(str, length);
- lua_pushstring(fL, s.c_str());
- CHECK_SETFIELD(key);
- }
- void SkLua::pushString(const SkString& str, const char key[]) {
- lua_pushstring(fL, str.c_str());
- CHECK_SETFIELD(key);
- }
- void SkLua::pushColor(SkColor color, const char key[]) {
- lua_newtable(fL);
- setfield_number(fL, "a", SkColorGetA(color) / 255.0);
- setfield_number(fL, "r", SkColorGetR(color) / 255.0);
- setfield_number(fL, "g", SkColorGetG(color) / 255.0);
- setfield_number(fL, "b", SkColorGetB(color) / 255.0);
- CHECK_SETFIELD(key);
- }
- void SkLua::pushU32(uint32_t value, const char key[]) {
- lua_pushnumber(fL, (double)value);
- CHECK_SETFIELD(key);
- }
- void SkLua::pushScalar(SkScalar value, const char key[]) {
- lua_pushnumber(fL, SkScalarToLua(value));
- CHECK_SETFIELD(key);
- }
- void SkLua::pushArrayU16(const uint16_t array[], int count, const char key[]) {
- lua_newtable(fL);
- for (int i = 0; i < count; ++i) {
- // make it base-1 to match lua convention
- setarray_number(fL, i + 1, (double)array[i]);
- }
- CHECK_SETFIELD(key);
- }
- void SkLua::pushArrayPoint(const SkPoint array[], int count, const char key[]) {
- lua_newtable(fL);
- for (int i = 0; i < count; ++i) {
- // make it base-1 to match lua convention
- lua_newtable(fL);
- this->pushScalar(array[i].fX, "x");
- this->pushScalar(array[i].fY, "y");
- lua_rawseti(fL, -2, i + 1);
- }
- CHECK_SETFIELD(key);
- }
- void SkLua::pushArrayScalar(const SkScalar array[], int count, const char key[]) {
- lua_newtable(fL);
- for (int i = 0; i < count; ++i) {
- // make it base-1 to match lua convention
- setarray_scalar(fL, i + 1, array[i]);
- }
- CHECK_SETFIELD(key);
- }
- void SkLua::pushRect(const SkRect& r, const char key[]) {
- lua_newtable(fL);
- setfield_scalar(fL, "left", r.fLeft);
- setfield_scalar(fL, "top", r.fTop);
- setfield_scalar(fL, "right", r.fRight);
- setfield_scalar(fL, "bottom", r.fBottom);
- CHECK_SETFIELD(key);
- }
- void SkLua::pushRRect(const SkRRect& rr, const char key[]) {
- push_obj(fL, rr);
- CHECK_SETFIELD(key);
- }
- void SkLua::pushDash(const SkPathEffect::DashInfo& info, const char key[]) {
- lua_newtable(fL);
- setfield_scalar(fL, "phase", info.fPhase);
- this->pushArrayScalar(info.fIntervals, info.fCount, "intervals");
- CHECK_SETFIELD(key);
- }
- void SkLua::pushMatrix(const SkMatrix& matrix, const char key[]) {
- push_obj(fL, matrix);
- CHECK_SETFIELD(key);
- }
- void SkLua::pushPaint(const SkPaint& paint, const char key[]) {
- push_obj(fL, paint);
- CHECK_SETFIELD(key);
- }
- void SkLua::pushPath(const SkPath& path, const char key[]) {
- push_obj(fL, path);
- CHECK_SETFIELD(key);
- }
- void SkLua::pushCanvas(SkCanvas* canvas, const char key[]) {
- push_ptr(fL, canvas);
- CHECK_SETFIELD(key);
- }
- void SkLua::pushTextBlob(const SkTextBlob* blob, const char key[]) {
- push_ref(fL, const_cast<SkTextBlob*>(blob));
- CHECK_SETFIELD(key);
- }
- ///////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- static SkScalar getfield_scalar(lua_State* L, int index, const char key[]) {
- SkASSERT(lua_istable(L, index));
- lua_pushstring(L, key);
- lua_gettable(L, index);
- SkScalar value = lua2scalar(L, -1);
- lua_pop(L, 1);
- return value;
- }
- static SkScalar getfield_scalar_default(lua_State* L, int index, const char key[], SkScalar def) {
- SkASSERT(lua_istable(L, index));
- lua_pushstring(L, key);
- lua_gettable(L, index);
- SkScalar value;
- if (lua_isnil(L, -1)) {
- value = def;
- } else {
- value = lua2scalar(L, -1);
- }
- lua_pop(L, 1);
- return value;
- }
- static SkScalar byte2unit(U8CPU byte) {
- return byte / 255.0f;
- }
- static U8CPU unit2byte(SkScalar x) {
- if (x <= 0) {
- return 0;
- } else if (x >= 1) {
- return 255;
- } else {
- return SkScalarRoundToInt(x * 255);
- }
- }
- static SkColor lua2color(lua_State* L, int index) {
- return SkColorSetARGB(unit2byte(getfield_scalar_default(L, index, "a", 1)),
- unit2byte(getfield_scalar_default(L, index, "r", 0)),
- unit2byte(getfield_scalar_default(L, index, "g", 0)),
- unit2byte(getfield_scalar_default(L, index, "b", 0)));
- }
- static SkRect* lua2rect(lua_State* L, int index, SkRect* rect) {
- rect->set(getfield_scalar_default(L, index, "left", 0),
- getfield_scalar_default(L, index, "top", 0),
- getfield_scalar(L, index, "right"),
- getfield_scalar(L, index, "bottom"));
- return rect;
- }
- static int lcanvas_clear(lua_State* L) {
- get_ref<SkCanvas>(L, 1)->clear(0);
- return 0;
- }
- static int lcanvas_drawColor(lua_State* L) {
- get_ref<SkCanvas>(L, 1)->drawColor(lua2color(L, 2));
- return 0;
- }
- static int lcanvas_drawPaint(lua_State* L) {
- get_ref<SkCanvas>(L, 1)->drawPaint(*get_obj<SkPaint>(L, 2));
- return 0;
- }
- static int lcanvas_drawRect(lua_State* L) {
- SkRect rect;
- lua2rect(L, 2, &rect);
- const SkPaint* paint = get_obj<SkPaint>(L, 3);
- get_ref<SkCanvas>(L, 1)->drawRect(rect, *paint);
- return 0;
- }
- static int lcanvas_drawOval(lua_State* L) {
- SkRect rect;
- get_ref<SkCanvas>(L, 1)->drawOval(*lua2rect(L, 2, &rect),
- *get_obj<SkPaint>(L, 3));
- return 0;
- }
- static int lcanvas_drawCircle(lua_State* L) {
- get_ref<SkCanvas>(L, 1)->drawCircle(lua2scalar(L, 2),
- lua2scalar(L, 3),
- lua2scalar(L, 4),
- *get_obj<SkPaint>(L, 5));
- return 0;
- }
- static SkPaint* lua2OptionalPaint(lua_State* L, int index, SkPaint* paint) {
- if (lua_isnumber(L, index)) {
- paint->setAlpha(SkScalarRoundToInt(lua2scalar(L, index) * 255));
- return paint;
- } else if (lua_isuserdata(L, index)) {
- const SkPaint* ptr = get_obj<SkPaint>(L, index);
- if (ptr) {
- *paint = *ptr;
- return paint;
- }
- }
- return nullptr;
- }
- static int lcanvas_drawImage(lua_State* L) {
- SkCanvas* canvas = get_ref<SkCanvas>(L, 1);
- SkImage* image = get_ref<SkImage>(L, 2);
- if (nullptr == image) {
- return 0;
- }
- SkScalar x = lua2scalar(L, 3);
- SkScalar y = lua2scalar(L, 4);
- SkPaint paint;
- canvas->drawImage(image, x, y, lua2OptionalPaint(L, 5, &paint));
- return 0;
- }
- static int lcanvas_drawImageRect(lua_State* L) {
- SkCanvas* canvas = get_ref<SkCanvas>(L, 1);
- SkImage* image = get_ref<SkImage>(L, 2);
- if (nullptr == image) {
- return 0;
- }
- SkRect srcR, dstR;
- SkRect* srcRPtr = nullptr;
- if (!lua_isnil(L, 3)) {
- srcRPtr = lua2rect(L, 3, &srcR);
- }
- lua2rect(L, 4, &dstR);
- SkPaint paint;
- canvas->legacy_drawImageRect(image, srcRPtr, dstR, lua2OptionalPaint(L, 5, &paint));
- return 0;
- }
- static int lcanvas_drawPatch(lua_State* L) {
- SkPoint cubics[12];
- SkColor colorStorage[4];
- SkPoint texStorage[4];
- const SkColor* colors = nullptr;
- const SkPoint* texs = nullptr;
- getarray_points(L, 2, cubics, 12);
- colorStorage[0] = SK_ColorRED;
- colorStorage[1] = SK_ColorGREEN;
- colorStorage[2] = SK_ColorBLUE;
- colorStorage[3] = SK_ColorGRAY;
- if (lua_isnil(L, 4)) {
- colors = colorStorage;
- } else {
- getarray_points(L, 4, texStorage, 4);
- texs = texStorage;
- }
- get_ref<SkCanvas>(L, 1)->drawPatch(cubics, colors, texs, *get_obj<SkPaint>(L, 5));
- return 0;
- }
- static int lcanvas_drawPath(lua_State* L) {
- get_ref<SkCanvas>(L, 1)->drawPath(*get_obj<SkPath>(L, 2),
- *get_obj<SkPaint>(L, 3));
- return 0;
- }
- // drawPicture(pic, x, y, paint)
- static int lcanvas_drawPicture(lua_State* L) {
- SkCanvas* canvas = get_ref<SkCanvas>(L, 1);
- SkPicture* picture = get_ref<SkPicture>(L, 2);
- SkScalar x = lua2scalar_def(L, 3, 0);
- SkScalar y = lua2scalar_def(L, 4, 0);
- SkMatrix matrix, *matrixPtr = nullptr;
- if (x || y) {
- matrix.setTranslate(x, y);
- matrixPtr = &matrix;
- }
- SkPaint paint;
- canvas->drawPicture(picture, matrixPtr, lua2OptionalPaint(L, 5, &paint));
- return 0;
- }
- static int lcanvas_drawText(lua_State* L) {
- if (lua_gettop(L) < 5) {
- return 0;
- }
- // TODO: restore this logic based on SkFont instead of SkPaint
- #if 0
- if (lua_isstring(L, 2) && lua_isnumber(L, 3) && lua_isnumber(L, 4)) {
- size_t len;
- const char* text = lua_tolstring(L, 2, &len);
- get_ref<SkCanvas>(L, 1)->drawSimpleText(
- text, len, SkTextEncoding::kUTF8,
- lua2scalar(L, 3), lua2scalar(L, 4),
- SkFont::LEGACY_ExtractFromPaint(*get_obj<SkPaint>(L, 5)),
- *get_obj<SkPaint>(L, 5));
- }
- #endif
- return 0;
- }
- static int lcanvas_drawTextBlob(lua_State* L) {
- const SkTextBlob* blob = get_ref<SkTextBlob>(L, 2);
- SkScalar x = lua2scalar(L, 3);
- SkScalar y = lua2scalar(L, 4);
- const SkPaint& paint = *get_obj<SkPaint>(L, 5);
- get_ref<SkCanvas>(L, 1)->drawTextBlob(blob, x, y, paint);
- return 0;
- }
- static int lcanvas_getSaveCount(lua_State* L) {
- lua_pushnumber(L, get_ref<SkCanvas>(L, 1)->getSaveCount());
- return 1;
- }
- static int lcanvas_getTotalMatrix(lua_State* L) {
- SkLua(L).pushMatrix(get_ref<SkCanvas>(L, 1)->getTotalMatrix());
- return 1;
- }
- static int lcanvas_save(lua_State* L) {
- lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->save());
- return 1;
- }
- static int lcanvas_saveLayer(lua_State* L) {
- SkPaint paint;
- lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->saveLayer(nullptr, lua2OptionalPaint(L, 2, &paint)));
- return 1;
- }
- static int lcanvas_restore(lua_State* L) {
- get_ref<SkCanvas>(L, 1)->restore();
- return 0;
- }
- static int lcanvas_scale(lua_State* L) {
- SkScalar sx = lua2scalar_def(L, 2, 1);
- SkScalar sy = lua2scalar_def(L, 3, sx);
- get_ref<SkCanvas>(L, 1)->scale(sx, sy);
- return 0;
- }
- static int lcanvas_translate(lua_State* L) {
- SkScalar tx = lua2scalar_def(L, 2, 0);
- SkScalar ty = lua2scalar_def(L, 3, 0);
- get_ref<SkCanvas>(L, 1)->translate(tx, ty);
- return 0;
- }
- static int lcanvas_rotate(lua_State* L) {
- SkScalar degrees = lua2scalar_def(L, 2, 0);
- get_ref<SkCanvas>(L, 1)->rotate(degrees);
- return 0;
- }
- static int lcanvas_concat(lua_State* L) {
- get_ref<SkCanvas>(L, 1)->concat(*get_obj<SkMatrix>(L, 2));
- return 0;
- }
- static int lcanvas_newSurface(lua_State* L) {
- int width = lua2int_def(L, 2, 0);
- int height = lua2int_def(L, 3, 0);
- SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
- auto surface = get_ref<SkCanvas>(L, 1)->makeSurface(info);
- if (nullptr == surface) {
- lua_pushnil(L);
- } else {
- push_ref(L, surface);
- }
- return 1;
- }
- static int lcanvas_gc(lua_State* L) {
- // don't know how to track a ptr...
- return 0;
- }
- const struct luaL_Reg gSkCanvas_Methods[] = {
- { "clear", lcanvas_clear },
- { "drawColor", lcanvas_drawColor },
- { "drawPaint", lcanvas_drawPaint },
- { "drawRect", lcanvas_drawRect },
- { "drawOval", lcanvas_drawOval },
- { "drawCircle", lcanvas_drawCircle },
- { "drawImage", lcanvas_drawImage },
- { "drawImageRect", lcanvas_drawImageRect },
- { "drawPatch", lcanvas_drawPatch },
- { "drawPath", lcanvas_drawPath },
- { "drawPicture", lcanvas_drawPicture },
- { "drawText", lcanvas_drawText },
- { "drawTextBlob", lcanvas_drawTextBlob },
- { "getSaveCount", lcanvas_getSaveCount },
- { "getTotalMatrix", lcanvas_getTotalMatrix },
- { "save", lcanvas_save },
- { "saveLayer", lcanvas_saveLayer },
- { "restore", lcanvas_restore },
- { "scale", lcanvas_scale },
- { "translate", lcanvas_translate },
- { "rotate", lcanvas_rotate },
- { "concat", lcanvas_concat },
- { "newSurface", lcanvas_newSurface },
- { "__gc", lcanvas_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int ldocument_beginPage(lua_State* L) {
- const SkRect* contentPtr = nullptr;
- push_ptr(L, get_obj<DocHolder>(L, 1)->fDoc->beginPage(lua2scalar(L, 2),
- lua2scalar(L, 3),
- contentPtr));
- return 1;
- }
- static int ldocument_endPage(lua_State* L) {
- get_obj<DocHolder>(L, 1)->fDoc->endPage();
- return 0;
- }
- static int ldocument_close(lua_State* L) {
- get_obj<DocHolder>(L, 1)->fDoc->close();
- return 0;
- }
- static int ldocument_gc(lua_State* L) {
- get_obj<DocHolder>(L, 1)->~DocHolder();
- return 0;
- }
- static const struct luaL_Reg gDocHolder_Methods[] = {
- { "beginPage", ldocument_beginPage },
- { "endPage", ldocument_endPage },
- { "close", ldocument_close },
- { "__gc", ldocument_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int lpaint_isAntiAlias(lua_State* L) {
- lua_pushboolean(L, get_obj<SkPaint>(L, 1)->isAntiAlias());
- return 1;
- }
- static int lpaint_setAntiAlias(lua_State* L) {
- get_obj<SkPaint>(L, 1)->setAntiAlias(lua2bool(L, 2));
- return 0;
- }
- static int lpaint_isDither(lua_State* L) {
- lua_pushboolean(L, get_obj<SkPaint>(L, 1)->isDither());
- return 1;
- }
- static int lpaint_setDither(lua_State* L) {
- get_obj<SkPaint>(L, 1)->setDither(lua2bool(L, 2));
- return 0;
- }
- static int lpaint_getAlpha(lua_State* L) {
- SkLua(L).pushScalar(byte2unit(get_obj<SkPaint>(L, 1)->getAlpha()));
- return 1;
- }
- static int lpaint_setAlpha(lua_State* L) {
- get_obj<SkPaint>(L, 1)->setAlpha(unit2byte(lua2scalar(L, 2)));
- return 0;
- }
- static int lpaint_getColor(lua_State* L) {
- SkLua(L).pushColor(get_obj<SkPaint>(L, 1)->getColor());
- return 1;
- }
- static int lpaint_setColor(lua_State* L) {
- get_obj<SkPaint>(L, 1)->setColor(lua2color(L, 2));
- return 0;
- }
- static int lpaint_getFilterQuality(lua_State* L) {
- SkLua(L).pushU32(get_obj<SkPaint>(L, 1)->getFilterQuality());
- return 1;
- }
- static int lpaint_setFilterQuality(lua_State* L) {
- int level = lua2int_def(L, 2, -1);
- if (level >= 0 && level <= 3) {
- get_obj<SkPaint>(L, 1)->setFilterQuality((SkFilterQuality)level);
- }
- return 0;
- }
- static int lpaint_getStroke(lua_State* L) {
- lua_pushboolean(L, SkPaint::kStroke_Style == get_obj<SkPaint>(L, 1)->getStyle());
- return 1;
- }
- static int lpaint_setStroke(lua_State* L) {
- SkPaint::Style style;
- if (lua_toboolean(L, 2)) {
- style = SkPaint::kStroke_Style;
- } else {
- style = SkPaint::kFill_Style;
- }
- get_obj<SkPaint>(L, 1)->setStyle(style);
- return 0;
- }
- static int lpaint_getStrokeCap(lua_State* L) {
- SkLua(L).pushU32(get_obj<SkPaint>(L, 1)->getStrokeCap());
- return 1;
- }
- static int lpaint_getStrokeJoin(lua_State* L) {
- SkLua(L).pushU32(get_obj<SkPaint>(L, 1)->getStrokeJoin());
- return 1;
- }
- static int lpaint_getStrokeWidth(lua_State* L) {
- SkLua(L).pushScalar(get_obj<SkPaint>(L, 1)->getStrokeWidth());
- return 1;
- }
- static int lpaint_setStrokeWidth(lua_State* L) {
- get_obj<SkPaint>(L, 1)->setStrokeWidth(lua2scalar(L, 2));
- return 0;
- }
- static int lpaint_getStrokeMiter(lua_State* L) {
- SkLua(L).pushScalar(get_obj<SkPaint>(L, 1)->getStrokeMiter());
- return 1;
- }
- static int lpaint_getEffects(lua_State* L) {
- const SkPaint* paint = get_obj<SkPaint>(L, 1);
- lua_newtable(L);
- #ifdef SK_SUPPORT_LEGACY_DRAWLOOPER
- setfield_bool_if(L, "looper", !!paint->getLooper());
- #endif
- setfield_bool_if(L, "pathEffect", !!paint->getPathEffect());
- setfield_bool_if(L, "maskFilter", !!paint->getMaskFilter());
- setfield_bool_if(L, "shader", !!paint->getShader());
- setfield_bool_if(L, "colorFilter", !!paint->getColorFilter());
- setfield_bool_if(L, "imageFilter", !!paint->getImageFilter());
- return 1;
- }
- static int lpaint_getColorFilter(lua_State* L) {
- const SkPaint* paint = get_obj<SkPaint>(L, 1);
- SkColorFilter* cf = paint->getColorFilter();
- if (cf) {
- push_ref(L, cf);
- return 1;
- }
- return 0;
- }
- static int lpaint_setColorFilter(lua_State* L) {
- SkPaint* paint = get_obj<SkPaint>(L, 1);
- paint->setColorFilter(sk_ref_sp(get_ref<SkColorFilter>(L, 2)));
- return 0;
- }
- static int lpaint_getImageFilter(lua_State* L) {
- const SkPaint* paint = get_obj<SkPaint>(L, 1);
- SkImageFilter* imf = paint->getImageFilter();
- if (imf) {
- push_ref(L, imf);
- return 1;
- }
- return 0;
- }
- static int lpaint_setImageFilter(lua_State* L) {
- SkPaint* paint = get_obj<SkPaint>(L, 1);
- paint->setImageFilter(sk_ref_sp(get_ref<SkImageFilter>(L, 2)));
- return 0;
- }
- static int lpaint_getShader(lua_State* L) {
- const SkPaint* paint = get_obj<SkPaint>(L, 1);
- SkShader* shader = paint->getShader();
- if (shader) {
- push_ref(L, shader);
- return 1;
- }
- return 0;
- }
- static int lpaint_setShader(lua_State* L) {
- SkPaint* paint = get_obj<SkPaint>(L, 1);
- paint->setShader(sk_ref_sp(get_ref<SkShader>(L, 2)));
- return 0;
- }
- static int lpaint_getPathEffect(lua_State* L) {
- const SkPaint* paint = get_obj<SkPaint>(L, 1);
- SkPathEffect* pe = paint->getPathEffect();
- if (pe) {
- push_ref(L, pe);
- return 1;
- }
- return 0;
- }
- static int lpaint_getFillPath(lua_State* L) {
- const SkPaint* paint = get_obj<SkPaint>(L, 1);
- const SkPath* path = get_obj<SkPath>(L, 2);
- SkPath fillpath;
- paint->getFillPath(*path, &fillpath);
- SkLua lua(L);
- lua.pushPath(fillpath);
- return 1;
- }
- static int lpaint_gc(lua_State* L) {
- get_obj<SkPaint>(L, 1)->~SkPaint();
- return 0;
- }
- static const struct luaL_Reg gSkPaint_Methods[] = {
- { "isAntiAlias", lpaint_isAntiAlias },
- { "setAntiAlias", lpaint_setAntiAlias },
- { "isDither", lpaint_isDither },
- { "setDither", lpaint_setDither },
- { "getFilterQuality", lpaint_getFilterQuality },
- { "setFilterQuality", lpaint_setFilterQuality },
- { "getAlpha", lpaint_getAlpha },
- { "setAlpha", lpaint_setAlpha },
- { "getColor", lpaint_getColor },
- { "setColor", lpaint_setColor },
- { "getStroke", lpaint_getStroke },
- { "setStroke", lpaint_setStroke },
- { "getStrokeCap", lpaint_getStrokeCap },
- { "getStrokeJoin", lpaint_getStrokeJoin },
- { "getStrokeWidth", lpaint_getStrokeWidth },
- { "setStrokeWidth", lpaint_setStrokeWidth },
- { "getStrokeMiter", lpaint_getStrokeMiter },
- { "getEffects", lpaint_getEffects },
- { "getColorFilter", lpaint_getColorFilter },
- { "setColorFilter", lpaint_setColorFilter },
- { "getImageFilter", lpaint_getImageFilter },
- { "setImageFilter", lpaint_setImageFilter },
- { "getShader", lpaint_getShader },
- { "setShader", lpaint_setShader },
- { "getPathEffect", lpaint_getPathEffect },
- { "getFillPath", lpaint_getFillPath },
- { "__gc", lpaint_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int lfont_getSize(lua_State* L) {
- SkLua(L).pushScalar(get_obj<SkFont>(L, 1)->getSize());
- return 1;
- }
- static int lfont_getScaleX(lua_State* L) {
- SkLua(L).pushScalar(get_obj<SkFont>(L, 1)->getScaleX());
- return 1;
- }
- static int lfont_getSkewX(lua_State* L) {
- SkLua(L).pushScalar(get_obj<SkFont>(L, 1)->getSkewX());
- return 1;
- }
- static int lfont_setSize(lua_State* L) {
- get_obj<SkFont>(L, 1)->setSize(lua2scalar(L, 2));
- return 0;
- }
- static int lfont_getTypeface(lua_State* L) {
- push_ref(L, get_obj<SkFont>(L, 1)->getTypefaceOrDefault());
- return 1;
- }
- static int lfont_setTypeface(lua_State* L) {
- get_obj<SkFont>(L, 1)->setTypeface(sk_ref_sp(get_ref<SkTypeface>(L, 2)));
- return 0;
- }
- static int lfont_getHinting(lua_State* L) {
- SkLua(L).pushU32((unsigned)get_obj<SkFont>(L, 1)->getHinting());
- return 1;
- }
- static int lfont_getFontID(lua_State* L) {
- SkTypeface* face = get_obj<SkFont>(L, 1)->getTypefaceOrDefault();
- SkLua(L).pushU32(SkTypeface::UniqueID(face));
- return 1;
- }
- static int lfont_measureText(lua_State* L) {
- if (lua_isstring(L, 2)) {
- size_t len;
- const char* text = lua_tolstring(L, 2, &len);
- SkLua(L).pushScalar(get_obj<SkFont>(L, 1)->measureText(text, len, SkTextEncoding::kUTF8));
- return 1;
- }
- return 0;
- }
- static int lfont_getMetrics(lua_State* L) {
- SkFontMetrics fm;
- SkScalar height = get_obj<SkFont>(L, 1)->getMetrics(&fm);
- lua_newtable(L);
- setfield_scalar(L, "top", fm.fTop);
- setfield_scalar(L, "ascent", fm.fAscent);
- setfield_scalar(L, "descent", fm.fDescent);
- setfield_scalar(L, "bottom", fm.fBottom);
- setfield_scalar(L, "leading", fm.fLeading);
- SkLua(L).pushScalar(height);
- return 2;
- }
- static int lfont_gc(lua_State* L) {
- get_obj<SkFont>(L, 1)->~SkFont();
- return 0;
- }
- static const struct luaL_Reg gSkFont_Methods[] = {
- { "getSize", lfont_getSize },
- { "setSize", lfont_setSize },
- { "getScaleX", lfont_getScaleX },
- { "getSkewX", lfont_getSkewX },
- { "getTypeface", lfont_getTypeface },
- { "setTypeface", lfont_setTypeface },
- { "getHinting", lfont_getHinting },
- { "getFontID", lfont_getFontID },
- { "measureText", lfont_measureText },
- { "getMetrics", lfont_getMetrics },
- { "__gc", lfont_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static const char* mode2string(SkTileMode mode) {
- static const char* gNames[] = { "clamp", "repeat", "mirror", "decal" };
- SkASSERT((unsigned)mode < SK_ARRAY_COUNT(gNames));
- return gNames[static_cast<int>(mode)];
- }
- static const char* gradtype2string(SkShader::GradientType t) {
- static const char* gNames[] = {
- "none", "color", "linear", "radial", "radial2", "sweep", "conical"
- };
- SkASSERT((unsigned)t < SK_ARRAY_COUNT(gNames));
- return gNames[t];
- }
- static int lshader_isOpaque(lua_State* L) {
- SkShader* shader = get_ref<SkShader>(L, 1);
- return shader && shader->isOpaque();
- }
- static int lshader_isAImage(lua_State* L) {
- SkShader* shader = get_ref<SkShader>(L, 1);
- if (shader) {
- SkMatrix matrix;
- SkTileMode modes[2];
- if (SkImage* image = shader->isAImage(&matrix, modes)) {
- lua_newtable(L);
- setfield_number(L, "id", image->uniqueID());
- setfield_number(L, "width", image->width());
- setfield_number(L, "height", image->height());
- setfield_string(L, "tileX", mode2string(modes[0]));
- setfield_string(L, "tileY", mode2string(modes[1]));
- return 1;
- }
- }
- return 0;
- }
- static int lshader_asAGradient(lua_State* L) {
- SkShader* shader = get_ref<SkShader>(L, 1);
- if (shader) {
- SkShader::GradientInfo info;
- sk_bzero(&info, sizeof(info));
- SkShader::GradientType t = shader->asAGradient(&info);
- if (SkShader::kNone_GradientType != t) {
- SkAutoTArray<SkScalar> pos(info.fColorCount);
- info.fColorOffsets = pos.get();
- shader->asAGradient(&info);
- lua_newtable(L);
- setfield_string(L, "type", gradtype2string(t));
- setfield_string(L, "tile", mode2string((SkTileMode)info.fTileMode));
- setfield_number(L, "colorCount", info.fColorCount);
- lua_newtable(L);
- for (int i = 0; i < info.fColorCount; i++) {
- // Lua uses 1-based indexing
- setarray_scalar(L, i+1, pos[i]);
- }
- lua_setfield(L, -2, "positions");
- return 1;
- }
- }
- return 0;
- }
- static int lshader_gc(lua_State* L) {
- get_ref<SkShader>(L, 1)->unref();
- return 0;
- }
- static const struct luaL_Reg gSkShader_Methods[] = {
- { "isOpaque", lshader_isOpaque },
- { "isAImage", lshader_isAImage },
- { "asAGradient", lshader_asAGradient },
- { "__gc", lshader_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int lpatheffect_asADash(lua_State* L) {
- SkPathEffect* pe = get_ref<SkPathEffect>(L, 1);
- if (pe) {
- SkPathEffect::DashInfo info;
- SkPathEffect::DashType dashType = pe->asADash(&info);
- if (SkPathEffect::kDash_DashType == dashType) {
- SkAutoTArray<SkScalar> intervals(info.fCount);
- info.fIntervals = intervals.get();
- pe->asADash(&info);
- SkLua(L).pushDash(info);
- return 1;
- }
- }
- return 0;
- }
- static int lpatheffect_gc(lua_State* L) {
- get_ref<SkPathEffect>(L, 1)->unref();
- return 0;
- }
- static const struct luaL_Reg gSkPathEffect_Methods[] = {
- { "asADash", lpatheffect_asADash },
- { "__gc", lpatheffect_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int lpcolorfilter_gc(lua_State* L) {
- get_ref<SkColorFilter>(L, 1)->unref();
- return 0;
- }
- static const struct luaL_Reg gSkColorFilter_Methods[] = {
- { "__gc", lpcolorfilter_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int lpimagefilter_gc(lua_State* L) {
- get_ref<SkImageFilter>(L, 1)->unref();
- return 0;
- }
- static const struct luaL_Reg gSkImageFilter_Methods[] = {
- { "__gc", lpimagefilter_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int lmatrix_getType(lua_State* L) {
- SkMatrix::TypeMask mask = get_obj<SkMatrix>(L, 1)->getType();
- lua_newtable(L);
- setfield_boolean(L, "translate", SkToBool(mask & SkMatrix::kTranslate_Mask));
- setfield_boolean(L, "scale", SkToBool(mask & SkMatrix::kScale_Mask));
- setfield_boolean(L, "affine", SkToBool(mask & SkMatrix::kAffine_Mask));
- setfield_boolean(L, "perspective", SkToBool(mask & SkMatrix::kPerspective_Mask));
- return 1;
- }
- static int lmatrix_getScaleX(lua_State* L) {
- lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getScaleX());
- return 1;
- }
- static int lmatrix_getScaleY(lua_State* L) {
- lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getScaleY());
- return 1;
- }
- static int lmatrix_getTranslateX(lua_State* L) {
- lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getTranslateX());
- return 1;
- }
- static int lmatrix_getTranslateY(lua_State* L) {
- lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getTranslateY());
- return 1;
- }
- static int lmatrix_invert(lua_State* L) {
- lua_pushboolean(L, get_obj<SkMatrix>(L, 1)->invert(get_obj<SkMatrix>(L, 2)));
- return 1;
- }
- static int lmatrix_mapXY(lua_State* L) {
- SkPoint pt = { lua2scalar(L, 2), lua2scalar(L, 3) };
- get_obj<SkMatrix>(L, 1)->mapPoints(&pt, &pt, 1);
- lua_pushnumber(L, pt.x());
- lua_pushnumber(L, pt.y());
- return 2;
- }
- static int lmatrix_setRectToRect(lua_State* L) {
- SkMatrix* matrix = get_obj<SkMatrix>(L, 1);
- SkRect srcR, dstR;
- lua2rect(L, 2, &srcR);
- lua2rect(L, 3, &dstR);
- const char* scaleToFitStr = lua_tostring(L, 4);
- SkMatrix::ScaleToFit scaleToFit = SkMatrix::kFill_ScaleToFit;
- if (scaleToFitStr) {
- const struct {
- const char* fName;
- SkMatrix::ScaleToFit fScaleToFit;
- } rec[] = {
- { "fill", SkMatrix::kFill_ScaleToFit },
- { "start", SkMatrix::kStart_ScaleToFit },
- { "center", SkMatrix::kCenter_ScaleToFit },
- { "end", SkMatrix::kEnd_ScaleToFit },
- };
- for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
- if (strcmp(rec[i].fName, scaleToFitStr) == 0) {
- scaleToFit = rec[i].fScaleToFit;
- break;
- }
- }
- }
- matrix->setRectToRect(srcR, dstR, scaleToFit);
- return 0;
- }
- static const struct luaL_Reg gSkMatrix_Methods[] = {
- { "getType", lmatrix_getType },
- { "getScaleX", lmatrix_getScaleX },
- { "getScaleY", lmatrix_getScaleY },
- { "getTranslateX", lmatrix_getTranslateX },
- { "getTranslateY", lmatrix_getTranslateY },
- { "setRectToRect", lmatrix_setRectToRect },
- { "invert", lmatrix_invert },
- { "mapXY", lmatrix_mapXY },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int lpath_getBounds(lua_State* L) {
- SkLua(L).pushRect(get_obj<SkPath>(L, 1)->getBounds());
- return 1;
- }
- static const char* fill_type_to_str(SkPath::FillType fill) {
- switch (fill) {
- case SkPath::kEvenOdd_FillType:
- return "even-odd";
- case SkPath::kWinding_FillType:
- return "winding";
- case SkPath::kInverseEvenOdd_FillType:
- return "inverse-even-odd";
- case SkPath::kInverseWinding_FillType:
- return "inverse-winding";
- }
- return "unknown";
- }
- static int lpath_getFillType(lua_State* L) {
- SkPath::FillType fill = get_obj<SkPath>(L, 1)->getFillType();
- SkLua(L).pushString(fill_type_to_str(fill));
- return 1;
- }
- static SkString segment_masks_to_str(uint32_t segmentMasks) {
- SkString result;
- bool first = true;
- if (SkPath::kLine_SegmentMask & segmentMasks) {
- result.append("line");
- first = false;
- SkDEBUGCODE(segmentMasks &= ~SkPath::kLine_SegmentMask;)
- }
- if (SkPath::kQuad_SegmentMask & segmentMasks) {
- if (!first) {
- result.append(" ");
- }
- result.append("quad");
- first = false;
- SkDEBUGCODE(segmentMasks &= ~SkPath::kQuad_SegmentMask;)
- }
- if (SkPath::kConic_SegmentMask & segmentMasks) {
- if (!first) {
- result.append(" ");
- }
- result.append("conic");
- first = false;
- SkDEBUGCODE(segmentMasks &= ~SkPath::kConic_SegmentMask;)
- }
- if (SkPath::kCubic_SegmentMask & segmentMasks) {
- if (!first) {
- result.append(" ");
- }
- result.append("cubic");
- SkDEBUGCODE(segmentMasks &= ~SkPath::kCubic_SegmentMask;)
- }
- SkASSERT(0 == segmentMasks);
- return result;
- }
- static int lpath_getSegmentTypes(lua_State* L) {
- uint32_t segMasks = get_obj<SkPath>(L, 1)->getSegmentMasks();
- SkLua(L).pushString(segment_masks_to_str(segMasks));
- return 1;
- }
- static int lpath_isConvex(lua_State* L) {
- bool isConvex = SkPath::kConvex_Convexity == get_obj<SkPath>(L, 1)->getConvexity();
- SkLua(L).pushBool(isConvex);
- return 1;
- }
- static int lpath_isEmpty(lua_State* L) {
- lua_pushboolean(L, get_obj<SkPath>(L, 1)->isEmpty());
- return 1;
- }
- static int lpath_isRect(lua_State* L) {
- SkRect r;
- bool pred = get_obj<SkPath>(L, 1)->isRect(&r);
- int ret_count = 1;
- lua_pushboolean(L, pred);
- if (pred) {
- SkLua(L).pushRect(r);
- ret_count += 1;
- }
- return ret_count;
- }
- static const char* dir2string(SkPath::Direction dir) {
- static const char* gStr[] = {
- "unknown", "cw", "ccw"
- };
- SkASSERT((unsigned)dir < SK_ARRAY_COUNT(gStr));
- return gStr[dir];
- }
- static int lpath_isNestedFillRects(lua_State* L) {
- SkRect rects[2];
- SkPath::Direction dirs[2];
- bool pred = get_obj<SkPath>(L, 1)->isNestedFillRects(rects, dirs);
- int ret_count = 1;
- lua_pushboolean(L, pred);
- if (pred) {
- SkLua lua(L);
- lua.pushRect(rects[0]);
- lua.pushRect(rects[1]);
- lua_pushstring(L, dir2string(dirs[0]));
- lua_pushstring(L, dir2string(dirs[0]));
- ret_count += 4;
- }
- return ret_count;
- }
- static int lpath_countPoints(lua_State* L) {
- lua_pushinteger(L, get_obj<SkPath>(L, 1)->countPoints());
- return 1;
- }
- static int lpath_getVerbs(lua_State* L) {
- const SkPath* path = get_obj<SkPath>(L, 1);
- SkPath::Iter iter(*path, false);
- SkPoint pts[4];
- lua_newtable(L);
- bool done = false;
- int i = 0;
- do {
- switch (iter.next(pts, true)) {
- case SkPath::kMove_Verb:
- setarray_string(L, ++i, "move");
- break;
- case SkPath::kClose_Verb:
- setarray_string(L, ++i, "close");
- break;
- case SkPath::kLine_Verb:
- setarray_string(L, ++i, "line");
- break;
- case SkPath::kQuad_Verb:
- setarray_string(L, ++i, "quad");
- break;
- case SkPath::kConic_Verb:
- setarray_string(L, ++i, "conic");
- break;
- case SkPath::kCubic_Verb:
- setarray_string(L, ++i, "cubic");
- break;
- case SkPath::kDone_Verb:
- setarray_string(L, ++i, "done");
- done = true;
- break;
- }
- } while (!done);
- return 1;
- }
- static int lpath_reset(lua_State* L) {
- get_obj<SkPath>(L, 1)->reset();
- return 0;
- }
- static int lpath_moveTo(lua_State* L) {
- get_obj<SkPath>(L, 1)->moveTo(lua2scalar(L, 2), lua2scalar(L, 3));
- return 0;
- }
- static int lpath_lineTo(lua_State* L) {
- get_obj<SkPath>(L, 1)->lineTo(lua2scalar(L, 2), lua2scalar(L, 3));
- return 0;
- }
- static int lpath_quadTo(lua_State* L) {
- get_obj<SkPath>(L, 1)->quadTo(lua2scalar(L, 2), lua2scalar(L, 3),
- lua2scalar(L, 4), lua2scalar(L, 5));
- return 0;
- }
- static int lpath_cubicTo(lua_State* L) {
- get_obj<SkPath>(L, 1)->cubicTo(lua2scalar(L, 2), lua2scalar(L, 3),
- lua2scalar(L, 4), lua2scalar(L, 5),
- lua2scalar(L, 6), lua2scalar(L, 7));
- return 0;
- }
- static int lpath_close(lua_State* L) {
- get_obj<SkPath>(L, 1)->close();
- return 0;
- }
- static int lpath_gc(lua_State* L) {
- get_obj<SkPath>(L, 1)->~SkPath();
- return 0;
- }
- static const struct luaL_Reg gSkPath_Methods[] = {
- { "getBounds", lpath_getBounds },
- { "getFillType", lpath_getFillType },
- { "getSegmentTypes", lpath_getSegmentTypes },
- { "getVerbs", lpath_getVerbs },
- { "isConvex", lpath_isConvex },
- { "isEmpty", lpath_isEmpty },
- { "isRect", lpath_isRect },
- { "isNestedFillRects", lpath_isNestedFillRects },
- { "countPoints", lpath_countPoints },
- { "reset", lpath_reset },
- { "moveTo", lpath_moveTo },
- { "lineTo", lpath_lineTo },
- { "quadTo", lpath_quadTo },
- { "cubicTo", lpath_cubicTo },
- { "close", lpath_close },
- { "__gc", lpath_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static const char* rrect_type(const SkRRect& rr) {
- switch (rr.getType()) {
- case SkRRect::kEmpty_Type: return "empty";
- case SkRRect::kRect_Type: return "rect";
- case SkRRect::kOval_Type: return "oval";
- case SkRRect::kSimple_Type: return "simple";
- case SkRRect::kNinePatch_Type: return "nine-patch";
- case SkRRect::kComplex_Type: return "complex";
- }
- SkDEBUGFAIL("never get here");
- return "";
- }
- static int lrrect_rect(lua_State* L) {
- SkLua(L).pushRect(get_obj<SkRRect>(L, 1)->rect());
- return 1;
- }
- static int lrrect_type(lua_State* L) {
- lua_pushstring(L, rrect_type(*get_obj<SkRRect>(L, 1)));
- return 1;
- }
- static int lrrect_radii(lua_State* L) {
- int corner = SkToInt(lua_tointeger(L, 2));
- SkVector v;
- if (corner < 0 || corner > 3) {
- SkDebugf("bad corner index %d", corner);
- v.set(0, 0);
- } else {
- v = get_obj<SkRRect>(L, 1)->radii((SkRRect::Corner)corner);
- }
- lua_pushnumber(L, v.fX);
- lua_pushnumber(L, v.fY);
- return 2;
- }
- static int lrrect_gc(lua_State* L) {
- get_obj<SkRRect>(L, 1)->~SkRRect();
- return 0;
- }
- static const struct luaL_Reg gSkRRect_Methods[] = {
- { "rect", lrrect_rect },
- { "type", lrrect_type },
- { "radii", lrrect_radii },
- { "__gc", lrrect_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int limage_width(lua_State* L) {
- lua_pushinteger(L, get_ref<SkImage>(L, 1)->width());
- return 1;
- }
- static int limage_height(lua_State* L) {
- lua_pushinteger(L, get_ref<SkImage>(L, 1)->height());
- return 1;
- }
- static int limage_newShader(lua_State* L) {
- SkTileMode tmode = SkTileMode::kClamp;
- const SkMatrix* localM = nullptr;
- push_ref(L, get_ref<SkImage>(L, 1)->makeShader(tmode, tmode, localM));
- return 1;
- }
- static int limage_gc(lua_State* L) {
- get_ref<SkImage>(L, 1)->unref();
- return 0;
- }
- static const struct luaL_Reg gSkImage_Methods[] = {
- { "width", limage_width },
- { "height", limage_height },
- { "newShader", limage_newShader },
- { "__gc", limage_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int lsurface_width(lua_State* L) {
- lua_pushinteger(L, get_ref<SkSurface>(L, 1)->width());
- return 1;
- }
- static int lsurface_height(lua_State* L) {
- lua_pushinteger(L, get_ref<SkSurface>(L, 1)->height());
- return 1;
- }
- static int lsurface_getCanvas(lua_State* L) {
- SkCanvas* canvas = get_ref<SkSurface>(L, 1)->getCanvas();
- if (nullptr == canvas) {
- lua_pushnil(L);
- } else {
- push_ptr(L, canvas);
- // note: we don't unref canvas, since getCanvas did not ref it.
- // warning: this is weird: now Lua owns a ref on this canvas, but what if they let
- // the real owner (the surface) go away, but still hold onto the canvas?
- // *really* we want to sort of ref the surface again, but have the native object
- // know that it is supposed to be treated as a canvas...
- }
- return 1;
- }
- static int lsurface_newImageSnapshot(lua_State* L) {
- sk_sp<SkImage> image = get_ref<SkSurface>(L, 1)->makeImageSnapshot();
- if (!image) {
- lua_pushnil(L);
- } else {
- push_ref(L, image);
- }
- return 1;
- }
- static int lsurface_newSurface(lua_State* L) {
- int width = lua2int_def(L, 2, 0);
- int height = lua2int_def(L, 3, 0);
- SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
- auto surface = get_ref<SkSurface>(L, 1)->makeSurface(info);
- if (nullptr == surface) {
- lua_pushnil(L);
- } else {
- push_ref(L, surface);
- }
- return 1;
- }
- static int lsurface_gc(lua_State* L) {
- get_ref<SkSurface>(L, 1)->unref();
- return 0;
- }
- static const struct luaL_Reg gSkSurface_Methods[] = {
- { "width", lsurface_width },
- { "height", lsurface_height },
- { "getCanvas", lsurface_getCanvas },
- { "newImageSnapshot", lsurface_newImageSnapshot },
- { "newSurface", lsurface_newSurface },
- { "__gc", lsurface_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int lpicturerecorder_beginRecording(lua_State* L) {
- const SkScalar w = lua2scalar_def(L, 2, -1);
- const SkScalar h = lua2scalar_def(L, 3, -1);
- if (w <= 0 || h <= 0) {
- lua_pushnil(L);
- return 1;
- }
- SkCanvas* canvas = get_obj<SkPictureRecorder>(L, 1)->beginRecording(w, h);
- if (nullptr == canvas) {
- lua_pushnil(L);
- return 1;
- }
- push_ptr(L, canvas);
- return 1;
- }
- static int lpicturerecorder_getCanvas(lua_State* L) {
- SkCanvas* canvas = get_obj<SkPictureRecorder>(L, 1)->getRecordingCanvas();
- if (nullptr == canvas) {
- lua_pushnil(L);
- return 1;
- }
- push_ptr(L, canvas);
- return 1;
- }
- static int lpicturerecorder_endRecording(lua_State* L) {
- sk_sp<SkPicture> pic = get_obj<SkPictureRecorder>(L, 1)->finishRecordingAsPicture();
- if (!pic) {
- lua_pushnil(L);
- return 1;
- }
- push_ref(L, std::move(pic));
- return 1;
- }
- static int lpicturerecorder_gc(lua_State* L) {
- get_obj<SkPictureRecorder>(L, 1)->~SkPictureRecorder();
- return 0;
- }
- static const struct luaL_Reg gSkPictureRecorder_Methods[] = {
- { "beginRecording", lpicturerecorder_beginRecording },
- { "getCanvas", lpicturerecorder_getCanvas },
- { "endRecording", lpicturerecorder_endRecording },
- { "__gc", lpicturerecorder_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int lpicture_width(lua_State* L) {
- lua_pushnumber(L, get_ref<SkPicture>(L, 1)->cullRect().width());
- return 1;
- }
- static int lpicture_height(lua_State* L) {
- lua_pushnumber(L, get_ref<SkPicture>(L, 1)->cullRect().height());
- return 1;
- }
- static int lpicture_gc(lua_State* L) {
- get_ref<SkPicture>(L, 1)->unref();
- return 0;
- }
- static const struct luaL_Reg gSkPicture_Methods[] = {
- { "width", lpicture_width },
- { "height", lpicture_height },
- { "__gc", lpicture_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int ltextblob_bounds(lua_State* L) {
- SkLua(L).pushRect(get_ref<SkTextBlob>(L, 1)->bounds());
- return 1;
- }
- static int ltextblob_gc(lua_State* L) {
- SkSafeUnref(get_ref<SkTextBlob>(L, 1));
- return 0;
- }
- static const struct luaL_Reg gSkTextBlob_Methods[] = {
- { "bounds", ltextblob_bounds },
- { "__gc", ltextblob_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int ltypeface_getFamilyName(lua_State* L) {
- SkString str;
- get_ref<SkTypeface>(L, 1)->getFamilyName(&str);
- lua_pushstring(L, str.c_str());
- return 1;
- }
- static int ltypeface_getStyle(lua_State* L) {
- push_obj(L, get_ref<SkTypeface>(L, 1)->fontStyle());
- return 1;
- }
- static int ltypeface_gc(lua_State* L) {
- SkSafeUnref(get_ref<SkTypeface>(L, 1));
- return 0;
- }
- static const struct luaL_Reg gSkTypeface_Methods[] = {
- { "getFamilyName", ltypeface_getFamilyName },
- { "getStyle", ltypeface_getStyle },
- { "__gc", ltypeface_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- static int lfontstyle_weight(lua_State* L) {
- lua_pushnumber(L, get_ref<SkFontStyle>(L, 1)->weight());
- return 1;
- }
- static int lfontstyle_width(lua_State* L) {
- lua_pushnumber(L, get_ref<SkFontStyle>(L, 1)->width());
- return 1;
- }
- static int lfontstyle_slant(lua_State* L) {
- lua_pushnumber(L, get_ref<SkFontStyle>(L, 1)->slant());
- return 1;
- }
- static int lfontstyle_gc(lua_State* L) {
- get_obj<SkFontStyle>(L, 1)->~SkFontStyle();
- return 0;
- }
- static const struct luaL_Reg gSkFontStyle_Methods[] = {
- { "weight", lfontstyle_weight },
- { "width", lfontstyle_width },
- { "slant", lfontstyle_slant },
- { "__gc", lfontstyle_gc },
- { nullptr, nullptr }
- };
- ///////////////////////////////////////////////////////////////////////////////
- class AutoCallLua {
- public:
- AutoCallLua(lua_State* L, const char func[], const char verb[]) : fL(L) {
- lua_getglobal(L, func);
- if (!lua_isfunction(L, -1)) {
- int t = lua_type(L, -1);
- SkDebugf("--- expected function %d\n", t);
- }
- lua_newtable(L);
- setfield_string(L, "verb", verb);
- }
- ~AutoCallLua() {
- if (lua_pcall(fL, 1, 0, 0) != LUA_OK) {
- SkDebugf("lua err: %s\n", lua_tostring(fL, -1));
- }
- lua_settop(fL, -1);
- }
- private:
- lua_State* fL;
- };
- #define AUTO_LUA(verb) AutoCallLua acl(fL, fFunc.c_str(), verb)
- ///////////////////////////////////////////////////////////////////////////////
- static int lsk_newDocumentPDF(lua_State* L) {
- const char* filename = nullptr;
- if (lua_gettop(L) > 0 && lua_isstring(L, 1)) {
- filename = lua_tolstring(L, 1, nullptr);
- }
- if (!filename) {
- return 0;
- }
- auto file = skstd::make_unique<SkFILEWStream>(filename);
- if (!file->isValid()) {
- return 0;
- }
- auto doc = SkPDF::MakeDocument(file.get());
- if (!doc) {
- return 0;
- }
- push_ptr(L, new DocHolder{std::move(doc), std::move(file)});
- return 1;
- }
- static int lsk_newBlurImageFilter(lua_State* L) {
- SkScalar sigmaX = lua2scalar_def(L, 1, 0);
- SkScalar sigmaY = lua2scalar_def(L, 2, 0);
- sk_sp<SkImageFilter> imf(SkBlurImageFilter::Make(sigmaX, sigmaY, nullptr));
- if (!imf) {
- lua_pushnil(L);
- } else {
- push_ref(L, std::move(imf));
- }
- return 1;
- }
- static int lsk_newLinearGradient(lua_State* L) {
- SkScalar x0 = lua2scalar_def(L, 1, 0);
- SkScalar y0 = lua2scalar_def(L, 2, 0);
- SkColor c0 = lua2color(L, 3);
- SkScalar x1 = lua2scalar_def(L, 4, 0);
- SkScalar y1 = lua2scalar_def(L, 5, 0);
- SkColor c1 = lua2color(L, 6);
- SkPoint pts[] = { { x0, y0 }, { x1, y1 } };
- SkColor colors[] = { c0, c1 };
- sk_sp<SkShader> s(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp));
- if (!s) {
- lua_pushnil(L);
- } else {
- push_ref(L, std::move(s));
- }
- return 1;
- }
- static int lsk_newMatrix(lua_State* L) {
- push_new<SkMatrix>(L)->reset();
- return 1;
- }
- static int lsk_newPaint(lua_State* L) {
- push_new<SkPaint>(L);
- return 1;
- }
- static int lsk_newPath(lua_State* L) {
- push_new<SkPath>(L);
- return 1;
- }
- static int lsk_newPictureRecorder(lua_State* L) {
- push_new<SkPictureRecorder>(L);
- return 1;
- }
- static int lsk_newRRect(lua_State* L) {
- push_new<SkRRect>(L)->setEmpty();
- return 1;
- }
- // Sk.newTextBlob(text, rect, paint)
- static int lsk_newTextBlob(lua_State* L) {
- const char* text = lua_tolstring(L, 1, nullptr);
- SkRect bounds;
- lua2rect(L, 2, &bounds);
- std::unique_ptr<SkShaper> shaper = SkShaper::Make();
- // TODO: restore this logic based on SkFont instead of SkPaint
- #if 0
- const SkPaint& paint = *get_obj<SkPaint>(L, 3);
- SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
- #else
- SkFont font;
- #endif
- SkTextBlobBuilderRunHandler builder(text, { bounds.left(), bounds.top() });
- shaper->shape(text, strlen(text), font, true, bounds.width(), &builder);
- push_ref<SkTextBlob>(L, builder.makeBlob());
- SkLua(L).pushScalar(builder.endPoint().fY);
- return 2;
- }
- static int lsk_newTypeface(lua_State* L) {
- const char* name = nullptr;
- SkFontStyle style;
- int count = lua_gettop(L);
- if (count > 0 && lua_isstring(L, 1)) {
- name = lua_tolstring(L, 1, nullptr);
- if (count > 1) {
- SkFontStyle* passedStyle = get_obj<SkFontStyle>(L, 2);
- if (passedStyle) {
- style = *passedStyle;
- }
- }
- }
- sk_sp<SkTypeface> face(SkTypeface::MakeFromName(name, style));
- // SkDebugf("---- name <%s> style=%d, face=%p ref=%d\n", name, style, face, face->getRefCnt());
- if (nullptr == face) {
- face = SkTypeface::MakeDefault();
- }
- push_ref(L, std::move(face));
- return 1;
- }
- static int lsk_newFontStyle(lua_State* L) {
- int count = lua_gettop(L);
- int weight = SkFontStyle::kNormal_Weight;
- int width = SkFontStyle::kNormal_Width;
- SkFontStyle::Slant slant = SkFontStyle::kUpright_Slant;
- if (count >= 1 && lua_isnumber(L, 1)) {
- weight = lua_tointegerx(L, 1, nullptr);
- }
- if (count >= 2 && lua_isnumber(L, 2)) {
- width = lua_tointegerx(L, 2, nullptr);
- }
- if (count >= 3 && lua_isnumber(L, 3)) {
- slant = static_cast<SkFontStyle::Slant>(lua_tointegerx(L, 3, nullptr));
- }
- push_new<SkFontStyle>(L, weight, width, slant);
- return 1;
- }
- static int lsk_newRasterSurface(lua_State* L) {
- int width = lua2int_def(L, 1, 0);
- int height = lua2int_def(L, 2, 0);
- SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
- SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
- auto surface = SkSurface::MakeRaster(info, &props);
- if (nullptr == surface) {
- lua_pushnil(L);
- } else {
- push_ref(L, surface);
- }
- return 1;
- }
- static int lsk_loadImage(lua_State* L) {
- if (lua_gettop(L) > 0 && lua_isstring(L, 1)) {
- const char* name = lua_tolstring(L, 1, nullptr);
- sk_sp<SkData> data(SkData::MakeFromFileName(name));
- if (data) {
- auto image = SkImage::MakeFromEncoded(std::move(data));
- if (image) {
- push_ref(L, std::move(image));
- return 1;
- }
- }
- }
- return 0;
- }
- static void register_Sk(lua_State* L) {
- lua_newtable(L);
- lua_pushvalue(L, -1);
- lua_setglobal(L, "Sk");
- // the Sk table is still on top
- setfield_function(L, "newDocumentPDF", lsk_newDocumentPDF);
- setfield_function(L, "loadImage", lsk_loadImage);
- setfield_function(L, "newBlurImageFilter", lsk_newBlurImageFilter);
- setfield_function(L, "newLinearGradient", lsk_newLinearGradient);
- setfield_function(L, "newMatrix", lsk_newMatrix);
- setfield_function(L, "newPaint", lsk_newPaint);
- setfield_function(L, "newPath", lsk_newPath);
- setfield_function(L, "newPictureRecorder", lsk_newPictureRecorder);
- setfield_function(L, "newRRect", lsk_newRRect);
- setfield_function(L, "newRasterSurface", lsk_newRasterSurface);
- setfield_function(L, "newTextBlob", lsk_newTextBlob);
- setfield_function(L, "newTypeface", lsk_newTypeface);
- setfield_function(L, "newFontStyle", lsk_newFontStyle);
- lua_pop(L, 1); // pop off the Sk table
- }
- #define REG_CLASS(L, C) \
- do { \
- luaL_newmetatable(L, get_mtname<C>()); \
- lua_pushvalue(L, -1); \
- lua_setfield(L, -2, "__index"); \
- luaL_setfuncs(L, g##C##_Methods, 0); \
- lua_pop(L, 1); /* pop off the meta-table */ \
- } while (0)
- void SkLua::Load(lua_State* L) {
- register_Sk(L);
- REG_CLASS(L, SkCanvas);
- REG_CLASS(L, SkColorFilter);
- REG_CLASS(L, DocHolder);
- REG_CLASS(L, SkFont);
- REG_CLASS(L, SkImage);
- REG_CLASS(L, SkImageFilter);
- REG_CLASS(L, SkMatrix);
- REG_CLASS(L, SkPaint);
- REG_CLASS(L, SkPath);
- REG_CLASS(L, SkPathEffect);
- REG_CLASS(L, SkPicture);
- REG_CLASS(L, SkPictureRecorder);
- REG_CLASS(L, SkRRect);
- REG_CLASS(L, SkShader);
- REG_CLASS(L, SkSurface);
- REG_CLASS(L, SkTextBlob);
- REG_CLASS(L, SkTypeface);
- REG_CLASS(L, SkFontStyle);
- }
- extern "C" int luaopen_skia(lua_State* L);
- extern "C" int luaopen_skia(lua_State* L) {
- SkLua::Load(L);
- return 0;
- }
|