VirtualBox

Changeset 9811

Show
Ignore:
Timestamp:
06/19/08 11:29:12 (6 months ago)
Author:
vboxsync
Message:

Additions/x11: use the guest/host registry to save the last resolution on machine shutdown and to restore it at startup

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/VBox/VBoxGuest.h

    r9662 r9811  
    15651565VBGLR3DECL(int)     VbglR3DisplayChangeWaitEvent(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits, uint32_t *piDisplay); 
    15661566VBGLR3DECL(bool)    VbglR3HostLikesVideoMode(uint32_t cx, uint32_t cy, uint32_t cBits); 
     1567VBGLR3DECL(int)     VbglR3SaveVideoMode(char *pszName, uint32_t cx, uint32_t cy, uint32_t cBits); 
     1568VBGLR3DECL(int)     VbglR3RetrieveVideoMode(char *pszName, uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits); 
    15671569/** @}  */ 
    15681570 
     1571/** @name Information Services 
     1572 * @{ */ 
     1573VBGLR3DECL(int)     VbglR3InfoSvcConnect(uint32_t *pu32ClientId); 
     1574VBGLR3DECL(int)     VbglR3InfoSvcDisconnect(uint32_t u32ClientId); 
     1575VBGLR3DECL(int)     VbglR3InfoSvcWriteKey(uint32_t u32ClientId, char *pszKey, char *pszValue); 
     1576VBGLR3DECL(int)     VbglR3InfoSvcReadKey(uint32_t u32ClientId, char *pszKey, char *pcValue, uint32_t cbValue, uint32_t *pcbActual); 
     1577/** @}  */ 
     1578 
    15691579 
    15701580__END_DECLS 
  • trunk/src/VBox/Additions/common/VBoxGuestLib/Makefile.kmk

    r9632 r9811  
    8888        VBoxGuestR3LibDaemonize.cpp \ 
    8989        VBoxGuestR3LibGR.cpp \ 
     90        VBoxGuestR3LibInfoSvc.cpp \ 
    9091        VBoxGuestR3LibMouse.cpp \ 
    9192        VBoxGuestR3LibMisc.cpp \ 
     
    117118        VBoxGuestR3Lib.cpp \ 
    118119        VBoxGuestR3LibGR.cpp \ 
     120        VBoxGuestR3LibInfoSvc.cpp \ 
    119121        VBoxGuestR3LibMouse.cpp \ 
    120122        VBoxGuestR3LibMisc.cpp \ 
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibVideo.cpp

    r8425 r9811  
    2828#include <iprt/assert.h> 
    2929#include <VBox/log.h> 
     30#include <VBox/HostServices/VBoxInfoSvc.h>  /* For Save and RetrieveVideoMode */ 
    3031 
    3132#include "VBGLR3Internal.h" 
     
    232233    return fRc; 
    233234} 
     235 
     236/** 
     237 * Save video mode parameters to the registry. 
     238 *  
     239 * @returns iprt status value 
     240 * @param   pszName the name to save the mode parameters under 
     241 * @param   cx      mode width 
     242 * @param   cy      mode height 
     243 * @param   cBits   bits per pixel for the mode 
     244 */ 
     245VBGLR3DECL(int) VbglR3SaveVideoMode(char *pszName, uint32_t cx, uint32_t cy, uint32_t cBits) 
     246{ 
     247    using namespace svcInfo; 
     248 
     249    char pcModeName[KEY_MAX_LEN]; 
     250    char pcModeParms[KEY_MAX_VALUE_LEN]; 
     251    uint32_t u32ClientId = 0; 
     252    RTStrPrintf(pcModeName, sizeof(pcModeName), "VideoMode/%s", pszName); 
     253    RTStrPrintf(pcModeParms, sizeof(pcModeParms), "%dx%dx%d", cx, cy, cBits); 
     254    int rc = VbglR3InfoSvcConnect(&u32ClientId); 
     255    if (RT_SUCCESS(rc)) 
     256        rc = VbglR3InfoSvcWriteKey(u32ClientId, pcModeName, pcModeParms); 
     257    if (u32ClientId != 0) 
     258        VbglR3InfoSvcDisconnect(u32ClientId);  /* Return value ignored, because what can we do anyway? */ 
     259    return rc; 
     260} 
     261 
     262 
     263/** 
     264 * Retrieve video mode parameters from the registry. 
     265 *  
     266 * @returns iprt status value 
     267 * @param   pszName the name under which the mode parameters are saved 
     268 * @param   pcx     where to store the mode width 
     269 * @param   pcy     where to store the mode height 
     270 * @param   pcBits  where to store the bits per pixel for the mode 
     271 */ 
     272VBGLR3DECL(int) VbglR3RetrieveVideoMode(char *pszName, uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits) 
     273{ 
     274    using namespace svcInfo; 
     275 
     276    char pcModeName[KEY_MAX_LEN]; 
     277    char pcModeParms[KEY_MAX_VALUE_LEN]; 
     278    char *pszNext; 
     279    uint32_t u32ClientId; 
     280    uint32_t cx, cy, cBits; 
     281 
     282    RTStrPrintf(pcModeName, sizeof(pcModeName), "VideoMode/%s", pszName); 
     283    int rc = VbglR3InfoSvcConnect(&u32ClientId); 
     284    if (RT_SUCCESS(rc)) 
     285        rc = VbglR3InfoSvcReadKey(u32ClientId, pcModeName, pcModeParms, 
     286                                  sizeof(pcModeParms), NULL); 
     287    if (RT_SUCCESS(rc)) 
     288        /* Extract the width from the string */ 
     289        rc = RTStrToUInt32Ex(pcModeParms, &pszNext, 10, &cx); 
     290    if (   (VWRN_NUMBER_TOO_BIG == rc) 
     291        || (VWRN_NEGATIVE_UNSIGNED == rc) 
     292        || (RT_SUCCESS(rc) && (*pszNext != ',') && (*pszNext != 'x'))) 
     293        rc = VERR_INVALID_PARAMETER; 
     294    if (RT_SUCCESS(rc)) 
     295    { 
     296        if ((*pszNext != ',') || (*pszNext != 'x')) 
     297            ++pszNext; 
     298        for (;' ' == *pszNext; ++pszNext); 
     299        rc = RTStrToUInt32Ex(pszNext, &pszNext, 10, &cy); 
     300    } 
     301    if (   (VWRN_NUMBER_TOO_BIG == rc) 
     302        || (VWRN_NEGATIVE_UNSIGNED == rc) 
     303        || (RT_SUCCESS(rc) && (*pszNext != ',') && (*pszNext != 'x'))) 
     304        rc = VERR_INVALID_PARAMETER; 
     305    if (RT_SUCCESS(rc)) 
     306    { 
     307        if ((*pszNext != ',') || (*pszNext != 'x')) 
     308            ++pszNext; 
     309        for (;' ' == *pszNext; ++pszNext); 
     310        rc = RTStrToUInt32Ex(pszNext, &pszNext, 10, &cBits); 
     311    } 
     312    if (   (VWRN_NUMBER_TOO_BIG == rc) 
     313        || (VWRN_NEGATIVE_UNSIGNED == rc) 
     314        || (VWRN_TRAILING_CHARS == rc)) 
     315        rc = VERR_INVALID_PARAMETER; 
     316    if (u32ClientId != 0) 
     317        VbglR3InfoSvcDisconnect(u32ClientId);  /* Return value ignored, because what can we do anyway? */ 
     318    if (RT_SUCCESS(rc)) 
     319    { 
     320        *pcx = cx; 
     321        *pcy = cy; 
     322        *pcBits = cBits; 
     323    } 
     324    return rc; 
     325} 
  • trunk/src/VBox/Additions/x11/xgraphics/vboxutils.c

    r9252 r9811  
    10021002Bool 
    10031003vboxGetDisplayChangeRequest(ScrnInfoPtr pScrn, uint32_t *pcx, uint32_t *pcy, 
    1004                             uint32_t *pcBits, uint32_t *piDisplay, 
    1005                             VBOXPtr pVBox) 
    1006 
     1004                            uint32_t *pcBits, uint32_t *piDisplay) 
     1005
     1006    VBOXPtr pVBox = pScrn->driverPrivate; 
    10071007    TRACE_ENTRY(); 
    10081008    if (!pVBox->useDevice) 
     
    10251025 */ 
    10261026Bool 
    1027 vboxHostLikesVideoMode(uint32_t cx, uint32_t cy, uint32_t cBits) 
    1028 
    1029     TRACE_ENTRY(); 
     1027vboxHostLikesVideoMode(ScrnInfoPtr pScrn, uint32_t cx, uint32_t cy, uint32_t cBits) 
     1028
     1029    VBOXPtr pVBox = pScrn->driverPrivate; 
     1030    TRACE_ENTRY(); 
     1031    if (!pVBox->useDevice) 
     1032        return TRUE;  /* If we can't ask the host then we like everything. */ 
    10301033    return VbglR3HostLikesVideoMode(cx, cy, cBits); 
    10311034} 
     1035 
     1036/** 
     1037 * Save video mode parameters to the registry. 
     1038 *  
     1039 * @returns iprt status value 
     1040 * @param   pszName the name to save the mode parameters under 
     1041 * @param   cx      mode width 
     1042 * @param   cy      mode height 
     1043 * @param   cBits   bits per pixel for the mode 
     1044 */ 
     1045Bool 
     1046vboxSaveVideoMode(ScrnInfoPtr pScrn, uint32_t cx, uint32_t cy, uint32_t cBits) 
     1047{ 
     1048    VBOXPtr pVBox = pScrn->driverPrivate; 
     1049    TRACE_ENTRY(); 
     1050    if (!pVBox->useDevice) 
     1051        return FALSE; 
     1052    return RT_SUCCESS(VbglR3SaveVideoMode("SavedMode", cx, cy, cBits)); 
     1053} 
     1054 
     1055/** 
     1056 * Retrieve video mode parameters from the registry. 
     1057 *  
     1058 * @returns iprt status value 
     1059 * @param   pszName the name under which the mode parameters are saved 
     1060 * @param   pcx     where to store the mode width 
     1061 * @param   pcy     where to store the mode height 
     1062 * @param   pcBits  where to store the bits per pixel for the mode 
     1063 */ 
     1064Bool 
     1065vboxRetrieveVideoMode(ScrnInfoPtr pScrn, uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits) 
     1066{ 
     1067    VBOXPtr pVBox = pScrn->driverPrivate; 
     1068    TRACE_ENTRY(); 
     1069    if (!pVBox->useDevice) 
     1070        return FALSE; 
     1071    int rc = VbglR3RetrieveVideoMode("SavedMode", pcx, pcy, pcBits); 
     1072    if (RT_SUCCESS(rc)) 
     1073        TRACE_LOG("Retrieved a video mode of %dx%dx%d\n", *pcx, *pcy, *pcBits); 
     1074    else 
     1075        TRACE_LOG("Failed to retrieve video mode, error %d\n", rc); 
     1076    return (RT_SUCCESS(rc)); 
     1077} 
  • trunk/src/VBox/Additions/x11/xgraphics/vboxvideo.h

    r9252 r9811  
    189189extern Bool vboxGetDisplayChangeRequest(ScrnInfoPtr pScrn, uint32_t *pcx, 
    190190                                        uint32_t *pcy, uint32_t *pcBits, 
    191                                         uint32_t *piDisplay, VBOXPtr pVBox); 
     191                                        uint32_t *piDisplay); 
    192192 
    193 extern Bool vboxHostLikesVideoMode(uint32_t cx, uint32_t cy, uint32_t cBits); 
     193extern Bool vboxHostLikesVideoMode(ScrnInfoPtr pScrn, uint32_t cx, uint32_t cy, uint32_t cBits); 
     194extern Bool vboxSaveVideoMode(ScrnInfoPtr pScrn, uint32_t cx, uint32_t cy, uint32_t cBits); 
     195extern Bool vboxRetrieveVideoMode(ScrnInfoPtr pScrn, uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits); 
    194196 
    195197#endif /* _VBOXVIDEO_H_ */ 
  • trunk/src/VBox/Additions/x11/xgraphics/vboxvideo_13.c

    r9018 r9811  
    5252 */ 
    5353 
    54 /* #define DEBUG_VIDEO 1 */ 
     54#ifdef DEBUG_michael 
     55# define DEBUG_VIDEO 1 
     56#endif 
    5557#ifdef DEBUG_VIDEO 
    5658 
     
    300302    VBOXSetMode(crtc->scrn, adjusted_mode); 
    301303    VBOXAdjustFrame(crtc->scrn->scrnIndex, x, y, 0); 
     304    vboxSaveVideoMode(crtc->scrn, adjusted_mode->HDisplay, 
     305                      adjusted_mode->VDisplay, crtc->scrn->bitsPerPixel); 
    302306} 
    303307 
     
    345349vbox_output_mode_valid (xf86OutputPtr output, DisplayModePtr mode) 
    346350{ 
     351    ScrnInfoPtr pScrn = output->scrn; 
    347352    int rc = MODE_OK; 
    348353    TRACE3("HDisplay=%d, VDisplay=%d\n", mode->HDisplay, mode->VDisplay); 
    349     if (   vbox_device_available(VBOXGetRec(output->scrn)) 
    350         && !vboxHostLikesVideoMode(mode->HDisplay, mode->VDisplay, 
    351                                    output->scrn->bitsPerPixel) 
     354    if (   vbox_device_available(VBOXGetRec(pScrn)) 
     355        && !vboxHostLikesVideoMode(pScrn, mode->HDisplay, 
     356                                   mode->VDisplay, pScrn->bitsPerPixel) 
    352357       ) 
    353358        rc = MODE_BAD; 
     
    413418    if (vbox_device_available(pVBox)) 
    414419    { 
    415         rc = vboxGetDisplayChangeRequest(pScrn, &x, &y, &bpp, &display, pVBox); 
    416         /* @todo - check the display number once we support multiple displays. */ 
     420        rc = vboxGetDisplayChangeRequest(pScrn, &x, &y, &bpp, &display); 
     421        /** @todo - check the display number once we support multiple displays. */ 
     422        /* If we don't find a display request, see if we have a saved hint 
     423         * from a previous session. */ 
     424        if (rc) 
     425            TRACE3("Got a display change request for %dx%d\n", x, y); 
     426        if (!rc || (0 == x) || (0 == y)) 
     427        { 
     428            rc = vboxRetrieveVideoMode(pScrn, &x, &y, &bpp); 
     429            if (rc) 
     430                TRACE3("Retrieved a video mode of %dx%d\n", x, y); 
     431        } 
    417432        if (rc && (0 != x) && (0 != y)) { 
    418433            /* We prefer a slightly smaller size to a slightly larger one */ 
     
    720735            /* We only support 16 and 24 bits depth (i.e. 16 and 32bpp) */ 
    721736            if (   vboxGetDisplayChangeRequest(pScrn, &cx, &cy, &cBits, 
    722                                                &iDisplay, pVBox
     737                                               &iDisplay
    723738                && (cBits != 16) 
    724739               ) 
  • trunk/src/VBox/Additions/x11/xgraphics/vboxvideo_15.c

    r9252 r9811  
    117117static const OptionInfoRec * VBOXAvailableOptions(int chipid, int busid); 
    118118static void VBOXIdentify(int flags); 
     119#ifndef PCIACCESS 
    119120static Bool VBOXProbe(DriverPtr drv, int flags); 
    120 #ifdef PCIACCESS 
     121#else 
    121122static Bool VBOXPciProbe(DriverPtr drv, int entity_num, 
    122123     struct pci_device *dev, intptr_t match_data); 
     
    334335    VBOXSetMode(crtc->scrn, adjusted_mode); 
    335336    VBOXAdjustFrame(crtc->scrn->scrnIndex, x, y, 0); 
     337    vboxSaveVideoMode(crtc->scrn, adjusted_mode->HDisplay, 
     338                      adjusted_mode->VDisplay, crtc->scrn->bitsPerPixel); 
    336339} 
    337340 
     
    379382vbox_output_mode_valid (xf86OutputPtr output, DisplayModePtr mode) 
    380383{ 
     384    ScrnInfoPtr pScrn = output->scrn; 
    381385    int rc = MODE_OK; 
    382386    TRACE3("HDisplay=%d, VDisplay=%d\n", mode->HDisplay, mode->VDisplay); 
    383     if (   vbox_device_available(VBOXGetRec(output->scrn)) 
    384         && !vboxHostLikesVideoMode(mode->HDisplay, mode->VDisplay, 
    385                                    output->scrn->bitsPerPixel) 
     387    if (   vbox_device_available(VBOXGetRec(pScrn)) 
     388        && !vboxHostLikesVideoMode(pScrn, mode->HDisplay, mode->VDisplay, 
     389                                   pScrn->bitsPerPixel) 
    386390       ) 
    387391        rc = MODE_BAD; 
     
    447451    if (vbox_device_available(pVBox)) 
    448452    { 
    449         rc = vboxGetDisplayChangeRequest(pScrn, &x, &y, &bpp, &display, pVBox); 
     453        rc = vboxGetDisplayChangeRequest(pScrn, &x, &y, &bpp, &display); 
    450454        /* @todo - check the display number once we support multiple displays. */ 
     455        /* If we don't find a display request, see if we have a saved hint 
     456         * from a previous session. */ 
     457        if (!rc || (0 == x) || (0 == y)) 
     458            rc = vboxRetrieveVideoMode(pScrn, &x, &y, &bpp); 
    451459        if (rc && (0 != x) && (0 != y)) { 
    452460            /* We prefer a slightly smaller size to a slightly larger one */ 
     
    636644#endif 
    637645 
     646#ifndef PCIACCESS 
    638647static Bool 
    639648VBOXProbe(DriverPtr drv, int flags) 
     
    651660        return (FALSE); 
    652661 
    653 #ifndef PCIACCESS 
    654662    /* PCI BUS */ 
    655663    if (xf86GetPciVideoInfo()) { 
     
    690698        } 
    691699    } 
     700 
     701    xfree(devSections); 
     702 
     703    return (foundScreen); 
     704} 
    692705#endif 
    693  
    694     xfree(devSections); 
    695  
    696     return (foundScreen); 
    697 } 
    698706 
    699707/* 
     
    804812            /* We only support 16 and 24 bits depth (i.e. 16 and 32bpp) */ 
    805813            if (   vboxGetDisplayChangeRequest(pScrn, &cx, &cy, &cBits, 
    806                                                &iDisplay, pVBox
     814                                               &iDisplay
    807815                && (cBits != 16) 
    808816               ) 
  • trunk/src/VBox/Additions/x11/xgraphics/vboxvideo_70.c

    r8472 r9811  
    470470        uint32_t cx = 0, cy = 0, iDisplay = 0, cBits = 24; 
    471471 
    472         if (vboxGetDisplayChangeRequest(pScrn, &cx, &cy, &cBits, &iDisplay, 
    473                                         pVBox)) 
     472        if (vboxGetDisplayChangeRequest(pScrn, &cx, &cy, &cBits, &iDisplay)) 
    474473        { 
    475474            /* We only support 16 and 24 bits depth (i.e. 16 and 32bpp) */ 
     
    515514        ++i; 
    516515    } 
    517     if (vboxHostLikesVideoMode(1024, 768, pScrn->bitsPerPixel)) 
     516    if (vboxHostLikesVideoMode(pScrn, 1024, 768, pScrn->bitsPerPixel)) 
    518517    { 
    519518        pScrn->display->modes[i] = "1024x768"; 
    520519        ++i; 
    521520    } 
    522     if (vboxHostLikesVideoMode(800, 600, pScrn->bitsPerPixel)) 
     521    if (vboxHostLikesVideoMode(pScrn, 800, 600, pScrn->bitsPerPixel)) 
    523522    { 
    524523        pScrn->display->modes[i] = "800x600"; 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy