Skip to content

Commit

Permalink
libvirt-machine: Offer option to disable 3D acceleration
Browse files Browse the repository at this point in the history
Unfortunately not all the hosts support 3D acceleration with the
current machinery we provide. Therefore VMs can become unusable
by enabling 3D acceleration.

We throw a notification for OSes that support 3D acceleration
offering the user to DISABLE it manually in case they want.
If the notification is dismissed, we assume the user is not
having any problems and therefore we don't show the notification
ever again.

A workaround in order to bring the notification back is to edit
the broker source file (usually $HOME/.config/gnome-boxes/sources/
QEMU\ Session) and change the "tweaked-accel3d" key from "true" to
"false".

See flathub/org.gnome.Boxes#15
  • Loading branch information
felipeborges committed Mar 15, 2019
1 parent 68a0fff commit 655800c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/box-config.vala
Expand Up @@ -37,6 +37,11 @@ public class Boxes.BoxConfig: GLib.Object, Boxes.IConfig {
set { keyfile.set_string_list (group, "categories", value); }
}

public bool tweaked_accel3d {
get { return get_boolean (group, "tweaked-accel3d", false); }
set { keyfile.set_boolean (group, "tweaked-accel3d", value); }
}

public int64 access_last_time { set; get; }
public int64 access_first_time { set; get; }
public int64 access_total_time { set; get; } // in seconds
Expand Down
77 changes: 77 additions & 0 deletions src/libvirt-machine.vala
Expand Up @@ -23,6 +23,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
update_status ();
}
}

// If this machine is currently being imported
public bool importing { get { return vm_creator != null && vm_creator is VMImporter; } }

Expand Down Expand Up @@ -615,6 +616,58 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
}
}
}

/* Some users might have issues with 3D acceleration due to various setups
* with different video drivers in the host. So we should offer an option
* to run these VMs without 3D acceleration.
*/
if (!config.tweaked_accel3d && yield supports_accel3d ()) {
Boxes.Notification notification = null;

Notification.OKFunc disable_accel3d = () => {
notification = null;

GLib.List<GVirConfig.DomainDevice> devices = null;
foreach (var device in domain_config.get_devices ()) {
if (device is GVirConfig.DomainGraphicsSpice) {
var graphics_device = VMConfigurator.create_graphics_device (false);

devices.prepend (graphics_device);
} else if (device is GVirConfig.DomainVideo) {
var video_device = device as GVirConfig.DomainVideo;

video_device.set_accel3d (false);
devices.prepend (device);
} else {
devices.prepend (device);
}
}

devices.reverse ();
domain_config.set_devices (devices);

try {
domain.set_config (domain_config);
config.tweaked_accel3d = true;
} catch (GLib.Error error) {
debug ("Failed to disable 3d acceleration!\n");
}

force_shutdown ();
};

Notification.DismissFunc dismiss_notification = () => {
notification = null;

config.tweaked_accel3d = true;
};

var message = _("Experiencing graphics problems?");
notification = window.notificationbar.display_for_action (message,
_("Disable 3D acceleration"),
(owned) disable_accel3d,
(owned) dismiss_notification);
}
}

public override void restart () {
Expand Down Expand Up @@ -722,6 +775,30 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
}
}

private async bool supports_accel3d () {
var os = yield get_os ();
if (os == null)
return false;

var devices = os.get_all_devices (null);

return (find_device_by_prop (devices, Osinfo.DEVICE_PROP_NAME, "virtio1.0-gpu") != null);
}

public async Osinfo.Os? get_os () {
var os_id = VMConfigurator.get_os_id (domain_config);
if (os_id == null)
return null;

var os_db = MediaManager.get_instance ().os_db;
try {
return yield os_db.get_os_by_id (os_id);
} catch (OSDatabaseError error) {
warning ("Failed to find OS with ID '%s': %s", os_id, error.message);
return null;
}
}

public string? get_ip_address () {
if (system_virt_connection == null || !is_on)
return null;
Expand Down

0 comments on commit 655800c

Please sign in to comment.