From eb261f0bd16a0df62902bc5fefdc2e483d5c004d Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Thu, 16 Aug 2018 22:49:05 -0400 Subject: [PATCH] Perf improvement when nil clip and solid color (usual case) --- context.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/context.go b/context.go index ac23fbd..f436878 100644 --- a/context.go +++ b/context.go @@ -410,7 +410,19 @@ func (dc *Context) fill(painter raster.Painter) { // line cap, line join and dash settings. The path is preserved after this // operation. 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) } @@ -425,7 +437,19 @@ func (dc *Context) Stroke() { // FillPreserve fills the current path with the current color. Open subpaths // are implicity closed. The path is preserved after this operation. 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) }