Files
magpie/internal/gui/webkit_linux_test.go
T
yetone 2d12ce98be gui: on Linux without a GPU WebKitGTK draws without accelerated compositing (#2827)
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.
2026-10-20 20:23:53 +08:00

64 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package gui
import (
"errors"
"testing"
)
// Under Wayland the pages are drawn without accelerated compositing, which
// flickered (myxxts); under X11 too when no GPU can be reached, where
// compositing fell back to llvmpipe and took 459%–830% CPU (#2827). X11
// with a GPU is left alone, and so is a user's own setting.
func TestWebkitDefaults(t *testing.T) {
for _, c := range []struct {
name string
env map[string]string
gpu bool
want string
}{
{"wayland", map[string]string{"XDG_SESSION_TYPE": "wayland"}, true, "1"},
{"wayland display only", map[string]string{"WAYLAND_DISPLAY": "wayland-0"}, true, "1"},
{"x11", map[string]string{"XDG_SESSION_TYPE": "x11"}, true, ""},
{"x11 without a gpu (xrdp)", map[string]string{"XDG_SESSION_TYPE": "x11", "DISPLAY": ":10"}, false, "1"},
{"user turned it on again", map[string]string{"XDG_SESSION_TYPE": "wayland", "WEBKIT_DISABLE_COMPOSITING_MODE": "0"}, true, "0"},
{"user turned it on again without a gpu", map[string]string{"XDG_SESSION_TYPE": "x11", "WEBKIT_DISABLE_COMPOSITING_MODE": "0"}, false, "0"},
{"user chose dmabuf off", map[string]string{"XDG_SESSION_TYPE": "wayland", "WEBKIT_DISABLE_DMABUF_RENDERER": "1"}, true, ""},
{"user chose dmabuf off without a gpu", map[string]string{"XDG_SESSION_TYPE": "x11", "WEBKIT_DISABLE_DMABUF_RENDERER": "1"}, false, ""},
} {
env := map[string]string{}
for k, v := range c.env {
env[k] = v
}
webkitDefaultsFor(func(k string) string { return env[k] }, func(k, v string) error { env[k] = v; return nil }, func() bool { return c.gpu })
if got := env["WEBKIT_DISABLE_COMPOSITING_MODE"]; got != c.want {
t.Errorf("%s: WEBKIT_DISABLE_COMPOSITING_MODE=%q, want %q", c.name, got, c.want)
}
}
}
// A GPU is reachable when one render node opens: none there, or each one
// refused (the xrdp user outside the render group), is software drawing.
func TestRenderNodeOpens(t *testing.T) {
denied := errors.New("permission denied")
for _, c := range []struct {
name string
nodes []string
ok map[string]bool
want bool
}{
{"no render node", nil, nil, false},
{"every node refused", []string{"/dev/dri/renderD128", "/dev/dri/renderD129"}, nil, false},
{"the second node opens", []string{"/dev/dri/renderD128", "/dev/dri/renderD129"}, map[string]bool{"/dev/dri/renderD129": true}, true},
} {
got := renderNodeOpens(c.nodes, func(p string) error {
if c.ok[p] {
return nil
}
return denied
})
if got != c.want {
t.Errorf("%s: renderNodeOpens = %v, want %v", c.name, got, c.want)
}
}
}