1package drm
2
3import (
4 "slices"
5
6 "github.com/bnema/neferwl/internal/ports"
7)
8
9// frontImage is what the output image last committed by a composed frame
10// holds: the scene drawn into it and the content Seq of each window and
11// layer it lists. When only the window on the overlay plane changes, the
12// next frame commits that image again with the new overlay buffer: no GPU
13// pass, no fence. Paths that draw into an output image outside
14// submitFrame (security, protection, image setup, the async probe) forget
15// it.
16type frontImage struct {
17 fb uint32 // 0: unknown
18 scene ports.Scene
19 seqs []uint64 // Seq of each window, then each layer, of scene
20 // Backing arrays of scene's slices, reused across frames.
21 windows []ports.SceneWindow
22 separators []ports.Separator
23 layers []ports.SceneLayer
24 hints []ports.Rect
25 indicators []ports.CaptureIndicator
26}
27
28// forget drops the image's contents: the next frame composes.
29func (f *frontImage) forget() { f.fb = 0 }
30
31// hold records that fb holds s drawn from surfaces. A capture scene is not
32// recorded (SameAs never matches it).
33func (f *frontImage) hold(fb uint32, s ports.Scene, surfaces map[ports.WindowID]ports.SurfaceContent) {
34 if s.Capture != nil || s.CaptureScene != nil {
35 f.forget()
36 return
37 }
38 f.windows = append(f.windows[:0], s.Windows...)
39 f.separators = append(f.separators[:0], s.Separators...)
40 f.layers = append(f.layers[:0], s.Layers...)
41 f.hints = append(f.hints[:0], s.DropHints...)
42 f.indicators = append(f.indicators[:0], s.CaptureIndicators...)
43 f.scene = s
44 f.scene.Windows, f.scene.Separators, f.scene.Layers = f.windows, f.separators, f.layers
45 f.scene.DropHints, f.scene.CaptureIndicators = f.hints, f.indicators
46 f.seqs = appendSeqs(f.seqs[:0], s, surfaces)
47 f.fb = fb
48}
49
50// holds reports whether fb holds exactly what drawing s from surfaces would.
51func (f *frontImage) holds(fb uint32, s ports.Scene, surfaces map[ports.WindowID]ports.SurfaceContent) bool {
52 if f.fb == 0 || f.fb != fb || !s.SameAs(f.scene) {
53 return false
54 }
55 i := 0
56 for _, w := range s.Windows {
57 if surfaces[w.ID].Seq != f.seqs[i] {
58 return false
59 }
60 i++
61 }
62 for _, l := range s.Layers {
63 if surfaces[l.ID].Seq != f.seqs[i] {
64 return false
65 }
66 i++
67 }
68 return true
69}
70
71func appendSeqs(seqs []uint64, s ports.Scene, surfaces map[ports.WindowID]ports.SurfaceContent) []uint64 {
72 seqs = slices.Grow(seqs, len(s.Windows)+len(s.Layers))
73 for _, w := range s.Windows {
74 seqs = append(seqs, surfaces[w.ID].Seq)
75 }
76 for _, l := range s.Layers {
77 seqs = append(seqs, surfaces[l.ID].Seq)
78 }
79 return seqs
80}