-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdxgi.go
40 lines (36 loc) · 792 Bytes
/
dxgi.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
// dxgi.go
package main
import (
"context"
"fmt"
"image"
"time"
"github.com/kirides/screencapture/d3d"
)
func DxgiCapture(ctx context.Context, c chan image.Image) {
device, deviceCtx, err := d3d.NewD3D11Device()
if err != nil {
fmt.Printf("Could not create D3D11 Device. %v\n", err)
return
}
defer device.Release()
defer deviceCtx.Release()
n := 1
ddup, err := d3d.NewIDXGIOutputDuplication(device, deviceCtx, uint(n))
if err != nil {
fmt.Printf("Err NewIDXGIOutputDuplication: %v\n", err)
return
}
defer ddup.Release()
ticker := time.NewTicker(1000 * time.Millisecond / time.Duration(fps))
img := image.NewRGBA(image.Rect(0, 0, RectW, RectH))
for range ticker.C {
select {
case <-ctx.Done():
return
default:
}
ddup.GetImage(img, 0)
c <- img
}
}