clean up etc

This commit is contained in:
Samuel Gateau 2019-07-05 13:23:19 +02:00
parent 4cc3800384
commit 0c26d3ef66
4 changed files with 87 additions and 75 deletions

View file

@ -44,15 +44,13 @@ namespace platform { namespace keys{
extern const char* boundsTop; extern const char* boundsTop;
extern const char* boundsBottom; extern const char* boundsBottom;
extern const char* gpu; extern const char* gpu;
extern const char* ppiHorizontal;
extern const char* ppiVertical;
extern const char* ppi; extern const char* ppi;
extern const char* ppiDesktop;
extern const char* physicalWidth; extern const char* physicalWidth;
extern const char* physicalHeight; extern const char* physicalHeight;
extern const char* modeRefreshrate; extern const char* modeRefreshrate;
extern const char* modeWidth; extern const char* modeWidth;
extern const char* modeHeight; extern const char* modeHeight;
extern const char* desktopPpi;
extern const char* isMaster; extern const char* isMaster;
} }
namespace memory { namespace memory {

View file

@ -100,8 +100,6 @@ void MACOSInstance::enumerateGpusAndDisplays() {
display[keys::display::boundsBottom] = displayBounds.origin.y + displayBounds.size.height; display[keys::display::boundsBottom] = displayBounds.origin.y + displayBounds.size.height;
// PPI & resolution // PPI & resolution
display[keys::display::ppiHorizontal] = ppiH;
display[keys::display::ppiVertical] = ppiV;
display[keys::display::physicalWidth] = displaySizeWidthInches; display[keys::display::physicalWidth] = displaySizeWidthInches;
display[keys::display::physicalHeight] = displaySizeHeightInches; display[keys::display::physicalHeight] = displaySizeHeightInches;
display[keys::display::modeWidth] = displayModeWidth; display[keys::display::modeWidth] = displayModeWidth;
@ -109,7 +107,7 @@ void MACOSInstance::enumerateGpusAndDisplays() {
//Average the ppiH and V for the simple ppi //Average the ppiH and V for the simple ppi
display[keys::display::ppi] = std::round(0.5f * (ppiH + ppiV)); display[keys::display::ppi] = std::round(0.5f * (ppiH + ppiV));
display[keys::display::desktopPpi] = std::round(0.5f * (ppiHScaled + ppiVScaled)); display[keys::display::ppiDesktop] = std::round(0.5f * (ppiHScaled + ppiVScaled));
// refreshrate // refreshrate
display[keys::display::modeRefreshrate] = displayRefreshrate; display[keys::display::modeRefreshrate] = displayRefreshrate;

View file

@ -45,15 +45,13 @@ namespace platform { namespace keys {
const char* boundsTop = "boundsTop"; const char* boundsTop = "boundsTop";
const char* boundsBottom = "boundsBottom"; const char* boundsBottom = "boundsBottom";
const char* gpu = "gpu"; const char* gpu = "gpu";
const char* ppiHorizontal = "ppiHorizontal";
const char* ppiVertical = "ppiHorizontal";
const char* ppi = "ppi"; const char* ppi = "ppi";
const char* ppiDesktop = "ppiDesktop";
const char* physicalWidth = "physicalWidth"; const char* physicalWidth = "physicalWidth";
const char* physicalHeight = "physicalHeight"; const char* physicalHeight = "physicalHeight";
const char* modeRefreshrate = "modeRefreshrate"; const char* modeRefreshrate = "modeRefreshrate";
const char* modeWidth = "modeWidth"; const char* modeWidth = "modeWidth";
const char* modeHeight = "modeHeight"; const char* modeHeight = "modeHeight";
const char* desktopPpi = "desktopPpi";
const char* isMaster = "isMaster"; const char* isMaster = "isMaster";
} }
namespace memory { namespace memory {

View file

@ -81,90 +81,108 @@ void WINInstance::enumerateGpusAndDisplays() {
// Found an adapter, get descriptor // Found an adapter, get descriptor
DXGI_ADAPTER_DESC1 adapterDesc; DXGI_ADAPTER_DESC1 adapterDesc;
pAdapter->GetDesc1(&adapterDesc); pAdapter->GetDesc1(&adapterDesc);
// Only describe gpu if it is a hardware adapter
if (!(adapterDesc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)) {
LARGE_INTEGER version;
hr = pAdapter->CheckInterfaceSupport(__uuidof(IDXGIDevice), &version);
LARGE_INTEGER version; std::wstring wDescription(adapterDesc.Description);
hr = pAdapter->CheckInterfaceSupport(__uuidof(IDXGIDevice), &version); std::string description(wDescription.begin(), wDescription.end());
std::wstring wDescription(adapterDesc.Description); json gpu = {};
std::string description(wDescription.begin(), wDescription.end()); gpu[keys::gpu::model] = description;
gpu[keys::gpu::vendor] = findGPUVendorInDescription(gpu[keys::gpu::model].get<std::string>());
const SIZE_T BYTES_PER_MEGABYTE = 1024 * 1024;
gpu[keys::gpu::videoMemory] = (uint32_t)(adapterDesc.DedicatedVideoMemory / BYTES_PER_MEGABYTE);
gpu[keys::gpu::driver] = convertDriverVersionToString.convert(version);
json gpu = {}; std::vector<int> displayIndices;
gpu[keys::gpu::model] = description;
gpu[keys::gpu::vendor] = findGPUVendorInDescription(gpu[keys::gpu::model].get<std::string>());
const SIZE_T BYTES_PER_MEGABYTE = 1024 * 1024;
gpu[keys::gpu::videoMemory] = (uint32_t)(adapterDesc.DedicatedVideoMemory / BYTES_PER_MEGABYTE);
gpu[keys::gpu::driver] = convertDriverVersionToString.convert(version);
std::vector<int> displayIndices; UINT outputNum = 0;
IDXGIOutput* pOutput;
bool hasOutputConnectedToDesktop = false;
while (pAdapter->EnumOutputs(outputNum, &pOutput) != DXGI_ERROR_NOT_FOUND) {
// FOund an output attached to the adapter, get descriptor
DXGI_OUTPUT_DESC outputDesc;
pOutput->GetDesc(&outputDesc);
pOutput->Release();
outputNum++;
UINT outputNum = 0; // Grab the monitor info
IDXGIOutput* pOutput; MONITORINFO monitorInfo;
bool hasOutputConnectedToDesktop = false; monitorInfo.cbSize = sizeof(MONITORINFO);
while (pAdapter->EnumOutputs(outputNum, &pOutput) != DXGI_ERROR_NOT_FOUND) { GetMonitorInfo(outputDesc.Monitor, &monitorInfo);
// FOund an output attached to the adapter, get descriptor
DXGI_OUTPUT_DESC outputDesc;
pOutput->GetDesc(&outputDesc);
// Grab the dpi info for the monitor // Grab the dpi info for the monitor
UINT dpiX{ 0 }; UINT dpiX{ 0 };
UINT dpiY{ 0 }; UINT dpiY{ 0 };
GetDpiForMonitor(outputDesc.Monitor, MDT_RAW_DPI, &dpiX, &dpiY); GetDpiForMonitor(outputDesc.Monitor, MDT_RAW_DPI, &dpiX, &dpiY);
UINT dpiXScaled{ 0 }; UINT dpiXScaled{ 0 };
UINT dpiYScaled{ 0 }; UINT dpiYScaled{ 0 };
GetDpiForMonitor(outputDesc.Monitor, MDT_EFFECTIVE_DPI, &dpiXScaled, &dpiYScaled); GetDpiForMonitor(outputDesc.Monitor, MDT_EFFECTIVE_DPI, &dpiXScaled, &dpiYScaled);
// CUrrent display mode // CUrrent display mode
DEVMODEW devMode; DEVMODEW devMode;
devMode.dmSize = sizeof(DEVMODEW); devMode.dmSize = sizeof(DEVMODEW);
EnumDisplaySettingsW(outputDesc.DeviceName, ENUM_CURRENT_SETTINGS, &devMode); EnumDisplaySettingsW(outputDesc.DeviceName, ENUM_CURRENT_SETTINGS, &devMode);
json display = {}; json display = {};
// Display name // Display name
std::wstring wDeviceName(outputDesc.DeviceName); std::wstring wDeviceName(outputDesc.DeviceName);
std::string deviceName(wDeviceName.begin(), wDeviceName.end()); std::string deviceName(wDeviceName.begin(), wDeviceName.end());
display[keys::display::name] = deviceName; display[keys::display::name] = deviceName;
display[keys::display::description] = ""; display[keys::display::description] = "";
// Rect region of the desktop in desktop units // Rect region of the desktop in desktop units
//display["desktopRect"] = (outputDesc.AttachedToDesktop ? true : false); //display["desktopRect"] = (outputDesc.AttachedToDesktop ? true : false);
display[keys::display::boundsLeft] = outputDesc.DesktopCoordinates.left; display[keys::display::boundsLeft] = outputDesc.DesktopCoordinates.left;
display[keys::display::boundsRight] = outputDesc.DesktopCoordinates.right; display[keys::display::boundsRight] = outputDesc.DesktopCoordinates.right;
display[keys::display::boundsBottom] = outputDesc.DesktopCoordinates.bottom; display[keys::display::boundsBottom] = outputDesc.DesktopCoordinates.bottom;
display[keys::display::boundsTop] = outputDesc.DesktopCoordinates.top; display[keys::display::boundsTop] = outputDesc.DesktopCoordinates.top;
// PPI & resolution // PPI & resolution
display[keys::display::ppiHorizontal] = dpiX; display[keys::display::physicalWidth] = devMode.dmPelsWidth / (float) dpiX;
display[keys::display::ppiVertical] = dpiY; display[keys::display::physicalHeight] = devMode.dmPelsHeight / (float) dpiY;
display[keys::display::physicalWidth] = devMode.dmPelsWidth / (float) dpiX; display[keys::display::modeWidth] = devMode.dmPelsWidth;
display[keys::display::physicalHeight] = devMode.dmPelsHeight / (float) dpiY; display[keys::display::modeHeight] = devMode.dmPelsHeight;
display[keys::display::modeWidth] = devMode.dmPelsWidth;
display[keys::display::modeHeight] = devMode.dmPelsHeight;
//Average the ppiH and V for the simple ppi //Average the ppiH and V for the simple ppi
display[keys::display::ppi] = std::round(0.5f * (dpiX + dpiY)); display[keys::display::ppi] = std::round(0.5f * (dpiX + dpiY));
display[keys::display::desktopPpi] = std::round(0.5f * (dpiXScaled + dpiYScaled)); display[keys::display::ppiDesktop] = std::round(0.5f * (dpiXScaled + dpiYScaled));
// refreshrate // refreshrate
display[keys::display::modeRefreshrate] = devMode.dmDisplayFrequency;; display[keys::display::modeRefreshrate] = devMode.dmDisplayFrequency;;
// Master display ? // Master display ?
display[keys::display::isMaster] = true; display[keys::display::isMaster] = (bool) (monitorInfo.dwFlags & MONITORINFOF_PRIMARY);
// Add the display index to the list of displays of the gpu // Add the display index to the list of displays of the gpu
displayIndices.push_back(_displays.size()); displayIndices.push_back((int) _displays.size());
// And set the gpu index to the display description // And set the gpu index to the display description
display[keys::display::gpu] = _gpus.size(); display[keys::display::gpu] = (int) _gpus.size();
// One more display desc // WIN specific
_displays.push_back(display); display["win_workLeft"] = monitorInfo.rcWork.left;
pOutput->Release(); display["win_workRight"] = monitorInfo.rcWork.right;
outputNum++; display["win_workTop"] = monitorInfo.rcWork.top;
display["win_workBottom"] = monitorInfo.rcWork.bottom;
display["win_monLeft"] = monitorInfo.rcMonitor.left;
display["win_monRight"] = monitorInfo.rcMonitor.right;
display["win_monTop"] = monitorInfo.rcMonitor.top;
display["win_monBottom"] = monitorInfo.rcMonitor.bottom;
// One more display desc
_displays.push_back(display);
}
gpu[keys::gpu::displays] = displayIndices;
_gpus.push_back(gpu);
} }
gpu[keys::gpu::displays] = displayIndices;
_gpus.push_back(gpu);
pAdapter->Release(); pAdapter->Release();
adapterNum++; adapterNum++;
} }