graphics: Skip resetPixelsIfDependingOn if possible

This commit is contained in:
Hajime Hoshi 2016-10-28 02:54:09 +09:00
parent 26e290b2bc
commit 2b2d6157c7

View File

@ -36,8 +36,9 @@ func glContext() *opengl.Context {
} }
type images struct { type images struct {
images map[*imageImpl]struct{} images map[*imageImpl]struct{}
m sync.Mutex m sync.Mutex
lastChecked *imageImpl
} }
var theImagesForRestoring = images{ var theImagesForRestoring = images{
@ -66,6 +67,7 @@ func (i *images) remove(img *Image) {
func (i *images) resolveStalePixels(context *opengl.Context) error { func (i *images) resolveStalePixels(context *opengl.Context) error {
i.m.Lock() i.m.Lock()
defer i.m.Unlock() defer i.m.Unlock()
i.lastChecked = nil
for img := range i.images { for img := range i.images {
if err := img.resolveStalePixels(context); err != nil { if err := img.resolveStalePixels(context); err != nil {
return err return err
@ -77,6 +79,10 @@ func (i *images) resolveStalePixels(context *opengl.Context) error {
func (i *images) resetPixelsIfDependingOn(target *Image, context *opengl.Context) error { func (i *images) resetPixelsIfDependingOn(target *Image, context *opengl.Context) error {
i.m.Lock() i.m.Lock()
defer i.m.Unlock() defer i.m.Unlock()
if i.lastChecked == target.impl {
return nil
}
i.lastChecked = target.impl
for img := range i.images { for img := range i.images {
if err := img.resetPixelsIfDependingOn(target.impl, context); err != nil { if err := img.resetPixelsIfDependingOn(target.impl, context); err != nil {
return err return err