gpu,internal/ops: move gpu.clipOp to ops.ClipOp

We're about to use clip.Ops for pointer areas; this change makes the
decoding accessible from the router package.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-10-25 11:20:14 +02:00
parent 9548dbe901
commit 1eab4b84a6
3 changed files with 42 additions and 41 deletions
+28
View File
@@ -4,6 +4,7 @@ package ops
import (
"encoding/binary"
"image"
"math"
"gioui.org/f32"
@@ -86,6 +87,12 @@ type stack struct {
type StackKind uint8
// ClipOp is the shadow of clip.Op.
type ClipOp struct {
Bounds image.Rectangle
Outline bool
}
const (
ClipStack StackKind = iota
AreaStack
@@ -126,6 +133,27 @@ const (
TypeStrokeLen = 1 + 4
)
func (op *ClipOp) Decode(data []byte) {
if OpType(data[0]) != TypeClip {
panic("invalid op")
}
bo := binary.LittleEndian
r := image.Rectangle{
Min: image.Point{
X: int(int32(bo.Uint32(data[1:]))),
Y: int(int32(bo.Uint32(data[5:]))),
},
Max: image.Point{
X: int(int32(bo.Uint32(data[9:]))),
Y: int(int32(bo.Uint32(data[13:]))),
},
}
*op = ClipOp{
Bounds: r,
Outline: data[17] == 1,
}
}
func Reset(o *Ops) {
o.macroStack = stack{}
for i := range o.stacks {