~emersion/go-drm

ref: c0c2450906d94f52d69c264e485731cbaf1a63f4 go-drm/fourcc.go -rw-r--r-- 900 bytes
c0c24509Simon Ser Improve format/modifier pretty-printing a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package drm

//go:generate ./fourcc.py

import (
	"fmt"
	"strings"
)

type Format uint32

func (f Format) Name() string {
	if name := f.str(); name != "" {
		return name
	}
	return "unknown"
}

func (f Format) String() string {
	return fmt.Sprintf("%s (0x%X)", f.Name(), uint32(f))
}

type ModifierVendor uint8

func (vendor ModifierVendor) String() string {
	if name := vendor.str(); name != "" {
		return name
	}
	return "unknown"
}

type Modifier uint64

func (mod Modifier) Vendor() ModifierVendor {
	return ModifierVendor(mod >> 56)
}

func (mod Modifier) Name() string {
	// TODO: parse complicated modifiers
	if name := mod.str(); name != "" {
		return name
	}
	if vendor := mod.Vendor().str(); vendor != "" {
		return fmt.Sprintf("%s(unknown)", strings.ToUpper(vendor))
	}
	return "unknown"
}

func (mod Modifier) String() string {
	return fmt.Sprintf("%s (0x%X)", mod.Name(), uint64(mod))
}