mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
ui/app/internal/gpu: upload path data to GPU before re-use
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -32,6 +32,7 @@ type GPU struct {
|
|||||||
results chan frameResult
|
results chan frameResult
|
||||||
refresh chan struct{}
|
refresh chan struct{}
|
||||||
refreshErr chan error
|
refreshErr chan error
|
||||||
|
ack chan struct{}
|
||||||
stop chan struct{}
|
stop chan struct{}
|
||||||
stopped chan struct{}
|
stopped chan struct{}
|
||||||
ops drawOps
|
ops drawOps
|
||||||
@@ -90,6 +91,7 @@ type pathOp struct {
|
|||||||
// later clip rectangles.
|
// later clip rectangles.
|
||||||
clip image.Rectangle
|
clip image.Rectangle
|
||||||
pathKey ui.OpKey
|
pathKey ui.OpKey
|
||||||
|
path bool
|
||||||
pathVerts []byte
|
pathVerts []byte
|
||||||
parent *pathOp
|
parent *pathOp
|
||||||
place placement
|
place placement
|
||||||
@@ -190,6 +192,7 @@ func NewGPU(ctx gl.Context) (*GPU, error) {
|
|||||||
results: make(chan frameResult),
|
results: make(chan frameResult),
|
||||||
refresh: make(chan struct{}),
|
refresh: make(chan struct{}),
|
||||||
refreshErr: make(chan error),
|
refreshErr: make(chan error),
|
||||||
|
ack: make(chan struct{}),
|
||||||
stop: make(chan struct{}),
|
stop: make(chan struct{}),
|
||||||
stopped: make(chan struct{}),
|
stopped: make(chan struct{}),
|
||||||
pathCache: newOpCache(),
|
pathCache: newOpCache(),
|
||||||
@@ -243,6 +246,16 @@ func (g *GPU) renderLoop(glctx gl.Context) error {
|
|||||||
defer timers.release()
|
defer timers.release()
|
||||||
}
|
}
|
||||||
ops := frame.ops
|
ops := frame.ops
|
||||||
|
// Upload path data to GPU before ack'ing the frame data for re-use.
|
||||||
|
for _, p := range ops.pathOps {
|
||||||
|
data, exists := g.pathCache.get(p.pathKey)
|
||||||
|
if !exists {
|
||||||
|
data = buildPath(r.ctx, p.pathVerts)
|
||||||
|
g.pathCache.put(p.pathKey, data)
|
||||||
|
}
|
||||||
|
p.pathVerts = nil
|
||||||
|
}
|
||||||
|
g.ack <- struct{}{}
|
||||||
r.blitter.viewport = frame.viewport
|
r.blitter.viewport = frame.viewport
|
||||||
r.pather.viewport = frame.viewport
|
r.pather.viewport = frame.viewport
|
||||||
for _, img := range ops.imageOps {
|
for _, img := range ops.imageOps {
|
||||||
@@ -338,6 +351,7 @@ func (g *GPU) Draw(profile bool, viewport image.Point, root *ui.Ops) {
|
|||||||
g.ops.reset(g.cache, viewport)
|
g.ops.reset(g.cache, viewport)
|
||||||
g.ops.collect(g.cache, root, viewport)
|
g.ops.collect(g.cache, root, viewport)
|
||||||
g.frames <- frame{profile, viewport, g.ops}
|
g.frames <- frame{profile, viewport, g.ops}
|
||||||
|
<-g.ack
|
||||||
g.drawing = true
|
g.drawing = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,11 +480,7 @@ func (r *renderer) stencilClips(pathCache *opCache, ops []*pathOp) {
|
|||||||
bindFramebuffer(r.ctx, f.fbo)
|
bindFramebuffer(r.ctx, f.fbo)
|
||||||
r.ctx.Clear(gl.COLOR_BUFFER_BIT)
|
r.ctx.Clear(gl.COLOR_BUFFER_BIT)
|
||||||
}
|
}
|
||||||
data, exists := pathCache.get(p.pathKey)
|
data, _ := pathCache.get(p.pathKey)
|
||||||
if !exists {
|
|
||||||
data = buildPath(r.ctx, p.pathVerts)
|
|
||||||
pathCache.put(p.pathKey, data)
|
|
||||||
}
|
|
||||||
r.pather.stencilPath(p.clip, p.off, p.place.Pos, data.(*pathData))
|
r.pather.stencilPath(p.clip, p.off, p.place.Pos, data.(*pathData))
|
||||||
}
|
}
|
||||||
r.pather.end()
|
r.pather.end()
|
||||||
@@ -509,7 +519,7 @@ func (r *renderer) intersectPath(p *pathOp, clip image.Rectangle) {
|
|||||||
if p.parent != nil {
|
if p.parent != nil {
|
||||||
r.intersectPath(p.parent, clip)
|
r.intersectPath(p.parent, clip)
|
||||||
}
|
}
|
||||||
if len(p.pathVerts) == 0 {
|
if !p.path {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
o := p.place.Pos.Add(clip.Min).Sub(p.clip.Min)
|
o := p.place.Pos.Add(clip.Min).Sub(p.clip.Min)
|
||||||
@@ -531,7 +541,7 @@ func (r *renderer) packIntersections(ops []imageOp) {
|
|||||||
var npaths int
|
var npaths int
|
||||||
var onePath *pathOp
|
var onePath *pathOp
|
||||||
for p := img.path; p != nil; p = p.parent {
|
for p := img.path; p != nil; p = p.parent {
|
||||||
if len(p.pathVerts) > 0 {
|
if p.path {
|
||||||
onePath = p
|
onePath = p
|
||||||
npaths++
|
npaths++
|
||||||
}
|
}
|
||||||
@@ -679,6 +689,7 @@ loop:
|
|||||||
if len(aux) > 0 {
|
if len(aux) > 0 {
|
||||||
state.rect = false
|
state.rect = false
|
||||||
state.cpath.pathKey = auxKey
|
state.cpath.pathKey = auxKey
|
||||||
|
state.cpath.path = true
|
||||||
state.cpath.pathVerts = aux
|
state.cpath.pathVerts = aux
|
||||||
d.pathOps = append(d.pathOps, state.cpath)
|
d.pathOps = append(d.pathOps, state.cpath)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user