mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
internal/ops: switch quad encoding to compute format
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+7
-20
@@ -5,12 +5,15 @@ package ops
|
||||
import (
|
||||
"encoding/binary"
|
||||
"math"
|
||||
"unsafe"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/internal/byteslice"
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/internal/scene"
|
||||
)
|
||||
|
||||
const QuadSize = 4 * 2 * 3
|
||||
const QuadSize = int(unsafe.Sizeof(scene.Command{}))
|
||||
|
||||
type Quad struct {
|
||||
From, Ctrl, To f32.Point
|
||||
@@ -23,26 +26,10 @@ func (q Quad) Transform(t f32.Affine2D) Quad {
|
||||
return q
|
||||
}
|
||||
|
||||
func EncodeQuad(d []byte, q Quad) {
|
||||
d = d[:24]
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(d[0:], math.Float32bits(q.From.X))
|
||||
bo.PutUint32(d[4:], math.Float32bits(q.From.Y))
|
||||
bo.PutUint32(d[8:], math.Float32bits(q.Ctrl.X))
|
||||
bo.PutUint32(d[12:], math.Float32bits(q.Ctrl.Y))
|
||||
bo.PutUint32(d[16:], math.Float32bits(q.To.X))
|
||||
bo.PutUint32(d[20:], math.Float32bits(q.To.Y))
|
||||
}
|
||||
|
||||
func DecodeQuad(d []byte) (q Quad) {
|
||||
d = d[:24]
|
||||
bo := binary.LittleEndian
|
||||
q.From.X = math.Float32frombits(bo.Uint32(d[0:]))
|
||||
q.From.Y = math.Float32frombits(bo.Uint32(d[4:]))
|
||||
q.Ctrl.X = math.Float32frombits(bo.Uint32(d[8:]))
|
||||
q.Ctrl.Y = math.Float32frombits(bo.Uint32(d[12:]))
|
||||
q.To.X = math.Float32frombits(bo.Uint32(d[16:]))
|
||||
q.To.Y = math.Float32frombits(bo.Uint32(d[20:]))
|
||||
var cmd scene.Command
|
||||
copy(byteslice.Slice(cmd[:]), d)
|
||||
q.From, q.Ctrl, q.To = scene.DecodeQuad(cmd)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -123,3 +123,13 @@ func FillImage(index int) Command {
|
||||
1: uint32(index),
|
||||
}
|
||||
}
|
||||
|
||||
func DecodeQuad(cmd Command) (from, ctrl, to f32.Point) {
|
||||
if cmd[0] != elemFillQuad {
|
||||
panic("invalid command")
|
||||
}
|
||||
from = f32.Pt(math.Float32frombits(cmd[1]), math.Float32frombits(cmd[2]))
|
||||
ctrl = f32.Pt(math.Float32frombits(cmd[3]), math.Float32frombits(cmd[4]))
|
||||
to = f32.Pt(math.Float32frombits(cmd[5]), math.Float32frombits(cmd[6]))
|
||||
return
|
||||
}
|
||||
|
||||
+7
-5
@@ -8,8 +8,10 @@ import (
|
||||
"math"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/internal/byteslice"
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/internal/scene"
|
||||
"gioui.org/op"
|
||||
)
|
||||
|
||||
@@ -155,11 +157,7 @@ func (p *Path) QuadTo(ctrl, to f32.Point) {
|
||||
data := p.ops.Write(ops.QuadSize + 4)
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(data[0:], uint32(p.contour))
|
||||
ops.EncodeQuad(data[4:], ops.Quad{
|
||||
From: p.pen,
|
||||
Ctrl: ctrl,
|
||||
To: to,
|
||||
})
|
||||
encodeCommand(data[4:], scene.Quad(p.pen, ctrl, to, false))
|
||||
p.pen = to
|
||||
p.hasSegments = true
|
||||
}
|
||||
@@ -395,3 +393,7 @@ func (o Outline) Op() Op {
|
||||
outline: true,
|
||||
}
|
||||
}
|
||||
|
||||
func encodeCommand(out []byte, cmd scene.Command) {
|
||||
copy(out, byteslice.Slice(cmd[:]))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user