using System; using System.Linq; using NvAPIWrapper.GPU; using NvAPIWrapper.Native; using NvAPIWrapper.Native.Display; using NvAPIWrapper.Native.Display.Structures; using NvAPIWrapper.Native.Exceptions; using NvAPIWrapper.Native.GPU; using NvAPIWrapper.Native.Interfaces.Display; namespace NvAPIWrapper.Display { /// /// Represents an attached display /// public class Display : IEquatable { /// /// Creates a new Display /// /// Handle of the display device public Display(DisplayHandle handle) { Handle = handle; } /// /// Creates a new Display /// /// Name of the display device public Display(string displayName) { Handle = DisplayApi.GetAssociatedNvidiaDisplayHandle(displayName); } /// /// Gets the corresponding Digital Vibrance Control information /// public DVCInformation DigitalVibranceControl { get => new DVCInformation(Handle); } /// /// Gets corresponding DisplayDevice based on display name /// public DisplayDevice DisplayDevice { get => new DisplayDevice(Name); } /// /// Gets display driver build title /// public string DriverBuildTitle { get => DisplayApi.GetDisplayDriverBuildTitle(Handle); } /// /// Gets display handle /// public DisplayHandle Handle { get; } /// /// Gets the display HDMI support information /// public IHDMISupportInfo HDMISupportInfo { get { var outputId = OutputId.Invalid; try { outputId = DisplayApi.GetAssociatedDisplayOutputId(Handle); } catch (NVIDIAApiException) { // ignore } return DisplayApi.GetHDMISupportInfo(Handle, outputId); } } /// /// Gets the corresponding HUE information /// public HUEInformation HUEControl { get => new HUEInformation(Handle); } /// /// Gets the driving logical GPU /// public LogicalGPU LogicalGPU { get => new LogicalGPU(GPUApi.GetLogicalGPUFromDisplay(Handle)); } /// /// Gets display name /// public string Name { get => DisplayApi.GetAssociatedNvidiaDisplayName(Handle); } /// /// Gets the connected GPU output /// public GPUOutput Output { get => new GPUOutput(DisplayApi.GetAssociatedDisplayOutputId(Handle), PhysicalGPUs.FirstOrDefault()); } /// /// Gets the list of all physical GPUs responsible for this display, with the first GPU returned as the one with the /// attached active output. /// public PhysicalGPU[] PhysicalGPUs { get => GPUApi.GetPhysicalGPUsFromDisplay(Handle).Select(handle => new PhysicalGPU(handle)).ToArray(); } /// public bool Equals(Display other) { if (ReferenceEquals(null, other)) { return false; } if (ReferenceEquals(this, other)) { return true; } return Handle.Equals(other.Handle); } /// /// This function returns all NVIDIA displays /// Note: Display handles can get invalidated on a modeset. /// /// An array of Display objects public static Display[] GetDisplays() { return DisplayApi.EnumNvidiaDisplayHandle().Select(handle => new Display(handle)).ToArray(); } /// /// Checks for equality between two objects of same type /// /// The first object /// The second object /// true, if both objects are equal, otherwise false public static bool operator ==(Display left, Display right) { return right?.Equals(left) ?? ReferenceEquals(left, null); } /// /// Checks for inequality between two objects of same type /// /// The first object /// The second object /// true, if both objects are not equal, otherwise false public static bool operator !=(Display left, Display right) { return !(right == left); } /// public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) { return false; } if (ReferenceEquals(this, obj)) { return true; } if (obj.GetType() != GetType()) { return false; } return Equals((Display) obj); } /// public override int GetHashCode() { return Handle.GetHashCode(); } /// public override string ToString() { return Name; } /// /// Gets all the supported NVIDIA display views (nView and Dualview modes) for this display. /// /// public TargetViewMode[] GetSupportedViews() { return DisplayApi.GetSupportedViews(Handle); } /// /// Overrides the refresh rate on this display. /// The new refresh rate can be applied right away or deferred to be applied with the next OS /// mode-set. /// The override is good for only one mode-set (regardless whether it's deferred or immediate). /// /// The refresh rate to be applied. /// /// A boolean value indicating if the refresh rate override should be deferred to the next OS /// mode-set. /// public void OverrideRefreshRate(float refreshRate, bool isDeferred = false) { DisplayApi.SetRefreshRateOverride(Handle, refreshRate, isDeferred); } } }