Changeset 31051 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Jul 23, 2010 11:58:16 AM (14 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/selector
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVMPreviewWindow.cpp
r31019 r31051 39 39 , m_pGlossyImg(0) 40 40 { 41 m_session.createInstance(CLSID_Session); 42 41 43 setContentsMargins(0, 5, 0, 5); 42 44 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); … … 80 82 /* Retranslate the UI */ 81 83 retranslateUi(); 84 } 85 86 UIVMPreviewWindow::~UIVMPreviewWindow() 87 { 88 /* Close any open session */ 89 if (m_session.GetState() == KSessionState_Locked) 90 m_session.Close(); 82 91 } 83 92 … … 240 249 || m_machineState == KMachineState_Paused) 241 250 { 242 CSession session; 243 session.createInstance(CLSID_Session); 244 if (!session.isNull()) 251 if (m_session.GetState() == KSessionState_Locked) 245 252 { 246 253 CVirtualBox vbox = vboxGlobal().virtualBox(); 247 m_machine.LockMachine(session, KLockType_Shared);248 254 if (vbox.isOk()) 249 255 { 250 CDisplay display = session.GetConsole().GetDisplay(); 251 /* Todo: correct aspect radio */ 252 // ULONG w, h, bpp; 253 // display.GetScreenResolution(0, w, h, bpp); 254 // QImage shot = QImage(w, h, QImage::Format_RGB32); 255 // shot.fill(Qt::black); 256 // display.TakeScreenShot(0, shot.bits(), shot.width(), shot.height()); 257 QVector<BYTE> screenData = display.TakeScreenShotToArray(0, m_vRect.width(), m_vRect.height()); 258 if ( display.isOk() 259 && screenData.size() != 0) 256 const CConsole& console = m_session.GetConsole(); 257 if (!console.isNull()) 260 258 { 261 /* Unfortunately we have to reorder the pixel 262 * data, cause the VBox API returns RGBA data, 263 * which is not a format QImage understand. 264 * Todo: check for 32bit alignment, for both 265 * the data and the scanlines. Maybe we need to 266 * copy the data in any case. */ 267 uint32_t *d = (uint32_t*)screenData.data(); 268 for (int i = 0; i < screenData.size() / 4; ++i) 259 CDisplay display = console.GetDisplay(); 260 /* Todo: correct aspect radio */ 261 // ULONG w, h, bpp; 262 // display.GetScreenResolution(0, w, h, bpp); 263 // QImage shot = QImage(w, h, QImage::Format_RGB32); 264 // shot.fill(Qt::black); 265 // display.TakeScreenShot(0, shot.bits(), shot.width(), shot.height()); 266 QVector<BYTE> screenData = display.TakeScreenShotToArray(0, m_vRect.width(), m_vRect.height()); 267 if ( display.isOk() 268 && screenData.size() != 0) 269 269 { 270 uint32_t e = d[i]; 271 d[i] = RT_MAKE_U32_FROM_U8(RT_BYTE3(e), RT_BYTE2(e), RT_BYTE1(e), RT_BYTE4(e)); 270 /* Unfortunately we have to reorder the pixel 271 * data, cause the VBox API returns RGBA data, 272 * which is not a format QImage understand. 273 * Todo: check for 32bit alignment, for both 274 * the data and the scanlines. Maybe we need to 275 * copy the data in any case. */ 276 uint32_t *d = (uint32_t*)screenData.data(); 277 for (int i = 0; i < screenData.size() / 4; ++i) 278 { 279 uint32_t e = d[i]; 280 d[i] = RT_MAKE_U32_FROM_U8(RT_BYTE3(e), RT_BYTE2(e), RT_BYTE1(e), RT_BYTE4(e)); 281 } 282 283 QImage shot = QImage((uchar*)d, m_vRect.width(), m_vRect.height(), QImage::Format_RGB32); 284 285 if (m_machineState == KMachineState_Paused) 286 dimImage(shot); 287 painter.drawImage(m_vRect.x(), m_vRect.y(), shot); 288 fDone = true; 272 289 } 273 274 QImage shot = QImage((uchar*)d, m_vRect.width(), m_vRect.height(), QImage::Format_RGB32);275 276 if (m_machineState == KMachineState_Paused)277 dimImage(shot);278 painter.drawImage(m_vRect.x(), m_vRect.y(), shot);279 fDone = true;280 290 } 281 291 } … … 340 350 void UIVMPreviewWindow::restart() 341 351 { 342 /* Fetch the latest machine state */ 352 /* Close any open session */ 353 if (m_session.GetState() == KSessionState_Locked) 354 m_session.Close(); 343 355 if (!m_machine.isNull()) 356 { 357 /* Fetch the latest machine state */ 344 358 m_machineState = m_machine.GetState(); 359 /* Lock the session for the current machine */ 360 if ( m_machineState == KMachineState_Running 361 // || m_machineState == KMachineState_Saving /* Not sure if this is valid */ 362 || m_machineState == KMachineState_Paused) 363 m_machine.LockMachine(m_session, KLockType_Shared); 364 } 365 345 366 /* Recreate the preview image */ 346 367 sltRecreatePreview(); -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVMPreviewWindow.h
r30868 r31051 51 51 52 52 UIVMPreviewWindow(QWidget *pParent); 53 ~UIVMPreviewWindow(); 53 54 54 55 void setMachine(const CMachine& machine); … … 79 80 80 81 /* Private member vars */ 82 CSession m_session; 81 83 CMachine m_machine; 82 84 KMachineState m_machineState;
Note:
See TracChangeset
for help on using the changeset viewer.