From 528768e4092954011e331d4ef360c017f300e080 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sat, 21 Dec 2024 08:46:42 -0800 Subject: [PATCH 1/2] ensure text and SVG textures re-rasterize when window is dragged to new monitor --- internal/cache/texture_common.go | 14 ++++++++++++++ internal/driver/glfw/window_desktop.go | 5 +++++ internal/driver/glfw/window_wasm.go | 7 ++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/internal/cache/texture_common.go b/internal/cache/texture_common.go index be0dce90b1..c8e8dea7e4 100644 --- a/internal/cache/texture_common.go +++ b/internal/cache/texture_common.go @@ -78,6 +78,20 @@ func RangeTexturesFor(canvas fyne.Canvas, f func(fyne.CanvasObject)) { }) } +// DeleteTextTexturesFor deletes all text textures for the given canvas. +func DeleteTextTexturesFor(canvas fyne.Canvas) { + textures.Range(func(key, value any) bool { + if _, ok := key.(FontCacheEntry); ok { + tinfo := value.(*textureInfo) + if tinfo.canvas == canvas { + textures.Delete(key) + tinfo.textFree() + } + } + return true + }) +} + // SetTextTexture sets cached texture for a text run. func SetTextTexture(ent FontCacheEntry, texture TextureType, canvas fyne.Canvas, free func()) { store(ent, texture, canvas, free) diff --git a/internal/driver/glfw/window_desktop.go b/internal/driver/glfw/window_desktop.go index 3aae611b8f..9a1a365643 100644 --- a/internal/driver/glfw/window_desktop.go +++ b/internal/driver/glfw/window_desktop.go @@ -15,6 +15,7 @@ import ( "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/driver/desktop" "fyne.io/fyne/v2/internal/build" + "fyne.io/fyne/v2/internal/cache" "fyne.io/fyne/v2/internal/painter" "fyne.io/fyne/v2/internal/painter/gl" "fyne.io/fyne/v2/internal/scale" @@ -703,6 +704,10 @@ func (w *window) rescaleOnMain() { size := w.canvas.size.Max(w.canvas.MinSize()) newWidth, newHeight := w.screenSize(size) w.viewport.SetSize(newWidth, newHeight) + + // Ensure textures re-rasterize at the new scale + cache.DeleteTextTexturesFor(w.canvas) + w.canvas.content.Refresh() } func (w *window) create() { diff --git a/internal/driver/glfw/window_wasm.go b/internal/driver/glfw/window_wasm.go index c33a2cd97d..38833200b6 100644 --- a/internal/driver/glfw/window_wasm.go +++ b/internal/driver/glfw/window_wasm.go @@ -11,6 +11,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/driver/desktop" + "fyne.io/fyne/v2/internal/cache" "fyne.io/fyne/v2/internal/painter/gl" "fyne.io/fyne/v2/internal/scale" @@ -474,7 +475,11 @@ func (w *window) rescaleOnMain() { scale.ToFyneCoordinate(w.canvas, w.width), scale.ToFyneCoordinate(w.canvas, w.height)) w.canvas.Resize(scaledFull) - return + + // Ensure textures re-rasterize at the new scale + cache.DeleteTextTexturesFor(w.canvas) + w.canvas.content.Refresh() + //return // } // size := w.canvas.size.Union(w.canvas.MinSize()) From 91a524f32cf069a78d1655c5c15f321d4633eb86 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sun, 22 Dec 2024 15:15:30 -0800 Subject: [PATCH 2/2] remove commented-out lines --- internal/driver/glfw/window_wasm.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/internal/driver/glfw/window_wasm.go b/internal/driver/glfw/window_wasm.go index 38833200b6..b969a128a4 100644 --- a/internal/driver/glfw/window_wasm.go +++ b/internal/driver/glfw/window_wasm.go @@ -469,7 +469,6 @@ func (w *window) rescaleOnMain() { return } - // if w.fullScreen { w.width, w.height = w.viewport.GetSize() scaledFull := fyne.NewSize( scale.ToFyneCoordinate(w.canvas, w.width), @@ -479,12 +478,6 @@ func (w *window) rescaleOnMain() { // Ensure textures re-rasterize at the new scale cache.DeleteTextTexturesFor(w.canvas) w.canvas.content.Refresh() - //return - // } - - // size := w.canvas.size.Union(w.canvas.MinSize()) - // newWidth, newHeight := w.screenSize(size) - // w.viewport.SetSize(newWidth, newHeight) } func (w *window) create() {