From 3cbc1870bf6d2fd9f98fb321c40808a6f369fb9c Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 17 Jan 2024 00:00:31 +0900 Subject: [PATCH] internal/buffered: update pixels instead of dotsBuffer when possible --- internal/buffered/image.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/buffered/image.go b/internal/buffered/image.go index beb8b0cd9..41ebf81e4 100644 --- a/internal/buffered/image.go +++ b/internal/buffered/image.go @@ -120,8 +120,20 @@ func (i *Image) WritePixels(pix []byte, region image.Rectangle) { } // Writing one pixel is a special case. - // Do not discard the cached pixels in this case, especially for (image/draw).Image. + // Do not write pixels in GPU especially for (image/draw).Image. if region.Dx() == 1 && region.Dy() == 1 { + // If i.pixels exists, update this instead of adding an entry to dotsBuffer. + if i.pixels != nil { + idx := 4 * (region.Min.Y*i.width + region.Min.X) + i.pixels[idx] = pix[0] + i.pixels[idx+1] = pix[1] + i.pixels[idx+2] = pix[2] + i.pixels[idx+3] = pix[3] + i.pixelsUnsynced = true + delete(i.dotsBuffer, region.Min) + return + } + if i.dotsBuffer == nil { i.dotsBuffer = map[image.Point][4]byte{} }