forked from gonutz/d3d9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
volume_windows.go
206 lines (191 loc) · 4.37 KB
/
volume_windows.go
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package d3d9
import (
"syscall"
"unsafe"
)
// Volume and its methods are used to manipulate volume resources.
type Volume struct {
vtbl *volumeVtbl
}
type volumeVtbl struct {
QueryInterface uintptr
AddRef uintptr
Release uintptr
GetDevice uintptr
SetPrivateData uintptr
GetPrivateData uintptr
FreePrivateData uintptr
GetContainer uintptr
GetDesc uintptr
LockBox uintptr
UnlockBox uintptr
}
// AddRef increments the reference count for an interface on an object. This
// method should be called for every new copy of a pointer to an interface on an
// object.
func (obj *Volume) AddRef() uint32 {
ret, _, _ := syscall.Syscall(
obj.vtbl.AddRef,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return uint32(ret)
}
// Release has to be called when finished using the object to free its
// associated resources.
func (obj *Volume) Release() uint32 {
ret, _, _ := syscall.Syscall(
obj.vtbl.Release,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return uint32(ret)
}
// GetDevice retrieves the device associated with a volume.
func (obj *Volume) GetDevice() (device *Device, err Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetDevice,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&device)),
0,
)
err = toErr(ret)
return
}
// SetPrivateData associates data with the volume that is intended for use by
// the application, not by Direct3D.
func (obj *Volume) SetPrivateData(
refguid GUID,
data uintptr,
sizeOfData uint32,
flags uint32,
) Error {
ret, _, _ := syscall.Syscall6(
obj.vtbl.SetPrivateData,
5,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&refguid)),
data,
uintptr(sizeOfData),
uintptr(flags),
0,
)
return toErr(ret)
}
// SetPrivateDataInBytes associates data with the volume that is intended for
// use by the application, not by Direct3D.
func (obj Volume) SetPrivateDataInBytes(
refguid GUID,
data []byte,
flags uint32,
) Error {
return obj.SetPrivateData(
refguid,
uintptr(unsafe.Pointer(&data[0])),
uint32(len(data)),
flags,
)
}
// GetPrivateData copies the private data associated with the volume to a
// buffer.
func (obj *Volume) GetPrivateData(refguid GUID) (data []byte, err Error) {
// first get the buffer size by passing nil as the data pointer
var sizeInBytes uint
ret, _, _ := syscall.Syscall6(
obj.vtbl.GetPrivateData,
4,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&refguid)),
0,
uintptr(unsafe.Pointer(&sizeInBytes)),
0,
0,
)
if err := toErr(ret); err != nil {
return nil, err
}
data = make([]byte, sizeInBytes)
ret, _, _ = syscall.Syscall6(
obj.vtbl.GetPrivateData,
4,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&refguid)),
uintptr(unsafe.Pointer(&data[0])),
uintptr(unsafe.Pointer(&sizeInBytes)),
0,
0,
)
err = toErr(ret)
return
}
// FreePrivateData frees the specified private data associated with this volume.
func (obj *Volume) FreePrivateData(refguid GUID) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.FreePrivateData,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&refguid)),
0,
)
return toErr(ret)
}
// GetContainer provides access to the parent volume texture object, if this
// surface is a child level of a volume texture.
// Call Release on the returned volume texture when finished using it.
func (obj *Volume) GetContainer(riid GUID) (tex *VolumeTexture, err Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetContainer,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&riid)),
uintptr(unsafe.Pointer(tex)),
)
err = toErr(ret)
return
}
// GetDesc retrieves a description of the volume.
func (obj *Volume) GetDesc() (desc VOLUME_DESC, err Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetDesc,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&desc)),
0,
)
err = toErr(ret)
return
}
// LockBox locks a box on a volume resource.
func (obj *Volume) LockBox(
box *BOX,
flags uint32,
) (locked *LOCKED_BOX, err Error) {
ret, _, _ := syscall.Syscall6(
obj.vtbl.LockBox,
4,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&locked)),
uintptr(unsafe.Pointer(&box)),
uintptr(flags),
0,
0,
)
err = toErr(ret)
return
}
// UnlockBox unlocks a box on a volume resource.
func (obj *Volume) UnlockBox() Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.UnlockBox,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return toErr(ret)
}