using System;
using System.Runtime.InteropServices;
using NvAPIWrapper.Native.Helpers;
using NvAPIWrapper.Native.Helpers.Structures;
using NvAPIWrapper.Native.Interfaces;
using NvAPIWrapper.Native.Interfaces.Display;
// ReSharper disable RedundantExtendsListEntry
namespace NvAPIWrapper.Native.Display.Structures
{
///
/// Holds information about a path's target
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct PathTargetInfoV2 : IPathTargetInfo,
IInitializable,
IDisposable,
IAllocatable,
IEquatable,
IEquatable
{
internal readonly uint _DisplayId;
internal ValueTypeReference _Details;
internal readonly uint _WindowsCCDTargetId;
///
public uint DisplayId
{
get => _DisplayId;
}
///
public override string ToString()
{
return $"PathTargetInfoV2: Display #{_DisplayId}";
}
///
public PathAdvancedTargetInfo? Details
{
get => _Details.ToValueType();
}
///
/// Windows CCD target ID. Must be present only for non-NVIDIA adapter, for NVIDIA adapter this parameter is ignored.
///
public uint WindowsCCDTargetId
{
get => _WindowsCCDTargetId;
}
///
/// Creates a new PathTargetInfoV1
///
/// Display Id
public PathTargetInfoV2(uint displayId) : this()
{
_DisplayId = displayId;
}
///
public bool Equals(PathTargetInfoV2 other)
{
return _DisplayId == other._DisplayId && _Details.Equals(other._Details);
}
///
public bool Equals(PathTargetInfoV1 other)
{
return _DisplayId == other._DisplayId && _Details.Equals(other._Details);
}
///
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is PathTargetInfoV2 v2 && Equals(v2);
}
///
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) _DisplayId;
// ReSharper disable once NonReadonlyMemberInGetHashCode
hashCode = (hashCode * 397) ^ _Details.GetHashCode();
hashCode = (hashCode * 397) ^ (int) _WindowsCCDTargetId;
return hashCode;
}
}
///
/// Creates a new PathTargetInfoV1
///
/// Display Id
/// Windows CCD target Id
public PathTargetInfoV2(uint displayId, uint windowsCCDTargetId) : this(displayId)
{
_WindowsCCDTargetId = windowsCCDTargetId;
}
///
/// Creates a new PathTargetInfoV1
///
/// Display Id
/// Extra information
public PathTargetInfoV2(uint displayId, PathAdvancedTargetInfo details) : this(displayId)
{
_Details = ValueTypeReference.FromValueType(details);
}
///
/// Creates a new PathTargetInfoV1
///
/// Display Id
/// Windows CCD target Id
/// Extra information
public PathTargetInfoV2(uint displayId, uint windowsCCDTargetId, PathAdvancedTargetInfo details)
: this(displayId, windowsCCDTargetId)
{
_Details = ValueTypeReference.FromValueType(details);
}
///
public void Dispose()
{
_Details.Dispose();
}
void IAllocatable.Allocate()
{
if (_Details.IsNull)
{
var detail = typeof(PathAdvancedTargetInfo).Instantiate();
_Details = ValueTypeReference.FromValueType(detail);
}
}
}
}