win

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Rendered for windows/amd64

Overview

Package win holds the minimal COM, DXGI, and Direct3D 11 bindings Planck needs, called through syscall with no cgo.

Index

Constants

View Source
const (
	DXGI_FORMAT_R10G10B10A2_UNORM  = 24
	DXGI_FORMAT_R16G16B16A16_FLOAT = 10
	DXGI_FORMAT_B8G8R8A8_UNORM     = 87
	DXGI_FORMAT_AYUV               = 100
	DXGI_FORMAT_NV12               = 103
	DXGI_FORMAT_P010               = 104
	DXGI_FORMAT_Y410               = 108

	D3D11_USAGE_DEFAULT = 0
	D3D11_USAGE_STAGING = 3

	D3D11_BIND_SHADER_RESOURCE = 0x8
	D3D11_BIND_RENDER_TARGET   = 0x20

	D3D11_CPU_ACCESS_WRITE = 0x10000
	D3D11_CPU_ACCESS_READ  = 0x20000

	D3D11_RESOURCE_MISC_SHARED            = 0x2
	D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX = 0x100
	D3D11_RESOURCE_MISC_SHARED_NTHANDLE   = 0x800

	D3D11_MAP_READ  = 1
	D3D11_MAP_WRITE = 2

	D3D11_CREATE_DEVICE_BGRA_SUPPORT  = 0x20
	D3D11_CREATE_DEVICE_VIDEO_SUPPORT = 0x800

	D3D11_QUERY_EVENT              = 0
	D3D11_QUERY_TIMESTAMP          = 2
	D3D11_QUERY_TIMESTAMP_DISJOINT = 3

	DXGI_SHARED_RESOURCE_READ  = 0x80000000
	DXGI_SHARED_RESOURCE_WRITE = 1
)

Variables

View Source
var (
	IID_IDXGIFactory1   = NewGUID(0x770aae78, 0xf26f, 0x4dba, [8]byte{0xa8, 0x29, 0x25, 0x3c, 0x83, 0xd1, 0xb3, 0x87})
	IID_IDXGIOutput1    = NewGUID(0x00cddea8, 0x939b, 0x4b83, [8]byte{0xa3, 0x40, 0xa6, 0x85, 0x22, 0x66, 0x66, 0xcc})
	IID_IDXGIOutput5    = NewGUID(0x80a07424, 0xab52, 0x42eb, [8]byte{0x83, 0x3c, 0x0c, 0x42, 0xfd, 0x28, 0x2d, 0x98})
	IID_IDXGIOutput6    = NewGUID(0x068346e8, 0xaaec, 0x4b84, [8]byte{0xad, 0xd7, 0x13, 0x7f, 0x51, 0x3f, 0x77, 0xa1})
	IID_IDXGIResource   = NewGUID(0x035f3ab4, 0x482e, 0x4e50, [8]byte{0xb4, 0x1f, 0x8a, 0x7f, 0x8b, 0xd8, 0x96, 0x0b})
	IID_IDXGIResource1  = NewGUID(0x30961379, 0x4609, 0x4a41, [8]byte{0x99, 0x8e, 0x54, 0xfe, 0x56, 0x7e, 0xe0, 0xc1})
	IID_IDXGIKeyedMutex = NewGUID(0x9d8e1289, 0xd7b3, 0x465f, [8]byte{0x81, 0x26, 0x25, 0x0e, 0x34, 0x9a, 0xf8, 0x5d})
	IID_ID3D11Texture2D = NewGUID(0x6f15aaf2, 0xd208, 0x4e89, [8]byte{0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c})
)
View Source
var IID_ID3D11Device1 = NewGUID(0xa04bfb29, 0x08ef, 0x43d6, [8]byte{0xa4, 0x9c, 0xa9, 0xbd, 0xbd, 0xcb, 0xe6, 0x86})
View Source
var IID_IDXGIDevice = NewGUID(0x54ec77fa, 0x1377, 0x44e6, [8]byte{0x8c, 0x32, 0x88, 0xfd, 0x5f, 0x44, 0xc8, 0x4c})

Functions

func Animate

func Animate(x, y, size int32, stop <-chan struct{}) error

Animate shows a small non-activating window at (x, y) that changes color once per desktop composition until stop is closed, so Desktop Duplication has a new image every refresh. It never takes focus or moves the cursor.

func BoostThread

func BoostThread(task string) (revert func(), err error)

BoostThread registers the calling OS thread with the Multimedia Class Scheduler Service as task ("Games", "Pro Audio"), falling back to THREAD_PRIORITY_HIGHEST when MMCSS is unavailable. At normal priority a paced encode thread wakes late often enough to add 5-30 ms tails. The caller must hold runtime.LockOSThread until it calls revert.

func CreateDevice

func CreateDevice(a Adapter) (Device, Context, error)

CreateDevice makes a hardware D3D11 device on the given adapter.

func DisablePowerThrottling added in v0.2.0

func DisablePowerThrottling() error

DisablePowerThrottling opts the process out of EcoQoS: Windows 11 runs a background process, which the host is whenever a game is in front, on efficiency cores with coalesced timers, and stalls every thread in it for 20-140 ms every few seconds, MMCSS or not.

func Ptr

func Ptr(p uintptr) unsafe.Pointer

Ptr turns an address returned by native code into a pointer. The memory is not Go managed, so the conversion cannot confuse the garbage collector.

Types

type Adapter

type Adapter struct{ *Object }

func (Adapter) Desc

func (a Adapter) Desc() (AdapterDesc1, error)

func (Adapter) EnumOutputs

func (a Adapter) EnumOutputs(i int) (Output, error)

func (Adapter) Info

func (a Adapter) Info() (gpu.Adapter, error)

func (Adapter) Outputs

func (a Adapter) Outputs() ([]Output, error)

type AdapterDesc1

type AdapterDesc1 struct {
	Description           [128]uint16
	VendorID              uint32
	DeviceID              uint32
	SubSysID              uint32
	Revision              uint32
	DedicatedVideoMemory  uintptr
	DedicatedSystemMemory uintptr
	SharedSystemMemory    uintptr
	AdapterLuid           LUIDPair
	Flags                 uint32
}

type Box

type Box struct{ Left, Top, Front, Right, Bottom, Back uint32 }

type Context

type Context struct{ *Object }

func (Context) Begin

func (c Context) Begin(q Query)

func (Context) CopyResource

func (c Context) CopyResource(dst, src *Object)

func (Context) CopySubresourceRegion

func (c Context) CopySubresourceRegion(dst *Object, x, y uint32, src *Object, box *Box)

func (Context) End

func (c Context) End(q Query)

func (Context) Flush

func (c Context) Flush()

func (Context) GetData

func (c Context) GetData(q Query, out unsafe.Pointer, size uint32) uintptr

GetData returns S_FALSE (1) while the query is pending.

func (Context) Map

func (c Context) Map(res *Object, mapType uint32, out *MappedSubresource) error

func (Context) Unmap

func (c Context) Unmap(res *Object)

func (Context) WaitIdle

func (c Context) WaitIdle(q Query)

WaitIdle spins on an event query until the GPU has run everything submitted.

type Device

type Device struct{ *Object }

func (Device) CreateQuery

func (d Device) CreateQuery(kind uint32) (Query, error)

func (Device) CreateTexture2D

func (d Device) CreateTexture2D(desc *Texture2DDesc) (Texture, error)

func (Device) CreateTexture2DInit

func (d Device) CreateTexture2DInit(desc *Texture2DDesc, data []byte, rowPitch uint32) (Texture, error)

CreateTexture2DInit creates a texture with initial pixel data for mip 0.

func (Device) OpenSharedResource

func (d Device) OpenSharedResource(handle uintptr) (Texture, error)

OpenSharedResource opens a legacy (non-NT) shared handle.

func (Device) OpenSharedResource1

func (d Device) OpenSharedResource1(handle uintptr) (Texture, error)

OpenSharedResource1 opens an NT handle made by IDXGIResource1::CreateSharedHandle.

func (Device) RaiseGPUThreadPriority

func (d Device) RaiseGPUThreadPriority() int

RaiseGPUThreadPriority asks the GPU scheduler to run the device's work ahead of other processes' (IDXGIDevice::SetGPUThreadPriority, +7) and returns the priority in effect. Without the privilege to raise it the device keeps the default, 0.

type Duplication

type Duplication struct{ *Object }

Duplication wraps IDXGIOutputDuplication.

func (Duplication) AcquireNextFrame

func (d Duplication) AcquireNextFrame(timeoutMs uint32, info *OutduplFrameInfo, res **Object) error

AcquireNextFrame returns the desktop image as an IDXGIResource. Callers must pass heap pointers for info and res (they are written by the call).

func (Duplication) Desc

func (d Duplication) Desc() OutduplDesc

func (Duplication) ReleaseFrame

func (d Duplication) ReleaseFrame() error

type Factory

type Factory struct{ *Object }

func CreateFactory

func CreateFactory() (Factory, error)

func (Factory) Adapters

func (f Factory) Adapters() ([]Adapter, error)

func (Factory) EnumAdapters1

func (f Factory) EnumAdapters1(i int) (Adapter, error)

EnumAdapters1 returns DXGI_ERROR_NOT_FOUND past the last adapter.

type GUID

type GUID struct {
	Data1 uint32
	Data2 uint16
	Data3 uint16
	Data4 [8]byte
}

func NewGUID

func NewGUID(d1 uint32, d2, d3 uint16, d4 [8]byte) GUID

type HRESULT

type HRESULT uint32
const (
	DXGI_ERROR_INVALID_CALL            HRESULT = 0x887a0001
	DXGI_ERROR_NOT_FOUND               HRESULT = 0x887a0002
	DXGI_ERROR_WAIT_TIMEOUT            HRESULT = 0x887a0027
	DXGI_ERROR_ACCESS_LOST             HRESULT = 0x887a0026
	DXGI_ERROR_UNSUPPORTED             HRESULT = 0x887a0004
	DXGI_ERROR_NOT_CURRENTLY_AVAILABLE HRESULT = 0x887a0022
)

func (HRESULT) Error

func (h HRESULT) Error() string

func (HRESULT) Failed

func (h HRESULT) Failed() bool

type LUIDPair

type LUIDPair struct {
	Low  uint32
	High int32
}

func (LUIDPair) LUID

func (l LUIDPair) LUID() gpu.LUID

type MappedSubresource

type MappedSubresource struct {
	Data       uintptr
	RowPitch   uint32
	DepthPitch uint32
}

type Object

type Object struct {
	// contains filtered or unexported fields
}

Object is any COM interface pointer. Its first word is the vtable.

func ObjectAt

func ObjectAt(p uintptr) *Object

ObjectAt views a raw interface pointer, such as capture.Frame.Surface.

func (*Object) QueryInterface

func (o *Object) QueryInterface(iid *GUID) (*Object, error)

func (*Object) Release

func (o *Object) Release()

type OutduplDesc

type OutduplDesc struct {
	ModeDesc struct {
		Width            uint32
		Height           uint32
		RefreshNum       uint32
		RefreshDen       uint32
		Format           uint32
		ScanlineOrdering uint32
		Scaling          uint32
	}
	Rotation                   uint32
	DesktopImageInSystemMemory int32
}

type OutduplFrameInfo

type OutduplFrameInfo struct {
	LastPresentTime           int64
	LastMouseUpdateTime       int64
	AccumulatedFrames         uint32
	RectsCoalesced            int32
	ProtectedContentMaskedOut int32
	PointerPosition           struct {
		X, Y    int32
		Visible int32
	}
	TotalMetadataBufferSize uint32
	PointerShapeBufferSize  uint32
}

type Output

type Output struct{ *Object }

func (Output) Desc

func (o Output) Desc() (OutputDesc, error)

func (Output) Desc1

func (o Output) Desc1() (OutputDesc1, error)

Desc1 reports HDR color space and bits per color (IDXGIOutput6).

func (Output) Duplicate

func (o Output) Duplicate(device *Object, formats []uint32) (Duplication, error)

Duplicate opens Desktop Duplication on this output. formats non-empty uses IDXGIOutput5::DuplicateOutput1 so HDR desktops can be captured as 10-bit or FP16; otherwise IDXGIOutput1::DuplicateOutput (BGRA8 only).

type OutputDesc

type OutputDesc struct {
	DeviceName         [32]uint16
	DesktopCoordinates Rect32
	AttachedToDesktop  int32
	Rotation           uint32
	Monitor            uintptr
}

func (OutputDesc) Name

func (d OutputDesc) Name() string

type OutputDesc1

type OutputDesc1 struct {
	DeviceName            [32]uint16
	DesktopCoordinates    Rect32
	AttachedToDesktop     int32
	Rotation              uint32
	Monitor               uintptr
	BitsPerColor          uint32
	ColorSpace            uint32
	RedPrimary            [2]float32
	GreenPrimary          [2]float32
	BluePrimary           [2]float32
	WhitePoint            [2]float32
	MinLuminance          float32
	MaxLuminance          float32
	MaxFullFrameLuminance float32
}

type Query

type Query struct{ *Object }

type Rect32

type Rect32 struct{ Left, Top, Right, Bottom int32 }

type Texture

type Texture struct{ *Object }

func (Texture) CreateSharedHandle

func (t Texture) CreateSharedHandle() (uintptr, error)

CreateSharedHandle exports the texture as an NT handle (needs MISC_SHARED_NTHANDLE).

func (Texture) Desc

func (t Texture) Desc() Texture2DDesc

func (Texture) SharedHandle

func (t Texture) SharedHandle() (uintptr, error)

SharedHandle returns the legacy shared handle (needs MISC_SHARED).

type Texture2DDesc

type Texture2DDesc struct {
	Width, Height, MipLevels, ArraySize, Format uint32
	SampleCount, SampleQuality                  uint32
	Usage, BindFlags, CPUAccessFlags, MiscFlags uint32
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL