From 490b3ba007c7142a0eeb1f13f69180b55dc472ca Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 23 Dec 2019 11:48:16 +0100 Subject: [PATCH] osc: use new overlay API This tries to avoid the update() call if nothing changed. This brings it more into line with the old code (the osd-overlay command simply does not skip the update if nothing changed). I don't know whether this matters; most likely not. Normally, code should try to avoid redundant updates on its own, so it's not the job of the command. However, for the OSC we simply want to reduce the differences. --- player/lua/osc.lua | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/player/lua/osc.lua b/player/lua/osc.lua index c30e7e3b32..c7d155d0f0 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -116,6 +116,7 @@ local state = { using_video_margins = false, border = true, maximized = false, + osd = mp.create_osd_overlay("ass-events"), } local window_control_box_width = 80 @@ -127,6 +128,18 @@ local is_december = os.date("*t").month == 12 -- Helperfunctions -- +function set_osd(res_x, res_y, text) + if state.osd.res_x == res_x and + state.osd.res_y == res_y and + state.osd.data == text then + return + end + state.osd.res_x = res_x + state.osd.res_y = res_y + state.osd.data = text + state.osd:update() +end + local margins_opts = { {"l", "video-margin-ratio-left"}, {"r", "video-margin-ratio-right"}, @@ -2180,7 +2193,7 @@ end function render_wipe() msg.trace("render_wipe()") - mp.set_osd_ass(0, 0, "{}") + state.osd:remove() end function render() @@ -2329,8 +2342,8 @@ function render() end -- submit - mp.set_osd_ass(osc_param.playresy * osc_param.display_aspect, - osc_param.playresy, ass.text) + set_osd(osc_param.playresy * osc_param.display_aspect, + osc_param.playresy, ass.text) end -- @@ -2466,7 +2479,7 @@ function tick() ass:pos(320, icon_y+65) ass:an(8) ass:append("Drop files or URLs to play here.") - mp.set_osd_ass(640, 360, ass.text) + set_osd(640, 360, ass.text) if state.showhide_enabled then mp.disable_key_bindings("showhide") @@ -2482,7 +2495,7 @@ function tick() render() else -- Flush OSD - mp.set_osd_ass(osc_param.playresy, osc_param.playresy, "") + set_osd(osc_param.playresy, osc_param.playresy, "") end state.tick_last_time = mp.get_time()