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