diff --git a/gpu/internal/d3d11/d3d11_windows.go b/gpu/internal/d3d11/d3d11_windows.go index 0ed1dcf9..8638f9f7 100644 --- a/gpu/internal/d3d11/d3d11_windows.go +++ b/gpu/internal/d3d11/d3d11_windows.go @@ -7,13 +7,13 @@ import ( "fmt" "image" "math" + "reflect" "unsafe" "golang.org/x/sys/windows" "gioui.org/gpu/internal/driver" "gioui.org/internal/d3d11" - gunsafe "gioui.org/internal/unsafe" ) type Backend struct { @@ -675,7 +675,7 @@ func (f *Framebuffer) ReadPixels(src image.Rectangle, pixels []byte) error { srcPitch := w * 4 dstPitch := int(resMap.RowPitch) mapSize := dstPitch * h - data := gunsafe.SliceOf(resMap.PData)[:mapSize:mapSize] + data := sliceOf(resMap.PData, mapSize) width := w * 4 for r := 0; r < h; r++ { pixels := pixels[r*srcPitch:] @@ -749,3 +749,13 @@ func toBlendFactor(f driver.BlendFactor) (uint32, uint32) { panic("unsupported blend source factor") } } + +// sliceOf returns a slice from a (native) pointer. +func sliceOf(ptr uintptr, cap int) []byte { + var data []byte + h := (*reflect.SliceHeader)(unsafe.Pointer(&data)) + h.Data = ptr + h.Cap = cap + h.Len = cap + return data +} diff --git a/internal/unsafe/unsafe.go b/internal/unsafe/unsafe.go index 1226513b..5c6d6840 100644 --- a/internal/unsafe/unsafe.go +++ b/internal/unsafe/unsafe.go @@ -31,16 +31,3 @@ func BytesView(s interface{}) []byte { h.Len = v.Len() * sz return res } - -// SliceOf returns a slice from a (native) pointer. -func SliceOf(s uintptr) []byte { - if s == 0 { - return nil - } - var res []byte - h := (*reflect.SliceHeader)(unsafe.Pointer(&res)) - h.Data = s - h.Cap = 1 << 30 - h.Len = 1 << 30 - return res -}