feat/data-dnd e05cb15

scanout.go RawHistoryFolder

1package drm
2
3import (
4	"errors"
5	"math"
6	"os"
7	"slices"
8	"time"
9	"unsafe"
10
11	"github.com/bnema/neferwl/internal/ports"
12	"golang.org/x/sys/unix"
13)
14
15// Direct scanout (ADR 006): when one fullscreen window covers the output
16// with a GPU buffer whose source can fill the plane, the output flips to that buffer
17// instead of compositing it. The buffer becomes a KMS framebuffer once
18// (PRIME import + ADDFB2) and is cached by DMABuf ID while the client
19// keeps using it. KMS waits on the buffer's implicit fences before showing
20// it. Anything else on screen or a buffer KMS refuses falls back to composition.
21
22const (
23	ioctlGemClose        = 0x40086409
24	ioctlPrimeFDToHandle = 0xC00C642E
25	ioctlAddFB2          = 0xC06864B8
26
27	fbModifiers        = 1 << 1
28	capAddFB2Modifiers = 0x10
29	modInvalid         = 0x00ffffffffffffff
30	scanoutIdleTTL     = 5 * time.Second // a cached framebuffer survives unused
31)
32
33type primeHandle struct {
34	handle, flags uint32
35	fd            int32
36}
37
38type gemClose struct{ handle, pad uint32 }
39
40type fbCmd2 struct {
41	fbID, width, height, format, flags uint32
42	handles, pitches, offsets          [4]uint32
43	modifiers                          [4]uint64
44}
45
46// planeRect contains source coordinates in 16.16 and destination pixels.
47type planeRect struct {
48	src  [4]uint64
49	crtc [4]uint64
50}
51
52func fullPlaneRect(w, h int) planeRect {
53	return planeRect{src: [4]uint64{0, 0, uint64(w) << 16, uint64(h) << 16}, crtc: [4]uint64{0, 0, uint64(w), uint64(h)}}
54}
55
56func scanoutRect(c ports.SurfaceContent, w, h int) planeRect {
57	r := fullPlaneRect(w, h)
58	r.src = [4]uint64{0, 0, uint64(c.Width) << 16, uint64(c.Height) << 16}
59	if c.Source[2] != 0 {
60		for i, value := range c.Source {
61			r.src[i] = uint64(float64(value) * 65536)
62		}
63	}
64	return r
65}
66
67// covers reports whether win fills the output of scene s.
68func covers(s *ports.Scene, win *ports.SceneWindow) bool {
69	return (s.WorkspaceClip == (ports.Rect{}) || s.WorkspaceClip == (ports.Rect{W: s.OutputWidth, H: s.OutputHeight})) &&
70		win.Rect.X == 0 && win.Rect.Y == 0 && win.Rect.W == s.OutputWidth && win.Rect.H == s.OutputHeight
71}
72
73// fullscreenShown reports whether a visible fullscreen window covers the
74// output, whether its frame is scanned out or composed.
75func fullscreenShown(s *ports.Scene) bool {
76	for i := range s.Windows {
77		win := &s.Windows[i]
78		if win.Fullscreen && !win.Hidden && covers(s, win) {
79			return true
80		}
81	}
82	return false
83}
84
85// scanoutCandidate returns the window content the output can scan out
86// directly, or a reason why it cannot. w, h are the output's physical size.
87// The plane's formats are checked by scanoutFB.
88//
89// kept reports a window drawn from a content its client withdrew (it
90// closed and fades out): the client may already have its buffer back, so
91// it is never put on a plane (nil: none is).
92func scanoutCandidate(s ports.Scene, surfaces map[ports.WindowID]ports.SurfaceContent, w, h int, kept func(ports.WindowID) bool) (ports.SurfaceContent, string) {
93	if s.Transform != 0 {
94		// The scanout buffer would have to be pre-rotated: rotated outputs compose.
95		return ports.SurfaceContent{}, "output_transform"
96	}
97	if s.WorkspaceClip != (ports.Rect{}) && s.WorkspaceClip != (ports.Rect{W: s.OutputWidth, H: s.OutputHeight}) {
98		return ports.SurfaceContent{}, "workspace_clip"
99	}
100	var full *ports.SceneWindow
101	for i := range s.Windows {
102		win := &s.Windows[i]
103		if !s.Draws(*win) {
104			continue
105		}
106		if !win.Fullscreen || !covers(&s, win) || full != nil {
107			return ports.SurfaceContent{}, "other_windows"
108		}
109		full = win
110	}
111	if full == nil {
112		return ports.SurfaceContent{}, "no_fullscreen"
113	}
114	if kept != nil && kept(full.ID) {
115		return ports.SurfaceContent{}, "leaving"
116	}
117	if len(s.DropHints) > 0 {
118		// Drag hints are drawn over the window.
119		return ports.SurfaceContent{}, "drop_hint"
120	}
121	if full.Dim > 0 {
122		// Its veil is composed over it: the plane would show it bright.
123		return ports.SurfaceContent{}, "dim"
124	}
125	if full.Fade > 0 || full.Preview > 0 || full.Zoom > 0 {
126		// A fading or zoomed window is composed: the plane would show it
127		// whole and opaque.
128		return ports.SurfaceContent{}, "window_fade"
129	}
130	// Core leaves the layers a fullscreen window hides out of the scene:
131	// one above the windows here is drawn.
132	for _, l := range s.Layers {
133		if l.Layer >= ports.LayerTop && l.Rect.W > 0 && l.Rect.H > 0 {
134			return ports.SurfaceContent{}, "overlay_surface"
135		}
136	}
137	c := surfaces[full.ID]
138	if c.DMABuf == nil && len(c.Children) > 0 {
139		var reason string
140		if c, reason = clientSubsurface(c); reason != "" {
141			return c, reason
142		}
143	}
144	switch {
145	case c.DMABuf == nil:
146		return c, "not_dmabuf"
147	case c.Fade > 0:
148		// The plane would show it unfaded (wp_alpha_modifier_v1).
149		return c, "fade"
150	case len(c.Children) > 0:
151		return c, "subsurfaces"
152	case c.Transform != 0:
153		// Planes show buffers as they are: rotation is composed.
154		return c, "buffer_transform"
155	case c.LogicalW != full.Rect.W || c.LogicalH != full.Rect.H:
156		return c, "letterbox"
157	case c.Width <= 0 || c.Height <= 0 || c.Source[2] < 0 || c.Source[3] < 0 || !finiteSource(c.Source):
158		return c, "source_crop"
159	case c.Geometry != (ports.Rect{}) && (c.Geometry.X != 0 || c.Geometry.Y != 0 || c.Geometry.W != c.LogicalW || c.Geometry.H != c.LogicalH):
160		return c, "geometry_crop"
161	}
162	if c.Source[2] != 0 && (c.Source[0] < 0 || c.Source[1] < 0 || c.Source[2] <= 0 || c.Source[3] <= 0 || c.Source[0]+c.Source[2] > float32(c.Width) || c.Source[1]+c.Source[3] > float32(c.Height)) {
163		return c, "source_crop"
164	}
165	return c, ""
166}
167
168func finiteSource(src [4]float32) bool {
169	for _, n := range src {
170		if math.IsNaN(float64(n)) || math.IsInf(float64(n), 0) {
171			return false
172		}
173	}
174	return true
175}
176
177// cropped reports whether a viewport source shows less than the buffer.
178func cropped(c ports.SurfaceContent) bool {
179	return c.Source[2] != 0 && c.Source != [4]float32{0, 0, float32(c.Width), float32(c.Height)}
180}
181
182// clientSubsurface returns the content to scan out for a window whose
183// root has no GPU buffer but one opaque subsurface over its geometry: Wine
184// draws the frame in the root (wl_shm) and presents Vulkan in a subsurface
185// on the client area. That subsurface hides the root entirely, so it is
186// what the screen shows. The returned content keeps the window's ID and
187// Seq for release and presentation.
188func clientSubsurface(c ports.SurfaceContent) (ports.SurfaceContent, string) {
189	if len(c.Children) != 1 {
190		return c, "subsurfaces"
191	}
192	ch := c.Children[0]
193	switch {
194	case ch.DMABuf == nil:
195		return c, "not_dmabuf"
196	case !ch.Opaque:
197		return c, "subsurface_translucent"
198	case ch.Below:
199		// The root is drawn over it.
200		return c, "subsurface_below"
201	case ch.X != c.Geometry.X || ch.Y != c.Geometry.Y:
202		return c, "subsurface_offset"
203	}
204	out := ch.SurfaceContent
205	out.ID, out.Seq, out.Geometry = c.ID, c.Seq, ports.Rect{}
206	return out, ""
207}
208
209// scanoutFrame picks a fullscreen client buffer to flip directly. It
210// returns fb 0, with the reason logged on change, when the frame must be
211// composed.
212func (o *Output) scanoutFrame(scene ports.Scene, surfaces map[ports.WindowID]ports.SurfaceContent) (fb uint32, c ports.SurfaceContent, mode colorMode) {
213	reason := "disabled"
214	if o.scanout {
215		c, reason = scanoutCandidate(scene, surfaces, o.Width(), o.Height(), o.kept)
216		if reason == "" {
217			mode, reason = planeColor(c.Color, c.DMABuf.Format, c.Opaque, o.hdr.on, o.primary.pipeline)
218		}
219	}
220	if reason == "" {
221		fb, reason = o.scanoutFB(c.DMABuf, time.Now())
222		if reason == "" {
223			rect := scanoutRect(c, o.Width(), o.Height())
224			cfb := o.clientFBs[c.DMABuf.ID]
225			if cfb.scaleRefused && cfb.scaleFailed == rect {
226				reason = "scale_refused"
227			} else if rect != fullPlaneRect(o.Width(), o.Height()) && (!cfb.scaleTestedOK || cfb.scaleTested != rect) {
228				req := &o.probeReq
229				req.reset()
230				o.primaryRectProps(req, fb, rect)
231				if err := o.k.commit(req, atomicTestOnly, 0); err != nil {
232					cfb.scaleFailed = rect
233					cfb.scaleRefused = true
234					reason = "scale_refused"
235					o.renderLog.Info().Err(err).Str("reason", reason).Str("connector", o.conn.name).Msg("scanout scaling refused")
236				} else {
237					cfb.scaleTested = rect
238					cfb.scaleTestedOK = true
239				}
240			}
241			if reason == "" && mode != colorBypass && !o.colorAllowed(o.primary, c.DMABuf.Format, func(req *atomicReq) {
242				o.primaryRectProps(req, fb, rect)
243				if o.overlayOn != 0 {
244					o.overlayProps(req, overlayWin{})
245				}
246			}) {
247				reason = "color_refused"
248			}
249		}
250	}
251	o.setScanoutReason(reason)
252	if reason != "" {
253		return 0, c, colorBypass
254	}
255	return fb, c, mode
256}
257
258// overlayFrame decides the overlay of a frame: the window, and the scene
259// the renderer composes (the window left out). A zero overlayWin means
260// none; the reason is logged on change. The returned scene's Windows is
261// valid until the next call: it reuses o.restWindows (its consumers, Render,
262// ExcludedScene and the capture tracking, run synchronously before then).
263func (o *Output) overlayFrame(s ports.Scene, surfaces map[ports.WindowID]ports.SurfaceContent) (overlayWin, ports.Scene) {
264	reason := "no_plane"
265	var ov overlayWin
266	if o.overlay != nil && o.scanout {
267		var w ports.SceneWindow
268		var c ports.SurfaceContent
269		var mode colorMode
270		w, c, mode, reason = overlayCandidate(s, surfaces, o.hdr.on, o.overlay.pipeline, o.kept)
271		if reason == "" && mode != colorBypass {
272			if ok, known := o.overlay.verdict(c.DMABuf.Format, o.cursorShown()); known && !ok {
273				reason = "color_refused"
274			}
275		}
276		if reason == "" {
277			var fb uint32
278			if fb, reason = o.overlayFB(c.DMABuf, time.Now()); reason == "" {
279				scale := s.Scale
280				if scale <= 0 {
281					scale = 1
282				}
283				ov = overlayWin{id: w.ID, fb: fb, buf: c.DMABuf.ID, w: c.Width, h: c.Height,
284					rect:    ports.Rect{X: int(float64(w.Rect.X) * scale), Y: int(float64(w.Rect.Y) * scale), W: c.Width, H: c.Height},
285					acquire: dupFence(c.Acquire), color: colorUse{mode: mode, format: c.DMABuf.Format}}
286			}
287		}
288	}
289	o.setOverlayReason(reason)
290	if ov.id == 0 {
291		return overlayWin{}, s
292	}
293	// The composed frame leaves the window out: the overlay shows it.
294	rest := s
295	o.restWindows = o.restWindows[:0]
296	for _, w := range s.Windows {
297		if w.ID != ov.id {
298			o.restWindows = append(o.restWindows, w)
299		}
300	}
301	rest.Windows = o.restWindows
302	return ov, rest
303}
304
305// frameDecision selects the zero-copy path or the scene to compose.
306type frameDecision struct {
307	fb       uint32
308	content  ports.SurfaceContent
309	rect     planeRect
310	color    colorMode // how the primary plane shows fb
311	overlay  overlayWin
312	composed ports.Scene
313}
314
315// composeFrame chooses overlay or composition after direct scanout cannot commit.
316// The caller owns the returned overlay fence.
317func (o *Output) composeFrame(s ports.Scene, surfaces map[ports.WindowID]ports.SurfaceContent) frameDecision {
318	ov, rest := o.overlayFrame(s, surfaces)
319	if ov.fb != 0 {
320		return frameDecision{overlay: ov, composed: rest}
321	}
322	return frameDecision{composed: s}
323}
324
325// decideFrame tries direct scanout, then overlay, then composition.
326// Captures require composition; the caller owns the returned overlay fence.
327func (o *Output) decideFrame(s ports.Scene, surfaces map[ports.WindowID]ports.SurfaceContent, capture bool) frameDecision {
328	if capture {
329		o.setScanoutReason("capture")
330		o.setOverlayReason("capture")
331		return frameDecision{composed: s}
332	}
333	fb, c, mode := o.scanoutFrame(s, surfaces)
334	if fb != 0 {
335		return frameDecision{fb: fb, content: c, rect: scanoutRect(c, o.Width(), o.Height()), color: mode}
336	}
337	return o.composeFrame(s, surfaces)
338}
339
340// setScanoutReason logs a direct-scanout transition once.
341func (o *Output) setScanoutReason(reason string) {
342	if reason != o.reason {
343		o.renderLog.Info().Bool("direct_scanout", reason == "").Str("reason", reason).Str("connector", o.conn.name).Msg("scanout")
344		o.reason = reason
345	}
346}
347
348// setOverlayReason logs an overlay transition once.
349func (o *Output) setOverlayReason(reason string) {
350	if reason != o.overlayReason {
351		o.renderLog.Info().Bool("overlay", reason == "").Str("reason", reason).Str("connector", o.conn.name).Msg("overlay")
352		o.overlayReason = reason
353	}
354}
355
356// clientFB is a client buffer imported as a KMS framebuffer.
357type clientFB struct {
358	fbID uint32
359	last time.Time // when last wanted on screen
360	// failed is the reason KMS refused the buffer; it is not retried.
361	failed string
362	// noAsync: KMS refused an async flip to it; it flips at vblank.
363	noAsync                     bool
364	scaleTested, scaleFailed    planeRect
365	scaleRefused, scaleTestedOK bool
366	// overlayFailed is why the overlay plane refused it; kept apart from
367	// failed, so a refusal on one plane does not bar the other.
368	overlayFailed string
369	importErr     bool
370}
371
372// scanoutFB returns the framebuffer of a client buffer for the primary
373// plane, importing it on first use. A buffer KMS refuses is remembered
374// with its reason.
375func (o *Output) scanoutFB(b *ports.DMABuf, now time.Time) (uint32, string) {
376	return o.planeFB(o.primary, b, now, func(fb *clientFB) *string { return &fb.failed })
377}
378
379// overlayFB is scanoutFB for the overlay plane, with its own formats and
380// refusal reason.
381func (o *Output) overlayFB(b *ports.DMABuf, now time.Time) (uint32, string) {
382	return o.planeFB(o.overlay, b, now, func(fb *clientFB) *string { return &fb.overlayFailed })
383}
384
385// planeFB imports b once as a framebuffer; reason is the plane's refusal
386// field. Both planes share the framebuffer: they show the same format.
387func (o *Output) planeFB(p *plane, b *ports.DMABuf, now time.Time, reason func(*clientFB) *string) (uint32, string) {
388	fb := o.clientFBs[b.ID]
389	if fb == nil {
390		fb = &clientFB{}
391		o.clientFBs[b.ID] = fb
392	}
393	fb.last = now
394	why := reason(fb)
395	if *why != "" {
396		return 0, *why
397	}
398	format, ok := planeFormat(p, b)
399	if !ok {
400		*why = "format"
401		return 0, *why
402	}
403	if fb.fbID == 0 {
404		if fb.importErr {
405			*why = "import_failed"
406			return 0, *why
407		}
408		id, err := o.k.addFB(b, format)
409		if err != nil {
410			o.renderLog.Info().Err(err).Uint32("format", b.Format).Uint64("modifier", b.Modifier).Msg("scanout import failed")
411			fb.importErr, *why = true, "import_failed"
412			return 0, *why
413		}
414		fb.fbID = id
415	}
416	return fb.fbID, ""
417}
418
419// scanoutFormat is the framebuffer format a client buffer is scanned out
420// as on the primary plane (see planeFormat).
421func (o *Output) scanoutFormat(b *ports.DMABuf) (uint32, bool) { return planeFormat(o.primary, b) }
422
423// planeFormat is the framebuffer format a client buffer shows as on p,
424// when p lists it with the buffer's modifier. Planes here show no alpha:
425// an alpha format goes as its X variant when the plane has that one.
426func planeFormat(p *plane, b *ports.DMABuf) (uint32, bool) {
427	has := func(f uint32) bool {
428		return slices.Contains(p.formats, ports.DMABufFormat{Format: f, Modifier: b.Modifier})
429	}
430	if x, ok := opaqueVariant[b.Format]; ok && has(x) {
431		return x, true
432	}
433	return b.Format, has(b.Format)
434}
435
436// opaqueVariant maps alpha formats to the same layout without alpha.
437var opaqueVariant = map[uint32]uint32{
438	fourccARGB: fourccXRGB,
439	fourccABGR: fourccXBGR,
440	fourccAR30: fourccXR30,
441	fourccAB30: fourccXB30,
442	fourccAR4H: fourccXR4H,
443	fourccAB4H: fourccXB4H,
444}
445
446// scanoutFormats are the formats a buffer can be scanned out with: in the
447// primary plane's IN_FORMATS (directly or as its opaque variant) and
448// composable by the renderer.
449func (o *Output) scanoutFormats(sampled []ports.DMABufFormat) []ports.DMABufFormat {
450	var out []ports.DMABufFormat
451	for _, f := range sampled {
452		b := ports.DMABuf{Format: f.Format, Modifier: f.Modifier}
453		if _, ok := o.scanoutFormat(&b); ok {
454			out = append(out, f)
455		}
456	}
457	return out
458}
459
460// isYUVFormat identifies video formats which are always composed, never scanned out.
461func isYUVFormat(format uint32) bool {
462	return format == fourccNV12 || format == fourccP010
463}
464
465// isTenBit identifies the packed 2101010 formats supported by the renderer.
466func isTenBit(format uint32) bool {
467	switch format {
468	case fourccXR30, fourccAR30, fourccXB30, fourccAB30:
469		return true
470	}
471	return false
472}
473
474const (
475	fourccNV12 = 'N' | 'V'<<8 | '1'<<16 | '2'<<24
476	fourccP010 = 'P' | '0'<<8 | '1'<<16 | '0'<<24
477	fourccXRGB = 'X' | 'R'<<8 | '2'<<16 | '4'<<24
478	fourccARGB = 'A' | 'R'<<8 | '2'<<16 | '4'<<24
479	fourccXBGR = 'X' | 'B'<<8 | '2'<<16 | '4'<<24
480	fourccABGR = 'A' | 'B'<<8 | '2'<<16 | '4'<<24
481	fourccXR30 = 'X' | 'R'<<8 | '3'<<16 | '0'<<24
482	fourccAR30 = 'A' | 'R'<<8 | '3'<<16 | '0'<<24
483	fourccXB30 = 'X' | 'B'<<8 | '3'<<16 | '0'<<24
484	fourccAB30 = 'A' | 'B'<<8 | '3'<<16 | '0'<<24
485	fourccXR4H = 'X' | 'R'<<8 | '4'<<16 | 'H'<<24
486	fourccAR4H = 'A' | 'R'<<8 | '4'<<16 | 'H'<<24
487	fourccXB4H = 'X' | 'B'<<8 | '4'<<16 | 'H'<<24
488	fourccAB4H = 'A' | 'B'<<8 | '4'<<16 | 'H'<<24
489)
490
491// addFB imports a dmabuf as a framebuffer of the given fourcc: client buffers, the renderer's
492// output images and cursor images. The GEM handle belongs to the card fd
493// and is shared by every import of the same buffer, so import, ADDFB2 and
494// close run under the lock and the handle is closed right away: the
495// framebuffer keeps its own reference to the buffer.
496func (k kmsDevice) addFB(b *ports.DMABuf, format uint32) (uint32, error) {
497	raw, err := b.Planes[0].File.SyscallConn()
498	if err != nil {
499		return 0, err
500	}
501	k.gemMu.Lock()
502	defer k.gemMu.Unlock()
503	var p primeHandle
504	var ioErr error
505	if err := raw.Control(func(fd uintptr) {
506		p.fd = int32(fd)
507		ioErr = ioctl(k.fd, ioctlPrimeFDToHandle, unsafe.Pointer(&p))
508	}); err != nil {
509		return 0, err
510	}
511	if ioErr != nil {
512		return 0, errors.Join(errors.New("prime import"), ioErr)
513	}
514	defer func() {
515		g := gemClose{handle: p.handle}
516		_ = ioctl(k.fd, ioctlGemClose, unsafe.Pointer(&g))
517	}()
518	cmd := fbCmd2{width: uint32(b.Width), height: uint32(b.Height), format: format}
519	useMod := b.Modifier != modInvalid && (b.Modifier != 0 || k.modifiers)
520	if useMod {
521		cmd.flags = fbModifiers
522	}
523	// Planes in the same dmabuf share its GEM handle: each distinct
524	// handle is closed once.
525	closing := map[uint32]bool{p.handle: true}
526	for i, pl := range b.Planes {
527		if i >= len(cmd.handles) {
528			break
529		}
530		h := p.handle
531		if i > 0 {
532			var err error
533			if h, err = k.primeImport(pl.File); err != nil {
534				return 0, err
535			}
536			if !closing[h] {
537				closing[h] = true
538				defer k.gemClose(h)
539			}
540		}
541		cmd.handles[i], cmd.pitches[i], cmd.offsets[i] = h, pl.Stride, pl.Offset
542		if useMod {
543			cmd.modifiers[i] = b.Modifier
544		}
545	}
546	if err := ioctl(k.fd, ioctlAddFB2, unsafe.Pointer(&cmd)); err != nil {
547		return 0, errors.Join(errors.New("add fb2"), err)
548	}
549	return cmd.fbID, nil
550}
551
552// primeImport returns the GEM handle of a dmabuf file. The caller holds
553// gemMu and closes the handle.
554func (k kmsDevice) primeImport(f *os.File) (uint32, error) {
555	raw, err := f.SyscallConn()
556	if err != nil {
557		return 0, err
558	}
559	var p primeHandle
560	var ioErr error
561	if err := raw.Control(func(fd uintptr) {
562		p.fd = int32(fd)
563		ioErr = ioctl(k.fd, ioctlPrimeFDToHandle, unsafe.Pointer(&p))
564	}); err != nil {
565		return 0, err
566	}
567	if ioErr != nil {
568		return 0, errors.Join(errors.New("prime import"), ioErr)
569	}
570	return p.handle, nil
571}
572
573func (k kmsDevice) gemClose(h uint32) {
574	g := gemClose{handle: h}
575	_ = ioctl(k.fd, ioctlGemClose, unsafe.Pointer(&g))
576}
577
578// dropClientFBs frees framebuffers not wanted for scanoutIdleTTL, or all
579// of them, except those on screen or queued.
580func (o *Output) dropClientFBs(now time.Time, all bool) {
581	for id, fb := range o.clientFBs {
582		if id == o.shown || id == o.queued {
583			continue
584		}
585		if !all && now.Sub(fb.last) < scanoutIdleTTL {
586			continue
587		}
588		if fb.fbID != 0 {
589			_ = o.k.rmFB(fb.fbID)
590			// KMS may give the id to another buffer.
591			o.forgetOverlayProbes()
592		}
593		delete(o.clientFBs, id)
594	}
595}
596
597// dupFence duplicates a sync file under its SyscallConn, so a concurrent
598// Close cannot hand us a reused fd; nil when f is nil or closed.
599func dupFence(f *os.File) *os.File {
600	if f == nil {
601		return nil
602	}
603	raw, err := f.SyscallConn()
604	if err != nil {
605		return nil
606	}
607	fd := -1
608	if raw.Control(func(v uintptr) { fd, _ = unix.FcntlInt(v, unix.F_DUPFD_CLOEXEC, 0) }) != nil || fd < 0 {
609		return nil
610	}
611	return os.NewFile(uintptr(fd), "acquire-fence")
612}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 25

Tags 10

↑↓ moveenter openesc close