From a324cfd3b6e70c23ccafc70ad78a097633fbbdc0 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 6 Sep 2024 14:27:46 +0900 Subject: [PATCH] Revert "internal/restorable: remove ImageType" This reverts commit 21ef462c379337b74e7ac7fedca2947f5c4fff8a. Updates #3083 --- internal/atlas/image.go | 9 ++++----- internal/restorable/image.go | 24 ++++++++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/internal/atlas/image.go b/internal/atlas/image.go index ca8add1c6..f014b528d 100644 --- a/internal/atlas/image.go +++ b/internal/atlas/image.go @@ -119,8 +119,7 @@ func (b *backend) tryAlloc(width, height int) (*packing.Node, bool) { return nil, false } - w, h := b.page.Size() - b.restorable = b.restorable.Extend(w, h) + b.restorable = b.restorable.Extend(b.page.Size()) return n, true } @@ -672,7 +671,7 @@ func (i *Image) allocate(forbiddenBackends []*backend, asSource bool) { } // A screen image doesn't have a padding. i.backend = &backend{ - restorable: restorable.NewImage(i.width, i.height, true), + restorable: restorable.NewImage(i.width, i.height, restorable.ImageTypeScreen), } theBackends = append(theBackends, i.backend) return @@ -687,7 +686,7 @@ func (i *Image) allocate(forbiddenBackends []*backend, asSource bool) { } i.backend = &backend{ - restorable: restorable.NewImage(wp, hp, false), + restorable: restorable.NewImage(wp, hp, restorable.ImageTypeRegular), source: asSource && i.imageType == ImageTypeRegular, } theBackends = append(theBackends, i.backend) @@ -733,7 +732,7 @@ loop: } b := &backend{ - restorable: restorable.NewImage(width, height, false), + restorable: restorable.NewImage(width, height, restorable.ImageTypeRegular), page: packing.NewPage(width, height, maxSize), source: asSource, } diff --git a/internal/restorable/image.go b/internal/restorable/image.go index 3d533585f..6298d761c 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -23,6 +23,16 @@ import ( "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver" ) +type ImageType int + +const ( + // ImageTypeRegular indicates the image is a regular image. + ImageTypeRegular ImageType = iota + + // ImageTypeScreen indicates the image is used as an actual screen. + ImageTypeScreen +) + // Image represents an image. type Image struct { // Image is the underlying image. @@ -32,6 +42,8 @@ type Image struct { width int height int + + imageType ImageType } // NewImage creates an emtpy image with the given size. @@ -39,11 +51,12 @@ type Image struct { // The returned image is cleared. // // Note that Dispose is not called automatically. -func NewImage(width, height int, screen bool) *Image { +func NewImage(width, height int, imageType ImageType) *Image { i := &Image{ - Image: graphicscommand.NewImage(width, height, screen), - width: width, - height: height, + Image: graphicscommand.NewImage(width, height, imageType == ImageTypeScreen), + width: width, + height: height, + imageType: imageType, } // This needs to use 'InternalSize' to render the whole region, or edges are unexpectedly cleared on some @@ -61,8 +74,7 @@ func (i *Image) Extend(width, height int) *Image { return i } - // Assume that the screen image is never extended. - newImg := NewImage(width, height, false) + newImg := NewImage(width, height, i.imageType) // Use DrawTriangles instead of WritePixels because the image i might be stale and not have its pixels // information.