31 lines
776 B
Go
31 lines
776 B
Go
package canvas
|
|
|
|
import "io"
|
|
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.
|
|
Clip (image.Rectangle) Texture
|
|
}
|
|
|
|
type protectedTexture struct {
|
|
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 }
|
|
}
|