aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils/SkLua.cpp
diff options
context:
space:
mode:
authorGravatar Heather Miller <hcm@google.com>2016-11-10 21:25:30 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-10 21:25:44 +0000
commitb613c266df48cf45296ecc23d1bd7098c84bb7ba (patch)
tree50f7d84a4238918bf5869ee760ed78332b2db946 /src/utils/SkLua.cpp
parentfac8db2df8b5cf6fd62189315bad0726d8e51f6d (diff)
Revert "Change SkCanvas to *not* inherit from SkRefCnt"
This reverts commit 824075071885b6b741c141cbe2134d8345d34589. Reason for revert: Breaking WebView (chromium:663959) Original change's description: > Change SkCanvas to *not* inherit from SkRefCnt > > Definitely tricky for classes like SkNWayCanvas, where the caller (today) > need not pay attention to ownership of the canvases it gave the NWay > (after this CL, the caller *must* managed ownership) > > BUG=skia: > > GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4441 > > DOCS_PREVIEW= https://skia.org/?cl=4441 > > Change-Id: Ib1ac07a3cdf0686d78e7aaa4735d45cc90bea081 > Reviewed-on: https://skia-review.googlesource.com/4441 > Commit-Queue: Mike Reed <reed@google.com> > Reviewed-by: Florin Malita <fmalita@chromium.org> > Reviewed-by: Robert Phillips <robertphillips@google.com> > TBR=djsollen@google.com,mtklein@google.com,halcanary@google.com,robertphillips@google.com,fmalita@chromium.org,fmalita@google.com,reed@google.com,reviews@skia.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Change-Id: I5e3b3e876b7d2c09833cf841801321033b6b968b Reviewed-on: https://skia-review.googlesource.com/4687 Commit-Queue: Heather Miller <hcm@google.com> Reviewed-by: Heather Miller <hcm@google.com>
Diffstat (limited to 'src/utils/SkLua.cpp')
-rw-r--r--src/utils/SkLua.cpp19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index 27127df6a8..a2234565cb 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -73,13 +73,6 @@ 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>());
@@ -340,7 +333,7 @@ void SkLua::pushPath(const SkPath& path, const char key[]) {
}
void SkLua::pushCanvas(SkCanvas* canvas, const char key[]) {
- push_ptr(fL, canvas);
+ push_ref(fL, canvas);
CHECK_SETFIELD(key);
}
@@ -722,7 +715,7 @@ static int lcanvas_newSurface(lua_State* L) {
}
static int lcanvas_gc(lua_State* L) {
- // don't know how to track a ptr...
+ get_ref<SkCanvas>(L, 1)->unref();
return 0;
}
@@ -764,7 +757,7 @@ const struct luaL_Reg gSkCanvas_Methods[] = {
static int ldocument_beginPage(lua_State* L) {
const SkRect* contentPtr = nullptr;
- push_ptr(L, get_ref<SkDocument>(L, 1)->beginPage(lua2scalar(L, 2),
+ push_ref(L, get_ref<SkDocument>(L, 1)->beginPage(lua2scalar(L, 2),
lua2scalar(L, 3),
contentPtr));
return 1;
@@ -1757,7 +1750,7 @@ static int lsurface_getCanvas(lua_State* L) {
if (nullptr == canvas) {
lua_pushnil(L);
} else {
- push_ptr(L, canvas);
+ push_ref(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?
@@ -1821,7 +1814,7 @@ static int lpicturerecorder_beginRecording(lua_State* L) {
return 1;
}
- push_ptr(L, canvas);
+ push_ref(L, canvas);
return 1;
}
@@ -1831,7 +1824,7 @@ static int lpicturerecorder_getCanvas(lua_State* L) {
lua_pushnil(L);
return 1;
}
- push_ptr(L, canvas);
+ push_ref(L, canvas);
return 1;
}