forked from Code-Hex/vz
-
Notifications
You must be signed in to change notification settings - Fork 1
/
graphics_arm64.go
84 lines (73 loc) · 2.61 KB
/
graphics_arm64.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
//go:build darwin && arm64
// +build darwin,arm64
package vz
/*
#cgo darwin CFLAGS: -mmacosx-version-min=11 -x objective-c -fno-objc-arc
#cgo darwin LDFLAGS: -lobjc -framework Foundation -framework Virtualization
# include "virtualization_12_arm64.h"
*/
import "C"
import (
"github.com/Code-Hex/vz/v3/internal/objc"
)
// MacGraphicsDeviceConfiguration is a configuration for a display attached to a Mac graphics device.
type MacGraphicsDeviceConfiguration struct {
*pointer
*baseGraphicsDeviceConfiguration
}
var _ GraphicsDeviceConfiguration = (*MacGraphicsDeviceConfiguration)(nil)
// NewMacGraphicsDeviceConfiguration creates a new MacGraphicsDeviceConfiguration.
//
// This is only supported on macOS 12 and newer, error will
// be returned on older versions.
func NewMacGraphicsDeviceConfiguration() (*MacGraphicsDeviceConfiguration, error) {
if err := macOSAvailable(12); err != nil {
return nil, err
}
graphicsConfiguration := &MacGraphicsDeviceConfiguration{
pointer: objc.NewPointer(
C.newVZMacGraphicsDeviceConfiguration(),
),
}
objc.SetFinalizer(graphicsConfiguration, func(self *MacGraphicsDeviceConfiguration) {
objc.Release(self)
})
return graphicsConfiguration, nil
}
// SetDisplays sets the displays associated with this graphics device.
func (m *MacGraphicsDeviceConfiguration) SetDisplays(displayConfigs ...*MacGraphicsDisplayConfiguration) {
ptrs := make([]objc.NSObject, len(displayConfigs))
for i, val := range displayConfigs {
ptrs[i] = val
}
array := objc.ConvertToNSMutableArray(ptrs)
C.setDisplaysVZMacGraphicsDeviceConfiguration(objc.Ptr(m), objc.Ptr(array))
}
// MacGraphicsDisplayConfiguration is the configuration for a Mac graphics device.
type MacGraphicsDisplayConfiguration struct {
*pointer
}
// NewMacGraphicsDisplayConfiguration creates a new MacGraphicsDisplayConfiguration.
//
// Creates a display configuration with the specified pixel dimensions and pixel density.
//
// This is only supported on macOS 12 and newer, error will
// be returned on older versions.
func NewMacGraphicsDisplayConfiguration(widthInPixels int64, heightInPixels int64, pixelsPerInch int64) (*MacGraphicsDisplayConfiguration, error) {
if err := macOSAvailable(12); err != nil {
return nil, err
}
graphicsDisplayConfiguration := &MacGraphicsDisplayConfiguration{
pointer: objc.NewPointer(
C.newVZMacGraphicsDisplayConfiguration(
C.NSInteger(widthInPixels),
C.NSInteger(heightInPixels),
C.NSInteger(pixelsPerInch),
),
),
}
objc.SetFinalizer(graphicsDisplayConfiguration, func(self *MacGraphicsDisplayConfiguration) {
objc.Release(self)
})
return graphicsDisplayConfiguration, nil
}