mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
restorable: Add ClearPixels
This hides the implementation details of allocating byte slice. This change also adds comments about #897.
This commit is contained in:
parent
5ec2f66524
commit
fd9e376ff6
@ -281,6 +281,12 @@ func (i *Image) CopyPixels(src *Image) {
|
||||
i.makeStale()
|
||||
}
|
||||
|
||||
// ClearPixels clears the specified region by ReplacePixels.
|
||||
func (i *Image) ClearPixels(x, y, width, height int) {
|
||||
// TODO: Allocating bytes for all pixels are wasteful. Allocate memory only for required regions (#897).
|
||||
i.ReplacePixels(make([]byte, 4*width*height), x, y, width, height)
|
||||
}
|
||||
|
||||
// ReplacePixels replaces the image pixels with the given pixels slice.
|
||||
//
|
||||
// If pixels is nil, ReplacePixels clears the specified reagion.
|
||||
@ -298,6 +304,8 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
||||
theImages.makeStaleIfDependingOn(i)
|
||||
|
||||
if pixels == nil {
|
||||
// TODO: Allocating bytes for all pixels are wasteful. Allocate memory only for required regions
|
||||
// (#897).
|
||||
pixels = make([]byte, 4*width*height)
|
||||
}
|
||||
i.image.ReplacePixels(pixels, x, y, width, height)
|
||||
|
@ -400,9 +400,7 @@ func (i *Image) dispose(markDisposed bool) {
|
||||
i.backend.page.Free(i.node)
|
||||
if !i.backend.page.IsEmpty() {
|
||||
// As this part can be reused, this should be cleared explicitly.
|
||||
x, y, w, h := i.region()
|
||||
// TODO: Now nil cannot be used here (see the test result). Fix this.
|
||||
i.backend.restorable.ReplacePixels(make([]byte, 4*w*h), x, y, w, h)
|
||||
i.backend.restorable.ClearPixels(i.region())
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user