mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
graphics: Image.ReplacePixels/Dispose always returns nil (#331)
This commit is contained in:
parent
6a4bb0513b
commit
a3e14c9ddb
16
image.go
16
image.go
@ -230,13 +230,18 @@ func (i *Image) At(x, y int) color.Color {
|
|||||||
//
|
//
|
||||||
// The behavior of any functions for a disposed image is undefined.
|
// The behavior of any functions for a disposed image is undefined.
|
||||||
//
|
//
|
||||||
|
// When the image is disposed, Dipose does nothing.
|
||||||
|
//
|
||||||
|
// Dipose always return nil as of 1.5.0-alpha.
|
||||||
|
//
|
||||||
// This function is concurrent-safe.
|
// This function is concurrent-safe.
|
||||||
func (i *Image) Dispose() error {
|
func (i *Image) Dispose() error {
|
||||||
if i.impl.isDisposed() {
|
if i.impl.isDisposed() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
theImagesForRestoring.resetPixelsIfDependingOn(i, glContext())
|
theImagesForRestoring.resetPixelsIfDependingOn(i, glContext())
|
||||||
return i.impl.Dispose()
|
i.impl.Dispose()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReplacePixels replaces the pixels of the image with p.
|
// ReplacePixels replaces the pixels of the image with p.
|
||||||
@ -245,10 +250,17 @@ func (i *Image) Dispose() error {
|
|||||||
//
|
//
|
||||||
// ReplacePixels may be slow (as for implementation, this calls glTexSubImage2D).
|
// ReplacePixels may be slow (as for implementation, this calls glTexSubImage2D).
|
||||||
//
|
//
|
||||||
|
// When len(p) is not 4 * (width) * (height), ReplacePixels panics.
|
||||||
|
//
|
||||||
|
// When the image is disposed, ReplacePixels does nothing.
|
||||||
|
//
|
||||||
|
// ReplacePixels always returns nil as of 1.5.0-alpha.
|
||||||
|
//
|
||||||
// This function is concurrent-safe.
|
// This function is concurrent-safe.
|
||||||
func (i *Image) ReplacePixels(p []uint8) error {
|
func (i *Image) ReplacePixels(p []uint8) error {
|
||||||
theImagesForRestoring.resetPixelsIfDependingOn(i, glContext())
|
theImagesForRestoring.resetPixelsIfDependingOn(i, glContext())
|
||||||
return i.impl.ReplacePixels(p)
|
i.impl.ReplacePixels(p)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// A DrawImageOptions represents options to render an image on an image.
|
// A DrawImageOptions represents options to render an image on an image.
|
||||||
|
17
imageimpl.go
17
imageimpl.go
@ -15,7 +15,6 @@
|
|||||||
package ebiten
|
package ebiten
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
@ -184,29 +183,26 @@ func (i *imageImpl) restore(context *opengl.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *imageImpl) Dispose() error {
|
func (i *imageImpl) Dispose() {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
if i.restorable == nil {
|
if i.restorable == nil {
|
||||||
return errors.New("ebiten: image is already disposed")
|
return
|
||||||
}
|
|
||||||
if err := i.restorable.Dispose(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
i.restorable.Dispose()
|
||||||
i.restorable = nil
|
i.restorable = nil
|
||||||
runtime.SetFinalizer(i, nil)
|
runtime.SetFinalizer(i, nil)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *imageImpl) ReplacePixels(p []uint8) error {
|
func (i *imageImpl) ReplacePixels(p []uint8) {
|
||||||
w, h := i.restorable.Size()
|
w, h := i.restorable.Size()
|
||||||
if l := 4 * w * h; len(p) != l {
|
if l := 4 * w * h; len(p) != l {
|
||||||
return fmt.Errorf("ebiten: p's length must be %d", l)
|
panic(fmt.Sprintf("ebiten: len(p) was %d but must be %d", len(p), l))
|
||||||
}
|
}
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
if i.restorable == nil {
|
if i.restorable == nil {
|
||||||
return errors.New("ebiten: image is already disposed")
|
return
|
||||||
}
|
}
|
||||||
w2, h2 := graphics.NextPowerOf2Int(w), graphics.NextPowerOf2Int(h)
|
w2, h2 := graphics.NextPowerOf2Int(w), graphics.NextPowerOf2Int(h)
|
||||||
pix := make([]uint8, 4*w2*h2)
|
pix := make([]uint8, 4*w2*h2)
|
||||||
@ -214,7 +210,6 @@ func (i *imageImpl) ReplacePixels(p []uint8) error {
|
|||||||
copy(pix[j*w2*4:], p[j*w*4:(j+1)*w*4])
|
copy(pix[j*w2*4:], p[j*w*4:(j+1)*w*4])
|
||||||
}
|
}
|
||||||
i.restorable.ReplacePixels(pix)
|
i.restorable.ReplacePixels(pix)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *imageImpl) isDisposed() bool {
|
func (i *imageImpl) isDisposed() bool {
|
||||||
|
@ -261,14 +261,13 @@ func (p *Image) Restore(context *opengl.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Image) Dispose() error {
|
func (p *Image) Dispose() {
|
||||||
p.image.Dispose()
|
p.image.Dispose()
|
||||||
p.image = nil
|
p.image = nil
|
||||||
p.basePixels = nil
|
p.basePixels = nil
|
||||||
p.baseColor = color.RGBA{}
|
p.baseColor = color.RGBA{}
|
||||||
p.drawImageHistory = nil
|
p.drawImageHistory = nil
|
||||||
p.stale = false
|
p.stale = false
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Image) IsInvalidated(context *opengl.Context) bool {
|
func (p *Image) IsInvalidated(context *opengl.Context) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user