mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 19:58: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()
|
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.
|
// ReplacePixels replaces the image pixels with the given pixels slice.
|
||||||
//
|
//
|
||||||
// If pixels is nil, ReplacePixels clears the specified reagion.
|
// 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)
|
theImages.makeStaleIfDependingOn(i)
|
||||||
|
|
||||||
if pixels == nil {
|
if pixels == nil {
|
||||||
|
// TODO: Allocating bytes for all pixels are wasteful. Allocate memory only for required regions
|
||||||
|
// (#897).
|
||||||
pixels = make([]byte, 4*width*height)
|
pixels = make([]byte, 4*width*height)
|
||||||
}
|
}
|
||||||
i.image.ReplacePixels(pixels, x, y, 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)
|
i.backend.page.Free(i.node)
|
||||||
if !i.backend.page.IsEmpty() {
|
if !i.backend.page.IsEmpty() {
|
||||||
// As this part can be reused, this should be cleared explicitly.
|
// As this part can be reused, this should be cleared explicitly.
|
||||||
x, y, w, h := i.region()
|
i.backend.restorable.ClearPixels(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)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user