mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
pixels: Remove 'inconsistent' property
This commit is contained in:
parent
931e60902f
commit
95dae4ad45
@ -95,6 +95,9 @@ func (c *graphicsContext) initializeIfNeeded(context *opengl.Context) error {
|
||||
if err := graphics.Reset(context); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := theImagesForRestoring.flushPixels(context); err != nil {
|
||||
return err
|
||||
}
|
||||
atomic.StoreInt32(&c.initialized, 1)
|
||||
}
|
||||
r, err := c.needsRestoring(context)
|
||||
@ -141,9 +144,6 @@ func (c *graphicsContext) UpdateAndDraw(context *opengl.Context, updateCount int
|
||||
if err := c.initializeIfNeeded(context); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := theImagesForRestoring.flushPixelsIfInconsistent(context); err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < updateCount; i++ {
|
||||
if err := theImagesForRestoring.clearVolatileImages(); err != nil {
|
||||
return err
|
||||
|
4
image.go
4
image.go
@ -63,11 +63,11 @@ func (i *images) remove(img *Image) {
|
||||
runtime.SetFinalizer(img, nil)
|
||||
}
|
||||
|
||||
func (i *images) flushPixelsIfInconsistent(context *opengl.Context) error {
|
||||
func (i *images) flushPixels(context *opengl.Context) error {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
for img := range i.images {
|
||||
if err := img.flushPixelsIfInconsistent(context); err != nil {
|
||||
if err := img.flushPixels(context); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -171,9 +171,6 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
||||
}
|
||||
geom := options.GeoM
|
||||
colorm := options.ColorM
|
||||
if image.impl.pixels.IsInconsistent() {
|
||||
i.pixels.MakeInconsistent()
|
||||
}
|
||||
i.pixels.AppendDrawImageHistory(image.impl.image, vertices, &geom, &colorm, opengl.CompositeMode(options.CompositeMode))
|
||||
mode := opengl.CompositeMode(options.CompositeMode)
|
||||
if err := i.image.DrawImage(image.impl.image, vertices, &geom, &colorm, mode); err != nil {
|
||||
@ -199,13 +196,13 @@ func (i *imageImpl) At(x, y int, context *opengl.Context) color.Color {
|
||||
return clr
|
||||
}
|
||||
|
||||
func (i *imageImpl) flushPixelsIfInconsistent(context *opengl.Context) error {
|
||||
func (i *imageImpl) flushPixels(context *opengl.Context) error {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
if i.disposed {
|
||||
return nil
|
||||
}
|
||||
if err := i.pixels.FlushIfInconsistent(context); err != nil {
|
||||
if err := i.pixels.Flush(context); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -225,7 +222,7 @@ func (i *imageImpl) flushPixelsIfNeeded(target *imageImpl, context *opengl.Conte
|
||||
}
|
||||
if context == nil {
|
||||
// context is null when this is not initialized yet.
|
||||
i.pixels.MakeInconsistent()
|
||||
// In this case, pixels is inconsistent with the image.
|
||||
return nil
|
||||
}
|
||||
if err := i.pixels.FlushIfNeeded(target.image, context); err != nil {
|
||||
|
@ -34,7 +34,6 @@ type drawImageHistoryItem struct {
|
||||
|
||||
type Pixels struct {
|
||||
image *graphics.Image
|
||||
inconsistent bool
|
||||
basePixels []uint8
|
||||
baseColor color.Color
|
||||
drawImageHistory []*drawImageHistoryItem
|
||||
@ -51,47 +50,27 @@ func (p *Pixels) ResetWithPixels(pixels []uint8) {
|
||||
p.basePixels = make([]uint8, len(pixels))
|
||||
}
|
||||
copy(p.basePixels, pixels)
|
||||
p.inconsistent = false
|
||||
p.baseColor = nil
|
||||
p.drawImageHistory = nil
|
||||
}
|
||||
|
||||
func (p *Pixels) Clear() {
|
||||
p.inconsistent = false
|
||||
p.basePixels = nil
|
||||
p.baseColor = nil
|
||||
p.drawImageHistory = nil
|
||||
}
|
||||
|
||||
func (p *Pixels) IsCleared() bool {
|
||||
if p.inconsistent {
|
||||
return false
|
||||
}
|
||||
return p.basePixels == nil && p.baseColor == nil && p.drawImageHistory == nil
|
||||
}
|
||||
|
||||
func (p *Pixels) Fill(clr color.Color) {
|
||||
p.inconsistent = false
|
||||
p.basePixels = nil
|
||||
p.baseColor = clr
|
||||
p.drawImageHistory = nil
|
||||
}
|
||||
|
||||
func (p *Pixels) IsInconsistent() bool {
|
||||
return p.inconsistent
|
||||
}
|
||||
|
||||
func (p *Pixels) MakeInconsistent() {
|
||||
p.inconsistent = true
|
||||
p.basePixels = nil
|
||||
p.baseColor = nil
|
||||
p.drawImageHistory = nil
|
||||
}
|
||||
|
||||
func (p *Pixels) AppendDrawImageHistory(image *graphics.Image, vertices []int16, geom graphics.Matrix, colorm graphics.Matrix, mode opengl.CompositeMode) {
|
||||
if p.inconsistent {
|
||||
return
|
||||
}
|
||||
item := &drawImageHistoryItem{
|
||||
image: image,
|
||||
vertices: vertices,
|
||||
@ -103,8 +82,7 @@ func (p *Pixels) AppendDrawImageHistory(image *graphics.Image, vertices []int16,
|
||||
}
|
||||
|
||||
func (p *Pixels) At(idx int, context *opengl.Context) (color.Color, error) {
|
||||
if p.inconsistent || p.basePixels == nil || p.drawImageHistory != nil {
|
||||
p.inconsistent = false
|
||||
if p.basePixels == nil || p.drawImageHistory != nil {
|
||||
var err error
|
||||
p.basePixels, err = p.image.Pixels(context)
|
||||
if err != nil {
|
||||
@ -126,11 +104,7 @@ func (p *Pixels) hasHistoryWith(target *graphics.Image) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *Pixels) FlushIfInconsistent(context *opengl.Context) error {
|
||||
if !p.inconsistent {
|
||||
return nil
|
||||
}
|
||||
p.inconsistent = false
|
||||
func (p *Pixels) Flush(context *opengl.Context) error {
|
||||
var err error
|
||||
p.basePixels, err = p.image.Pixels(context)
|
||||
if err != nil {
|
||||
@ -148,7 +122,6 @@ func (p *Pixels) FlushIfNeeded(target *graphics.Image, context *opengl.Context)
|
||||
if !p.hasHistoryWith(target) {
|
||||
return nil
|
||||
}
|
||||
p.inconsistent = false
|
||||
var err error
|
||||
p.basePixels, err = p.image.Pixels(context)
|
||||
if err != nil {
|
||||
@ -194,7 +167,6 @@ func (p *Pixels) Restore(context *opengl.Context, width, height int, filter open
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
p.inconsistent = false
|
||||
p.basePixels, err = gimg.Pixels(context)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user