From cc574ad67ee900395662b9632b99c1223fdde6fb Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 20 Mar 2022 04:20:23 +0900 Subject: [PATCH] internal/atlas: rename functions: Area -> Region --- image.go | 6 +++--- internal/buffered/image.go | 14 ++++++++++---- internal/mipmap/mipmap.go | 8 ++++---- internal/ui/image.go | 8 ++++---- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/image.go b/image.go index 93a1ec85d..e45855b28 100644 --- a/image.go +++ b/image.go @@ -764,7 +764,7 @@ func (i *Image) Set(x, y int, clr color.Color) { r, g, b, a := clr.RGBA() pix := []byte{byte(r >> 8), byte(g >> 8), byte(b >> 8), byte(a >> 8)} - if err := i.image.ReplaceSmallAreaPixels(pix, x, y, 1, 1); err != nil { + if err := i.image.ReplaceSmallRegionPixels(pix, x, y, 1, 1); err != nil { ui.SetError(err) } } @@ -815,8 +815,8 @@ func (i *Image) ReplacePixels(pixels []byte) { // Do not need to copy pixels here. // * In internal/mipmap, pixels are copied when necessary. - // * In internal/shareable, pixels are copied to make its paddings. - if err := i.image.ReplaceLargeAreaPixels(pixels, r.Min.X, r.Min.Y, r.Dx(), r.Dy()); err != nil { + // * In internal/atlas, pixels are copied to make its paddings. + if err := i.image.ReplaceLargeRegionPixels(pixels, r.Min.X, r.Min.Y, r.Dx(), r.Dy()); err != nil { ui.SetError(err) } } diff --git a/internal/buffered/image.go b/internal/buffered/image.go index dcea25c18..14159d3cb 100644 --- a/internal/buffered/image.go +++ b/internal/buffered/image.go @@ -166,7 +166,10 @@ func (i *Image) DumpScreenshot(graphicsDriver graphicsdriver.Graphics, name stri return i.img.DumpScreenshot(graphicsDriver, name, blackbg) } -func (i *Image) ReplaceLargeAreaPixels(pix []byte, x, y, width, height int) error { +// ReplaceLargeRegionPixels replaces the pixels with the specified region. +// ReplaceLargeRegionPixels is used for a relatively large region. +// This call is not accumulated and send one draw call to replace pixels. +func (i *Image) ReplaceLargeRegionPixels(pix []byte, x, y, width, height int) error { if l := 4 * width * height; len(pix) != l { panic(fmt.Sprintf("buffered: len(pix) was %d but must be %d", len(pix), l)) } @@ -175,7 +178,7 @@ func (i *Image) ReplaceLargeAreaPixels(pix []byte, x, y, width, height int) erro copied := make([]byte, len(pix)) copy(copied, pix) if tryAddDelayedCommand(func() error { - i.ReplaceLargeAreaPixels(copied, x, y, width, height) + i.ReplaceLargeRegionPixels(copied, x, y, width, height) return nil }) { return nil @@ -188,7 +191,10 @@ func (i *Image) ReplaceLargeAreaPixels(pix []byte, x, y, width, height int) erro return nil } -func (i *Image) ReplaceSmallAreaPixels(graphicsDriver graphicsdriver.Graphics, pix []byte, x, y, width, height int) error { +// ReplaceSmallRegionPixels replaces the pixels with the specified region. +// ReplaceSmallRegionPixels is used for a relatively small region. +// This call might be accumulated and send one draw call to replace pixels for the accumulated calls. +func (i *Image) ReplaceSmallRegionPixels(graphicsDriver graphicsdriver.Graphics, pix []byte, x, y, width, height int) error { if l := 4 * width * height; len(pix) != l { panic(fmt.Sprintf("buffered: len(pix) was %d but must be %d", len(pix), l)) } @@ -197,7 +203,7 @@ func (i *Image) ReplaceSmallAreaPixels(graphicsDriver graphicsdriver.Graphics, p copied := make([]byte, len(pix)) copy(copied, pix) if tryAddDelayedCommand(func() error { - i.ReplaceSmallAreaPixels(graphicsDriver, copied, x, y, width, height) + i.ReplaceSmallRegionPixels(graphicsDriver, copied, x, y, width, height) return nil }) { return nil diff --git a/internal/mipmap/mipmap.go b/internal/mipmap/mipmap.go index 899bab926..966a86bcf 100644 --- a/internal/mipmap/mipmap.go +++ b/internal/mipmap/mipmap.go @@ -71,16 +71,16 @@ func (m *Mipmap) DumpScreenshot(graphicsDriver graphicsdriver.Graphics, name str return m.orig.DumpScreenshot(graphicsDriver, name, blackbg) } -func (m *Mipmap) ReplaceLargeAreaPixels(pix []byte, x, y, width, height int) error { - if err := m.orig.ReplaceLargeAreaPixels(pix, x, y, width, height); err != nil { +func (m *Mipmap) ReplaceLargeRegionPixels(pix []byte, x, y, width, height int) error { + if err := m.orig.ReplaceLargeRegionPixels(pix, x, y, width, height); err != nil { return err } m.disposeMipmaps() return nil } -func (m *Mipmap) ReplaceSmallAreaPixels(graphicsDriver graphicsdriver.Graphics, pix []byte, x, y, width, height int) error { - if err := m.orig.ReplaceSmallAreaPixels(graphicsDriver, pix, x, y, width, height); err != nil { +func (m *Mipmap) ReplaceSmallRegionPixels(graphicsDriver graphicsdriver.Graphics, pix []byte, x, y, width, height int) error { + if err := m.orig.ReplaceSmallRegionPixels(graphicsDriver, pix, x, y, width, height); err != nil { return err } m.disposeMipmaps() diff --git a/internal/ui/image.go b/internal/ui/image.go index 40f059603..4686dbb37 100644 --- a/internal/ui/image.go +++ b/internal/ui/image.go @@ -60,12 +60,12 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []f i.mipmap.DrawTriangles(srcMipmaps, vertices, indices, colorm, mode, filter, address, dstRegion, srcRegion, subimageOffsets, s, uniforms, evenOdd, canSkipMipmap) } -func (i *Image) ReplaceLargeAreaPixels(pix []byte, x, y, width, height int) error { - return i.mipmap.ReplaceLargeAreaPixels(pix, x, y, width, height) +func (i *Image) ReplaceLargeRegionPixels(pix []byte, x, y, width, height int) error { + return i.mipmap.ReplaceLargeRegionPixels(pix, x, y, width, height) } -func (i *Image) ReplaceSmallAreaPixels(pix []byte, x, y, width, height int) error { - return i.mipmap.ReplaceSmallAreaPixels(graphicsDriver(), pix, x, y, width, height) +func (i *Image) ReplaceSmallRegionPixels(pix []byte, x, y, width, height int) error { + return i.mipmap.ReplaceSmallRegionPixels(graphicsDriver(), pix, x, y, width, height) } func (i *Image) Pixels(x, y, width, height int) ([]byte, error) {