1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * Header with common definitions and global functions
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License as published by the Free Software Foundation,
|
---|
14 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
15 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
16 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * If you received this file as part of a commercial VirtualBox
|
---|
19 | * distribution, then only the terms of your commercial VirtualBox
|
---|
20 | * license agreement apply instead of the previous paragraph.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #ifndef __VBoxDefs_h__
|
---|
24 | #define __VBoxDefs_h__
|
---|
25 |
|
---|
26 | #include <qevent.h>
|
---|
27 |
|
---|
28 | #define LOG_GROUP LOG_GROUP_GUI
|
---|
29 | #include <VBox/log.h>
|
---|
30 | #include <iprt/assert.h>
|
---|
31 |
|
---|
32 | #include <iprt/alloc.h>
|
---|
33 |
|
---|
34 | #ifdef VBOX_GUI_DEBUG
|
---|
35 |
|
---|
36 | #define AssertWrapperOk(w) \
|
---|
37 | AssertMsg (w.isOk(), (#w " is not okay (RC=0x%08X)", w.lastRC()))
|
---|
38 | #define AssertWrapperOkMsg(w, m) \
|
---|
39 | AssertMsg (w.isOk(), (#w ": " m " (RC=0x%08X)", w.lastRC()))
|
---|
40 |
|
---|
41 | #else // !VBOX_GUI_DEBUG
|
---|
42 |
|
---|
43 | #define AssertWrapperOk(w) do {} while (0)
|
---|
44 | #define AssertWrapperOkMsg(w, m) do {} while (0)
|
---|
45 |
|
---|
46 | #endif // !VBOX_GUI_DEBUG
|
---|
47 |
|
---|
48 | #ifndef SIZEOF_ARRAY
|
---|
49 | #define SIZEOF_ARRAY(a) (sizeof(a) / sizeof(a[0]))
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | #if defined (VBOX_GUI_USE_QIMAGE) || \
|
---|
53 | defined (VBOX_GUI_USE_SDL) || \
|
---|
54 | defined (VBOX_GUI_USE_DDRAW)
|
---|
55 | #if !defined (VBOX_GUI_USE_EXT_FRAMEBUFFER)
|
---|
56 | #define VBOX_GUI_USE_EXT_FRAMEBUFFER
|
---|
57 | #endif
|
---|
58 | #else
|
---|
59 | #if defined (VBOX_GUI_USE_EXT_FRAMEBUFFER)
|
---|
60 | #undef VBOX_GUI_USE_EXT_FRAMEBUFFER
|
---|
61 | #endif
|
---|
62 | #if !defined (VBOX_GUI_USE_REFRESH_TIMER)
|
---|
63 | #define VBOX_GUI_USE_REFRESH_TIMER
|
---|
64 | #endif
|
---|
65 | #endif
|
---|
66 |
|
---|
67 | /////////////////////////////////////////////////////////////////////////////
|
---|
68 |
|
---|
69 | #if defined (VBOX_GUI_DEBUG)
|
---|
70 |
|
---|
71 | #include <VBox/types.h> // for uint64_t type
|
---|
72 |
|
---|
73 | #include <qthread.h>
|
---|
74 | #include <qdatetime.h>
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * A class to measure intervals using rdtsc instruction.
|
---|
78 | */
|
---|
79 | class VMCPUTimer : public QThread // for crossplatform msleep()
|
---|
80 | {
|
---|
81 | public:
|
---|
82 | inline static uint64_t ticks() {
|
---|
83 | #if defined (Q_CC_MSVC)
|
---|
84 | union {
|
---|
85 | uint64_t ll;
|
---|
86 | struct {
|
---|
87 | uint32_t low, high;
|
---|
88 | } l;
|
---|
89 | } val;
|
---|
90 | __asm rdtsc
|
---|
91 | __asm mov val.l.low, eax
|
---|
92 | __asm mov val.l.high, edx
|
---|
93 | return val.ll;
|
---|
94 | #elif defined (Q_CC_GNU)
|
---|
95 | uint64_t val;
|
---|
96 | asm volatile ("rdtsc" : "=A" (val));
|
---|
97 | return val;
|
---|
98 | #else
|
---|
99 | return 0;
|
---|
100 | #endif
|
---|
101 | }
|
---|
102 | inline static uint64_t msecs( uint64_t tcks ) {
|
---|
103 | return tcks / ticks_per_msec;
|
---|
104 | }
|
---|
105 | inline static uint64_t msecsSince( uint64_t tcks ) {
|
---|
106 | tcks = ticks() - tcks;
|
---|
107 | return tcks / ticks_per_msec;
|
---|
108 | }
|
---|
109 | inline static void calibrate( int ms )
|
---|
110 | {
|
---|
111 | QTime t;
|
---|
112 | uint64_t tcks = ticks();
|
---|
113 | t.start();
|
---|
114 | msleep( ms );
|
---|
115 | tcks = ticks() - tcks;
|
---|
116 | int msecs = t.elapsed();
|
---|
117 | ticks_per_msec = tcks / msecs;
|
---|
118 | }
|
---|
119 | inline static uint64_t ticksPerMsec() {
|
---|
120 | return ticks_per_msec;
|
---|
121 | }
|
---|
122 | private:
|
---|
123 | static uint64_t ticks_per_msec;
|
---|
124 | };
|
---|
125 |
|
---|
126 | #endif // VBOX_GUI_DEBUG
|
---|
127 |
|
---|
128 | /* A common namespace for all enums */
|
---|
129 | struct VBoxDefs
|
---|
130 | {
|
---|
131 | /** Disk image type. */
|
---|
132 | enum DiskType { InvalidType, HD = 0x01, CD = 0x02, FD = 0x04 };
|
---|
133 |
|
---|
134 | /** VM display rendering mode. */
|
---|
135 | enum RenderMode {
|
---|
136 | TimerMode, QImageMode, SDLMode, DDRAWMode
|
---|
137 | };
|
---|
138 |
|
---|
139 | /** Additional Qt event types. */
|
---|
140 | enum {
|
---|
141 | ResizeEventType = QEvent::User + 0,
|
---|
142 | RepaintEventType = QEvent::User + 1,
|
---|
143 | MouseCapabilityEventType = QEvent::User + 2,
|
---|
144 | MousePointerChangeEventType = QEvent::User + 3,
|
---|
145 | MachineStateChangeEventType = QEvent::User + 4,
|
---|
146 | MachineDataChangeEventType = QEvent::User + 5,
|
---|
147 | MachineRegisteredEventType = QEvent::User + 6,
|
---|
148 | SessionStateChangeEventType = QEvent::User + 7,
|
---|
149 | SnapshotEventType = QEvent::User + 8,
|
---|
150 | RuntimeErrorEventType = QEvent::User + 9,
|
---|
151 | ModifierKeyChangeEventType = QEvent::User + 10,
|
---|
152 | EnumerateMediaEventType = QEvent::User + 100,
|
---|
153 | ActivateMenuEventType = QEvent::User + 101,
|
---|
154 | };
|
---|
155 | };
|
---|
156 |
|
---|
157 | #endif // __VBoxDefs_h__
|
---|
158 |
|
---|