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.
This commit is contained in:
wm4 2019-12-23 11:48:16 +01:00
parent 0728726251
commit 490b3ba007
1 changed files with 18 additions and 5 deletions

View File

@ -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()