Changeset 53372 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Nov 21, 2014 1:52:39 PM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 96997
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.cpp
r53249 r53372 136 136 const char* UIExtraDataDefs::GUI_GuruMeditationHandler = "GUI/GuruMeditationHandler"; 137 137 const char* UIExtraDataDefs::GUI_HidLedsSync = "GUI/HidLedsSync"; 138 const char* UIExtraDataDefs::GUI_ScaleFactor = "GUI/ScaleFactor"; 138 139 139 140 /* Virtual Machine: Information dialog: */ -
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.h
r53249 r53372 237 237 /** Holds whether machine should perform HID LEDs synchronization. */ 238 238 extern const char* GUI_HidLedsSync; 239 /** Holds the scale-factor. */ 240 extern const char* GUI_ScaleFactor; 239 241 /** @} */ 240 242 -
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp
r53320 r53372 1792 1792 << GUI_GuruMeditationHandler 1793 1793 << GUI_HidLedsSync 1794 << GUI_ScaleFactor 1794 1795 << GUI_InformationWindowGeometry 1795 1796 << GUI_DefaultCloseAction << GUI_RestrictedCloseActions … … 3255 3256 /* 'True' unless feature restricted: */ 3256 3257 return !isFeatureRestricted(GUI_HidLedsSync, strID); 3258 } 3259 3260 double UIExtraDataManager::scaleFactor(const QString &strID) 3261 { 3262 /* Get corresponding extra-data value: */ 3263 const QString strValue = extraDataString(GUI_ScaleFactor, strID); 3264 3265 /* Try to convert loaded data to double: */ 3266 bool fOk = false; 3267 double dValue = strValue.toDouble(&fOk); 3268 3269 /* Invent the default value: */ 3270 if (!fOk || !dValue) 3271 dValue = 1; 3272 3273 /* Return value: */ 3274 return dValue; 3257 3275 } 3258 3276 -
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h
r53320 r53372 450 450 /** Returns whether machine should perform HID LEDs synchronization. */ 451 451 bool hidLedsSyncState(const QString &strID); 452 453 /** Returns scale-factor. */ 454 double scaleFactor(const QString &strID); 452 455 /** @} */ 453 456 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.cpp
r53236 r53372 28 28 # include "UIMachineView.h" 29 29 # include "UIPopupCenter.h" 30 # include "UIExtraDataManager.h" 30 31 # include "VBoxGlobal.h" 31 32 # ifdef VBOX_WITH_MASKED_SEAMLESS … … 61 62 , m_fUnused(false) 62 63 , m_fAutoEnabled(false) 64 , m_dScaleFactor(gEDataManager->scaleFactor(vboxGlobal().managedVMUuid())) 63 65 , m_hiDPIOptimizationType(HiDPIOptimizationType_None) 64 66 , m_dBackingScaleFactor(1.0) … … 469 471 rect.setRight(rects->xRight - 1); 470 472 rect.setBottom(rects->yBottom - 1); 473 /* Tune according scale-factor: */ 474 // TODO: Take rounding into account.. 475 rect.moveTo(rect.topLeft() * m_dScaleFactor); 476 rect.setSize(rect.size() * m_dScaleFactor); 471 477 /* Append region: */ 472 478 region += rect; … … 719 725 paintSeamless(pEvent); 720 726 break; 721 case UIVisualStateType_Scale:722 paintScaled(pEvent);723 break;724 727 default: 725 728 paintDefault(pEvent); … … 791 794 void UIFrameBuffer::paintDefault(QPaintEvent *pEvent) 792 795 { 796 /* Scaled image is NULL by default: */ 797 QImage scaledImage; 798 /* But if scaled-factor is set and current image is NOT null: */ 799 if (m_scaledSize.isValid() && !m_image.isNull()) 800 { 801 /* We are doing a deep copy of the image to make sure it will not be 802 * detached during scale process, otherwise we can get a frozen frame-buffer. */ 803 scaledImage = m_image.copy(); 804 /* And scaling the image to predefined scaled-factor: */ 805 scaledImage = scaledImage.scaled(m_scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); 806 } 807 /* Finally we are choosing image to paint from: */ 808 const QImage &sourceImage = scaledImage.isNull() ? m_image : scaledImage; 809 793 810 /* Get rectangle to paint: */ 794 QRect paintRect = pEvent->rect().intersected( m_image.rect()).intersected(m_pMachineView->viewport()->geometry());811 QRect paintRect = pEvent->rect().intersected(sourceImage.rect()).intersected(m_pMachineView->viewport()->geometry()); 795 812 if (paintRect.isEmpty()) 796 813 return; … … 800 817 801 818 /* Draw image rectangle: */ 802 drawImageRect(painter, m_image, paintRect,819 drawImageRect(painter, sourceImage, paintRect, 803 820 m_pMachineView->contentsX(), m_pMachineView->contentsY(), 804 821 hiDPIOptimizationType(), backingScaleFactor()); … … 807 824 void UIFrameBuffer::paintSeamless(QPaintEvent *pEvent) 808 825 { 826 /* Scaled image is NULL by default: */ 827 QImage scaledImage; 828 /* But if scaled-factor is set and current image is NOT null: */ 829 if (m_scaledSize.isValid() && !m_image.isNull()) 830 { 831 /* We are doing a deep copy of the image to make sure it will not be 832 * detached during scale process, otherwise we can get a frozen frame-buffer. */ 833 scaledImage = m_image.copy(); 834 /* And scaling the image to predefined scaled-factor: */ 835 scaledImage = scaledImage.scaled(m_scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); 836 } 837 /* Finally we are choosing image to paint from: */ 838 const QImage &sourceImage = scaledImage.isNull() ? m_image : scaledImage; 839 809 840 /* Get rectangle to paint: */ 810 QRect paintRect = pEvent->rect().intersected( m_image.rect()).intersected(m_pMachineView->viewport()->geometry());841 QRect paintRect = pEvent->rect().intersected(sourceImage.rect()).intersected(m_pMachineView->viewport()->geometry()); 811 842 if (paintRect.isEmpty()) 812 843 return; … … 851 882 852 883 /* Draw image rectangle: */ 853 drawImageRect(painter, m_image, rect,884 drawImageRect(painter, sourceImage, rect, 854 885 m_pMachineView->contentsX(), m_pMachineView->contentsY(), 855 886 hiDPIOptimizationType(), backingScaleFactor()); 856 887 } 857 888 } 858 }859 860 void UIFrameBuffer::paintScaled(QPaintEvent *pEvent)861 {862 /* Scaled image is NULL by default: */863 QImage scaledImage;864 /* But if scaled-factor is set and current image is NOT null: */865 if (m_scaledSize.isValid() && !m_image.isNull())866 {867 /* We are doing a deep copy of the image to make sure it will not be868 * detached during scale process, otherwise we can get a frozen frame-buffer. */869 scaledImage = m_image.copy();870 /* And scaling the image to predefined scaled-factor: */871 scaledImage = scaledImage.scaled(m_scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);872 }873 /* Finally we are choosing image to paint from: */874 QImage &sourceImage = scaledImage.isNull() ? m_image : scaledImage;875 876 /* Get rectangle to paint: */877 QRect paintRect = pEvent->rect().intersected(sourceImage.rect()).intersected(m_pMachineView->viewport()->geometry());878 if (paintRect.isEmpty())879 return;880 881 /* Create painter: */882 QPainter painter(m_pMachineView->viewport());883 884 /* Draw image rectangle: */885 drawImageRect(painter, sourceImage, paintRect,886 m_pMachineView->contentsX(), m_pMachineView->contentsY(),887 hiDPIOptimizationType(), backingScaleFactor());888 889 } 889 890 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.h
r52902 r53372 234 234 /** Paint routine for seamless mode. */ 235 235 void paintSeamless(QPaintEvent *pEvent); 236 /** Paint routine for scaled mode. */237 void paintScaled(QPaintEvent *pEvent);238 236 239 237 /** Draws corresponding @a rect of passed @a image with @a painter. */ … … 277 275 mutable RTCRITSECT m_critSect; 278 276 279 /** @name Scale d moderelated variables.277 /** @name Scale-factor related variables. 280 278 * @{ */ 281 /** Holds frame-buffer scaled size. */ 279 /** Holds the scale-factor used by the scaled-size. */ 280 const double m_dScaleFactor; 281 /** Holds the frame-buffer's scaled-size. */ 282 282 QSize m_scaledSize; 283 283 /** @} */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp
r53365 r53372 185 185 AssertMsg(newSize.isValid(), ("Size should be valid!\n")); 186 186 187 /* Take the scale-factor into account: */ 188 const double dScaleFactor = gEDataManager->scaleFactor(vboxGlobal().managedVMUuid()); 189 newSize /= dScaleFactor; 190 187 191 /* Expand current limitations: */ 188 192 setMaxGuestSize(newSize); … … 224 228 frameBuffer()->setScaledSize(size()); 225 229 } 230 /* Adjust other modes to current NotifyChange event size: */ 231 else 232 { 233 /* Assign new frame-buffer logical-size taking the scale-factor into account: */ 234 const double dScaleFactor = gEDataManager->scaleFactor(vboxGlobal().managedVMUuid()); 235 frameBuffer()->setScaledSize(dScaleFactor == 1 ? QSize() : QSize(iWidth * dScaleFactor, iHeight * dScaleFactor)); 236 } 226 237 227 238 /* Perform frame-buffer mode-change: */ … … 271 282 void UIMachineView::sltHandleNotifyUpdate(int iX, int iY, int iWidth, int iHeight) 272 283 { 273 /* Update corresponding viewport part: */ 274 viewport()->update(iX - contentsX(), iY - contentsY(), iWidth, iHeight); 284 /* Take the scale-factor into account: */ 285 const double dScaleFactor = gEDataManager->scaleFactor(vboxGlobal().managedVMUuid()); 286 if (dScaleFactor == 1) 287 { 288 /* Just update corresponding viewport part: */ 289 viewport()->update(iX - contentsX(), iY - contentsY(), iWidth, iHeight); 290 } 291 else 292 { 293 /* Calculate corresponding viewport part: */ 294 QRect rect(iX * dScaleFactor - 1 - contentsX(), 295 iY * dScaleFactor - 1 - contentsY(), 296 iWidth * dScaleFactor + 2 * dScaleFactor + 1, 297 iHeight * dScaleFactor + 2 * dScaleFactor + 1); 298 /* Limit the resulting part by the viewport rectangle: */ 299 rect &= viewport()->rect(); 300 /* Update corresponding viewport part: */ 301 viewport()->update(rect); 302 } 275 303 } 276 304 … … 392 420 void UIMachineView::prepareFrameBuffer() 393 421 { 422 /* Take scale-factor into account: */ 423 const double dScaleFactor = gEDataManager->scaleFactor(vboxGlobal().managedVMUuid()); 424 394 425 /* Prepare frame-buffer: */ 395 426 UIFrameBuffer *pFrameBuffer = uisession()->frameBuffer(screenId()); … … 422 453 # endif /* !VBOX_WITH_VIDEOHWACCEL */ 423 454 m_pFrameBuffer->setHiDPIOptimizationType(uisession()->hiDPIOptimizationType()); 424 455 m_pFrameBuffer->setScaledSize(dScaleFactor == 1 ? QSize() : 456 QSize(m_pFrameBuffer->width() * dScaleFactor, 457 m_pFrameBuffer->height() * dScaleFactor)); 425 458 uisession()->setFrameBuffer(screenId(), m_pFrameBuffer); 426 459 } … … 463 496 /* If we have a valid size, resize the framebuffer. */ 464 497 if (size.width() > 0 && size.height() > 0) 498 { 465 499 frameBuffer()->resizeEvent(size.width(), size.height()); 500 frameBuffer()->setScaledSize(dScaleFactor == 1 ? QSize() : 501 QSize(frameBuffer()->width() * dScaleFactor, 502 frameBuffer()->height() * dScaleFactor)); 503 } 466 504 } 467 505 … … 609 647 QSize size(m_pFrameBuffer->width(), m_pFrameBuffer->height()); 610 648 649 /* Take the scale-factor into account: */ 650 const double dScaleFactor = gEDataManager->scaleFactor(vboxGlobal().managedVMUuid()); 651 size *= dScaleFactor; 652 611 653 #ifdef VBOX_WITH_DEBUGGER_GUI 612 654 // TODO: Fix all DEBUGGER stuff! … … 689 731 size = QSize(800, 600); 690 732 733 /* Take the scale-factor into account: */ 734 const double dScaleFactor = gEDataManager->scaleFactor(vboxGlobal().managedVMUuid()); 735 size *= dScaleFactor; 736 691 737 /* Return size: */ 692 738 return size; … … 704 750 void UIMachineView::resetPausePixmap() 705 751 { 706 /* Reset pixmap : */752 /* Reset pixmap(s): */ 707 753 m_pausePixmap = QPixmap(); 754 m_pausePixmapScaled = QPixmap(); 708 755 } 709 756 … … 737 784 /* Finally copy the screen-shot to pause-pixmap: */ 738 785 m_pausePixmap = QPixmap::fromImage(screenShot); 786 787 /* Update scaled pause pixmap: */ 788 updateScaledPausePixmap(); 739 789 } 740 790 … … 763 813 /* Finally copy the screen-shot to pause-pixmap: */ 764 814 m_pausePixmap = QPixmap::fromImage(screenShot); 815 816 /* Update scaled pause pixmap: */ 817 updateScaledPausePixmap(); 818 } 819 820 void UIMachineView::updateScaledPausePixmap() 821 { 822 /* Make sure pause pixmap is not null: */ 823 if (pausePixmap().isNull()) 824 return; 825 826 /* Make sure scaled-size is not null: */ 827 const QSize scaledSize = frameBuffer()->scaledSize(); 828 if (!scaledSize.isValid()) 829 return; 830 831 /* Update pause pixmap finally: */ 832 m_pausePixmapScaled = pausePixmap().scaled(scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); 765 833 } 766 834 … … 1001 1069 QRect rect = pPaintEvent->rect().intersect(viewport()->rect()); 1002 1070 QPainter painter(viewport()); 1003 painter.drawPixmap(rect, pausePixmap(), QRect(rect.x() + contentsX(), rect.y() + contentsY(), 1004 rect.width(), rect.height())); 1071 /* Take the scale-factor into account: */ 1072 const double dScaleFactor = gEDataManager->scaleFactor(vboxGlobal().managedVMUuid()); 1073 if (dScaleFactor == 1) 1074 painter.drawPixmap(rect, pausePixmap(), QRect(rect.x() + contentsX(), rect.y() + contentsY(), 1075 rect.width(), rect.height())); 1076 else 1077 painter.drawPixmap(rect, pausePixmapScaled(), QRect(rect.x() + contentsX(), rect.y() + contentsY(), 1078 rect.width(), rect.height())); 1005 1079 #ifdef Q_WS_MAC 1006 1080 /* Update the dock icon: */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h
r53363 r53372 194 194 /** Returns the pause-pixmap: */ 195 195 const QPixmap& pausePixmap() const { return m_pausePixmap; } 196 /** Returns the scaled pause-pixmap: */ 197 const QPixmap& pausePixmapScaled() const { return m_pausePixmapScaled; } 196 198 /** Resets the pause-pixmap. */ 197 v irtual void resetPausePixmap();199 void resetPausePixmap(); 198 200 /** Acquires live pause-pixmap. */ 199 v irtual void takePausePixmapLive();201 void takePausePixmapLive(); 200 202 /** Acquires snapshot pause-pixmap. */ 201 virtual void takePausePixmapSnapshot(); 203 void takePausePixmapSnapshot(); 204 /** Updates the scaled pause-pixmap. */ 205 void updateScaledPausePixmap(); 202 206 203 207 /** The available area on the current screen for application windows. */ … … 275 279 /** Holds the pause-pixmap. */ 276 280 QPixmap m_pausePixmap; 281 /** Holds the scaled pause-pixmap. */ 282 QPixmap m_pausePixmapScaled; 277 283 278 284 /* Friend classes: */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.cpp
r53363 r53372 53 53 #endif 54 54 ) 55 , m_pPauseImage(0)56 55 { 57 56 /* Resend the last resize hint if necessary: */ … … 71 70 } 72 71 73 void UIMachineViewScale::takePausePixmapLive()74 {75 /* Take a screen snapshot. Note that TakeScreenShot() always needs a 32bpp image: */76 QImage shot = QImage(m_pFrameBuffer->width(), m_pFrameBuffer->height(), QImage::Format_RGB32);77 /* If TakeScreenShot fails or returns no image, just show a black image. */78 shot.fill(0);79 display().TakeScreenShot(screenId(), shot.bits(), shot.width(), shot.height(), KBitmapFormat_BGR0);80 m_pPauseImage = new QImage(shot);81 scalePauseShot();82 }83 84 void UIMachineViewScale::takePausePixmapSnapshot()85 {86 ULONG width = 0, height = 0;87 QVector<BYTE> screenData = machine().ReadSavedScreenshotPNGToArray(0, width, height);88 if (screenData.size() != 0)89 {90 ULONG guestOriginX = 0, guestOriginY = 0, guestWidth = 0, guestHeight = 0;91 BOOL fEnabled = true;92 machine().QuerySavedGuestScreenInfo(m_uScreenId, guestOriginX, guestOriginY, guestWidth, guestHeight, fEnabled);93 QImage shot = QImage::fromData(screenData.data(), screenData.size(), "PNG").scaled(guestWidth > 0 ? QSize(guestWidth, guestHeight) : guestSizeHint());94 m_pPauseImage = new QImage(shot);95 scalePauseShot();96 }97 }98 99 void UIMachineViewScale::resetPausePixmap()100 {101 /* Call the base class */102 UIMachineView::resetPausePixmap();103 104 if (m_pPauseImage)105 {106 delete m_pPauseImage;107 m_pPauseImage = 0;108 }109 }110 111 void UIMachineViewScale::scalePauseShot()112 {113 if (m_pPauseImage)114 {115 QSize scaledSize = frameBuffer()->scaledSize();116 if (scaledSize.isValid())117 {118 QImage tmpImg = m_pPauseImage->scaled(scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);119 dimImage(tmpImg);120 m_pausePixmap = QPixmap::fromImage(tmpImg);121 }122 }123 }124 125 72 void UIMachineViewScale::sltPerformGuestScale() 126 73 { … … 129 76 frameBuffer()->setScaledSize(viewport()->size()); 130 77 131 /* Scale the pause image if necessary*/132 scalePauseShot();78 /* Scale the pause-pixmap: */ 79 updateScaledPausePixmap(); 133 80 134 81 /* Update viewport: */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.h
r53363 r53372 37 37 virtual ~UIMachineViewScale(); 38 38 39 virtual void takePausePixmapLive();40 virtual void takePausePixmapSnapshot();41 virtual void resetPausePixmap();42 void scalePauseShot();43 44 39 private slots: 45 40 … … 70 65 void updateSliders(); 71 66 72 /* Private members: */73 QImage *m_pPauseImage;74 75 67 /* Friend classes: */ 76 68 friend class UIMachineView;
Note:
See TracChangeset
for help on using the changeset viewer.