gpu: avoid pointers of pathData

Save allocations by using pathData instead of *pathData.

Signed-off-by: Viktor <viktor.ogeman@gmail.com>
This commit is contained in:
Viktor
2020-06-20 23:30:00 +02:00
committed by Elias Naur
parent 42f07ca538
commit 901478d102
3 changed files with 9 additions and 9 deletions
+3 -3
View File
@@ -26,7 +26,7 @@ type opCache struct {
} }
type opCacheValue struct { type opCacheValue struct {
data *pathData data pathData
bounds f32.Rectangle bounds f32.Rectangle
key ops.Key key ops.Key
keep bool keep bool
@@ -120,9 +120,9 @@ func (r *opCache) frame() {
if v.keep { if v.keep {
continue continue
} }
if v.data != nil { if v.data.data != nil {
v.data.release() v.data.release()
r.cache[i].data = nil r.cache[i].data.data = nil
} }
delete(r.index, v.key) delete(r.index, v.key)
r.freelist = append(r.freelist, i) r.freelist = append(r.freelist, i)
+1 -1
View File
@@ -318,7 +318,7 @@ func (g *GPU) Collect(viewport image.Point, frameOps *op.Ops) {
g.cleanupTimer = g.timers.newTimer() g.cleanupTimer = g.timers.newTimer()
} }
for _, p := range g.drawOps.pathOps { for _, p := range g.drawOps.pathOps {
if v, exists := g.drawOps.pathCache.get(p.pathKey); !exists || v.data == nil { if v, exists := g.drawOps.pathCache.get(p.pathKey); !exists || v.data.data == nil {
data := buildPath(g.ctx, p.pathVerts) data := buildPath(g.ctx, p.pathVerts)
g.drawOps.pathCache.put(p.pathKey, opCacheValue{ g.drawOps.pathCache.put(p.pathKey, opCacheValue{
data: data, data: data,
+5 -5
View File
@@ -289,18 +289,18 @@ func (c *coverer) release() {
c.layout.Release() c.layout.Release()
} }
func buildPath(ctx backend.Device, p []byte) *pathData { func buildPath(ctx backend.Device, p []byte) pathData {
buf, err := ctx.NewImmutableBuffer(backend.BufferBindingVertices, p) buf, err := ctx.NewImmutableBuffer(backend.BufferBindingVertices, p)
if err != nil { if err != nil {
panic(err) panic(err)
} }
return &pathData{ return pathData{
ncurves: len(p) / vertStride, ncurves: len(p) / vertStride,
data: buf, data: buf,
} }
} }
func (p *pathData) release() { func (p pathData) release() {
p.data.Release() p.data.Release()
} }
@@ -308,7 +308,7 @@ func (p *pather) begin(sizes []image.Point) {
p.stenciler.begin(sizes) p.stenciler.begin(sizes)
} }
func (p *pather) stencilPath(bounds image.Rectangle, offset f32.Point, uv image.Point, data *pathData) { func (p *pather) stencilPath(bounds image.Rectangle, offset f32.Point, uv image.Point, data pathData) {
p.stenciler.stencilPath(bounds, offset, uv, data) p.stenciler.stencilPath(bounds, offset, uv, data)
} }
@@ -338,7 +338,7 @@ func (s *stenciler) begin(sizes []image.Point) {
s.ctx.BindIndexBuffer(s.indexBuf) s.ctx.BindIndexBuffer(s.indexBuf)
} }
func (s *stenciler) stencilPath(bounds image.Rectangle, offset f32.Point, uv image.Point, data *pathData) { func (s *stenciler) stencilPath(bounds image.Rectangle, offset f32.Point, uv image.Point, data pathData) {
s.ctx.Viewport(uv.X, uv.Y, bounds.Dx(), bounds.Dy()) s.ctx.Viewport(uv.X, uv.Y, bounds.Dx(), bounds.Dy())
// Transform UI coordinates to OpenGL coordinates. // Transform UI coordinates to OpenGL coordinates.
texSize := f32.Point{X: float32(bounds.Dx()), Y: float32(bounds.Dy())} texSize := f32.Point{X: float32(bounds.Dx()), Y: float32(bounds.Dy())}