VirtualBox

Changeset 104819 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 30, 2024 9:17:47 AM (6 months ago)
Author:
vboxsync
Message:

Main: Also make use of PlatformPropertiesImpl::s_getSupportedVRAMRange() in GraphicsAdapter::setVRAMSize(); also take the SchemaDefs in PlatformPropertiesImpl::s_getSupportedVRAMRange() into account. bugref:​10693

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/PlatformPropertiesImpl.h

    r104780 r104819  
    6767    static ULONG s_getMaxNetworkAdapters(ChipsetType_T aChipset);
    6868    static ULONG s_getMaxNetworkAdaptersOfType(ChipsetType_T aChipset, NetworkAttachmentType_T aType);
     69    static HRESULT s_getSupportedVRAMRange(GraphicsControllerType_T aGraphicsControllerType, BOOL fAccelerate3DEnabled, ULONG *aMinMB, ULONG *aMaxMB, ULONG *aStrideSizeMB);
    6970
    7071private:
  • trunk/src/VBox/Main/src-all/PlatformPropertiesImpl.cpp

    r104786 r104819  
    822822}
    823823
    824 HRESULT PlatformProperties::getSupportedVRAMRange(GraphicsControllerType_T aGraphicsControllerType, BOOL fAccelerate3DEnabled,
    825                                                   ULONG *aMinMB, ULONG *aMaxMB, ULONG *aStrideSizeMB)
     824/**
     825 * Returns the [minimum, maximum] VRAM range and stride size for a given graphics controller.
     826 *
     827 * @returns HRESULT
     828 * @param   aGraphicsControllerType Graphics controller type to return values for.
     829 * @param   fAccelerate3DEnabled    whether 3D acceleration is enabled / disabled for the selected graphics controller.
     830 * @param   aMinMB                  Where to return the minimum VRAM (in MB).
     831 * @param   aMaxMB                  Where to return the maximum VRAM (in MB).
     832 * @param   aStrideSizeMB           Where to return stride size (in MB). Optional, can be NULL.
     833 */
     834/* static */
     835HRESULT PlatformProperties::s_getSupportedVRAMRange(GraphicsControllerType_T aGraphicsControllerType, BOOL fAccelerate3DEnabled,
     836                                                    ULONG *aMinMB, ULONG *aMaxMB, ULONG *aStrideSizeMB)
    826837{
    827838#if !defined(VBOX_WITH_VMSVGA) || !defined(VBOX_WITH_VMSVGA3D)
     
    860871            cbMax = SVGA_VRAM_MAX_SIZE;
    861872#else
    862             return setError(VBOX_E_NOT_SUPPORTED, tr("Support for SVGA not available in this version"));
     873            return VBOX_E_NOT_SUPPORTED;
    863874#endif
    864875            break;
     
    874885
    875886        default:
    876             return setError(E_INVALIDARG, tr("The graphics controller type (%d) is invalid"), aGraphicsControllerType);
    877     }
    878 
    879     *aMinMB        = (ULONG)(RT_ALIGN_64(cbMin, cbStride) / _1M);
    880     *aMaxMB        = (ULONG)(RT_ALIGN_64(cbMax, cbStride) / _1M);
    881     *aStrideSizeMB = (ULONG)cbStride / _1M;
     887            return E_INVALIDARG;
     888    }
     889
     890    /* Convert bytes -> MB, align to stride. */
     891    cbMin    = (ULONG)(RT_ALIGN_64(cbMin, cbStride) / _1M);
     892    cbMax    = (ULONG)(RT_ALIGN_64(cbMax, cbStride) / _1M);
     893    cbStride = (ULONG)cbStride / _1M;
    882894
    883895#define MAKE_POWER_OF_TWO(a_MB) \
     
    885897        a_MB = a_MB + 1; \
    886898
    887     MAKE_POWER_OF_TWO(*aMinMB);
    888     MAKE_POWER_OF_TWO(*aMaxMB);
    889     MAKE_POWER_OF_TWO(*aStrideSizeMB);
     899    MAKE_POWER_OF_TWO(cbMin);
     900    MAKE_POWER_OF_TWO(cbMax);
     901    MAKE_POWER_OF_TWO(cbStride);
    890902
    891903#undef MAKE_POWER_OF_TWO
     904
     905    /* Finally, clamp the values to our schema definitions before returning. */
     906    cbMin = RT_CLAMP(cbMin, (size_t)SchemaDefs::MinGuestVRAM, (size_t)SchemaDefs::MaxGuestVRAM);
     907    cbMax = RT_CLAMP(cbMax, (size_t)SchemaDefs::MinGuestVRAM, (size_t)SchemaDefs::MaxGuestVRAM);
     908
     909    *aMinMB = (ULONG)cbMin;
     910    *aMaxMB = (ULONG)cbMax;
     911    if (aStrideSizeMB)
     912        *aStrideSizeMB = (ULONG)cbStride;
     913
     914    return S_OK;
     915}
     916
     917HRESULT PlatformProperties::getSupportedVRAMRange(GraphicsControllerType_T aGraphicsControllerType, BOOL fAccelerate3DEnabled,
     918                                                  ULONG *aMinMB, ULONG *aMaxMB, ULONG *aStrideSizeMB)
     919{
     920    HRESULT hrc = PlatformProperties::s_getSupportedVRAMRange(aGraphicsControllerType, fAccelerate3DEnabled, aMinMB, aMaxMB,
     921                                                              aStrideSizeMB);
     922    switch (hrc)
     923    {
     924        case VBOX_E_NOT_SUPPORTED:
     925            return setError(VBOX_E_NOT_SUPPORTED, tr("Selected graphics controller not supported in this version"));
     926
     927        case E_INVALIDARG:
     928            return setError(E_INVALIDARG, tr("The graphics controller type (%d) is invalid"), aGraphicsControllerType);
     929
     930        default:
     931            break;
     932    }
    892933
    893934    return S_OK;
  • trunk/src/VBox/Main/src-server/GraphicsAdapterImpl.cpp

    r101200 r104819  
    229229HRESULT GraphicsAdapter::setVRAMSize(ULONG aVRAMSize)
    230230{
    231     /* check VRAM limits */
    232     if (aVRAMSize > SchemaDefs::MaxGuestVRAM)
    233         return setError(E_INVALIDARG,
    234                         tr("Invalid VRAM size: %lu MB (must be in range [%lu, %lu] MB)"),
    235                         aVRAMSize, SchemaDefs::MinGuestVRAM, SchemaDefs::MaxGuestVRAM);
    236 
    237231    /* the machine needs to be mutable */
    238232    AutoMutableStateDependency adep(mParent);
    239233    if (FAILED(adep.hrc())) return adep.hrc();
     234
     235    ULONG uMin, uMax;
     236    HRESULT hrc = PlatformProperties::s_getSupportedVRAMRange(mData->graphicsControllerType, mData->fAccelerate3D,
     237                                                              &uMin, &uMax, NULL /* aStrideSizeMB */);
     238    if (FAILED(hrc))
     239        return setError(hrc,
     240                        tr("Error getting VRAM range for selected graphics controller"));
     241
     242    /* check VRAM limits */
     243    if (   aVRAMSize < uMin
     244        || aVRAMSize > uMax)
     245        return setError(E_INVALIDARG,
     246                        tr("Invalid VRAM size: %lu MB (must be in range [%lu, %lu] MB)"),
     247                        aVRAMSize, uMin, uMax);
    240248
    241249    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
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