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
+4 -3
View File
@@ -1772,9 +1772,10 @@ func (c *collector) collect(root *op.Ops, viewport image.Point, texOps *[]textur
pathData.key = encOp.Key
pathData.hash = hash
case ops.TypeClip:
var op clipOp
op.decode(encOp.Data)
c.addClip(&state, fview, op.bounds, pathData.data, pathData.key, pathData.hash, strWidth, true)
var op ops.ClipOp
op.Decode(encOp.Data)
bounds := layout.FRect(op.Bounds)
c.addClip(&state, fview, bounds, pathData.data, pathData.key, pathData.hash, strWidth, true)
pathData.data = nil
strWidth = 0
case ops.TypePopClip:
+10 -38
View File
@@ -165,13 +165,6 @@ type material struct {
uvTrans f32.Affine2D
}
// clipOp is the shadow of clip.Op.
type clipOp struct {
// TODO: Use image.Rectangle?
bounds f32.Rectangle
outline bool
}
// imageOpData is the shadow of paint.ImageOp.
type imageOpData struct {
src *image.RGBA
@@ -185,27 +178,6 @@ type linearGradientOpData struct {
color2 color.NRGBA
}
func (op *clipOp) decode(data []byte) {
if ops.OpType(data[0]) != ops.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: layout.FRect(r),
outline: data[17] == 1,
}
}
func decodeImageOp(data []byte, refs []interface{}) imageOpData {
if ops.OpType(data[0]) != ops.TypeImage {
panic("invalid op")
@@ -937,10 +909,10 @@ loop:
quads.key.Key = encOp.Key
case ops.TypeClip:
var op clipOp
op.decode(encOp.Data)
quads.key.outline = op.outline
bounds := op.bounds
var op ops.ClipOp
op.Decode(encOp.Data)
quads.key.outline = op.Outline
bounds := layout.FRect(op.Bounds)
trans, off := splitTransform(state.t)
if len(quads.aux) > 0 {
// There is a clipping path, build the gpu data and update the
@@ -950,22 +922,22 @@ loop:
if v, ok := d.pathCache.get(quads.key); ok {
// Since the GPU data exists in the cache aux will not be used.
// Why is this not used for the offset shapes?
op.bounds = v.bounds
bounds = v.bounds
} else {
pathData, bounds := d.buildVerts(
var pathData []byte
pathData, bounds = d.buildVerts(
quads.aux, trans, quads.key.outline, quads.key.strokeWidth,
)
op.bounds = bounds
quads.aux = pathData
// add it to the cache, without GPU data, so the transform can be
// reused.
d.pathCache.put(quads.key, opCacheValue{bounds: op.bounds})
d.pathCache.put(quads.key, opCacheValue{bounds: bounds})
}
} else {
quads.aux, op.bounds, _ = d.boundsForTransformedRect(bounds, trans)
quads.aux, bounds, _ = d.boundsForTransformedRect(bounds, trans)
quads.key = opKey{Key: encOp.Key}
}
d.addClipPath(&state, quads.aux, quads.key, op.bounds, off, true)
d.addClipPath(&state, quads.aux, quads.key, bounds, off, true)
quads = quadsOp{}
case ops.TypePopClip:
state.cpath = state.cpath.parent
+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 {