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:
Elias Naur
2019-04-24 13:33:01 +02:00
parent 7b6e1ce35a
commit 252e058766
21 changed files with 809 additions and 385 deletions
+21 -4
View File
@@ -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() {}