vendetta / src / surface.v
46 lines · 45 sloc · 1.32 KB · 77754ad9e6dc749afefba326ff89abc5ddd8c9c9
Raw
1import time
2import sokol.sapp
3import ui2
4import libvendetta
5
6// draw runs the app's per-frame work and then the widget's render, with the GL
7// context current. A frame that started more than 18 ms after the one before
8// missed its 60 Hz slot, so in performance mode the thumbnail and media work
9// waits for the next frame.
10fn (mut p Player) draw(id string, frame ui2.Rect, scale f64, height f64) {
11 if id != libvendetta.video_surface_id {
12 return
13 }
14 now := time.ticks()
15 late_frame := p.last_frame_t0 > 0 && now - p.last_frame_t0 > 18
16 p.last_frame_t0 = now
17 p.drain_events()
18 p.resume_pending_queue()
19 p.drain_mpris()
20 if p.want_fullscreen {
21 p.want_fullscreen = false
22 p.toggle_fullscreen()
23 }
24 if !(p.low_quality && late_frame) {
25 if p.thumb_ctx != unsafe { nil } {
26 p.drain_thumb()
27 if ui2.refresh_on_demand() && p.preview_state != 0 {
28 // The thumbnail mpv has no render context, so nothing wakes the
29 // loop for its replies: this poll is how a capture finishes
30 // after the pointer has stopped moving.
31 if p.thumb_wake != 0 {
32 ui2.cancel_timer(p.thumb_wake)
33 }
34 p.thumb_wake = ui2.after(0.1, fn () {
35 ui2.request_refresh()
36 })
37 }
38 }
39 p.drain_media()
40 }
41 p.update_preview()
42 if p.fullscreen && time.ticks() - p.last_motion > 2500 {
43 sapp.show_mouse(false)
44 }
45 p.render(id, frame, scale, height)
46}
47