VirtualBox

Ignore:
Timestamp:
Jul 3, 2024 4:04:01 PM (8 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
163749
Message:

FE/Qt: Moving Display COM stuff from UICommon to UIGuestOSTypeManager and new UIGuestOSTypeHelpers namespace as it's all CGuestOSType dependent.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.cpp

    r105104 r105119  
    14481448}
    14491449
    1450 #ifdef VBOX_WITH_3D_ACCELERATION
    1451 /* static */
    1452 bool UICommon::isWddmCompatibleOsType(const QString &strGuestOSTypeId)
    1453 {
    1454     return    strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("WindowsVista"))
    1455            || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows7"))
    1456            || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows8"))
    1457            || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows81"))
    1458            || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows10"))
    1459            || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows11"))
    1460            || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows2008"))
    1461            || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows2012"))
    1462            || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows2016"))
    1463            || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows2019"));
    1464 }
    1465 #endif /* VBOX_WITH_3D_ACCELERATION */
    1466 
    1467 /* static */
    1468 quint64 UICommon::requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors /* = 1 */)
    1469 {
    1470     /* We create a list of the size of all available host monitors. This list
    1471      * is sorted by value and by starting with the biggest one, we calculate
    1472      * the memory requirements for every guest screen. This is of course not
    1473      * correct, but as we can't predict on which host screens the user will
    1474      * open the guest windows, this is the best assumption we can do, cause it
    1475      * is the worst case. */
    1476     const int cHostScreens = UIDesktopWidgetWatchdog::screenCount();
    1477     QVector<int> screenSize(qMax(cMonitors, cHostScreens), 0);
    1478     for (int i = 0; i < cHostScreens; ++i)
    1479     {
    1480         QRect r = gpDesktop->screenGeometry(i);
    1481         screenSize[i] = r.width() * r.height();
    1482     }
    1483     /* Now sort the vector: */
    1484     std::sort(screenSize.begin(), screenSize.end(), std::greater<int>());
    1485     /* For the case that there are more guest screens configured then host
    1486      * screens available, replace all zeros with the greatest value in the
    1487      * vector. */
    1488     for (int i = 0; i < screenSize.size(); ++i)
    1489         if (screenSize.at(i) == 0)
    1490             screenSize.replace(i, screenSize.at(0));
    1491 
    1492     quint64 uNeedBits = 0;
    1493     for (int i = 0; i < cMonitors; ++i)
    1494     {
    1495         /* Calculate summary required memory amount in bits: */
    1496         uNeedBits += (screenSize.at(i) * /* with x height */
    1497                      32 + /* we will take the maximum possible bpp for now */
    1498                      8 * _1M) + /* current cache per screen - may be changed in future */
    1499                      8 * 4096; /* adapter info */
    1500     }
    1501     /* Translate value into megabytes with rounding to highest side: */
    1502     quint64 uNeedMBytes = uNeedBits % (8 * _1M)
    1503                         ? uNeedBits / (8 * _1M) + 1
    1504                         : uNeedBits / (8 * _1M) /* convert to megabytes */;
    1505 
    1506     if (strGuestOSTypeId.startsWith("Windows"))
    1507     {
    1508         /* Windows guests need offscreen VRAM too for graphics acceleration features: */
    1509 #ifdef VBOX_WITH_3D_ACCELERATION
    1510         if (isWddmCompatibleOsType(strGuestOSTypeId))
    1511         {
    1512             /* WDDM mode, there are two surfaces for each screen: shadow & primary: */
    1513             uNeedMBytes *= 3;
    1514         }
    1515         else
    1516 #endif /* VBOX_WITH_3D_ACCELERATION */
    1517         {
    1518             uNeedMBytes *= 2;
    1519         }
    1520     }
    1521 
    1522     return uNeedMBytes * _1M;
    1523 }
    1524 
    1525 KGraphicsControllerType UICommon::getRecommendedGraphicsController(const QString &strGuestOSTypeId) const
    1526 {
    1527     return gpGlobalSession->guestOSTypeManager().getRecommendedGraphicsController(strGuestOSTypeId);
    1528 }
    1529 
    15301450/* static */
    15311451void UICommon::setHelpKeyword(QObject *pObject, const QString &strHelpKeyword)
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.h

    r105104 r105119  
    4343#endif
    4444
    45 /* COM includes: */
    46 #include "KGraphicsControllerType.h"
    47 
    48 /* Other VBox includes: */
    49 #include <iprt/types.h>
    50 
    5145/* Forward declarations: */
    5246class QSessionManager;
     
    308302    /** @} */
    309303
    310     /** @name Display stuff.
    311      * @{ */
    312 #ifdef VBOX_WITH_3D_ACCELERATION
    313         /** Returns whether guest OS type with passed @a strGuestOSTypeId is WDDM compatible. */
    314         static bool isWddmCompatibleOsType(const QString &strGuestOSTypeId);
    315 #endif
    316         /** Returns the required video memory in bytes for the current desktop
    317           * resolution at maximum possible screen depth in bpp. */
    318         static quint64 requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
    319         KGraphicsControllerType getRecommendedGraphicsController(const QString &strGuestOSTypeId) const;
    320     /** @} */
    321 
    322304    /** @name Thread stuff.
    323305     * @{ */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIGuestOSType.cpp

    r103906 r105119  
    55
    66/*
    7  * Copyright (C) 2006-2023 Oracle and/or its affiliates.
     7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
    88 *
    99 * This file is part of VirtualBox base platform packages, as
     
    2828/* GUI includes: */
    2929#include "UICommon.h"
     30#include "UIDesktopWidgetWatchdog.h"
    3031#include "UIGlobalSession.h"
    3132#include "UIGuestOSType.h"
     
    3637#include "CSystemProperties.h"
    3738
     39/* VirtualBox interface declarations: */
     40#include <VBox/com/VirtualBox.h>
     41
     42
     43/*********************************************************************************************************************************
     44*   Class UIGuestOSTypeHelpers implementation.                                                                                   *
     45*********************************************************************************************************************************/
     46
     47#ifdef VBOX_WITH_3D_ACCELERATION
     48bool UIGuestOSTypeHelpers::isWddmCompatibleOsType(const QString &strGuestOSTypeId)
     49{
     50    return    strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("WindowsVista"))
     51           || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows7"))
     52           || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows8"))
     53           || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows81"))
     54           || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows10"))
     55           || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows11"))
     56           || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows2008"))
     57           || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows2012"))
     58           || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows2016"))
     59           || strGuestOSTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows2019"));
     60}
     61#endif /* VBOX_WITH_3D_ACCELERATION */
     62
     63quint64 UIGuestOSTypeHelpers::requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors /* = 1 */)
     64{
     65    /* We create a list of the size of all available host monitors. This list
     66     * is sorted by value and by starting with the biggest one, we calculate
     67     * the memory requirements for every guest screen. This is of course not
     68     * correct, but as we can't predict on which host screens the user will
     69     * open the guest windows, this is the best assumption we can do, cause it
     70     * is the worst case. */
     71    const int cHostScreens = UIDesktopWidgetWatchdog::screenCount();
     72    QVector<int> screenSize(qMax(cMonitors, cHostScreens), 0);
     73    for (int i = 0; i < cHostScreens; ++i)
     74    {
     75        QRect r = gpDesktop->screenGeometry(i);
     76        screenSize[i] = r.width() * r.height();
     77    }
     78    /* Now sort the vector: */
     79    std::sort(screenSize.begin(), screenSize.end(), std::greater<int>());
     80    /* For the case that there are more guest screens configured then host
     81     * screens available, replace all zeros with the greatest value in the
     82     * vector. */
     83    for (int i = 0; i < screenSize.size(); ++i)
     84        if (screenSize.at(i) == 0)
     85            screenSize.replace(i, screenSize.at(0));
     86
     87    quint64 uNeedBits = 0;
     88    for (int i = 0; i < cMonitors; ++i)
     89    {
     90        /* Calculate summary required memory amount in bits: */
     91        uNeedBits += (screenSize.at(i) * /* with x height */
     92                     32 + /* we will take the maximum possible bpp for now */
     93                     8 * _1M) + /* current cache per screen - may be changed in future */
     94                     8 * 4096; /* adapter info */
     95    }
     96    /* Translate value into megabytes with rounding to highest side: */
     97    quint64 uNeedMBytes = uNeedBits % (8 * _1M)
     98                        ? uNeedBits / (8 * _1M) + 1
     99                        : uNeedBits / (8 * _1M) /* convert to megabytes */;
     100
     101    if (strGuestOSTypeId.startsWith("Windows"))
     102    {
     103        /* Windows guests need offscreen VRAM too for graphics acceleration features: */
     104#ifdef VBOX_WITH_3D_ACCELERATION
     105        if (isWddmCompatibleOsType(strGuestOSTypeId))
     106        {
     107            /* WDDM mode, there are two surfaces for each screen: shadow & primary: */
     108            uNeedMBytes *= 3;
     109        }
     110        else
     111#endif /* VBOX_WITH_3D_ACCELERATION */
     112        {
     113            uNeedMBytes *= 2;
     114        }
     115    }
     116
     117    return uNeedMBytes * _1M;
     118}
     119
     120
     121/*********************************************************************************************************************************
     122*   Class UIGuestOSTypeManager implementation.                                                                                   *
     123*********************************************************************************************************************************/
    38124
    39125void UIGuestOSTypeManager::reCacheGuestOSTypes()
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIGuestOSType.h

    r103906 r105119  
    55
    66/*
    7  * Copyright (C) 2006-2023 Oracle and/or its affiliates.
     7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
    88 *
    99 * This file is part of VirtualBox base platform packages, as
     
    3939/* COM includes: */
    4040#include "CGuestOSType.h"
     41
     42/** Holds various Guest OS type helper stuff. */
     43namespace UIGuestOSTypeHelpers
     44{
     45#ifdef VBOX_WITH_3D_ACCELERATION
     46    /** Returns whether guest OS type with passed @a strGuestOSTypeId is WDDM compatible. */
     47    SHARED_LIBRARY_STUFF bool isWddmCompatibleOsType(const QString &strGuestOSTypeId);
     48#endif
     49
     50    /** Returns the required video memory in bytes for the current desktop
     51      * resolution at maximum possible screen depth in bpp. */
     52    SHARED_LIBRARY_STUFF quint64 requiredVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
     53}
    4154
    4255/** Represents guest OS family info. */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIVideoMemoryEditor.cpp

    r104313 r105119  
    55
    66/*
    7  * Copyright (C) 2019-2023 Oracle and/or its affiliates.
     7 * Copyright (C) 2019-2024 Oracle and/or its affiliates.
    88 *
    99 * This file is part of VirtualBox base platform packages, as
     
    3535/* GUI includes: */
    3636#include "QIAdvancedSlider.h"
    37 #include "UICommon.h"
    3837#include "UIGlobalSession.h"
     38#include "UIGuestOSType.h"
    3939#include "UIVideoMemoryEditor.h"
    4040
     
    323323
    324324    /* Get monitors count and recommended VRAM: */
    325     int iNeedMBytes = UICommon::requiredVideoMemory(m_strGuestOSTypeId, m_cGuestScreenCount) / _1M;
     325    int iNeedMBytes = UIGuestOSTypeHelpers::requiredVideoMemory(m_strGuestOSTypeId, m_cGuestScreenCount) / _1M;
    326326
    327327    /* Adjust visible maximum VRAM to be no less than 128MB (if possible): */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsDisplay.cpp

    r104313 r105119  
    55
    66/*
    7  * Copyright (C) 2008-2023 Oracle and/or its affiliates.
     7 * Copyright (C) 2008-2024 Oracle and/or its affiliates.
    88 *
    99 * This file is part of VirtualBox base platform packages, as
     
    3838#include "UIGlobalSession.h"
    3939#include "UIGraphicsControllerEditor.h"
    40 #ifdef VBOX_WITH_3D_ACCELERATION
    41 # include "UIDisplayScreenFeaturesEditor.h"
    42 #endif
     40#include "UIGuestOSType.h"
    4341#include "UIMachineSettingsDisplay.h"
    4442#include "UIMonitorCountEditor.h"
     
    4846#include "UIVideoMemoryEditor.h"
    4947#include "UIVRDESettingsEditor.h"
     48#ifdef VBOX_WITH_3D_ACCELERATION
     49# include "UIDisplayScreenFeaturesEditor.h"
     50#endif
    5051
    5152/* COM includes: */
     
    336337#ifdef VBOX_WITH_3D_ACCELERATION
    337338    /* Check if WDDM mode supported by the guest OS type: */
    338     m_fWddmModeSupported = UICommon::isWddmCompatibleOsType(m_strGuestOSTypeId);
     339    m_fWddmModeSupported = UIGuestOSTypeHelpers::isWddmCompatibleOsType(m_strGuestOSTypeId);
    339340    m_pEditorVideoMemorySize->set3DAccelerationSupported(m_fWddmModeSupported);
    340341#endif /* VBOX_WITH_3D_ACCELERATION */
    341342    /* Acquire recommended graphics controller type: */
    342     m_enmGraphicsControllerTypeRecommended = uiCommon().getRecommendedGraphicsController(m_strGuestOSTypeId);
     343    m_enmGraphicsControllerTypeRecommended =
     344        gpGlobalSession->guestOSTypeManager().getRecommendedGraphicsController(m_strGuestOSTypeId);
    343345    /* Revalidate: */
    344346    revalidate();
     
    638640        if (shouldWeWarnAboutLowVRAM() && !m_strGuestOSTypeId.isEmpty())
    639641        {
    640             quint64 uNeedBytes = UICommon::requiredVideoMemory(m_strGuestOSTypeId, m_pEditorMonitorCount->value());
     642            quint64 uNeedBytes = UIGuestOSTypeHelpers::requiredVideoMemory(m_strGuestOSTypeId, m_pEditorMonitorCount->value());
    641643
    642644            /* Basic video RAM amount test: */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVM.cpp

    r105081 r105119  
    55
    66/*
    7  * Copyright (C) 2006-2023 Oracle and/or its affiliates.
     7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
    88 *
    99 * This file is part of VirtualBox base platform packages, as
     
    3131
    3232/* GUI includes: */
    33 #include "UICommon.h"
    3433#include "UIGlobalSession.h"
    3534#include "UIGuestOSType.h"
     
    180179    /* Correct the VRAM size since API does not take fullscreen memory requirements into account: */
    181180    CGraphicsAdapter comGraphics = m_machine.GetGraphicsAdapter();
    182     comGraphics.SetVRAMSize(qMax(comGraphics.GetVRAMSize(), (ULONG)(UICommon::requiredVideoMemory(m_guestOSTypeId) / _1M)));
     181    comGraphics.SetVRAMSize(qMax(comGraphics.GetVRAMSize(),
     182                                 (ULONG)(UIGuestOSTypeHelpers::requiredVideoMemory(m_guestOSTypeId) / _1M)));
    183183    /* Enabled I/O APIC explicitly in we have more than 1 VCPU: */
    184184    if (iVPUCount > 1)
     
    242242        return fResult;
    243243
    244     /* Inform UICommon about it: */
     244    /* Inform UIMediumEnumerator about it: */
    245245    gpMediumEnumerator->createMedium(UIMedium(newVirtualDisk, UIMediumDeviceType_HardDisk, KMediumState_Created));
    246246
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette