draw: disable the image.Rectangle DstMask fast path until Go 1.5 is

released.

Change-Id: Ie5d6766d53952d3a81dfbd19a9f4022aaad6af5a
Reviewed-on: https://go-review.googlesource.com/9463
Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
Nigel Tao 2015-04-29 10:46:24 +10:00
parent b2f48f3f51
commit 918b3735c3
2 changed files with 21 additions and 4 deletions

View File

@ -410,9 +410,11 @@ func clipAffectedDestRect(adr image.Rectangle, dstMask image.Image, dstMaskP ima
if dstMask == nil {
return adr, nil
}
if r, ok := dstMask.(image.Rectangle); ok {
return adr.Intersect(r.Sub(dstMaskP)), nil
}
// TODO: enable this fast path once Go 1.5 is released, where an
// image.Rectangle implements image.Image.
// if r, ok := dstMask.(image.Rectangle); ok {
// return adr.Intersect(r.Sub(dstMaskP)), nil
// }
// TODO: clip to dstMask.Bounds() if the color model implies that out-of-bounds means 0 alpha?
return adr, dstMask
}

View File

@ -433,7 +433,9 @@ func TestRectDstMask(t *testing.T) {
for _, dstMaskP := range dstMaskPs {
dstInside := mk(q, nil, image.Point{})
for _, wrap := range []bool{false, true} {
dstMask := image.Image(rect)
// TODO: replace "rectImage(rect)" with "rect" once Go 1.5 is
// released, where an image.Rectangle implements image.Image.
dstMask := image.Image(rectImage(rect))
if wrap {
dstMask = srcWrapper{dstMask}
}
@ -463,6 +465,19 @@ func TestRectDstMask(t *testing.T) {
}
}
// TODO: delete this wrapper type once Go 1.5 is released, where an
// image.Rectangle implements image.Image.
type rectImage image.Rectangle
func (r rectImage) ColorModel() color.Model { return color.Alpha16Model }
func (r rectImage) Bounds() image.Rectangle { return image.Rectangle(r) }
func (r rectImage) At(x, y int) color.Color {
if (image.Point{x, y}).In(image.Rectangle(r)) {
return color.Opaque
}
return color.Transparent
}
// The fooWrapper types wrap the dst or src image to avoid triggering the
// type-specific fast path implementations.
type (