-
Notifications
You must be signed in to change notification settings - Fork 13
/
query_windows.go
119 lines (108 loc) · 2.28 KB
/
query_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
package d3d9
import (
"syscall"
"unsafe"
)
// Query and its methods are used to perform asynchronous queries on a driver.
type Query struct {
vtbl *queryVtbl
}
type queryVtbl struct {
QueryInterface uintptr
AddRef uintptr
Release uintptr
GetDevice uintptr
GetType uintptr
GetDataSize uintptr
Issue uintptr
GetData 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 *Query) 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 *Query) Release() uint32 {
ret, _, _ := syscall.Syscall(
obj.vtbl.Release,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return uint32(ret)
}
// GetDevice retrieves the associated device.
// Call Release on the returned device when finished using it.
func (obj *Query) 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
}
// GetType returns the query type.
func (obj *Query) GetType() QUERYTYPE {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetType,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return QUERYTYPE(ret)
}
// GetDataSize returns the number of bytes in the query data.
func (obj *Query) GetDataSize() uint32 {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetDataSize,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return uint32(ret)
}
// Issue issues a query.
func (obj *Query) Issue(issueFlags uint32) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.Issue,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(issueFlags),
0,
)
return toErr(ret)
}
// GetData polls a queried resource to get the query state or a query result.
func (obj *Query) GetData(data []byte, flags uint32) Error {
var dataPtr uintptr
if len(data) > 0 {
dataPtr = uintptr(unsafe.Pointer(&data[0]))
}
ret, _, _ := syscall.Syscall6(
obj.vtbl.GetData,
4,
uintptr(unsafe.Pointer(obj)),
dataPtr,
uintptr(len(data)),
uintptr(flags),
0,
0,
)
return toErr(ret)
}