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