mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-03 22:44:28 +01:00
graphics: Don't ref *Image in pixels. Ref *graphics.Image instead
This commit is contained in:
parent
9bbd5e89c3
commit
3ea6033c3d
2
image.go
2
image.go
@ -78,7 +78,7 @@ func (i *images) flushPixelsIfNeeded(target *Image, context *opengl.Context) err
|
|||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
for img := range i.images {
|
for img := range i.images {
|
||||||
if err := img.flushPixelsIfNeeded(target, context); err != nil {
|
if err := img.flushPixelsIfNeeded(target.impl, context); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
imageimpl.go
15
imageimpl.go
@ -175,12 +175,15 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
|||||||
return errors.New("ebiten: image is already disposed")
|
return errors.New("ebiten: image is already disposed")
|
||||||
}
|
}
|
||||||
c := &drawImageHistoryItem{
|
c := &drawImageHistoryItem{
|
||||||
image: image,
|
image: image.impl.image,
|
||||||
vertices: vertices,
|
vertices: vertices,
|
||||||
geom: options.GeoM,
|
geom: options.GeoM,
|
||||||
colorm: options.ColorM,
|
colorm: options.ColorM,
|
||||||
mode: opengl.CompositeMode(options.CompositeMode),
|
mode: opengl.CompositeMode(options.CompositeMode),
|
||||||
}
|
}
|
||||||
|
if image.impl.pixels.inconsistent {
|
||||||
|
i.pixels.makeInconsistent()
|
||||||
|
}
|
||||||
i.pixels.appendDrawImageHistory(c)
|
i.pixels.appendDrawImageHistory(c)
|
||||||
geom := &options.GeoM
|
geom := &options.GeoM
|
||||||
colorm := &options.ColorM
|
colorm := &options.ColorM
|
||||||
@ -220,13 +223,19 @@ func (i *imageImpl) flushPixelsIfInconsistent(context *opengl.Context) error {
|
|||||||
return nil
|
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()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
|
if i == target {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if i.disposed {
|
if i.disposed {
|
||||||
return nil
|
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 err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
15
pixels.go
15
pixels.go
@ -23,7 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type drawImageHistoryItem struct {
|
type drawImageHistoryItem struct {
|
||||||
image *Image
|
image *graphics.Image
|
||||||
vertices []int16
|
vertices []int16
|
||||||
geom GeoM
|
geom GeoM
|
||||||
colorm ColorM
|
colorm ColorM
|
||||||
@ -83,9 +83,6 @@ func (p *pixels) makeInconsistent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *pixels) appendDrawImageHistory(item *drawImageHistoryItem) {
|
func (p *pixels) appendDrawImageHistory(item *drawImageHistoryItem) {
|
||||||
if item.image.impl.pixels.inconsistent {
|
|
||||||
p.makeInconsistent()
|
|
||||||
}
|
|
||||||
if p.inconsistent {
|
if p.inconsistent {
|
||||||
return
|
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
|
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 {
|
for _, c := range p.drawImageHistory {
|
||||||
if c.image == target {
|
if c.image == target {
|
||||||
return true
|
return true
|
||||||
@ -131,7 +128,7 @@ func (p *pixels) flushIfInconsistent(context *opengl.Context) error {
|
|||||||
return nil
|
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 {
|
if p.drawImageHistory == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -181,10 +178,10 @@ func (p *pixels) restore(context *opengl.Context, width, height int, filter Filt
|
|||||||
}
|
}
|
||||||
for _, c := range p.drawImageHistory {
|
for _, c := range p.drawImageHistory {
|
||||||
// c.image.impl must be already restored.
|
// c.image.impl must be already restored.
|
||||||
if c.image.impl.hasHistory() {
|
/*if c.image.impl.hasHistory() {
|
||||||
panic("not reach")
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user