diff --git a/internal/graphics/command.go b/internal/graphics/command.go index 2f9e120f8..c11a0c226 100644 --- a/internal/graphics/command.go +++ b/internal/graphics/command.go @@ -49,13 +49,14 @@ func (q *commandQueue) appendVertices(vertices []float32) { } func (q *commandQueue) EnqueueDrawImageCommand(dst, src *Image, vertices []float32, clr *affine.ColorM, mode opengl.CompositeMode) { + // Avoid defer for performance q.m.Lock() - defer q.m.Unlock() q.appendVertices(vertices) if 0 < len(q.commands) { if c, ok := q.commands[len(q.commands)-1].(*drawImageCommand); ok { if c.isMergeable(dst, src, clr, mode) { c.verticesNum += len(vertices) + q.m.Unlock() return } } @@ -68,12 +69,13 @@ func (q *commandQueue) EnqueueDrawImageCommand(dst, src *Image, vertices []float mode: mode, } q.commands = append(q.commands, c) + q.m.Unlock() } func (q *commandQueue) Enqueue(command command) { q.m.Lock() - defer q.m.Unlock() q.commands = append(q.commands, command) + q.m.Unlock() } // commandGroups separates q.commands into some groups. diff --git a/internal/restorable/images.go b/internal/restorable/images.go index 116816350..67f8a0640 100644 --- a/internal/restorable/images.go +++ b/internal/restorable/images.go @@ -66,19 +66,22 @@ func (i *images) resolveStalePixels(context *opengl.Context) error { } func (i *images) resetPixelsIfDependingOn(target *Image) { + // Avoid defer for performance i.m.Lock() - defer i.m.Unlock() if target == nil { // disposed + i.m.Unlock() return } if i.lastChecked == target { + i.m.Unlock() return } i.lastChecked = target for img := range i.images { img.makeStaleIfDependingOn(target) } + i.m.Unlock() } func (i *images) restore(context *opengl.Context) error {