Use XAppGpuOffloadHelper for gpu offloading, respect

PrefersNonDefaultGPU desktop entry key.

XApp.util_gpu_offload_supported() is still used as a fallback
for older libxapp versions.
This commit is contained in:
Michael Webster 2023-05-10 11:48:10 -04:00
parent 90688a9c9f
commit e4eab43d06
No known key found for this signature in database
GPG Key ID: 9E8DD70A52A44C58
4 changed files with 25 additions and 5 deletions

View File

@ -10,6 +10,7 @@ import traceback
import gi import gi
gi.require_version("Gtk", "3.0") gi.require_version("Gtk", "3.0")
gi.require_version('MatePanelApplet', '4.0') gi.require_version('MatePanelApplet', '4.0')
gi.require_version('XApp', '1.0')
from gi.repository import Gtk, GdkPixbuf, Gdk, GObject from gi.repository import Gtk, GdkPixbuf, Gdk, GObject
from gi.repository import MatePanelApplet from gi.repository import MatePanelApplet
from gi.repository import Gio from gi.repository import Gio

View File

@ -191,6 +191,10 @@ class pluginclass(object):
self.canOffload = False self.canOffload = False
try:
helper = XApp.GpuOffloadHelper.get_sync()
self.canOffload = helper.is_offload_supported()
except AttributeError:
try: try:
self.canOffload = XApp.util_gpu_offload_supported() self.canOffload = XApp.util_gpu_offload_supported()
except AttributeError: except AttributeError:

View File

@ -268,6 +268,7 @@ class ApplicationLauncher(easyButton):
self.appMateDocPath = desktopItem.get("X-MATE-DocPath") or "" self.appMateDocPath = desktopItem.get("X-MATE-DocPath") or ""
self.useTerminal = desktopItem.getTerminal() self.useTerminal = desktopItem.getTerminal()
self.appPath = desktopItem.getPath() self.appPath = desktopItem.getPath()
self.prefersOffload = desktopItem.get("PrefersNonDefaultGPU", "Desktop Entry", type="boolean")
if not self.appMateDocPath: if not self.appMateDocPath:
self.appKdeDocPath = desktopItem.getDocPath() or "" self.appKdeDocPath = desktopItem.getDocPath() or ""
@ -355,6 +356,9 @@ class ApplicationLauncher(easyButton):
except KeyError: except KeyError:
pass pass
if self.prefersOffload:
offload = True
Execute(None, desktopFile=self.desktopFile, offload=offload) Execute(None, desktopFile=self.desktopFile, offload=offload)
def uninstall(self, *args): def uninstall(self, *args):

View File

@ -1,7 +1,7 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os import os
from gi.repository import Gio, GLib, Gdk from gi.repository import Gio, GLib, Gdk, XApp
def RemoveArgs(Execline): def RemoveArgs(Execline):
@ -32,6 +32,17 @@ def Execute(cmd , commandCwd=None, desktopFile=None, offload=False):
if offload: if offload:
print("Offloading '%s' to discrete gpu." % launcher.get_name()); print("Offloading '%s' to discrete gpu." % launcher.get_name());
try:
helper = XApp.GpuOffloadHelper.get_sync()
infos = helper.get_offload_infos()
if infos:
i = 0
env_strv = infos[0].env_strv
while i < len(env_strv):
context.setenv(env_strv[i], env_strv[i + 1])
i += 2
except AttributeError:
context.setenv("__NV_PRIME_RENDER_OFFLOAD", "1") context.setenv("__NV_PRIME_RENDER_OFFLOAD", "1")
context.setenv("__GLX_VENDOR_LIBRARY_NAME", "nvidia"); context.setenv("__GLX_VENDOR_LIBRARY_NAME", "nvidia");