2017-02-26 19:23:31 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using EDIDParser;
|
|
|
|
|
using EDIDParser.Descriptors;
|
|
|
|
|
using EDIDParser.Enums;
|
2018-10-20 00:19:30 +00:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Converters;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
using NvAPIWrapper.Mosaic;
|
|
|
|
|
|
|
|
|
|
namespace HeliosDisplayManagement.Shared.NVIDIA
|
|
|
|
|
{
|
|
|
|
|
public class SurroundTopologyDisplay : IEquatable<SurroundTopologyDisplay>
|
|
|
|
|
{
|
|
|
|
|
public SurroundTopologyDisplay(GridTopologyDisplay display)
|
|
|
|
|
{
|
|
|
|
|
DisplayId = display.DisplayDevice.DisplayId;
|
|
|
|
|
Rotation = display.Rotation.ToRotation();
|
|
|
|
|
Overlap = new Point(display.Overlap.HorizontalOverlap, display.Overlap.VerticalOverlap);
|
2018-10-20 00:19:30 +00:00
|
|
|
|
PixelShift = display.PixelShiftType.ToPixelShift();
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var bytes = display.DisplayDevice.PhysicalGPU.ReadEDIDData(display.DisplayDevice.Output);
|
|
|
|
|
DisplayName = new EDID(bytes).Descriptors
|
|
|
|
|
.Where(descriptor => descriptor is StringDescriptor)
|
|
|
|
|
.Cast<StringDescriptor>()
|
|
|
|
|
.FirstOrDefault(descriptor => descriptor.Type == StringDescriptorType.MonitorName)?.Value;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SurroundTopologyDisplay()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint DisplayId { get; set; }
|
|
|
|
|
|
|
|
|
|
public string DisplayName { get; set; }
|
|
|
|
|
|
|
|
|
|
public Point Overlap { get; set; }
|
2018-10-20 00:19:30 +00:00
|
|
|
|
|
|
|
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
|
|
|
|
public PixelShift PixelShift { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
2017-02-26 19:23:31 +00:00
|
|
|
|
public Rotation Rotation { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public bool Equals(SurroundTopologyDisplay other)
|
|
|
|
|
{
|
2018-10-20 00:27:25 +00:00
|
|
|
|
if (ReferenceEquals(null, other))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ReferenceEquals(this, other))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DisplayId == other.DisplayId &&
|
|
|
|
|
Overlap.Equals(other.Overlap) &&
|
|
|
|
|
PixelShift == other.PixelShift &&
|
|
|
|
|
Rotation == other.Rotation;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool operator ==(SurroundTopologyDisplay left, SurroundTopologyDisplay right)
|
|
|
|
|
{
|
2018-10-20 00:17:32 +00:00
|
|
|
|
return Equals(left, right) || left?.Equals(right) == true;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool operator !=(SurroundTopologyDisplay left, SurroundTopologyDisplay right)
|
|
|
|
|
{
|
2018-10-20 00:17:32 +00:00
|
|
|
|
return !(left == right);
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
2018-10-20 00:27:25 +00:00
|
|
|
|
if (ReferenceEquals(null, obj))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ReferenceEquals(this, obj))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (obj.GetType() != GetType())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
return Equals((SurroundTopologyDisplay) obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
unchecked
|
|
|
|
|
{
|
|
|
|
|
var hashCode = (int) DisplayId;
|
2018-10-20 00:27:25 +00:00
|
|
|
|
hashCode = (hashCode * 397) ^ Overlap.GetHashCode();
|
|
|
|
|
hashCode = (hashCode * 397) ^ (int) PixelShift;
|
|
|
|
|
hashCode = (hashCode * 397) ^ (int) Rotation;
|
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
return hashCode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return DisplayName ?? $"SurroundTopologyDisplay #{DisplayId}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GridTopologyDisplay ToGridTopologyDisplay()
|
|
|
|
|
{
|
|
|
|
|
return new GridTopologyDisplay(DisplayId, new Overlap(Overlap.X, Overlap.Y), Rotation.ToRotate(), 0,
|
2018-10-20 00:19:30 +00:00
|
|
|
|
PixelShift.ToPixelShiftType());
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|