mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
internal/unsafe: get rid of SliceOf
Move SliceOf to the package of the only user and unexport it. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -7,13 +7,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"math"
|
"math"
|
||||||
|
"reflect"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
|
|
||||||
"gioui.org/gpu/internal/driver"
|
"gioui.org/gpu/internal/driver"
|
||||||
"gioui.org/internal/d3d11"
|
"gioui.org/internal/d3d11"
|
||||||
gunsafe "gioui.org/internal/unsafe"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Backend struct {
|
type Backend struct {
|
||||||
@@ -675,7 +675,7 @@ func (f *Framebuffer) ReadPixels(src image.Rectangle, pixels []byte) error {
|
|||||||
srcPitch := w * 4
|
srcPitch := w * 4
|
||||||
dstPitch := int(resMap.RowPitch)
|
dstPitch := int(resMap.RowPitch)
|
||||||
mapSize := dstPitch * h
|
mapSize := dstPitch * h
|
||||||
data := gunsafe.SliceOf(resMap.PData)[:mapSize:mapSize]
|
data := sliceOf(resMap.PData, mapSize)
|
||||||
width := w * 4
|
width := w * 4
|
||||||
for r := 0; r < h; r++ {
|
for r := 0; r < h; r++ {
|
||||||
pixels := pixels[r*srcPitch:]
|
pixels := pixels[r*srcPitch:]
|
||||||
@@ -749,3 +749,13 @@ func toBlendFactor(f driver.BlendFactor) (uint32, uint32) {
|
|||||||
panic("unsupported blend source factor")
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,16 +31,3 @@ func BytesView(s interface{}) []byte {
|
|||||||
h.Len = v.Len() * sz
|
h.Len = v.Len() * sz
|
||||||
return res
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user