diff --git a/electron/gpuSwitches.test.ts b/electron/gpuSwitches.test.ts index 4cbb1cdf4..04d12556d 100644 --- a/electron/gpuSwitches.test.ts +++ b/electron/gpuSwitches.test.ts @@ -1,66 +1,27 @@ import { describe, expect, it } from "vitest"; -import { getGpuSwitches, shouldForceLinuxEgl } from "./gpuSwitches"; - -describe("shouldForceLinuxEgl", () => { - it("does not force EGL in a Wayland session", () => { - expect( - shouldForceLinuxEgl({ - XDG_SESSION_TYPE: "wayland", - WAYLAND_DISPLAY: "wayland-0", - }), - ).toBe(false); - }); - - it("does not force EGL when Wayland is explicitly requested via Ozone", () => { - expect( - shouldForceLinuxEgl({ - OZONE_PLATFORM: "wayland", - XDG_SESSION_TYPE: "x11", - }), - ).toBe(false); - }); - - it("falls back to Electron's ozone hint when OZONE_PLATFORM is invalid", () => { - expect( - shouldForceLinuxEgl({ - OZONE_PLATFORM: "auto", - ELECTRON_OZONE_PLATFORM_HINT: "wayland", - XDG_SESSION_TYPE: "x11", - }), - ).toBe(false); - }); - - it("forces EGL in an X11 session", () => { - expect(shouldForceLinuxEgl({ XDG_SESSION_TYPE: "x11" })).toBe(true); - }); - - it("forces EGL when x11 is explicitly requested via Electron's ozone hint", () => { - expect( - shouldForceLinuxEgl({ - ELECTRON_OZONE_PLATFORM_HINT: "x11", - WAYLAND_DISPLAY: "wayland-0", - }), - ).toBe(true); - }); -}); +import { getGpuSwitches } from "./gpuSwitches"; describe("getGpuSwitches", () => { - it("returns the Linux VAAPI workaround without forcing EGL on Wayland", () => { + it("returns the Linux VAAPI workaround without forcing a GL implementation on Wayland", () => { expect( getGpuSwitches("linux", { XDG_SESSION_TYPE: "wayland", WAYLAND_DISPLAY: "wayland-0", }), ).toEqual({ - useGl: undefined, disableFeatures: ["VaapiVideoDecoder", "VaapiVideoEncoder"], }); }); - it("returns the X11 EGL workaround on Linux X11", () => { + it("does not force a GL implementation on Linux X11", () => { expect(getGpuSwitches("linux", { XDG_SESSION_TYPE: "x11" })).toEqual({ - useGl: "egl", + disableFeatures: ["VaapiVideoDecoder", "VaapiVideoEncoder"], + }); + }); + + it("does not force a GL implementation when the session type is unknown", () => { + expect(getGpuSwitches("linux", {})).toEqual({ disableFeatures: ["VaapiVideoDecoder", "VaapiVideoEncoder"], }); }); diff --git a/electron/gpuSwitches.ts b/electron/gpuSwitches.ts index 7b7c81ee8..48eb4b35d 100644 --- a/electron/gpuSwitches.ts +++ b/electron/gpuSwitches.ts @@ -1,48 +1,11 @@ export interface GpuSwitches { useAngle?: string; - useGl?: string; disableFeatures?: string[]; } -function normalizeLinuxWindowSystem(value: string | undefined): "wayland" | "x11" | null { - const normalized = value?.trim().toLowerCase(); - if (normalized === "wayland" || normalized === "x11") { - return normalized; - } - - return null; -} - -function getForcedLinuxWindowSystem(env: NodeJS.ProcessEnv): "wayland" | "x11" | null { - return ( - normalizeLinuxWindowSystem(env.OZONE_PLATFORM) ?? - normalizeLinuxWindowSystem(env.ELECTRON_OZONE_PLATFORM_HINT) - ); -} - -export function shouldForceLinuxEgl(env: NodeJS.ProcessEnv): boolean { - const forcedWindowSystem = getForcedLinuxWindowSystem(env); - if (forcedWindowSystem === "wayland") { - return false; - } - if (forcedWindowSystem === "x11") { - return true; - } - - const sessionType = env.XDG_SESSION_TYPE?.toLowerCase(); - if (sessionType === "wayland") { - return false; - } - if (sessionType === "x11") { - return true; - } - - return !env.WAYLAND_DISPLAY; -} - export function getGpuSwitches( platform: NodeJS.Platform, - env: NodeJS.ProcessEnv = process.env, + _env: NodeJS.ProcessEnv = process.env, ): GpuSwitches { if (platform === "darwin") { return { @@ -56,8 +19,9 @@ export function getGpuSwitches( } if (platform === "linux") { + // No use-gl override: Chromium only allows (gl=egl-angle, angle=default) on Linux now. + // Passing use-gl=egl requests (gl=egl-gles2, angle=none) and kills the GPU process. return { - useGl: shouldForceLinuxEgl(env) ? "egl" : undefined, disableFeatures: ["VaapiVideoDecoder", "VaapiVideoEncoder"], }; } diff --git a/electron/main.ts b/electron/main.ts index 38f4333ff..a8c84dc4b 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -89,13 +89,11 @@ app.on("web-contents-created", (_event, contents) => { }); function configureGpuAccelerationSwitches() { - const { useAngle, useGl, disableFeatures } = getGpuSwitches(process.platform, process.env); + const { useAngle, disableFeatures } = getGpuSwitches(process.platform, process.env); if (useAngle) { app.commandLine.appendSwitch("use-angle", useAngle); } - if (useGl) { - app.commandLine.appendSwitch("use-gl", useGl); - } + if (disableFeatures && disableFeatures.length > 0) { app.commandLine.appendSwitch("disable-features", disableFeatures.join(",")); }