mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 19:22:49 +01:00
shareable: Rename border -> padding
This commit is contained in:
parent
484473b6d9
commit
1735dda586
@ -29,9 +29,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// borderSize represents the size of border around an image.
|
// paddingSize represents the size of padding around an image.
|
||||||
// Every image or node except for a screen image has its border.
|
// Every image or node except for a screen image has its padding.
|
||||||
borderSize = 1
|
paddingSize = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
var graphicsDriver driver.Graphics
|
var graphicsDriver driver.Graphics
|
||||||
@ -203,7 +203,7 @@ func (i *Image) ensureNotShared() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ox, oy, w, h := i.regionWithBorder()
|
ox, oy, w, h := i.regionWithPadding()
|
||||||
dx0 := float32(0)
|
dx0 := float32(0)
|
||||||
dy0 := float32(0)
|
dy0 := float32(0)
|
||||||
dx1 := float32(w)
|
dx1 := float32(w)
|
||||||
@ -246,7 +246,7 @@ func (i *Image) makeShared() error {
|
|||||||
pixels := make([]byte, 4*i.width*i.height)
|
pixels := make([]byte, 4*i.width*i.height)
|
||||||
for y := 0; y < i.height; y++ {
|
for y := 0; y < i.height; y++ {
|
||||||
for x := 0; x < i.width; x++ {
|
for x := 0; x < i.width; x++ {
|
||||||
r, g, b, a, err := i.at(x+borderSize, y+borderSize)
|
r, g, b, a, err := i.at(x+paddingSize, y+paddingSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -262,12 +262,12 @@ func (i *Image) makeShared() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) regionWithBorder() (x, y, width, height int) {
|
func (i *Image) regionWithPadding() (x, y, width, height int) {
|
||||||
if i.backend == nil {
|
if i.backend == nil {
|
||||||
panic("shareable: backend must not be nil: not allocated yet?")
|
panic("shareable: backend must not be nil: not allocated yet?")
|
||||||
}
|
}
|
||||||
if !i.isShared() {
|
if !i.isShared() {
|
||||||
return 0, 0, i.width + 2*borderSize, i.height + 2*borderSize
|
return 0, 0, i.width + 2*paddingSize, i.height + 2*paddingSize
|
||||||
}
|
}
|
||||||
return i.node.Region()
|
return i.node.Region()
|
||||||
}
|
}
|
||||||
@ -328,16 +328,16 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var dx, dy float32
|
var dx, dy float32
|
||||||
// A screen image doesn't have its border.
|
// A screen image doesn't have its padding.
|
||||||
if !i.screen {
|
if !i.screen {
|
||||||
dx = borderSize
|
dx = paddingSize
|
||||||
dy = borderSize
|
dy = paddingSize
|
||||||
}
|
}
|
||||||
var oxf, oyf float32
|
var oxf, oyf float32
|
||||||
if len(srcs) > 0 {
|
if len(srcs) > 0 {
|
||||||
ox, oy, _, _ := srcs[0].regionWithBorder()
|
ox, oy, _, _ := srcs[0].regionWithPadding()
|
||||||
ox += borderSize
|
ox += paddingSize
|
||||||
oy += borderSize
|
oy += paddingSize
|
||||||
oxf, oyf = float32(ox), float32(oy)
|
oxf, oyf = float32(ox), float32(oy)
|
||||||
n := len(vertices) / graphics.VertexFloatNum
|
n := len(vertices) / graphics.VertexFloatNum
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
@ -436,21 +436,21 @@ func (i *Image) replacePixels(pix []byte) {
|
|||||||
i.allocate(true)
|
i.allocate(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
x, y, w, h := i.regionWithBorder()
|
x, y, w, h := i.regionWithPadding()
|
||||||
if pix == nil {
|
if pix == nil {
|
||||||
i.backend.restorable.ReplacePixels(nil, x, y, w, h)
|
i.backend.restorable.ReplacePixels(nil, x, y, w, h)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ow, oh := w-2*borderSize, h-2*borderSize
|
ow, oh := w-2*paddingSize, h-2*paddingSize
|
||||||
if l := 4 * ow * oh; len(pix) != l {
|
if l := 4 * ow * oh; len(pix) != l {
|
||||||
panic(fmt.Sprintf("shareable: len(p) must be %d but %d", l, len(pix)))
|
panic(fmt.Sprintf("shareable: len(p) must be %d but %d", l, len(pix)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a border around the image.
|
// Add a padding around the image.
|
||||||
pixb := make([]byte, 4*w*h)
|
pixb := make([]byte, 4*w*h)
|
||||||
for j := 0; j < oh; j++ {
|
for j := 0; j < oh; j++ {
|
||||||
copy(pixb[4*((j+borderSize)*w+borderSize):], pix[4*j*ow:4*(j+1)*ow])
|
copy(pixb[4*((j+paddingSize)*w+paddingSize):], pix[4*j*ow:4*(j+1)*ow])
|
||||||
}
|
}
|
||||||
|
|
||||||
i.backend.restorable.ReplacePixels(pixb, x, y, w, h)
|
i.backend.restorable.ReplacePixels(pixb, x, y, w, h)
|
||||||
@ -460,8 +460,8 @@ func (img *Image) Pixels(x, y, width, height int) ([]byte, error) {
|
|||||||
backendsM.Lock()
|
backendsM.Lock()
|
||||||
defer backendsM.Unlock()
|
defer backendsM.Unlock()
|
||||||
|
|
||||||
x += borderSize
|
x += paddingSize
|
||||||
y += borderSize
|
y += paddingSize
|
||||||
|
|
||||||
bs := make([]byte, 4*width*height)
|
bs := make([]byte, 4*width*height)
|
||||||
idx := 0
|
idx := 0
|
||||||
@ -486,7 +486,7 @@ func (i *Image) at(x, y int) (byte, byte, byte, byte, error) {
|
|||||||
return 0, 0, 0, 0, nil
|
return 0, 0, 0, 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ox, oy, w, h := i.regionWithBorder()
|
ox, oy, w, h := i.regionWithPadding()
|
||||||
if x < 0 || y < 0 || x >= w || y >= h {
|
if x < 0 || y < 0 || x >= w || y >= h {
|
||||||
return 0, 0, 0, 0, nil
|
return 0, 0, 0, 0, nil
|
||||||
}
|
}
|
||||||
@ -536,7 +536,7 @@ func (i *Image) dispose(markDisposed bool) {
|
|||||||
i.backend.page.Free(i.node)
|
i.backend.page.Free(i.node)
|
||||||
if !i.backend.page.IsEmpty() {
|
if !i.backend.page.IsEmpty() {
|
||||||
// As this part can be reused, this should be cleared explicitly.
|
// As this part can be reused, this should be cleared explicitly.
|
||||||
i.backend.restorable.ClearPixels(i.regionWithBorder())
|
i.backend.restorable.ClearPixels(i.regionWithPadding())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -584,7 +584,7 @@ func (i *Image) allocate(shareable bool) {
|
|||||||
runtime.SetFinalizer(i, (*Image).MarkDisposed)
|
runtime.SetFinalizer(i, (*Image).MarkDisposed)
|
||||||
|
|
||||||
if i.screen {
|
if i.screen {
|
||||||
// A screen image doesn't have a border.
|
// A screen image doesn't have a padding.
|
||||||
i.backend = &backend{
|
i.backend = &backend{
|
||||||
restorable: restorable.NewScreenFramebufferImage(i.width, i.height),
|
restorable: restorable.NewScreenFramebufferImage(i.width, i.height),
|
||||||
}
|
}
|
||||||
@ -593,13 +593,13 @@ func (i *Image) allocate(shareable bool) {
|
|||||||
|
|
||||||
if !shareable || !i.shareable() {
|
if !shareable || !i.shareable() {
|
||||||
i.backend = &backend{
|
i.backend = &backend{
|
||||||
restorable: restorable.NewImage(i.width+2*borderSize, i.height+2*borderSize, i.volatile),
|
restorable: restorable.NewImage(i.width+2*paddingSize, i.height+2*paddingSize, i.volatile),
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, b := range theBackends {
|
for _, b := range theBackends {
|
||||||
if n, ok := b.TryAlloc(i.width+2*borderSize, i.height+2*borderSize); ok {
|
if n, ok := b.TryAlloc(i.width+2*paddingSize, i.height+2*paddingSize); ok {
|
||||||
i.backend = b
|
i.backend = b
|
||||||
i.node = n
|
i.node = n
|
||||||
return
|
return
|
||||||
@ -619,7 +619,7 @@ func (i *Image) allocate(shareable bool) {
|
|||||||
}
|
}
|
||||||
theBackends = append(theBackends, b)
|
theBackends = append(theBackends, b)
|
||||||
|
|
||||||
n := b.page.Alloc(i.width+2*borderSize, i.height+2*borderSize)
|
n := b.page.Alloc(i.width+2*paddingSize, i.height+2*paddingSize)
|
||||||
if n == nil {
|
if n == nil {
|
||||||
panic("shareable: Alloc result must not be nil at allocate")
|
panic("shareable: Alloc result must not be nil at allocate")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user