diff --git a/libraries/platform/src/WINPlatform.cpp b/libraries/platform/src/WINPlatform.cpp index c335e3745e..c29f29483e 100644 --- a/libraries/platform/src/WINPlatform.cpp +++ b/libraries/platform/src/WINPlatform.cpp @@ -11,36 +11,33 @@ #include #include + + +#ifdef Q_OS_WINDOWS +#include +#include +#endif + using namespace platform; using namespace nlohmann; bool WINInstance::enumerateProcessors() { - - - json cpu; - - getCpuDetails(cpu); - - cpu["numCores"] = getNumLogicalCores(); - - _processors.push_back(cpu); - - json mem; - mem["totalRam"] = getTotalSystemRam(); - - _memory.push_back(mem); + enumerateCpu(); + enumerateGpu(); + enumerateRam(); return true; } -void WINInstance::getCpuDetails(json &cpu) { +void WINInstance::enumerateCpu() { + json cpu; int CPUInfo[4] = { -1 }; unsigned nExIds; unsigned int i = 0; char CPUBrandString[16]; char CPUModelString[16]; char CPUClockString[16]; - + // Get the information associated with each extended ID. __cpuid(CPUInfo, 0x80000000); nExIds = CPUInfo[0]; @@ -56,24 +53,79 @@ void WINInstance::getCpuDetails(json &cpu) { memcpy(CPUClockString, CPUInfo, sizeof(CPUInfo)); } } - + cpu["brand"] = CPUBrandString; cpu["model"] = CPUModelString; cpu["clockSpeed"] = CPUClockString; + cpu["numCores"] = getNumLogicalCores(); + + _processors.push_back(cpu); } unsigned int WINInstance::getNumLogicalCores() { return std::thread::hardware_concurrency(); } -int WINInstance::getTotalSystemRam() { +void WINInstance::enumerateGpu() { +#ifdef Q_OS_WINDOWS + IDXGIAdapter* adapter; + std::vector adapters; + IDXGIFactory* factory = NULL; + + HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory); + _gpu.clear(); + if (SUCCEEDED(hr)) { + for (UINT i = 0; factory->EnumAdapters(i, &adapter) != DXGI_ERROR_NOT_FOUND; ++i) { + DXGI_ADAPTER_DESC* desc; + + if (SUCCEEDED(adapter->GetDesc(desc))) { + json* gpu = new json(); + + (*gpu)["BrandModel"] = desc->Description; + (*gpu)["DedicatedRam"] = desc->DedicatedVideoMemory/1024/1024; + (*gpu)["SharedRam"] = desc->SharedSystemMemory / 1024 / 1024; + + UINT numModes = 0; + DXGI_MODE_DESC* displayModes = NULL; + DXGI_FORMAT format = DXGI_FORMAT_R32G32B32A32_FLOAT; + IDXGIOutput* output = NULL; + + if (SUCCEEDED(adapter->EnumOutputs(0, &output))) { + output->GetDisplayModeList(format, 0, &numModes, displayModes); + + DXGI_OUTPUT_DESC* desc; + + output->GetDesc(desc); + + //auto a = desc->Monitor; + //auto b = desc->DeviceName; + //figure out monitor info here + + } + + _gpu.push_back(gpu); + + } + } + } + + if (adapter) { + adapter->Release(); + } + if (factory) { + factory->Release(); + } + + +#endif +} + +void WINInstance::enumerateRam() { + json ram; MEMORYSTATUSEX statex; statex.dwLength = sizeof(statex); GlobalMemoryStatusEx(&statex); - return statex.ullTotalPhys / 1024 / 1024; + int totalRam = statex.ullTotalPhys / 1024 / 1024; + ram["totalMem"] = totalRam; + _memory.push_back(ram); } - - - - - diff --git a/libraries/platform/src/WINPlatform.h b/libraries/platform/src/WINPlatform.h index 1579767b60..542bebb5de 100644 --- a/libraries/platform/src/WINPlatform.h +++ b/libraries/platform/src/WINPlatform.h @@ -23,9 +23,10 @@ namespace platform { private: unsigned int getNumLogicalCores(); - void getCpuDetails(nlohmann::json& cpu); - int getTotalSystemRam(); -}; + void enumerateCpu(); + void enumerateRam(); + void enumerateGpu(); + }; } // namespace platform diff --git a/libraries/platform/src/platform.cpp b/libraries/platform/src/platform.cpp index 5ab2e7fbc2..c71b62bbd8 100644 --- a/libraries/platform/src/platform.cpp +++ b/libraries/platform/src/platform.cpp @@ -69,6 +69,37 @@ json Instance::getGPU(int index) { } +Instance::~Instance() { + //if (_processors.size() > 0) { + + // for (std::vector::iterator it = _processors.begin(); it != _processors.end(); ++it) { + // delete (*it); + // } + // + // _processors.clear(); + // + // } + // + // if (_memory.size() > 0) { + // for (std::vector::iterator it = _memory.begin(); it != _memory.end(); ++it) { + // delete (*it); + // } + // + // _memory.clear(); + // } + + + if (_gpu.size() > 0) { + for (std::vector::iterator it = _gpu.begin(); it != _gpu.end(); ++it) { + delete (*it); + } + + _gpu.clear(); + } + + +} + bool platform::enumerateProcessors() { return _instance->enumerateProcessors(); } diff --git a/libraries/platform/src/platform.h b/libraries/platform/src/platform.h index d539db4387..b14421ffff 100644 --- a/libraries/platform/src/platform.h +++ b/libraries/platform/src/platform.h @@ -27,11 +27,12 @@ public: int getNumGPU() { return _gpu.size(); } nlohmann::json getGPU(int index); + ~Instance(); protected: std::vector _processors; std::vector _memory; - std::vector _gpu; + std::vector _gpu; }; //Platform level functions