Skip to content

Commit

Permalink
Merge pull request fyne-io#4437 from Jacalz/driver-function-call-less
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz authored Dec 5, 2023
2 parents fc111ac + bf0e3b0 commit 30adb16
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
8 changes: 3 additions & 5 deletions internal/driver/common/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,9 @@ func (c *Canvas) FreeDirtyTextures() (freed uint64) {
}
}

cache.RangeExpiredTexturesFor(c.impl, func(obj fyne.CanvasObject) {
if c.painter != nil {
c.painter.Free(obj)
}
})
if c.painter != nil {
cache.RangeExpiredTexturesFor(c.impl, c.painter.Free)
}
return
}

Expand Down
3 changes: 2 additions & 1 deletion internal/driver/glfw/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ func (c *glCanvas) Padded() bool {
func (c *glCanvas) PixelCoordinateForPosition(pos fyne.Position) (int, int) {
c.RLock()
texScale := c.texScale
scale := c.scale
c.RUnlock()
multiple := c.Scale() * texScale
multiple := scale * texScale
scaleInt := func(x float32) int {
return int(math.Round(float64(x * multiple)))
}
Expand Down
34 changes: 18 additions & 16 deletions internal/driver/glfw/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ func (w *window) calculatedScale() float32 {
}

func (w *window) detectTextureScale() float32 {
winWidth, _ := w.view().GetSize()
texWidth, _ := w.view().GetFramebufferSize()
view := w.view()
winWidth, _ := view.GetSize()
texWidth, _ := view.GetFramebufferSize()
return float32(texWidth) / float32(winWidth)
}

Expand All @@ -145,15 +146,16 @@ func (w *window) doShow() {
w.viewLock.Lock()
w.visible = true
w.viewLock.Unlock()
w.view().SetTitle(w.title)
view := w.view()
view.SetTitle(w.title)

if w.centered {
w.doCenterOnScreen() // lastly center if that was requested
}
w.view().Show()
view.Show()

// save coordinates
w.xpos, w.ypos = w.view().GetPos()
w.xpos, w.ypos = view.GetPos()

if w.fullScreen { // this does not work if called before viewport.Show()
go func() {
Expand All @@ -164,8 +166,8 @@ func (w *window) doShow() {
})

// show top canvas element
if w.canvas.Content() != nil {
w.canvas.Content().Show()
if content := w.canvas.Content(); content != nil {
content.Show()

runOnDraw(w, func() {
w.driver.repaintWindow(w)
Expand All @@ -188,8 +190,8 @@ func (w *window) Hide() {
v.Hide()

// hide top canvas element
if w.canvas.Content() != nil {
w.canvas.Content().Hide()
if content := w.canvas.Content(); content != nil {
content.Hide()
}
})
}
Expand All @@ -210,9 +212,8 @@ func (w *window) Close() {
w.closing = true
w.viewLock.Unlock()
w.viewport.SetShouldClose(true)
cache.RangeTexturesFor(w.canvas, func(obj fyne.CanvasObject) {
w.canvas.Painter().Free(obj)
})

cache.RangeTexturesFor(w.canvas, w.canvas.Painter().Free)
})

w.canvas.WalkTrees(nil, func(node *common.RenderCacheNode, _ fyne.Position) {
Expand Down Expand Up @@ -968,12 +969,13 @@ func (w *window) doShowAgain() {

runOnMain(func() {
// show top canvas element
if w.canvas.Content() != nil {
w.canvas.Content().Show()
if content := w.canvas.Content(); content != nil {
content.Show()
}

w.view().SetPos(w.xpos, w.ypos)
w.view().Show()
view := w.view()
view.SetPos(w.xpos, w.ypos)
view.Show()
w.viewLock.Lock()
w.visible = true
w.viewLock.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion internal/driver/glfw/window_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (w *window) getMonitorForWindow() *glfw.Monitor {
if x > xOff || y > yOff {
continue
}
if x+monitor.GetVideoMode().Width <= xOff || y+monitor.GetVideoMode().Height <= yOff {
if videoMode := monitor.GetVideoMode(); x+videoMode.Width <= xOff || y+videoMode.Height <= yOff {
continue
}

Expand Down
4 changes: 1 addition & 3 deletions internal/driver/mobile/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ func (w *window) Close() {
d.windows = append(d.windows[:pos], d.windows[pos+1:]...)
}

cache.RangeTexturesFor(w.canvas, func(obj fyne.CanvasObject) {
w.canvas.Painter().Free(obj)
})
cache.RangeTexturesFor(w.canvas, w.canvas.Painter().Free)

w.canvas.WalkTrees(nil, func(node *common.RenderCacheNode, _ fyne.Position) {
if wid, ok := node.Obj().(fyne.Widget); ok {
Expand Down

0 comments on commit 30adb16

Please sign in to comment.