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:
Elias Naur
2021-03-11 11:20:07 +01:00
parent 5894127204
commit 86f10e33d7
2 changed files with 12 additions and 15 deletions
+12 -2
View File
@@ -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
}
-13
View File
@@ -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
}