mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-03 22:44:28 +01:00
restorable: Refactoring: Replace CopyPixels with NewImageFromImage
This commit is contained in:
parent
9e8b23f7dc
commit
aee26eec1e
@ -143,6 +143,24 @@ func NewImage(width, height int) *Image {
|
|||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewImage creates a new image and copies the pixels of the given source image.
|
||||||
|
//
|
||||||
|
// The given size (width and height) doesn't have to match with the source image's size.
|
||||||
|
// The image is copied at the left-upper corner of the new image.
|
||||||
|
func NewImageFromImage(width, height int, src *Image) *Image {
|
||||||
|
i := NewImage(width, height)
|
||||||
|
|
||||||
|
// Do not use DrawTriangles here. ReplacePixels will be called on a part of newImg later, and it looked like
|
||||||
|
// ReplacePixels on a part of image deletes other region that are rendered by DrawTriangles (#593, #758).
|
||||||
|
i.image.CopyPixels(src.image)
|
||||||
|
|
||||||
|
// As pixels should not be obtained here, making the image stale is inevitable.
|
||||||
|
// TODO: Copy pixel data from the source instead of making this stale (#897).
|
||||||
|
i.makeStale()
|
||||||
|
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
func (i *Image) MakeVolatile() {
|
func (i *Image) MakeVolatile() {
|
||||||
i.volatile = true
|
i.volatile = true
|
||||||
}
|
}
|
||||||
@ -270,17 +288,6 @@ func (i *Image) makeStale() {
|
|||||||
// the former image can be restored from the latest state of the latter image.
|
// the former image can be restored from the latest state of the latter image.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) CopyPixels(src *Image) {
|
|
||||||
// TODO: Avoid making other images stale if possible. (#514)
|
|
||||||
// For this purpuse, images should remember which part of that is used for DrawTriangles.
|
|
||||||
theImages.makeStaleIfDependingOn(i)
|
|
||||||
|
|
||||||
i.image.CopyPixels(src.image)
|
|
||||||
|
|
||||||
// As pixels should not be obtained here, making the image stale is inevitable.
|
|
||||||
i.makeStale()
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearPixels clears the specified region by ReplacePixels.
|
// ClearPixels clears the specified region by ReplacePixels.
|
||||||
func (i *Image) ClearPixels(x, y, width, height int) {
|
func (i *Image) ClearPixels(x, y, width, height int) {
|
||||||
// TODO: Allocating bytes for all pixels are wasteful. Allocate memory only for required regions (#897).
|
// TODO: Allocating bytes for all pixels are wasteful. Allocate memory only for required regions (#897).
|
||||||
|
@ -121,12 +121,8 @@ func (b *backend) TryAlloc(width, height int) (*packing.Node, bool) {
|
|||||||
b.page.Extend()
|
b.page.Extend()
|
||||||
}
|
}
|
||||||
s := b.page.Size()
|
s := b.page.Size()
|
||||||
newImg := restorable.NewImage(s, s)
|
newImg := restorable.NewImageFromImage(s, s, b.restorable)
|
||||||
oldImg := b.restorable
|
b.restorable.Dispose()
|
||||||
// Do not use DrawTriangles here. ReplacePixels will be called on a part of newImg later, and it looked like
|
|
||||||
// ReplacePixels on a part of image deletes other region that are rendered by DrawTriangles (#593, #758).
|
|
||||||
newImg.CopyPixels(oldImg)
|
|
||||||
oldImg.Dispose()
|
|
||||||
b.restorable = newImg
|
b.restorable = newImg
|
||||||
|
|
||||||
n := b.page.Alloc(width, height)
|
n := b.page.Alloc(width, height)
|
||||||
|
Loading…
Reference in New Issue
Block a user