From f72fc6feea1b6b9bdee62f28b5f92ad452a6dda8 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Sun, 31 Oct 2021 12:50:57 +1300 Subject: [PATCH] Attempted to reduce the number of video card library calls Found some calls that were bypassing the video library state buffering I'd put in place earlier. This should generally make DisplayMagician faster and minimise the number of log entries written to DisplayMagician.log. --- DisplayMagicianShared/ProfileItem.cs | 6 ++++-- DisplayMagicianShared/ProfileRepository.cs | 15 +++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/DisplayMagicianShared/ProfileItem.cs b/DisplayMagicianShared/ProfileItem.cs index 5d691f6..c63820d 100644 --- a/DisplayMagicianShared/ProfileItem.cs +++ b/DisplayMagicianShared/ProfileItem.cs @@ -454,10 +454,11 @@ namespace DisplayMagicianShared public virtual bool PreSave() { // Prepare our profile data for saving - if (_profileDisplayIdentifiers.Count == 0) + // Disabling as this should never happen now + /*if (_profileDisplayIdentifiers.Count == 0) { _profileDisplayIdentifiers = ProfileRepository.GetCurrentDisplayIdentifiers(); - } + }*/ // Return if it is valid and we should continue return IsValid(); @@ -638,6 +639,7 @@ namespace DisplayMagicianShared } else { + SharedLogger.logger.Warn($"ProfileRepository/IsPossibleRefresh: We have a current video mode we don't understand, or it's not installed! The current video mode is {ProfileRepository.CurrentVideoMode}. The profile {Name} has a {VideoMode.ToString("G")} video mode and NVIDIALibrary IsInstalled is {NVIDIALibrary.GetLibrary().IsInstalled}, AMDLibrary IsInstalled is {AMDLibrary.GetLibrary().IsInstalled} and WinLibrary IsInstalled is {WinLibrary.GetLibrary().IsInstalled} "); _isPossible = false; } } diff --git a/DisplayMagicianShared/ProfileRepository.cs b/DisplayMagicianShared/ProfileRepository.cs index 7305c97..b6794f4 100644 --- a/DisplayMagicianShared/ProfileRepository.cs +++ b/DisplayMagicianShared/ProfileRepository.cs @@ -769,7 +769,7 @@ namespace DisplayMagicianShared _profilesLoaded = true; // Update the current active profile - UpdateActiveProfile(); + //UpdateActiveProfile(); IsPossibleRefresh(); return true; @@ -998,7 +998,7 @@ namespace DisplayMagicianShared { // We need to refresh the cached answer // Get the list of connected devices - ConnectedDisplayIdentifiers = GetAllConnectedDisplayIdentifiers(); + //ConnectedDisplayIdentifiers = GetAllConnectedDisplayIdentifiers(); if (_profilesLoaded && _allProfiles.Count > 0) { @@ -1029,15 +1029,15 @@ namespace DisplayMagicianShared { if (_currentVideoMode == VIDEO_MODE.NVIDIA && NVIDIALibrary.GetLibrary().IsInstalled) { - return NVIDIALibrary.GetLibrary().GetCurrentDisplayIdentifiers(); + return NVIDIALibrary.GetLibrary().CurrentDisplayIdentifiers; } else if (_currentVideoMode == VIDEO_MODE.AMD && AMDLibrary.GetLibrary().IsInstalled) { - return AMDLibrary.GetLibrary().GetCurrentDisplayIdentifiers(); + return AMDLibrary.GetLibrary().CurrentDisplayIdentifiers; } else { - return WinLibrary.GetLibrary().GetCurrentDisplayIdentifiers(); + return WinLibrary.GetLibrary().CurrentDisplayIdentifiers; } } @@ -1143,14 +1143,13 @@ namespace DisplayMagicianShared if (wasDisplayChangeSuccessful) { result = "was successful"; + ProfileRepository.UpdateActiveProfile(); + } // Display the TimeSpan time and result. SharedLogger.logger.Debug($"ProfileRepository/ApplyProfile: Display change attempt took {ts.Minutes}:{ts.Seconds}.{ts.Milliseconds} and {result}."); } - - ProfileRepository.UpdateActiveProfile(); - return ApplyProfileResult.Successful; }