using System;
using System.Runtime.InteropServices;
using NvAPIWrapper.Native.Helpers;
using NvAPIWrapper.Native.Interfaces;
namespace NvAPIWrapper.Native.Display.Structures
{
///
/// Holds NVIDIA-specific timing extras
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct TimingExtra : IInitializable, IEquatable
{
internal readonly uint _HardwareFlags;
internal readonly ushort _RefreshRate;
internal readonly uint _FrequencyInMillihertz;
internal readonly ushort _VerticalAspect;
internal readonly ushort _HorizontalAspect;
internal readonly ushort _HorizontalPixelRepetition;
internal readonly uint _Standard;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
internal string _Name;
///
/// Creates a new instance of structure.
///
/// The timing frequency in hertz
/// The timing source name
/// The display horizontal aspect
/// The display vertical aspect
/// The number of identical horizontal pixels that are repeated; 1 = no repetition
/// The NVIDIA hardware-based enhancement, such as double-scan.
public TimingExtra(
double frequencyInHertz,
string name,
ushort horizontalAspect = 0,
ushort verticalAspect = 0,
ushort horizontalPixelRepetition = 1,
uint hardwareFlags = 0
) : this(
(uint) (frequencyInHertz * 1000d),
(ushort) frequencyInHertz,
name,
horizontalAspect,
verticalAspect,
horizontalPixelRepetition,
hardwareFlags
)
{
}
///
/// Creates a new instance of structure.
///
/// The timing frequency in millihertz
/// The refresh rate
/// The timing source name
/// The display horizontal aspect
/// The display vertical aspect
/// The number of identical horizontal pixels that are repeated; 1 = no repetition
/// The NVIDIA hardware-based enhancement, such as double-scan.
public TimingExtra(
uint frequencyInMillihertz,
ushort refreshRate,
string name,
ushort horizontalAspect = 0,
ushort verticalAspect = 0,
ushort horizontalPixelRepetition = 1,
uint hardwareFlags = 0
)
{
this = typeof(TimingExtra).Instantiate();
_FrequencyInMillihertz = frequencyInMillihertz;
_RefreshRate = refreshRate;
_HorizontalAspect = horizontalAspect;
_VerticalAspect = verticalAspect;
_HorizontalPixelRepetition = horizontalPixelRepetition;
_HardwareFlags = hardwareFlags;
_Name = name?.Length > 40 ? name.Substring(0, 40) : name ?? "";
}
///
public bool Equals(TimingExtra other)
{
return _HardwareFlags == other._HardwareFlags &&
_RefreshRate == other._RefreshRate &&
_FrequencyInMillihertz == other._FrequencyInMillihertz &&
_VerticalAspect == other._VerticalAspect &&
_HorizontalAspect == other._HorizontalAspect &&
_HorizontalPixelRepetition == other._HorizontalPixelRepetition &&
_Standard == other._Standard;
}
///
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is TimingExtra extra && Equals(extra);
}
///
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) _HardwareFlags;
hashCode = (hashCode * 397) ^ _RefreshRate.GetHashCode();
hashCode = (hashCode * 397) ^ (int) _FrequencyInMillihertz;
hashCode = (hashCode * 397) ^ _VerticalAspect.GetHashCode();
hashCode = (hashCode * 397) ^ _HorizontalAspect.GetHashCode();
hashCode = (hashCode * 397) ^ _HorizontalPixelRepetition.GetHashCode();
hashCode = (hashCode * 397) ^ (int) _Standard;
return hashCode;
}
}
///
/// Gets the NVIDIA hardware-based enhancement, such as double-scan.
///
public uint HardwareFlags
{
get => _HardwareFlags;
}
///
/// Gets the logical refresh rate to present
///
public int RefreshRate
{
get => _RefreshRate;
}
///
/// Gets the physical vertical refresh rate in 0.001Hz
///
public int FrequencyInMillihertz
{
get => (int) _FrequencyInMillihertz;
}
///
/// Gets the display vertical aspect
///
public int VerticalAspect
{
get => _VerticalAspect;
}
///
/// Gets the display horizontal aspect
///
public int HorizontalAspect
{
get => _HorizontalAspect;
}
///
/// Gets the bit-wise pixel repetition factor: 0x1:no pixel repetition; 0x2:each pixel repeats twice horizontally,..
///
public int PixelRepetition
{
get => _HorizontalPixelRepetition;
}
///
/// Gets the timing standard
///
public uint Standard
{
get => _Standard;
}
///
/// Gets the timing name
///
public string Name
{
get => _Name;
}
///
public override string ToString()
{
return Name;
}
///
/// Checks two instance of for equality.
///
/// The first instance.
/// The second instance.
/// Returns a boolean value indicating if the two instances are equal; otherwise false
public static bool operator ==(TimingExtra left, TimingExtra right)
{
return left.Equals(right);
}
///
/// Checks two instance of for equality.
///
/// The first instance.
/// The second instance.
/// Returns a boolean value indicating if the two instances are equal; otherwise false
public static bool operator !=(TimingExtra left, TimingExtra right)
{
return !(left == right);
}
}
}