Perf improvement when nil clip and solid color (usual case)

This commit is contained in:
Michael Fogleman 2018-08-16 22:49:05 -04:00
parent a4f287e211
commit eb261f0bd1

View File

@ -410,7 +410,19 @@ func (dc *Context) fill(painter raster.Painter) {
// line cap, line join and dash settings. The path is preserved after this // line cap, line join and dash settings. The path is preserved after this
// operation. // operation.
func (dc *Context) StrokePreserve() { func (dc *Context) StrokePreserve() {
painter := newPatternPainter(dc.im, dc.mask, dc.strokePattern) var painter raster.Painter
if dc.mask == nil {
if pattern, ok := dc.strokePattern.(*solidPattern); ok {
// with a nil mask and a solid color pattern, we can be more efficient
// TODO: refactor so we don't have to do this type assertion stuff?
p := raster.NewRGBAPainter(dc.im)
p.SetColor(pattern.color)
painter = p
}
}
if painter == nil {
painter = newPatternPainter(dc.im, dc.mask, dc.strokePattern)
}
dc.stroke(painter) dc.stroke(painter)
} }
@ -425,7 +437,19 @@ func (dc *Context) Stroke() {
// FillPreserve fills the current path with the current color. Open subpaths // FillPreserve fills the current path with the current color. Open subpaths
// are implicity closed. The path is preserved after this operation. // are implicity closed. The path is preserved after this operation.
func (dc *Context) FillPreserve() { func (dc *Context) FillPreserve() {
painter := newPatternPainter(dc.im, dc.mask, dc.fillPattern) var painter raster.Painter
if dc.mask == nil {
if pattern, ok := dc.fillPattern.(*solidPattern); ok {
// with a nil mask and a solid color pattern, we can be more efficient
// TODO: refactor so we don't have to do this type assertion stuff?
p := raster.NewRGBAPainter(dc.im)
p.SetColor(pattern.color)
painter = p
}
}
if painter == nil {
painter = newPatternPainter(dc.im, dc.mask, dc.fillPattern)
}
dc.fill(painter) dc.fill(painter)
} }