diff options
author | Mike Reed <reed@google.com> | 2016-11-12 08:06:55 -0600 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-11-13 18:31:13 +0000 |
commit | 5df4934b3e40cdc378e225d1dda39f015cae9bae (patch) | |
tree | f0871dcbca35730333ad3b14115e6a14987fac7b /src/utils/SkLua.cpp | |
parent | f982cb37e3092e7a69c13a12ec09806ceff5af45 (diff) |
Revert[2] "Change SkCanvas to *not* inherit from SkRefCnt"
Changes over original:
- conditionalize ownership in SkPictureRecorder
- conditionalize ownership in SkCanvasStateUtils
This reverts commit b613c266df48cf45296ecc23d1bd7098c84bb7ba.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4742
Change-Id: Ib25514d6f546c69b6650b5c957403b04f7380dc2
Reviewed-on: https://skia-review.googlesource.com/4742
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/utils/SkLua.cpp')
-rw-r--r-- | src/utils/SkLua.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp index a2234565cb..27127df6a8 100644 --- a/src/utils/SkLua.cpp +++ b/src/utils/SkLua.cpp @@ -73,6 +73,13 @@ template <typename T> void push_obj(lua_State* L, const T& obj) { 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>()); @@ -333,7 +340,7 @@ void SkLua::pushPath(const SkPath& path, const char key[]) { } void SkLua::pushCanvas(SkCanvas* canvas, const char key[]) { - push_ref(fL, canvas); + push_ptr(fL, canvas); CHECK_SETFIELD(key); } @@ -715,7 +722,7 @@ static int lcanvas_newSurface(lua_State* L) { } static int lcanvas_gc(lua_State* L) { - get_ref<SkCanvas>(L, 1)->unref(); + // don't know how to track a ptr... return 0; } @@ -757,7 +764,7 @@ const struct luaL_Reg gSkCanvas_Methods[] = { static int ldocument_beginPage(lua_State* L) { const SkRect* contentPtr = nullptr; - push_ref(L, get_ref<SkDocument>(L, 1)->beginPage(lua2scalar(L, 2), + push_ptr(L, get_ref<SkDocument>(L, 1)->beginPage(lua2scalar(L, 2), lua2scalar(L, 3), contentPtr)); return 1; @@ -1750,7 +1757,7 @@ static int lsurface_getCanvas(lua_State* L) { if (nullptr == canvas) { lua_pushnil(L); } else { - push_ref(L, canvas); + 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? @@ -1814,7 +1821,7 @@ static int lpicturerecorder_beginRecording(lua_State* L) { return 1; } - push_ref(L, canvas); + push_ptr(L, canvas); return 1; } @@ -1824,7 +1831,7 @@ static int lpicturerecorder_getCanvas(lua_State* L) { lua_pushnil(L); return 1; } - push_ref(L, canvas); + push_ptr(L, canvas); return 1; } |