2017-02-26 19:23:31 +00:00
|
|
|
|
using System;
|
2020-05-14 10:38:31 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
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;
|
2020-10-07 08:32:12 +00:00
|
|
|
|
using NvAPIWrapper.Native.Exceptions;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
|
2020-12-02 08:11:23 +00:00
|
|
|
|
namespace DisplayMagician.Shared.NVIDIA
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
2020-05-14 10:38:31 +00:00
|
|
|
|
public class SurroundTopologyDisplay
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
{
|
2020-10-07 08:32:12 +00:00
|
|
|
|
NvAPIWrapper.Native.GeneralApi.Initialize();
|
|
|
|
|
//var phyGPU = display.DisplayDevice.PhysicalGPU;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2020-10-07 08:32:12 +00:00
|
|
|
|
catch (NVIDIAApiException ex)
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
2020-10-07 08:32:12 +00:00
|
|
|
|
//Debug.WriteLine($"SurroundTopologyDisplay/NVIDIAApiException exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
|
|
|
|
|
// If we hit here then we cannot find the DisplayName from the EDID Data from the GPU
|
|
|
|
|
// So we just make one up using the DisplayID
|
2020-10-07 08:58:05 +00:00
|
|
|
|
DisplayName = $"Display #{DisplayId}";
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
|
2020-05-14 10:38:31 +00:00
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
/// <inheritdoc />
|
2020-05-14 10:38:31 +00:00
|
|
|
|
public override string ToString()
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
2020-05-14 10:38:31 +00:00
|
|
|
|
return DisplayName ?? $"SurroundTopologyDisplay #{DisplayId}";
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-14 10:38:31 +00:00
|
|
|
|
public GridTopologyDisplay ToGridTopologyDisplay()
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
2020-05-14 10:38:31 +00:00
|
|
|
|
return new GridTopologyDisplay(DisplayId, new Overlap(Overlap.X, Overlap.Y), Rotation.ToRotate(), 0,
|
|
|
|
|
PixelShift.ToPixelShiftType());
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-14 10:38:31 +00:00
|
|
|
|
// The public override for the Object.Equals
|
|
|
|
|
public override bool Equals(object obj)
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
2020-05-14 10:38:31 +00:00
|
|
|
|
return this.Equals(obj as SurroundTopologyDisplay);
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-14 10:38:31 +00:00
|
|
|
|
// SurroundTopologyDisplay are equal if their contents are equal
|
|
|
|
|
public bool Equals(SurroundTopologyDisplay other)
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
2020-05-14 10:38:31 +00:00
|
|
|
|
|
|
|
|
|
// If parameter is null, return false.
|
|
|
|
|
if (Object.ReferenceEquals(other, null))
|
2018-10-20 00:27:25 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2020-05-14 10:38:31 +00:00
|
|
|
|
// Optimization for a common success case.
|
|
|
|
|
if (Object.ReferenceEquals(this, other))
|
2018-10-20 00:27:25 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
2020-05-14 10:38:31 +00:00
|
|
|
|
// If run-time types are not exactly the same, return false.
|
|
|
|
|
if (this.GetType() != other.GetType())
|
2018-10-20 00:27:25 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2020-05-14 10:38:31 +00:00
|
|
|
|
// Check whether the SurroundTopologyDisplay properties are equal
|
|
|
|
|
// Two SurroundTopologyDisplay are equal only when they have the same data exactly
|
|
|
|
|
if (DisplayId == other.DisplayId &&
|
|
|
|
|
Overlap.Equals(other.Overlap) &&
|
|
|
|
|
PixelShift == other.PixelShift &&
|
|
|
|
|
Rotation == other.Rotation)
|
|
|
|
|
return true;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-14 10:38:31 +00:00
|
|
|
|
// If Equals() returns true for this object compared to another
|
|
|
|
|
// then GetHashCode() must return the same value for these objects.
|
2017-02-26 19:23:31 +00:00
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
2020-05-14 10:38:31 +00:00
|
|
|
|
// Get hash code for the DisplayId field if it is not null.
|
|
|
|
|
int hashDisplayId = DisplayId.GetHashCode();
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2020-05-14 10:38:31 +00:00
|
|
|
|
// Get hash code for the Overlap field if it is not null.
|
|
|
|
|
int hashOverlap = Overlap.GetHashCode();
|
|
|
|
|
|
|
|
|
|
// Get hash code for the PixelShift field if it is not null.
|
|
|
|
|
int hashPixelShift = PixelShift.GetHashCode();
|
|
|
|
|
|
|
|
|
|
// Get hash code for the Rotation field if it is not null.
|
|
|
|
|
int hashRotation = Rotation.GetHashCode();
|
|
|
|
|
|
|
|
|
|
//Calculate the hash code for the product.
|
|
|
|
|
return hashDisplayId ^ hashOverlap ^ hashPixelShift ^ hashRotation;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-14 10:38:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Custom comparer for the ProfileViewportTargetDisplay class
|
|
|
|
|
class SurroundTopologyDisplayComparer : IEqualityComparer<SurroundTopologyDisplay>
|
|
|
|
|
{
|
|
|
|
|
// Products are equal if their names and product numbers are equal.
|
|
|
|
|
public bool Equals(SurroundTopologyDisplay x, SurroundTopologyDisplay y)
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
2020-05-14 10:38:31 +00:00
|
|
|
|
|
|
|
|
|
//Check whether the compared objects reference the same data.
|
|
|
|
|
if (Object.ReferenceEquals(x, y)) return true;
|
|
|
|
|
|
|
|
|
|
//Check whether any of the compared objects is null.
|
|
|
|
|
if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Check whether the SurroundTopologyDisplay properties are equal
|
|
|
|
|
// Two SurroundTopologyDisplay are equal only when they have the same data exactly
|
|
|
|
|
if (x.DisplayId == y.DisplayId &&
|
|
|
|
|
x.Overlap.Equals(y.Overlap) &&
|
|
|
|
|
x.PixelShift == y.PixelShift &&
|
|
|
|
|
x.Rotation == y.Rotation)
|
|
|
|
|
return true;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-14 10:38:31 +00:00
|
|
|
|
// If Equals() returns true for a pair of objects
|
|
|
|
|
// then GetHashCode() must return the same value for these objects.
|
|
|
|
|
public int GetHashCode(SurroundTopologyDisplay surroundTopologyDisplay)
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
2020-05-14 10:38:31 +00:00
|
|
|
|
// Check whether the object is null
|
|
|
|
|
if (Object.ReferenceEquals(surroundTopologyDisplay, null)) return 0;
|
|
|
|
|
|
|
|
|
|
// Get hash code for the DisplayId field if it is not null.
|
|
|
|
|
int hashDisplayId = surroundTopologyDisplay.DisplayId.GetHashCode();
|
|
|
|
|
|
|
|
|
|
// Get hash code for the Overlap field if it is not null.
|
|
|
|
|
int hashOverlap = surroundTopologyDisplay.Overlap.GetHashCode();
|
|
|
|
|
|
|
|
|
|
// Get hash code for the PixelShift field if it is not null.
|
|
|
|
|
int hashPixelShift = surroundTopologyDisplay.PixelShift.GetHashCode();
|
|
|
|
|
|
|
|
|
|
// Get hash code for the Rotation field if it is not null.
|
|
|
|
|
int hashRotation = surroundTopologyDisplay.Rotation.GetHashCode();
|
|
|
|
|
|
|
|
|
|
//Calculate the hash code for the product.
|
|
|
|
|
return hashDisplayId ^ hashOverlap ^ hashPixelShift ^ hashRotation;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
2020-05-14 10:38:31 +00:00
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|