pixels: Rename fuctions

This commit is contained in:
Hajime Hoshi 2016-07-26 10:51:48 +09:00
parent 558f559323
commit 0fc61ed568
4 changed files with 17 additions and 17 deletions

View File

@ -140,7 +140,7 @@ func (c *graphicsContext) UpdateAndDraw(context *opengl.Context, updateCount int
if err := c.initializeIfNeeded(context); err != nil { if err := c.initializeIfNeeded(context); err != nil {
return err return err
} }
if err := theImagesForRestoring.resetPixels(context); err != nil { if err := theImagesForRestoring.ensurePixels(context); err != nil {
return err return err
} }
for i := 0; i < updateCount; i++ { for i := 0; i < updateCount; i++ {

View File

@ -63,11 +63,11 @@ func (i *images) remove(img *Image) {
runtime.SetFinalizer(img, nil) runtime.SetFinalizer(img, nil)
} }
func (i *images) resetPixels(context *opengl.Context) error { func (i *images) ensurePixels(context *opengl.Context) error {
i.m.Lock() i.m.Lock()
defer i.m.Unlock() defer i.m.Unlock()
for img := range i.images { for img := range i.images {
if err := img.resetPixels(context); err != nil { if err := img.ensurePixels(context); err != nil {
return err return err
} }
} }

View File

@ -53,7 +53,7 @@ func newImageImpl(width, height int, filter Filter, volatile bool) (*imageImpl,
volatile: volatile, volatile: volatile,
pixels: pixels.NewPixels(img), pixels: pixels.NewPixels(img),
} }
i.pixels.ResetWithPixels(make([]uint8, width*height*4)) i.pixels.ReplacePixels(make([]uint8, width*height*4))
runtime.SetFinalizer(i, (*imageImpl).Dispose) runtime.SetFinalizer(i, (*imageImpl).Dispose)
return i, nil return i, nil
} }
@ -86,7 +86,7 @@ func newImageImplFromImage(source image.Image, filter Filter) (*imageImpl, error
filter: filter, filter: filter,
pixels: pixels.NewPixels(img), pixels: pixels.NewPixels(img),
} }
i.pixels.ResetWithPixels(p) i.pixels.ReplacePixels(p)
runtime.SetFinalizer(i, (*imageImpl).Dispose) runtime.SetFinalizer(i, (*imageImpl).Dispose)
return i, nil return i, nil
} }
@ -104,7 +104,7 @@ func newScreenImageImpl(width, height int) (*imageImpl, error) {
screen: true, screen: true,
pixels: pixels.NewPixels(img), pixels: pixels.NewPixels(img),
} }
i.pixels.ResetWithPixels(make([]uint8, width*height*4)) i.pixels.ReplacePixels(make([]uint8, width*height*4))
runtime.SetFinalizer(i, (*imageImpl).Dispose) runtime.SetFinalizer(i, (*imageImpl).Dispose)
return i, nil return i, nil
} }
@ -198,7 +198,7 @@ func (i *imageImpl) At(x, y int, context *opengl.Context) color.Color {
return clr return clr
} }
func (i *imageImpl) resetPixels(context *opengl.Context) error { func (i *imageImpl) ensurePixels(context *opengl.Context) error {
i.m.Lock() i.m.Lock()
defer i.m.Unlock() defer i.m.Unlock()
if i.disposed { if i.disposed {
@ -305,7 +305,7 @@ func (i *imageImpl) ReplacePixels(p []uint8) error {
if i.pixels == nil { if i.pixels == nil {
i.pixels = pixels.NewPixels(i.image) i.pixels = pixels.NewPixels(i.image)
} }
i.pixels.ResetWithPixels(p) i.pixels.ReplacePixels(p)
if i.disposed { if i.disposed {
return errors.New("ebiten: image is already disposed") return errors.New("ebiten: image is already disposed")
} }

View File

@ -46,15 +46,6 @@ func NewPixels(image *graphics.Image) *Pixels {
} }
} }
func (p *Pixels) ResetWithPixels(pixels []uint8) {
if p.basePixels == nil {
p.basePixels = make([]uint8, len(pixels))
}
copy(p.basePixels, pixels)
p.baseColor = nil
p.drawImageHistory = nil
}
func (p *Pixels) Clear() { func (p *Pixels) Clear() {
p.basePixels = nil p.basePixels = nil
p.baseColor = nil p.baseColor = nil
@ -67,6 +58,15 @@ func (p *Pixels) Fill(clr color.Color) {
p.drawImageHistory = nil p.drawImageHistory = nil
} }
func (p *Pixels) ReplacePixels(pixels []uint8) {
if p.basePixels == nil {
p.basePixels = make([]uint8, len(pixels))
}
copy(p.basePixels, pixels)
p.baseColor = nil
p.drawImageHistory = nil
}
func (p *Pixels) AppendDrawImageHistory(image *graphics.Image, vertices []int16, geom graphics.Matrix, colorm graphics.Matrix, mode opengl.CompositeMode) { func (p *Pixels) AppendDrawImageHistory(image *graphics.Image, vertices []int16, geom graphics.Matrix, colorm graphics.Matrix, mode opengl.CompositeMode) {
item := &drawImageHistoryItem{ item := &drawImageHistoryItem{
image: image, image: image,