-
Notifications
You must be signed in to change notification settings - Fork 13
/
swap_chain_windows.go
164 lines (151 loc) · 3.84 KB
/
swap_chain_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
package d3d9
import (
"syscall"
"unsafe"
)
// SwapChain and its methods are used to manipulate a swap chain.
type SwapChain struct {
vtbl *swapChainVtbl
}
type swapChainVtbl struct {
QueryInterface uintptr
AddRef uintptr
Release uintptr
Present uintptr
GetFrontBufferData uintptr
GetBackBuffer uintptr
GetRasterStatus uintptr
GetDisplayMode uintptr
GetDevice uintptr
GetPresentParameters 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 *SwapChain) 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 *SwapChain) Release() uint32 {
ret, _, _ := syscall.Syscall(
obj.vtbl.Release,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return uint32(ret)
}
// Present presents the contents of the next buffer in the sequence of back
// buffers owned by the swap chain.
func (obj *SwapChain) Present(
sourceRect *RECT,
destRect *RECT,
destWindowOverride HWND,
dirtyRegion *RGNDATA,
flags uint32,
) Error {
ret, _, _ := syscall.Syscall6(
obj.vtbl.Present,
6,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(sourceRect)),
uintptr(unsafe.Pointer(destRect)),
uintptr(destWindowOverride),
uintptr(unsafe.Pointer(dirtyRegion)),
uintptr(flags),
)
return toErr(ret)
}
// GetFrontBufferData generates a copy of the swapchain's front buffer and
// places that copy in a system memory buffer provided by the application.
// Call Release on the returned surface when finished using it.
func (obj *SwapChain) GetFrontBufferData(destSurface *Surface) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetFrontBufferData,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(destSurface)),
0,
)
return toErr(ret)
}
// GetBackBuffer retrieves a back buffer from the swap chain of the device.
// Call Release on the returned surface when finished using it.
func (obj *SwapChain) GetBackBuffer(
backBuffer uint,
typ BACKBUFFER_TYPE,
) (buffer *Surface, err Error) {
ret, _, _ := syscall.Syscall6(
obj.vtbl.GetBackBuffer,
4,
uintptr(unsafe.Pointer(obj)),
uintptr(backBuffer),
uintptr(typ),
uintptr(unsafe.Pointer(&buffer)),
0,
0,
)
err = toErr(ret)
return
}
// GetRasterStatus returns information describing the raster of the monitor on
// which the swap chain is presented.
func (obj *SwapChain) GetRasterStatus() (status RASTER_STATUS, err Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetRasterStatus,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&status)),
0,
)
err = toErr(ret)
return
}
// GetDisplayMode retrieves the display mode's spatial resolution, color
// resolution, and refresh frequency.
func (obj *SwapChain) GetDisplayMode() (mode DISPLAYMODE, err Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetDisplayMode,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&mode)),
0,
)
err = toErr(ret)
return
}
// GetDevice retrieves the device associated with the swap chain.
// Call Release on the returned device when finished using it.
func (obj *SwapChain) 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
}
// GetPresentParameters retrieves the presentation parameters associated with a
// swap chain.
func (obj *SwapChain) GetPresentParameters() (params PRESENT_PARAMETERS, err Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetPresentParameters,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(¶ms)),
0,
)
err = toErr(ret)
return
}