From 4c526867a49159f62c31bfc8dbe17f550ee35f46 Mon Sep 17 00:00:00 2001 From: faiface Date: Mon, 20 Mar 2017 19:54:59 +0100 Subject: [PATCH] heavily optimize Canvas.MakePicture with PictureData --- pixelgl/canvas.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pixelgl/canvas.go b/pixelgl/canvas.go index cb3b4fb..7be4950 100644 --- a/pixelgl/canvas.go +++ b/pixelgl/canvas.go @@ -102,7 +102,16 @@ func (c *Canvas) MakePicture(p pixel.Picture) pixel.TargetPicture { bx, by, bw, bh := intBounds(bounds) pixels := make([]uint8, 4*bw*bh) - if p, ok := p.(pixel.PictureColor); ok { + + if pd, ok := p.(*pixel.PictureData); ok { + // PictureData short path + for i, nrgba := range pd.Pix { + pixels[i*4+0] = nrgba.R + pixels[i*4+1] = nrgba.G + pixels[i*4+2] = nrgba.B + pixels[i*4+3] = nrgba.A + } + } else if p, ok := p.(pixel.PictureColor); ok { for y := 0; y < bh; y++ { for x := 0; x < bw; x++ { at := pixel.V(