mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +01:00
Simplify internal API not to return errors
This commit is contained in:
parent
33ff25cc40
commit
1c7ce07edf
34
image.go
34
image.go
@ -76,19 +76,19 @@ func (i *images) resolveStalePixels(context *opengl.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *images) resetPixelsIfDependingOn(target *Image, context *opengl.Context) error {
|
func (i *images) resetPixelsIfDependingOn(target *Image, context *opengl.Context) {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
if i.lastChecked == target.impl {
|
if i.lastChecked == target.impl {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
i.lastChecked = target.impl
|
i.lastChecked = target.impl
|
||||||
for img := range i.images {
|
if target.impl.isDisposed() {
|
||||||
if err := img.resetPixelsIfDependingOn(target.impl, context); err != nil {
|
return
|
||||||
return err
|
}
|
||||||
}
|
for img := range i.images {
|
||||||
|
img.resetPixelsIfDependingOn(target.impl, context)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *images) restore(context *opengl.Context) error {
|
func (i *images) restore(context *opengl.Context) error {
|
||||||
@ -146,9 +146,7 @@ func (i *Image) Size() (width, height int) {
|
|||||||
//
|
//
|
||||||
// This function is concurrent-safe.
|
// This function is concurrent-safe.
|
||||||
func (i *Image) Clear() error {
|
func (i *Image) Clear() error {
|
||||||
if err := theImagesForRestoring.resetPixelsIfDependingOn(i, glContext()); err != nil {
|
theImagesForRestoring.resetPixelsIfDependingOn(i, glContext())
|
||||||
return err
|
|
||||||
}
|
|
||||||
return i.impl.Fill(color.Transparent)
|
return i.impl.Fill(color.Transparent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,9 +154,7 @@ func (i *Image) Clear() error {
|
|||||||
//
|
//
|
||||||
// This function is concurrent-safe.
|
// This function is concurrent-safe.
|
||||||
func (i *Image) Fill(clr color.Color) error {
|
func (i *Image) Fill(clr color.Color) error {
|
||||||
if err := theImagesForRestoring.resetPixelsIfDependingOn(i, glContext()); err != nil {
|
theImagesForRestoring.resetPixelsIfDependingOn(i, glContext())
|
||||||
return err
|
|
||||||
}
|
|
||||||
return i.impl.Fill(clr)
|
return i.impl.Fill(clr)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,9 +177,7 @@ func (i *Image) Fill(clr color.Color) error {
|
|||||||
//
|
//
|
||||||
// This function is concurrent-safe.
|
// This function is concurrent-safe.
|
||||||
func (i *Image) DrawImage(image *Image, options *DrawImageOptions) error {
|
func (i *Image) DrawImage(image *Image, options *DrawImageOptions) error {
|
||||||
if err := theImagesForRestoring.resetPixelsIfDependingOn(i, glContext()); err != nil {
|
theImagesForRestoring.resetPixelsIfDependingOn(i, glContext())
|
||||||
return err
|
|
||||||
}
|
|
||||||
return i.impl.DrawImage(image, options)
|
return i.impl.DrawImage(image, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,9 +217,7 @@ func (i *Image) Dispose() error {
|
|||||||
if i.impl.isDisposed() {
|
if i.impl.isDisposed() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := theImagesForRestoring.resetPixelsIfDependingOn(i, glContext()); err != nil {
|
theImagesForRestoring.resetPixelsIfDependingOn(i, glContext())
|
||||||
return err
|
|
||||||
}
|
|
||||||
return i.impl.Dispose()
|
return i.impl.Dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,9 +229,7 @@ func (i *Image) Dispose() error {
|
|||||||
//
|
//
|
||||||
// This function is concurrent-safe.
|
// This function is concurrent-safe.
|
||||||
func (i *Image) ReplacePixels(p []uint8) error {
|
func (i *Image) ReplacePixels(p []uint8) error {
|
||||||
if err := theImagesForRestoring.resetPixelsIfDependingOn(i, glContext()); err != nil {
|
theImagesForRestoring.resetPixelsIfDependingOn(i, glContext())
|
||||||
return err
|
|
||||||
}
|
|
||||||
return i.impl.ReplacePixels(p)
|
return i.impl.ReplacePixels(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,22 +173,21 @@ func (i *imageImpl) resolveStalePixels(context *opengl.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *imageImpl) resetPixelsIfDependingOn(target *imageImpl, context *opengl.Context) error {
|
func (i *imageImpl) resetPixelsIfDependingOn(target *imageImpl, context *opengl.Context) {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
if i == target {
|
if i == target {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
if i.restorable == nil {
|
if i.restorable == nil {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
if target.isDisposed() {
|
if target.isDisposed() {
|
||||||
return errors.New("ebiten: target is already disposed")
|
panic("ebiten: target must not be disposed")
|
||||||
}
|
}
|
||||||
// target is an image that is about to be tried mutating.
|
// target is an image that is about to be tried mutating.
|
||||||
// If pixels object is related to that image, the pixels must be reset.
|
// If pixels object is related to that image, the pixels must be reset.
|
||||||
i.restorable.MakeStaleIfDependingOn(target.restorable)
|
i.restorable.MakeStaleIfDependingOn(target.restorable)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *imageImpl) hasDependency() bool {
|
func (i *imageImpl) hasDependency() bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user