Changeset 86086 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Sep 10, 2020 2:31:20 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 140315
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 2 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r86085 r86086 838 838 src/settings/editors/UIAudioHostDriverEditor.h \ 839 839 src/settings/editors/UIBaseMemoryEditor.h \ 840 src/settings/editors/UIBaseMemorySlider.h \841 840 src/settings/editors/UIBootOrderEditor.h \ 842 841 src/settings/editors/UIGraphicsControllerEditor.h \ … … 989 988 src/medium/viso/UIVisoHostBrowser.cpp \ 990 989 src/medium/viso/UIVisoBrowserBase.cpp \ 990 src/settings/editors/UIBaseMemoryEditor.cpp \ 991 991 src/settings/editors/UIBootOrderEditor.cpp \ 992 992 src/settings/editors/UIHotKeyEditor.cpp \ … … 1351 1351 src/settings/editors/UIAudioHostDriverEditor.cpp \ 1352 1352 src/settings/editors/UIBaseMemoryEditor.cpp \ 1353 src/settings/editors/UIBaseMemorySlider.cpp \1354 1353 src/settings/editors/UIBootOrderEditor.cpp \ 1355 1354 src/settings/editors/UIGraphicsControllerEditor.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIBaseMemoryEditor.cpp
r86085 r86086 24 24 25 25 /* GUI includes: */ 26 #include "QIAdvancedSlider.h" 26 27 #include "UIBaseMemoryEditor.h" 27 #include "UIBaseMemorySlider.h" 28 28 #include "UICommon.h" 29 30 /* COM includes: */ 31 #include "CSystemProperties.h" 32 33 34 /** QIAdvancedSlider subclass used as a base memory slider. */ 35 class SHARED_LIBRARY_STUFF UIBaseMemorySlider : public QIAdvancedSlider 36 { 37 Q_OBJECT; 38 39 public: 40 41 /** Constructs guest RAM slider passing @a pParent to the base-class. */ 42 UIBaseMemorySlider(QWidget *pParent = 0); 43 /** Constructs guest RAM slider passing @a pParent and @a enmOrientation to the base-class. */ 44 UIBaseMemorySlider(Qt::Orientation enmOrientation, QWidget *pParent = 0); 45 46 /** Returns the minimum RAM. */ 47 uint minRAM() const; 48 /** Returns the maximum optimal RAM. */ 49 uint maxRAMOpt() const; 50 /** Returns the maximum allowed RAM. */ 51 uint maxRAMAlw() const; 52 /** Returns the maximum possible RAM. */ 53 uint maxRAM() const; 54 55 private: 56 57 /** Prepares all. */ 58 void prepare(); 59 60 /** Calculates page step for passed @a iMaximum value. */ 61 int calcPageStep(int iMaximum) const; 62 63 /** Holds the minimum RAM. */ 64 uint m_uMinRAM; 65 /** Holds the maximum optimal RAM. */ 66 uint m_uMaxRAMOpt; 67 /** Holds the maximum allowed RAM. */ 68 uint m_uMaxRAMAlw; 69 /** Holds the maximum possible RAM. */ 70 uint m_uMaxRAM; 71 }; 72 73 74 /********************************************************************************************************************************* 75 * Class UIBaseMemorySlider implementation. * 76 *********************************************************************************************************************************/ 77 78 UIBaseMemorySlider::UIBaseMemorySlider(QWidget *pParent /* = 0 */) 79 : QIAdvancedSlider(pParent) 80 , m_uMinRAM(0) 81 , m_uMaxRAMOpt(0) 82 , m_uMaxRAMAlw(0) 83 , m_uMaxRAM(0) 84 { 85 /* Prepare: */ 86 prepare(); 87 } 88 89 UIBaseMemorySlider::UIBaseMemorySlider(Qt::Orientation enmOrientation, QWidget *pParent /* = 0 */) 90 : QIAdvancedSlider(enmOrientation, pParent) 91 , m_uMinRAM(0) 92 , m_uMaxRAMOpt(0) 93 , m_uMaxRAMAlw(0) 94 , m_uMaxRAM(0) 95 { 96 /* Prepare: */ 97 prepare(); 98 } 99 100 uint UIBaseMemorySlider::minRAM() const 101 { 102 return m_uMinRAM; 103 } 104 105 uint UIBaseMemorySlider::maxRAMOpt() const 106 { 107 return m_uMaxRAMOpt; 108 } 109 110 uint UIBaseMemorySlider::maxRAMAlw() const 111 { 112 return m_uMaxRAMAlw; 113 } 114 115 uint UIBaseMemorySlider::maxRAM() const 116 { 117 return m_uMaxRAM; 118 } 119 120 void UIBaseMemorySlider::prepare() 121 { 122 ulong uFullSize = uiCommon().host().GetMemorySize(); 123 CSystemProperties sys = uiCommon().virtualBox().GetSystemProperties(); 124 m_uMinRAM = sys.GetMinGuestRAM(); 125 m_uMaxRAM = RT_MIN(RT_ALIGN(uFullSize, _1G / _1M), sys.GetMaxGuestRAM()); 126 127 /* Come up with some nice round percent boundaries relative to 128 * the system memory. A max of 75% on a 256GB config is ridiculous, 129 * even on an 8GB rig reserving 2GB for the OS is way to conservative. 130 * The max numbers can be estimated using the following program: 131 * 132 * double calcMaxPct(uint64_t cbRam) 133 * { 134 * double cbRamOverhead = cbRam * 0.0390625; // 160 bytes per page. 135 * double cbRamForTheOS = RT_MAX(RT_MIN(_512M, cbRam * 0.25), _64M); 136 * double OSPct = (cbRamOverhead + cbRamForTheOS) * 100.0 / cbRam; 137 * double MaxPct = 100 - OSPct; 138 * return MaxPct; 139 * } 140 * 141 * int main() 142 * { 143 * uint64_t cbRam = _1G; 144 * for (; !(cbRam >> 33); cbRam += _1G) 145 * printf("%8lluGB %.1f%% %8lluKB\n", cbRam >> 30, calcMaxPct(cbRam), 146 * (uint64_t)(cbRam * calcMaxPct(cbRam) / 100.0) >> 20); 147 * for (; !(cbRam >> 51); cbRam <<= 1) 148 * printf("%8lluGB %.1f%% %8lluKB\n", cbRam >> 30, calcMaxPct(cbRam), 149 * (uint64_t)(cbRam * calcMaxPct(cbRam) / 100.0) >> 20); 150 * return 0; 151 * } 152 * 153 * Note. We might wanna put these calculations somewhere global later. */ 154 155 /* System RAM amount test: */ 156 m_uMaxRAMAlw = (uint)(0.75 * uFullSize); 157 m_uMaxRAMOpt = (uint)(0.50 * uFullSize); 158 if (uFullSize < 3072) 159 /* done */; 160 else if (uFullSize < 4096) /* 3GB */ 161 m_uMaxRAMAlw = (uint)(0.80 * uFullSize); 162 else if (uFullSize < 6144) /* 4-5GB */ 163 { 164 m_uMaxRAMAlw = (uint)(0.84 * uFullSize); 165 m_uMaxRAMOpt = (uint)(0.60 * uFullSize); 166 } 167 else if (uFullSize < 8192) /* 6-7GB */ 168 { 169 m_uMaxRAMAlw = (uint)(0.88 * uFullSize); 170 m_uMaxRAMOpt = (uint)(0.65 * uFullSize); 171 } 172 else if (uFullSize < 16384) /* 8-15GB */ 173 { 174 m_uMaxRAMAlw = (uint)(0.90 * uFullSize); 175 m_uMaxRAMOpt = (uint)(0.70 * uFullSize); 176 } 177 else if (uFullSize < 32768) /* 16-31GB */ 178 { 179 m_uMaxRAMAlw = (uint)(0.93 * uFullSize); 180 m_uMaxRAMOpt = (uint)(0.75 * uFullSize); 181 } 182 else if (uFullSize < 65536) /* 32-63GB */ 183 { 184 m_uMaxRAMAlw = (uint)(0.94 * uFullSize); 185 m_uMaxRAMOpt = (uint)(0.80 * uFullSize); 186 } 187 else if (uFullSize < 131072) /* 64-127GB */ 188 { 189 m_uMaxRAMAlw = (uint)(0.95 * uFullSize); 190 m_uMaxRAMOpt = (uint)(0.85 * uFullSize); 191 } 192 else /* 128GB- */ 193 { 194 m_uMaxRAMAlw = (uint)(0.96 * uFullSize); 195 m_uMaxRAMOpt = (uint)(0.90 * uFullSize); 196 } 197 /* Now check the calculated maximums are out of the range for the guest 198 * RAM. If so change it accordingly. */ 199 m_uMaxRAMAlw = RT_MIN(m_uMaxRAMAlw, m_uMaxRAM); 200 m_uMaxRAMOpt = RT_MIN(m_uMaxRAMOpt, m_uMaxRAM); 201 202 setPageStep(calcPageStep(m_uMaxRAM)); 203 setSingleStep(pageStep() / 4); 204 setTickInterval(pageStep()); 205 /* Setup the scale so that ticks are at page step boundaries */ 206 if (m_uMinRAM >= static_cast<uint>(pageStep())) 207 setMinimum((m_uMinRAM / pageStep()) * pageStep()); 208 else 209 setMinimum(m_uMinRAM); 210 211 setMaximum(m_uMaxRAM); 212 setSnappingEnabled(true); 213 setOptimalHint(m_uMinRAM, m_uMaxRAMOpt); 214 setWarningHint(m_uMaxRAMOpt, m_uMaxRAMAlw); 215 setErrorHint(m_uMaxRAMAlw, m_uMaxRAM); 216 } 217 218 int UIBaseMemorySlider::calcPageStep(int iMaximum) const 219 { 220 /* Calculate a suitable page step size for the given max value. 221 * The returned size is so that there will be no more than 32 222 * pages. The minimum returned page size is 4. */ 223 224 /* Reasonable max. number of page steps is 32: */ 225 uint uPage = ((uint)iMaximum + 31) / 32; 226 /* Make it a power of 2: */ 227 uint p = uPage, p2 = 0x1; 228 while ((p >>= 1)) 229 p2 <<= 1; 230 if (uPage != p2) 231 p2 <<= 1; 232 if (p2 < 4) 233 p2 = 4; 234 return (int) p2; 235 } 236 237 238 /********************************************************************************************************************************* 239 * Class UIBaseMemoryEditor implementation. * 240 *********************************************************************************************************************************/ 29 241 30 242 UIBaseMemoryEditor::UIBaseMemoryEditor(QWidget *pParent /* = 0 */, bool fWithLabel /* = false */) … … 183 395 emit sigValidChanged(m_pSlider->value() < (int)m_pSlider->maxRAMAlw()); 184 396 } 397 398 399 #include "UIBaseMemoryEditor.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageExpert.cpp
r85637 r86086 31 31 #include "QIRichTextLabel.h" 32 32 #include "QIToolButton.h" 33 #include "UIBaseMemorySlider.h"34 33 #include "UIBaseMemoryEditor.h" 35 34 #include "UIFilePathSelector.h"
Note:
See TracChangeset
for help on using the changeset viewer.