internal/restorable: move SwapBuffers to internal/atlas

Updates #805
This commit is contained in:
Hajime Hoshi 2024-01-09 04:54:38 +09:00
parent 7c9266d8b6
commit f610cb5724
3 changed files with 13 additions and 39 deletions

View File

@ -21,6 +21,7 @@ import (
"runtime"
"sync"
"github.com/hajimehoshi/ebiten/v2/internal/debug"
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
@ -762,7 +763,18 @@ func SwapBuffers(graphicsDriver graphicsdriver.Graphics) error {
}
}()
if err := restorable.SwapBuffers(graphicsDriver); err != nil {
if debug.IsDebug {
debug.Logf("Internal image sizes:\n")
imgs := make([]*graphicscommand.Image, 0, len(theBackends))
for _, backend := range theBackends {
if backend.restorable == nil {
continue
}
imgs = append(imgs, backend.restorable.Image)
}
graphicscommand.LogImagesInfo(imgs)
}
if err := graphicscommand.FlushCommands(graphicsDriver, true); err != nil {
return err
}
return nil

View File

@ -67,7 +67,6 @@ func NewImage(width, height int, imageType ImageType) *Image {
// devices.
iw, ih := i.Image.InternalSize()
clearImage(i.Image, image.Rect(0, 0, iw, ih))
theImages.add(i)
return i
}
@ -177,7 +176,6 @@ func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, pixels []byte
//
// After disposing, calling the function of the image causes unexpected results.
func (i *Image) Dispose() {
theImages.remove(i)
i.Image.Dispose()
i.Image = nil
}

View File

@ -15,46 +15,10 @@
package restorable
import (
"github.com/hajimehoshi/ebiten/v2/internal/debug"
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
)
// images is a set of Image objects.
type images struct {
images map[*Image]struct{}
}
// theImages represents the images for the current process.
var theImages = &images{
images: map[*Image]struct{}{},
}
func SwapBuffers(graphicsDriver graphicsdriver.Graphics) error {
if debug.IsDebug {
debug.Logf("Internal image sizes:\n")
imgs := make([]*graphicscommand.Image, 0, len(theImages.images))
for i := range theImages.images {
imgs = append(imgs, i.Image)
}
graphicscommand.LogImagesInfo(imgs)
}
if err := graphicscommand.FlushCommands(graphicsDriver, true); err != nil {
return err
}
return nil
}
// add adds img to the images.
func (i *images) add(img *Image) {
i.images[img] = struct{}{}
}
// remove removes img from the images.
func (i *images) remove(img *Image) {
delete(i.images, img)
}
var graphicsDriverInitialized bool
// InitializeGraphicsDriverState initializes the graphics driver state.