zhang-4411 (#2827): under xrdp/X11 with no GPU the Routing page's web process took 459%-830% CPU, and 23% with WEBKIT_DISABLE_COMPOSITING_MODE=1, looking the same. With no render node EGL can open, WebKitGTK's compositing falls back to Mesa's llvmpipe, which rasterises and blends every layer on the CPU with a thread per core. webkitDefaults already turned compositing off under Wayland (myxxts's flicker). It now does so under X11 too when gpuReachable finds no /dev/dri/renderD* this process can open (none there, or each refused: the xrdp user outside the render group). X11 with a GPU is left as it was, and a user who set WEBKIT_DISABLE_COMPOSITING_MODE or WEBKIT_DISABLE_DMABUF_RENDERER keeps what they set (WEBKIT_DISABLE_COMPOSITING_MODE=0 turns compositing back on). Run: - gofmt -l internal/gui: nothing - go vet ./internal/gui; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet -tags nogui ./...: clean - go test -tags nogui ./internal/gui -timeout 45m (macOS): ok github.com/yetone/magpie/internal/gui 1013.214s - webkit_linux*.go build only on Linux, so the tests ran there: CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go test -c -tags nogui, run in docker golang:1.26.8: TestWebkitDefaults and TestRenderNodeOpens PASS. - Broken by hand (gpu() || true in webkitDefaultsFor): FAIL "x11 without a gpu (xrdp): WEBKIT_DISABLE_COMPOSITING_MODE="", want "1"". Restored. Not tried: a real xrdp session, llvmpipe or WebKitGTK. gpuReachable was not run on a machine where the render node is refused; the CPU figures are the reporter's.
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
package gui
|
||
|
||
import (
|
||
"os"
|
||
"path/filepath"
|
||
)
|
||
|
||
// webkitDefaults sets how WebKitGTK draws the pages before the app makes
|
||
// its first webview. Under Wayland its accelerated compositing flickers the
|
||
// window on a click or a hover (myxxts on Discord: Fedora 44, KDE, AMD
|
||
// Radeon 780M; Wails already turns DMA-BUF off for NVIDIA only), and with
|
||
// it off the pages draw steadily and, as they said, smoother. A user who
|
||
// set either variable keeps what they set; WEBKIT_DISABLE_COMPOSITING_MODE=0
|
||
// turns compositing back on.
|
||
//
|
||
// Under X11 with no GPU this process can draw with — an xrdp, VNC or Xvfb
|
||
// session, or a user outside the render group — the compositing falls back
|
||
// to Mesa's llvmpipe, which rasterises and blends every layer on the CPU
|
||
// with a thread per core: the Routing page took 459%–830% CPU there, and
|
||
// 23% with compositing off, looking the same (#2827, zhang-4411). So with
|
||
// no render node this process can open, compositing is off too.
|
||
func webkitDefaults() {
|
||
webkitDefaultsFor(os.Getenv, os.Setenv, gpuReachable)
|
||
}
|
||
|
||
func webkitDefaultsFor(getenv func(string) string, setenv func(string, string) error, gpu func() bool) {
|
||
if getenv("WEBKIT_DISABLE_COMPOSITING_MODE") != "" || getenv("WEBKIT_DISABLE_DMABUF_RENDERER") != "" {
|
||
return
|
||
}
|
||
wayland := getenv("XDG_SESSION_TYPE") == "wayland" || getenv("WAYLAND_DISPLAY") != ""
|
||
if !wayland && gpu() {
|
||
return
|
||
}
|
||
setenv("WEBKIT_DISABLE_COMPOSITING_MODE", "1")
|
||
}
|
||
|
||
// gpuReachable reports whether this process can open a DRM render node,
|
||
// which is what EGL needs to draw on a GPU: none there, or none this user
|
||
// may open (libEGL's "failed to open /dev/dri/renderD128: Permission
|
||
// denied"), and WebKit's GL is software.
|
||
func gpuReachable() bool {
|
||
nodes, _ := filepath.Glob("/dev/dri/renderD*")
|
||
return renderNodeOpens(nodes, func(p string) error {
|
||
f, err := os.OpenFile(p, os.O_RDWR, 0)
|
||
if err == nil {
|
||
f.Close()
|
||
}
|
||
return err
|
||
})
|
||
}
|
||
|
||
func renderNodeOpens(nodes []string, open func(string) error) bool {
|
||
for _, n := range nodes {
|
||
if open(n) == nil {
|
||
return true
|
||
}
|
||
}
|
||
return false
|
||
}
|