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

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