mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
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:
+4
-3
@@ -1772,9 +1772,10 @@ func (c *collector) collect(root *op.Ops, viewport image.Point, texOps *[]textur
|
|||||||
pathData.key = encOp.Key
|
pathData.key = encOp.Key
|
||||||
pathData.hash = hash
|
pathData.hash = hash
|
||||||
case ops.TypeClip:
|
case ops.TypeClip:
|
||||||
var op clipOp
|
var op ops.ClipOp
|
||||||
op.decode(encOp.Data)
|
op.Decode(encOp.Data)
|
||||||
c.addClip(&state, fview, op.bounds, pathData.data, pathData.key, pathData.hash, strWidth, true)
|
bounds := layout.FRect(op.Bounds)
|
||||||
|
c.addClip(&state, fview, bounds, pathData.data, pathData.key, pathData.hash, strWidth, true)
|
||||||
pathData.data = nil
|
pathData.data = nil
|
||||||
strWidth = 0
|
strWidth = 0
|
||||||
case ops.TypePopClip:
|
case ops.TypePopClip:
|
||||||
|
|||||||
+10
-38
@@ -165,13 +165,6 @@ type material struct {
|
|||||||
uvTrans f32.Affine2D
|
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.
|
// imageOpData is the shadow of paint.ImageOp.
|
||||||
type imageOpData struct {
|
type imageOpData struct {
|
||||||
src *image.RGBA
|
src *image.RGBA
|
||||||
@@ -185,27 +178,6 @@ type linearGradientOpData struct {
|
|||||||
color2 color.NRGBA
|
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 {
|
func decodeImageOp(data []byte, refs []interface{}) imageOpData {
|
||||||
if ops.OpType(data[0]) != ops.TypeImage {
|
if ops.OpType(data[0]) != ops.TypeImage {
|
||||||
panic("invalid op")
|
panic("invalid op")
|
||||||
@@ -937,10 +909,10 @@ loop:
|
|||||||
quads.key.Key = encOp.Key
|
quads.key.Key = encOp.Key
|
||||||
|
|
||||||
case ops.TypeClip:
|
case ops.TypeClip:
|
||||||
var op clipOp
|
var op ops.ClipOp
|
||||||
op.decode(encOp.Data)
|
op.Decode(encOp.Data)
|
||||||
quads.key.outline = op.outline
|
quads.key.outline = op.Outline
|
||||||
bounds := op.bounds
|
bounds := layout.FRect(op.Bounds)
|
||||||
trans, off := splitTransform(state.t)
|
trans, off := splitTransform(state.t)
|
||||||
if len(quads.aux) > 0 {
|
if len(quads.aux) > 0 {
|
||||||
// There is a clipping path, build the gpu data and update the
|
// 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 {
|
if v, ok := d.pathCache.get(quads.key); ok {
|
||||||
// Since the GPU data exists in the cache aux will not be used.
|
// Since the GPU data exists in the cache aux will not be used.
|
||||||
// Why is this not used for the offset shapes?
|
// Why is this not used for the offset shapes?
|
||||||
op.bounds = v.bounds
|
bounds = v.bounds
|
||||||
} else {
|
} else {
|
||||||
pathData, bounds := d.buildVerts(
|
var pathData []byte
|
||||||
|
pathData, bounds = d.buildVerts(
|
||||||
quads.aux, trans, quads.key.outline, quads.key.strokeWidth,
|
quads.aux, trans, quads.key.outline, quads.key.strokeWidth,
|
||||||
)
|
)
|
||||||
op.bounds = bounds
|
|
||||||
quads.aux = pathData
|
quads.aux = pathData
|
||||||
// add it to the cache, without GPU data, so the transform can be
|
// add it to the cache, without GPU data, so the transform can be
|
||||||
// reused.
|
// reused.
|
||||||
d.pathCache.put(quads.key, opCacheValue{bounds: op.bounds})
|
d.pathCache.put(quads.key, opCacheValue{bounds: bounds})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quads.aux, op.bounds, _ = d.boundsForTransformedRect(bounds, trans)
|
quads.aux, bounds, _ = d.boundsForTransformedRect(bounds, trans)
|
||||||
quads.key = opKey{Key: encOp.Key}
|
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{}
|
quads = quadsOp{}
|
||||||
case ops.TypePopClip:
|
case ops.TypePopClip:
|
||||||
state.cpath = state.cpath.parent
|
state.cpath = state.cpath.parent
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package ops
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"image"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"gioui.org/f32"
|
"gioui.org/f32"
|
||||||
@@ -86,6 +87,12 @@ type stack struct {
|
|||||||
|
|
||||||
type StackKind uint8
|
type StackKind uint8
|
||||||
|
|
||||||
|
// ClipOp is the shadow of clip.Op.
|
||||||
|
type ClipOp struct {
|
||||||
|
Bounds image.Rectangle
|
||||||
|
Outline bool
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ClipStack StackKind = iota
|
ClipStack StackKind = iota
|
||||||
AreaStack
|
AreaStack
|
||||||
@@ -126,6 +133,27 @@ const (
|
|||||||
TypeStrokeLen = 1 + 4
|
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) {
|
func Reset(o *Ops) {
|
||||||
o.macroStack = stack{}
|
o.macroStack = stack{}
|
||||||
for i := range o.stacks {
|
for i := range o.stacks {
|
||||||
|
|||||||
Reference in New Issue
Block a user