Skip to content

Commit

Permalink
Merge pull request #5374 from Jacalz/remove-test-only-painterData
Browse files Browse the repository at this point in the history
Remove painterData field only used in tests
  • Loading branch information
Jacalz authored Jan 8, 2025
2 parents 190fe42 + 389c9bf commit fff7da7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
5 changes: 0 additions & 5 deletions internal/driver/common/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,6 @@ type RenderCacheNode struct {
parent *RenderCacheNode
// cache data
minSize fyne.Size
// painterData is some data from the painter associated with the drawn node
// it may for instance point to a GL texture
// it should free all associated resources when released
// i.e. it should not simply be a texture reference integer
painterData any
}

// Obj returns the node object.
Expand Down
28 changes: 15 additions & 13 deletions internal/driver/common/canvas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,24 @@ func TestCanvas_walkTree(t *testing.T) {
obj fyne.CanvasObject
lastBeforeCallIndex, lastAfterCallIndex int
}

painterData := make(map[*RenderCacheNode]nodeInfo)
updateInfoBefore := func(node *RenderCacheNode, index int) {
pd, _ := node.painterData.(nodeInfo)
if (pd != nodeInfo{}) && pd.obj != node.obj {
pd, ok := painterData[node]
if ok && pd.obj != node.obj {
panic("node cache does not match node obj - nodes should not be reused for different objects")
}
pd.obj = node.obj
pd.lastBeforeCallIndex = index
node.painterData = pd
painterData[node] = pd
}
updateInfoAfter := func(node *RenderCacheNode, index int) {
pd := node.painterData.(nodeInfo)
pd := painterData[node]
if pd.obj != node.obj {
panic("node cache does not match node obj - nodes should not be reused for different objects")
}
pd.lastAfterCallIndex = index
node.painterData = pd
painterData[node] = pd
}

//
Expand Down Expand Up @@ -122,10 +124,10 @@ func TestCanvas_walkTree(t *testing.T) {
nodes := []*RenderCacheNode{}

c.walkTree(tree, func(node *RenderCacheNode, pos fyne.Position) {
secondRunBeforePainterData = append(secondRunBeforePainterData, node.painterData.(nodeInfo))
secondRunBeforePainterData = append(secondRunBeforePainterData, painterData[node])
nodes = append(nodes, node)
}, func(node *RenderCacheNode, _ fyne.Position) {
secondRunAfterPainterData = append(secondRunAfterPainterData, node.painterData.(nodeInfo))
secondRunAfterPainterData = append(secondRunAfterPainterData, painterData[node])
})

assert.Equal(t, []nodeInfo{
Expand Down Expand Up @@ -172,11 +174,11 @@ func TestCanvas_walkTree(t *testing.T) {
c.walkTree(tree, func(node *RenderCacheNode, pos fyne.Position) {
i++
updateInfoBefore(node, i)
thirdRunBeforePainterData = append(thirdRunBeforePainterData, node.painterData.(nodeInfo))
thirdRunBeforePainterData = append(thirdRunBeforePainterData, painterData[node])
}, func(node *RenderCacheNode, _ fyne.Position) {
i++
updateInfoAfter(node, i)
thirdRunAfterPainterData = append(thirdRunAfterPainterData, node.painterData.(nodeInfo))
thirdRunAfterPainterData = append(thirdRunAfterPainterData, painterData[node])
})

assert.Equal(t, []nodeInfo{
Expand Down Expand Up @@ -217,12 +219,12 @@ func TestCanvas_walkTree(t *testing.T) {
c.walkTree(tree, func(node *RenderCacheNode, pos fyne.Position) {
i++
updateInfoBefore(node, i)
fourthRunBeforePainterData = append(fourthRunBeforePainterData, node.painterData.(nodeInfo))
fourthRunBeforePainterData = append(fourthRunBeforePainterData, painterData[node])
nodes = append(nodes, node)
}, func(node *RenderCacheNode, _ fyne.Position) {
i++
updateInfoAfter(node, i)
fourthRunAfterPainterData = append(fourthRunAfterPainterData, node.painterData.(nodeInfo))
fourthRunAfterPainterData = append(fourthRunAfterPainterData, painterData[node])
})

assert.Equal(t, []nodeInfo{
Expand Down Expand Up @@ -299,12 +301,12 @@ func TestCanvas_walkTree(t *testing.T) {
c.walkTree(tree, func(node *RenderCacheNode, pos fyne.Position) {
i++
updateInfoBefore(node, i)
fifthRunBeforePainterData = append(fifthRunBeforePainterData, node.painterData.(nodeInfo))
fifthRunBeforePainterData = append(fifthRunBeforePainterData, painterData[node])
nodes = append(nodes, node)
}, func(node *RenderCacheNode, _ fyne.Position) {
i++
updateInfoAfter(node, i)
fifthRunAfterPainterData = append(fifthRunAfterPainterData, node.painterData.(nodeInfo))
fifthRunAfterPainterData = append(fifthRunAfterPainterData, painterData[node])
})

assert.Equal(t, []nodeInfo{
Expand Down

0 comments on commit fff7da7

Please sign in to comment.