mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
shareable: Rename ImagePart -> Image
This commit is contained in:
parent
6c6b25647a
commit
a2d6ae7eee
@ -134,7 +134,7 @@ func (c *graphicsContext) needsRestoring() (bool, error) {
|
||||
if web.IsBrowser() {
|
||||
return c.invalidated, nil
|
||||
}
|
||||
return c.offscreen.shareableImagePart.IsInvalidated()
|
||||
return c.offscreen.shareableImage.IsInvalidated()
|
||||
}
|
||||
|
||||
func (c *graphicsContext) restoreIfNeeded() error {
|
||||
|
42
image.go
42
image.go
@ -51,7 +51,7 @@ type Image struct {
|
||||
// See strings.Builder for similar examples.
|
||||
addr *Image
|
||||
|
||||
shareableImagePart *shareable.ImagePart
|
||||
shareableImage *shareable.Image
|
||||
|
||||
filter Filter
|
||||
}
|
||||
@ -70,7 +70,7 @@ func (i *Image) copyCheck() {
|
||||
|
||||
// Size returns the size of the image.
|
||||
func (i *Image) Size() (width, height int) {
|
||||
return i.shareableImagePart.Size()
|
||||
return i.shareableImage.Size()
|
||||
}
|
||||
|
||||
// Clear resets the pixels of the image into 0.
|
||||
@ -116,7 +116,7 @@ func (i *Image) fill(r, g, b, a uint8) {
|
||||
}
|
||||
|
||||
func (i *Image) isDisposed() bool {
|
||||
return i.shareableImagePart == nil
|
||||
return i.shareableImage == nil
|
||||
}
|
||||
|
||||
// DrawImage draws the given image on the image i.
|
||||
@ -231,7 +231,7 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
|
||||
filter = graphics.Filter(img.filter)
|
||||
}
|
||||
|
||||
i.shareableImagePart.DrawImage(img.shareableImagePart, sx0, sy0, sx1, sy1, geom, options.ColorM.impl, mode, filter)
|
||||
i.shareableImage.DrawImage(img.shareableImage, sx0, sy0, sx1, sy1, geom, options.ColorM.impl, mode, filter)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -257,7 +257,7 @@ func (i *Image) At(x, y int) color.Color {
|
||||
if i.isDisposed() {
|
||||
return color.RGBA{}
|
||||
}
|
||||
clr, err := i.shareableImagePart.At(x, y)
|
||||
clr, err := i.shareableImage.At(x, y)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -276,8 +276,8 @@ func (i *Image) Dispose() error {
|
||||
if i.isDisposed() {
|
||||
return nil
|
||||
}
|
||||
i.shareableImagePart.Dispose()
|
||||
i.shareableImagePart = nil
|
||||
i.shareableImage.Dispose()
|
||||
i.shareableImage = nil
|
||||
runtime.SetFinalizer(i, nil)
|
||||
return nil
|
||||
}
|
||||
@ -298,7 +298,7 @@ func (i *Image) ReplacePixels(p []byte) error {
|
||||
if i.isDisposed() {
|
||||
return nil
|
||||
}
|
||||
i.shareableImagePart.ReplacePixels(p)
|
||||
i.shareableImage.ReplacePixels(p)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -350,10 +350,10 @@ type DrawImageOptions struct {
|
||||
//
|
||||
// Error returned by NewImage is always nil as of 1.5.0-alpha.
|
||||
func NewImage(width, height int, filter Filter) (*Image, error) {
|
||||
s := shareable.NewImagePart(width, height)
|
||||
s := shareable.NewImage(width, height)
|
||||
i := &Image{
|
||||
shareableImagePart: s,
|
||||
filter: filter,
|
||||
shareableImage: s,
|
||||
filter: filter,
|
||||
}
|
||||
i.fill(0, 0, 0, 0)
|
||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||
@ -362,10 +362,10 @@ func NewImage(width, height int, filter Filter) (*Image, error) {
|
||||
|
||||
// newImageWithoutInit creates an empty image without initialization.
|
||||
func newImageWithoutInit(width, height int) *Image {
|
||||
s := shareable.NewImagePart(width, height)
|
||||
s := shareable.NewImage(width, height)
|
||||
i := &Image{
|
||||
shareableImagePart: s,
|
||||
filter: FilterDefault,
|
||||
shareableImage: s,
|
||||
filter: FilterDefault,
|
||||
}
|
||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||
return i
|
||||
@ -388,8 +388,8 @@ func newImageWithoutInit(width, height int) *Image {
|
||||
// Error returned by newVolatileImage is always nil as of 1.5.0-alpha.
|
||||
func newVolatileImage(width, height int, filter Filter) *Image {
|
||||
i := &Image{
|
||||
shareableImagePart: shareable.NewVolatileImagePart(width, height),
|
||||
filter: filter,
|
||||
shareableImage: shareable.NewVolatileImage(width, height),
|
||||
filter: filter,
|
||||
}
|
||||
i.fill(0, 0, 0, 0)
|
||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||
@ -409,10 +409,10 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
|
||||
|
||||
width, height := size.X, size.Y
|
||||
|
||||
s := shareable.NewImagePart(width, height)
|
||||
s := shareable.NewImage(width, height)
|
||||
i := &Image{
|
||||
shareableImagePart: s,
|
||||
filter: filter,
|
||||
shareableImage: s,
|
||||
filter: filter,
|
||||
}
|
||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||
|
||||
@ -422,8 +422,8 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
|
||||
|
||||
func newImageWithScreenFramebuffer(width, height int) *Image {
|
||||
i := &Image{
|
||||
shareableImagePart: shareable.NewScreenFramebufferImagePart(width, height),
|
||||
filter: FilterDefault,
|
||||
shareableImage: shareable.NewScreenFramebufferImage(width, height),
|
||||
filter: FilterDefault,
|
||||
}
|
||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||
return i
|
||||
|
@ -36,14 +36,14 @@ var (
|
||||
theBackends = []*backend{}
|
||||
)
|
||||
|
||||
type ImagePart struct {
|
||||
type Image struct {
|
||||
backend *backend
|
||||
|
||||
// If node is nil, the image is not shared.
|
||||
node *packing.Node
|
||||
}
|
||||
|
||||
func (s *ImagePart) ensureNotShared() {
|
||||
func (s *Image) ensureNotShared() {
|
||||
if s.node == nil {
|
||||
return
|
||||
}
|
||||
@ -58,7 +58,7 @@ func (s *ImagePart) ensureNotShared() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ImagePart) region() (x, y, width, height int) {
|
||||
func (s *Image) region() (x, y, width, height int) {
|
||||
if s.node == nil {
|
||||
w, h := s.backend.restorable.Size()
|
||||
return 0, 0, w, h
|
||||
@ -66,12 +66,12 @@ func (s *ImagePart) region() (x, y, width, height int) {
|
||||
return s.node.Region()
|
||||
}
|
||||
|
||||
func (s *ImagePart) Size() (width, height int) {
|
||||
func (s *Image) Size() (width, height int) {
|
||||
_, _, w, h := s.region()
|
||||
return w, h
|
||||
}
|
||||
|
||||
func (s *ImagePart) DrawImage(img *ImagePart, sx0, sy0, sx1, sy1 int, geom *affine.GeoM, colorm *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) {
|
||||
func (s *Image) DrawImage(img *Image, sx0, sy0, sx1, sy1 int, geom *affine.GeoM, colorm *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) {
|
||||
s.ensureNotShared()
|
||||
|
||||
// Compare i and img after ensuring i is not shared, or
|
||||
@ -88,7 +88,7 @@ func (s *ImagePart) DrawImage(img *ImagePart, sx0, sy0, sx1, sy1 int, geom *affi
|
||||
s.backend.restorable.DrawImage(img.backend.restorable, sx0, sy0, sx1, sy1, geom, colorm, mode, filter)
|
||||
}
|
||||
|
||||
func (s *ImagePart) ReplacePixels(p []byte) {
|
||||
func (s *Image) ReplacePixels(p []byte) {
|
||||
x, y, w, h := s.region()
|
||||
if l := 4 * w * h; len(p) != l {
|
||||
panic(fmt.Sprintf("shareable: len(p) was %d but must be %d", len(p), l))
|
||||
@ -96,7 +96,7 @@ func (s *ImagePart) ReplacePixels(p []byte) {
|
||||
s.backend.restorable.ReplacePixels(p, x, y, w, h)
|
||||
}
|
||||
|
||||
func (s *ImagePart) At(x, y int) (color.Color, error) {
|
||||
func (s *Image) At(x, y int) (color.Color, error) {
|
||||
ox, oy, w, h := s.region()
|
||||
if x < 0 || y < 0 || x >= w || y >= h {
|
||||
return color.RGBA{}, nil
|
||||
@ -104,11 +104,11 @@ func (s *ImagePart) At(x, y int) (color.Color, error) {
|
||||
return s.backend.restorable.At(x+ox, y+oy)
|
||||
}
|
||||
|
||||
func (s *ImagePart) isDisposed() bool {
|
||||
func (s *Image) isDisposed() bool {
|
||||
return s.backend == nil
|
||||
}
|
||||
|
||||
func (s *ImagePart) Dispose() {
|
||||
func (s *Image) Dispose() {
|
||||
if s.isDisposed() {
|
||||
return
|
||||
}
|
||||
@ -141,13 +141,13 @@ func (s *ImagePart) Dispose() {
|
||||
theBackends = append(theBackends[:index], theBackends[index+1:]...)
|
||||
}
|
||||
|
||||
func (s *ImagePart) IsInvalidated() (bool, error) {
|
||||
func (s *Image) IsInvalidated() (bool, error) {
|
||||
return s.backend.restorable.IsInvalidated()
|
||||
}
|
||||
|
||||
var shareableImageLock sync.Mutex
|
||||
|
||||
func NewImagePart(width, height int) *ImagePart {
|
||||
func NewImage(width, height int) *Image {
|
||||
const maxSize = 2048
|
||||
|
||||
shareableImageLock.Lock()
|
||||
@ -157,14 +157,14 @@ func NewImagePart(width, height int) *ImagePart {
|
||||
s := &backend{
|
||||
restorable: restorable.NewImage(width, height, false),
|
||||
}
|
||||
return &ImagePart{
|
||||
return &Image{
|
||||
backend: s,
|
||||
}
|
||||
}
|
||||
|
||||
for _, s := range theBackends {
|
||||
if n := s.page.Alloc(width, height); n != nil {
|
||||
return &ImagePart{
|
||||
return &Image{
|
||||
backend: s,
|
||||
node: n,
|
||||
}
|
||||
@ -180,24 +180,24 @@ func NewImagePart(width, height int) *ImagePart {
|
||||
if n == nil {
|
||||
panic("not reached")
|
||||
}
|
||||
return &ImagePart{
|
||||
return &Image{
|
||||
backend: s,
|
||||
node: n,
|
||||
}
|
||||
}
|
||||
|
||||
func NewVolatileImagePart(width, height int) *ImagePart {
|
||||
func NewVolatileImage(width, height int) *Image {
|
||||
r := restorable.NewImage(width, height, true)
|
||||
return &ImagePart{
|
||||
return &Image{
|
||||
backend: &backend{
|
||||
restorable: r,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func NewScreenFramebufferImagePart(width, height int) *ImagePart {
|
||||
func NewScreenFramebufferImage(width, height int) *Image {
|
||||
r := restorable.NewScreenFramebufferImage(width, height)
|
||||
return &ImagePart{
|
||||
return &Image{
|
||||
backend: &backend{
|
||||
restorable: r,
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user