graphics: Don't ref *Image in pixels. Ref *graphics.Image instead

This commit is contained in:
Hajime Hoshi 2016-07-24 06:22:33 +09:00
parent 9bbd5e89c3
commit 3ea6033c3d
3 changed files with 19 additions and 13 deletions

View File

@ -78,7 +78,7 @@ func (i *images) flushPixelsIfNeeded(target *Image, context *opengl.Context) err
i.m.Lock()
defer i.m.Unlock()
for img := range i.images {
if err := img.flushPixelsIfNeeded(target, context); err != nil {
if err := img.flushPixelsIfNeeded(target.impl, context); err != nil {
return err
}
}

View File

@ -175,12 +175,15 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
return errors.New("ebiten: image is already disposed")
}
c := &drawImageHistoryItem{
image: image,
image: image.impl.image,
vertices: vertices,
geom: options.GeoM,
colorm: options.ColorM,
mode: opengl.CompositeMode(options.CompositeMode),
}
if image.impl.pixels.inconsistent {
i.pixels.makeInconsistent()
}
i.pixels.appendDrawImageHistory(c)
geom := &options.GeoM
colorm := &options.ColorM
@ -220,13 +223,19 @@ func (i *imageImpl) flushPixelsIfInconsistent(context *opengl.Context) error {
return nil
}
func (i *imageImpl) flushPixelsIfNeeded(target *Image, context *opengl.Context) error {
func (i *imageImpl) flushPixelsIfNeeded(target *imageImpl, context *opengl.Context) error {
i.m.Lock()
defer i.m.Unlock()
if i == target {
return nil
}
if i.disposed {
return nil
}
if err := i.pixels.flushIfNeeded(target, context); err != nil {
if target.isDisposed() {
return errors.New("ebiten: target is already disposed")
}
if err := i.pixels.flushIfNeeded(target.image, context); err != nil {
return err
}
return nil

View File

@ -23,7 +23,7 @@ import (
)
type drawImageHistoryItem struct {
image *Image
image *graphics.Image
vertices []int16
geom GeoM
colorm ColorM
@ -83,9 +83,6 @@ func (p *pixels) makeInconsistent() {
}
func (p *pixels) appendDrawImageHistory(item *drawImageHistoryItem) {
if item.image.impl.pixels.inconsistent {
p.makeInconsistent()
}
if p.inconsistent {
return
}
@ -107,7 +104,7 @@ func (p *pixels) at(idx int, context *opengl.Context) (color.Color, error) {
return color.RGBA{r, g, b, a}, nil
}
func (p *pixels) hasHistoryWith(target *Image) bool {
func (p *pixels) hasHistoryWith(target *graphics.Image) bool {
for _, c := range p.drawImageHistory {
if c.image == target {
return true
@ -131,7 +128,7 @@ func (p *pixels) flushIfInconsistent(context *opengl.Context) error {
return nil
}
func (p *pixels) flushIfNeeded(target *Image, context *opengl.Context) error {
func (p *pixels) flushIfNeeded(target *graphics.Image, context *opengl.Context) error {
if p.drawImageHistory == nil {
return nil
}
@ -181,10 +178,10 @@ func (p *pixels) restore(context *opengl.Context, width, height int, filter Filt
}
for _, c := range p.drawImageHistory {
// c.image.impl must be already restored.
if c.image.impl.hasHistory() {
/*if c.image.impl.hasHistory() {
panic("not reach")
}
if err := gimg.DrawImage(c.image.impl.image, c.vertices, &c.geom, &c.colorm, c.mode); err != nil {
}*/
if err := gimg.DrawImage(c.image, c.vertices, &c.geom, &c.colorm, c.mode); err != nil {
return nil, err
}
}