X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=theme.cpp;h=61e149c3320c9256d0985d51a3db26dc913e99f2;hb=a98732df9454028ddaa54a9d07b5d7513767bfe9;hp=bd1259062780ae0859b65b4042fdfa644785d745;hpb=46a29f577f39bf2000553e53683b34b7f50f8dbf;p=nageru diff --git a/theme.cpp b/theme.cpp index bd12590..61e149c 100644 --- a/theme.cpp +++ b/theme.cpp @@ -20,16 +20,15 @@ #include #include #include +#include +#include "defs.h" #include "image_input.h" namespace movit { class ResourcePool; } // namespace movit -#define WIDTH 1280 // FIXME -#define HEIGHT 720 // FIXME - using namespace std; using namespace movit; @@ -37,6 +36,23 @@ namespace { vector live_inputs; +class LuaRefWithDeleter { +public: + LuaRefWithDeleter(mutex *m, lua_State *L, int ref) : m(m), L(L), ref(ref) {} + ~LuaRefWithDeleter() { + unique_lock lock(*m); + luaL_unref(L, LUA_REGISTRYINDEX, ref); + } + int get() const { return ref; } + +private: + LuaRefWithDeleter(const LuaRefWithDeleter &) = delete; + + mutex *m; + lua_State *L; + int ref; +}; + template int wrap_lua_object(lua_State* L, const char *class_name, Args&&... args) { @@ -501,14 +517,14 @@ Theme::get_chain(unsigned num, float t, unsigned width, unsigned height) exit(1); } lua_pushvalue(L, -1); - int funcref = luaL_ref(L, LUA_REGISTRYINDEX); // TODO: leak! + shared_ptr funcref(new LuaRefWithDeleter(&m, L, luaL_ref(L, LUA_REGISTRYINDEX))); lua_pop(L, 2); assert(lua_gettop(L) == 0); return make_pair(chain, [this, funcref]{ unique_lock lock(m); // Set up state, including connecting signals. - lua_rawgeti(L, LUA_REGISTRYINDEX, funcref); + lua_rawgeti(L, LUA_REGISTRYINDEX, funcref->get()); if (lua_pcall(L, 0, 0, 0) != 0) { fprintf(stderr, "error running chain setup callback: %s\n", lua_tostring(L, -1)); exit(1); @@ -597,6 +613,8 @@ void Theme::connect_signal(YCbCrInput *input, int signal_num) } input->set_texture_num(0, input_textures[signal_num].tex_y); input->set_texture_num(1, input_textures[signal_num].tex_cbcr); + input->set_width(input_textures[signal_num].width); + input->set_height(input_textures[signal_num].height); } void Theme::transition_clicked(int transition_num, float t)