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
+36
View File
@@ -2,6 +2,13 @@
package key
import (
"encoding/binary"
"gioui.org/ui"
"gioui.org/ui/internal/ops"
)
type OpHandler struct {
Key Key
Focus bool
@@ -63,6 +70,35 @@ const (
NamePageDown = '⇟'
)
func (h OpHandler) Add(o *ui.Ops) {
data := make([]byte, ops.TypeKeyHandlerLen)
data[0] = byte(ops.TypeKeyHandler)
bo := binary.LittleEndian
if h.Focus {
data[1] = 1
}
bo.PutUint32(data[2:], uint32(o.Ref(h.Key)))
o.Write(data)
}
func (h *OpHandler) Decode(d []byte, refs []interface{}) {
bo := binary.LittleEndian
if ops.OpType(d[0]) != ops.TypeKeyHandler {
panic("invalid op")
}
key := int(bo.Uint32(d[2:]))
*h = OpHandler{
Focus: d[1] != 0,
Key: refs[key].(Key),
}
}
func (h OpHideInput) Add(o *ui.Ops) {
data := make([]byte, ops.TypeHideInputLen)
data[0] = byte(ops.TypeHideInput)
o.Write(data)
}
func (OpHandler) ImplementsOp() {}
func (OpHideInput) ImplementsOp() {}