port from perforce
This commit is contained in:
141
aiwaz/Aiwaz/DeviceEnumerator/DeviceEnumerator.cpp
Normal file
141
aiwaz/Aiwaz/DeviceEnumerator/DeviceEnumerator.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
#include "stdafx.h"
|
||||
#include "DeviceEnumerator.h"
|
||||
#include "DisplayAdapter.h"
|
||||
|
||||
|
||||
DeviceEnumerator::DeviceEnumerator(ID3D10Device* ar_Device_)
|
||||
: m_DXGIFactory(NULL)
|
||||
, m_Device(ar_Device_)
|
||||
, m_HasEnumerated(false)
|
||||
, m_DesiredWidth(0)
|
||||
, m_DesiredHeight(0)
|
||||
, m_DesiredRefreshRate(0)
|
||||
, m_DesiredFormat(DataFormat::Unknown)
|
||||
{
|
||||
HRESULT result = ::CreateDXGIFactory (__uuidof(IDXGIFactory), (void**)&m_DXGIFactory);
|
||||
if (result != S_OK)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
DeviceEnumerator::~DeviceEnumerator()
|
||||
{
|
||||
for (uint32 i = 0; i < m_EnumeratedAdapters.size(); ++i)
|
||||
delete m_EnumeratedAdapters[i];
|
||||
|
||||
if (m_DXGIFactory != NULL)
|
||||
m_DXGIFactory->Release();
|
||||
m_DXGIFactory = NULL;
|
||||
}
|
||||
|
||||
|
||||
bool DeviceEnumerator::TryEnumerate(uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (m_HasEnumerated)
|
||||
{
|
||||
if (m_DesiredWidth == argDesiredWidth ||
|
||||
m_DesiredHeight == argDesiredHeight ||
|
||||
m_DesiredRefreshRate == argDesiredRefreshRate ||
|
||||
m_DesiredFormat == argDesiredFormat)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
m_HasEnumerated = false;
|
||||
}
|
||||
if (m_DXGIFactory == NULL)
|
||||
return false;
|
||||
|
||||
int adapterIndex = 0;
|
||||
IDXGIAdapter* adapter = NULL;
|
||||
while (m_DXGIFactory->EnumAdapters(adapterIndex, &adapter) == S_OK)
|
||||
{
|
||||
LARGE_INTEGER version;
|
||||
if (adapter->CheckInterfaceSupport (__uuidof (ID3D10Device), &version) == S_OK)
|
||||
{
|
||||
IDisplayAdapter* deviceAdapter = new DisplayAdapter(adapter, m_Device);
|
||||
if (deviceAdapter->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
m_EnumeratedAdapters.push_back(deviceAdapter);
|
||||
else
|
||||
delete deviceAdapter;
|
||||
}
|
||||
|
||||
adapter->Release();
|
||||
adapterIndex++;
|
||||
}
|
||||
|
||||
m_DesiredWidth = argDesiredWidth;
|
||||
m_DesiredHeight = argDesiredHeight;
|
||||
m_DesiredRefreshRate = argDesiredRefreshRate;
|
||||
m_DesiredFormat = argDesiredFormat;
|
||||
|
||||
m_HasEnumerated = !m_EnumeratedAdapters.empty();
|
||||
return m_HasEnumerated;
|
||||
}
|
||||
|
||||
|
||||
IDisplayAdapter* DeviceEnumerator::FindBestAdapter(bool argAllowToEnumerate, uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (argAllowToEnumerate && !this->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
return NULL;
|
||||
|
||||
if (!m_HasEnumerated)
|
||||
return NULL;
|
||||
|
||||
return m_EnumeratedAdapters.front();
|
||||
}
|
||||
|
||||
|
||||
IOutputDevice* DeviceEnumerator::FindBestOutput(bool argAllowToEnumerate, uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (argAllowToEnumerate && !this->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
return NULL;
|
||||
|
||||
if (!m_HasEnumerated)
|
||||
return NULL;
|
||||
|
||||
return m_EnumeratedAdapters.front()->FindBestOutput(argAllowToEnumerate, argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat);
|
||||
}
|
||||
|
||||
|
||||
IDisplayMode* DeviceEnumerator::FindBestDisplayMode(bool argAllowToEnumerate, uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (argAllowToEnumerate && !this->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
return NULL;
|
||||
|
||||
if (!m_HasEnumerated)
|
||||
return NULL;
|
||||
|
||||
return m_EnumeratedAdapters.front()->FindBestDisplayMode(argAllowToEnumerate, argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat);
|
||||
}
|
||||
|
||||
|
||||
void DeviceEnumerator::Verbose()
|
||||
{
|
||||
if (!this->get_HasEnumerated())
|
||||
{
|
||||
std::wcout << std::red << L"Enumeration was not executed or no results available." << std::white << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
IDisplayAdapter* displayAdapter = this->FindBestAdapter();
|
||||
std::wcout << L"Adapter: " << displayAdapter->get_Name() << std::endl;
|
||||
std::wcout << L"Dedicated System Memory: " << displayAdapter->get_DedicatedSystemMemory()/1024/1024 << L"MB" << std::endl;
|
||||
std::wcout << L"Dedicated Video Memory: " << displayAdapter->get_DedicatedVideoMemory()/1024/1024 << L"MB" << std::endl;
|
||||
std::wcout << L"Shared System Memory: " << displayAdapter->get_SharedSystemMemory()/1024/1024 << L"MB" << std::endl << std::endl;
|
||||
|
||||
for (uint32 i = 0; i < displayAdapter->get_DeviceOutputs().size(); ++i)
|
||||
{
|
||||
IOutputDevice* outputDevice = displayAdapter->get_DeviceOutputs()[i];
|
||||
if (i == 0)
|
||||
std::wcout << L"Primary Output: ";
|
||||
else
|
||||
std::wcout << L"Output: ";
|
||||
|
||||
std::wcout << outputDevice->get_Name() << std::endl;
|
||||
|
||||
IDisplayMode* displayMode = outputDevice->FindBestDisplayMode();
|
||||
int bpp = DataFormat::GetDataFormatByteSize(displayMode->get_Format()) * 8;
|
||||
std::wcout << L"Display: " << displayMode->get_Width() << L"x" << displayMode->get_Height() << L"x" << bpp << L" @" << displayMode->get_RefreshRate() << L"Hz" << std::endl << std::endl;
|
||||
}
|
||||
}
|
||||
33
aiwaz/Aiwaz/DeviceEnumerator/DeviceEnumerator.h
Normal file
33
aiwaz/Aiwaz/DeviceEnumerator/DeviceEnumerator.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "IDeviceEnumerator.h"
|
||||
|
||||
|
||||
class DeviceEnumerator
|
||||
: public IDeviceEnumerator
|
||||
{
|
||||
public:
|
||||
DeviceEnumerator(ID3D10Device* ar_Device_ = NULL);
|
||||
virtual ~DeviceEnumerator();
|
||||
|
||||
virtual bool get_HasEnumerated() const { return m_HasEnumerated; }
|
||||
virtual const std::vector<IDisplayAdapter*>& get_DeviceAdapters() const { return m_EnumeratedAdapters; }
|
||||
|
||||
virtual bool TryEnumerate(uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
virtual IDisplayAdapter* FindBestAdapter(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
virtual IOutputDevice* FindBestOutput(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
virtual IDisplayMode* FindBestDisplayMode(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
|
||||
virtual void Verbose();
|
||||
|
||||
private:
|
||||
IDXGIFactory* m_DXGIFactory;
|
||||
ID3D10Device* m_Device;
|
||||
bool m_HasEnumerated;
|
||||
|
||||
std::vector<IDisplayAdapter*> m_EnumeratedAdapters;
|
||||
uint32 m_DesiredWidth;
|
||||
uint32 m_DesiredHeight;
|
||||
uint32 m_DesiredRefreshRate;
|
||||
DataFormat::Enumeration m_DesiredFormat;
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "stdafx.h"
|
||||
#include "DeviceVisitorBase.h"
|
||||
#include "IDeviceEnumerator.h"
|
||||
|
||||
|
||||
DeviceVisitorBase::DeviceVisitorBase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
DeviceVisitorBase::~DeviceVisitorBase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DeviceVisitorBase::Visit(IDeviceEnumerator& argEnumerator)
|
||||
{
|
||||
this->VisitEnumerator(argEnumerator);
|
||||
}
|
||||
|
||||
|
||||
void DeviceVisitorBase::VisitEnumerator(IDeviceEnumerator& argEnumerator)
|
||||
{
|
||||
const std::vector<IDisplayAdapter*>& adapters = argEnumerator.get_DeviceAdapters();
|
||||
for (uint32 i = 0; i < adapters.size(); ++i)
|
||||
this->VisitAdapter(*adapters[i]);
|
||||
}
|
||||
|
||||
|
||||
void DeviceVisitorBase::VisitAdapter(IDisplayAdapter& argAdapter)
|
||||
{
|
||||
const std::vector<IOutputDevice*>& outputs = argAdapter.get_DeviceOutputs();
|
||||
for (uint32 i = 0; i < outputs.size(); ++i)
|
||||
this->VisitOutput(*outputs[i]);
|
||||
}
|
||||
|
||||
|
||||
void DeviceVisitorBase::VisitOutput(IOutputDevice& argOutput)
|
||||
{
|
||||
const std::vector<IDisplayMode*>& displayModes = argOutput.get_DisplayModes();
|
||||
for (uint32 i = 0; i < displayModes.size(); ++i)
|
||||
this->VisitDisplayMode(*displayModes[i]);
|
||||
}
|
||||
|
||||
|
||||
void DeviceVisitorBase::VisitDisplayMode(IDisplayMode& argMode)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "IDeviceEnumerator.h"
|
||||
|
||||
class DeviceVisitorBase
|
||||
{
|
||||
public:
|
||||
DeviceVisitorBase();
|
||||
virtual ~DeviceVisitorBase();
|
||||
|
||||
virtual void Visit(IDeviceEnumerator& argEnumerator);
|
||||
|
||||
protected:
|
||||
virtual void VisitEnumerator(IDeviceEnumerator& argEnumerator);
|
||||
virtual void VisitAdapter(IDisplayAdapter& argAdapter);
|
||||
virtual void VisitOutput(IOutputDevice& argOutput);
|
||||
virtual void VisitDisplayMode(IDisplayMode& argMode);
|
||||
};
|
||||
@@ -0,0 +1,99 @@
|
||||
#include "stdafx.h"
|
||||
#include "XmlDeviceVisitor.h"
|
||||
#include "IDeviceEnumerator.h"
|
||||
|
||||
|
||||
XmlDeviceVisitor::XmlDeviceVisitor(const string16& argOutputFile)
|
||||
: DeviceVisitorBase()
|
||||
, m_OutputFile(argOutputFile)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
XmlDeviceVisitor::~XmlDeviceVisitor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void XmlDeviceVisitor::Visit(IDeviceEnumerator& argEnumerator)
|
||||
{
|
||||
m_FileStream.open(m_OutputFile.c_str());
|
||||
|
||||
DeviceVisitorBase::Visit(argEnumerator);
|
||||
|
||||
m_FileStream.close();
|
||||
}
|
||||
|
||||
|
||||
void XmlDeviceVisitor::VisitEnumerator(IDeviceEnumerator& argEnumerator)
|
||||
{
|
||||
m_FileStream << L"<?xml version=\"1.0\" encoding=\"utf-8\"?>" << std::endl;
|
||||
m_FileStream << L"<DeviceEnumeration>" << std::endl;
|
||||
|
||||
IDisplayAdapter* bestAdapter = argEnumerator.FindBestAdapter();
|
||||
if (bestAdapter != NULL)
|
||||
m_FileStream << L"\t<BestAdapter>" << bestAdapter->get_Name() << L"</BestAdapter>" << std::endl;
|
||||
|
||||
IOutputDevice* bestOutput = argEnumerator.FindBestOutput();
|
||||
if (bestOutput != NULL)
|
||||
m_FileStream << L"\t<BestOutput>" << bestOutput->get_Name() << L"</BestOutput>" << std::endl;
|
||||
|
||||
IDisplayMode* bestDisplayMode = argEnumerator.FindBestDisplayMode();
|
||||
if (bestDisplayMode != NULL)
|
||||
{
|
||||
m_FileStream << L"\t<BestDisplayMode>" << std::endl;
|
||||
m_FileStream << L"\t\t<Resolution>" << bestDisplayMode->get_Width() << L"," << bestDisplayMode->get_Height() << L"</Resolution>" << std::endl;
|
||||
m_FileStream << L"\t\t<RefreshRate>" << bestDisplayMode->get_RefreshRate() << L"</RefreshRate>" << std::endl;
|
||||
m_FileStream << L"\t\t<Format>" << std::to_string16(DataFormat::ToString(bestDisplayMode->get_Format())) << L"</Format>" << std::endl;
|
||||
m_FileStream << L"\t</BestDisplayMode>" << std::endl;
|
||||
}
|
||||
|
||||
DeviceVisitorBase::VisitEnumerator(argEnumerator);
|
||||
|
||||
m_FileStream << L"</DeviceEnumeration>" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void XmlDeviceVisitor::VisitAdapter(IDisplayAdapter& argAdapter)
|
||||
{
|
||||
m_FileStream << L"\t<Adapter Name=\"" << argAdapter.get_Name() << L"\">"<< std::endl;
|
||||
m_FileStream << L"\t\t<DedicatedSystemMemory>" << argAdapter.get_DedicatedSystemMemory() << L"</DedicatedSystemMemory>" << std::endl;
|
||||
m_FileStream << L"\t\t<DedicatedVideoMemory>" << argAdapter.get_DedicatedVideoMemory() << L"</DedicatedVideoMemory>" << std::endl;
|
||||
m_FileStream << L"\t\t<SharedSystemMemory>" << argAdapter.get_SharedSystemMemory() << L"</SharedSystemMemory>" << std::endl;
|
||||
|
||||
DeviceVisitorBase::VisitAdapter(argAdapter);
|
||||
|
||||
m_FileStream << L"\t</Adapter>"<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
void XmlDeviceVisitor::VisitOutput(IOutputDevice& argOutput)
|
||||
{
|
||||
m_FileStream << L"\t\t<Output Name=\"" << argOutput.get_Name() << L"\">" << std::endl;
|
||||
m_FileStream << L"\t\t\t<AttachedToDesktop>" << argOutput.get_IsAttachedToDesktop() << L"</AttachedToDesktop>" << std::endl;
|
||||
m_FileStream << L"\t\t\t<DesktopCoordinates>" << argOutput.get_DesktopCoordinates().left << L"," << argOutput.get_DesktopCoordinates().top << L"," << argOutput.get_DesktopCoordinates().right << L"," << argOutput.get_DesktopCoordinates().bottom << L"</DesktopCoordinates>" << std::endl;
|
||||
|
||||
const std::vector<IDisplayMode*>& displayModes = argOutput.get_DisplayModes();
|
||||
if (!displayModes.empty())
|
||||
m_FileStream << L"\t\t\t<DisplayModes Count=\"" << displayModes.size() << L"\">" << std::endl;
|
||||
|
||||
DeviceVisitorBase::VisitOutput(argOutput);
|
||||
|
||||
if (!displayModes.empty())
|
||||
m_FileStream << L"\t\t\t</DisplayModes>" << std::endl;
|
||||
|
||||
m_FileStream << L"\t\t</Output>"<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
void XmlDeviceVisitor::VisitDisplayMode(IDisplayMode& argMode)
|
||||
{
|
||||
m_FileStream << L"\t\t\t\t<Mode>" << std::endl;
|
||||
m_FileStream << L"\t\t\t\t\t<Resolution>" << argMode.get_Width() << L"," << argMode.get_Height() << L"</Resolution>" << std::endl;
|
||||
m_FileStream << L"\t\t\t\t\t<RefreshRate>" << argMode.get_RefreshRate() << L"</RefreshRate>" << std::endl;
|
||||
m_FileStream << L"\t\t\t\t\t<Format>" << std::to_string16(DataFormat::ToString(argMode.get_Format())) << L"</Format>" << std::endl;
|
||||
m_FileStream << L"\t\t\t\t</Mode>" << std::endl;
|
||||
|
||||
DeviceVisitorBase::VisitDisplayMode(argMode);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include "DeviceVisitorBase.h"
|
||||
|
||||
class XmlDeviceVisitor
|
||||
: public DeviceVisitorBase
|
||||
{
|
||||
public:
|
||||
XmlDeviceVisitor(const string16& argOutputFile);
|
||||
virtual ~XmlDeviceVisitor();
|
||||
|
||||
virtual void Visit(IDeviceEnumerator& argEnumerator);
|
||||
|
||||
protected:
|
||||
virtual void VisitEnumerator(IDeviceEnumerator& argEnumerator);
|
||||
virtual void VisitAdapter(IDisplayAdapter& argAdapter);
|
||||
virtual void VisitOutput(IOutputDevice& argOutput);
|
||||
virtual void VisitDisplayMode(IDisplayMode& argMode);
|
||||
|
||||
private:
|
||||
std::wofstream m_FileStream;
|
||||
string16 m_OutputFile;
|
||||
};
|
||||
96
aiwaz/Aiwaz/DeviceEnumerator/DisplayAdapter.cpp
Normal file
96
aiwaz/Aiwaz/DeviceEnumerator/DisplayAdapter.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "stdafx.h"
|
||||
#include "DisplayAdapter.h"
|
||||
#include "outputDevice.h"
|
||||
|
||||
|
||||
DisplayAdapter::DisplayAdapter(IDXGIAdapter* ar_Adapter_, ID3D10Device* ar_Device_)
|
||||
: m_Adapter(ar_Adapter_)
|
||||
, m_Device(ar_Device_)
|
||||
, m_HasEnumerated(false)
|
||||
, m_DesiredWidth(0)
|
||||
, m_DesiredHeight(0)
|
||||
, m_DesiredRefreshRate(0)
|
||||
, m_DesiredFormat(DataFormat::Unknown)
|
||||
{
|
||||
if (m_Adapter != NULL)
|
||||
{
|
||||
m_Adapter->AddRef();
|
||||
m_Adapter->GetDesc(&m_AdapterDesc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DisplayAdapter::~DisplayAdapter()
|
||||
{
|
||||
for (uint32 i = 0; i < m_EnumeratedOutputs.size(); ++i)
|
||||
delete m_EnumeratedOutputs[i];
|
||||
|
||||
if (m_Adapter != NULL)
|
||||
m_Adapter->Release();
|
||||
m_Adapter = NULL;
|
||||
}
|
||||
|
||||
|
||||
bool DisplayAdapter::TryEnumerate(uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (m_HasEnumerated)
|
||||
{
|
||||
if (m_DesiredWidth == argDesiredWidth ||
|
||||
m_DesiredHeight == argDesiredHeight ||
|
||||
m_DesiredRefreshRate == argDesiredRefreshRate ||
|
||||
m_DesiredFormat == argDesiredFormat)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
m_HasEnumerated = false;
|
||||
}
|
||||
if (m_Adapter == NULL)
|
||||
return false;
|
||||
|
||||
int outputIndex = 0;
|
||||
IDXGIOutput* output = NULL;
|
||||
while (m_Adapter->EnumOutputs(outputIndex, &output) == S_OK)
|
||||
{
|
||||
IOutputDevice* deviceOutput = new OutputDevice(output, m_Device);
|
||||
if (deviceOutput->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
m_EnumeratedOutputs.push_back(deviceOutput);
|
||||
else
|
||||
delete deviceOutput;
|
||||
|
||||
output->Release();
|
||||
outputIndex++;
|
||||
}
|
||||
|
||||
m_DesiredWidth = argDesiredWidth;
|
||||
m_DesiredHeight = argDesiredHeight;
|
||||
m_DesiredRefreshRate = argDesiredRefreshRate;
|
||||
m_DesiredFormat = argDesiredFormat;
|
||||
|
||||
m_HasEnumerated = !m_EnumeratedOutputs.empty();
|
||||
return m_HasEnumerated;
|
||||
}
|
||||
|
||||
|
||||
IOutputDevice* DisplayAdapter::FindBestOutput(bool argAllowToEnumerate, uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (argAllowToEnumerate && !this->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
return NULL;
|
||||
|
||||
if (!m_HasEnumerated)
|
||||
return NULL;
|
||||
|
||||
return m_EnumeratedOutputs.front();
|
||||
}
|
||||
|
||||
|
||||
IDisplayMode* DisplayAdapter::FindBestDisplayMode(bool argAllowToEnumerate, uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (argAllowToEnumerate && !this->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
return NULL;
|
||||
|
||||
if (!m_HasEnumerated)
|
||||
return NULL;
|
||||
|
||||
return m_EnumeratedOutputs.front()->FindBestDisplayMode(argAllowToEnumerate, argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat);
|
||||
}
|
||||
34
aiwaz/Aiwaz/DeviceEnumerator/DisplayAdapter.h
Normal file
34
aiwaz/Aiwaz/DeviceEnumerator/DisplayAdapter.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "IDeviceEnumerator.h"
|
||||
|
||||
|
||||
class DisplayAdapter
|
||||
: public IDisplayAdapter
|
||||
{
|
||||
public:
|
||||
DisplayAdapter(IDXGIAdapter* ar_Adapter_, ID3D10Device* ar_Device_ = NULL);
|
||||
virtual ~DisplayAdapter();
|
||||
|
||||
virtual size_t get_DedicatedSystemMemory() const { return m_AdapterDesc.DedicatedSystemMemory; }
|
||||
virtual size_t get_DedicatedVideoMemory() const { return m_AdapterDesc.DedicatedVideoMemory; }
|
||||
virtual size_t get_SharedSystemMemory() const { return m_AdapterDesc.SharedSystemMemory; }
|
||||
virtual const std::vector<IOutputDevice*>& get_DeviceOutputs() const { return m_EnumeratedOutputs; }
|
||||
virtual bool get_HasEnumerated() const { return m_HasEnumerated; }
|
||||
virtual IDXGIAdapter* get_Adapter() const { return m_Adapter; }
|
||||
|
||||
virtual string16 get_Name() const { return m_AdapterDesc.Description; }
|
||||
virtual bool TryEnumerate(uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
virtual IOutputDevice* FindBestOutput(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
virtual IDisplayMode* FindBestDisplayMode(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
|
||||
private:
|
||||
IDXGIAdapter* m_Adapter;
|
||||
ID3D10Device* m_Device;
|
||||
DXGI_ADAPTER_DESC m_AdapterDesc;
|
||||
bool m_HasEnumerated;
|
||||
|
||||
std::vector<IOutputDevice*> m_EnumeratedOutputs;
|
||||
uint32 m_DesiredWidth;
|
||||
uint32 m_DesiredHeight;
|
||||
uint32 m_DesiredRefreshRate;
|
||||
DataFormat::Enumeration m_DesiredFormat;
|
||||
};
|
||||
2
aiwaz/Aiwaz/DeviceEnumerator/DisplayMode.cpp
Normal file
2
aiwaz/Aiwaz/DeviceEnumerator/DisplayMode.cpp
Normal file
@@ -0,0 +1,2 @@
|
||||
#include "stdafx.h"
|
||||
#include "DisplayMode.h"
|
||||
21
aiwaz/Aiwaz/DeviceEnumerator/DisplayMode.h
Normal file
21
aiwaz/Aiwaz/DeviceEnumerator/DisplayMode.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <DXGI.h>
|
||||
#include "IDeviceEnumerator.h"
|
||||
|
||||
|
||||
class DisplayMode
|
||||
: public IDisplayMode
|
||||
{
|
||||
public:
|
||||
DisplayMode(DXGI_MODE_DESC& argDescriptor)
|
||||
: m_Descriptor(argDescriptor)
|
||||
{}
|
||||
virtual ~DisplayMode() {}
|
||||
|
||||
virtual uint32 get_Width() const { return m_Descriptor.Width; }
|
||||
virtual uint32 get_Height() const { return m_Descriptor.Height; }
|
||||
virtual uint32 get_RefreshRate() const { return m_Descriptor.RefreshRate.Numerator == 0 ? 0 : static_cast<int>(m_Descriptor.RefreshRate.Numerator / m_Descriptor.RefreshRate.Denominator); }
|
||||
virtual DataFormat::Enumeration get_Format() const { return (DataFormat::Enumeration)m_Descriptor.Format; }
|
||||
|
||||
private:
|
||||
DXGI_MODE_DESC m_Descriptor;
|
||||
};
|
||||
110
aiwaz/Aiwaz/DeviceEnumerator/OutputDevice.cpp
Normal file
110
aiwaz/Aiwaz/DeviceEnumerator/OutputDevice.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
#include "stdafx.h"
|
||||
#include "OutputDevice.h"
|
||||
#include "DisplayMode.h"
|
||||
|
||||
|
||||
OutputDevice::OutputDevice(IDXGIOutput* ar_Output_, ID3D10Device* ar_Device_)
|
||||
: m_Output(ar_Output_)
|
||||
, m_Device(ar_Device_)
|
||||
, m_HasEnumerated(false)
|
||||
, m_DesiredWidth(0)
|
||||
, m_DesiredHeight(0)
|
||||
, m_DesiredRefreshRate(0)
|
||||
, m_DesiredFormat(DataFormat::Unknown)
|
||||
{
|
||||
if (m_Output != NULL)
|
||||
{
|
||||
m_Output->AddRef();
|
||||
m_Output->GetDesc(&m_OutputDesc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
OutputDevice::~OutputDevice()
|
||||
{
|
||||
for (uint32 i = 0; i < m_DisplayModes.size(); ++i)
|
||||
delete m_DisplayModes[i];
|
||||
|
||||
if (m_Output != NULL)
|
||||
m_Output->Release();
|
||||
m_Output = NULL;
|
||||
}
|
||||
|
||||
|
||||
bool OutputDevice::TryEnumerate(uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (m_HasEnumerated)
|
||||
{
|
||||
if (m_DesiredWidth == argDesiredWidth ||
|
||||
m_DesiredHeight == argDesiredHeight ||
|
||||
m_DesiredRefreshRate == argDesiredRefreshRate ||
|
||||
m_DesiredFormat == argDesiredFormat)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
m_HasEnumerated = false;
|
||||
}
|
||||
|
||||
for (int formatIndex = (int)argDesiredFormat; formatIndex <= (argDesiredFormat == DataFormat::Unknown ? DXGI_FORMAT_B8G8R8X8_UNORM : (int)argDesiredFormat); ++formatIndex)
|
||||
{
|
||||
DXGI_FORMAT format = (DXGI_FORMAT)formatIndex;
|
||||
uint32 flags = DXGI_ENUM_MODES_SCALING;
|
||||
uint32 displayModeCount = 0;
|
||||
if (m_Output->GetDisplayModeList(format, flags, &displayModeCount, 0) == S_OK && displayModeCount > 0)
|
||||
{
|
||||
DXGI_MODE_DESC* descs = new DXGI_MODE_DESC[displayModeCount];
|
||||
if (m_Output->GetDisplayModeList(format, flags, &displayModeCount, descs) == S_OK)
|
||||
{
|
||||
for (uint32 i = 0; i < displayModeCount; ++i)
|
||||
{
|
||||
IDisplayMode* displayMode = new DisplayMode(descs[i]);
|
||||
bool keepDisplayMode = false;
|
||||
|
||||
if ((argDesiredWidth == 0 || argDesiredWidth <= displayMode->get_Width()) &&
|
||||
(argDesiredHeight == 0 || argDesiredHeight <= displayMode->get_Height()) &&
|
||||
(argDesiredRefreshRate == 0 || argDesiredRefreshRate <= displayMode->get_RefreshRate()) &&
|
||||
(argDesiredFormat == DataFormat::Unknown || argDesiredFormat == displayMode->get_Format()))
|
||||
{
|
||||
if (m_Device != NULL)
|
||||
{
|
||||
uint32 supportBits = 0;
|
||||
m_Device->CheckFormatSupport((DXGI_FORMAT)format, &supportBits);
|
||||
if ((supportBits & D3D10_FORMAT_SUPPORT_DISPLAY) != 0)
|
||||
keepDisplayMode = true;
|
||||
}
|
||||
else
|
||||
keepDisplayMode = true;
|
||||
}
|
||||
|
||||
if (keepDisplayMode)
|
||||
m_DisplayModes.push_back(displayMode);
|
||||
else
|
||||
delete displayMode;
|
||||
|
||||
}
|
||||
delete [] descs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_DesiredWidth = argDesiredWidth;
|
||||
m_DesiredHeight = argDesiredHeight;
|
||||
m_DesiredRefreshRate = argDesiredRefreshRate;
|
||||
m_DesiredFormat = argDesiredFormat;
|
||||
|
||||
m_HasEnumerated = !m_DisplayModes.empty();
|
||||
return m_HasEnumerated;
|
||||
}
|
||||
|
||||
|
||||
IDisplayMode* OutputDevice::FindBestDisplayMode(bool argAllowToEnumerate, uint32 argDesiredWidth, uint32 argDesiredHeight, uint32 argDesiredRefreshRate, DataFormat::Enumeration argDesiredFormat)
|
||||
{
|
||||
if (argAllowToEnumerate && !this->TryEnumerate(argDesiredWidth, argDesiredHeight, argDesiredRefreshRate, argDesiredFormat))
|
||||
return NULL;
|
||||
|
||||
if (!m_HasEnumerated)
|
||||
return NULL;
|
||||
|
||||
return m_DisplayModes.back();
|
||||
}
|
||||
35
aiwaz/Aiwaz/DeviceEnumerator/OutputDevice.h
Normal file
35
aiwaz/Aiwaz/DeviceEnumerator/OutputDevice.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "IDeviceEnumerator.h"
|
||||
|
||||
|
||||
class OutputDevice
|
||||
: public IOutputDevice
|
||||
{
|
||||
public:
|
||||
OutputDevice(IDXGIOutput* ar_Output_, ID3D10Device* ar_Device_ = NULL);
|
||||
virtual ~OutputDevice();
|
||||
|
||||
virtual bool get_IsAttachedToDesktop() const { return m_OutputDesc.AttachedToDesktop == TRUE; }
|
||||
virtual HMONITOR get_MonitorHandle() const { return m_OutputDesc.Monitor; }
|
||||
virtual RECT get_DesktopCoordinates() const { return m_OutputDesc.DesktopCoordinates; }
|
||||
virtual const std::vector<IDisplayMode*>& get_DisplayModes() const { return m_DisplayModes; }
|
||||
virtual bool get_HasEnumerated() const { return m_HasEnumerated; }
|
||||
|
||||
virtual bool TryEnumerate(uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
virtual IDisplayMode* FindBestDisplayMode(bool argAllowToEnumerate = false, uint32 argDesiredWidth = 0, uint32 argDesiredHeight = 0, uint32 argDesiredRefreshRate = 0, DataFormat::Enumeration argDesiredFormat = DataFormat::Unknown);
|
||||
virtual string16 get_Name() const { return m_OutputDesc.DeviceName; }
|
||||
|
||||
private:
|
||||
void GatherDisplayModes();
|
||||
|
||||
private:
|
||||
IDXGIOutput* m_Output;
|
||||
ID3D10Device* m_Device;
|
||||
DXGI_OUTPUT_DESC m_OutputDesc;
|
||||
bool m_HasEnumerated;
|
||||
|
||||
std::vector<IDisplayMode*> m_DisplayModes;
|
||||
uint32 m_DesiredWidth;
|
||||
uint32 m_DesiredHeight;
|
||||
uint32 m_DesiredRefreshRate;
|
||||
DataFormat::Enumeration m_DesiredFormat;
|
||||
};
|
||||
Reference in New Issue
Block a user