1package drm
2
3import (
4 "os"
5 "testing"
6 "time"
7
8 "github.com/bnema/neferwl/internal/ports"
9 "github.com/stretchr/testify/mock"
10)
11
12func TestScanoutCandidate(t *testing.T) {
13 full := ports.SceneWindow{ID: 1, Rect: ports.Rect{W: 100, H: 50}, Fullscreen: true}
14 scene := ports.Scene{OutputWidth: 100, OutputHeight: 50, Windows: []ports.SceneWindow{full}}
15 buf := &ports.DMABuf{ID: 9, Width: 200, Height: 100, Format: fourccARGB, Planes: []ports.DMABufPlane{{}}}
16 game := ports.SurfaceContent{ID: 1, Width: 200, Height: 100, LogicalW: 100, LogicalH: 50, DMABuf: buf}
17 for _, tc := range []struct {
18 name string
19 scene func(s *ports.Scene)
20 cont func(c *ports.SurfaceContent)
21 reason string
22 }{
23 {"scanout", nil, nil, ""},
24 {"hidden others ignored", func(s *ports.Scene) {
25 s.Windows = append(s.Windows, ports.SceneWindow{ID: 2, Hidden: true})
26 }, nil, ""},
27 {"no window", func(s *ports.Scene) { s.Windows = nil }, nil, "no_fullscreen"},
28 {"rotated output", func(s *ports.Scene) { s.Transform = 1 }, nil, "output_transform"},
29 {"dimmed", func(s *ports.Scene) { s.Windows[0].Dim = 0.5 }, nil, "dim"},
30 {"faded", nil, func(c *ports.SurfaceContent) { c.Fade = 0.5 }, "fade"},
31 {"tiled", func(s *ports.Scene) { s.Windows[0].Fullscreen = false }, nil, "other_windows"},
32 {"float above", func(s *ports.Scene) {
33 s.Windows = append(s.Windows, ports.SceneWindow{ID: 2, Rect: ports.Rect{W: 10, H: 10}})
34 }, nil, "other_windows"},
35 {"not covering", func(s *ports.Scene) { s.Windows[0].Rect.W = 90 }, nil, "other_windows"},
36 {"overlay layer", func(s *ports.Scene) {
37 s.Layers = []ports.SceneLayer{{ID: 3, Layer: ports.LayerOverlay, Rect: ports.Rect{W: 10, H: 10}}}
38 }, nil, "overlay_surface"},
39 {"top layer", func(s *ports.Scene) {
40 s.Layers = []ports.SceneLayer{{ID: 3, Layer: ports.LayerTop, Rect: ports.Rect{W: 10, H: 10}}}
41 }, nil, "overlay_surface"},
42 {"background layer", func(s *ports.Scene) {
43 s.Layers = []ports.SceneLayer{{ID: 3, Layer: ports.LayerBackground, Rect: ports.Rect{W: 10, H: 10}}}
44 }, nil, ""},
45 {"shm", nil, func(c *ports.SurfaceContent) { c.DMABuf, c.SHM = nil, &ports.SHMBuffer{} }, "not_dmabuf"},
46 {"subsurface", nil, func(c *ports.SurfaceContent) { c.Children = []ports.Subsurface{{}} }, "subsurfaces"},
47 {"buffer transform", nil, func(c *ports.SurfaceContent) { c.Transform = 2 }, "buffer_transform"},
48 {"scaled", nil, func(c *ports.SurfaceContent) { c.Width = 100 }, ""},
49 {"cropped", nil, func(c *ports.SurfaceContent) { c.Geometry = ports.Rect{X: 5, W: 90, H: 50} }, "geometry_crop"},
50 {"client ignores scale", nil, func(c *ports.SurfaceContent) { c.LogicalW = 200 }, "letterbox"},
51 {"whole geometry", nil, func(c *ports.SurfaceContent) { c.Geometry = ports.Rect{W: 100, H: 50} }, ""},
52 {"wine client subsurface", nil, wineTree(nil), ""},
53 {"client subsurface translucent", nil, wineTree(func(ch *ports.Subsurface) { ch.Opaque = false }), "subsurface_translucent"},
54 {"client subsurface shm", nil, wineTree(func(ch *ports.Subsurface) { ch.DMABuf, ch.SHM = nil, &ports.SHMBuffer{} }), "not_dmabuf"},
55 {"client subsurface offset", nil, wineTree(func(ch *ports.Subsurface) { ch.X = 4 }), "subsurface_offset"},
56 {"client subsurface below root", nil, wineTree(func(ch *ports.Subsurface) { ch.Below = true }), "subsurface_below"},
57 {"client subsurface cropped", nil, wineTree(func(ch *ports.Subsurface) { ch.Source = [4]float32{0, 0, 100, 50} }), ""},
58 {"client subsurface full source", nil, wineTree(func(ch *ports.Subsurface) { ch.Source = [4]float32{0, 0, 200, 100} }), ""},
59 {"root cropped", nil, func(c *ports.SurfaceContent) { c.Source = [4]float32{10, 0, 190, 100} }, ""},
60 {"client subsurface scaled", nil, wineTree(func(ch *ports.Subsurface) { ch.Width = 100 }), ""},
61 {"client subsurface small", nil, wineTree(func(ch *ports.Subsurface) { ch.LogicalW = 90 }), "letterbox"},
62 {"two subsurfaces", nil, func(c *ports.SurfaceContent) {
63 wineTree(nil)(c)
64 c.Children = append(c.Children, c.Children[0])
65 }, "subsurfaces"},
66 } {
67 s := scene
68 s.Windows = append([]ports.SceneWindow(nil), scene.Windows...)
69 c := game
70 if tc.scene != nil {
71 tc.scene(&s)
72 }
73 if tc.cont != nil {
74 tc.cont(&c)
75 }
76 if _, reason := scanoutCandidate(s, map[ports.WindowID]ports.SurfaceContent{1: c}, 200, 100); reason != tc.reason {
77 t.Errorf("%s: reason %q, want %q", tc.name, reason, tc.reason)
78 }
79 }
80}
81
82// wineTree turns the test content into Wine's layout: the root is a wl_shm
83// frame and the game is one opaque GPU subsurface over the client area.
84func wineTree(edit func(ch *ports.Subsurface)) func(c *ports.SurfaceContent) {
85 return func(c *ports.SurfaceContent) {
86 ch := ports.Subsurface{SurfaceContent: *c}
87 ch.Opaque = true
88 if edit != nil {
89 edit(&ch)
90 }
91 c.DMABuf, c.SHM = nil, &ports.SHMBuffer{}
92 c.Children = []ports.Subsurface{ch}
93 }
94}
95
96// Wine's game subsurface is scanned out in place of the window: the
97// content keeps the window's ID and Seq and takes the subsurface buffer.
98func TestScanoutCandidateClientSubsurface(t *testing.T) {
99 scene := ports.Scene{OutputWidth: 100, OutputHeight: 50, Windows: []ports.SceneWindow{{ID: 1, Rect: ports.Rect{W: 100, H: 50}, Fullscreen: true}}}
100 game := &ports.DMABuf{ID: 9, Width: 200, Height: 100, Format: fourccXRGB, Planes: []ports.DMABufPlane{{}}}
101 acquire := &os.File{}
102 root := ports.SurfaceContent{ID: 1, Seq: 7, Width: 200, Height: 100, LogicalW: 100, LogicalH: 50, SHM: &ports.SHMBuffer{},
103 Geometry: ports.Rect{W: 100, H: 50},
104 Children: []ports.Subsurface{{SurfaceContent: ports.SurfaceContent{Seq: 3, Width: 200, Height: 100, LogicalW: 100, LogicalH: 50, Opaque: true, DMABuf: game, Async: true, Acquire: acquire}}}}
105 c, reason := scanoutCandidate(scene, map[ports.WindowID]ports.SurfaceContent{1: root}, 200, 100)
106 if reason != "" || c.DMABuf != game || c.ID != 1 || c.Seq != 7 || !c.Async || c.Acquire != acquire || c.Geometry != (ports.Rect{}) {
107 t.Fatalf("candidate %+v, reason %q", c, reason)
108 }
109
110 // A single-pixel root is hidden by the opaque dmabuf over it, like an shm
111 // one; alone it is not a dmabuf.
112 solidRoot := root
113 solidRoot.SHM, solidRoot.Solid = nil, &ports.SolidColor{A: 1}
114 c, reason = scanoutCandidate(scene, map[ports.WindowID]ports.SurfaceContent{1: solidRoot}, 200, 100)
115 if reason != "" || c.DMABuf != game || c.Solid != nil || c.ID != 1 || c.Seq != 7 {
116 t.Fatalf("solid root with dmabuf child: candidate %+v, reason %q", c, reason)
117 }
118 solidRoot.Children = nil
119 if _, reason = scanoutCandidate(scene, map[ports.WindowID]ports.SurfaceContent{1: solidRoot}, 200, 100); reason != "not_dmabuf" {
120 t.Fatalf("solid root alone: reason %q, want not_dmabuf", reason)
121 }
122}
123
124// VRR follows a visible fullscreen window covering the output, even
125// when other windows or layers force composition.
126func TestFullscreenShown(t *testing.T) {
127 full := ports.SceneWindow{ID: 1, Rect: ports.Rect{W: 100, H: 50}, Fullscreen: true}
128 for _, tc := range []struct {
129 name string
130 wins []ports.SceneWindow
131 want bool
132 }{
133 {"fullscreen", []ports.SceneWindow{full}, true},
134 {"with dialog above", []ports.SceneWindow{full, {ID: 2, Rect: ports.Rect{W: 10, H: 10}, Floating: true}}, true},
135 {"hidden", []ports.SceneWindow{{ID: 1, Rect: full.Rect, Fullscreen: true, Hidden: true}}, false},
136 {"off screen", []ports.SceneWindow{{ID: 1, Rect: ports.Rect{X: 100, W: 100, H: 50}, Fullscreen: true}}, false},
137 {"tiled covering", []ports.SceneWindow{{ID: 1, Rect: full.Rect}}, false},
138 {"none", nil, false},
139 } {
140 s := ports.Scene{OutputWidth: 100, OutputHeight: 50, Windows: tc.wins}
141 if got := fullscreenShown(&s); got != tc.want {
142 t.Errorf("%s: %v, want %v", tc.name, got, tc.want)
143 }
144 }
145}
146
147// fullscreenShown runs on every composed frame of a VRR output.
148func TestFullscreenShownAllocations(t *testing.T) {
149 s := tiledFullscreenScene()
150 if allocs := testing.AllocsPerRun(100, func() { fullscreenShown(&s) }); allocs != 0 {
151 t.Errorf("fullscreenShown: %.1f allocs, want 0", allocs)
152 }
153}
154
155func BenchmarkFullscreenShown(b *testing.B) {
156 s := tiledFullscreenScene()
157 b.ReportAllocs()
158 for b.Loop() {
159 fullscreenShown(&s)
160 }
161}
162
163// tiledFullscreenScene is 64 tiled windows with the fullscreen one last
164// (worst case for the walk).
165func tiledFullscreenScene() ports.Scene {
166 s := ports.Scene{OutputWidth: 3840, OutputHeight: 2160}
167 for i := range 64 {
168 s.Windows = append(s.Windows, ports.SceneWindow{ID: ports.WindowID(i + 1), Rect: ports.Rect{X: i * 60, W: 60, H: 2160}})
169 }
170 s.Windows = append(s.Windows, ports.SceneWindow{ID: 99, Rect: ports.Rect{W: 3840, H: 2160}, Fullscreen: true})
171 return s
172}
173
174// A buffer scans out when the primary plane lists its format (or the
175// opaque variant) with its modifier; the tranche offers only formats the
176// renderer also composes.
177func TestScanoutFormatFollowsInFormats(t *testing.T) {
178 const tiled = 0x0200000000000001
179 o, k, _ := testOutput(t)
180 o.primary.formats = []ports.DMABufFormat{{Format: fourccXRGB, Modifier: tiled}, {Format: fourccXRGB, Modifier: 0}, {Format: fourccXR30, Modifier: tiled}}
181 nv12 := uint32('N' | 'V'<<8 | '1'<<16 | '2'<<24)
182 for _, tc := range []struct {
183 name string
184 format uint32
185 mod uint64
186 as uint32
187 ok bool
188 }{
189 {"argb as xrgb", fourccARGB, tiled, fourccXRGB, true},
190 {"xrgb linear", fourccXRGB, 0, fourccXRGB, true},
191 {"10 bit alpha as opaque", fourccAR30, tiled, fourccXR30, true},
192 {"modifier not listed", fourccXRGB, 0x0200000000000002, 0, false},
193 {"format not listed", nv12, tiled, 0, false},
194 } {
195 got, ok := o.scanoutFormat(&ports.DMABuf{Format: tc.format, Modifier: tc.mod})
196 if ok != tc.ok || ok && got != tc.as {
197 t.Errorf("%s: %#x %v", tc.name, got, ok)
198 }
199 }
200 sampled := []ports.DMABufFormat{{Format: fourccARGB, Modifier: tiled}, {Format: fourccARGB, Modifier: 0x0200000000000002}, {Format: nv12, Modifier: tiled}}
201 if got := o.scanoutFormats(sampled); len(got) != 1 || got[0] != sampled[0] {
202 t.Fatalf("tranche %v", got)
203 }
204 // A buffer not in IN_FORMATS is refused before any import.
205 o.clientFBs = map[uint64]*clientFB{}
206 if fb, reason := o.scanoutFB(&ports.DMABuf{ID: 4, Format: nv12, Modifier: tiled}, time.Now()); fb != 0 || reason != "format" {
207 t.Fatalf("fb %d reason %q", fb, reason)
208 }
209 // A listed one is imported with every plane (addFB builds ADDFB2).
210 k.EXPECT().addFB(mock.Anything, uint32(fourccXRGB)).Return(88, nil).Once()
211 if fb, reason := o.scanoutFB(&ports.DMABuf{ID: 5, Format: fourccARGB, Modifier: tiled, Planes: []ports.DMABufPlane{{}, {}}}, time.Now()); fb != 88 || reason != "" {
212 t.Fatalf("fb %d reason %q", fb, reason)
213 }
214}
215
216// Each modeset reports the formats clients may allocate for scanout;
217// with direct scanout off the list is empty.
218func TestModesetSendsScanoutFormats(t *testing.T) {
219 const tiled = 0x0200000000000001
220 for _, on := range []bool{true, false} {
221 o, k, _ := testOutput(t)
222 o.cursor = nil
223 o.scanout, o.device = on, 9
224 o.primary.formats = []ports.DMABufFormat{{Format: fourccXRGB, Modifier: tiled}, {Format: fourccNV12, Modifier: tiled}, {Format: fourccP010, Modifier: tiled}}
225 o.sampled = []ports.DMABufFormat{{Format: fourccARGB, Modifier: tiled}, {Format: fourccARGB, Modifier: 0}, {Format: fourccNV12, Modifier: tiled}, {Format: fourccP010, Modifier: tiled}}
226 ch := make(chan ports.OutputFormats, 1)
227 o.formats = ch
228 k.EXPECT().createBlob(mock.Anything).Return(99, nil).Once()
229 if err := o.modeset(); err != nil {
230 t.Fatal(err)
231 }
232 f := <-ch
233 if f.Output != "DP-1" || f.Device != 9 {
234 t.Fatalf("report %+v", f)
235 }
236 if on != (len(f.Formats) == 1 && f.Formats[0] == o.sampled[0]) || !on && len(f.Formats) != 0 {
237 t.Fatalf("scanout=%v formats %v", on, f.Formats)
238 }
239 }
240}
241
242func TestHDRScanoutDecision(t *testing.T) {
243 o, k, _ := testOutput(t)
244 o.hdr.on = true
245 o.primary.formats = []ports.DMABufFormat{{Format: fourccXR30}}
246 scene := ports.Scene{OutputWidth: 200, OutputHeight: 100, Windows: []ports.SceneWindow{{ID: 1, Fullscreen: true, Rect: ports.Rect{W: 200, H: 100}}}}
247 c := ports.SurfaceContent{ID: 1, Width: 200, Height: 100, LogicalW: 200, LogicalH: 100, DMABuf: &ports.DMABuf{ID: 11, Format: fourccXR30}}
248 check := func(want string) {
249 t.Helper()
250 fb, _, _ := o.scanoutFrame(scene, map[ports.WindowID]ports.SurfaceContent{1: c})
251 if o.reason != want || (fb != 0) != (want == "") {
252 t.Fatalf("fb %d reason %q, want %q", fb, o.reason, want)
253 }
254 }
255 check("hdr_sdr_content")
256 c.Color = ports.SurfaceColor{TF: ports.ColorTFPQ, Primaries: ports.ColorPrimariesBT2020}
257 c.DMABuf.Format = fourccXRGB
258 check("hdr_format")
259 c.DMABuf.Format = fourccP010
260 check("yuv")
261 c.DMABuf.Format = fourccXR30
262 k.EXPECT().addFB(mock.Anything, uint32(fourccXR30)).Return(uint32(77), nil).Once()
263 check("")
264 o.hdr.on = false
265 check("sdr_pq_content")
266}
267
268func TestModesetReportsConfirmedHDR(t *testing.T) {
269 o, k, _ := testOutput(t)
270 o.cursor = nil
271 o.hdr.on = true
272 o.hdr.cap = hdrCapability{MaxLuminance: 1000, MaxFrameAverage: 400, MinLuminance: 0.005}
273 o.primary.formats = []ports.DMABufFormat{{Format: fourccXR30}, {Format: fourccXRGB}}
274 o.sampled = []ports.DMABufFormat{{Format: fourccXR30}, {Format: fourccXRGB}}
275 ch := make(chan ports.OutputFormats, 2)
276 o.formats = ch
277 k.EXPECT().createBlob(mock.Anything).Return(99, nil).Twice()
278 k.EXPECT().destroyBlob(uint32(99)).Return(nil).Once()
279 if err := o.modeset(); err != nil {
280 t.Fatal(err)
281 }
282 if f := <-ch; f.HDR == nil || f.HDR.MaxLuminance != 1000 || f.HDR.MaxFrameAverage != 400 || f.HDR.MinLuminance != 0.005 || len(f.Formats) != 1 || f.Formats[0].Format != fourccXR30 {
283 t.Fatalf("HDR report: %+v", f)
284 }
285 o.hdr.on = false // fallback to SDR
286 if err := o.modeset(); err != nil {
287 t.Fatal(err)
288 }
289 if f := <-ch; f.HDR != nil || len(f.Formats) != 1 || f.Formats[0].Format != fourccXRGB {
290 t.Fatalf("SDR fallback report: %+v", f)
291 }
292}
293
294// Power off withdraws HDR and scanout formats: clients must not target an
295// inactive output.
296func TestPowerOffWithdrawsHDRAndFormats(t *testing.T) {
297 o, _, _ := testOutput(t)
298 o.cursor = nil
299 o.hdr.on, o.scanout = true, true
300 o.hdr.cap = hdrCapability{MaxLuminance: 1000}
301 o.primary.formats = []ports.DMABufFormat{{Format: fourccXR30}}
302 o.sampled = []ports.DMABufFormat{{Format: fourccXR30}}
303 ch := make(chan ports.OutputFormats, 1)
304 o.formats = ch
305 if err := o.powerOff(); err != nil {
306 t.Fatal(err)
307 }
308 select {
309 case f := <-ch:
310 if f.HDR != nil || len(f.Formats) != 0 {
311 t.Fatalf("power-off report: %+v", f)
312 }
313 default:
314 t.Fatal("no report after power off")
315 }
316}
317
318// A plane without IN_FORMATS (driver without modifiers) scans out its
319// GETPLANE formats, linear.
320func TestPlaneWithoutInFormatsIsLinear(t *testing.T) {
321 k := newMockkms(t)
322 k.EXPECT().planes().Return([]planeRes{{id: 1, possible: 1, formats: []uint32{fourccXRGB}}}, nil)
323 k.EXPECT().objProps(uint32(1), uint32(objPlane)).Return(map[string][2]uint64{"type": {20, planePrimary}}, nil)
324 ps, err := readPlanes(k, 0)
325 if err != nil || len(ps) != 1 {
326 t.Fatalf("%v %v", ps, err)
327 }
328 o := &Output{primary: ps[0]}
329 if f, ok := o.scanoutFormat(&ports.DMABuf{Format: fourccARGB}); !ok || f != fourccXRGB {
330 t.Fatalf("linear argb: %#x %v", f, ok)
331 }
332 if _, ok := o.scanoutFormat(&ports.DMABuf{Format: fourccARGB, Modifier: 0x0200000000000001}); ok {
333 t.Fatal("tiled accepted without IN_FORMATS")
334 }
335}
336
337// A flip shows only the windows its scene draws: presentation feedback of
338// a window on another workspace, hidden or scrolled off the output is
339// discarded, not presented.
340func TestShownByScene(t *testing.T) {
341 s := ports.Scene{OutputWidth: 10, OutputHeight: 10, Windows: []ports.SceneWindow{{ID: 1, Rect: ports.Rect{X: 5, W: 10, H: 10}}, {ID: 2, Hidden: true}, {ID: 3, Rect: ports.Rect{X: 10, W: 10, H: 10}}}, Layers: []ports.SceneLayer{{ID: 5}}}
342 got := (&Output{}).shownBy(s, map[ports.WindowID]uint64{1: 3, 2: 4, 3: 8, 5: 6, 9: 7})
343 if len(got) != 2 || got[1] != 3 || got[5] != 6 {
344 t.Fatalf("shows %v", got)
345 }
346}
347
348// The decision is callable without Run and keeps the zero-allocation
349// composition and cached direct-scanout paths cheap.
350func TestFrameDecisionAllocations(t *testing.T) {
351 o, _, _ := testOutput(t)
352 o.scanout = true
353 s := ports.Scene{OutputWidth: 200, OutputHeight: 100, Windows: []ports.SceneWindow{{ID: 1, Fullscreen: true, Rect: ports.Rect{W: 200, H: 100}}}}
354 c := ports.SurfaceContent{ID: 1, Width: 200, Height: 100, LogicalW: 200, LogicalH: 100, DMABuf: &ports.DMABuf{ID: 17, Format: fourccXRGB}}
355 surfaces := map[ports.WindowID]ports.SurfaceContent{1: c}
356 o.clientFBs[17] = &clientFB{fbID: 77}
357 o.primary.formats = []ports.DMABufFormat{{Format: fourccXRGB}}
358 for _, tc := range []struct {
359 name string
360 capture bool
361 wantFB uint32
362 wantReason string
363 }{
364 {"direct", false, 77, ""}, {"capture", true, 0, "capture"},
365 } {
366 t.Run(tc.name, func(t *testing.T) {
367 d := o.decideFrame(s, surfaces, tc.capture)
368 if d.fb != tc.wantFB || o.reason != tc.wantReason {
369 t.Fatalf("decision: fb=%d reason=%q", d.fb, o.reason)
370 }
371 if tc.capture && o.overlayReason != "capture" {
372 t.Fatalf("capture overlay reason %q", o.overlayReason)
373 }
374 if n := testing.AllocsPerRun(100, func() { o.decideFrame(s, surfaces, tc.capture) }); n != 0 {
375 t.Fatalf("decision: %.1f allocs", n)
376 }
377 })
378 }
379 o.primary.formats = nil
380 d := o.decideFrame(s, surfaces, false)
381 if d.fb != 0 || o.overlayReason != "no_plane" || len(d.composed.Windows) != 1 {
382 t.Fatalf("composition: %+v", d)
383 }
384 if n := testing.AllocsPerRun(100, func() { o.decideFrame(s, surfaces, false) }); n != 0 {
385 t.Fatalf("composition decision: %.1f allocs", n)
386 }
387
388 // Overlay active: the scene composed without the overlaid window reuses
389 // the output's window slice.
390 t.Run("overlay", func(t *testing.T) {
391 o, _, _ := overlayOutput(t)
392 o.overlay.formats = []ports.DMABufFormat{{Format: fourccXRGB}}
393 s, surfaces := overlayScene()
394 o.clientFBs[9] = &clientFB{fbID: 88}
395 d := o.decideFrame(s, surfaces, false)
396 if d.fb != 0 || d.overlay.fb != 88 || o.overlayReason != "" || len(d.composed.Windows) != 1 || d.composed.Windows[0].ID != 1 {
397 t.Fatalf("overlay decision: %+v reason %q", d, o.overlayReason)
398 }
399 if n := testing.AllocsPerRun(100, func() { o.decideFrame(s, surfaces, false) }); n != 0 {
400 t.Fatalf("overlay decision: %.1f allocs", n)
401 }
402 // The slice is reused: the previous scene's Windows is overwritten
403 // by the next call, and the input scene is never modified.
404 first := d.composed.Windows
405 d2 := o.decideFrame(s, surfaces, false)
406 if &first[0] != &d2.composed.Windows[0] || len(s.Windows) != 2 || s.Windows[0].ID != 1 || s.Windows[1].ID != 2 {
407 t.Fatal("rest windows not reused or the input scene changed")
408 }
409 })
410}
411
412func TestFrameDecisionOverlayFallback(t *testing.T) {
413 o, k, _ := overlayOutput(t)
414 o.overlay.formats = []ports.DMABufFormat{{Format: fourccXRGB}}
415 s, surfaces := overlayScene()
416 k.EXPECT().addFB(mock.Anything, uint32(fourccXRGB)).Return(88, nil).Once()
417 d := o.decideFrame(s, surfaces, false)
418 if d.fb != 0 || d.overlay.fb != 88 || o.reason != "other_windows" || len(d.composed.Windows) != 1 {
419 t.Fatalf("overlay decision: %+v", d)
420 }
421 d.overlay.close()
422 o.clientFBs[9].overlayFailed = "overlay_refused"
423 d = o.decideFrame(s, surfaces, false)
424 if d.overlay.fb != 0 || o.overlayReason != "overlay_refused" || len(d.composed.Windows) != 2 {
425 t.Fatalf("fallback decision: %+v", d)
426 }
427}