restorable: Refactoring: Remove Clear

Fill now fills the whole texture.
This commit is contained in:
Hajime Hoshi 2019-12-02 02:26:03 +09:00
parent b35ffa57b3
commit 42056c2d61
5 changed files with 10 additions and 76 deletions

View File

@ -187,20 +187,6 @@ func (i *Image) Fill(clr color.RGBA) {
i.img.Fill(clr)
}
func (i *Image) ClearFramebuffer() {
delayedCommandsM.Lock()
if needsToDelayCommands {
delayedCommands = append(delayedCommands, func() {
i.img.ClearFramebuffer()
})
delayedCommandsM.Unlock()
return
}
delayedCommandsM.Unlock()
i.img.ClearFramebuffer()
}
func (i *Image) ReplacePixels(pix []byte) {
delayedCommandsM.Lock()
if needsToDelayCommands {

View File

@ -144,7 +144,7 @@ func NewImage(width, height int, volatile bool) *Image {
height: height,
volatile: volatile,
}
i.clear()
fillImage(i.image, color.RGBA{})
theImages.add(i)
return i
}
@ -196,16 +196,11 @@ func NewScreenFramebufferImage(width, height int) *Image {
height: height,
screen: true,
}
i.clear()
fillImage(i.image, color.RGBA{})
theImages.add(i)
return i
}
func (i *Image) Clear() {
theImages.makeStaleIfDependingOn(i)
i.clear()
}
// quadVertices returns vertices to render a quad. These values are passed to graphicscommand.Image.
func quadVertices(dx0, dy0, dx1, dy1, sx0, sy0, sx1, sy1, cr, cg, cb, ca float32) []float32 {
return []float32{
@ -216,39 +211,6 @@ func quadVertices(dx0, dy0, dx1, dy1, sx0, sy0, sx1, sy1, cr, cg, cb, ca float32
}
}
// clearImage clears a graphicscommand.Image.
// This does nothing to do with a restorable.Image's rendering state.
func clearImage(img *graphicscommand.Image) {
if img == emptyImage.image {
panic("restorable: clearImage cannot be called on emptyImage")
}
// There are not 'drawTrianglesHistoryItem's for this image and emptyImage.
// As emptyImage is a priority image, this is restored before other regular images are restored.
// The rendering target size needs to be its 'internal' size instead of the exposed size to avoid glitches on
// mobile platforms (See the change 1e1f309a).
dw, dh := img.InternalSize()
sw, sh := emptyImage.image.InternalSize()
vs := quadVertices(0, 0, float32(dw), float32(dh), 0, 0, float32(sw), float32(sh), 0, 0, 0, 0)
is := graphics.QuadIndices()
// The first DrawTriangles must be clear mode for initialization.
// TODO: Can the graphicscommand package hide this knowledge?
img.DrawTriangles(emptyImage.image, vs, is, nil, driver.CompositeModeClear, driver.FilterNearest, driver.AddressClampToZero)
}
func (i *Image) clear() {
if i.priority {
panic("restorable: clear cannot be called on a priority image")
}
clearImage(i.image)
i.basePixels = Pixels{}
i.drawTrianglesHistory = nil
i.stale = false
}
// Fill fills the specified part of the image with a solid color.
func (i *Image) Fill(clr color.RGBA) {
i.basePixels = Pixels{
@ -277,7 +239,10 @@ func fillImage(i *graphicscommand.Image, clr color.RGBA) {
// TODO: Use the previous composite mode if possible.
compositemode := driver.CompositeModeSourceOver
if af < 1.0 {
switch {
case af == 0.0:
compositemode = driver.CompositeModeClear
case af < 1.0:
compositemode = driver.CompositeModeCopy
}
@ -538,7 +503,7 @@ func (i *Image) restore() {
}
if i.volatile {
i.image = graphicscommand.NewImage(w, h)
i.clear()
fillImage(i.image, color.RGBA{})
return
}
if i.stale {
@ -548,9 +513,9 @@ func (i *Image) restore() {
gimg := graphicscommand.NewImage(w, h)
// Clear the image explicitly.
if i != emptyImage {
// As clearImage uses emptyImage, clearImage cannot be called on emptyImage.
// As fillImage uses emptyImage, fillImage cannot be called on emptyImage.
// It is OK to skip this since emptyImage has its entire pixel information.
clearImage(gimg)
fillImage(gimg, color.RGBA{})
}
i.basePixels.Apply(gimg)

View File

@ -344,19 +344,6 @@ func (i *Image) Fill(clr color.RGBA) {
delete(imagesToMakeShared, i)
}
// ClearFramebuffer clears the image with a color. This affects not only the (0, 0)-(width, height) region but also
// the whole framebuffer region.
func (i *Image) ClearFramebuffer() {
backendsM.Lock()
defer backendsM.Unlock()
if i.disposed {
panic("shareable: the drawing target image must not be disposed (Fill)")
}
i.ensureNotShared()
i.backend.restorable.Clear()
}
func (i *Image) ReplacePixels(p []byte) {
backendsM.Lock()
defer backendsM.Unlock()

View File

@ -285,10 +285,6 @@ func (m *mipmap) disposeMipmaps() {
}
}
func (m *mipmap) clearFramebuffer() {
m.orig.ClearFramebuffer()
}
// mipmapLevel returns an appropriate mipmap level for the given determinant of a geometry matrix.
//
// mipmapLevel panics if det is NaN or 0.

View File

@ -98,7 +98,7 @@ func (c *uiContext) Update(afterFrameUpdate func()) error {
}
// This clear is needed for fullscreen mode or some mobile platforms (#622).
c.screen.mipmap.clearFramebuffer()
c.screen.Clear()
op := &DrawImageOptions{}