/// <summary>
        /// Retrieves the singleton instance of AdapterIdMapper.
        /// </summary>
        /// <returns>The singleton instance of AdapterIdMapper.</returns>
        public static AdapterIdMapper GetAdapterIdMapper()
        {
            if (mInstance == null)
            {
                mInstance = new AdapterIdMapper();
            }

            return(mInstance);
        }
示例#2
0
        /// <summary>
        /// Applies the supplied display preset to the system, and dynamically changes it.
        /// Throws if the settings failed to be applied.
        /// </summary>
        /// <param name="displayPreset">The display preset to apply.</param>
        static public void ApplyPreset(DisplayPreset displayPreset)
        {
            AdapterIdMapper.DisplayPresetAdapterIdValidation validationResult =
                AdapterIdMapper.GetAdapterIdMapper().ValidateDisplayPresetAdapterIds(displayPreset);

            // Copy to working arrays so that if we need to remap we don't affect the original
            // display preset data.
            CCD.DisplayConfigPathInfo[] pathInfoArrayToApply = new CCD.DisplayConfigPathInfo[displayPreset.PathInfoArray.Length];
            displayPreset.PathInfoArray.CopyTo(pathInfoArrayToApply, 0);

            CCD.DisplayConfigModeInfo[] modeInfoArrayToApply = new CCD.DisplayConfigModeInfo[displayPreset.ModeInfoArray.Length];
            displayPreset.ModeInfoArray.CopyTo(modeInfoArrayToApply, 0);

            if (validationResult == AdapterIdMapper.DisplayPresetAdapterIdValidation.NeedAdapterIdRemap)
            {
                // TODO: The remap methods return a boolean, though it sorta doesn't matter for us since
                // we've already done validation. It's the right design that those methods return a
                // boolean, so maybe we should put an assert here?
                AdapterIdMapper.GetAdapterIdMapper().RemapDisplayConfigPathInfoAdapterIds(displayPreset, ref pathInfoArrayToApply);
                AdapterIdMapper.GetAdapterIdMapper().RemapDisplayConfigModeInfoAdapterIds(displayPreset, ref modeInfoArrayToApply);
            }
            else if (validationResult == AdapterIdMapper.DisplayPresetAdapterIdValidation.MissingAdapter)
            {
                // TODO: Have better interface for handling this case, cuz it's a real case where someone
                // upgrades a video card for example.
                throw new Exception("Missing adapter! Can't apply preset.");
            }
            else if (validationResult == AdapterIdMapper.DisplayPresetAdapterIdValidation.DisplayPresetMissingAdapterInformation)
            {
                // TODO: Handle this better, basically case where schema change
                throw new Exception("Display Preset is missing adapter name information.");
            }

            // Third validation result case is that all the adapter IDs are still valid and map correctly, so no action required.

            Win32Utilities.ThrowIfResultCodeNotSuccess(
                CCD.SetDisplayConfig(
                    (uint)pathInfoArrayToApply.Length,
                    pathInfoArrayToApply,
                    (uint)modeInfoArrayToApply.Length,
                    modeInfoArrayToApply,
                    CCD.SdcFlags.Apply | CCD.SdcFlags.UseSuppliedDisplayConfig | CCD.SdcFlags.AllowChanges | CCD.SdcFlags.SaveToDatabase));
        }