diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index cd329e109a..b022984bb7 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -228,6 +228,7 @@ target_bullet() target_opengl() add_crashpad() target_breakpad() +target_json() # perform standard include and linking for found externals foreach(EXTERNAL ${OPTIONAL_EXTERNALS}) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b13fd3dda9..48c3ae594a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -196,6 +196,8 @@ #include "scripting/RefreshRateScriptingInterface.h" +#include +#include #if defined(Q_OS_MAC) || defined(Q_OS_WIN) #include "SpeechRecognizer.h" @@ -245,7 +247,7 @@ #include "webbrowser/WebBrowserSuggestionsEngine.h" #include - +#include #include "AboutUtil.h" #include @@ -1032,6 +1034,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _sampleSound(nullptr) { + initPlatform(); auto steamClient = PluginManager::getInstance()->getSteamClientPlugin(); setProperty(hifi::properties::STEAM, (steamClient && steamClient->isRunning())); setProperty(hifi::properties::CRASHED, _previousSessionCrashed); @@ -2486,6 +2489,18 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo pauseUntilLoginDetermined(); } +void Application::initPlatform() { + + platform::create(); + + platform::enumeratePlatform(); + + nlohmann::json test = platform::getGraphics(0); + nlohmann::json test1 = platform::getProcessor(0); + nlohmann::json test2 = platform::getMemory(0); + nlohmann::json test3 = platform::getDisplay(0); +} + void Application::updateVerboseLogging() { auto menu = Menu::getInstance(); if (!menu) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 94e983290e..69db555d56 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -130,6 +130,9 @@ public: virtual bool makeRenderingContextCurrent() override; virtual bool isForeground() const override; + //test + void initPlatform(); + virtual DisplayPluginPointer getActiveDisplayPlugin() const override; // FIXME? Empty methods, do we still need them? diff --git a/libraries/platform/src/WINPlatform.cpp b/libraries/platform/src/WINPlatform.cpp index c29f29483e..21997a6fbe 100644 --- a/libraries/platform/src/WINPlatform.cpp +++ b/libraries/platform/src/WINPlatform.cpp @@ -10,27 +10,22 @@ #include #include #include +#include +#include - -#ifdef Q_OS_WINDOWS -#include -#include -#endif - using namespace platform; using namespace nlohmann; -bool WINInstance::enumerateProcessors() { +bool WINInstance::enumeratePlatform() { enumerateCpu(); enumerateGpu(); enumerateRam(); - return true; } void WINInstance::enumerateCpu() { - json cpu; + json *cpu= new json(); int CPUInfo[4] = { -1 }; unsigned nExIds; unsigned int i = 0; @@ -54,12 +49,12 @@ void WINInstance::enumerateCpu() { } } - cpu["brand"] = CPUBrandString; - cpu["model"] = CPUModelString; - cpu["clockSpeed"] = CPUClockString; - cpu["numCores"] = getNumLogicalCores(); + (*cpu)["brand"] = CPUBrandString; + (*cpu)["model"] = CPUModelString; + (*cpu)["clockSpeed"] = CPUClockString; + (*cpu)["numCores"] = getNumLogicalCores(); - _processors.push_back(cpu); + _cpu.push_back(cpu); } unsigned int WINInstance::getNumLogicalCores() { @@ -67,65 +62,26 @@ unsigned int WINInstance::getNumLogicalCores() { } 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; + GPUIdent* ident = GPUIdent::getInstance(); + + json *gpu = new json(); + (*gpu)["name"] = ident->getName().toUtf8().constData(); + (*gpu)["memory"] = ident->getMemory(); + (*gpu)["driver"] = ident->getDriver().toUtf8().constData(); - 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 + _gpu.push_back(gpu); + _display = ident->getOutput(); } void WINInstance::enumerateRam() { - json ram; + json* ram = new json(); + MEMORYSTATUSEX statex; statex.dwLength = sizeof(statex); GlobalMemoryStatusEx(&statex); int totalRam = statex.ullTotalPhys / 1024 / 1024; - ram["totalMem"] = totalRam; + (*ram)["totalMem"] = totalRam; + _memory.push_back(ram); } diff --git a/libraries/platform/src/WINPlatform.h b/libraries/platform/src/WINPlatform.h index 542bebb5de..198fad5b77 100644 --- a/libraries/platform/src/WINPlatform.h +++ b/libraries/platform/src/WINPlatform.h @@ -19,7 +19,7 @@ namespace platform { class WINInstance : public Instance { public: - bool enumerateProcessors(); + bool enumeratePlatform(); private: unsigned int getNumLogicalCores(); diff --git a/libraries/platform/src/platform.cpp b/libraries/platform/src/platform.cpp index c71b62bbd8..a6ae58e305 100644 --- a/libraries/platform/src/platform.cpp +++ b/libraries/platform/src/platform.cpp @@ -35,19 +35,23 @@ void platform::create() { #endif } -json Instance::getProcessor(int index) { +void platform::destroy() { + delete _instance; +} + +json Instance::getCPU(int index) { assert(index < _processor.size()); json result; - if (index >= _processors.size()) + if (index >= _cpu.size()) return result; - return _processors.at(index); + return _cpu.at(index); } //These are ripe for template.. will work on that next -json Instance::getSystemRam(int index) { +json Instance::getMemory(int index) { assert(index < _memory.size()); @@ -68,25 +72,34 @@ json Instance::getGPU(int index) { return _gpu.at(index); } +json Instance::getDisplay(int index) { + assert(index < _display.size()); + + json result; + if (index >= _display.size()) + return result; + + return _display.at(index); +} Instance::~Instance() { - //if (_processors.size() > 0) { + if (_cpu.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(); - // } + for (std::vector::iterator it = _cpu.begin(); it != _cpu.end(); ++it) { + delete (*it); + } + + _cpu.clear(); + + } + + if (_memory.size() > 0) { + for (std::vector::iterator it = _memory.begin(); it != _memory.end(); ++it) { + delete (*it); + } + + _memory.clear(); + } if (_gpu.size() > 0) { @@ -97,25 +110,48 @@ Instance::~Instance() { _gpu.clear(); } + if (_display.size() > 0) { + for (std::vector::iterator it = _display.begin(); it != _display.end(); ++it) { + delete (*it); + } + _display.clear(); + } } -bool platform::enumerateProcessors() { - return _instance->enumerateProcessors(); +bool platform::enumeratePlatform() { + return _instance->enumeratePlatform(); +} + +int platform::getNumProcessor() { + return _instance->getNumCPU(); } json platform::getProcessor(int index) { - return _instance->getProcessor(index); + return _instance->getCPU(index); } -json platform::getSystemRam(int index) { - return _instance->getSystemRam(index); +int platform::getNumGraphics() { + return _instance->getNumGPU(); +} + +nlohmann::json platform::getGraphics(int index) { + return _instance->getGPU(index); +} + +int platform::getNumDisplay() { + return _instance->getNumDisplay(); +} + +nlohmann::json platform::getDisplay(int index) { + return _instance->getDisplay(index); +} + +json platform::getMemory(int index) { + return _instance->getMemory(index); } int platform::getNumMemory() { return _instance->getNumMemory(); } -int platform::getNumProcessor() { - return _instance->getNumProcessor(); -} \ No newline at end of file diff --git a/libraries/platform/src/platform.h b/libraries/platform/src/platform.h index b14421ffff..db78502fa4 100644 --- a/libraries/platform/src/platform.h +++ b/libraries/platform/src/platform.h @@ -12,37 +12,53 @@ #include #include #include + + namespace platform { class Instance { public: - bool virtual enumerateProcessors() = 0; + bool virtual enumeratePlatform() = 0; - int getNumProcessor() { return _processors.size(); } - nlohmann::json getProcessor(int index); - - int getNumMemory() { return _memory.size(); } - nlohmann::json getSystemRam(int index); + int getNumCPU() { return _cpu.size(); } + nlohmann::json getCPU(int index); int getNumGPU() { return _gpu.size(); } nlohmann::json getGPU(int index); + int getNumMemory() { return _memory.size(); } + nlohmann::json getMemory(int index); + + int getNumDisplay() { return _display.size(); } + nlohmann::json getDisplay(int index); + ~Instance(); protected: - std::vector _processors; - std::vector _memory; + std::vector _cpu; + std::vector _memory; std::vector _gpu; + std::vector _display; + }; //Platform level functions void create(); +void destroy(); + +bool enumeratePlatform(); -bool enumerateProcessors(); int getNumProcessor(); nlohmann::json getProcessor(int index); + +int getNumGraphics(); +nlohmann::json getGraphics(int index); + +int getNumDisplay(); +nlohmann::json getDisplay(int index); + int getNumMemory(); -nlohmann::json getSystemRam(int index); +nlohmann::json getMemory(int index); } // namespace platform diff --git a/libraries/shared/CMakeLists.txt b/libraries/shared/CMakeLists.txt index 713501aa77..81e85c0d85 100644 --- a/libraries/shared/CMakeLists.txt +++ b/libraries/shared/CMakeLists.txt @@ -13,3 +13,4 @@ endif() target_zlib() target_nsight() +target_json() diff --git a/libraries/shared/src/GPUIdent.cpp b/libraries/shared/src/GPUIdent.cpp index 3b7a6cee40..2fc29e0d19 100644 --- a/libraries/shared/src/GPUIdent.cpp +++ b/libraries/shared/src/GPUIdent.cpp @@ -12,6 +12,7 @@ #ifdef Q_OS_WIN #include +#include //#include //#include @@ -250,6 +251,26 @@ GPUIdent* GPUIdent::ensureQuery(const QString& vendor, const QString& renderer) */ if (!validAdapterList.empty()) { + + for (auto outy = adapterToOutputs.begin(); outy != adapterToOutputs.end(); outy++) { + + AdapterEntry entry = *outy; + + entry.first.first.Description; + for (auto test = entry.second.begin(); test != entry.second.end(); test++) { + nlohmann::json* output = new nlohmann::json(); + (*output)["description"] = entry.first.first.Description; + (*output)["deviceName"]= test->DeviceName; + (*output)["coordinatesleft"] = test->DesktopCoordinates.left; + (*output)["coordinatesright"] = test->DesktopCoordinates.right; + (*output)["coordinatestop"] = test->DesktopCoordinates.top; + (*output)["coordinatesbottom"] = test->DesktopCoordinates.bottom; + _output.push_back(output); + + } + + } + auto& adapterEntry = adapterToOutputs[validAdapterList.front()]; std::wstring wDescription(adapterEntry.first.first.Description); diff --git a/libraries/shared/src/GPUIdent.h b/libraries/shared/src/GPUIdent.h index f780a4ddbd..8bb3a33d44 100644 --- a/libraries/shared/src/GPUIdent.h +++ b/libraries/shared/src/GPUIdent.h @@ -15,19 +15,25 @@ #define hifi_GPUIdent_h #include - #include +#include +#include +#include class GPUIdent { + public: uint64_t getMemory() { return _dedicatedMemoryMB; } QString getName() { return _name; } QString getDriver() { return _driver; } bool isValid() { return _isValid; } + std::vector getOutput() { return _output; } + // E.g., GPUIdent::getInstance()->getMemory(); static GPUIdent* getInstance(const QString& vendor = "", const QString& renderer = "") { return _instance.ensureQuery(vendor, renderer); } private: + std::vector _output; uint64_t _dedicatedMemoryMB { 0 }; QString _name { "" }; QString _driver { "" };