using System;
using System.Runtime.InteropServices;
using NvAPIWrapper.Native.Helpers;
namespace NvAPIWrapper.Native.Display.Structures
{
///
/// Holds information about a source mode
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct SourceModeInfo : IEquatable
{
internal readonly Resolution _Resolution;
internal readonly ColorFormat _ColorFormat;
internal readonly Position _Position;
internal readonly SpanningOrientation _SpanningOrientation;
internal uint _RawReserved;
///
/// Creates a new SourceModeInfo
///
/// Source resolution
/// Must be Format.Unknown
/// Source position
/// Spanning orientation for XP
/// true if this source represents the GDI primary display, otherwise false
/// true if this source represents the SLI focus display, otherwise false
public SourceModeInfo(
Resolution resolution,
ColorFormat colorFormat,
Position position = default(Position),
SpanningOrientation spanningOrientation = SpanningOrientation.None,
bool isGDIPrimary = false,
bool isSLIFocus = false) : this()
{
_Resolution = resolution;
_ColorFormat = colorFormat;
_Position = position;
_SpanningOrientation = spanningOrientation;
IsGDIPrimary = isGDIPrimary;
IsSLIFocus = isSLIFocus;
}
///
public bool Equals(SourceModeInfo other)
{
return _Resolution.Equals(other._Resolution) &&
_ColorFormat == other._ColorFormat &&
_Position.Equals(other._Position) &&
_SpanningOrientation == other._SpanningOrientation &&
_RawReserved == other._RawReserved;
}
///
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
return obj is SourceModeInfo info && Equals(info);
}
///
public override int GetHashCode()
{
unchecked
{
var hashCode = _Resolution.GetHashCode();
hashCode = (hashCode * 397) ^ (int) _ColorFormat;
hashCode = (hashCode * 397) ^ _Position.GetHashCode();
hashCode = (hashCode * 397) ^ (int) _SpanningOrientation;
// ReSharper disable once NonReadonlyMemberInGetHashCode
hashCode = (hashCode * 397) ^ (int) _RawReserved;
return hashCode;
}
}
///
public override string ToString()
{
return $"{Resolution} @ {Position} - {ColorFormat}";
}
///
/// Holds the source resolution
///
public Resolution Resolution
{
get => _Resolution;
}
///
/// Ignored at present, must be Format.Unknown
///
public ColorFormat ColorFormat
{
get => _ColorFormat;
}
///
/// Is all positions are 0 or invalid, displays will be automatically positioned from left to right with GDI Primary at
/// 0,0, and all other displays in the order of the path array.
///
public Position Position
{
get => _Position;
}
///
/// Spanning is only supported on XP
///
public SpanningOrientation SpanningOrientation
{
get => _SpanningOrientation;
}
///
/// Indicates if the path is for the primary GDI display
///
public bool IsGDIPrimary
{
get => _RawReserved.GetBit(0);
private set => _RawReserved = _RawReserved.SetBit(0, value);
}
///
/// Indicates if the path is for the SLI focus display
///
public bool IsSLIFocus
{
get => _RawReserved.GetBit(1);
private set => _RawReserved = _RawReserved.SetBit(1, value);
}
}
}