mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 21:12:53 +02:00
Exposing a lot more details about displays on mac
This commit is contained in:
parent
d406e52d71
commit
76836ebe9f
4 changed files with 113 additions and 1 deletions
|
@ -18,6 +18,9 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <cpuid.h>
|
#include <cpuid.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace platform;
|
using namespace platform;
|
||||||
|
@ -33,18 +36,124 @@ void MACOSInstance::enumerateCpu() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MACOSInstance::enumerateGpu() {
|
void MACOSInstance::enumerateGpu() {
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
/* uint32_t cglDisplayMask = -1; // Iterate over all of them.
|
||||||
|
CGLRendererInfoObj rendererInfo;
|
||||||
|
GLint rendererInfoCount;
|
||||||
|
CGLError err = CGLQueryRendererInfo(cglDisplayMask, &rendererInfo, &rendererInfoCount);
|
||||||
|
GLint j, numRenderers = 0, deviceVRAM, bestVRAM = 0;
|
||||||
|
err = CGLQueryRendererInfo(cglDisplayMask, &rendererInfo, &numRenderers);
|
||||||
|
if (0 == err) {
|
||||||
|
// Iterate over all of them and use the figure for the one with the most VRAM,
|
||||||
|
// on the assumption that this is the one that will actually be used.
|
||||||
|
CGLDescribeRenderer(rendererInfo, 0, kCGLRPRendererCount, &numRenderers);
|
||||||
|
for (j = 0; j < numRenderers; j++) {
|
||||||
|
CGLDescribeRenderer(rendererInfo, j, kCGLRPVideoMemoryMegabytes, &deviceVRAM);
|
||||||
|
if (deviceVRAM > bestVRAM) {
|
||||||
|
bestVRAM = deviceVRAM;
|
||||||
|
isValid = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//get gpu name
|
||||||
|
FILE* stream = popen("system_profiler SPDisplaysDataType | grep Chipset", "r");
|
||||||
|
|
||||||
|
std::ostringstream hostStream;
|
||||||
|
while (!feof(stream) && !ferror(stream)) {
|
||||||
|
char buf[128];
|
||||||
|
int bytesRead = fread(buf, 1, 128, stream);
|
||||||
|
hostStream.write(buf, bytesRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString result = QString::fromStdString(hostStream.str());
|
||||||
|
QStringList parts = result.split('\n');
|
||||||
|
std::string name;
|
||||||
|
|
||||||
|
for (int i = 0; i < parts.size(); ++i) {
|
||||||
|
if (parts[i].toLower().contains("radeon") || parts[i].toLower().contains("nvidia")) {
|
||||||
|
_name=parts[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_dedicatedMemoryMB = bestVRAM;
|
||||||
|
CGLDestroyRendererInfo(rendererInfo);
|
||||||
|
*/
|
||||||
|
|
||||||
|
// auto displayID = CGMainDisplayID();
|
||||||
|
// auto displayGLMask = CGDisplayIDToOpenGLDisplayMask(displayID);
|
||||||
|
// auto metalDevice = CGDirectDisplayCopyCurrentMetalDevice(displayID);
|
||||||
|
|
||||||
GPUIdent* ident = GPUIdent::getInstance();
|
GPUIdent* ident = GPUIdent::getInstance();
|
||||||
json gpu = {};
|
json gpu = {};
|
||||||
|
|
||||||
gpu[keys::gpu::vendor] = ident->getName().toUtf8().constData();
|
gpu[keys::gpu::vendor] = ident->getName().toUtf8().constData();
|
||||||
gpu[keys::gpu::model] = ident->getName().toUtf8().constData();
|
gpu[keys::gpu::model] = ident->getName().toUtf8().constData();
|
||||||
gpu[keys::gpu::videoMemory] = ident->getMemory();
|
gpu[keys::gpu::videoMemory] = ident->getMemory();
|
||||||
gpu[keys::gpu::driver] = ident->getDriver().toUtf8().constData();
|
gpu[keys::gpu::driver] = ident->getDriver().toUtf8().constData();
|
||||||
|
|
||||||
_gpu.push_back(gpu);
|
_gpu.push_back(gpu);
|
||||||
_display = ident->getOutput();
|
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MACOSInstance::enumerateDisplays() {
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
auto displayID = CGMainDisplayID();
|
||||||
|
auto displaySize = CGDisplayScreenSize(displayID);
|
||||||
|
auto displaySizeWidthInches = displaySize.width * 0.0393701;
|
||||||
|
auto displaySizeHeightInches = displaySize.height * 0.0393701;
|
||||||
|
auto displaySizeDiagonalInches = sqrt(displaySizeWidthInches * displaySizeWidthInches + displaySizeHeightInches * displaySizeHeightInches);
|
||||||
|
|
||||||
|
auto displayPixelsWidth= CGDisplayPixelsWide(displayID);
|
||||||
|
auto displayPixelsHeight= CGDisplayPixelsHigh(displayID);
|
||||||
|
auto displayBounds = CGDisplayBounds(displayID);
|
||||||
|
auto displayMaster =CGDisplayIsMain(displayID);
|
||||||
|
|
||||||
|
auto displayUnit =CGDisplayUnitNumber(displayID);
|
||||||
|
auto displayModel =CGDisplayModelNumber(displayID);
|
||||||
|
auto displayVendor = CGDisplayVendorNumber(displayID);
|
||||||
|
auto displaySerial = CGDisplaySerialNumber(displayID);
|
||||||
|
|
||||||
|
auto displayMode = CGDisplayCopyDisplayMode(displayID);
|
||||||
|
auto displayModeWidth = CGDisplayModeGetPixelWidth(displayMode);
|
||||||
|
auto displayModeHeight = CGDisplayModeGetPixelHeight(displayMode);
|
||||||
|
auto displayRefreshrate = CGDisplayModeGetRefreshRate(displayMode);
|
||||||
|
|
||||||
|
CGDisplayModeRelease(displayMode);
|
||||||
|
|
||||||
|
json display = {};
|
||||||
|
|
||||||
|
// display["physicalWidth"] = displaySizeWidthInches;
|
||||||
|
// display["physicalHeight"] = displaySizeHeightInches;
|
||||||
|
display["physicalDiagonal"] = displaySizeDiagonalInches;
|
||||||
|
|
||||||
|
// display["ppiH"] = displayModeWidth / displaySizeWidthInches;
|
||||||
|
// display["ppiV"] = displayModeHeight / displaySizeHeightInches;
|
||||||
|
display["ppi"] = sqrt(displayModeHeight * displayModeHeight + displayModeWidth * displayModeWidth) / displaySizeDiagonalInches;
|
||||||
|
|
||||||
|
display["coordLeft"] = displayBounds.origin.x;
|
||||||
|
display["coordRight"] = displayBounds.origin.x + displayBounds.size.width;
|
||||||
|
display["coordTop"] = displayBounds.origin.y;
|
||||||
|
display["coordBottom"] = displayBounds.origin.y + displayBounds.size.height;
|
||||||
|
|
||||||
|
display["isMaster"] = displayMaster;
|
||||||
|
|
||||||
|
display["unit"] = displayUnit;
|
||||||
|
display["vendor"] = displayVendor;
|
||||||
|
display["model"] = displayModel;
|
||||||
|
display["serial"] = displaySerial;
|
||||||
|
|
||||||
|
display["refreshrate"] =displayRefreshrate;
|
||||||
|
display["modeWidth"] = displayModeWidth;
|
||||||
|
display["modeHeight"] = displayModeHeight;
|
||||||
|
|
||||||
|
|
||||||
|
_display.push_back(display);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void MACOSInstance::enumerateMemory() {
|
void MACOSInstance::enumerateMemory() {
|
||||||
json ram = {};
|
json ram = {};
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ namespace platform {
|
||||||
void enumerateCpu() override;
|
void enumerateCpu() override;
|
||||||
void enumerateMemory() override;
|
void enumerateMemory() override;
|
||||||
void enumerateGpu() override;
|
void enumerateGpu() override;
|
||||||
|
void enumerateDisplays() override;
|
||||||
void enumerateComputer () override;
|
void enumerateComputer () override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ bool Instance::enumeratePlatform() {
|
||||||
enumerateComputer();
|
enumerateComputer();
|
||||||
enumerateCpu();
|
enumerateCpu();
|
||||||
enumerateGpu();
|
enumerateGpu();
|
||||||
|
enumerateDisplays();
|
||||||
enumerateMemory();
|
enumerateMemory();
|
||||||
|
|
||||||
// And profile the platform and put the tier in "computer"
|
// And profile the platform and put the tier in "computer"
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
void virtual enumerateCpu()=0;
|
void virtual enumerateCpu()=0;
|
||||||
void virtual enumerateMemory()=0;
|
void virtual enumerateMemory()=0;
|
||||||
void virtual enumerateGpu()=0;
|
void virtual enumerateGpu()=0;
|
||||||
|
void virtual enumerateDisplays() {}
|
||||||
void virtual enumerateComputer()=0;
|
void virtual enumerateComputer()=0;
|
||||||
|
|
||||||
virtual ~Instance();
|
virtual ~Instance();
|
||||||
|
|
Loading…
Reference in a new issue