mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
shareable: Allocate the screen framebuffer image lazily
This improves consistency.
This commit is contained in:
parent
ef56d0a535
commit
e931494c66
2
image.go
2
image.go
@ -724,7 +724,7 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
|
|||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newImageWithScreenFramebuffer(width, height int) *Image {
|
func newScreenFramebufferImage(width, height int) *Image {
|
||||||
i := &Image{
|
i := &Image{
|
||||||
mipmap: newMipmap(shareable.NewScreenFramebufferImage(width, height)),
|
mipmap: newMipmap(shareable.NewScreenFramebufferImage(width, height)),
|
||||||
filter: FilterDefault,
|
filter: FilterDefault,
|
||||||
|
@ -166,6 +166,7 @@ type Image struct {
|
|||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
disposed bool
|
disposed bool
|
||||||
|
screen bool
|
||||||
|
|
||||||
backend *backend
|
backend *backend
|
||||||
|
|
||||||
@ -494,6 +495,14 @@ func (i *Image) allocate(shareable bool) {
|
|||||||
panic("shareable: the image is already allocated")
|
panic("shareable: the image is already allocated")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if i.screen {
|
||||||
|
i.backend = &backend{
|
||||||
|
restorable: restorable.NewScreenFramebufferImage(i.width, i.height),
|
||||||
|
}
|
||||||
|
runtime.SetFinalizer(i, (*Image).disposeFromFinalizer)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if !shareable || !i.shareable() {
|
if !shareable || !i.shareable() {
|
||||||
i.backend = &backend{
|
i.backend = &backend{
|
||||||
restorable: restorable.NewImage(i.width, i.height),
|
restorable: restorable.NewImage(i.width, i.height),
|
||||||
@ -550,19 +559,13 @@ func (i *Image) Dump(path string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewScreenFramebufferImage(width, height int) *Image {
|
func NewScreenFramebufferImage(width, height int) *Image {
|
||||||
backendsM.Lock()
|
// Actual allocation is done lazily.
|
||||||
defer backendsM.Unlock()
|
|
||||||
|
|
||||||
r := restorable.NewScreenFramebufferImage(width, height)
|
|
||||||
i := &Image{
|
i := &Image{
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
backend: &backend{
|
screen: true,
|
||||||
restorable: r,
|
|
||||||
},
|
|
||||||
neverShared: true,
|
neverShared: true,
|
||||||
}
|
}
|
||||||
runtime.SetFinalizer(i, (*Image).disposeFromFinalizer)
|
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ func (c *uiContext) SetSize(screenWidth, screenHeight int, screenScale float64)
|
|||||||
w := int(math.Ceil(float64(screenWidth) * screenScale))
|
w := int(math.Ceil(float64(screenWidth) * screenScale))
|
||||||
h := int(math.Ceil(float64(screenHeight) * screenScale))
|
h := int(math.Ceil(float64(screenHeight) * screenScale))
|
||||||
px0, py0, px1, py1 := uidriver.Get().ScreenPadding()
|
px0, py0, px1, py1 := uidriver.Get().ScreenPadding()
|
||||||
c.screen = newImageWithScreenFramebuffer(w+int(math.Ceil(px0+px1)), h+int(math.Ceil(py0+py1)))
|
c.screen = newScreenFramebufferImage(w+int(math.Ceil(px0+px1)), h+int(math.Ceil(py0+py1)))
|
||||||
c.screenWidth = w
|
c.screenWidth = w
|
||||||
c.screenHeight = h
|
c.screenHeight = h
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user