Revert "internal/restorable: move DumpImages to internal/atlas"

This reverts commit 7c9266d8b6.

Updates #3083
This commit is contained in:
Hajime Hoshi 2024-09-06 14:39:33 +09:00
parent a9d8f374c8
commit 169b9fe51e
3 changed files with 28 additions and 27 deletions

View File

@ -23,7 +23,6 @@ import (
"sync"
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/v2/internal/packing"
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
@ -840,12 +839,5 @@ func DumpImages(graphicsDriver graphicsdriver.Graphics, dir string) (string, err
panic("atlas: DumpImages must be called in between BeginFrame and EndFrame")
}
images := make([]*graphicscommand.Image, 0, len(theBackends))
for _, backend := range theBackends {
if backend.restorable == nil {
continue
}
images = append(images, backend.restorable.Image)
}
return graphicscommand.DumpImages(images, graphicsDriver, dir)
return restorable.DumpImages(graphicsDriver, dir)
}

View File

@ -35,10 +35,7 @@ const (
// Image represents an image.
type Image struct {
// Image is the underlying image.
// This member is exported on purpose.
// TODO: Move the implementation to internal/atlas package (#805).
Image *graphicscommand.Image
image *graphicscommand.Image
width int
height int
@ -57,7 +54,7 @@ func NewImage(width, height int, imageType ImageType) *Image {
}
i := &Image{
Image: graphicscommand.NewImage(width, height, imageType == ImageTypeScreen),
image: graphicscommand.NewImage(width, height, imageType == ImageTypeScreen),
width: width,
height: height,
imageType: imageType,
@ -65,8 +62,8 @@ func NewImage(width, height int, imageType ImageType) *Image {
// This needs to use 'InternalSize' to render the whole region, or edges are unexpectedly cleared on some
// devices.
iw, ih := i.Image.InternalSize()
clearImage(i.Image, image.Rect(0, 0, iw, ih))
iw, ih := i.image.InternalSize()
clearImage(i.image, image.Rect(0, 0, iw, ih))
theImages.add(i)
return i
}
@ -84,7 +81,7 @@ func (i *Image) Extend(width, height int) *Image {
// Use DrawTriangles instead of WritePixels because the image i might be stale and not have its pixels
// information.
srcs := [graphics.ShaderSrcImageCount]*Image{i}
sw, sh := i.Image.InternalSize()
sw, sh := i.image.InternalSize()
vs := make([]float32, 4*graphics.VertexFloatCount)
graphics.QuadVerticesFromDstAndSrc(vs, 0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1)
is := graphics.QuadIndices()
@ -120,9 +117,9 @@ func (i *Image) WritePixels(pixels *graphics.ManagedBytes, region image.Rectangl
}
if pixels != nil {
i.Image.WritePixels(pixels, region)
i.image.WritePixels(pixels, region)
} else {
clearImage(i.Image, region)
clearImage(i.image, region)
}
}
@ -148,13 +145,13 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderSrcImageCount]*Image, vertice
if src == nil {
continue
}
imgs[i] = src.Image
imgs[i] = src.image
}
i.Image.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.shader, uniforms, fillRule)
i.image.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.shader, uniforms, fillRule)
}
func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, pixels []byte, region image.Rectangle) error {
if err := i.Image.ReadPixels(graphicsDriver, []graphicsdriver.PixelsArgs{
if err := i.image.ReadPixels(graphicsDriver, []graphicsdriver.PixelsArgs{
{
Pixels: pixels,
Region: region,
@ -170,14 +167,14 @@ 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
i.image.Dispose()
i.image = nil
}
func (i *Image) Dump(graphicsDriver graphicsdriver.Graphics, path string, blackbg bool, rect image.Rectangle) (string, error) {
return i.Image.Dump(graphicsDriver, path, blackbg, rect)
return i.image.Dump(graphicsDriver, path, blackbg, rect)
}
func (i *Image) InternalSize() (int, int) {
return i.Image.InternalSize()
return i.image.InternalSize()
}

View File

@ -35,7 +35,7 @@ func SwapBuffers(graphicsDriver graphicsdriver.Graphics) error {
debug.FrameLogf("Internal image sizes:\n")
imgs := make([]*graphicscommand.Image, 0, len(theImages.images))
for i := range theImages.images {
imgs = append(imgs, i.Image)
imgs = append(imgs, i.image)
}
graphicscommand.LogImagesInfo(imgs)
}
@ -45,6 +45,18 @@ func SwapBuffers(graphicsDriver graphicsdriver.Graphics) error {
return nil
}
// DumpImages dumps all the current images to the specified directory.
//
// This is for testing usage.
func DumpImages(graphicsDriver graphicsdriver.Graphics, dir string) (string, error) {
images := make([]*graphicscommand.Image, 0, len(theImages.images))
for img := range theImages.images {
images = append(images, img.image)
}
return graphicscommand.DumpImages(images, graphicsDriver, dir)
}
// add adds img to the images.
func (i *images) add(img *Image) {
i.images[img] = struct{}{}