mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
all: serialize ops
Pros: - Much less per-frame garbage - Allow future preprocessing of ops while building it - Much fewer interface calls and pointer chasing - Allow future serialization of ops for remote rendering Cons: - Slightly clumsier API Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+21
-4
@@ -3,16 +3,17 @@
|
||||
package draw
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"math"
|
||||
|
||||
"gioui.org/ui"
|
||||
"gioui.org/ui/f32"
|
||||
"gioui.org/ui/internal/ops"
|
||||
"gioui.org/ui/internal/path"
|
||||
)
|
||||
|
||||
type OpClip struct {
|
||||
Path *Path
|
||||
Op ui.Op
|
||||
}
|
||||
|
||||
type Path struct {
|
||||
@@ -33,11 +34,25 @@ func (p *Path) Data() interface{} {
|
||||
return p.data
|
||||
}
|
||||
|
||||
func (p OpClip) ChildOp() ui.Op {
|
||||
return p.Op
|
||||
func (c OpClip) Add(o *ui.Ops) {
|
||||
data := make([]byte, ops.TypeClipLen)
|
||||
data[0] = byte(ops.TypeClip)
|
||||
bo := binary.LittleEndian
|
||||
ref := o.Ref(c.Path)
|
||||
bo.PutUint32(data[1:], uint32(ref))
|
||||
o.Write(data)
|
||||
}
|
||||
|
||||
func (p OpClip) ImplementsOp() {}
|
||||
func (c *OpClip) Decode(d []byte, refs []interface{}) {
|
||||
bo := binary.LittleEndian
|
||||
if ops.OpType(d[0]) != ops.TypeClip {
|
||||
panic("invalid op")
|
||||
}
|
||||
ref := int(bo.Uint32(d[1:]))
|
||||
*c = OpClip{
|
||||
Path: refs[ref].(*Path),
|
||||
}
|
||||
}
|
||||
|
||||
// MoveTo moves the pen to the given position.
|
||||
func (p *PathBuilder) Move(to f32.Point) {
|
||||
@@ -265,3 +280,5 @@ func (p *PathBuilder) Path() *Path {
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func (p OpClip) ImplementsOp() {}
|
||||
|
||||
Reference in New Issue
Block a user