~emersion/go-drm

go-drm/object.go -rw-r--r-- 2.6 KiB
7088ebfeSimon Ser Add support for Amlogic format modifiers 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package drm

import (
	"fmt"
)

type ObjectType uint32

const (
	ObjectAny       ObjectType = 0
	ObjectCRTC      ObjectType = 0xCCCCCCCC
	ObjectConnector ObjectType = 0xC0C0C0C0
	ObjectEncoder   ObjectType = 0xE0E0E0E0
	ObjectMode      ObjectType = 0xDEDEDEDE
	ObjectProperty  ObjectType = 0xB0B0B0B0
	ObjectFB        ObjectType = 0xFBFBFBFB
	ObjectBlob      ObjectType = 0xBBBBBBBB
	ObjectPlane     ObjectType = 0xEEEEEEEE
)

func (t ObjectType) String() string {
	switch t {
	case ObjectAny:
		return "any"
	case ObjectCRTC:
		return "CRTC"
	case ObjectConnector:
		return "connector"
	case ObjectEncoder:
		return "encoder"
	case ObjectMode:
		return "mode"
	case ObjectProperty:
		return "property"
	case ObjectFB:
		return "FB"
	case ObjectBlob:
		return "blob"
	case ObjectPlane:
		return "plane"
	default:
		return "unknown"
	}
}

type (
	ObjectID    uint32
	CRTCID      ObjectID
	ConnectorID ObjectID
	EncoderID   ObjectID
	ModeID      ObjectID
	PropertyID  ObjectID
	FBID        ObjectID
	BlobID      ObjectID
	PlaneID     ObjectID
)

type AnyID interface {
	Type() ObjectType
	Object() ObjectID
}

func NewAnyID(id ObjectID, t ObjectType) AnyID {
	switch t {
	case ObjectAny:
		return id
	case ObjectCRTC:
		return CRTCID(id)
	case ObjectConnector:
		return ConnectorID(id)
	case ObjectEncoder:
		return EncoderID(id)
	case ObjectMode:
		return ModeID(id)
	case ObjectProperty:
		return PropertyID(id)
	case ObjectFB:
		return FBID(id)
	case ObjectBlob:
		return BlobID(id)
	case ObjectPlane:
		return PlaneID(id)
	default:
		panic(fmt.Sprintf("drm: unknown object type %v", t))
	}
}

func (id ObjectID) Type() ObjectType {
	return ObjectAny
}

func (id ObjectID) Object() ObjectID {
	return id
}

func (id CRTCID) Type() ObjectType {
	return ObjectCRTC
}

func (id CRTCID) Object() ObjectID {
	return ObjectID(id)
}

func (id ConnectorID) Type() ObjectType {
	return ObjectConnector
}

func (id ConnectorID) Object() ObjectID {
	return ObjectID(id)
}

func (id EncoderID) Type() ObjectType {
	return ObjectEncoder
}

func (id EncoderID) Object() ObjectID {
	return ObjectID(id)
}

func (id ModeID) Type() ObjectType {
	return ObjectMode
}

func (id ModeID) Object() ObjectID {
	return ObjectID(id)
}

func (id PropertyID) Type() ObjectType {
	return ObjectProperty
}

func (id PropertyID) Object() ObjectID {
	return ObjectID(id)
}

func (id FBID) Type() ObjectType {
	return ObjectFB
}

func (id FBID) Object() ObjectID {
	return ObjectID(id)
}

func (id BlobID) Type() ObjectType {
	return ObjectBlob
}

func (id BlobID) Object() ObjectID {
	return ObjectID(id)
}

func (id PlaneID) Type() ObjectType {
	return ObjectPlane
}

func (id PlaneID) Object() ObjectID {
	return ObjectID(id)
}