2013-03-17 17:06:52 -04:00
#
2013-10-27 21:59:46 +01:00
# Copyright 2009, 2013 Red Hat, Inc.
2013-03-17 17:06:52 -04:00
#
2018-04-04 14:35:41 +01:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 15:00:02 -04:00
# See the COPYING file in the top-level directory.
2013-03-17 17:06:52 -04:00
2018-03-20 12:18:35 -04:00
from . device import Device
2018-03-20 12:27:37 -04:00
from . . xmlbuilder import XMLProperty
2013-03-17 17:06:52 -04:00
2013-04-13 14:34:52 -04:00
2018-03-20 12:18:35 -04:00
class DeviceVideo ( Device ) :
2018-03-21 10:53:34 -04:00
XML_NAME = " video "
2013-03-17 17:06:52 -04:00
2018-09-06 14:43:45 -04:00
@staticmethod
def get_recommended_models ( guest ) :
if guest . conn . is_xen ( ) :
return [ " xen " , " vga " ]
if guest . conn . is_qemu ( ) or guest . conn . is_test ( ) :
return [ " vga " , " qxl " , " virtio " ]
return [ ]
2013-03-17 17:06:52 -04:00
@staticmethod
def pretty_model ( model ) :
2013-07-15 11:07:40 -04:00
if model in [ " qxl " , " vmvga " , " vga " ] :
2013-03-17 17:06:52 -04:00
return model . upper ( )
return model . capitalize ( )
2014-12-01 15:56:29 +01:00
_XML_PROP_ORDER = [ " model " , " vram " , " heads " , " vgamem " ]
2018-09-01 17:01:46 -04:00
model = XMLProperty ( " ./model/@type " )
2013-09-19 13:27:30 -04:00
vram = XMLProperty ( " ./model/@vram " , is_int = True )
2017-03-05 14:51:25 -05:00
vram64 = XMLProperty ( " ./model/@vram64 " , is_int = True )
2013-09-19 13:27:30 -04:00
ram = XMLProperty ( " ./model/@ram " , is_int = True )
heads = XMLProperty ( " ./model/@heads " , is_int = True )
2014-12-01 15:56:29 +01:00
vgamem = XMLProperty ( " ./model/@vgamem " , is_int = True )
2016-03-04 12:31:52 +01:00
accel3d = XMLProperty ( " ./model/acceleration/@accel3d " , is_yesno = True )
2018-09-01 17:01:46 -04:00
##################
# Default config #
##################
@staticmethod
def default_model ( guest ) :
if guest . os . is_pseries ( ) :
return " vga "
if guest . os . is_arm_machvirt ( ) :
return " virtio "
2018-12-13 16:39:43 -05:00
if guest . conn . is_qemu ( ) and guest . os . is_s390x ( ) :
return " virtio "
2018-09-01 17:01:46 -04:00
if guest . has_spice ( ) and guest . os . is_x86 ( ) :
if guest . has_gl ( ) :
return " virtio "
return " qxl "
if guest . os . is_hvm ( ) :
if guest . conn . is_qemu ( ) :
return " qxl "
return " vga "
return None
def set_defaults ( self , guest ) :
if not self . model :
self . model = self . default_model ( guest )
if self . model == ' virtio ' and guest . has_gl ( ) :
self . accel3d = True