mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +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
|
||||
}
|
||||
|
||||
func newImageWithScreenFramebuffer(width, height int) *Image {
|
||||
func newScreenFramebufferImage(width, height int) *Image {
|
||||
i := &Image{
|
||||
mipmap: newMipmap(shareable.NewScreenFramebufferImage(width, height)),
|
||||
filter: FilterDefault,
|
||||
|
@ -166,6 +166,7 @@ type Image struct {
|
||||
width int
|
||||
height int
|
||||
disposed bool
|
||||
screen bool
|
||||
|
||||
backend *backend
|
||||
|
||||
@ -494,6 +495,14 @@ func (i *Image) allocate(shareable bool) {
|
||||
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() {
|
||||
i.backend = &backend{
|
||||
restorable: restorable.NewImage(i.width, i.height),
|
||||
@ -550,19 +559,13 @@ func (i *Image) Dump(path string) error {
|
||||
}
|
||||
|
||||
func NewScreenFramebufferImage(width, height int) *Image {
|
||||
backendsM.Lock()
|
||||
defer backendsM.Unlock()
|
||||
|
||||
r := restorable.NewScreenFramebufferImage(width, height)
|
||||
// Actual allocation is done lazily.
|
||||
i := &Image{
|
||||
width: width,
|
||||
height: height,
|
||||
backend: &backend{
|
||||
restorable: r,
|
||||
},
|
||||
width: width,
|
||||
height: height,
|
||||
screen: true,
|
||||
neverShared: true,
|
||||
}
|
||||
runtime.SetFinalizer(i, (*Image).disposeFromFinalizer)
|
||||
return i
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ func (c *uiContext) SetSize(screenWidth, screenHeight int, screenScale float64)
|
||||
w := int(math.Ceil(float64(screenWidth) * screenScale))
|
||||
h := int(math.Ceil(float64(screenHeight) * screenScale))
|
||||
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.screenHeight = h
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user