using System;
using System.Drawing;
using WindowsDisplayAPI.Native.DisplayConfig;
using WindowsDisplayAPI.Native.DisplayConfig.Structures;
namespace WindowsDisplayAPI.DisplayConfig
{
///
/// Contains information about the target signal info
///
public class PathTargetSignalInfo : IEquatable
{
///
/// Creates a new PathTargetSignalInfo
///
/// Specifies the width and height (in pixels) of the active portion of the video signal.
/// Specifies the width and height (in pixels) of the entire video signal.
/// Vertical synchronization frequency.
/// The scan-line ordering (for example, progressive or interlaced) of the video signal.
///
/// The video standard (if any) that defines the video signal. Supported by WDDM 1.3 and later
/// display mini-port drivers running on Windows 8.1 and later.
///
///
/// The ratio of the VSync rate of a monitor that displays through a Miracast
/// connected session to the VSync rate of the Miracast sink. The ratio of the VSync rate of a monitor that displays
/// through a Miracast connected session to the VSync rate of the Miracast sink. Supported by WDDM 1.3 and later
/// display mini-port drivers running on Windows 8.1 and later.
///
public PathTargetSignalInfo(
Size activeSize,
Size totalSize,
ulong verticalSyncFrequencyInMillihertz,
DisplayConfigScanLineOrdering scanLineOrdering,
VideoSignalStandard videoStandard = VideoSignalStandard.Uninitialized,
ushort verticalSyncFrequencyDivider = 0
)
{
ActiveSize = activeSize;
ScanLineOrdering = scanLineOrdering;
TotalSize = totalSize;
VerticalSyncFrequencyDivider = verticalSyncFrequencyDivider;
VerticalSyncFrequencyInMillihertz = verticalSyncFrequencyInMillihertz;
VideoStandard = videoStandard;
PixelRate = (ulong) (verticalSyncFrequencyInMillihertz / 1000d * totalSize.Width * totalSize.Height);
HorizontalSyncFrequencyInMillihertz = (ulong) totalSize.Height * verticalSyncFrequencyInMillihertz;
}
///
/// Creates a new PathTargetSignalInfo
///
/// A possible display settings
/// Total signal size
public PathTargetSignalInfo(DisplayPossibleSetting displaySetting, Size totalSignalSize) :
this(
displaySetting.Resolution, totalSignalSize,
(uint) (displaySetting.Frequency * 1000),
displaySetting.IsInterlaced
? DisplayConfigScanLineOrdering.InterlacedWithUpperFieldFirst
: DisplayConfigScanLineOrdering.Progressive
)
{
}
internal PathTargetSignalInfo(DisplayConfigVideoSignalInfo signalInfo)
{
PixelRate = signalInfo.PixelRate;
HorizontalSyncFrequencyInMillihertz = signalInfo.HorizontalSyncFrequency.ToValue(1000);
VerticalSyncFrequencyInMillihertz = signalInfo.VerticalSyncFrequency.ToValue(1000);
ActiveSize = new Size((int) signalInfo.ActiveSize.Width, (int) signalInfo.ActiveSize.Height);
TotalSize = new Size((int) signalInfo.TotalSize.Width, (int) signalInfo.TotalSize.Height);
VideoStandard = signalInfo.VideoStandard;
VerticalSyncFrequencyDivider = signalInfo.VerticalSyncFrequencyDivider;
ScanLineOrdering = signalInfo.ScanLineOrdering;
}
///
/// Gets the width and height (in pixels) of the active portion of the video signal
///
public Size ActiveSize { get; }
///
/// Gets the horizontal synchronization frequency
///
public ulong HorizontalSyncFrequencyInMillihertz { get; }
///
/// Gets the pixel clock rate
///
public ulong PixelRate { get; }
///
/// Gets the scan-line ordering (for example, progressive or interlaced) of the video signal
///
public DisplayConfigScanLineOrdering ScanLineOrdering { get; }
///
/// Gets the width and height (in pixels) of the entire video signal
///
public Size TotalSize { get; }
///
/// Gets the ratio of the VSync rate of a monitor that displays through a Miracast connected session to the VSync rate
/// of the Miracast sink. The ratio of the VSync rate of a monitor that displays through a Miracast connected session
/// to the VSync rate of the Miracast sink. Supported by WDDM 1.3 and later display mini-port drivers running on Windows
/// 8.1 and later
///
public ushort VerticalSyncFrequencyDivider { get; }
///
/// Gets the vertical synchronization frequency
///
public ulong VerticalSyncFrequencyInMillihertz { get; }
///
/// Gets the video standard (if any) that defines the video signal. Supported by WDDM 1.3 and later display mini-port
/// drivers running on Windows 8.1 and later
///
public VideoSignalStandard VideoStandard { get; }
///
public bool Equals(PathTargetSignalInfo other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return ActiveSize == other.ActiveSize &&
HorizontalSyncFrequencyInMillihertz == other.HorizontalSyncFrequencyInMillihertz &&
PixelRate == other.PixelRate &&
ScanLineOrdering == other.ScanLineOrdering &&
TotalSize == other.TotalSize &&
VerticalSyncFrequencyDivider == other.VerticalSyncFrequencyDivider &&
VerticalSyncFrequencyInMillihertz == other.VerticalSyncFrequencyInMillihertz &&
VideoStandard == other.VideoStandard;
}
///
/// Checks for equality of two PathTargetSignalInfo instances
///
/// The first instance
/// The second instance
/// true if both instances are equal, otherwise false
public static bool operator ==(PathTargetSignalInfo left, PathTargetSignalInfo right)
{
return Equals(left, right) || left?.Equals(right) == true;
}
///
/// Checks for inequality of two PathTargetSignalInfo instances
///
/// The first instance
/// The second instance
/// true if both instances are not equal, otherwise false
public static bool operator !=(PathTargetSignalInfo left, PathTargetSignalInfo right)
{
return !(left == right);
}
///
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
return obj.GetType() == GetType() && Equals((PathTargetSignalInfo) obj);
}
///
public override int GetHashCode()
{
unchecked
{
var hashCode = ActiveSize.GetHashCode();
hashCode = (hashCode * 397) ^ (int) HorizontalSyncFrequencyInMillihertz;
hashCode = (hashCode * 397) ^ PixelRate.GetHashCode();
hashCode = (hashCode * 397) ^ (int) ScanLineOrdering;
hashCode = (hashCode * 397) ^ TotalSize.GetHashCode();
hashCode = (hashCode * 397) ^ VerticalSyncFrequencyDivider.GetHashCode();
hashCode = (hashCode * 397) ^ (int) VerticalSyncFrequencyInMillihertz;
hashCode = (hashCode * 397) ^ (int) VideoStandard;
return hashCode;
}
}
///
public override string ToString()
{
return $"{ActiveSize} @ {VerticalSyncFrequencyInMillihertz / 1000}hz {VideoStandard}";
}
internal DisplayConfigVideoSignalInfo GetDisplayConfigVideoSignalInfo()
{
return new DisplayConfigVideoSignalInfo(
PixelRate,
new DisplayConfigRational(HorizontalSyncFrequencyInMillihertz, 1000, true),
new DisplayConfigRational(VerticalSyncFrequencyInMillihertz, 1000, true),
new DisplayConfig2DRegion((uint) ActiveSize.Width, (uint) ActiveSize.Height),
new DisplayConfig2DRegion((uint) TotalSize.Width, (uint) TotalSize.Height),
VideoStandard,
VerticalSyncFrequencyDivider,
ScanLineOrdering
);
}
}
}