22 #include <sys/sysinfo.h>
26 #if defined(IS_OSX) || defined(IS_FREEBSD)
27 #include <sys/sysctl.h>
32 #ifndef WIN32_LEAN_AND_MEAN
33 #define WIN32_LEAN_AND_MEAN 1
39 #if defined(__i386) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64)
41 #if defined(__GNUC__) && !defined(__APPLE__)
54 uint32_t eax, ebx, ecx, edx;
61 static inline void get_cpuid(uint32_t leaf, cpuid_info &info) {
62 #if defined(__GNUC__) && !defined(__APPLE__)
63 __cpuid(leaf, info.eax, info.ebx, info.ecx, info.edx);
64 #elif defined(_MSC_VER)
65 __cpuid((
int *)info.str, leaf);
68 :
"=a" (info.eax),
"=b" (info.ebx),
"=c" (info.ecx),
"=d" (info.edx)
76 static inline uint32_t get_cpuid_max(uint32_t leaf) {
77 #if defined(__GNUC__) && !defined(__APPLE__)
78 return __get_cpuid_max(leaf,
nullptr);
81 get_cpuid(leaf, info);
92 struct sysinfo meminfo;
93 if (sysinfo(&meminfo) == 0) {
94 info->_physical_memory = meminfo.totalram;
95 info->_available_physical_memory = meminfo.freeram;
96 info->_page_file_size = meminfo.totalswap;
97 info->_available_page_file_size = meminfo.freeswap;
103 static PN_stdfloat detected_display_zoom = 1.0;
112 _lock(
"GraphicsPipe")
120 _supported_types = 0;
127 #if defined(__i386) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64)
129 const uint32_t max_cpuid = get_cpuid_max(0);
130 const uint32_t max_extended = get_cpuid_max(0x80000000);
132 if (max_cpuid >= 1) {
134 std::swap(info.ecx, info.edx);
135 _display_information->_cpu_vendor_string = std::string(info.str + 4, 12);
138 _display_information->_cpu_version_information = info.eax;
139 _display_information->_cpu_brand_index = info.ebx & 0xff;
142 if (max_extended >= 0x80000004) {
144 get_cpuid(0x80000002, info);
145 memcpy(brand, info.str, 16);
146 get_cpuid(0x80000003, info);
147 memcpy(brand + 16, info.str, 16);
148 get_cpuid(0x80000004, info);
149 memcpy(brand + 32, info.str, 16);
151 _display_information->_cpu_brand_string = brand;
157 size_t len =
sizeof(uint64_t);
158 sysctlbyname(
"hw.memsize", &_display_information->_physical_memory, &len,
nullptr, 0);
159 len =
sizeof(uint64_t);
160 sysctlbyname(
"hw.cpufrequency", &_display_information->_cpu_frequency, &len,
nullptr, 0);
161 len =
sizeof(uint64_t);
162 sysctlbyname(
"hw.cpufrequency", &_display_information->_current_cpu_frequency, &len,
nullptr, 0);
163 len =
sizeof(uint64_t);
164 sysctlbyname(
"hw.cpufrequency_max", &_display_information->_maximum_cpu_frequency, &len,
nullptr, 0);
166 sysctlbyname(
"hw.physicalcpu", &_display_information->_num_cpu_cores, &len,
nullptr, 0);
168 sysctlbyname(
"hw.logicalcpu", &_display_information->_num_logical_cpus, &len,
nullptr, 0);
170 #elif defined(IS_LINUX)
171 _display_information->_get_memory_information_function = &update_memory_info;
172 update_memory_info(_display_information);
174 #elif defined(IS_FREEBSD)
175 size_t len =
sizeof(uint64_t);
176 sysctlbyname(
"hw.physmem", &_display_information->_physical_memory, &len,
nullptr, 0);
177 len =
sizeof(uint64_t);
178 sysctlbyname(
"vm.swap_total", &_display_information->_page_file_size, &len,
nullptr, 0);
180 #elif defined(_WIN32)
181 MEMORYSTATUSEX status;
182 status.dwLength =
sizeof(MEMORYSTATUSEX);
183 if (GlobalMemoryStatusEx(&status)) {
184 _display_information->_physical_memory = status.ullTotalPhys;
185 _display_information->_available_physical_memory = status.ullAvailPhys;
186 _display_information->_page_file_size = status.ullTotalPageFile;
187 _display_information->_available_page_file_size = status.ullAvailPageFile;
188 _display_information->_process_virtual_memory = status.ullTotalVirtual;
189 _display_information->_available_process_virtual_memory = status.ullAvailVirtual;
190 _display_information->_memory_load = status.dwMemoryLoad;
194 #if defined(IS_LINUX) || defined(IS_FREEBSD)
195 long nproc = sysconf(_SC_NPROCESSORS_CONF);
197 _display_information->_num_logical_cpus = nproc;
207 delete _display_information;
215 GraphicsPipe::PreferredWindowThread
236 make_device(
void *scrn) {
238 <<
"make_device() unimplemented by " << get_type() <<
"\n";
251 if (gsg !=
nullptr) {
260 make_output(
const std::string &name,
270 << get_type() <<
" cannot create buffers or windows.\n";
287 double override = display_zoom.
get_value();
288 if (
override != 0.0) {
292 return detected_display_zoom;
299 set_detected_display_zoom(PN_stdfloat zoom) {
300 detected_display_zoom = zoom;
308 return _display_information;
get_value
Returns the variable's value.
size_t get_num_words() const
Returns the number of words in the variable's value.
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
An abstract device object that is part of Graphics Pipe.
This class is the main interface to controlling the render process.
This is a base class for the various different classes that represent the result of a frame of render...
get_display_zoom
Returns the display zoom factor configured in the operating system.
get_display_information
Gets the pipe's DisplayInformation.
virtual void lookup_cpu_data()
Looks up the detailed CPU information and stores it in _display_information, if supported by the OS.
virtual PreferredWindowThread get_preferred_window_thread() const
Returns an indication of the thread in which this GraphicsPipe requires its window processing to be p...
Encapsulates all the communication with a particular instance of a given rendering backend.
TypeHandle is the identifier used to differentiate C++ class types.
A container for the various kinds of properties we might ask to have on a graphics window before we o...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PT(GraphicsStateGuardian) GraphicsPipe
This is called when make_output() is used to create a CallbackGraphicsWindow.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.