Panda3D
displayInformation.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file displayInformation.cxx
10 * @author aignacio
11 * @date 2007-01-17
12 */
13
15#include "displayInformation.h"
16
17// For __rdtsc
18#if defined(__i386) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64)
19#ifdef _MSC_VER
20#include <intrin.h>
21#elif defined(__GNUC__) && !defined(__clang__)
22#include <x86intrin.h>
23#endif
24#endif
25
26/**
27 * Returns true if these two DisplayModes are identical.
28 */
30operator == (const DisplayMode &other) const {
31 return (width == other.width && height == other.height &&
32 bits_per_pixel == other.bits_per_pixel &&
33 refresh_rate == other.refresh_rate &&
34 fullscreen_only == other.fullscreen_only);
35}
36
37/**
38 * Returns false if these two DisplayModes are identical.
39 */
41operator != (const DisplayMode &other) const {
42 return !operator == (other);
43}
44
45/**
46 *
47 */
48void DisplayMode::
49output(std::ostream &out) const {
50 out << width << 'x' << height;
51 if (bits_per_pixel > 0) {
52 out << ' ' << bits_per_pixel << "bpp";
53 }
54 if (refresh_rate > 0) {
55 out << ' ' << refresh_rate << "Hz";
56 }
57 if (fullscreen_only > 0) {
58 out << " (fullscreen only)";
59 }
60}
61
62/**
63 *
64 */
65DisplayInformation::
66~DisplayInformation() {
67 if (_display_mode_array != nullptr) {
68 delete[] _display_mode_array;
69 }
70}
71
72/**
73 *
74 */
75DisplayInformation::
76DisplayInformation() {
77 DisplayInformation::DetectionState state;
78 int get_adapter_display_mode_state;
79 int get_device_caps_state;
80 int window_width;
81 int window_height;
82 int window_bits_per_pixel;
83 int total_display_modes;
84 DisplayMode *display_mode_array;
85 int video_memory;
86 int texture_memory;
87 uint64_t physical_memory;
88 uint64_t available_physical_memory;
89
90 state = DisplayInformation::DS_unknown;
91 get_adapter_display_mode_state = false;
92 get_device_caps_state = false;
93 window_width = 0;
94 window_height = 0;
95 window_bits_per_pixel = 0;
96 total_display_modes = 0;
97 display_mode_array = nullptr;
98 video_memory = 0;
99 texture_memory = 0;
100 physical_memory = 0;
101 available_physical_memory = 0;
102
103 _state = state;
104 _get_adapter_display_mode_state = get_adapter_display_mode_state;
105 _get_device_caps_state = get_device_caps_state;
106 _maximum_window_width = window_width;
107 _maximum_window_height = window_height;
108 _window_bits_per_pixel = window_bits_per_pixel;
109 _total_display_modes = total_display_modes;
110 _display_mode_array = display_mode_array;
111 _shader_model = GraphicsStateGuardian::SM_00;
112 _video_memory = video_memory;
113 _texture_memory = texture_memory;
114
115 _physical_memory = physical_memory;
116 _available_physical_memory = available_physical_memory;
117 _page_file_size = 0;
118 _available_page_file_size = 0;
119 _process_virtual_memory = 0;
120 _available_process_virtual_memory = 0;
121 _memory_load = 0;
122 _page_fault_count = 0;
123 _process_memory = 0;
124 _peak_process_memory = 0;
125 _page_file_usage = 0;
126 _peak_page_file_usage = 0;
127
128 _vendor_id = 0;
129 _device_id = 0;
130
131 _driver_product = 0;
132 _driver_version = 0;
133 _driver_sub_version = 0;
134 _driver_build = 0;
135
136 _driver_date_month = 0;
137 _driver_date_day = 0;
138 _driver_date_year = 0;
139
140 _cpu_version_information = 0;
141 _cpu_brand_index = 0;
142
143 _cpu_frequency = 0;
144
145 _maximum_cpu_frequency = 0;
146 _current_cpu_frequency = 0;
147
148 _num_cpu_cores = 0;
149 _num_logical_cpus = 0;
150
151 _get_memory_information_function = nullptr;
152 _update_cpu_frequency_function = nullptr;
153
154 _os_version_major = -1;
155 _os_version_minor = -1;
156 _os_version_build = -1;
157 _os_platform_id = -1;
158}
159
160/**
161 *
162 */
163int DisplayInformation::get_display_state() {
164 return _state;
165}
166
167/**
168 *
169 */
170int DisplayInformation::
171get_maximum_window_width() {
172 return _maximum_window_width;
173}
174
175/**
176 *
177 */
178int DisplayInformation::
179get_maximum_window_height() {
180 return _maximum_window_height;
181}
182
183/**
184 *
185 */
186int DisplayInformation::
187get_window_bits_per_pixel() {
188 return _window_bits_per_pixel;
189}
190
191/**
192 *
193 */
194int DisplayInformation::
195get_total_display_modes() {
196 return _total_display_modes;
197}
198
199/**
200 *
201 */
202const DisplayMode &DisplayInformation::
203get_display_mode(int display_index) {
204#ifndef NDEBUG
205 static DisplayMode err_mode = {0};
206 nassertr(display_index >= 0 && display_index < _total_display_modes, err_mode);
207#endif
208
209 return _display_mode_array[display_index];
210}
211
212/**
213 *
214 */
215int DisplayInformation::
216get_display_mode_width (int display_index) {
217 int value;
218
219 value = 0;
220 if (display_index >= 0 && display_index < _total_display_modes) {
221 value = _display_mode_array [display_index].width;
222 }
223
224 return value;
225}
226
227/**
228 *
229 */
230int DisplayInformation::
231get_display_mode_height (int display_index) {
232 int value;
233
234 value = 0;
235 if (display_index >= 0 && display_index < _total_display_modes) {
236 value = _display_mode_array [display_index].height;
237 }
238
239 return value;
240}
241
242/**
243 *
244 */
245int DisplayInformation::
246get_display_mode_bits_per_pixel (int display_index) {
247 int value;
248
249 value = 0;
250 if (display_index >= 0 && display_index < _total_display_modes) {
251 value = _display_mode_array [display_index].bits_per_pixel;
252 }
253
254 return value;
255}
256
257/**
258 *
259 */
260int DisplayInformation::
261get_display_mode_refresh_rate (int display_index) {
262 int value;
263
264 value = 0;
265 if (display_index >= 0 && display_index < _total_display_modes) {
266 value = _display_mode_array [display_index].refresh_rate;
267 }
268
269 return value;
270}
271
272/**
273 *
274 */
275int DisplayInformation::
276get_display_mode_fullscreen_only (int display_index) {
277 int value;
278
279 value = 0;
280 if (display_index >= 0 && display_index < _total_display_modes) {
281 value = _display_mode_array [display_index].fullscreen_only;
282 }
283
284 return value;
285}
286
287/**
288 *
289 */
290GraphicsStateGuardian::ShaderModel DisplayInformation::
291get_shader_model() {
292 return _shader_model;
293}
294
295/**
296 *
297 */
298int DisplayInformation::
299get_video_memory ( ) {
300 return _video_memory;
301}
302
303/**
304 *
305 */
306int DisplayInformation::
307get_texture_memory() {
308 return _texture_memory;
309}
310
311/**
312 *
313 */
314void DisplayInformation::
315update_memory_information() {
316 if (_get_memory_information_function) {
317 _get_memory_information_function (this);
318 }
319}
320
321/**
322 *
323 */
324uint64_t DisplayInformation::
325get_physical_memory() {
326 return _physical_memory;
327}
328
329/**
330 *
331 */
332uint64_t DisplayInformation::
333get_available_physical_memory() {
334 return _available_physical_memory;
335}
336
337/**
338 *
339 */
340uint64_t DisplayInformation::
341get_page_file_size() {
342 return _page_file_size;
343}
344
345/**
346 *
347 */
348uint64_t DisplayInformation::
349get_available_page_file_size() {
350 return _available_page_file_size;
351}
352
353/**
354 *
355 */
356uint64_t DisplayInformation::
357get_process_virtual_memory() {
358 return _process_virtual_memory;
359}
360
361/**
362 *
363 */
364uint64_t DisplayInformation::
365get_available_process_virtual_memory() {
366 return _available_process_virtual_memory;
367}
368
369/**
370 *
371 */
372int DisplayInformation::
373get_memory_load() {
374 return _memory_load;
375}
376
377/**
378 *
379 */
380uint64_t DisplayInformation::
381get_page_fault_count() {
382 return _page_fault_count;
383}
384
385/**
386 *
387 */
388uint64_t DisplayInformation::
389get_process_memory() {
390 return _process_memory;
391}
392
393/**
394 *
395 */
396uint64_t DisplayInformation::
397get_peak_process_memory() {
398 return _peak_process_memory;
399}
400
401/**
402 *
403 */
404uint64_t DisplayInformation::
405get_page_file_usage() {
406 return _page_file_usage;
407}
408
409/**
410 *
411 */
412uint64_t DisplayInformation::
413get_peak_page_file_usage() {
414 return _peak_page_file_usage;
415}
416
417/**
418 *
419 */
420int DisplayInformation::
421get_vendor_id() {
422 return _vendor_id;
423}
424
425/**
426 *
427 */
428int DisplayInformation::
429get_device_id() {
430 return _device_id;
431}
432
433/**
434 *
435 */
436int DisplayInformation::
437get_driver_product() {
438 return _driver_product;
439}
440
441/**
442 *
443 */
444int DisplayInformation::
445get_driver_version() {
446 return _driver_version;
447}
448
449/**
450 *
451 */
452int DisplayInformation::
453get_driver_sub_version() {
454 return _driver_sub_version;
455}
456
457/**
458 *
459 */
460int DisplayInformation::
461get_driver_build() {
462 return _driver_build;
463}
464
465/**
466 *
467 */
468int DisplayInformation::
469get_driver_date_month() {
470 return _driver_date_month;
471}
472
473/**
474 *
475 */
476int DisplayInformation::
477get_driver_date_day() {
478 return _driver_date_day;
479}
480
481/**
482 *
483 */
484int DisplayInformation::
485get_driver_date_year() {
486 return _driver_date_year;
487}
488
489/**
490 *
491 */
492const std::string &DisplayInformation::
493get_cpu_vendor_string() const {
494 return _cpu_vendor_string;
495}
496
497/**
498 *
499 */
500const std::string &DisplayInformation::
501get_cpu_brand_string() const {
502 return _cpu_brand_string;
503}
504
505/**
506 *
507 */
508unsigned int DisplayInformation::
509get_cpu_version_information() {
510 return _cpu_version_information;
511}
512
513/**
514 *
515 */
516unsigned int DisplayInformation::
517get_cpu_brand_index() {
518 return _cpu_brand_index;
519}
520
521/**
522 *
523 */
524uint64_t DisplayInformation::
525get_cpu_frequency() {
526 return _cpu_frequency;
527}
528
529/**
530 * Equivalent to the rdtsc processor instruction.
531 */
533get_cpu_time() {
534#if defined(__i386) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64)
535#if defined(_MSC_VER) || (defined(__GNUC__) && !defined(__clang__))
536 return __rdtsc();
537#else
538 unsigned int lo, hi = 0;
539 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
540 return ((uint64_t)hi << 32) | lo;
541#endif
542#else
543 return 0;
544#endif
545}
546
547/**
548 *
549 */
550uint64_t DisplayInformation::
551get_maximum_cpu_frequency() {
552 return _maximum_cpu_frequency;
553}
554
555/**
556 *
557 */
558uint64_t DisplayInformation::
559get_current_cpu_frequency() {
560 return _current_cpu_frequency;
561}
562
563/**
564 *
565 */
566void DisplayInformation::
567update_cpu_frequency(int processor_number) {
568 if (_update_cpu_frequency_function) {
569 _update_cpu_frequency_function (processor_number, this);
570 }
571}
572
573/**
574 * Returns the number of individual CPU cores in the system, or 0 if this
575 * number is not available. A hyperthreaded CPU counts once here.
576 */
579 return _num_cpu_cores;
580}
581
582/**
583 * Returns the number of logical CPU's in the system, or 0 if this number is
584 * not available. A hyperthreaded CPU counts as two or more here.
585 */
588 return _num_logical_cpus;
589}
590
591/**
592 * Returns -1 if not set.
593 */
596 return _os_version_major;
597}
598
599/**
600 * Returns -1 if not set.
601 */
604 return _os_version_minor;
605}
606
607/**
608 * Returns -1 if not set.
609 */
612 return _os_version_build;
613}
614
615/**
616 * Returns -1 if not set.
617 */
620 return _os_platform_id;
621}
int get_num_cpu_cores()
Returns the number of individual CPU cores in the system, or 0 if this number is not available.
static uint64_t get_cpu_time()
Equivalent to the rdtsc processor instruction.
int get_os_version_minor()
Returns -1 if not set.
int get_os_version_build()
Returns -1 if not set.
int get_os_version_major()
Returns -1 if not set.
int get_num_logical_cpus()
Returns the number of logical CPU's in the system, or 0 if this number is not available.
int get_os_platform_id()
Returns -1 if not set.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool operator==(const DisplayMode &other) const
Returns true if these two DisplayModes are identical.
bool operator!=(const DisplayMode &other) const
Returns false if these two DisplayModes are identical.