mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
driver: Add Graphics.NeedsRestoring
This commit is contained in:
parent
1d51435bbb
commit
fcb5554aa1
@ -31,6 +31,7 @@ type Graphics interface {
|
||||
Draw(indexLen int, indexOffset int, mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter, address graphics.Address) error
|
||||
SetVsyncEnabled(enabled bool)
|
||||
VDirection() VDirection
|
||||
NeedsRestoring() bool
|
||||
IsGL() bool
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,10 @@ func SetGraphicsDriver(driver driver.Graphics) {
|
||||
theGraphicsDriver = driver
|
||||
}
|
||||
|
||||
func NeedsRestoring() bool {
|
||||
return theGraphicsDriver.NeedsRestoring()
|
||||
}
|
||||
|
||||
// command represents a drawing command.
|
||||
//
|
||||
// A command for drawing that is created when Image functions are called like DrawTriangles,
|
||||
|
@ -707,6 +707,10 @@ func (d *Driver) VDirection() driver.VDirection {
|
||||
return driver.VUpward
|
||||
}
|
||||
|
||||
func (d *Driver) NeedsRestoring() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (d *Driver) IsGL() bool {
|
||||
return false
|
||||
}
|
||||
|
@ -500,3 +500,7 @@ func (c *context) flush() {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (c *context) needsRestoring() bool {
|
||||
return false
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"syscall/js"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/web"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -459,3 +460,7 @@ func (c *context) flush() {
|
||||
gl := c.gl
|
||||
gl.Call("flush")
|
||||
}
|
||||
|
||||
func (c *context) needsRestoring() bool {
|
||||
return !web.IsMobileBrowser()
|
||||
}
|
||||
|
@ -378,3 +378,7 @@ func (c *context) flush() {
|
||||
gl := c.gl
|
||||
gl.Flush()
|
||||
}
|
||||
|
||||
func (c *context) needsRestoring() bool {
|
||||
return true
|
||||
}
|
||||
|
@ -126,6 +126,10 @@ func (d *Driver) VDirection() driver.VDirection {
|
||||
return driver.VDownward
|
||||
}
|
||||
|
||||
func (d *Driver) NeedsRestoring() bool {
|
||||
return d.context.needsRestoring()
|
||||
}
|
||||
|
||||
func (d *Driver) IsGL() bool {
|
||||
return true
|
||||
}
|
||||
|
@ -1,26 +0,0 @@
|
||||
// Copyright 2017 The Ebiten Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build darwin freebsd linux windows
|
||||
// +build !js
|
||||
// +build !android
|
||||
// +build !ios
|
||||
|
||||
package restorable
|
||||
|
||||
func init() {
|
||||
// OpenGL (not ES) never causes context lost,
|
||||
// so restorable feature is not needed.
|
||||
restoringEnabled = false
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// Copyright 2017 The Ebiten Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build js
|
||||
|
||||
package restorable
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/internal/web"
|
||||
)
|
||||
|
||||
func init() {
|
||||
if web.IsMobileBrowser() {
|
||||
restoringEnabled = false
|
||||
}
|
||||
}
|
@ -301,7 +301,7 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
||||
}
|
||||
i.image.ReplacePixels(pixels, x, y, width, height)
|
||||
|
||||
if !IsRestoringEnabled() {
|
||||
if !NeedsRestoring() {
|
||||
i.makeStale()
|
||||
return
|
||||
}
|
||||
@ -362,7 +362,7 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16,
|
||||
}
|
||||
theImages.makeStaleIfDependingOn(i)
|
||||
|
||||
if img.stale || img.volatile || i.screen || !IsRestoringEnabled() || i.volatile {
|
||||
if img.stale || img.volatile || i.screen || !NeedsRestoring() || i.volatile {
|
||||
i.makeStale()
|
||||
} else {
|
||||
i.appendDrawTrianglesHistory(img, vertices, indices, colorm, mode, filter, address)
|
||||
@ -447,7 +447,7 @@ func (i *Image) readPixelsFromGPU() {
|
||||
|
||||
// resolveStale resolves the image's 'stale' state.
|
||||
func (i *Image) resolveStale() {
|
||||
if !IsRestoringEnabled() {
|
||||
if !NeedsRestoring() {
|
||||
return
|
||||
}
|
||||
|
||||
@ -557,7 +557,7 @@ func (i *Image) Dispose() {
|
||||
func (i *Image) IsInvalidated() (bool, error) {
|
||||
// FlushCommands is required because c.offscreen.impl might not have an actual texture.
|
||||
graphicscommand.FlushCommands()
|
||||
if !IsRestoringEnabled() {
|
||||
if !NeedsRestoring() {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
@ -20,22 +20,20 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/internal/graphicscommand"
|
||||
)
|
||||
|
||||
// restoringEnabled indicates if restoring happens or not.
|
||||
//
|
||||
// This value is overridden at enabled_*.go.
|
||||
var restoringEnabled = true
|
||||
// forceRestoring reports whether restoring forcely happens or not.
|
||||
var forceRestoring = true
|
||||
|
||||
// IsRestoringEnabled returns a boolean value indicating whether
|
||||
// restoring process works or not.
|
||||
func IsRestoringEnabled() bool {
|
||||
// This value is updated only at init or EnableRestoringForTesting.
|
||||
// No need to lock here.
|
||||
return restoringEnabled
|
||||
// NeedsRestoring reports whether restoring process works or not.
|
||||
func NeedsRestoring() bool {
|
||||
if forceRestoring {
|
||||
return true
|
||||
}
|
||||
return graphicscommand.NeedsRestoring()
|
||||
}
|
||||
|
||||
// EnableRestoringForTesting forces to enable restoring for testing.
|
||||
func EnableRestoringForTesting() {
|
||||
restoringEnabled = true
|
||||
forceRestoring = true
|
||||
}
|
||||
|
||||
// images is a set of Image objects.
|
||||
@ -55,7 +53,7 @@ var theImages = &images{
|
||||
// ResolveStaleImages is intended to be called at the end of a frame.
|
||||
func ResolveStaleImages() {
|
||||
graphicscommand.FlushCommands()
|
||||
if !restoringEnabled {
|
||||
if !NeedsRestoring() {
|
||||
return
|
||||
}
|
||||
theImages.resolveStaleImages()
|
||||
@ -146,7 +144,7 @@ func (i *images) makeStaleIfDependingOnImpl(target *Image) {
|
||||
//
|
||||
// Restoring means to make all *graphicscommand.Image objects have their textures and framebuffers.
|
||||
func (i *images) restore() error {
|
||||
if !IsRestoringEnabled() {
|
||||
if !NeedsRestoring() {
|
||||
panic("restorable: restore cannot be called when restoring is disabled")
|
||||
}
|
||||
|
||||
|
@ -508,9 +508,9 @@ func ResolveStaleImages() {
|
||||
restorable.ResolveStaleImages()
|
||||
}
|
||||
|
||||
func IsRestoringEnabled() bool {
|
||||
// As IsRestoringEnabled is an immutable state, no need to lock here.
|
||||
return restorable.IsRestoringEnabled()
|
||||
func NeedsRestoring() bool {
|
||||
// As NeedsRestoring is an immutable state, no need to lock here.
|
||||
return restorable.NeedsRestoring()
|
||||
}
|
||||
|
||||
func Restore() error {
|
||||
|
@ -151,7 +151,7 @@ func (c *uiContext) needsRestoring() (bool, error) {
|
||||
}
|
||||
|
||||
func (c *uiContext) restoreIfNeeded() error {
|
||||
if !shareable.IsRestoringEnabled() {
|
||||
if !shareable.NeedsRestoring() {
|
||||
return nil
|
||||
}
|
||||
r, err := c.needsRestoring()
|
||||
|
Loading…
Reference in New Issue
Block a user