internal/byteslice: rename package unsafe

All functions left in the old package unsafe were provided byte slice
views of other types. Rename the package accordingly and avoid a name
clash with the standard library package unsafe.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-03-11 11:27:02 +01:00
parent 86f10e33d7
commit 2328ddfeca
6 changed files with 21 additions and 19 deletions
+6 -6
View File
@@ -15,8 +15,8 @@ import (
"gioui.org/f32"
"gioui.org/gpu/internal/driver"
"gioui.org/internal/byteslice"
"gioui.org/internal/f32color"
gunsafe "gioui.org/internal/unsafe"
"gioui.org/layout"
"gioui.org/op"
)
@@ -459,7 +459,7 @@ restart:
m.quads[i].posX = p.X
m.quads[i].posY = p.Y
}
vertexData := gunsafe.BytesView(m.quads)
vertexData := byteslice.Slice(m.quads)
if len(vertexData) > m.bufSize {
if m.buffer != nil {
m.buffer.Release()
@@ -757,7 +757,7 @@ func (g *compute) render(tileDims image.Point) error {
return err
}
}
g.buffers.scene.buffer.Upload(gunsafe.BytesView(g.enc.scene))
g.buffers.scene.buffer.Upload(byteslice.Slice(g.enc.scene))
w, h := tileDims.X*tileWidthPx, tileDims.Y*tileHeightPx
if g.output.size.X != w || g.output.size.Y != h {
@@ -805,7 +805,7 @@ func (g *compute) render(tileDims image.Point) error {
}
}
g.buffers.config.Upload(gunsafe.StructView(g.conf))
g.buffers.config.Upload(byteslice.Struct(g.conf))
minSize := int(unsafe.Sizeof(memoryHeader{})) + int(alloc)
if minSize > g.buffers.memory.size {
@@ -821,7 +821,7 @@ func (g *compute) render(tileDims image.Point) error {
*g.memHeader = memoryHeader{
mem_offset: alloc,
}
g.buffers.memory.buffer.Upload(gunsafe.StructView(g.memHeader))
g.buffers.memory.buffer.Upload(byteslice.Struct(g.memHeader))
g.buffers.state.buffer.Upload(g.zeros(clearSize))
if realloced {
@@ -864,7 +864,7 @@ func (g *compute) render(tileDims image.Point) error {
g.ctx.MemoryBarrier()
t.kernel4.end()
if err := g.buffers.memory.buffer.Download(gunsafe.StructView(g.memHeader)); err != nil {
if err := g.buffers.memory.buffer.Download(byteslice.Struct(g.memHeader)); err != nil {
if err == driver.ErrContentLost {
continue
}
+2 -2
View File
@@ -21,10 +21,10 @@ import (
"gioui.org/f32"
"gioui.org/gpu/internal/driver"
"gioui.org/internal/byteslice"
"gioui.org/internal/f32color"
"gioui.org/internal/opconst"
"gioui.org/internal/ops"
gunsafe "gioui.org/internal/unsafe"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/op/clip"
@@ -559,7 +559,7 @@ func (r *renderer) release() {
func newBlitter(ctx driver.Device) *blitter {
quadVerts, err := ctx.NewImmutableBuffer(driver.BufferBindingVertices,
gunsafe.BytesView([]float32{
byteslice.Slice([]float32{
-1, +1, 0, 0,
+1, +1, 1, 0,
-1, -1, 0, 1,
+2 -2
View File
@@ -13,8 +13,8 @@ import (
"testing"
"gioui.org/gpu/internal/driver"
"gioui.org/internal/byteslice"
"gioui.org/internal/f32color"
"gioui.org/internal/unsafe"
)
var dumpImages = flag.Bool("saveimages", false, "save test images")
@@ -66,7 +66,7 @@ func TestInputShader(t *testing.T) {
defer p.Release()
b.BindProgram(p)
buf, err := b.NewImmutableBuffer(driver.BufferBindingVertices,
unsafe.BytesView([]float32{
byteslice.Slice([]float32{
0, .5, .5, 1,
-.5, -.5, .5, 1,
.5, -.5, .5, 1,
+2 -2
View File
@@ -13,8 +13,8 @@ import (
"gioui.org/f32"
"gioui.org/gpu/internal/driver"
"gioui.org/internal/byteslice"
"gioui.org/internal/f32color"
gunsafe "gioui.org/internal/unsafe"
)
type pather struct {
@@ -185,7 +185,7 @@ func newStenciler(ctx driver.Device) *stenciler {
indices[i*6+4] = i*4 + 1
indices[i*6+5] = i*4 + 3
}
indexBuf, err := ctx.NewImmutableBuffer(driver.BufferBindingIndices, gunsafe.BytesView(indices))
indexBuf, err := ctx.NewImmutableBuffer(driver.BufferBindingIndices, byteslice.Slice(indices))
if err != nil {
panic(err)
}
@@ -1,14 +1,16 @@
// SPDX-License-Identifier: Unlicense OR MIT
package unsafe
// Package byteslice provides byte slice views of other Go values such as
// slices and structs.
package byteslice
import (
"reflect"
"unsafe"
)
// StructView returns a byte slice view of a struct.
func StructView(s interface{}) []byte {
// Struct returns a byte slice view of a struct.
func Struct(s interface{}) []byte {
v := reflect.ValueOf(s).Elem()
sz := int(v.Type().Size())
var res []byte
@@ -19,8 +21,8 @@ func StructView(s interface{}) []byte {
return res
}
// BytesView returns a byte slice view of a slice.
func BytesView(s interface{}) []byte {
// Slice returns a byte slice view of a slice.
func Slice(s interface{}) []byte {
v := reflect.ValueOf(s)
first := v.Index(0)
sz := int(first.Type().Size())
+2 -2
View File
@@ -7,8 +7,8 @@ import (
"runtime"
"strings"
"gioui.org/internal/byteslice"
"gioui.org/internal/gl"
"gioui.org/internal/unsafe"
)
// FBO implements an intermediate sRGB FBO
@@ -71,7 +71,7 @@ func (s *FBO) Blit() {
s.c.Uniform1i(s.c.GetUniformLocation(prog, "tex"), 0)
s.quad = s.c.CreateBuffer()
s.c.BindBuffer(gl.ARRAY_BUFFER, s.quad)
coords := unsafe.BytesView([]float32{
coords := byteslice.Slice([]float32{
-1, +1, 0, 1,
+1, +1, 1, 1,
-1, -1, 0, 0,