op/paint: NewImageOp does not need to make copies of RGBA images

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
aarzilli
2019-11-07 15:32:48 +01:00
committed by Elias Naur
parent 237a8dad8f
commit 454b226404
+11 -5
View File
@@ -19,7 +19,6 @@ type ImageOp struct {
uniform bool uniform bool
color color.RGBA color color.RGBA
src *image.RGBA src *image.RGBA
size image.Point
// handle is a key to uniquely identify this ImageOp // handle is a key to uniquely identify this ImageOp
// in a map of cached textures. // in a map of cached textures.
@@ -45,7 +44,16 @@ func NewImageOp(src image.Image) ImageOp {
uniform: true, uniform: true,
color: col, color: col,
} }
default: case *image.RGBA:
bounds := src.Bounds()
if bounds.Min == (image.Point{}) && src.Stride == bounds.Dx()*4 {
return ImageOp{
src: src,
handle: new(int),
}
}
}
sz := src.Bounds().Size() sz := src.Bounds().Size()
// Copy the image into a GPU friendly format. // Copy the image into a GPU friendly format.
dst := image.NewRGBA(image.Rectangle{ dst := image.NewRGBA(image.Rectangle{
@@ -54,14 +62,12 @@ func NewImageOp(src image.Image) ImageOp {
draw.Draw(dst, src.Bounds(), src, image.Point{}, draw.Src) draw.Draw(dst, src.Bounds(), src, image.Point{}, draw.Src)
return ImageOp{ return ImageOp{
src: dst, src: dst,
size: sz,
handle: new(int), handle: new(int),
} }
} }
}
func (i ImageOp) Size() image.Point { func (i ImageOp) Size() image.Point {
return i.size return i.src.Bounds().Size()
} }
func (i ImageOp) Add(o *op.Ops) { func (i ImageOp) Add(o *op.Ops) {