109 lines
2.7 KiB
C#
109 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Aiwaz.Contracts;
|
|
using SlimDX;
|
|
|
|
namespace Aiwaz.Core
|
|
{
|
|
public class DisplayAdapter : IDisposable
|
|
{
|
|
private DeviceEnumerator deviceEnumerator;
|
|
|
|
public SlimDX.DXGI.Adapter Adapter { get; private set; }
|
|
|
|
public bool HasEnumerated
|
|
{
|
|
get { return OutputDevices.Count > 0; }
|
|
}
|
|
|
|
public long DedicatedSystemMemory
|
|
{
|
|
get { return Adapter.Description.DedicatedSystemMemory; }
|
|
}
|
|
|
|
public long DedicatedVideoMemory
|
|
{
|
|
get { return Adapter.Description.DedicatedVideoMemory; }
|
|
}
|
|
|
|
public long SharedSystemMemory
|
|
{
|
|
get { return Adapter.Description.SharedSystemMemory; }
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get { return Adapter.Description.Description; }
|
|
}
|
|
|
|
public List<OutputDevice> OutputDevices { get; private set; }
|
|
|
|
public DisplayAdapter(DeviceEnumerator argDeviceEnumerator, SlimDX.DXGI.Adapter argAdapter)
|
|
{
|
|
this.deviceEnumerator = argDeviceEnumerator;
|
|
this.Adapter = argAdapter;
|
|
this.OutputDevices = new List<OutputDevice>();
|
|
}
|
|
|
|
~DisplayAdapter()
|
|
{
|
|
this.Dispose();
|
|
}
|
|
|
|
public bool TryEnumerate()
|
|
{
|
|
for (var i = 0; i < Adapter.GetOutputCount(); ++i)
|
|
{
|
|
var output = Adapter.GetOutput(i);
|
|
OutputDevice device = new OutputDevice(deviceEnumerator, output);
|
|
if (device.TryEnumerate())
|
|
OutputDevices.Add(device);
|
|
else
|
|
output.Dispose();
|
|
}
|
|
|
|
return HasEnumerated;
|
|
}
|
|
|
|
public OutputDevice FindBestOutput(bool argAllowToEnumerate)
|
|
{
|
|
if (argAllowToEnumerate && !this.TryEnumerate())
|
|
return null;
|
|
|
|
if (!HasEnumerated)
|
|
return null;
|
|
|
|
return OutputDevices.Last();
|
|
}
|
|
|
|
public DisplayMode FindBestDisplayMode(bool argAllowToEnumerate)
|
|
{
|
|
if (argAllowToEnumerate && !this.TryEnumerate())
|
|
return null;
|
|
|
|
if (!HasEnumerated)
|
|
return null;
|
|
|
|
return OutputDevices.Last().FindBestDisplayMode(argAllowToEnumerate);
|
|
}
|
|
|
|
#region IDisposable Members
|
|
|
|
public void Dispose()
|
|
{
|
|
if (Adapter != null)
|
|
Adapter.Dispose();
|
|
Adapter = null;
|
|
|
|
if (OutputDevices != null)
|
|
foreach (var output in OutputDevices)
|
|
output.Dispose();
|
|
OutputDevices = null;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|