diff -Nru nvidia-prime-0.6.2/debian/changelog nvidia-prime-0.6.2.1/debian/changelog --- nvidia-prime-0.6.2/debian/changelog 2014-03-31 15:15:00.000000000 +0000 +++ nvidia-prime-0.6.2.1/debian/changelog 2016-11-21 11:22:37.000000000 +0000 @@ -1,3 +1,15 @@ +nvidia-prime (0.6.2.1) trusty-proposed; urgency=medium + + * debian/postrm.in, prime-select: backport from yakkety's 0.8.4: + - Add support for EGL alternatives (LP: #1642662). + - Simplify the logic for enablement by getting rid of legacy code + that is only relevant to Ubuntu <= 12.04. This is now possible + thanks to the fact that we allow installing only one binary + driver at the time. + - Do not try to remove the old xorg.conf. + + -- Alberto Milone Mon, 21 Nov 2016 12:17:54 +0100 + nvidia-prime (0.6.2) trusty; urgency=medium * prime-supported: diff -Nru nvidia-prime-0.6.2/debian/postrm.in nvidia-prime-0.6.2.1/debian/postrm.in --- nvidia-prime-0.6.2/debian/postrm.in 2014-03-04 15:27:12.000000000 +0000 +++ nvidia-prime-0.6.2.1/debian/postrm.in 2016-11-21 11:16:57.000000000 +0000 @@ -18,7 +18,6 @@ # for details, see http://www.debian.org/doc/debian-policy/ or # the debian-policy package -xorg_conf="#XORG_CONF#" now=$(date +"%m%d%Y") lightdm_orig_conf=#LIGHTDM_LEGACY_CONF_FILE# host_arch_main=#HOST_ARCH_MAIN# @@ -60,11 +59,6 @@ case "$1" in purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) - # Remove the xorg.conf - if [ -f $xorg_conf ]; then - mv $xorg_conf $xorg_conf.$now - fi - if [ ! "$1" = "upgrade" ]; then if [ "$os_release" = "precise" ]; then # Remove the display-setup-script line diff -Nru nvidia-prime-0.6.2/prime-select nvidia-prime-0.6.2.1/prime-select --- nvidia-prime-0.6.2/prime-select 2014-02-21 08:58:08.000000000 +0000 +++ nvidia-prime-0.6.2.1/prime-select 2016-11-21 11:16:57.000000000 +0000 @@ -137,15 +137,30 @@ self._power_profile_path = '/etc/prime-discrete' self._supported_architectures = {'i386': 'i386', 'amd64': 'x86_64'} main_arch = self._get_architecture() - other_arch = self._supported_architectures.values()[ + + self._needs_multiarch = (main_arch == 'x86_64') + + if self._needs_multiarch: + other_arch = self._supported_architectures.values()[ int(not self._supported_architectures .values().index(main_arch))] - main_alternative_name = self._get_alternative_name_from_arch(main_arch) - other_alternative_name = self._get_alternative_name_from_arch(other_arch) + other_gl_alternative_name = self._get_gl_alternative_name_from_arch(other_arch) + other_egl_alternative_name = self._get_egl_alternative_name_from_arch(other_arch) + # GL alternative for the other architecture + self._gl_switcher_other = Alternatives(other_gl_alternative_name) + # EGL alternative for the other architecture + self._egl_switcher_other = Alternatives(other_egl_alternative_name) + else: + self._gl_switcher_other = None + self._egl_switcher_other = None - # We have 2 alternatives, one for each architecture + main_alternative_name = self._get_gl_alternative_name_from_arch(main_arch) + main_egl_alternative_name = self._get_egl_alternative_name_from_arch(main_arch) + + # GL alternative for the main architecture self._gl_switcher = Alternatives(main_alternative_name) - self._gl_switcher_other = Alternatives(other_alternative_name) + # EGL alternative for the main architecture + self._egl_switcher = Alternatives(main_egl_alternative_name) def _get_architecture(self): dev_null = open('/dev/null', 'w') @@ -155,10 +170,14 @@ architecture = p.strip() return self._supported_architectures.get(architecture) - def _get_alternative_name_from_arch(self, architecture): + def _get_gl_alternative_name_from_arch(self, architecture): alternative = '%s-linux-gnu_gl_conf' % architecture return alternative + def _get_egl_alternative_name_from_arch(self, architecture): + alternative = '%s-linux-gnu_egl_conf' % architecture + return alternative + def _simplify_x_alternative_name(self, alternative): return alternative.split('/')[-1] @@ -169,67 +188,83 @@ raw_alternatives = self._gl_switcher.list_alternatives() return [ self._simplify_gl_alternative_name(x) for x in raw_alternatives ] + def _get_egl_alternatives_list(self): + raw_alternatives = self._egl_switcher.list_alternatives() + return [ self._simplify_gl_alternative_name(x) for x in raw_alternatives ] + def _update_initramfs(self): subprocess.call(['update-initramfs', '-u']) # This may not be necessary subprocess.call(['update-initramfs', '-u', '-k', os.uname()[2]]) - def _get_current_alternative(self): + def _get_current_alternative(self, switcher, switcher_other): # This is a list as the 2nd item belongs to another architecture alternatives = [None, None] - raw_gl_alternative = self._gl_switcher.get_current_alternative() - raw_gl_alternative_other = self._gl_switcher_other.get_current_alternative() + raw_alternative = switcher.get_current_alternative() - if (raw_gl_alternative != None): - alternatives[0] = self._simplify_gl_alternative_name(raw_gl_alternative) - if (raw_gl_alternative_other != None): - alternatives[1] = self._simplify_gl_alternative_name(raw_gl_alternative_other) + if (raw_alternative != None): + alternatives[0] = self._simplify_gl_alternative_name(raw_alternative) - return alternatives + if self._needs_multiarch: + raw_alternative_other = switcher_other.get_current_alternative() + if (raw_alternative_other != None): + alternatives[1] = self._simplify_gl_alternative_name(raw_alternative_other) - def _get_current_alternative_status(self): - '''Get the current status i.e. either "auto" or "manual"''' - # This is a list as the 2nd item belongs to another architecture - alternatives = [None, None] - raw_gl_alternative = self._gl_switcher.get_current_alternative(True) - raw_gl_alternative_other = self._gl_switcher_other.get_current_alternative(True) + return alternatives - if (raw_gl_alternative != None): - alternatives[0] = raw_gl_alternative - if (raw_gl_alternative_other != None): - alternatives[1] = raw_gl_alternative_other + def _get_current_gl_alternative(self): + return self._get_current_alternative(self._gl_switcher, self._gl_switcher_other) - return alternatives + def _get_current_egl_alternative(self): + return self._get_current_alternative(self._egl_switcher, self._egl_switcher_other) def enable_alternative(self, alternative): - # Make sure that the alternative exists + success = False + gl_success = False + egl_success = False + + # Make sure that the alternatives exist gl_alternative = self._gl_switcher.get_alternative_by_name(alternative) - gl_alternative_other = self._gl_switcher_other.get_alternative_by_name(alternative) + egl_alternative = self._egl_switcher.get_alternative_by_name(alternative) + + # See if the alternatives for the main arch are null + # Abort if they are both null + if gl_alternative: + gl_success = self._gl_switcher.set_alternative(gl_alternative) + + if egl_alternative: + egl_success = self._egl_switcher.set_alternative(egl_alternative) + + success = (gl_success or egl_success) - # See if they are null - # Abort if gl_alternative is null - if gl_alternative and gl_alternative_other: - success = (self._gl_switcher.set_alternative(gl_alternative) and - self._gl_switcher_other.set_alternative(gl_alternative_other)) + if not success: + sys.stderr.write("Error: no GL or EGL alternatives can be found for %s\n" % alternative) return success - else: - sys.stderr.write("Error: no alternative can be found for %s\n" % alternative) - return False + # Do not abort if they do not exist + if self._needs_multiarch: + gl_alternative_other = self._gl_switcher_other.get_alternative_by_name(alternative) + egl_alternative_other = self._egl_switcher_other.get_alternative_by_name(alternative) + + if gl_alternative_other: + self._gl_switcher_other.set_alternative(gl_alternative_other) + + if egl_alternative_other: + self._egl_switcher_other.set_alternative(egl_alternative_other) + + return success def print_current_alternative(self): - alternatives = self._get_current_alternative() - try: - alternative = str(alternatives[0]) - alternative_other = str(alternatives[1]) - except IndexError: - # No alternative exists + gl_alternatives = self._get_current_gl_alternative() + + gl_alternative = str(gl_alternatives[0]) + + if not gl_alternative: return False - if (alternative == alternative_other and - 'nvidia' in alternative): - if 'prime' in alternative: + if 'nvidia' in gl_alternative: + if 'prime' in gl_alternative: sys.stdout.write('intel\n') else: sys.stdout.write('nvidia\n') @@ -251,76 +286,78 @@ settings.write('%s\n' % nvidia_power) settings.close() + def _supports_prime(self): + '''See if there are alternatives that support PRIME''' + alternatives = self._get_gl_alternatives_list() + for alternative in alternatives: + if 'prime' in alternative: + return True + return False + + def _find_alternative_by_name(self, name, func, ignore_pattern=''): + alternatives = func() + + for alternative in alternatives: + if name in alternative: + if ignore_pattern and ignore_pattern in alternative: + continue + return alternative + return None + + def _find_gl_alternative_by_name(self, name, ignore_pattern=''): + '''Find the alternative name that matches a generic name pattern''' + return self._find_alternative_by_name(name, + self._get_gl_alternatives_list, + ignore_pattern=ignore_pattern) + + def _find_egl_alternative_by_name(self, name, ignore_pattern=''): + '''Find the alternative name that matches a generic name pattern''' + return self._find_alternative_by_name(name, + self._get_egl_alternatives_list, + ignore_pattern=ignore_pattern) def enable_profile(self, profile): current_driver = '' current_profile = '' - alternatives = self._get_current_alternative() + gl_alternatives = self._get_current_gl_alternative() + egl_alternatives = self._get_current_egl_alternative() - try: - alternative = str(alternatives[0]) - alternative_other = str(alternatives[1]) - except IndexError: + sys.stdout.write('Info: the current GL alternatives in use are: %s\n' % str(gl_alternatives)) + sys.stdout.write('Info: the current EGL alternatives in use are: %s\n' % str(egl_alternatives)) + + # Make sure that the installed packages support PRIME + if not self._supports_prime(): + sys.stderr.write('Error: the installed packages do not support PRIME\n') + return False + + gl_alternative = str(gl_alternatives[0]) + egl_alternative = str(egl_alternatives[0]) + + if not (gl_alternative or egl_alternative): # No alternative exists sys.stderr.write('Error: the required alternatives do not exist\n') return False - # The alternatives we are looking for are both provided by - # an nvidia package - if (alternative == alternative_other and - 'nvidia' in alternative): - # The driver in use - current_driver = alternative - # The profile in use - if 'prime' in alternative: - current_profile = 'intel' - else: - current_profile = 'nvidia' - # Check that the alternative for the intel profile - # exists. If it doesn't, then the driver does not - # support power management with PRIME - alt_driver = '%s-prime' % current_driver - if (not self._gl_switcher.get_alternative_by_name(alt_driver) or - not self._gl_switcher_other.get_alternative_by_name(alt_driver)): - sys.stderr.write('Error: %s does not support PRIME power management\n') - return False - - # Are alternatives in "auto" or in "manual" mode? - status = self._get_current_alternative_status() - + if ((profile == 'intel' and 'prime' in gl_alternative) or + (profile == 'nvidia' and 'prime' not in gl_alternative and + 'nvidia' in gl_alternative)): # No need to do anything if we're already using the desired - # profile, provided that alternatives are not in "auto" mode - if profile == current_profile and 'auto' not in status: - sys.stdout.write('Info: the %s profile is already in use\n' % (profile)) - return True - elif (alternative != alternative_other and - 'nvidia' in alternative): - # Something's wrong here - # e.g. nvidia-319 on x86_64 and mesa on i386 - sys.stdout.write('Info: the alternatives do not match\n') - # The first alternative shows the driver in use - current_driver = alternative - - if 'prime' not in alternative: - # Check that the alternative for the intel profile - # exists. If it doesn't, then the driver does not - # support power management with PRIME - alt_driver = '%s-prime' % current_driver - if (not self._gl_switcher.get_alternative_by_name(alt_driver) or - not self._gl_switcher_other.get_alternative_by_name(alt_driver)): - sys.stderr.write('Error: %s does not support PRIME power management\n') - return False - else: - sys.stderr.write('Error: alternatives are not set up properly\n') - return False + # profile + sys.stdout.write('Info: the %s profile is already in use\n' % (profile)) + return True # Enable the desired alternative if profile == 'intel': - target_driver = '%s-prime' % current_driver + target_gl_driver = self._find_gl_alternative_by_name('prime') else: - target_driver = current_driver.replace('-prime', '') + # Make sure to get nvidia-$flavour instead of nvidia-$flavour-prime + target_gl_driver = self._find_gl_alternative_by_name('nvidia', ignore_pattern='prime') + + sys.stdout.write('Info: selecting %s for the %s profile\n' % (target_gl_driver, profile)) - if self.enable_alternative(target_driver): + # We only care about the gl_driver because the egl will have + # the same name + if self.enable_alternative(target_gl_driver): # Write the settings to the config file self._write_profile(profile) return True