diff --git a/backend.go b/backend.go index dba504a..e74810f 100644 --- a/backend.go +++ b/backend.go @@ -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. diff --git a/canvas/texture.go b/canvas/texture.go index ba72304..6fb2a05 100644 --- a/canvas/texture.go +++ b/canvas/texture.go @@ -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 } diff --git a/tomo.go b/tomo.go index c99d6d3..cd1b617 100644 --- a/tomo.go +++ b/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) }