~emersion/go-drm

c0c2450906d94f52d69c264e485731cbaf1a63f4 — Simon Ser 9 days ago 66aafcb
Improve format/modifier pretty-printing
1 files changed, 27 insertions(+), 10 deletions(-)

M fourcc.go
M fourcc.go => fourcc.go +27 -10
@@ 2,33 2,50 @@ package drm

//go:generate ./fourcc.py

import (
	"fmt"
	"strings"
)

type Format uint32

func (fmt Format) String() string {
	if s := fmt.str(); s != "" {
		return s
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 s := vendor.str(); s != "" {
		return s
	if name := vendor.str(); name != "" {
		return name
	}
	return "unknown"
}

type Modifier uint64

func (mod Modifier) String() string {
	if s := mod.str(); s != "" {
		return s
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) Vendor() ModifierVendor {
	return ModifierVendor(mod >> 56)
func (mod Modifier) String() string {
	return fmt.Sprintf("%s (0x%X)", mod.Name(), uint64(mod))
}