go-flutter-desktop / go-flutter

Flutter on Windows, MacOS and Linux - based on Flutter Embedding, Go and GLFW.
https://hover.build/
BSD 3-Clause "New" or "Revised" License
5.86k stars 282 forks source link

Render problem in linux #665

Closed mdpe-ir closed 2 years ago

mdpe-ir commented 2 years ago

Hover doctor

$ hover doctor
hover: Hover version v0.47.0 running on linux
hover: Sharing packaging tools
hover: darwin-bundle is supported
hover: darwin-dmg is supported
hover: To package darwin-pkg these tools are required: mkbom,xar
hover: Install bomutils from your package manager or from https://github.com/hogliux/bomutils
hover: Install xar from your package manager or from https://github.com/mackyle/xar
hover: To still package darwin-pkg without the required tools installed you need to run hover with the `--docker` flag.
hover: To package linux-appimage these tools are required: appimagetool
hover: Install appimagetool from your package manager or from https://github.com/AppImage/AppImageKit#appimagetool-usage
hover: To still package linux-appimage without the required tools installed you need to run hover with the `--docker` flag.
hover: linux-deb is supported
hover: To package linux-pkg these tools are required: makepkg
hover: You need to be on Arch Linux or another distro that uses pacman as package manager to use this. Installing makepkg on other distros is hard and dangerous.
hover: To still package linux-pkg without the required tools installed you need to run hover with the `--docker` flag.
hover: To package linux-rpm these tools are required: rpmbuild
hover: You need to be on Red Hat Linux or another distro that uses rpm as package manager to use this. Installing rpmbuild on other distros is hard and dangerous.
hover: To still package linux-rpm without the required tools installed you need to run hover with the `--docker` flag.
hover: To package linux-snap these tools are required: snapcraft
hover: Install snapd from your package manager or from https://snapcraft.io/docs/installing-snapd
hover: To still package linux-snap without the required tools installed you need to run hover with the `--docker` flag.
hover: To package windows-msi these tools are required: wixl
hover: Install msitools from your package manager or from https://wiki.gnome.org/msitools/
hover: To still package windows-msi without the required tools installed you need to run hover with the `--docker` flag.
hover: 
hover: Sharing flutter version
Flutter 2.10.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 5464c5bac7 (3 months ago) • 2022-04-18 09:55:37 -0700
Engine • revision 57d3bac3dd
Tools • Dart 2.16.2 • DevTools 2.9.2
hover: Flutter engine commit: https://github.com/flutter/engine/commit/57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab
hover: ⚠ The go-flutter project tries to stay compatible with the beta channel of Flutter.
hover: ⚠     It's advised to use the beta channel: `flutter channel beta`
hover: Finding out the C compiler version
gcc (Debian 11.3.0-3) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

hover: Sharing the content of go.mod
module simpleApplication/go

go 1.18

require (
    github.com/go-flutter-desktop/go-flutter v0.52.0
    github.com/pkg/errors v0.9.1
)

require (
    github.com/Xuanwo/go-locale v1.1.0 // indirect
    github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
    github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220622232848-a6c407ee30a0 // indirect
    golang.org/x/sys v0.0.0-20211023085530-d6a326fbbf70 // indirect
    golang.org/x/text v0.3.7 // indirect
)
hover: Sharing the content of hover.yaml
application-name: ""
executable-name: ""
package-name: ""
organization-name: com.tem
license: ""
target: lib/main_desktop.dart
branch: ""
cache-path: ""
opengl: ""
engine-version: ""
hover: Sharing the content of go/cmd
go/cmd/main.go  go/cmd/options.go

Error output

Screenshot from 2022-07-14 23-31-14


The last time I used this project was about 2 months ago and everything was working fine. But now the rendering is not done properly and the screen scale is very small.

Neofetch

                                               mahan@sparkylinux 
           .            `-:-`                  ----------------- 
          .o`       .-///-`                    OS: SparkyLinux 7 (Orion-Belt) x86_64 
         `oo`    .:/++:.                       Host: HP Compaq Elite 8300 SFF 
         os+`  -/+++:` ``.........```          Kernel: 5.18.0-2-amd64 
        /ys+`./+++/-.-::::::----......``       Uptime: 9 hours, 36 mins 
       `syyo`++o+--::::-::/+++/-``             Packages: 2931 (dpkg) 
       -yyy+.+o+`:/:-:sdmmmmmmmmdy+-`          Shell: zsh 5.9 
::-`   :yyy/-oo.-+/`ymho++++++oyhdmdy/`        Resolution: 1366x768 
`/yy+-`.syyo`+o..o--h..osyhhddhs+//osyy/`      DE: Cinnamon 5.2.7 
  -ydhs+-oyy/.+o.-: ` `  :/::+ydhy+```-os-     WM: Mutter (Muffin) 
   .sdddy::syo--/:.     `.:dy+-ohhho    ./:    WM Theme: Orchis-Dark (Orchis) 
     :yddds/:+oo+//:-`- /+ +hy+.shhy:     ``   Theme: Orchis-Compact [GTK2/3] 
      `:ydmmdysooooooo-.ss`/yss--oyyo          Icons: Flat-Remix-Blue-Light-darkPanel [GTK2/3] 
        `./ossyyyyo+:-/oo:.osso- .oys          Terminal: gnome-terminal 
       ``..-------::////.-oooo/   :so          CPU: Intel i5-3470 (4) @ 3.600GHz 
    `...----::::::::--.`/oooo:    .o:          GPU: Intel HD Graphics 
           ```````     ++o+:`     `:`        
                     ./+/-`        `
                   `-:-.                                               
                   ``                                                  
provokateurin commented 2 years ago

Very likely related to https://github.com/go-flutter-desktop/go-flutter/pull/458, @pchampio.

mdpe-ir commented 2 years ago

Very likely related to #458

I also changed my DPI Scaling but doesn't fix it.

pchampio commented 2 years ago
package main

import (
    "runtime"
    "fmt"
    "github.com/go-gl/glfw/v3.3/glfw"
)

// dpPerInch defines the amount of display pixels per inch as defined for Flutter.
const dpPerInch = 160.0

func getPixelRatioLinux(window *glfw.Window) float64 {
    widthPx, heightPx := window.GetFramebufferSize()

    var selectedMonitor *glfw.Monitor
    winX, winY := window.GetPos()
    winCenterX, winCenterY := winX+widthPx/2, winY+heightPx/2

    monitors := glfw.GetMonitors()
    for _, monitor := range monitors {
        monX1, monY1 := monitor.GetPos()
        monMode := monitor.GetVideoMode()
        if monMode == nil {
            continue
        }
        monX2, monY2 := monX1+monMode.Width, monY1+monMode.Height
        if (monX1 <= winCenterX && winCenterX <= monX2) &&
            (monY1 <= winCenterY && winCenterY <= monY2) {
            selectedMonitor = monitor
            break
        }
    }

    if selectedMonitor == nil {
        // when no monitor was selected, try fallback to primary monitor
        // TODO: ? perhaps select monitor that is "closest" to the window ?
        selectedMonitor = glfw.GetPrimaryMonitor()
    }
    if selectedMonitor == nil {
        fmt.Printf("selectedMonitor == nil")
        return getPixelRatioOther(window)
    }
    selectedMonitorMode := selectedMonitor.GetVideoMode()
    if selectedMonitorMode == nil {
        fmt.Printf("selectedMonitorMode == nil")
        return getPixelRatioOther(window)
    }
    selectedMonitorWidthMM, _ := selectedMonitor.GetPhysicalSize()
    if selectedMonitorWidthMM == 0 {
        fmt.Printf("selectedMonitorWidthMM == 0")
        return getPixelRatioOther(window)
    }
    monitorScreenCoordinatesPerInch := float64(selectedMonitorMode.Width) / (float64(selectedMonitorWidthMM) / 25.4)

    /// from another function
    widthPx, heightPx = window.GetFramebufferSize()
    width, _ := window.GetSize()
    if width == 0 {
        panic("go-flutter: Cannot calculate pixelsPerScreenCoordinate for zero-width window.")
    }
    pixelsPerScreenCoordinate := float64(widthPx) / float64(width)
    /// end

    dpi := pixelsPerScreenCoordinate * monitorScreenCoordinatesPerInch
    pixelRatio := dpi / dpPerInch

    // If the pixelRatio is lower than 1 use this pixelRatio factor to downscale the ContentScale
    fmt.Printf("\npixel ration : %v", pixelRatio)
    if pixelRatio < 1.0 {
        pixelRatio *= getPixelRatioOther(window)
        if pixelRatio < 1.0 {
            fmt.Printf("\npixel ration lower than 1 after rescaling : %v", pixelRatio)
        }
    }
    return pixelRatio
}

func getPixelRatioOther(window *glfw.Window) float64 {
    xscale, _ := window.GetContentScale()
    return float64(xscale)
}

func init() {
    // This is needed to arrange that main() runs on main thread.
    // See documentation for functions that are only allowed to be called from the main thread.
    runtime.LockOSThread()
}

func main() {
    err := glfw.Init()
    if err != nil {
        panic(err)
    }
    defer glfw.Terminate()

    window, err := glfw.CreateWindow(640, 480, "Testing", nil, nil)
    if err != nil {
        panic(err)
    }

    window.MakeContextCurrent()

    window.SetPosCallback(func(window *glfw.Window, xpos int, ypos int) {
        xscale := getPixelRatioOther(window)
        xscaleLinux := getPixelRatioLinux(window)
        fmt.Printf("\n%v content scale other.\n", xscale)
        fmt.Printf("%v content scale linux.\n", xscaleLinux)
    })

    for !window.ShouldClose() {
        // Do OpenGL stuff.
        window.SwapBuffers()
        glfw.PollEvents()
    }
}

Can you try to run this code (go run main.go), It should help me understand where this down-scaling issue comes.

mdpe-ir commented 2 years ago

Screenshot from 2022-07-17 18-55-45

pixel ration : 0.5289085365853659
pixel ration lower than 1 after rescaling : 0.5289085365853659
1 content scale other.
0.5289085365853659 content scale linux.

@pchampio

pchampio commented 2 years ago

Awesome, I know how to fix this ;)

pchampio commented 2 years ago

fixed in v0.52.1

mdpe-ir commented 2 years ago

fixed in v0.52.1 Screenshot from 2022-07-17 19-26-12

The problem is completely solved. 💯 thank you ❤️