From 96b9f09058c4fde7d2e036f4c2680a8ceebc9182 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 19 Mar 2018 02:28:17 +0900 Subject: [PATCH] Revert "shareable: Avoid unneeded extending images" This reverts commit ce4e00ff791a41ffb32358bc0663b7ee3ab385b2. Reason: #560 --- internal/packing/packing.go | 32 +----------------------------- internal/shareable/shareable.go | 35 +++++++++------------------------ 2 files changed, 10 insertions(+), 57 deletions(-) diff --git a/internal/packing/packing.go b/internal/packing/packing.go index 52859bc4a..f587e41a0 100644 --- a/internal/packing/packing.go +++ b/internal/packing/packing.go @@ -48,8 +48,8 @@ type Node struct { y int width int height int - used bool + used bool parent *Node child0 *Node child1 *Node @@ -268,33 +268,3 @@ func (p *Page) Extend() bool { p.size = newSize return true } - -func (n *Node) clone() *Node { - if n == nil { - return nil - } - cloned := &Node{ - x: n.x, - y: n.y, - width: n.width, - height: n.height, - used: n.used, - child0: n.child0.clone(), - child1: n.child1.clone(), - } - if cloned.child0 != nil { - cloned.child0.parent = cloned - } - if cloned.child1 != nil { - cloned.child1.parent = cloned - } - return cloned -} - -func (p *Page) Clone() *Page { - return &Page{ - root: p.root.clone(), - size: p.size, - maxSize: p.maxSize, - } -} diff --git a/internal/shareable/shareable.go b/internal/shareable/shareable.go index b80c1fb62..18483857c 100644 --- a/internal/shareable/shareable.go +++ b/internal/shareable/shareable.go @@ -35,39 +35,22 @@ type backend struct { } func (b *backend) TryAlloc(width, height int) (*packing.Node, bool) { - // If the region is allocated without any extention, it's fine. - if n := b.page.Alloc(width, height); n != nil { - return n, true - } - - // Simulate the extending the page and calculate the appropriate page size. - page := b.page.Clone() - nExtended := 0 for { - if !page.Extend() { - // The page can't be extended any more. Return as failure. - return nil, false + if n := b.page.Alloc(width, height); n != nil { + return n, true } - nExtended++ - if n := page.Alloc(width, height); n != nil { + if !b.page.Extend() { break } - } - for i := 0; i < nExtended; i++ { - b.page.Extend() - } - s := b.page.Size() - newImg := restorable.NewImage(s, s, false) - newImg.DrawImage(b.restorable, 0, 0, s, s, nil, nil, opengl.CompositeModeCopy, graphics.FilterNearest) - b.restorable.Dispose() - b.restorable = newImg + s := b.page.Size() + newImg := restorable.NewImage(s, s, false) + newImg.DrawImage(b.restorable, 0, 0, s, s, nil, nil, opengl.CompositeModeCopy, graphics.FilterNearest) - n := b.page.Alloc(width, height) - if n == nil { - panic("not reached") + b.restorable.Dispose() + b.restorable = newImg } - return n, true + return nil, false } var (