VirtualBox

Changeset 105864 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Aug 26, 2024 6:45:15 PM (5 months ago)
Author:
vboxsync
Message:

Main: Added API for querying graphics features (2D Video / 3D Acceleration) of a specific graphics controller for a given platform and revamped the graphics controller attributes for 2D / 3D setters/getters to also use the new graphics features enumeration. Also, the system properties also now contain a dedicated API to query for graphics features (very basic for now, needs to be stuffed out). See SDK changelog for details. Added validation code when setting a specific graphics feature (which we never did before). bugref:10749

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/GraphicsAdapterImpl.cpp

    r104819 r105864  
    3737
    3838#include <iprt/cpp/utils.h>
     39
     40
     41/** @def MY_VECTOR_ASSIGN_ARRAY
     42 * Safe way to copy an array (static + const) into a vector w/ minimal typing.
     43 *
     44 * @param a_rVector     The destination vector reference.
     45 * @param a_aSrcArray   The source array to assign to the vector.
     46 */
     47#if RT_GNUC_PREREQ(13, 0) && !RT_GNUC_PREREQ(14, 0) && defined(VBOX_WITH_GCC_SANITIZER)
     48/* Workaround for g++ 13.2 incorrectly failing on arrays with a single entry in ASAN builds.
     49   This is restricted to [13.0, 14.0), assuming the issue was introduced in the 13 cycle
     50   and will be fixed by the time 14 is done.  If 14 doesn't fix it, extend the range
     51   version by version till it is fixed. */
     52# define MY_VECTOR_ASSIGN_ARRAY(a_rVector, a_aSrcArray) do { \
     53        _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wstringop-overread\""); \
     54        (a_rVector).assign(&a_aSrcArray[0], &a_aSrcArray[RT_ELEMENTS(a_aSrcArray)]); \
     55        _Pragma("GCC diagnostic pop"); \
     56    } while (0)
     57#else
     58# define MY_VECTOR_ASSIGN_ARRAY(a_rVector, a_aSrcArray) do { \
     59        (a_rVector).assign(&a_aSrcArray[0], &a_aSrcArray[RT_ELEMENTS(a_aSrcArray)]); \
     60    } while (0)
     61#endif
    3962
    4063
     
    256279}
    257280
    258 HRESULT GraphicsAdapter::getAccelerate3DEnabled(BOOL *aAccelerate3DEnabled)
    259 {
    260     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    261 
    262     *aAccelerate3DEnabled = mData->fAccelerate3D;
    263 
    264     return S_OK;
    265 }
    266 
    267 HRESULT GraphicsAdapter::setAccelerate3DEnabled(BOOL aAccelerate3DEnabled)
     281/**
     282 * Static helper function to return all supported features for a given graphics controller.
     283 *
     284 * @returns VBox status code.
     285 * @param   enmController                          Graphics controller to return supported features for.
     286 * @param   vecSupportedGraphicsControllerFeatures Returned features on success.
     287 */
     288/* static */
     289int GraphicsAdapter::s_getSupportedFeatures(GraphicsControllerType_T enmController,
     290                                            std::vector<GraphicsFeature_T> &vecSupportedGraphicsFeatures)
     291{
     292    switch (enmController)
     293    {
     294#ifdef VBOX_WITH_VMSVGA
     295        case GraphicsControllerType_VBoxSVGA:
     296        {
     297            static const GraphicsFeature_T s_aGraphicsFeatures[] =
     298            {
     299# ifdef VBOX_WITH_VIDEOHWACCEL
     300                GraphicsFeature_Acceleration2DVideo,
     301# endif
     302# ifdef VBOX_WITH_3D_ACCELERATION
     303                GraphicsFeature_Acceleration3D
     304# endif
     305            };
     306            MY_VECTOR_ASSIGN_ARRAY(vecSupportedGraphicsFeatures, s_aGraphicsFeatures);
     307            break;
     308        }
     309#endif
     310        case GraphicsControllerType_VBoxVGA:
     311            RT_FALL_THROUGH();
     312        case GraphicsControllerType_QemuRamFB:
     313        {
     314            static const GraphicsFeature_T s_aGraphicsFeatures[] =
     315            {
     316                GraphicsFeature_None
     317            };
     318            MY_VECTOR_ASSIGN_ARRAY(vecSupportedGraphicsFeatures, s_aGraphicsFeatures);
     319            break;
     320        }
     321
     322        default:
     323            return VERR_INVALID_PARAMETER;
     324    }
     325
     326    return VINF_SUCCESS;
     327}
     328
     329/**
     330 * Static helper function to return whether a given graphics feature for a graphics controller is enabled or not.
     331 *
     332 * @returns \c true if the given feature is supported, or \c false if not.
     333 * @param   enmController           Graphics controlller to query a feature for.
     334 * @param   enmFeature              Feature to query.
     335 */
     336/* static */
     337bool GraphicsAdapter::s_isFeatureSupported(GraphicsControllerType_T enmController, GraphicsFeature_T enmFeature)
     338{
     339    std::vector<GraphicsFeature_T> vecSupportedGraphicsFeatures;
     340    int vrc = GraphicsAdapter::s_getSupportedFeatures(enmController, vecSupportedGraphicsFeatures);
     341    if (RT_SUCCESS(vrc))
     342        return std::find(vecSupportedGraphicsFeatures.begin(),
     343                         vecSupportedGraphicsFeatures.end(), enmFeature) != vecSupportedGraphicsFeatures.end();
     344    return false;
     345}
     346
     347HRESULT GraphicsAdapter::setFeature(GraphicsFeature_T aFeature, BOOL aEnabled)
    268348{
    269349    /* the machine needs to be mutable */
     
    273353    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    274354
    275     /** @todo check validity! */
    276 
    277     mParent->i_setModified(Machine::IsModified_GraphicsAdapter);
    278     mData.backup();
    279     mData->fAccelerate3D = !!aAccelerate3DEnabled;
    280 
    281     return S_OK;
    282 }
    283 
    284 
    285 HRESULT GraphicsAdapter::getAccelerate2DVideoEnabled(BOOL *aAccelerate2DVideoEnabled)
     355    /* Validate if the given feature is supported by this graphics controller. */
     356    if (!GraphicsAdapter::s_isFeatureSupported(mData->graphicsControllerType, aFeature))
     357        return setError(VBOX_E_NOT_SUPPORTED, tr("The graphics controller does not support the given feature"));
     358
     359    bool *pfSetting = NULL;
     360    switch (aFeature)
     361    {
     362        case GraphicsFeature_Acceleration2DVideo:
     363            pfSetting = &mData->fAccelerate2DVideo;
     364            break;
     365
     366        case GraphicsFeature_Acceleration3D:
     367            pfSetting = &mData->fAccelerate3D;
     368            break;
     369
     370        default:
     371            break;
     372    }
     373
     374    if (!pfSetting)
     375        return setError(E_NOTIMPL, tr("The given feature is not implemented"));
     376
     377    if (*pfSetting != RT_BOOL(aEnabled))
     378    {
     379        mParent->i_setModified(Machine::IsModified_GraphicsAdapter);
     380        mData.backup();
     381
     382        *pfSetting = RT_BOOL(aEnabled);
     383    }
     384
     385    return S_OK;
     386}
     387
     388HRESULT GraphicsAdapter::isFeatureEnabled(GraphicsFeature_T aFeature, BOOL *aEnabled)
    286389{
    287390    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    288391
    289     /* bugref:9691 The legacy VHWA acceleration has been disabled completely. */
    290     *aAccelerate2DVideoEnabled = FALSE;
    291 
    292     return S_OK;
    293 }
    294 
    295 HRESULT GraphicsAdapter::setAccelerate2DVideoEnabled(BOOL aAccelerate2DVideoEnabled)
    296 {
    297     /* the machine needs to be mutable */
    298     AutoMutableStateDependency adep(mParent);
    299     if (FAILED(adep.hrc())) return adep.hrc();
    300 
    301     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    302 
    303     /** @todo check validity! */
    304 
    305     mParent->i_setModified(Machine::IsModified_GraphicsAdapter);
    306     mData.backup();
    307     mData->fAccelerate2DVideo = !!aAccelerate2DVideoEnabled;
     392    bool *pfSetting = NULL;
     393
     394    switch (aFeature)
     395    {
     396#ifndef VBOX_WITH_VIRT_ARMV8 /* On macOS (ARM) we don't support any 2D/3D acceleration for now. */
     397        case GraphicsFeature_Acceleration2DVideo:
     398            pfSetting = &mData->fAccelerate2DVideo;
     399            *pfSetting = false; /* @bugref{9691} -- The legacy VHWA acceleration has been disabled completely. */
     400            break;
     401
     402        case GraphicsFeature_Acceleration3D:
     403            pfSetting = &mData->fAccelerate3D;
     404            break;
     405#endif
     406        default:
     407            break;
     408    }
     409
     410    if (!pfSetting)
     411        return VBOX_E_NOT_SUPPORTED;
     412
     413    *aEnabled = *pfSetting;
    308414
    309415    return S_OK;
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r105658 r105864  
    1523215232    if (FAILED(hrc)) return hrc;
    1523315233
    15234     hrc = mGraphicsAdapter->COMSETTER(Accelerate2DVideoEnabled)(fAccelerate2DVideoEnabled);
    15235     if (FAILED(hrc)) return hrc;
     15234    hrc = mGraphicsAdapter->SetFeature(GraphicsFeature_Acceleration2DVideo, fAccelerate2DVideoEnabled);
     15235    if (FAILED(hrc))
     15236    {
     15237        if (hrc != VBOX_E_NOT_SUPPORTED)
     15238            return hrc;
     15239    }
    1523615240
    1523715241    BOOL fAccelerate3DEnabled;
     
    1523915243    if (FAILED(hrc)) return hrc;
    1524015244
    15241     hrc = mGraphicsAdapter->COMSETTER(Accelerate3DEnabled)(fAccelerate3DEnabled);
    15242     if (FAILED(hrc)) return hrc;
     15245    hrc = mGraphicsAdapter->SetFeature(GraphicsFeature_Acceleration2DVideo, fAccelerate3DEnabled);
     15246    if (FAILED(hrc))
     15247    {
     15248        if (hrc != VBOX_E_NOT_SUPPORTED)
     15249            return hrc;
     15250    }
    1524315251
    1524415252    /* Apply network adapters defaults */
  • trunk/src/VBox/Main/src-server/SystemPropertiesImpl.cpp

    r105455 r105864  
    11761176}
    11771177
     1178HRESULT SystemProperties::getSupportedGraphicsFeatures(std::vector<GraphicsFeature_T> &aSupportedGraphicsFeatures)
     1179{
     1180    static const GraphicsFeature_T s_aGraphicsFeatures[] =
     1181    {
     1182#ifdef VBOX_WITH_VIDEOHWACCEL
     1183        GraphicsFeature_Acceleration2DVideo,
     1184#endif
     1185#ifdef VBOX_WITH_3D_ACCELERATION
     1186        GraphicsFeature_Acceleration3D
     1187#endif
     1188    };
     1189    MY_VECTOR_ASSIGN_ARRAY(aSupportedGraphicsFeatures, s_aGraphicsFeatures);
     1190
     1191    return S_OK;
     1192}
     1193
    11781194HRESULT SystemProperties::getSupportedRecordingFeatures(std::vector<RecordingFeature_T> &aSupportedRecordingFeatures)
    11791195{
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