Esempio n. 1
0
        /// <summary>
        ///     Applies one or more path information configurations
        /// </summary>
        /// <param name="pathInfos">An array of path information configuration</param>
        /// <param name="flags">DisplayConfigFlags flags</param>
        public static void SetDisplaysConfig(PathInfo[] pathInfos, DisplayConfigFlags flags)
        {
            try
            {
                var configsV2 = pathInfos.Select(config => config.GetPathInfoV2()).Cast <IPathInfo>().ToArray();
                DisplayApi.SetDisplayConfig(configsV2, flags);
                configsV2.DisposeAll();
            }
            catch (NVIDIAApiException ex)
            {
                if (ex.Status != Status.IncompatibleStructureVersion)
                {
                    throw;
                }
            }
            catch (NVIDIANotSupportedException)
            {
                // ignore
            }

            var configsV1 = pathInfos.Select(config => config.GetPathInfoV1()).Cast <IPathInfo>().ToArray();

            DisplayApi.SetDisplayConfig(configsV1, flags);
            configsV1.DisposeAll();
        }
Esempio n. 2
0
        /// <summary>
        ///     This API lets caller apply a global display configuration across multiple GPUs.
        ///     If all sourceIds are zero, then NvAPI will pick up sourceId's based on the following criteria :
        ///     - If user provides SourceModeInfo then we are trying to assign 0th SourceId always to GDIPrimary.
        ///     This is needed since active windows always moves along with 0th sourceId.
        ///     - For rest of the paths, we are incrementally assigning the SourceId per adapter basis.
        ///     - If user doesn't provide SourceModeInfo then NVAPI just picks up some default SourceId's in incremental order.
        ///     Note : NVAPI will not intelligently choose the SourceIDs for any configs that does not need a modeset.
        /// </summary>
        /// <param name="pathInfos">Array of path information</param>
        /// <param name="flags">Flags for applying settings</param>
        /// <exception cref="NVIDIANotSupportedException">This operation is not supported.</exception>
        /// <exception cref="NVIDIAApiException">Status.ApiNotInitialized: NVAPI not initialized</exception>
        /// <exception cref="NVIDIAApiException">Status.Error: Miscellaneous error occurred</exception>
        /// <exception cref="NVIDIAApiException">Status.InvalidArgument: Invalid input parameter.</exception>
        public static void SetDisplayConfig(IPathInfo[] pathInfos, DisplayConfigFlags flags)
        {
            var setDisplayConfig = DelegateFactory.Get <Delegates.Display.NvAPI_DISP_SetDisplayConfig>();

            if ((pathInfos.Length > 0) && !setDisplayConfig.Accepts().Contains(pathInfos[0].GetType()))
            {
                throw new NVIDIANotSupportedException("This operation is not supported.");
            }
            using (var arrayReference = ValueTypeArray.FromArray(pathInfos.Cast <object>()))
            {
                var status = setDisplayConfig((uint)pathInfos.Length, arrayReference, flags);
                if (status != Status.Ok)
                {
                    throw new NVIDIAApiException(status);
                }
            }
        }