go-tg-screenshot-bot

Форк
0
302 строки · 7.2 Кб
1
// Copyright 2011 The win Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4

5
// +build windows
6

7
package win
8

9
import (
10
	"golang.org/x/sys/windows"
11
	"syscall"
12
	"unsafe"
13
)
14

15
// for second parameter of WglSwapLayerBuffers
16
const (
17
	WGL_SWAP_MAIN_PLANE = (1 << 0)
18
	WGL_SWAP_OVERLAY1   = (1 << 1)
19
	WGL_SWAP_OVERLAY2   = (1 << 2)
20
	WGL_SWAP_OVERLAY3   = (1 << 3)
21
	WGL_SWAP_OVERLAY4   = (1 << 4)
22
	WGL_SWAP_OVERLAY5   = (1 << 5)
23
	WGL_SWAP_OVERLAY6   = (1 << 6)
24
	WGL_SWAP_OVERLAY7   = (1 << 7)
25
	WGL_SWAP_OVERLAY8   = (1 << 8)
26
	WGL_SWAP_OVERLAY9   = (1 << 9)
27
	WGL_SWAP_OVERLAY10  = (1 << 10)
28
	WGL_SWAP_OVERLAY11  = (1 << 11)
29
	WGL_SWAP_OVERLAY12  = (1 << 12)
30
	WGL_SWAP_OVERLAY13  = (1 << 13)
31
	WGL_SWAP_OVERLAY14  = (1 << 14)
32
	WGL_SWAP_OVERLAY15  = (1 << 15)
33
	WGL_SWAP_UNDERLAY1  = (1 << 16)
34
	WGL_SWAP_UNDERLAY2  = (1 << 17)
35
	WGL_SWAP_UNDERLAY3  = (1 << 18)
36
	WGL_SWAP_UNDERLAY4  = (1 << 19)
37
	WGL_SWAP_UNDERLAY5  = (1 << 20)
38
	WGL_SWAP_UNDERLAY6  = (1 << 21)
39
	WGL_SWAP_UNDERLAY7  = (1 << 22)
40
	WGL_SWAP_UNDERLAY8  = (1 << 23)
41
	WGL_SWAP_UNDERLAY9  = (1 << 24)
42
	WGL_SWAP_UNDERLAY10 = (1 << 25)
43
	WGL_SWAP_UNDERLAY11 = (1 << 26)
44
	WGL_SWAP_UNDERLAY12 = (1 << 27)
45
	WGL_SWAP_UNDERLAY13 = (1 << 28)
46
	WGL_SWAP_UNDERLAY14 = (1 << 29)
47
	WGL_SWAP_UNDERLAY15 = (1 << 30)
48
)
49

50
type (
51
	HGLRC HANDLE
52
)
53

54
type LAYERPLANEDESCRIPTOR struct {
55
	NSize           uint16
56
	NVersion        uint16
57
	DwFlags         uint32
58
	IPixelType      uint8
59
	CColorBits      uint8
60
	CRedBits        uint8
61
	CRedShift       uint8
62
	CGreenBits      uint8
63
	CGreenShift     uint8
64
	CBlueBits       uint8
65
	CBlueShift      uint8
66
	CAlphaBits      uint8
67
	CAlphaShift     uint8
68
	CAccumBits      uint8
69
	CAccumRedBits   uint8
70
	CAccumGreenBits uint8
71
	CAccumBlueBits  uint8
72
	CAccumAlphaBits uint8
73
	CDepthBits      uint8
74
	CStencilBits    uint8
75
	CAuxBuffers     uint8
76
	ILayerType      uint8
77
	BReserved       uint8
78
	CrTransparent   COLORREF
79
}
80

81
type POINTFLOAT struct {
82
	X, Y float32
83
}
84

85
type GLYPHMETRICSFLOAT struct {
86
	GmfBlackBoxX     float32
87
	GmfBlackBoxY     float32
88
	GmfptGlyphOrigin POINTFLOAT
89
	GmfCellIncX      float32
90
	GmfCellIncY      float32
91
}
92

93
var (
94
	// Library
95
	lib *windows.LazyDLL
96

97
	// Functions
98
	wglCopyContext            *windows.LazyProc
99
	wglCreateContext          *windows.LazyProc
100
	wglCreateLayerContext     *windows.LazyProc
101
	wglDeleteContext          *windows.LazyProc
102
	wglDescribeLayerPlane     *windows.LazyProc
103
	wglGetCurrentContext      *windows.LazyProc
104
	wglGetCurrentDC           *windows.LazyProc
105
	wglGetLayerPaletteEntries *windows.LazyProc
106
	wglGetProcAddress         *windows.LazyProc
107
	wglMakeCurrent            *windows.LazyProc
108
	wglRealizeLayerPalette    *windows.LazyProc
109
	wglSetLayerPaletteEntries *windows.LazyProc
110
	wglShareLists             *windows.LazyProc
111
	wglSwapLayerBuffers       *windows.LazyProc
112
	wglUseFontBitmaps         *windows.LazyProc
113
	wglUseFontOutlines        *windows.LazyProc
114
)
115

116
func init() {
117
	// Library
118
	lib = windows.NewLazySystemDLL("opengl32.dll")
119

120
	// Functions
121
	wglCopyContext = lib.NewProc("wglCopyContext")
122
	wglCreateContext = lib.NewProc("wglCreateContext")
123
	wglCreateLayerContext = lib.NewProc("wglCreateLayerContext")
124
	wglDeleteContext = lib.NewProc("wglDeleteContext")
125
	wglDescribeLayerPlane = lib.NewProc("wglDescribeLayerPlane")
126
	wglGetCurrentContext = lib.NewProc("wglGetCurrentContext")
127
	wglGetCurrentDC = lib.NewProc("wglGetCurrentDC")
128
	wglGetLayerPaletteEntries = lib.NewProc("wglGetLayerPaletteEntries")
129
	wglGetProcAddress = lib.NewProc("wglGetProcAddress")
130
	wglMakeCurrent = lib.NewProc("wglMakeCurrent")
131
	wglRealizeLayerPalette = lib.NewProc("wglRealizeLayerPalette")
132
	wglSetLayerPaletteEntries = lib.NewProc("wglSetLayerPaletteEntries")
133
	wglShareLists = lib.NewProc("wglShareLists")
134
	wglSwapLayerBuffers = lib.NewProc("wglSwapLayerBuffers")
135
	wglUseFontBitmaps = lib.NewProc("wglUseFontBitmapsW")
136
	wglUseFontOutlines = lib.NewProc("wglUseFontOutlinesW")
137
}
138

139
func WglCopyContext(hglrcSrc, hglrcDst HGLRC, mask uint) bool {
140
	ret, _, _ := syscall.Syscall(wglCopyContext.Addr(), 3,
141
		uintptr(hglrcSrc),
142
		uintptr(hglrcDst),
143
		uintptr(mask))
144

145
	return ret != 0
146
}
147

148
func WglCreateContext(hdc HDC) HGLRC {
149
	ret, _, _ := syscall.Syscall(wglCreateContext.Addr(), 1,
150
		uintptr(hdc),
151
		0,
152
		0)
153

154
	return HGLRC(ret)
155
}
156

157
func WglCreateLayerContext(hdc HDC, iLayerPlane int) HGLRC {
158
	ret, _, _ := syscall.Syscall(wglCreateLayerContext.Addr(), 2,
159
		uintptr(hdc),
160
		uintptr(iLayerPlane),
161
		0)
162

163
	return HGLRC(ret)
164
}
165

166
func WglDeleteContext(hglrc HGLRC) bool {
167
	ret, _, _ := syscall.Syscall(wglDeleteContext.Addr(), 1,
168
		uintptr(hglrc),
169
		0,
170
		0)
171

172
	return ret != 0
173
}
174

175
func WglDescribeLayerPlane(hdc HDC, iPixelFormat, iLayerPlane int, nBytes uint8, plpd *LAYERPLANEDESCRIPTOR) bool {
176
	ret, _, _ := syscall.Syscall6(wglDescribeLayerPlane.Addr(), 5,
177
		uintptr(hdc),
178
		uintptr(iPixelFormat),
179
		uintptr(iLayerPlane),
180
		uintptr(nBytes),
181
		uintptr(unsafe.Pointer(plpd)),
182
		0)
183

184
	return ret != 0
185
}
186

187
func WglGetCurrentContext() HGLRC {
188
	ret, _, _ := syscall.Syscall(wglGetCurrentContext.Addr(), 0,
189
		0,
190
		0,
191
		0)
192

193
	return HGLRC(ret)
194
}
195

196
func WglGetCurrentDC() HDC {
197
	ret, _, _ := syscall.Syscall(wglGetCurrentDC.Addr(), 0,
198
		0,
199
		0,
200
		0)
201

202
	return HDC(ret)
203
}
204

205
func WglGetLayerPaletteEntries(hdc HDC, iLayerPlane, iStart, cEntries int, pcr *COLORREF) int {
206
	ret, _, _ := syscall.Syscall6(wglGetLayerPaletteEntries.Addr(), 5,
207
		uintptr(hdc),
208
		uintptr(iLayerPlane),
209
		uintptr(iStart),
210
		uintptr(cEntries),
211
		uintptr(unsafe.Pointer(pcr)),
212
		0)
213

214
	return int(ret)
215
}
216

217
func WglGetProcAddress(lpszProc *byte) uintptr {
218
	ret, _, _ := syscall.Syscall(wglGetProcAddress.Addr(), 1,
219
		uintptr(unsafe.Pointer(lpszProc)),
220
		0,
221
		0)
222

223
	return uintptr(ret)
224
}
225

226
func WglMakeCurrent(hdc HDC, hglrc HGLRC) bool {
227
	ret, _, _ := syscall.Syscall(wglMakeCurrent.Addr(), 2,
228
		uintptr(hdc),
229
		uintptr(hglrc),
230
		0)
231

232
	return ret != 0
233
}
234

235
func WglRealizeLayerPalette(hdc HDC, iLayerPlane int, bRealize bool) bool {
236
	ret, _, _ := syscall.Syscall(wglRealizeLayerPalette.Addr(), 3,
237
		uintptr(hdc),
238
		uintptr(iLayerPlane),
239
		uintptr(BoolToBOOL(bRealize)))
240

241
	return ret != 0
242
}
243

244
func WglSetLayerPaletteEntries(hdc HDC, iLayerPlane, iStart, cEntries int, pcr *COLORREF) int {
245
	ret, _, _ := syscall.Syscall6(wglSetLayerPaletteEntries.Addr(), 5,
246
		uintptr(hdc),
247
		uintptr(iLayerPlane),
248
		uintptr(iStart),
249
		uintptr(cEntries),
250
		uintptr(unsafe.Pointer(pcr)),
251
		0)
252

253
	return int(ret)
254
}
255

256
func WglShareLists(hglrc1, hglrc2 HGLRC) bool {
257
	ret, _, _ := syscall.Syscall(wglShareLists.Addr(), 2,
258
		uintptr(hglrc1),
259
		uintptr(hglrc2),
260
		0)
261

262
	return ret != 0
263
}
264

265
func WglSwapLayerBuffers(hdc HDC, fuPlanes uint) bool {
266
	ret, _, _ := syscall.Syscall(wglSwapLayerBuffers.Addr(), 2,
267
		uintptr(hdc),
268
		uintptr(fuPlanes),
269
		0)
270

271
	return ret != 0
272
}
273

274
func WglUseFontBitmaps(hdc HDC, first, count, listbase uint32) bool {
275
	ret, _, _ := syscall.Syscall6(wglUseFontBitmaps.Addr(), 4,
276
		uintptr(hdc),
277
		uintptr(first),
278
		uintptr(count),
279
		uintptr(listbase),
280
		0,
281
		0)
282

283
	return ret != 0
284
}
285

286
func WglUseFontOutlines(hdc HDC, first, count, listbase uint32, deviation, extrusion float32, format int, pgmf *GLYPHMETRICSFLOAT) bool {
287
	ret, _, _ := syscall.Syscall12(wglUseFontBitmaps.Addr(), 8,
288
		uintptr(hdc),
289
		uintptr(first),
290
		uintptr(count),
291
		uintptr(listbase),
292
		uintptr(deviation),
293
		uintptr(extrusion),
294
		uintptr(format),
295
		uintptr(unsafe.Pointer(pgmf)),
296
		0,
297
		0,
298
		0,
299
		0)
300

301
	return ret != 0
302
}
303

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.