mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
graphics: Skip resetPixelsIfDependingOn if possible
This commit is contained in:
parent
26e290b2bc
commit
2b2d6157c7
6
image.go
6
image.go
@ -38,6 +38,7 @@ 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
|
||||||
|
Loading…
Reference in New Issue
Block a user