graphice: Dispose old images before restoring

This commit is contained in:
Hajime Hoshi 2016-06-12 20:57:02 +09:00
parent 870ce85615
commit d99bfaf034
2 changed files with 14 additions and 3 deletions

View File

@ -105,6 +105,8 @@ func (c *graphicsContext) flush() error {
} }
func (c *graphicsContext) Resume() error { func (c *graphicsContext) Resume() error {
imageM.Lock()
defer imageM.Unlock()
ui.GLContext().Resume() ui.GLContext().Resume()
if err := graphics.Initialize(ui.GLContext()); err != nil { if err := graphics.Initialize(ui.GLContext()); err != nil {
return err return err

View File

@ -77,6 +77,17 @@ func (i *images) savePixels(context *opengl.Context, exceptions map[*imageImpl]s
func (i *images) restorePixels(context *opengl.Context) error { func (i *images) restorePixels(context *opengl.Context) error {
i.m.Lock() i.m.Lock()
defer i.m.Unlock() defer i.m.Unlock()
for img := range i.images {
if img.defaultFramebuffer {
continue
}
if img.isDisposed() {
continue
}
if err := img.image.Dispose(); err != nil {
return err
}
}
for img := range i.images { for img := range i.images {
if err := img.restorePixels(context); err != nil { if err := img.restorePixels(context); err != nil {
return err return err
@ -274,8 +285,6 @@ func (i *imageImpl) savePixels(context *opengl.Context) error {
} }
func (i *imageImpl) restorePixels(context *opengl.Context) error { func (i *imageImpl) restorePixels(context *opengl.Context) error {
imageM.Lock()
defer imageM.Unlock()
if i.defaultFramebuffer { if i.defaultFramebuffer {
return nil return nil
} }
@ -332,7 +341,6 @@ func (i *imageImpl) ReplacePixels(p []uint8) error {
} }
imageM.Lock() imageM.Lock()
defer imageM.Unlock() defer imageM.Unlock()
// TODO: Copy p?
if i.pixels == nil { if i.pixels == nil {
i.pixels = make([]uint8, len(p)) i.pixels = make([]uint8, len(p))
} }
@ -410,6 +418,7 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
draw.Draw(newImg, newImg.Bounds(), origImg, origImg.Bounds().Min, draw.Src) draw.Draw(newImg, newImg.Bounds(), origImg, origImg.Bounds().Min, draw.Src)
rgbaImg = newImg rgbaImg = newImg
} }
// TODO: Set pixels here?
img.image, err = graphics.NewImageFromImage(rgbaImg, glFilter(ui.GLContext(), filter)) img.image, err = graphics.NewImageFromImage(rgbaImg, glFilter(ui.GLContext(), filter))
if err != nil { if err != nil {
// TODO: texture should be removed here? // TODO: texture should be removed here?