Made ownership of textures more explicit
This commit is contained in:
parent
7b28419432
commit
6ac653adb6
@ -19,7 +19,7 @@ type Backend interface {
|
||||
|
||||
// NewTexture creates a new texture from an image. The backend must
|
||||
// reject any texture that was not made by it.
|
||||
NewTexture (image.Image) canvas.Texture
|
||||
NewTexture (image.Image) canvas.TextureCloser
|
||||
|
||||
// Run runs the event loop until Stop() is called, or the backend
|
||||
// experiences a fatal error.
|
||||
|
@ -5,26 +5,16 @@ import "image"
|
||||
|
||||
// Texture is a handle that points to a 2D raster image managed by the backend.
|
||||
type Texture interface {
|
||||
io.Closer
|
||||
image.Image
|
||||
|
||||
// Clip returns a smaller section of this texture, pointing to the same
|
||||
// internal data. Becaue of this, closing a clipped section will close
|
||||
// the original texture as well.
|
||||
// internal data.
|
||||
Clip (image.Rectangle) Texture
|
||||
}
|
||||
|
||||
type protectedTexture struct {
|
||||
// TextureCloser is a texture that can be closed. Anything that receives a
|
||||
// TextureCloser must close it after use.
|
||||
type TextureCloser interface {
|
||||
Texture
|
||||
}
|
||||
|
||||
func (protectedTexture) Close () error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Protect makes the Close() method of a texture do nothing. This is useful if
|
||||
// several of the same texture are given out to different objects, but only one
|
||||
// has the responsibility of closing it.
|
||||
func Protect (texture Texture) Texture {
|
||||
return protectedTexture { Texture: texture }
|
||||
io.Closer
|
||||
}
|
||||
|
2
tomo.go
2
tomo.go
@ -83,7 +83,7 @@ func NewContainerBox () ContainerBox {
|
||||
|
||||
// NewTexture creates a new texture from an image. When no longer in use, it
|
||||
// must be freed using Close().
|
||||
func NewTexture (source image.Image) canvas.Texture {
|
||||
func NewTexture (source image.Image) canvas.TextureCloser {
|
||||
assertBackend()
|
||||
return backend.NewTexture(source)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user