using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using NvAPIWrapper.Native.Attributes;
using NvAPIWrapper.Native.General.Structures;
using NvAPIWrapper.Native.Helpers;
using NvAPIWrapper.Native.Helpers.Structures;
using NvAPIWrapper.Native.Interfaces;
using NvAPIWrapper.Native.Interfaces.Display;
namespace NvAPIWrapper.Native.Display.Structures
{
///
/// Holds information about a path
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
[StructureVersion(2)]
// ReSharper disable once RedundantExtendsListEntry
public struct PathInfoV2 : IPathInfo, IInitializable, IAllocatable, IEquatable
{
internal StructureVersion _Version;
internal readonly uint _SourceId;
internal readonly uint _TargetInfoCount;
internal ValueTypeArray _TargetsInfo;
internal ValueTypeReference _SourceModeInfo;
internal readonly uint _RawReserved;
internal ValueTypeReference _OSAdapterLUID;
///
public uint SourceId
{
get => _SourceId;
}
///
public bool Equals(PathInfoV2 other)
{
return _TargetInfoCount == other._TargetInfoCount &&
_TargetsInfo.Equals(other._TargetsInfo) &&
_SourceModeInfo.Equals(other._SourceModeInfo) &&
_RawReserved == other._RawReserved;
}
///
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is PathInfoV2 v2 && Equals(v2);
}
///
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) _TargetInfoCount;
// ReSharper disable once NonReadonlyMemberInGetHashCode
hashCode = (hashCode * 397) ^ _TargetsInfo.GetHashCode();
// ReSharper disable once NonReadonlyMemberInGetHashCode
hashCode = (hashCode * 397) ^ _SourceModeInfo.GetHashCode();
hashCode = (hashCode * 397) ^ (int) _RawReserved;
return hashCode;
}
}
///
public IEnumerable TargetsInfo
{
get => _TargetsInfo.ToArray((int) _TargetInfoCount)?.Cast() ?? new IPathTargetInfo[0];
}
///
public SourceModeInfo SourceModeInfo
{
get => _SourceModeInfo.ToValueType() ?? default(SourceModeInfo);
}
///
/// True for non-NVIDIA adapter.
///
public bool IsNonNVIDIAAdapter
{
get => _RawReserved.GetBit(0);
}
///
/// Used by Non-NVIDIA adapter for OS Adapter of LUID
///
public LUID? OSAdapterLUID
{
get => _OSAdapterLUID.ToValueType();
}
///
/// Creates a new PathInfoV2
///
/// Information about path targets
/// Source mode information
/// Source Id, can be zero
public PathInfoV2(PathTargetInfoV2[] targetInformations, SourceModeInfo sourceModeInfo, uint sourceId = 0)
{
this = typeof(PathInfoV2).Instantiate();
_TargetInfoCount = (uint) targetInformations.Length;
_TargetsInfo = ValueTypeArray.FromArray(targetInformations);
_SourceModeInfo = ValueTypeReference.FromValueType(sourceModeInfo);
_SourceId = sourceId;
}
///
/// Creates a new PathInfoV2
///
/// Information about path targets
/// Source Id, can be zero
public PathInfoV2(PathTargetInfoV2[] targetInformations, uint sourceId = 0)
{
this = typeof(PathInfoV2).Instantiate();
_TargetInfoCount = (uint) targetInformations.Length;
_TargetsInfo = ValueTypeArray.FromArray(targetInformations);
_SourceModeInfo = ValueTypeReference.Null;
_SourceId = sourceId;
}
///
/// Creates a new PathInfoV2
///
/// Source Id, can be zero
public PathInfoV2(uint sourceId)
{
this = typeof(PathInfoV2).Instantiate();
_TargetInfoCount = 0;
_TargetsInfo = ValueTypeArray.Null;
_SourceModeInfo = ValueTypeReference.Null;
_SourceId = sourceId;
}
///
/// Creates a new PathInfoV2
///
/// Source mode information
/// Source Id, can be zero
public PathInfoV2(SourceModeInfo sourceModeInfo, uint sourceId)
{
this = typeof(PathInfoV2).Instantiate();
_TargetInfoCount = 0;
_TargetsInfo = ValueTypeArray.Null;
_SourceModeInfo = ValueTypeReference.FromValueType(sourceModeInfo);
_SourceId = sourceId;
}
///
public void Dispose()
{
TargetsInfo.DisposeAll();
_TargetsInfo.Dispose();
_SourceModeInfo.Dispose();
}
void IAllocatable.Allocate()
{
if (_TargetInfoCount > 0 && _TargetsInfo.IsNull)
{
var targetInfo = typeof(PathTargetInfoV2).Instantiate();
var targetInfoList = targetInfo.Repeat((int) _TargetInfoCount).AllocateAll();
_TargetsInfo = ValueTypeArray.FromArray(targetInfoList.ToArray());
}
if (_SourceModeInfo.IsNull)
{
var sourceModeInfo = typeof(SourceModeInfo).Instantiate();
_SourceModeInfo = ValueTypeReference.FromValueType(sourceModeInfo);
}
}
}
}