shareable: Refactoring

This commit is contained in:
Hajime Hoshi 2018-06-26 01:59:12 +09:00
parent b1e4c3c8f0
commit dec921809b

View File

@ -94,17 +94,20 @@ type Image struct {
backend *backend
// If node is nil, the image is not shared.
node *packing.Node
}
func (i *Image) isShared() bool {
return i.node != nil
}
func (i *Image) ensureNotShared() {
if i.backend == nil {
i.allocate(false)
return
}
if i.node == nil {
if !i.isShared() {
return
}
@ -124,7 +127,7 @@ func (i *Image) region() (x, y, width, height int) {
if i.backend == nil {
panic("not reached")
}
if i.node == nil {
if !i.isShared() {
w, h := i.backend.restorable.Size()
return 0, 0, w, h
}
@ -223,7 +226,7 @@ func (i *Image) dispose(markDisposed bool) {
return
}
if i.node == nil {
if !i.isShared() {
i.backend.restorable.Dispose()
return
}